I use Python's Sympy
module.
The Sympy module has a library called sympy.printing.mathml
, which converts formulas into mathml
.
However, I could not convert Greek letters such as α and β to mathml.
How can I solve this problem if I want to insert Greek letters into the formula?
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
I want to get mathml like example2 from python's formula like example1.
example1
S=abs(a)*(β-α)^3/6
example2
<math><mi>S</mi><mo>=</mo><mstyle displaystyle='true'><mfrac><mrow><mo>|</mo><mi>a</mi><mo>|</mo><mo>⁡<!--FUNCTION APPLICATION--></mo><mo>(</mo><mo>β</mo><mo>-</mo><mo>α</mo><msup><mo>)</mo><mn>3</mn></msup></mrow><mrow><mn>6</mn></mrow></mfrac></mstyle></math>
I executed the following code.
from sympy import *
from sympy.printing.mathml import mathml
print(mathml(S=abs(a)*(β-α)^3/6,printer='presentation'))
In a terminal that supported copy/paste of Greek characters, I was able to create a variable with Greek name, e.g. beta = Symbol('beta')
where beta
was a literal Greek character. The output of the formula you gave -- using **
instead of ^
is identical to the code generated when the symbols for alpha and beta are imported from abc:
>>> from sympy.abc import alpha, beta
>>> print(mathml(abs(a)*(beta-alpha)**3/6, printer='presentation'))
<mrow><mfrac><mrow><msup><mfenced><mrow><mrow><mo>-</mo><mi>α</
o>+</mo><mi>β</mi></mrow></mfenced><mn>3</mn></msup><mo>&Invisi
o><mrow><mfenced close="|" open="|"><mi>a</mi></mfenced></mrow></mro
</mfrac></mrow>