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(...), 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.
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): BlockDependencyRuleParameters
| Parameter | Description |
|---|---|
rule | Dependency 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:
SmartRendererfor new or source-changed blocks. - Collector usually calls:
deps.metadataordeps.citedKeys.
text
callback -> defineBlockDependencyRule -> blockDependencyRules registration
-> SmartRenderer dependency collectionExample
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.