Julia MathML parser
Author SciML
21 Stars
Updated Last
9 Months Ago
Started In
March 2021


Github Action CI Coverage Status ColPrac: Contributor's Guide on Collaborative Practices for Community Packages

A parser for the MathML XML standard.

Uses Symbolics.jl under the hood for defining equations and uses EzXML.jl for XML parsing.

MathML Specification:


using MathML, EzXML, Symbolics, AbstractTrees
xml = xml"""<math xmlns="">
      <times />

num = parse_node(xml)
# 1-element Vector{Num}:
#  S1*compartment*k1

# to pretty print the tree use `print_tree`
# math
# └─ apply
#    ├─ times
#    ├─ ci
#    ├─ ci
#    └─ ci

# you can also just go directly from EzXML.Document or String
str = "<apply><power/><ci>x</ci><cn>3</cn></apply>"
# x^3

# derivatives also work!
str = """
# 12(x^2)

# there is also a macro @MathML_str to directly call `parse_str`
ml = MathML"""
# 12(x^2)

Check the tests in test/parse.jl to see a more exaustive list of what is covered.


  • calculus:
    • ivars fix, make ODESystem(parse_node(readxml("lorenz.xml").root)) work
    • partial derivatives partialdiff tags
    • integration int tags - needs JuliaSymbolics/Symbolics.jl#58
      • often a var like dPidt is assigned to Differential(time)(Pi) where dPidt is refered to after this <eq> (I think solution is Symbolics.diff2term)
    • diffs with no independent variable: like <apply><diff/><ci>f</ci></apply>
  • to_mathml: julia expr -> mathml. round tripping


  • nested apply
  • fix sep/ tags in cn, take type attribute into account
    • rational, e-notation, complex, complex polar
  • basic diff handling
  • bound variables like bvar, might be lingering issues though
  • eq nodes sometimes needs to be ~ and sometimes needs to be =
  • fix sep tags in cis, take type attribute into account
  • piecewise tags: make heaviside test work
  • fix undefined namespacing issues JuliaIO/EzXML.jl#156
    • parsers like SBML and CellMLToolkit should be handling