Skip to content

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(...), and collect(...) are callbacks that your rule implements and SnapTeX calls.
  • renderer.name(...), context.name(...), input.name(...), and deps.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 constructs PreviewUpdateService.

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 ​

ts
function readLatexCommandAt(text, startIndex, options): LatexCommandCall | undefined
ts
interface 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 ​

ts
const call = readLatexCommandAt(source, index, {
    name: 'href',
    requiredArgs: 2,
    allowStar: false
});

See also ​

A fast structural preview, not a replacement for a full TeX compiler.