readMetadataCommand
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.
Finds the first balanced one-argument metadata command in source text. Use it inside a metadata extractor for simple \name{value} declarations.
Signature
ts
function readMetadataCommand(
text: string,
commandName: string
): { content: string; range: TextRange } | undefinedParameters
| Parameter | Description |
|---|---|
text | Source supplied to a MetadataExtractor |
commandName | Command name without the leading backslash |
Returns
The content inside the required group and the full command's source range, or undefined when no valid command is found.
Call relationships
- Called by: custom
MetadataExtractorcallbacks. - Uses: the shared balanced command reader in
src/utils.ts. - Returned range feeds: document cleanup that blanks metadata declarations from body rendering.
ts
const editor = readMetadataCommand(source, 'editor');
return editor
? { custom: { editor: editor.content }, ranges: [editor.range] }
: {};This convenience reader returns only the first occurrence. Use the lower-level source readers for repeated or multi-argument command syntax.