Skip to content

Registry Contract ​

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.

RuleRegistry is the single assembly object consumed by the document model and renderer. Individual rule constants are inert until they appear in the corresponding registry field.

ts
interface RuleRegistry {
    readonly metadataExtractors: readonly MetadataExtractor[];
    readonly renderRules: readonly PreprocessRule[];
    readonly astRenderRules: readonly AstRenderRule[];
    readonly astMathRules: readonly AstMathRule[];
    readonly blockDependencyRules: readonly BlockDependencyRule[];
    readonly splitterConfig: SplitterConfig;
    readonly splitterRules: readonly SplitterRule[];
}

Field ownership ​

FieldConsumerOrdering
metadataExtractorsLatexDocumentArray order
renderRulesLegacy SmartRendererAscending priority
astRenderRulesAST rendererArray order; first returned result wins
astMathRulesAST math rendererArray order; first command rule returning a result wins
blockDependencyRulesSmartRendererAll collectors contribute descriptors
splitterConfigLegacy coarse splitter and AST refinementNumeric limits
splitterRulesLegacy coarse splitter and AST refinementDeclarative structural hints selected by kind

Build a registry with defineRuleRegistry. The default instance is SNAP_TEX_RULES in src/rules.ts.

The legacy and AST rendering arrays are independent. astMathRules is a nested AST extension point used only after astRenderRules assigns a complete math node to the math renderer.

From field to callback ​

Registry fieldSnapTeX later callsCallback return becomes
metadataExtractorsextract(source)Merged document metadata and hidden source ranges
renderRulesapply(text, renderer)Input text for the next legacy rule
astRenderRules(input, context) => resultFinal HTML for one claimed AST node
astMathRulesapply(input, context)A source-preserving replacement for one command inside math
blockDependencyRules(input) => dependenciesStored descriptors used to dirty unchanged blocks
splitterRulesNo user callback; the splitter reads declarationsSource block spans

splitterConfig and splitterRules influence parsing before either render-rule array runs. They are not fallback renderers.

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