Closed pansitwattana closed 5 years ago
The function parser, hasn't been removed? Last commit fixed a bug, it didn't change anything.
I mean parsing function(sin, cos, tan, and etc..). I can't parse latex with that eg. \sin(0.5) or \sqrt(x)
@pansitwattana: Are you sure you are running the latest version (0.5.3)? The following code:
const AlgebraLatex = require('algebra-latex')
const latex = '\\sin 0.7 + \\tan{32*4x} - \\sqrt {33} + \\cos (8)'
const algebra = new AlgebraLatex(latex)
console.log(algebra.toMath())
Returns
sin(0.7)+tan(32*4*x)-sqrt(33)+cos(8)
If your latex is correct, and you are using the latest version, please post a snippet that doesn't work
Thanks for replying. I'm running with the latest version
In my case, I use function toAlgebra(algebraJS)
then I got result like this 128tanx + 7/10sin - 33sqrt + 8cos
Here my full code.
const algebraObj = new AlgebraLatex('\\sin 0.7 + \\tan{32*4x} - \\sqrt {33} + \\cos (8)')
let result = algebraObj.toAlgebra(algebraJS)
console.log(result.toString())
but I tried function toMath()
then It worked. I wonder why 2 function get different results.
Ah okay, that's because Algebra.js doesn't support functions, so when algebra.js's parser tries to parse the math, it thinks that the functions are variables.
If you're not planning to use equations, and only expressions, then you can use mathjs, it supports functions.
Here is an example of how you might do this.
const AlgebraLatex = require('algebra-latex')
const math = require('mathjs')
const latex = '\\sin 0.7 + \\tan{32*4} - \\sqrt {33x} + \\cos (8)'
const algebra = new AlgebraLatex(latex)
const result = math.simplify(algebra.toMath())
console.log(result.toString()) // "-0.5418972380037778 - sqrt(33 * x)"
console.log(result.toTex()) // "-0.5418972380037778-\sqrt{33\cdot x}"
See this page for more information about algebra in mathjs.
Do you have plan to support int function eg. \int_3^5x^2dx
Maybe, as I know. Only Algebrite supports integrals, but maybe I will add support for integrals for that library in the future. You are welcome to send a pull request, if you want.
When it will be fixed?