Skip to content

environmentName ​

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.

Reads an environment name from the shapes produced by the unified-latex parser. Use it when only the name is needed; use isEnvironmentNode when the rule also needs type narrowing.

Signature ​

ts
function environmentName(node: unknown): string | undefined

Returns ​

The string name when node.env is either a string or an object with string content; otherwise undefined.

Call relationships ​

  • Called by: isEnvironmentNode, verbatim guards, and environment rules.
  • Does not: require the node itself to have an environment type.
ts
const name = environmentName(input.node);
if (name === 'notice') { /* ... */ }

Prefer isEnvironmentNode when you need both validation and TypeScript narrowing.

See also ​

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