JavaScriptserialize

serialize

Python

Render a SyntaxNode to LaTeX text, and the output style options.

serializefunction#

serialize(    node: SyntaxNode,    options: SerializeOptions | null | undefined,): string

Deprecated. 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.

ParameterTypeDescription
nodeSyntaxNode
optionsSerializeOptions | null | undefined
Returns
string —

The serialized LaTeX string.

TypeScript
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.

FieldTypeDescription
styleStyle | null | undefined

"spaced" (default when omitted or null) separates every token and is byte-stable across releases. "compact" keeps only required spaces and drops braces around single-token scripts; it preserves parsed structure, but its layout may improve across releases.

TypeScript
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.