readAstCommandArguments
How to read this API
These are TypeScript APIs compiled into SnapTeX; a .tex project cannot load them at runtime.
function name(...)is a helper that your rule imports and calls.apply(...),render(...),extract(...), andcollect(...)are callbacks that your rule implements and SnapTeX calls.renderer.name(...),context.name(...),input.name(...), anddeps.name(...)are methods SnapTeX supplies to callbacks; do not import or construct them.service.name(...)is an instance method called after your host or test constructsPreviewUpdateService.
Register extension declarations through SNAP_TEX_RULES in src/rules.ts. See Source API Scope for imports, value ownership, output safety, rebuilds, and testing.
Reads optional and required arguments for the current AST macro, including detached sibling groups. Use it from an AstRenderRule when a command's arguments may not all be attached to the macro node by the parser.
Signature
function readAstCommandArguments(
input: AstNodeLocation,
requiredArgCount = 1
): AstCommandArgumentsinterface AstCommandArguments {
requiredArgs: string[];
optionalArgs: string[];
requiredArgNodes: SnaptexAstNode[][];
optionalArgNodes: SnaptexAstNode[][];
consumedNodes: number;
}Behavior
The function first reads arguments attached to input.node. If fewer required arguments are available, it skips sibling whitespace, reads detached bracket groups, then reads detached brace-group nodes until requiredArgCount is met.
The helper returns both plain argument text and the corresponding node arrays. In a normal AstRenderRule, pass an entry such as requiredArgNodes[0] to input.renderChildren when preserving parsed nested formatting is essential. In an AstMathRule, pass it to input.sourceContent to preserve the exact original TeX.
Call relationships
- Called by:
AstRenderRulecallbacks and the math-rule dispatcher. - Reads: arguments attached to the macro plus detached sibling groups.
- Return feeds: rendered argument content and
consumedNodesin either AST rule type.
AstRenderInput -> attached arguments + following sibling groups
-> requiredArgs / optionalArgs / consumedNodes
-> AstRenderResultconst args = readAstCommandArguments(input, 1);
if (args.requiredArgs[0] === undefined) return undefined;
return { html: context.escapeHtml(args.requiredArgs[0]), consumedNodes: args.consumedNodes };For a non-macro node, it returns empty argument arrays and consumedNodes: 1.