Skip to content

context.sourceSlice ​

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.

Returns the source represented by one AST node. Use it when a structural rule needs the original spelling or whitespace rather than rendered HTML.

Signature ​

ts
context.sourceSlice(node: SnaptexAstNode): string

Returns ​

The exact substring from the current block when the node has source offsets. Otherwise SnapTeX reconstructs readable node text.

Call relationships ​

  • Uses: node source positions and the current block source.
  • Called by: AST rules that need original command spelling or whitespace.
  • Does not: render or escape the result.
ts
const original = context.sourceSlice(input.node);

Treat the result as source text. Escape or render it before adding it to HTML.

See also ​

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