[Tex/LaTex] Converting mathematical TeX expressions

conversionequationsoutputprogramming

Is there a (hopefully simple) way to convert a mathematical TeX expression, such as \frac{\cos(x^2) - x}{x^2 + 1}, to expressions which you would use in a programming language? The outcome of the example should be (cos(x^2) - x)/(x^2 + 1).

Best Answer

It is of course possible it depends what tools you want to use and what subset of latex you want to support (you show an easy case, if the latex has fonts and colours or explicit spacing it gets harder). Wolfram alpha for example can compute with the expression exactly as given, in latex syntax.

https://www.wolframalpha.com/input/?i=%5Cfrac%7Bcos%28x%5E2%29+-+x%7D%7Bx%5E2+%2B+1%7D

enter image description here

It also works with cos corrected to \cos

https://www.wolframalpha.com/input/?i=%5Cfrac%7B%5Ccos%28x%5E2%29+-+x%7D%7Bx%5E2+%2B+1%7D

Related Question