formel
A Rust library that lays out mathematical formulas using OpenType MATH fonts and rustybuzz for unicode shaping. It implements the typesetting rules from the OpenType MATH specification and MathML Core: script and fraction placement, stretchy operators, radicals, tables, accents, italic corrections, math kerning and more, comparable in quality to modern unicode TeX engines, like LuaTeX and XeTeX. The output, i.e. the glyph positions and sizes, can be directly consumed by users of the rust library. A simple SVG renderer is provided, too.
Try it in the browser → Type LaTeX or MathML, compare the
bundled fonts (or drop in your own), and copy or download the result as SVG or PNG. The demo is this crate
compiled to WebAssembly (formel-wasm/, web/), resulting in a small WebAssembly bundle of ~1 MB.
Gallery
Any math font that is compatible with LuaTeX or XeTeX (or MS Word) can be used with formel.
Fractions, radicals & continued fractions
For comparison, the same formula as LaTeX, rendered live by GitHub (MathJax) in your browser:
$$ x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}, \qquad \varphi = 1 + \cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{1 + \dots}}} $$
x=
−b±
b2−4ac
2a
,
φ=
1+
11+11+11+…
Big operators with limits, integrals
Display-style ∑ is enlarged and gets under/over limits, while ∫ takes its limits as scripts and is italic-corrected.
For comparison, the same formula as LaTeX, rendered live by GitHub (MathJax) in your browser:
$$ \sum_{n=1}{\infty} \frac{1}{n2} = \frac{\pi2}{6}, \qquad \int_{-\infty}{\infty} e{-x2},dx = \sqrt{\pi} $$
∑n=1∞
1n2
=
π26
,
∫−∞∞
e−x2
dx
=
π
Stretchy operators & bold vectors
Contour and surface integrals with the correct glyph variants, plus bold math alphanumerics.
For comparison, the same formula as LaTeX, rendered live by GitHub (MathJax) in your browser:
$$ \oint_{\partial S} \mathbf{F}\cdot d\mathbf{s} = \iint_S \nabla\times\mathbf{F}\cdot d\mathbf{s} $$
∮∂S
F⋅ds
=
∬S
∇×F⋅ds
Tables, stretchy delimiters & cases
mtable layout with ellipsis glyphs; parentheses and braces stretch to the height of the content via glyph variants and assemblies.
For comparison, the same formula as LaTeX, rendered live by GitHub (MathJax) in your browser:
$$ A = \begin{pmatrix} a_{11} & \cdots & a_{1n} \ \vdots & \ddots & \vdots \ a_{m1} & \cdots & a_{mn} \end{pmatrix}, \qquad |x| = \begin{cases} x & \text{if } x \ge 0 \ -x & \text{if } x < 0 \end{cases} $$
A=
(
a11…a1n
⋮⋱⋮
am1…amn
)
,
|x|=
{
xif x≥0
−xif x<0
Fractions, brackets, accents
Quantum-mechanics notation: stretchy brackets and bras/kets, ħ, a wide-hat accent, and the Laplacian.
For comparison, the same formula as LaTeX, rendered live by GitHub (MathJax) in your browser:
$$ i\hbar\frac{\partial}{\partial t}\Psi = \left[-\frac{\hbar2}{2m}\nabla2 + V\right]\Psi, \qquad Z = \langle\psi|,e^{-\beta\hat H},|\psi\rangle $$
iℏ
∂∂t
Ψ=
[
−
ℏ22m
∇2+V
]
Ψ
,
Z=
⟨ψ|e−βĤ|ψ⟩
Prescripts (mmultiscripts)
Stacked pre-super/subscripts as used for isotopes and tensor indices.
For comparison, the same formula as LaTeX, rendered live by GitHub (MathJax) in your browser:
$$ {}{235}_{;,92}\mathrm{U} + n \to {}{141}{;,56}\mathrm{Ba} + {}^{92}{;,36}\mathrm{Kr} + 3n, \qquad {}{\alpha}_{\beta}\Lambda{\mu}_{\nu} $$
U92235+n→Ba56141+Kr3692+3n,Λνμβα
License
See LICENSE.