You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This small python module exports a single function, parse(), which parses a
string containing ASCIIMathML and returns the corresponding
MathML tree as an xml.etree.ElementTree instance.
Also included is a python-markdown extension that translates
text enclosed between $$ into MathML.
Example usage
The function parse() generates a tree of elements:
>>> import asciimathml
>>> asciimathml.parse('sqrt 2')
<Element math at b76fb28c>
The tree can then be manipulated using the standard python library. For
example we can generate its string representation:
>>> from xml.etree.ElementTree import tostring
>>> tostring(asciimathml.parse('sqrt 2'))
'<math><mstyle><msqrt><mn>2</mn></msqrt></mstyle></math>'
Or, if you want to add the attributes title and xmlns to the root node:
Tested with python 2.7 and python 3.4. The core module, asciimathml has no dependencies.
The markdown extension mdx_asciimathml requires at least markdown 2.0.
A standard setup.py is provided (as usual it's enough to execute python setup.py install to perform the installation). You can also manually copy the
two files asciimathml.py and (optionally) mdx_asciimathml.py somewhere in
your PYTHONPATH.
Browser support
The current status of support for MathML by web browsers is disheartening.
Only Firefox and Safari, among the major browsers, can properly
render MathML (webkit support is on the way, you can follow progress made
closing the tickets of this master bug).
Also note that MathML is displayed correctly only when embedded in a
XHTML or in HTML5 document.
About
python ASCIIMathML to Presentation MathML translator