Replies: 2 comments 1 reply
-
@GeO95 Your question is really a PHP question, not a KaTeX one. Your process could be something like:
Alternatively, if you want to do it in javascript, you could make use of MathJS https://mathjs.org/ which does a reasonable job of comparing math expressions. This may be the better solution (since it's already 'built-in', if I understand correctly) for handling the equivalence of things like polynomials written in a different order, but still correct, like x^3 - 5x^2 + x + 4 and 4 + x - 5x^2 + x^3 Hope it helps |
Beta Was this translation helpful? Give feedback.
-
Do you really need your students to learn LaTeX? If so, then ignore the following. But if not, this is how I would proceed. MathJS uses input very similar (identical in many cases) to ASCIIMath ( http://asciimath.org/ ) and can output LaTeX ( https://mathjs.org/docs/expressions/customization.html#custom-html-latex-and-string-output ). If your students entered their answers using MathJS input, and your database also had MathJS-type input to compare it against, then you could compare the 2 using MathJS and then possibly output both versions to LaTeX ready for KaTeX's pretty math. To give you an idea what I'm talking about, the input box (on the left) of the following page accepts ASCIIMath, and the script outputs LaTeX (ASCIIMath produces LaTeX output) and from there it is processed by KaTeX: https://www.intmath.com/help/asciimath-input-latex-katex-output.php Your page could have some of the same things going on in the background. Alternatively (since your original question was how to compare things using PHP), there are some PHP math libraries that appear to do some of the same things as MathJS does in terms of algebraic manipulation with various functions. Here's one: https://github.com/markrogoyski/math-php |
Beta Was this translation helpful? Give feedback.
-
Hi, I’m using your library so my users can write in latex, thanks. Then I would would like to compare the latex string to an expression I have in my database. So I need to parse it in php to be able to properly compare (evaluate the expression). Has anyone ever done that in PHP? Thanks
Beta Was this translation helpful? Give feedback.
All reactions