serializefunction#
serialize( node: SyntaxNode, options: SerializeOptions | null | undefined,): stringDeprecated. Prefer Document.fromSyntax(node).toLatex(options) or
document.toLatex(options). This remains exported as a compatibility helper
for older snapshot call sites and takes the same options as toLatex.
Render a SyntaxNode object to LaTeX text.
Error nodes round-trip their captured snippet. An ordinary Prime emits
\prime symbols, while a pure prime superscript serializes compactly as
f' or f''. The serializer guarantees text
idempotency.
| Parameter | Type | Description |
|---|---|---|
node | Syntax |
|
options | Serialize |
|
string — The serialized LaTeX string.
import { Parser, serialize } from 'texform';
const result = new Parser().parse(String.raw`x^2`);
if (!result.document) throw new Error('parse failed');
const syntax = result.document.toSyntax();
serialize(syntax); // 'x ^ { 2 }'
serialize(syntax, { style: 'compact' }); // 'x^2'SerializeOptionsinterface#
Options for Document.toLatex, Document.toTokenizedLatex,
and serialize. Unknown keys and invalid values throw
TexformConfigError. For a task-oriented walkthrough, see the
Serialization guide.
| Field | Type | Description |
|---|---|---|
style | Style | |
|
const doc = new Parser().parse(String.raw`\frac{a}{b}+x_i^2`).document;
doc.toLatex(); // '\\frac { a } { b } + x _ { i } ^ { 2 }'
doc.toLatex({ style: 'compact' }); // '\\frac{a}{b}+x_i^2'Styletype#
"spaced" | "compact"Spaced output is byte-stable; compact preserves structure and text idempotency.