Nodeclass#
A read-only handle into a Document.
Node carries navigation and accessor members but no editing methods — all
edits go through the owning document. It is a cheap reference, not a copy of
the subtree; reads delegate back into the document. Obtain handles from
Document.root, Document.errors, Document.findCommands,
the create* staging constructors, and the navigation members below.
const doc = new Parser().parse(String.raw`\frac{x}{y}`).document!;
const cmd = doc.root().children()[0];
cmd.kind; // 'command'
cmd.isCommand('frac'); // trueKind#
Predicates#
isCommand#
isCommand(name: string | null | undefined): booleanWhether the node is a command; with name, whether it is that specific
command.
| Parameter | Type | Description |
|---|---|---|
name | string | |
|
boolean — true if the node is a (matching) command.
node.isCommand(); // any command
node.isCommand('frac'); // specifically \fracisChar#
isChar(value: string | null | undefined): booleanWhether the node is a char; with value, whether it holds that specific
character.
| Parameter | Type | Description |
|---|---|---|
value | string | |
|
boolean — true if the node is a (matching) char.
isError#
isError(): booleanWhether the node is an Error placeholder.
boolean — true for an Error node.
isKnown#
isKnown(): boolean | nullWhether the knowledge base knows this command or environment; null for other kinds.
boolean | nullNavigation#
parent#
parent(): Node | nullThe parent Node, or null for the root.
Node | null — The parent handle, or null.
nextSibling#
nextSibling(): Node | nullThe following sibling Node, or null.
Node | null — The next sibling handle, or null.
prevSibling#
prevSibling(): Node | nullThe preceding sibling Node, or null.
Node | null — The previous sibling handle, or null.
ancestors#
ancestors(): Node[]The ancestor Nodes from parent upward.
Node[] — The ancestor handles, nearest first.
descendants#
descendants(): Node[]The descendant Nodes in document order.
Node[] — The descendant handles.
path#
path(): string | nullThe node's current path from the root, or null if detached. Edits change it; Document.nodeAt resolves it.
string | nullslot#
slot(): NodeSlot | nullThe slot this node fills in its parent, or null for the root and detached nodes.
NodeSlot | nullContent accessors#
commandNameattribute#
string | nullThe command name for a command / declarative node, else null
(read-only property).
envNameattribute#
string | nullThe environment name for an environment node, else null (read-only property).
primeCount#
primeCount(): number | nullThe prime count (greater than zero) for a prime node, else null.
number | null — The number of consecutive prime symbols, or null. Scripted determines their binding.
const doc = new Parser().parse(String.raw`f''`).document;
const prime = doc.root().descendants().find((n) => n.kind === 'prime');
prime.primeCount(); // 2errorParts#
errorParts(): { message: string; snippet: string } | nullFor an error node, its captured { message, snippet }, else null.
{ message: string; snippet: string } | null — The error message and the original source snippet, or null.
const doc = new Parser().parse(String.raw`\sqrt[`).document;
const err = doc.root().descendants().find((n) => n.isError());
err.errorParts(); // { message: 'unclosed bracket argument', snippet: '\\sqrt[' }contentMode#
contentMode(): RuntimeContentMode | nullThe runtime content mode ("math" or "text") where applicable, else
null.
RuntimeContentMode | null — The node's content mode, or null.
Groups#
groupKind#
groupKind(): GroupKindRef | nullThe GroupKindRef for a group node, else null.
The result carries a capitalized kind discriminator ('Explicit',
'Implicit', 'InlineMath', 'Delimited'). A Delimited group also
carries left and right delimiter strings such as '(' or '\\langle'.
GroupKindRef | null — The group kind view, or null.
const doc = new Parser().parse(String.raw`{x}`).document;
const group = doc.root().descendants().find((n) => n.kind === 'group');
group.groupKind(); // { kind: 'Explicit' }Command arguments#
argCount#
argCount(): numberThe number of argument slots for a command-like node.
number — The slot count.
arg#
arg(index: number): ArgRef | nullThe argument at index, or null if the slot is empty.
| Parameter | Type | Description |
|---|---|---|
index | number |
|
ArgRef | null — The ArgRef for the slot, or null.
const doc = new Parser().parse(String.raw`\frac{x}{y}`).document;
const frac = doc.root().descendants().find((n) => n.isCommand('frac'));
frac.argCount(); // 2
frac.arg(0); // { kind: 'Math', node: <Node> }argKind#
argKind(index: number): ArgForm | nullThe delimiter form of the argument slot at index, or null if there is no such slot.
| Parameter | Type |
|---|---|
index | number |
ArgForm | nullScripts and infix#
scriptBase#
scriptBase(): Node | nullThe base of a scripted node, else null.
Node | null — The base node handle, or null.
subscript#
subscript(): Node | nullThe subscript slot of a scripted node, else null.
Node | null — The subscript node handle, or null.
const doc = new Parser().parse(String.raw`x_i^2`).document;
const sc = doc.root().descendants().find((n) => n.kind === 'scripted');
[sc.subscript().kind, sc.superscript().kind]; // ['char', 'char']superscript#
superscript(): Node | nullThe superscript slot of a scripted node, else null.
Node | null — The superscript node handle, or null.
infixLeft#
infixLeft(): Node | nullThe left operand of an infix node, else null.
Node | null — The left operand handle, or null.
infixRight#
infixRight(): Node | nullThe right operand of an infix node, else null.
Node | null — The right operand handle, or null.
envBody#
envBody(): Node | nullThe body group of an environment node, else null.
Node | null — The body group handle, or null.
Spans#
Identity#
Lifecycle#
free#
free(): voidRelease this node handle's WASM wrapper immediately.
This does not free the owning Document. Prefer a using
declaration so [Symbol.dispose]() runs at scope exit. After free(),
further use of this handle is invalid. Skipping free() is safe:
garbage collection still reclaims the wrapper.
NodeKindtype#
"root" | "group" | "command" | "infix" | "declarative" | "environment" | "scripted" | "prime" | "text" | "char" | "activeSpace" | "alignmentTab" | "error"SyntaxContentModetype#
"Math" | "Text"Content mode as it appears in a SyntaxNode snapshot: "Math" or
"Text" (capitalized snapshot form).
RuntimeContentModetype#
"math" | "text"Content mode as reported by the runtime tree API: "math" or "text"
(lowercase form used by Node.contentMode and the mode arguments of
lookup methods).
GroupKindtype#
"Explicit" | "Implicit" | { Delimited: { left: Delimiter; right: Delimiter } } | "InlineMath"The kind of a group in SyntaxNode snapshot form: an Explicit brace
group, an Implicit group, a Delimited group carrying its left/right
delimiters, or an InlineMath group.
GroupKindReftype#
{ kind: "Explicit" } | { kind: "Implicit" } | { kind: "Delimited"; left: string; right: string } | { kind: "InlineMath" }The kind of a group in runtime view form, with a kind discriminator.
Returned by Node.groupKind; the discriminator keeps its capitalized
form ('Explicit', 'Delimited', ...). A Delimited group carries
left and right delimiter strings.
Delimitertype#
"None" | { Char: string } | { Control: string }A delimiter token in SyntaxNode snapshot form: the literal "None",
a single character ({ Char }), or a control sequence ({ Control }).
Runtime views use delimiter strings instead: ., one character, or a
backslash-prefixed control sequence such as \langle.
Argumentinterface#
A present command/environment argument in SyntaxNode snapshot form, pairing its syntactic ArgumentKind with its parsed ArgumentValue.
| Field | Type | Description |
|---|---|---|
kind | Argument | The argument's syntactic kind (mandatory, optional, delimited, ...). |
no_leading_space | boolean | | Whether the argspec slot was prefixed with |
value | Argument | The argument's parsed value. |
ArgumentKindtype#
"Mandatory" | "Optional" | "Star" | "Group" | { Until: { close: Delimiter } } | { Delimited: { open: Delimiter; close: Delimiter } } | { Paired: { open: Delimiter; close: Delimiter } }The syntactic kind of a command argument in SyntaxNode snapshot form
(mandatory, optional, starred, group, until, or delimited/paired).
Until forms carry close; delimited/paired forms carry open and close.
ArgumentValuetype#
{ MathContent: SyntaxNode } | { TextContent: SyntaxNode } | { OperatorNameContent: SyntaxNode } | { Delimiter: Delimiter } | { CSName: string } | { Dimension: string } | { Integer: string } | { KeyVal: string } | { Column: string } | { Boolean: boolean }The parsed value carried by an Argument in snapshot form: math or text content, a delimiter, a control-sequence name, a dimension, an integer, a key=value list, a column spec, or a boolean flag.
ArgumentSlottype#
Argument | null | undefinedArgReftype#
{ form: ArgForm } & ( | { kind: "Math"; node: Node } | { kind: "Text"; node: Node } | { kind: "OperatorName"; node: Node } | { kind: "Delimiter"; value: string } | { kind: "CSName"; value: string } | { kind: "Dimension"; value: string } | { kind: "Integer"; value: string } | { kind: "KeyVal"; value: string } | { kind: "Column"; value: string } | { kind: "Boolean"; value: boolean })A command/environment argument in runtime view form, returned by Node.arg and Node.argSlots.
Content kinds (Math, Text, OperatorName) carry a live node Node handle; leaf
kinds (Delimiter, CSName, Dimension, Integer, KeyVal, Column,
Boolean) carry a value. Delimiter values use source strings. The kind discriminator keeps its capitalized
form.
ArgFormtype#
{ kind: "mandatory" | "optional" | "star" | "group" | "until" | "delimited" | "paired"; open?: string; close?: string }The delimiter form of an argument slot; close is present for until, and both open and close for delimited and paired forms.
NodeSlottype#
{ kind: "child" | "arg" | "script_base" | "subscript" | "superscript" | "infix_left" | "infix_right" | "env_body"; index: number | null }The parent slot a Node fills; index is set for indexed slots such as children and arguments.
Argtype#
Node | string | boolean | null | { value: Arg; open: string; close: string }A slot value accepted by construction and editing methods: a string is the source written inside the slot's boundaries, a detached Node is content, boolean sets a star slot, null omits an optional slot, and { value, open, close } selects an explicit delimiter pair.