https://github.com/sciml/mathml.jl
Julia MathML parser
https://github.com/sciml/mathml.jl
Last synced: 6 months ago
JSON representation
Julia MathML parser
- Host: GitHub
- URL: https://github.com/sciml/mathml.jl
- Owner: SciML
- License: mit
- Created: 2021-03-09T20:30:10.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-12-30T19:52:36.000Z (7 months ago)
- Last Synced: 2026-01-01T13:06:19.692Z (7 months ago)
- Language: Julia
- Size: 271 KB
- Stars: 26
- Watchers: 4
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MathML
[](https://github.com/SciML/MathML.jl/actions)
[](https://coveralls.io/github/SciML/MathML.jl?branch=main)
[](https://SciML.github.io/MathML.jl/stable)
[](https://SciML.github.io/MathML.jl/dev)
[](https://github.com/SciML/ColPrac)
A parser for the [MathML](https://en.wikipedia.org/wiki/MathML) XML standard.
Uses Symbolics.jl under the hood for defining equations and uses EzXML.jl for XML parsing.
MathML Specification: https://www.w3.org/TR/MathML3/
## Examples:
```julia
using MathML, EzXML, Symbolics, AbstractTrees
xml = xml"""
compartment
k1
S1
"""
num = parse_node(xml)
# 1-element Vector{Num}:
# S1*compartment*k1
# to pretty print the tree use `print_tree`
print_tree(xml)
# math
# └─ apply
# ├─ times
# ├─ ci
# ├─ ci
# └─ ci
# you can also just go directly from EzXML.Document or String
str = "x3"
MathML.parse_str(str)
# x^3
# derivatives also work!
str = """
x2
x4
"""
expand_derivatives(MathML.parse_str(str))
# 12(x^2)
# there is also a macro @MathML_str to directly call `parse_str`
ml = MathML"""
x2
x4
"""
expand_derivatives(ml)
# 12(x^2)
```
Check the tests in `test/parse.jl` to see a more exhaustive list of what is covered.
## TODO:
* calculus:
- ivars fix, make ODESystem(parse_node(readxml("lorenz.xml").root)) work
- partial derivatives `partialdiff` tags
- integration `int` tags - needs https://github.com/JuliaSymbolics/Symbolics.jl/issues/58
- often a var like dPidt is assigned to Differential(time)(Pi) where dPidt is referred to after this \ (I think solution is `Symbolics.diff2term`)
- `diff`s with no independent variable: like `f`
## DONE:
* 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 `ci`s, take `type` attribute into account
* `piecewise` tags: make heaviside test work
* fix undefined namespacing issues https://github.com/JuliaIO/EzXML.jl/issues/156
- parsets like SBML and CellMLToolkit should be handling
* to_mathml: julia expr -> mathml and Symbolics Num -> mathml. round tripping