MathML to SVG Converter
Convert MathML markup to scalable SVG images online. Paste MathML code, get clean vector graphics with instant preview and download.
About
MathML is a W3C standard for encoding mathematical notation in XML. Browsers have inconsistent rendering support. Firefox implements full MathML rendering. Chrome and Safari offer partial support. If you embed raw MathML into a webpage or document, the output varies across platforms. Converting MathML to SVG produces a deterministic, resolution-independent vector graphic that renders identically everywhere. This tool parses MathML elements - mfrac, msqrt, msup, msub, mover, munder, mtable - and computes a two-pass layout: measurement pass for bounding boxes, then a positioning pass that emits SVG text and path elements.
Limitation: this tool approximates glyph metrics using a monospace-proportional model. Ligatures and complex OpenType math table features (like stretch variants for large delimiters) are simplified. For most algebraic, calculus, and linear algebra expressions, output fidelity is high. For extremely dense notation with deeply nested radicals inside matrices, manual SVG adjustment may be needed. Pro tip: keep your MathML well-formed. A missing closing tag will produce a parse error, not a silent misrender.
Formulas
The converter implements a recursive descent layout algorithm. Each MathML node produces a bounding box with three metrics: w (width), a (ascent above baseline), and d (descent below baseline). Total height is h = a + d.
Fraction layout (mfrac):
w = max(wnum, wden) + 2pa = anum + dnum + g + t
d = aden + dden + g
Where p = horizontal padding, g = gap between fraction bar and content, t = fraction bar thickness (1px default).
Superscript offset (msup):
shift = abase × 0.6scale = 0.7 × fontSizeparent
Glyph width estimation:
wchar ≈ fontSize × kWhere k = 0.6 for normal glyphs, 0.62 for italic, 1.0 for wide operators like ∑.
The converter uses a hidden SVG measurement element with getComputedTextLength() for precise width calculation when available, falling back to the coefficient model above.
Reference Data
| MathML Element | Purpose | SVG Mapping | Example |
|---|---|---|---|
| mi | Identifier (variable) | <text> italic | x, y |
| mn | Number | <text> normal | 42, 3.14 |
| mo | Operator | <text> normal | +, −, = |
| mfrac | Fraction | Stacked <text> + <line> | ab |
| msqrt | Square root | <path> radical + <line> vinculum | √x |
| mroot | Nth root | <path> + index <text> | 3√x |
| msup | Superscript | Offset <text> smaller | x2 |
| msub | Subscript | Offset <text> smaller | xi |
| msubsup | Sub + Superscript | Both offsets | xi2 |
| mrow | Horizontal group | Sequential layout | Groups child elements |
| mover | Over accent | Stacked above | |
| munder | Under accent | Stacked below | Limit notation |
| munderover | Under + Over | Both stacked | n∑i=0 |
| mtable | Table/Matrix | Grid of <text> elements | Matrices, equation systems |
| mtr | Table row | Row in grid | Used inside mtable |
| mtd | Table cell | Cell in grid | Used inside mtr |
| mtext | Literal text | <text> normal | Annotations, words |
| mspace | Whitespace | Horizontal offset | Width attribute controls gap |
| menclose | Enclosure | <rect> or <line> | Box, strike, radical |
| mpadded | Adjusted spacing | Modified bounding box | Fine-tuning layout |
| mfenced | Fenced group (deprecated) | Parentheses + content | (a, b) |
| math | Root element | <svg> root | Container for all MathML |