ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 02 Jan 2016 18:38:07 -0600Parse and Evaluate MathMLhttps://ask.sagemath.org/question/8097/parse-and-evaluate-mathml/Is there a possibility to parse content-mathml in Sage?
I would like to evaluate a formula that is given in a content-mathml document. How would I do this?Fri, 29 Apr 2011 02:32:37 -0500https://ask.sagemath.org/question/8097/parse-and-evaluate-mathml/Answer by vdelecroix for <p>Is there a possibility to parse content-mathml in Sage? </p>
<p>I would like to evaluate a formula that is given in a content-mathml document. How would I do this?</p>
https://ask.sagemath.org/question/8097/parse-and-evaluate-mathml/?answer=31997#post-id-31997Sage is based on Python which implies that any Python module is (in principle) usable from Sage. As there are modules to deal with mathml content in Python (such as [mathdom](http://mathdom.sourceforge.net/) you can do the following
Install the mathdom module within sage: within a console do
me@home$ sage -pip install mathdom
me@home$ sage -pip install lxml
(As a prerequisite, I needed to install to packages into my linux distribution, namely "libxslt1-dev")
Then, launch sage and use mathdom (the example is taken from mathdom website)
me@home$ sage
sage: from mathml.lmathdom import MathDOM
sage: doc = MathDOM.fromString("+2^x+4*-5i/6","infix_term")
sage: for apply_tag in doc.xpath(u'//math:apply[math:plus]'):
....: apply_tag.set_operator(u'minus')
sage: [ n.value() for n in doc.xpath(u'//math:cn') ]
[2, 4, Complex(0-5j), 6]
sage: from mathml.utils import pyterm
sage: doc.serialize("python")
u'2 ** x - 4 * (-5j) / 6'Sat, 02 Jan 2016 18:38:07 -0600https://ask.sagemath.org/question/8097/parse-and-evaluate-mathml/?answer=31997#post-id-31997