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