readLatexCommandAt
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.
Reads one named LaTeX command at a specified source position. Use it when a caller already controls the scan position; it deliberately does not search the remaining source.
Signature
function readLatexCommandAt(text, startIndex, options): LatexCommandCall | undefinedinterface LatexCommandReadOptions {
name: string;
requiredArgs?: number;
optionalArgs?: number;
allowStar?: boolean;
skipWhitespace?: boolean;
}Behavior
By default, leading whitespace and comments are skipped. The function then requires exactly \\${name} at that location. It does not search the rest of the string.
Required groups must all be present and balanced. Optional groups are read up to the requested count and may be absent. A star is accepted only when allowStar is true.
Returns
The command name, source offsets, star flag, and arrays of optional and required LatexGroup values. Returns undefined on a name boundary mismatch or malformed required argument.
Call relationships
- Calls:
skipLatexWhitespaceandreadLatexGroup. - Called by:
replaceLatexCommandCallsand targeted source readers.
const call = readLatexCommandAt(source, index, {
name: 'href',
requiredArgs: 2,
allowStar: false
});