Skip to main content

Crate katex_parser

Crate katex_parser 

Source
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 a ParseNode list.
  • render — render a parsed node list as Unicode text.
  • Settings — parser configuration (display mode, macros, strictness, trust policy, and a persistent macro store).

Structs§

ArrayEnvironmentOptions
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.
EnvironmentContext
Per-environment-call context: static data about the environment.
EnvironmentRegistry
A map from environment names to their specs.
EnvironmentSpec
The declaration of an environment (name, arguments, handler).
FunctionContext
Per-function-call context: static data about the function being parsed.
FunctionRegistry
A map from function names to their specs.
FunctionSpec
The declaration of a function (name, arguments, handler).
MacroExpansion
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).
RenderConfig
Configuration for the Unicode renderer.
Settings
Parser configuration: display mode, macros, strictness, trust, and limits.
SourceLocation
A span of the original input. start/end are char offsets into input.
SpacableItem
A renderable atom with its math class and baseline info.
SpacingSpec
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.
ArrayColumn
A column of an array environment: an alignment cell or a vertical separator.
AtomFamily
The math atom class of a symbol, used for spacing decisions.
ColumnSeparationType
How columns of an array are separated.
LapAlignment
Horizontal alignment of a Lap (mathllap/mathrlap/mathclap) node.
LineStyle
Glyph style for drawn lines: fraction bars, boxes, tables, etc.
MacroDefinition
A macro body: raw text or a pre-expanded token list.
Mode
The parsing mode: math or text.
OperatorContent
The body of an Op node: a symbol, a named operator, or an argument body.
ParseError
A parse failure, mirroring MoonBit’s ParseFailure suberror.
ParseNode
A parsed node in the LaTeX AST.
StrictResponse
The result of a strict-mode check: ignore, warn, or error.
Strictness
The strictness policy for LaTeX-incompatible input.
StyleLevel
The typesetting style level, as selected by \displaystyle and friends.
TrustContext
The context of a trust check for potentially unsafe commands.
TrustPolicy
The trust policy for commands that could be unsafe (\href, \url, HTML).
UnicodeScriptKind
Whether a Unicode script is a subscript or superscript.

Traits§

EnvironmentParser
Callbacks the parser exposes to environment handlers.
FunctionParser
Callbacks the parser exposes to function handlers. &mut methods mutate parser state; &self methods 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. \eval registered by the eval package).
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: em passes through, mu uses the 18 mu per em ratio, and ex the standard 0.5 x-height ratio. Returns None for 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-based Sizing.size field. 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 \mathchoice node for the current style level.
math_spacing
Look up spacing between two atom types.
parse
Parses input into a ParseNode list using the given settings. When settings.global_group is set and settings.macro_store is present, macros defined during the parse (e.g. via \newcommand) are written back into the caller’s store.
parse_with_specs
Parses input with 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 None when 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§

EnvironmentHandler
An environment handler implementation.
FunctionHandler
A function handler implementation.
StrictHandler
StrictWarningHandler
A callback invoked when strict mode produces a warning.
TrustHandler
A callback deciding whether a trust context is accepted.