Skip to main content

Module serialize

Module serialize 

Source
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
  -> String

Most 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§

EnvironmentSerializeOptions
Environment header formatting options.
MathInfixOptions
Infix serialization options for math mode.
MathScriptOptions
Sub/superscript formatting controls.
MathSerializeOptions
Math-mode serialization options.
MathSpacingOptions
Spacing controls within math mode.
SerializeOptions
Top-level serialization options, grouped by scope.
SyntaxSerializeOptions
Structural syntax options (mode-independent).

Enums§

AdjacentCharSpacing
Whether adjacent math character atoms get explicit space separation.
CommandSpacing
Whether to insert a space between a command and the following structural token in math mode.
EnvironmentNameSpacing
Whether \begin / \end get a space before the name brace.
InfixGrouping
Whether math infix operands are always braced or only when needed.
MathGroupInnerSpacing
Controls the inside spacing of math brace groups.
ScriptOrder
Fixed output order for subscript and superscript.
ScriptSpacing
Whether to insert spaces immediately around _ and ^ markers.
SerializeError
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.