Skip to content

readLatexGroup ​

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 balanced brace or bracket group, including nested groups and escaped delimiters. Use it when reading a group at a known offset; use replaceLatexCommandCalls for command-wide search and replacement.

Signature ​

ts
function readLatexGroup(
    text: string,
    startIndex: number,
    options?: {
        delimiter?: 'brace' | 'bracket';
        skipWhitespace?: boolean;
    }
): LatexGroup | undefined

Returns ​

ts
interface LatexGroup {
    content: string;
    start: number;
    end: number;
    open: '{' | '[';
    close: '}' | ']';
}

end is exclusive. The function returns undefined when the expected opening delimiter is absent or the group is unclosed.

Call relationships ​

ts
const group = readLatexGroup('  {outer {inner}}', 0);
// group.content === 'outer {inner}'

Use bracket mode for optional arguments:

ts
readLatexGroup(source, index, { delimiter: 'bracket' });

See also ​

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