Reputation: 10393
I would like to be able to convert a python mathematical expression into content MathML using Python. The goal would be to turn an expression like (a*x^2 + b*x + c)/(2*a) into the content MathML example in the Wikipedia article on MathML.
The asciimathml package will generate display MathML, but as far as I can tell, not content MathML.
I have not been able to google up an existing package, or even suggestions for how to do it.
Thanks in advance...
Upvotes: 2
Views: 2727
Reputation: 176930
MathDOM: http://mathdom.sourceforge.net/
Does exactly what you want. Quoting the page:
MathDOM is a set of Python 2.4 modules (using PyXML or lxml, and pyparsing) that import mathematical terms as a Content MathML DOM. It currently parses MathML and literal infix terms into a DOM or lxml document and writes out MathML and literal infix/prefix/postfix/Python terms. The DOM elements are enhanced by domain specific methods that make using the DOM a little easier. Input parsers and output converters are easily extensible.
Newer versions simplify the portability of code between the PyXML and lxml versions. They also extend the latter with an XSLT-based output filter for Presentational MathML and RelaxNG-based document validation. PyXML does not support any of these.
Edit: Found here. http://www.w3.org/Math/Software/mathml_software_cat_converters.html#Imathdom
Upvotes: 2