Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform source code into LaTeX

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.

like image 308
Shahriar Avatar asked Nov 13 '22 12:11

Shahriar


1 Answers

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.

like image 195
SpaceTrucker Avatar answered Nov 15 '22 06:11

SpaceTrucker