Parsing TeX to math.js
It would be nice, if at some point math.js could parse a subset of TeX into a node tree.
There is absolutely no urgency and it might be possible to take inspiration/use code from other projects for that :
MathJax manages with success to parse a lot of TeX commands and to coerce it into mathml (content and presentationnal).
Some possible applications of such a parser :
- testing the toTex function and the fromTeX function (roundtrip)
- getting input from users in the TeX language
- import/reuse available snipets of TeX maths
- data exchange math.js <-> TeX <-> MathMl ...
Thanks for your suggestion!
I would also like this feature in mathjs, it would be very nice and useful for users who needs a simpler way of typing a mathematical expressions. In this way you might be able to let users type an expression with for example mathquill and parse it to maths js and make it computable.
hmm I was looking for a feature like this
@Kreijstal I also needed to convert LaTeX to MathJS. For my purposes, it has been good enough to:
- replace all fractions:
'\frac{a}{1 + \frac{b}{c}}'becomes'{a}/{1 + {b}/{c}}' - replace some names
-
'{'becomes'(' -
'\cdot'becomes'*' - etc
-
Then the resulting string can be sent to MathJS's parser. This certainly isn't perfect, but it's covered all the use-cases I need.
Here's links to my code. It's currently written for Babel with Flow annotations, but wouldn't be too hard to strip those:
- preprocessMathQuill.js (MathQuill is what generates my LaTeX)
-
helpers.js defines
replaceAllandfindClosingBracefunctions -
preprocessMathQuill.test.js fairly minimal tests of
preprocessMathQuill
@Kreijstal I also needed to convert LaTeX to MathJS. For my purposes, it has been good enough to:
replace all fractions:
'\frac{a}{1 + \frac{b}{c}}'becomes'{a}/{1 + {b}/{c}}'replace some names
'{'becomes'(''\cdot'becomes'*'- etc
Then the resulting string can be sent to MathJS's parser. This certainly isn't perfect, but it's covered all the use-cases I need.
Here's links to my code. It's currently written for Babel with Flow annotations, but wouldn't be too hard to strip those:
- preprocessMathQuill.js (MathQuill is what generates my LaTeX)
- helpers.js defines
replaceAllandfindClosingBracefunctions- preprocessMathQuill.test.js fairly minimal tests of
preprocessMathQuill
@ChristopherChudzicki needing to do the same. would love to take a look at what you built if you can share that project again.
For anyone still looking for a solution to this, I wrote a library here: https://github.com/davidtranhq/tex-math-parser that parses TeX strings into MathJS expression trees.
Nice, thanks for sharing @davidtranhq !