mathics / Mathics

This repository is for archival. Please see https://github.com/Mathics3/mathics-core
https://mathics.org
Other
2.07k stars 206 forks source link

possibility of converting a given latex expression to mathics expression #1367

Open bala-ck12 opened 3 years ago

bala-ck12 commented 3 years ago

HI All,

Is there any way to convert a given latex expression to mathics expression and evaluate it? in Wolfram Alpha, there is a provision(see below) to convert the latex expression to wolfram expression and then we can do the evaluation as we want.

ToExpression["\\frac{1}{2}",TeXForm]

Please do let me know if there any possible solution or workaround to convert a latex(or asciimath or mathml) expression to mathics expression

rocky commented 3 years ago

Is there any way to convert a given latex expression to mathics expression and evaluate it?

There is always a way to get something done if you are willing to work on it. :-)

Right now Mathics is pretty weak compared to Wolfram Alpha in the kinds of forms it supports. I think a bit of this is pretty straightforward to add, but it requires someone to do the coding. Hey, how about you?

Personally, I am not interested in hacky solutions and can't think of any offhand that you probably can't figure out yourself. But if you can't, maybe StackOverflow or something like that can suggest something .

mmatera commented 3 years ago

One problem with LaTeX parsing is that LaTeX is designed for typesetting, not for evaluation. Therefore, there are several ways to write something that looks equal. Also, several things that look equal can have different meanings. So, the first step to accomplish that would be to write a LaTeX parser to AST WL expressions, which is not a small task. What could help is to find a library that already parses LaTeX to some other AST structure (to MathML?) @bala-ck12, do you have any suggestions?

axkr commented 3 years ago

See sympy.parsing.latex.parse_latex(s)

bala-ck12 commented 3 years ago

Hi @mmatera there is a tool which I found in GitHub https://github.com/rafaellc28/Latex2Wolfram this working well with most of the simple latex expressions but showing errors in complex latex, You can give it a try.

As you said we can't accurately parse the latex all the time. Even the wolfram's ToExpression["\\frac{1}{2}",TeXForm] is not parsing correctly all the kinda latex and its combinations. achieving 90% accuracy is great.

Alternatively, if we have SympyForm to MathicsForm converter in mathics, maybe we first let sympy to parse the given expression using parse_latex func in sympy and convert it to a sympy string and then let SympyForm to MathicsForm converter to convert the sympy input and do the mathics evaluation.

Either way, having either TexForm or SympyForm would be great for mathics as Latex is still the most famous tool to display math. Why don't evaluate :)

Please share your thoughts.

mmatera commented 3 years ago

@bala-ck12, thanks for the information, it seems promising! At this stage, our very reduced active work team (@rocky and me) are putting most of the efforts on making fixes of the Mathics core to support all the basic subset of the WL. This would be something beyond that closer goal, but we can try to start implementing ToExpression[..., Latex] when we have the chance. Of course, if you have the time and the will to do this, we can help you.