Improves the spacing of & and | in LaTeX math mode output.

This commit is contained in:
hneemann 2020-09-21 10:40:40 +02:00
parent 5857f214a9
commit a9409319bd
2 changed files with 14 additions and 5 deletions

View File

@ -42,10 +42,7 @@ public final class LaTeXFormatter {
if (text instanceof Simple) {
return ((Simple) text).getText();
} else if (text instanceof Blank) {
if (mathMode)
return "\\ ";
else
return " ";
return " ";
} else if (text instanceof Character) {
return character(((Character) text).getChar(), mathMode);
} else if (text instanceof Decorate) {
@ -112,7 +109,15 @@ public final class LaTeXFormatter {
else
return "\\textgreater{}";
case '&':
return "\\&";
if (inMath)
return "\\ \\&\\ ";
else
return "\\&";
case '|':
if (inMath)
return "\\ |\\ ";
else
return "|";
case '_':
return "\\_";
case '\\':

View File

@ -30,6 +30,10 @@ public class LaTeXFormatterTest extends TestCase {
assertEquals("a\\&b", LaTeXFormatter.format(new Parser("a&b").parse()));
assertEquals("a$\\neg{}$b", LaTeXFormatter.format(new Parser("a¬b").parse()));
assertEquals("$a\\neg{}b$", LaTeXFormatter.format(new Parser("$a¬b$").parse()));
assertEquals("a\\&b", LaTeXFormatter.format(new Parser("a&b").parse()));
assertEquals("$a\\ \\&\\ b$", LaTeXFormatter.format(new Parser("$a&b$").parse()));
assertEquals("a|b", LaTeXFormatter.format(new Parser("a|b").parse()));
assertEquals("$a\\ |\\ b$", LaTeXFormatter.format(new Parser("$a|b$").parse()));
}
public void testSumProd() throws ParseException {