Skip to content

API Call Relationships ​

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.

This page shows when each extension API runs and which lower-level functions it normally calls. The arrows describe runtime calls, not import direction.

Runtime values at a glance ​

These names appear repeatedly in rule examples, but they are created at different layers:

ValueCreated byAvailable insidePrimary role
textLegacy block rendererPreprocessRule.applyCurrent transformed block source
rendererSmartRendererPreprocessRule.applyLegacy document state and protected-output services
inputAST walkerAstRenderRuleCurrent node, siblings, and recursive rendering
contextAST rendererAstRenderRuleAST document state and direct-HTML services
input.argumentsAST math dispatcherAstMathRule.applyParsed text/node arguments and consumed sibling count
callreplaceLatexCommandCallsIts nested render callbackOne balanced source command call
depsDependency collector hostBlockDependencyRuleFactories for stable dependency descriptors

Your rule never constructs these objects. It declares callbacks; the owning service creates the values and invokes the callbacks.

Registry to rendering ​

defineRuleRegistry copies the registry collections and sorts only legacy rules by priority. LatexDocument consumes metadata and splitter definitions; SmartRenderer consumes rendering and dependency rules.

A declaration helper and the registry have different jobs:

text
defineAstRenderRule(rule)       -> type-check and return one declaration
defineAstMathRule(rule)         -> type-check and return one math-command declaration
defineBlockDependencyRule(rule) -> type-check and return one declaration
defineRuleRegistry({...})        -> assemble the declarations used by a preview lifecycle

Splitter flow ​

AST mode shares the mature coarse splitter rather than replacing it. On later edits, coarse hashes let the document reuse unchanged refined spans and run AST refinement only for the changed coarse range. See the Splitter Contract for the rule-kind ownership matrix.

Legacy rule flow ​

Legacy rules receive source text in priority order. Generated HTML must be protected before Markdown conversion. Balanced readers are optional helpers, but they are the preferred way to read command arguments.

The nested render(call) callback belongs to replaceLatexCommandCalls; it is invoked only for a syntactically valid command. Its returned string replaces that command inside the block passed to the next legacy rule.

AST rule flow ​

The first AST rule that returns a result claims the node; undefined passes it to the next rule. renderChildren reuses existing child nodes. renderSource parses generated source and is intended for macro expansion or reconstructed LaTeX, not ordinary child traversal.

AstRenderRule returns final HTML. consumedNodes controls how far the walker advances; it is not an HTML property and does not represent child count.

Metadata and dependencies ​

Dependency collection identifies what a block depends on. SnapTeX stores the descriptors for unchanged blocks and recomputes their fingerprints from current document state, avoiding repeated source scans.

End-to-end testing ​

Use PreviewUpdateService when a test needs to verify the behavior a host actually receives, including parsing, block diffing, numbering, dependencies, and backend selection.

Lazy block and resource calls ​

renderBlockByIndex returns backend-selected block HTML without knowing the host URL scheme. The host resolves LOCAL_IMG: markers after rendering and before sending BlockHtml. PDF drawing remains a separate request because the preview runtime controls canvas lifetime and viewport scale.

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