Commit 7383496f authored by 0xJMR's avatar 0xJMR
Browse files

Tweaks parentheses.

parent 04a0f53e
......@@ -9,6 +9,14 @@ import de.monticore.lang.matrixexpressions._ast.ASTMathArithmeticMatrixSolutionE
import de.monticore.numberunit._ast.ASTTimeDiv;
public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathStructuredVisitor {
protected boolean needsParenthesis;
protected int parenthesis;
public TeXMathPrettyPrinter() {
this.needsParenthesis = true;
this.parenthesis = 0;
}
@Override
public void visit(ASTElementType node) {
String printedNode = String.format("\\mathbb{%s}", node.getName());
......@@ -32,6 +40,7 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
@Override
public void visit(ASTDivideExpression node) {
this.needsParenthesis = false;
this.printer.print("\\frac{");
}
......@@ -43,6 +52,7 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
@Override
public void endVisit(ASTDivideExpression node) {
this.printer.print("}");
this.needsParenthesis = true;
}
@Override
......@@ -96,8 +106,10 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
@Override
public void revisit(ASTMathMatrixAccessExpression node) {
this.printSpace();
if (this.inMatrixEnvironment) this.printer.print("&");
else this.printComma();
this.printSpace();
}
......@@ -141,12 +153,20 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
@Override
public void visit(ASTBracketExpression node) {
this.printer.print("\\left(");
if (this.needsParenthesis) {
this.printer.print("\\left(");
this.parenthesis++;
} else {
this.needsParenthesis = true;
}
}
@Override
public void endVisit(ASTBracketExpression node) {
this.printer.print("\\right)");
if (this.parenthesis > 0) {
this.printer.print("\\right)");
this.parenthesis--;
}
}
@Override
......@@ -192,8 +212,8 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
}
@Override
public void visit(ASTMathIfExpression node) {}
public void visit(ASTMathIfExpression node) { /* NOOP */ }
@Override
public void visit(ASTMathElseIfExpression node) {}
public void visit(ASTMathElseIfExpression node) { /* NOOP */ }
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment