Skip to content

defineBlockDependencyRule ​

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.

Preserves a block dependency rule unchanged while providing contextual TypeScript typing. Use it only when unchanged block source can render differently because document-level state changed.

Signature ​

ts
function defineBlockDependencyRule(rule: BlockDependencyRule): BlockDependencyRule

Parameters ​

ParameterDescription
ruleDependency callback

Returns ​

The same callback. Registration happens only when it is added to blockDependencyRules.

Call relationships ​

  • Called by: dependency declarations in src/rules.ts.
  • Collector executed by: SmartRenderer for new or source-changed blocks.
  • Collector usually calls: deps.metadata or deps.citedKeys.
text
callback -> defineBlockDependencyRule -> blockDependencyRules registration
                                       -> SmartRenderer dependency collection

Example ​

ts
const RULE = defineBlockDependencyRule(({ text, deps }) => text.includes('\\makecover')
        ? [deps.metadata('title')]
        : []
);

Do not add a dependency when output depends only on the block's own source; source hashing already handles that case.

See also ​

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