使用mathml输出sympy方程式

时间:2016-12-01 21:57:48

标签: python scipy sympy mathml

似乎MathML可以正常工作,只需简单的复制和粘贴字符串,例如

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

但是当我尝试使用sympy的mathml打印机时:

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

输出结果为:

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

我无法将其复制并粘贴到word中,使其成为Word等式。

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:4)

看起来有效的MathML是presentation MathML,而SymPy输出content MathML。不出所料,Word无法从内容转换为演示文稿,因为这需要软件方面的某种程度的数学知识。

SymPy probably ought to support输出演示文稿格式,但在实施之前,您可能会尝试找到一些可以在两者之间进行转换的其他软件(遗憾的是,我自己也不知道)。

答案 1 :(得分:3)

SymPy supports presentation MathML now。为此,您可以使用arg printer="presentation"

mathml(expr, printer="presentation")

您应该将输出放在<math>标记内:

<math xmlns = "http://www.w3.org/1998/Math/MathML">
</math>
相关问题