Skip to content

isEnvironmentNode ​

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(...), and collect(...) are callbacks that your rule implements and SnapTeX calls.
  • renderer.name(...), context.name(...), input.name(...), and deps.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 constructs PreviewUpdateService.

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 an AST environment or math-environment node. Use it at the start of an environment rule's render callback.

Signature ​

ts
function isEnvironmentNode(
    node: unknown,
    name?: string
): node is SnaptexAstEnvironment

Returns ​

true for environment or mathenv nodes with a readable environment name. When name is supplied, the names must match exactly.

Call relationships ​

  • Calls: environmentName.
  • Called by: AST rule render callbacks and structural visitors.
  • Enables: TypeScript narrowing to SnaptexAstEnvironment.
ts
render: input => {
    if (!isEnvironmentNode(input.node, 'notice')) { return undefined; }
    return { html: input.renderChildren(input.node.content ?? []) };
}

See also ​

A fast structural preview, not a replacement for a full TeX compiler.