Yuxiang Wang - 2 months ago 33

Python Question

It seems that MathML works OK with my word with simple copy and paste for strings such as

`<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mn>1</mn><mn>2</mn></mfrac></math>`

But when I try to use

`sympy`

`from sympy import S`

from sympy.printing.mathml import mathml

my_eqn = S(1) / 2

print(mathml(my_eqn))

The output is:

`<apply><divide/><cn>1</cn><cn>2</cn></apply>`

And I cannot copy and paste it into word to make it a Word equation.

Could anyone please help?

Answer

Looks like the MathML that works is presentation MathML, whereas SymPy outputs content MathML. Unsurprisingly, Word is unable to convert from content to presentation, as that requires some degree of mathematical knowledge on the part of the software.

SymPy probably ought to support outputting presentation format, but until that is implemented, you might try to find some other software that can convert between the two (I don't know of any myself, unfortunately).