Expand description
Canonical AST serializer — converts Ast back to LaTeX text.
The serializer is independent of the transform stage: it covers the full AST
node vocabulary and makes no assumptions about whether the input has been
normalized. Its default style targets the corpus / equiv use cases with
strong disambiguation and explicit token boundaries in math mode, while text
mode content is preserved verbatim.
§Architecture
Serializer (recursive AST walk)
-> emit atom with kind + mode
-> AtomWriter decides inter-atom boundary
-> StringMost spacing rules are concentrated in the atom writer’s boundary decision,
which inspects the previous atom, the next atom, the current content mode,
and the active SerializeOptions. A few wrapper/scalar helpers still emit
preformatted spaces directly for cases that cannot be expressed as a simple
previous/next atom decision (for example empty padded groups). This keeps
the boundary logic local and avoids post-hoc string cleanup — important
because TeX whitespace carries both lexical and semantic weight.
Structs§
- Environment
Serialize Options - Environment header formatting options.
- Math
Infix Options - Infix serialization options for math mode.
- Math
Script Options - Sub/superscript formatting controls.
- Math
Serialize Options - Math-mode serialization options.
- Math
Spacing Options - Spacing controls within math mode.
- Serialize
Options - Top-level serialization options, grouped by scope.
- Syntax
Serialize Options - Structural syntax options (mode-independent).
Enums§
- Adjacent
Char Spacing - Whether adjacent math character atoms get explicit space separation.
- Command
Spacing - Whether to insert a space between a command and the following structural token in math mode.
- Environment
Name Spacing - Whether
\begin/\endget a space before the name brace. - Infix
Grouping - Whether math infix operands are always braced or only when needed.
- Math
Group Inner Spacing - Controls the inside spacing of math brace groups.
- Script
Order - Fixed output order for subscript and superscript.
- Script
Spacing - Whether to insert spaces immediately around
_and^markers. - Serialize
Error - Error type for fallible LaTeX serialization.
Functions§
- serialize
- Serialize an AST to LaTeX using the default canonical style.
- serialize_
with - Serialize an AST to LaTeX with explicit style options.