isMacroNode
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.
Checks whether an unknown value is a LaTeX AST macro node and optionally matches its name. Use it at the start of a command rule.
Signature
ts
function isMacroNode(node: unknown, name?: string): node is SnaptexAstMacroReturns
true only when node is an object with type === 'macro', string content, and, when supplied, the requested command name.
Call relationships
- Called by: AST rules and AST readers.
- Enables: TypeScript narrowing to
SnaptexAstMacro. - Does not: inspect or validate command arguments.
ts
const RULE = defineAstRenderRule((input, context) => {
if (!isMacroNode(input.node, 'badge')) { return undefined; }
// input.node is a SnaptexAstMacro here.
});Command names do not include the leading backslash.