MetadataExtractor
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.
Extracts document-level metadata and source ranges from LaTeX source. Register this callback in metadataExtractors; LatexDocument calls it during document parsing.
Signature
type MetadataExtractor = (text: string) => MetadataExtractionResultReturns
A partial metadata result. It may include built-in metadata fields, custom scalar values, and ranges to blank from ordinary body rendering.
The input has already passed through comment masking: each unescaped comment body is shortened to %, while line structure is preserved. \\today has also been expanded before extractors run.
| Returned field | Consumer |
|---|---|
| Metadata values | Merged into document.metadata |
custom values | Stored under metadata.custom |
ranges | Blanked from body rendering while preserving source lines |
Call relationships
- Called by:
LatexDocumentduring metadata parsing, in registry array order. - Usually calls:
readMetadataCommandor shared balanced readers. - Output merged into:
PreambleData; later non-empty values can replace earlier values.
comment-masked source -> extract(source) -> metadata + hidden ranges -> LatexDocumentconst EDITOR_METADATA_EXTRACTOR: MetadataExtractor = source => {
const editor = readMetadataCommand(source, 'editor');
return editor
? { custom: { editor: editor.content }, ranges: [editor.range] }
: {};
};Return ranges only for declarations that should disappear from body output. The document model preserves line structure needed by source mapping.