Mathjs: Parsing TeX to math.js

Created on 23 Mar 2015  路  5Comments  路  Source: josdejong/mathjs

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 :
1) testing the toTex function and the fromTeX function (roundtrip)
2) getting input from users in the TeX language
3) import/reuse available snipets of TeX maths
4) data exchange math.js <-> TeX <-> MathMl
...

feature

Most helpful comment

@Kreijstal I also needed to convert LaTeX to MathJS. For my purposes, it has been good enough to:

  1. replace all fractions: '\frac{a}{1 + \frac{b}{c}}' becomes '{a}/{1 + {b}/{c}}'
  2. 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:

@ChristopherChudzicki needing to do the same. would love to take a look at what you built if you can share that project again.

All 5 comments

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:

  1. replace all fractions: '\frac{a}{1 + \frac{b}{c}}' becomes '{a}/{1 + {b}/{c}}'
  2. 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:

@Kreijstal I also needed to convert LaTeX to MathJS. For my purposes, it has been good enough to:

  1. replace all fractions: '\frac{a}{1 + \frac{b}{c}}' becomes '{a}/{1 + {b}/{c}}'
  2. 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:

@ChristopherChudzicki needing to do the same. would love to take a look at what you built if you can share that project again.

Was this page helpful?
0 / 5 - 0 ratings