Yuxiang Wang Yuxiang Wang - 3 months ago 37
Python Question

Output sympy equation to word using mathml

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
's mathml printer:

from sympy import S
from sympy.printing.mathml import mathml
my_eqn = S(1) / 2

The output is:


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

Could anyone please help?


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).