serializefunction#
serialize(node: SyntaxNode, **options) -> strRender a SyntaxNode dict to LaTeX text.
This is the free-function counterpart to Document.to_latex(); both take
the same keyword options. Error nodes round-trip their captured snippet,
ordinary Prime nodes emit \prime symbols, pure prime superscripts
serialize compactly as f' / f'', and the
serializer guarantees text idempotency. For the conceptual model, see the
Serialization guide. It checks only the structure, not conformance to any knowledge base.
| Parameter | Type | Description |
|---|---|---|
node | Syntax | A |
**options | Unpack[ | Serializer style overlays. Omitted keys and explicit |
str — The serialized LaTeX string.
ConfigError—If an option key is unknown or a value has the wrong type.
result = texform.Parser().parse(r"x^2")
document = result["document"]
assert document is not None
syntax = document.to_syntax()
texform.serialize(syntax) # 'x ^ { 2 }'
texform.serialize(syntax, style="compact") # 'x^2'SerializeOptionsdict type#
Options for Document.to_latex, Document.to_tokenized_latex, and serialize.
Passed as keywords. Omitted or None style selects the default
spaced style. Unknown keys and invalid values raise ConfigError. For a
task-oriented walkthrough, see the Serialization guide.
| Field | Type | Description |
|---|---|---|
style | Style | |
|
doc = texform.Parser().parse(r"\frac{a}{b}+x_i^2")["document"]
doc.to_latex() # '\frac { a } { b } + x _ { i } ^ { 2 }'
doc.to_latex(style="compact") # '\frac{a}{b}+x_i^2'Styletype#
Literal['spaced', 'compact']Spaced output is byte-stable; compact preserves structure and text idempotency.