User Rating 0.0
Total Usage 0 times
MathML Input
24px
Transparent
20px
SVG Preview
Is this tool helpful?

Your feedback helps us improve.

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.

mathml svg converter math vector xml formula equation

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) + 2p
a = 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.6
scale = 0.7 × fontSizeparent

Glyph width estimation:

wchar fontSize × k

Where 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 ElementPurposeSVG MappingExample
miIdentifier (variable)<text> italicx, y
mnNumber<text> normal42, 3.14
moOperator<text> normal+, , =
mfracFractionStacked <text> + <line>ab
msqrtSquare root<path> radical + <line> vinculumx
mrootNth root<path> + index <text>3x
msupSuperscriptOffset <text> smallerx2
msubSubscriptOffset <text> smallerxi
msubsupSub + SuperscriptBoth offsetsxi2
mrowHorizontal groupSequential layoutGroups child elements
moverOver accentStacked abovex
munderUnder accentStacked belowLimit notation
munderoverUnder + OverBoth stackedni=0
mtableTable/MatrixGrid of <text> elementsMatrices, equation systems
mtrTable rowRow in gridUsed inside mtable
mtdTable cellCell in gridUsed inside mtr
mtextLiteral text<text> normalAnnotations, words
mspaceWhitespaceHorizontal offsetWidth attribute controls gap
mencloseEnclosure<rect> or <line>Box, strike, radical
mpaddedAdjusted spacingModified bounding boxFine-tuning layout
mfencedFenced group (deprecated)Parentheses + content(a, b)
mathRoot element<svg> rootContainer for all MathML

Frequently Asked Questions

The converter supports Presentation MathML elements: math, mi, mn, mo, mrow, mfrac, msqrt, mroot, msup, msub, msubsup, mover, munder, munderover, mtable, mtr, mtd, mtext, mspace, mpadded, menclose, and mfenced. Content MathML (apply, ci, cn) is not supported - convert it to Presentation MathML first.
Browser MathML renderers use the OpenType MATH table for precise glyph metrics, stretch variants, and kerning. This tool estimates character widths using a coefficient model where width ≈ fontSize × 0.6 for normal glyphs. For most expressions, the difference is under 2px per character. Deeply nested expressions may accumulate small layout shifts.
Yes. The SVG output uses standard elements: text, line, rect, and path. All text remains as live text elements with font-family declarations. You can open the SVG in any vector editor, reposition elements, change colors, or convert text to outlines for font-independent rendering.
Stretchy delimiters (parentheses, brackets, braces) are scaled vertically using SVG transform attributes. The converter calculates the total height of the enclosed content and applies a scaleY transform to the delimiter glyph. For very tall expressions (height exceeding 3× the base font size), the tool switches to a multi-segment path construction for braces.
The converter uses DOMParser in XML mode. Malformed XML produces a parsererror element in the DOM tree, which the tool detects and reports as a specific error message indicating the line and nature of the problem. Missing namespace declarations are handled by attempting both with and without the MathML namespace URI (http://www.w3.org/1998/Math/MathML).
The converter defaults to a serif font stack (Times New Roman, STIX Two Math, Latin Modern Math, serif) which matches traditional mathematical typesetting. If the user's system lacks these fonts, the SVG will render with the browser's default serif, which may alter spacing. For guaranteed portability, convert text to paths in a vector editor after export.