viktorstrate / algebra-latex

Parse and calculate latex formatted math
https://www.npmjs.com/package/algebra-latex
MIT License
28 stars 9 forks source link

Reverse functions #1

Closed Benjadahl closed 5 years ago

Benjadahl commented 7 years ago

Do you reckon it would be possible, to reverse the functions so that you could go from plain text string math, to latex? Would be greatly appreciated if possible :)

viktorstrate commented 7 years ago

I think it's a great idea, and if I find the time, I will implement it. (You are of course welcome to send a PR, if you want)

In the mean time, algebra.js has a .toTex() function that could help you, but that means that you'll have to parse it to a algebra.js object first.

 new algebra.parse("2 * 3x / 43 + 3").toTex() // "\frac{6}{43}x + 3"

But algebra.js will automatically try to solve the equation, and you can't divide by variables, (nicolewhite/algebra.js#73).

viktorstrate commented 5 years ago

@Benjadahl I have implemented this now! 😄 It is described in more details in the readme.

new AlgebraLatex().parseLatex('\\frac{1}{\\sqrt{2}}').toMath() // 1/sqrt(2)