diff --git a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorTerm.java b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorTerm.java index 10c42ff..79a2793 100644 --- a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorTerm.java +++ b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorTerm.java @@ -11,7 +11,6 @@ import static edu.kit.typicalc.view.content.typeinferencecontent.latexcreator.La * @see LambdaTerm */ public class LatexCreatorTerm implements TermVisitor { - // TODO: document private final StringBuilder latex = new StringBuilder(); private boolean needsParentheses = false; @@ -29,14 +28,13 @@ public class LatexCreatorTerm implements TermVisitor { * @return the generated LaTeX code */ public String getLatex() { - // todo remove most outer parentheses if they exist, untested -// long count = latex.chars().filter(ch -> ch == PAREN_LEFT).count(); -// if (latex.indexOf(String.valueOf(PAREN_LEFT)) == 0 -// && latex.indexOf(String.valueOf(PAREN_RIGHT)) == latex.length() - 1 -// && count == 1) { -// latex.deleteCharAt(latex.length() - 1); -// latex.deleteCharAt(0); -// } + long count = latex.chars().filter(ch -> ch == PAREN_LEFT).count(); + if (latex.indexOf(String.valueOf(PAREN_LEFT)) == 0 + && latex.indexOf(String.valueOf(PAREN_RIGHT)) == latex.length() - 1 + && count == 1) { + latex.deleteCharAt(latex.length() - 1); + latex.deleteCharAt(0); + } return latex.toString(); } diff --git a/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorTermTest.java b/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorTermTest.java index 886950a..0b51f67 100644 --- a/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorTermTest.java +++ b/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorTermTest.java @@ -18,8 +18,8 @@ class LatexCreatorTermTest { @Test void absTest() { typeInferer = model.getTypeInferer("λx.y", new HashMap<>()).unwrap(); - assertEquals(PAREN_LEFT + LAMBDA + SPACE + MONO_TEXT + "{x}" + DOT_SIGN - + LATEX_SPACE + MONO_TEXT + "{y}" + PAREN_RIGHT, + assertEquals(LAMBDA + SPACE + MONO_TEXT + "{x}" + DOT_SIGN + + LATEX_SPACE + MONO_TEXT + "{y}", new LatexCreatorTerm(typeInferer.getFirstInferenceStep().getConclusion().getLambdaTerm()).getLatex()); }