Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 980
Yuxiang Wang Avatar asked Feb 05 '23 14:02

Yuxiang Wang


1 Answers

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

like image 133
asmeurer Avatar answered Feb 08 '23 15:02

asmeurer