Math
TeX formulas rendered as native MathML: no font CSS, readable by screen readers, safe for untrusted input.
c2-math turns TeX into MathML with Temml. The browser lays the formula out with the system math font and exposes it to screen readers as math, so there are no font files or layout CSS to ship. Put the TeX in value or in the element’s text; wrap it in a <script type="math/tex"> so the browser does not parse it. Add display for a centred block formula. A display formula wider than its container scrolls instead of overflowing.
The input is treated as untrusted, so the component is safe for model output:
- Commands that would produce links, images, classes, ids or styles (
\href,\url,\includegraphics,\style,\class) are rejected. - Macro expansion and sizes are capped.
- The MathML is built as DOM nodes, never parsed from a string.
A formula that does not parse shows its source in the error style and fires math-error. Copying a whole formula puts its TeX on the clipboard as text and its MathML as HTML. Set page-wide macros once with configureMath({ macros }), or per element with the macros property.
Import
import '@c2n/components/math'Usage
A circle of radius rA = \pi r^2ax^2 + bx + cx = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}\begin{aligned} A &= \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \\ \det A &= 1 \cdot 4 - 2 \cdot 3 = -2 \end{aligned}\frac{1}{Page-wide macros:
import { configureMath } from '@c2n/components/math'
configureMath({ macros: { '\\\\RR': '\\\\mathbb{R}', '\\\\E': '\\\\operatorname{\\\\mathbb{E}}' } })