Expand description
§formulary
Native MathML Core layout in Rust.
Parse presentation MathML, lay it out using the font’s OpenType MATH table,
and get back a resolution-independent Layout — glyph ids and rules with
baseline metrics — that you rasterize through your own text pipeline.
No webview, no rasterization in the core, no I/O: you bring the font bytes (any font with a MATH table, e.g. STIX Two Math or New Computer Modern).
Parsing follows MathML Core’s error recovery: unknown or structurally
invalid elements render as mrow fallbacks and are reported in
MathRoot::warnings; only malformed XML is a hard error.
use formulary::{parse, layout, LayoutOptions, MathFont};
let font_data = std::fs::read("fonts/STIXTwoMath-Regular.otf").unwrap();
let font = MathFont::new(&font_data, 0).unwrap();
let tree = parse("<math><mi>x</mi><mo>+</mo><mn>2</mn></math>").unwrap();
let laid = layout(&tree, &font, &LayoutOptions { font_size: 16.0 });
assert!(laid.width > 0.0);Re-exports§
pub use ast::Color;pub use ast::DisplayMode;pub use ast::MathRoot;pub use ast::Warning;
Modules§
Structs§
- GlyphId
- A glyph index in the math font — the same 16-bit id the font’s own
tables use;
0is.notdef. - Layout
- A laid-out formula: extents plus a flat display list.
- Layout
Options - Caller-supplied layout parameters.
- Math
Font - A font validated to contain an OpenType MATH table.
Enums§
- Font
Error - Errors constructing a
MathFont. - Item
- One drawable in the display list.
- Parse
Error - Errors that prevent producing a tree at all. Everything else is recovered
from and reported via
MathRoot::warnings.