I frequently come across lots of physics equations implemented in Java and Fortran. In most cases these equations are copied straight from an advanced physics textbook or a publication. The equations in their original form are quite easy to read because they are usually typeset in LaTeX. However, when these equations are translated into code they look like gibberish. Even using short domain-specific variable names as suggested here, or breaking down the equation into multiple line doesn't make it look as intuitive as the typeset version.
Is there any tool that can parse a Java/Fortran source file and output it in LaTeX, transforming all mathematical expressions into their LaTeX equivalent. For example,
Math.sqrt(Math.pow(a,2) + Math.pow(b,2))
is transformed into
\sqrt{a^2 + b^2}
Just to be clear. I am not looking for solutions that allow LaTeX to be included as a part of comments/javadoc. Because that would only create LaTeX output of my comments and not the expression in the source code.
I think I have seen something like you request done with the projectional editor of jetbrains mps. It used to show arithmetic expressions in source code as latex-like rendered equations. Though I can't remember exactly, where I saw it. Maybe it was mbeddr.
However you are more interested in the way from source to latex, so here is my suggestion: ATL provides a model-to-model transformation. You could use it to transform your Java expressions to latex expressions. Therefore you need an EMF model of Java. MoDisco already ships with a Java 1.5 model. I don't know of a latex EMF model. To serialize the model to latex sources, you could use Xtext.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With