Conversation
Numbers and units were always typeset via a math.equation, so they inherited the math font even in documents set in a different body font, creating a visible mismatch with surrounding prose (siunitx has supported this via `mode = text` in LaTeX for a long time). Add a `mode: "math" | "text"` parameter to num, unit, qty, numrange, and qtyrange (default "math", fully backward compatible). In "text" mode, a `show math.text: set text(font: text.font, weight: text.weight)` rule restyles only the literal glyphs to the current document font and weight, while the math font still handles layout (superscripts, fractions, stretchy parentheses), so positioning stays correct and bold/emph contexts are inherited automatically. Unit symbols deliberately stay upright even in italic text, matching SI convention. Adds a _display-math helper in format.typ shared by all five public functions, and documents the feature in the README and example file.
|
Here are some backward compatibility issues I’ve found updating a document to this version:
I’d also like to suggest being able to use |
Thank you for testing the new rewrite!
|
|
I only used As for the |
Summary
This PR completely rewrites the core execution logic in Rust compiled to a Wasm plugin (
wasm32-unknown-unknown).The previous Typst-native implementation became increasingly difficult to maintain and extend, particularly due to complex, fragile regex patterns used for number parsing. The new architecture splits the processing pipeline into clean, explicit phases: Lexer → Parser → Typst Generator.
This also enables the solution to many long-standing issues with this package.
Key Improvements & Architecture
Performance & Memory
phf(Perfect Hash Function) maps generated at build time (build.rs). This eliminates runtime file I/O and dynamic parsing overhead, drastically speeding up unit evaluation.Modular Parsing Pipeline
New Features & API Changes
exponent-modeandunit-mode(e.g., controlling behavior for(2 to 4) °Cvs2 °C to 4 °C)."2.123(45)") (credit to @catlop, who already introduced it in the Typst version in Add parentheses notation for symmetric uncertainties #74).#update-num-config,#update-qty-config, etc.) to set workspace-wide defaults without repeating arguments across individual function calls.sqrt):sqrt(m)).sqrt(m^3)work as expected, but combinations likesqrt(m)^3are not yet supported and will fail parsing.Work in Progress & Known Limitations
Resultreturns in Wasm, but error diagnostic formatting is not yet fully optimal.Testing Strategy
Since this is a major architectural rewrite, testing is critical before merging into
main: