Skip to main content

Module mathml

Module mathml 

Source
Expand description

Node-tree → MathML Core serializer.

Deterministic: attribute order is fixed per element, every element has an explicit close tag (no self-closing form), and text/attr values are XML escaped. The walk never panics; a hostile or fragment tree still yields a well-formed fragment.

Functions§

mathml_well_formed
Std-only well-formedness check: balanced tags, quoted attributes, escaped text. Accepts the serializer’s output contract (no self-closing tags).
to_mathml
Serialize node as a complete <math>…</math> fragment.
to_mathml_element
Serialize node as a MathML element (no outer <math> wrapper).
to_mathml_with_capacity
to_mathml with a TeX-source-length hint used only to presize the output buffer (MATHML_CAPACITY_FLOOR + tex_len * MATHML_BYTES_PER_TEX_BYTE bytes, so the serializer does not walk the realloc-doubling chain for typical formulas). The emitted bytes are identical to to_mathml for every (node, display, tex_len) — buffer capacity is never observable in the output.