mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-22 11:55:15 -04:00
adds a \vee and \wedge command
This commit is contained in:
parent
39ae6ead0a
commit
769da5b07f
@ -74,7 +74,7 @@ of ~{s_1^{n+1}} in detail.
|
||||
von ~{s_1^{n+1}} im Detail erklärt.}}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="-120" y="400"/>
|
||||
<pos x="-120" y="440"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
@ -136,6 +136,36 @@ von ~{s_1^{n+1}} im Detail erklärt.}}</string>
|
||||
</elementAttributes>
|
||||
<pos x="140" y="340"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>A\wedge{}B</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="-20" y="400"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>~{A\vee{}B}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="140" y="400"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>\neg{}A</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="300" y="400"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires/>
|
||||
<measurementOrdering/>
|
||||
|
@ -14,11 +14,14 @@ import java.util.HashMap;
|
||||
* The text parser
|
||||
*/
|
||||
public class Parser {
|
||||
private static final HashMap<String, String> COMMANDS = new HashMap<>();
|
||||
private static final HashMap<String, java.lang.Character> COMMANDS = new HashMap<>();
|
||||
|
||||
static {
|
||||
COMMANDS.put("sum", "∑");
|
||||
COMMANDS.put("prod", "∏");
|
||||
COMMANDS.put("sum", '∑');
|
||||
COMMANDS.put("prod", '∏');
|
||||
COMMANDS.put("wedge", '∧');
|
||||
COMMANDS.put("vee", '∨');
|
||||
COMMANDS.put("neg", '¬');
|
||||
}
|
||||
|
||||
private final String text;
|
||||
@ -103,6 +106,10 @@ public class Parser {
|
||||
getChar();
|
||||
sentence.getIndex().addSub(parseBrace());
|
||||
break;
|
||||
case '{':
|
||||
getChar();
|
||||
expect('}');
|
||||
break;
|
||||
case '^':
|
||||
getChar();
|
||||
sentence.getIndex().addSuper(parseBrace());
|
||||
@ -118,10 +125,11 @@ public class Parser {
|
||||
break;
|
||||
default:
|
||||
String command = readWord();
|
||||
String t = COMMANDS.get(command);
|
||||
java.lang.Character t = COMMANDS.get(command);
|
||||
if (t == null)
|
||||
t = '\\' + command;
|
||||
sentence.add(new Simple(t).simplify());
|
||||
sentence.add(new Simple('\\' + command));
|
||||
else
|
||||
sentence.add(new Character(t));
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -132,6 +132,16 @@ public final class LaTeXFormatter {
|
||||
return "\\prod ";
|
||||
else
|
||||
return "$\\prod$";
|
||||
case '∧':
|
||||
if (inMath)
|
||||
return "\\wedge ";
|
||||
else
|
||||
return "$\\wedge$";
|
||||
case '∨':
|
||||
if (inMath)
|
||||
return "\\vee ";
|
||||
else
|
||||
return "$\\vee$";
|
||||
default:
|
||||
return "" + aChar;
|
||||
}
|
||||
|
@ -39,5 +39,15 @@ public class LaTeXFormatterTest extends TestCase {
|
||||
public void testSumProd() throws ParseException {
|
||||
assertEquals("$\\sum ^a_{n=0}$", LaTeXFormatter.format(new Parser("∑_{n=0}^a").parse()));
|
||||
assertEquals("$\\prod ^a_{n=0}$", LaTeXFormatter.format(new Parser("∏_{n=0}^a").parse()));
|
||||
assertEquals("$\\sum ^a_{n=0}$", LaTeXFormatter.format(new Parser("\\sum_{n=0}^a").parse()));
|
||||
assertEquals("$\\prod ^a_{n=0}$", LaTeXFormatter.format(new Parser("\\prod_{n=0}^a").parse()));
|
||||
}
|
||||
|
||||
public void testVeeWedge() throws ParseException {
|
||||
assertEquals("A $\\vee$ B", LaTeXFormatter.format(new Parser("A \\vee B").parse()));
|
||||
assertEquals("A $\\vee$ B", LaTeXFormatter.format(new Parser("A ∨ B").parse()));
|
||||
assertEquals("A$\\vee$B", LaTeXFormatter.format(new Parser("A∨B").parse()));
|
||||
assertEquals("$A \\wedge B$", LaTeXFormatter.format(new Parser("$A \\wedge B$").parse()));
|
||||
assertEquals("$A\\wedge B$", LaTeXFormatter.format(new Parser("$A\\wedge{}B$").parse()));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user