cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
375 stars 47 forks source link

MathML or other output formats #91

Closed Theratherverydarkestlordever closed 1 year ago

Theratherverydarkestlordever commented 1 year ago

I am currently working on a project where I use CortexJS as styled html math input and compute stuff on a server with sympy, as it has physics capabilities. Unfortunately, interaction between the two systems is hard as sympy does not support MathJSON. I can parse the Latex string into a sympy expression, but this is an experimental feature as Latex is not a typical transfer format.

Although I like MathJSON a lot more, I would really appreciate MathML output, which is more common. Alternatively, I could also work with a human readable string that contains e.g. "*" instead of "\cdot".

stefnotch commented 1 year ago

Hi, I did something like that once!

https://github.com/stefnotch/quantum-sheet/

Basically, I came to the conclusion that MathJSON is indeed what one wants, since it's a usable syntax tree that can reasonably be turned into sympy commands. Feel free to either check out the source code above, or to ask me about it. I'd also be available on Discord or other platform.

I would not recommend MathML, since Sympy doesn't understand it, and MathML is frequently missing a lot of crucial information. (Like the order of operations does not have to be included in MathML.)

LaTeX is, as you noticed, also not the right format.

rs-mobitech commented 1 year ago

Sounds like @stefnotch , has a good solution. But just in case, @Theratherverydarkestlordever Have you checked out mf.getValue('math-ml');

rs-mobitech commented 1 year ago

@Theratherverydarkestlordever "I can parse the Latex string into a sympy expression, but this is an experimental feature as Latex"

I wasn't aware this was experimental. Do you have a link where it talks about that?

stefnotch commented 1 year ago

@rs-mobitech Here you go, https://docs.sympy.org/latest/modules/parsing.html#mathrm-latex-parsing-caveats

arnog commented 1 year ago

The Compute Engine is unlikely to support formats other than LaTeX and MathJSON.

I suggest focusing on conversion solutions from these formats to others.

For example, the MathLive library does include a conversion utility from LaTeX to MathML: convertLatexToMathMl()