Metadata and Dependency Contracts
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.
Metadata extraction records document-level values. Dependency collection marks unchanged blocks whose HTML depends on those values.
document source -> MetadataExtractor -> document.metadata
changed block -> BlockDependencyRule -> stored descriptors
later update -> descriptor values + source hash -> dirty block selectionAn extractor is required to create a custom metadata value. A dependency rule is required only when another block can keep identical source while rendering from that changed value.
MetadataExtractor
type MetadataExtractor = (text: string) => MetadataExtractionResult;The extractor callback receives document source. It may return built-in metadata fields, custom values, and source ranges that should be blanked from body rendering while preserving source mapping.
Use readMetadataCommand to read a balanced one-argument command.
BlockDependencyRule
type BlockDependencyRule = (input: BlockDependencyInput) => RenderDependency[];The callback receives block text, its index, an optional AST artifact, and deps factories. It identifies external document state that can change the block's output without changing its own source.
Dependency descriptors are cached for unchanged blocks. Their current values are fingerprinted on later updates; a changed fingerprint marks the block dirty.
Neither contract renders HTML. Rendering rules consume the metadata after LatexDocument has merged extractor results.