Skip to content

defineRuleRegistry ​

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.

Creates the registry consumed by document parsing and rendering. Call it when assembling the exported SNAP_TEX_RULES; it is not called from an individual render callback.

Signature ​

ts
function defineRuleRegistry(registry: RuleRegistry): RuleRegistry

Parameters ​

ParameterDescription
registryComplete metadata, rendering, dependency, and splitter configuration

Returns ​

A new registry object. Every array and splitterConfig is shallow-copied. renderRules is sorted by ascending priority; other arrays preserve caller order.

Call relationships ​

  • Called while: constructing SNAP_TEX_RULES in src/rules.ts.
  • Consumed by: LatexDocument, SmartRenderer, and PreviewUpdateService.
  • Does not call: rule callbacks or render source.
text
rule constants -> defineRuleRegistry -> SNAP_TEX_RULES
                                      -> LatexDocument + SmartRenderer

Example ​

ts
export const SNAP_TEX_RULES = defineRuleRegistry({
    metadataExtractors: [BUILTIN_METADATA_EXTRACTOR],
    renderRules: DEFAULT_RENDER_RULES,
    astRenderRules: DEFAULT_AST_RENDER_RULES,
    astMathRules: DEFAULT_AST_MATH_RULES,
    blockDependencyRules: DEFAULT_BLOCK_DEPENDENCY_RULES,
    splitterConfig: DEFAULT_SPLITTER_CONFIG,
    splitterRules: DEFAULT_SPLITTER_RULES
});

The returned registry is a lifecycle snapshot. Rebuild and reload SnapTeX after changing rule definitions.

See also ​

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