Skip to main content

Crate leaf_math

Crate leaf_math 

Source
Expand description

TeX math, typeset to a picture leaf’s frontends already know how to draw.

One function: typeset takes the text between a formula’s delimiters and hands back a standalone SVG document plus the three numbers a frontend needs to place it — width, height above the baseline, and depth below it, in em. A display formula needs only the first two to size its box; an inline one needs all three, because it sits in a line and the text baseline has to pass through it at height from the top.

The SVG is self-contained: every glyph is a <path> with KaTeX’s own outlines embedded at build time, so the picture is byte-identical on every frontend and no font has to be found at runtime. Colour is an input, so a theme change is a re-render; the render is pure layout over embedded fonts — no I/O, and fast enough to run on a layout thread. Callers cache by (tex, display, size, colour).

Nothing here is leaf’s: it is RaTeX with leaf’s conventions on the door (pixels rather than points, a colour as four bytes, an error that names a byte). If it grows a consumer outside leaf it moves out, the way resvg-swift did.

Structs§

MathError
TeX the typesetter could not read. position is a byte offset into the formula’s text where the parser gave up, when it can say — so a frontend can show the revealed source with the fault marked, rather than a blank box.
MathPicture
A typeset formula: the picture and where its baseline is.

Functions§

typeset
Typeset tex — the text between the delimiters, $…$ and $$…$$ alike stripped — as a picture.