Skip to main content

Module math

Module math 

Source
Expand description

GridCraft equations. LaTeX source is laid out by RaTeX (ratex-parser, ratex-layout; MIT) into a MathList: plain glyph, rule and path data that the UI and the PDF writer paint without calling RaTeX again.

RaTeX is young (0.1.x), so it only ever runs inside this crate’s entry points (layout, to_omml, check). Each one caps its input (4 KB, nesting 32) and runs under catch_unwind, so a stray panic becomes a MathError. See the RaTeX gate in docs/decisions.md and tests/gate.rs.

Units are em: one em is the equation’s font size. Coordinates run right and down from the top-left of the list’s box; the baseline is at y = height.

Structs§

Glyph
One character.
MathError
Why an equation could not be laid out.
MathList
A laid-out equation.
Path
A vector outline (stretchy braces, arrows, radicals), relative to (x, y).
Rule
A filled rectangle (fraction bars, radical vinculums, table rules, box borders).

Enums§

Face
The typeface a glyph asks for. Painters map it onto the fonts they have.
Item
PathCmd

Constants§

GALLERY
The equation gallery (Insert › Equation): GridCraft’s own examples, as (name, LaTeX).
MAX_DEPTH
Deepest nesting of {…}, \left…\right and \begin…\end accepted.
MAX_EM
Largest coordinate or size accepted in a layout, in em. \rule{1e308em}{1em} lays out; this stops it from reaching a painter.
MAX_ITEMS
Most items one equation may produce.
MAX_SOURCE_BYTES
Longest source accepted, in bytes.

Statics§

SOURCE_TOO_LONG
The error for a source over MAX_SOURCE_BYTES. It is one shared value so that a cache can answer for such a source by its length alone, without reading it.

Functions§

check
Whether latex parses, without laying it out (cheap enough to run on every keystroke).
layout
Lays latex out. Errors carry the offending span when RaTeX reports one.
to_omml
latex as an <m:oMath> element (prefix m for the OMML namespace and a for DrawingML, declared by the caller), with runs at size_pt points in the ink colour (none: the paragraph’s own).