Reputation: 15605
How to generates MathJax formula from JavaScript's math functions? It doesn't need to evaluate the math equation, it just converts the string to a math equation for viewing purpose.
Example the following string Math.pow(2,3)
outputs to 22
Upvotes: 0
Views: 2020
Reputation: 6809
You could use math.js to parse an expression and convert it to Tex, which can be used to render a MathJax equation.
Here is an online example: http://mathjs.org/examples/browser/pretty_printing_with_mathjax.html
Upvotes: 1
Reputation: 2814
I don't think there exists a turnkey library for this, but it is not so hard to do what you want.
You can use an existing arithmetic expression parser: http://ariya.ofilabs.com/2011/08/math-evaluator-in-javascript-part1.html
You generate from the parse tree MathML code :http://fr.wikipedia.org/wiki/MathML
then there exist tools for viewing MathML like Mathjax: http://www.mathjax.org/
Upvotes: 0