Ask Your Question

Revision history [back]

Sage 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 you can do the following

  1. 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")

  1. 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'

Sage 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 you can do the following

  1. Install the mathdom module within sage: within a console do

    me@home$ sage -pip install mathdom
    me@home$ sage -pip install lxml

lxml

(As a prerequisite, I needed to install to packages into my linux distribution, namely "libxslt1-dev")

  1. 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")
    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'

  2. 6'