Cory
Cory

Reputation: 15605

How to convert Javascript's math functions to a math equation?

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

Answers (2)

Jos de Jong
Jos de Jong

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

M. Page
M. Page

Reputation: 2814

I don't think there exists a turnkey library for this, but it is not so hard to do what you want.

  1. You can use an existing arithmetic expression parser: http://ariya.ofilabs.com/2011/08/math-evaluator-in-javascript-part1.html

  2. You generate from the parse tree MathML code :http://fr.wikipedia.org/wiki/MathML

  3. then there exist tools for viewing MathML like Mathjax: http://www.mathjax.org/

Upvotes: 0

Related Questions