Expand description
A Rust port of the KaTeX parser: lexes and parses LaTeX math expressions
with macro expansion into a typed ParseNode AST, and renders that AST
to Unicode text.
The parser mirrors the MoonBit katex-parser package (itself a port of
KaTeX). Entry points:
parse/parse_with_specs— parse LaTeX into aParseNodelist.render— render a parsed node list as Unicode text.Settings— parser configuration (display mode, macros, strictness, trust policy, and a persistent macro store).
Structs§
- Array
Environment Options - Options controlling how an array environment is parsed.
- Block
- A 2D text block where every line has equal width. Supports vertical stacking, horizontal juxtaposition with baseline alignment, and delimiter wrapping — building blocks for block-mode Unicode rendering of matrices, fractions, delimited expressions, etc.
- Diagnostic
- Diagnostic information attached to an offending token.
- Environment
Context - Per-environment-call context: static data about the environment.
- Environment
Registry - A map from environment names to their specs.
- Environment
Spec - The declaration of an environment (name, arguments, handler).
- Function
Context - Per-function-call context: static data about the function being parsed.
- Function
Registry - A map from function names to their specs.
- Function
Spec - The declaration of a function (name, arguments, handler).
- Macro
Expansion - A macro expansion with its argument count and delimiters.
- Macros
- A persistent macro store shared across parses.
- Measurement
- A dimension with a numeric value and a unit (e.g.
em,pt). - Render
Config - Configuration for the Unicode renderer.
- Settings
- Parser configuration: display mode, macros, strictness, trust, and limits.
- Source
Location - A span of the original input.
start/endare char offsets intoinput. - Spacable
Item - A renderable atom with its math class and baseline info.
- Spacing
Spec - Concrete space representations for a rendering backend. Different backends (unicode text, HTML/CSS, LaTeX) provide their own spec.
- Token
- A lexed or macro-expanded token.
Enums§
- ArgType
- How a function argument should be parsed.
- Array
Column - A column of an array environment: an alignment cell or a vertical separator.
- Atom
Family - The math atom class of a symbol, used for spacing decisions.
- Column
Separation Type - How columns of an array are separated.
- LapAlignment
- Horizontal alignment of a
Lap(mathllap/mathrlap/mathclap) node. - Line
Style - Glyph style for drawn lines: fraction bars, boxes, tables, etc.
- Macro
Definition - A macro body: raw text or a pre-expanded token list.
- Mode
- The parsing mode: math or text.
- Operator
Content - The body of an
Opnode: a symbol, a named operator, or an argument body. - Parse
Error - A parse failure, mirroring MoonBit’s
ParseFailuresuberror. - Parse
Node - A parsed node in the LaTeX AST.
- Strict
Response - The result of a strict-mode check: ignore, warn, or error.
- Strictness
- The strictness policy for LaTeX-incompatible input.
- Style
Level - The typesetting style level, as selected by \displaystyle and friends.
- Trust
Context - The context of a trust check for potentially unsafe commands.
- Trust
Policy - The trust policy for commands that could be unsafe (\href, \url, HTML).
- Unicode
Script Kind - Whether a Unicode script is a subscript or superscript.
Traits§
- Environment
Parser - Callbacks the parser exposes to environment handlers.
- Function
Parser - Callbacks the parser exposes to function handlers.
&mutmethods mutate parser state;&selfmethods are pure reads of settings/state.
Functions§
- atom_
family_ name - Converts AtomFamily to the corresponding spacing type string.
- build_
environment_ registry - Builds an environment registry from the builtin specs plus caller-provided extension specs (which override builtins sharing the same name).
- build_
function_ registry - Builds a function registry from the builtin specs plus caller-provided
extension specs (e.g.
\evalregistered by theevalpackage). - cancel_
bin_ atoms - Apply bin cancellation: Mbin atoms become Mord in certain contexts.
- command_
name - Strips the leading backslash from a control-sequence label (
\sin->sin). Labels without a backslash are returned unchanged. - em_
value - Converts a measurement to an em length:
empasses through,muuses the 18 mu per em ratio, andexthe standard 0.5 x-height ratio. ReturnsNonefor units with no fixed em relation (fill,pt, …). - is_
null_ delimiter - True for the null delimiter
.used by\left./\right., which renders as nothing in every backend. - join_
with_ spacing - Join spacable items into a string, inserting spacing between adjacent
non-space atoms according to the given
SpacingSpec. - katex_
size_ multiplier - The KaTeX font-size multiplier table (
\tiny..\Huge, including\sixptsize), indexed by the 1-basedSizing.sizefield. Sizes outside the table fall back to 1.0 (\normalsize). - line_
style_ frac_ bar - The line character for a fraction bar under the given style.
- math_
choice_ variant - Selects the body of a
\mathchoicenode for the current style level. - math_
spacing - Look up spacing between two atom types.
- parse
- Parses
inputinto aParseNodelist using the given settings. Whensettings.global_groupis set andsettings.macro_storeis present, macros defined during the parse (e.g. via\newcommand) are written back into the caller’s store. - parse_
with_ specs - Parses
inputwith caller-provided extension function/environment specs. - render
- Renders parsed KaTeX nodes as Unicode text. Nodes without a direct Unicode rendering use UnicodeMath-style function syntax so that their structure is retained in plain text.
- resolve_
symbol - Resolves a TeX command name or raw Unicode string to its Unicode rendering via the parser’s symbol registry, falling back to the input itself.
- supported_
codepoint - True when the codepoint falls within one of the supported Unicode script
blocks. Mirrors KaTeX’s
supportedCodepoint(unicodeScripts.ts). - token_
location - Returns the source location of a token, if any.
- unicode_
font_ character - Returns the Unicode mathematical alphanumeric character for a given font
style and ASCII letter/digit, or
Nonewhen no mapping exists. - unicode_
script_ character - Returns the Unicode superscript or subscript character for
replacement. - unicode_
symbol - Returns a registered symbol’s Unicode replacement, if it has one.
- unicode_
text_ spacing - Unicode text spacing: regular spaces for thick/medium, thin and after operators.
Type Aliases§
- Environment
Handler - An environment handler implementation.
- Function
Handler - A function handler implementation.
- Strict
Handler - Strict
Warning Handler - A callback invoked when strict mode produces a warning.
- Trust
Handler - A callback deciding whether a trust context is accepted.