Skip to content

defineAstMathRule ​

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.

Provides contextual TypeScript typing for one command rule used inside AST math. The function returns the same rule object; the rule starts running only after it is added to SNAP_TEX_RULES.astMathRules.

Signature ​

ts
function defineAstMathRule(rule: AstMathRule): AstMathRule

Rule shape ​

ts
interface AstMathRule {
    readonly commands: readonly string[];
    apply(input: AstMathRuleInput, context: AstRenderContext): AstMathRuleResult | undefined;
}
  • commands lets the existing block AST decide whether the formula needs a local parse.
  • apply receives the matching macro, parsed arguments, exact local source access, and the normal AST render context.
  • Returning undefined lets the next rule for the same command try.
  • Rules run in array order; there is no numeric priority.

See Commands inside math for a complete declaration and registration example.

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