Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
MathPrettyPrinter
Commits
70805e1e
Commit
70805e1e
authored
Jun 28, 2018
by
0xJMR
Browse files
Further development on TeXMathPrettyPrinter.
parent
a5ad3fac
Pipeline
#58721
failed with stage
in 21 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/mpp/montimath/TeXHTMLMathPrettyPrinter.java
View file @
70805e1e
package
de.monticore.lang.monticar.mpp.montimath
;
import
de.monticore.lang.math._ast.ASTMathAssignmentDeclarationStatement
;
import
de.monticore.lang.math._ast.ASTMathAssignmentStatement
;
import
de.monticore.lang.math._ast.ASTMathCompilationUnit
;
import
de.monticore.lang.math._ast.ASTMathNode
;
import
de.monticore.lang.math._ast.*
;
import
de.monticore.lang.monticar.mpp.core.tex.SVGGenerator
;
import
de.se_rwth.commons.logging.Log
;
...
...
@@ -47,6 +44,16 @@ public class TeXHTMLMathPrettyPrinter extends HTMLMathPrettyPrinter implements T
this
.
printImageTag
(
node
);
}
@Override
public
void
visit
(
ASTMathDeclarationStatement
node
)
{
this
.
printImageTag
(
node
);
}
@Override
public
void
endVisit
(
ASTMathDeclarationStatement
node
)
{
this
.
printer
.
println
();
}
@Override
public
void
endVisit
(
ASTMathAssignmentDeclarationStatement
node
)
{
this
.
printer
.
println
();
...
...
@@ -61,4 +68,12 @@ public class TeXHTMLMathPrettyPrinter extends HTMLMathPrettyPrinter implements T
public
void
endVisit
(
ASTMathAssignmentStatement
node
)
{
this
.
printer
.
println
();
}
@Override
public
void
visit
(
ASTMathForLoopHead
node
)
{
this
.
printer
.
println
();
this
.
printFor
();
this
.
printSpace
();
this
.
printImageTag
(
node
);
}
}
src/main/java/de/monticore/lang/monticar/mpp/montimath/TeXHTMLMathStructuredVisitor.java
View file @
70805e1e
...
...
@@ -2,6 +2,8 @@ package de.monticore.lang.monticar.mpp.montimath;
import
de.monticore.lang.math._ast.ASTMathAssignmentDeclarationStatement
;
import
de.monticore.lang.math._ast.ASTMathAssignmentStatement
;
import
de.monticore.lang.math._ast.ASTMathDeclarationStatement
;
import
de.monticore.lang.math._ast.ASTMathForLoopHead
;
public
interface
TeXHTMLMathStructuredVisitor
extends
MathStructuredVisitor
{
@Override
...
...
@@ -12,4 +14,10 @@ public interface TeXHTMLMathStructuredVisitor extends MathStructuredVisitor {
@Override
default
void
traverse
(
ASTMathAssignmentStatement
node
)
{}
@Override
default
void
traverse
(
ASTMathDeclarationStatement
node
)
{}
@Override
default
void
traverse
(
ASTMathForLoopHead
node
)
{}
}
src/main/java/de/monticore/lang/monticar/mpp/montimath/TeXMathPrettyPrinter.java
View file @
70805e1e
package
de.monticore.lang.monticar.mpp.montimath
;
import
de.monticore.commonexpressions._ast.ASTDivideExpression
;
import
de.monticore.commonexpressions._ast.ASTModuloExpression
;
import
de.monticore.commonexpressions._ast.ASTMultExpression
;
import
de.monticore.lang.math._ast.*
;
import
de.monticore.lang.matrix._ast.ASTMathMatrixAccessExpression
;
import
de.monticore.lang.matrix._ast.ASTMathMatrixValueExplicitExpression
;
import
de.monticore.lang.matrix._ast.ASTMathVectorExpression
;
import
de.monticore.lang.matrixexpressions._ast.ASTMathArithmeticMatrixEELeftDivideExpression
;
import
de.monticore.lang.matrixexpressions._ast.ASTMathArithmeticMatrixEEPowExpression
;
import
de.monticore.lang.matrixexpressions._ast.ASTMathArithmeticMatrixSolutionExpression
;
import
de.monticore.numberunit._ast.ASTTimeDiv
;
public
class
TeXMathPrettyPrinter
extends
MathPrettyPrinter
implements
TeXMathStructuredVisitor
{
protected
boolean
inMatrixEnvironment
;
public
TeXMathPrettyPrinter
()
{
this
.
inMatrixEnvironment
=
false
;
}
@Override
public
void
visit
(
ASTElementType
node
)
{
String
printedNode
=
String
.
format
(
"\\mathbb{%s}"
,
node
.
getName
());
...
...
@@ -55,8 +68,15 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
this
.
printer
.
print
(
"~"
);
}
@Override
public
void
visit
(
ASTMathDeclarationStatement
node
)
{
this
.
printer
.
print
(
"~"
);
this
.
printer
.
print
(
node
.
getName
());
}
@Override
public
void
visit
(
ASTTimeDiv
node
)
{
//TODO: Create LaTeX
if
(
node
.
isPresentIsDiv
())
{
this
.
printer
.
print
(
node
.
getIsDiv
());
}
...
...
@@ -65,4 +85,77 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
this
.
printer
.
print
(
"\\cdot"
);
}
}
@Override
public
void
visit
(
ASTMathMatrixValueExplicitExpression
node
)
{
this
.
inMatrixEnvironment
=
true
;
this
.
printer
.
print
(
"\\begin{bmatrix}"
);
}
@Override
public
void
revisit
(
ASTMathMatrixValueExplicitExpression
node
)
{
this
.
printer
.
print
(
"\\\\"
);
}
@Override
public
void
endVisit
(
ASTMathMatrixValueExplicitExpression
node
)
{
this
.
printer
.
print
(
"\\end{bmatrix}"
);
this
.
inMatrixEnvironment
=
false
;
}
@Override
public
void
revisit
(
ASTMathMatrixAccessExpression
node
)
{
this
.
printSpace
();
if
(
this
.
inMatrixEnvironment
)
this
.
printer
.
print
(
"&"
);
else
this
.
printComma
();
this
.
printSpace
();
}
@Override
public
void
visit
(
ASTMathMatrixAccessExpression
node
)
{
if
(!
this
.
inMatrixEnvironment
)
this
.
printLeftBracket
();
}
@Override
public
void
endVisit
(
ASTMathMatrixAccessExpression
node
)
{
if
(!
this
.
inMatrixEnvironment
)
this
.
printRightBracket
();
}
@Override
public
void
revisit
(
ASTMathArithmeticMatrixEEPowExpression
node
)
{
this
.
printer
.
print
(
".\\hat{}~"
);
}
@Override
public
void
revisit
(
ASTModuloExpression
node
)
{
this
.
printer
.
print
(
"~\\%~"
);
}
@Override
public
void
visit
(
ASTMathVectorExpression
node
)
{
this
.
printer
.
print
(
"\\begin{bmatrix}"
);
}
@Override
public
void
revisit
(
ASTMathVectorExpression
node
)
{
this
.
printer
.
print
(
"\\\\"
);
}
@Override
public
void
endVisit
(
ASTMathVectorExpression
node
)
{
this
.
printer
.
print
(
"\\end{bmatrix}"
);
}
@Override
public
void
revisit
(
ASTMathArithmeticMatrixSolutionExpression
node
)
{
this
.
printer
.
print
(
"~.\\backslash\\backslash~"
);
}
@Override
public
void
visit
(
ASTMathForLoopHead
node
)
{
this
.
printer
.
print
(
node
.
getName
());
this
.
printSpace
();
this
.
printer
.
print
(
"="
);
this
.
printSpace
();
}
}
src/test/resources/models/montimath/vanilla/Example.m
View file @
70805e1e
package montimath.vanilla;
script Example
Q(0:10)^{
5,1
} c = 1:2:10;
Q(0:10)^{
1,5
} c = 1:2:10;
Q x = 0;
Q y = 0;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment