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(...), andcollect(...)are callbacks that your rule implements and SnapTeX calls.renderer.name(...),context.name(...),input.name(...), anddeps.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 constructsPreviewUpdateService.
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.
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
| Field | Consumer | Ordering |
|---|---|---|
metadataExtractors | LatexDocument | Array order |
renderRules | Legacy SmartRenderer | Ascending priority |
astRenderRules | AST renderer | Array order; first returned result wins |
astMathRules | AST math renderer | Array order; first command rule returning a result wins |
blockDependencyRules | SmartRenderer | All collectors contribute descriptors |
splitterConfig | Legacy coarse splitter and AST refinement | Numeric limits |
splitterRules | Legacy coarse splitter and AST refinement | Declarative 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 field | SnapTeX later calls | Callback return becomes |
|---|---|---|
metadataExtractors | extract(source) | Merged document metadata and hidden source ranges |
renderRules | apply(text, renderer) | Input text for the next legacy rule |
astRenderRules | (input, context) => result | Final HTML for one claimed AST node |
astMathRules | apply(input, context) | A source-preserving replacement for one command inside math |
blockDependencyRules | (input) => dependencies | Stored descriptors used to dirty unchanged blocks |
splitterRules | No user callback; the splitter reads declarations | Source block spans |
splitterConfig and splitterRules influence parsing before either render-rule array runs. They are not fallback renderers.