Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- sys.path.append('/home/vagrant/.local/lib/python3.4/site-packages')
- from sympy import *
- from sympy.printing.mathml import mathml
- def returnMathML(value):
- str = "<math>"
- if '=' in value:#文字列中に=(イコール)が含まれている場合
- str += mathml(Eq(*map(sympify, value.split('='))),printer='presentation')
- else:
- str += mathml(sympify(value),printer='presentation')
- str += "</math>"
- return str
- print(returnMathML("A"))
- <math><mi>A</mi></math>
- print(returnMathML("y=a*x**2+b*x+c"))
- $ python test001.py
- <math><mrow><mi>y</mi><mo>=</mo><mrow><mrow><mi>a</mi><mo>⁢</mo><msup><mi>x</mi><mn>2</mn></msup></mrow><mo>+</mo><mrow><mi>b</mi><mo>⁢</mo><mi>x</mi></mrow><mo>+</mo><mi>c</mi></mrow></mrow></math>
- print(returnMathML("S"))
- $ python test001.py
- Traceback (most recent call last):
- File "test001.py", line 15, in <module>
- print(returnMathML("S"))
- File "test001.py", line 11, in returnMathML
- str += mathml(sympify(value),printer='presentation')
- File "/home/vagrant/.pyenv/versions/3.6.7/lib/python3.6/site-packages/sympy/printing/mathml.py", line 1904, in mathml
- return MathMLPresentationPrinter(settings).doprint(expr)
- File "/home/vagrant/.pyenv/versions/3.6.7/lib/python3.6/site-packages/sympy/printing/mathml.py", line 68, in doprint
- unistr = mathML.toxml()
- AttributeError: 'str' object has no attribute 'toxml'
- print(returnMathML("S=abs(a)*(β-α)**3/6"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement