Skip to content

stripLatexComments ​

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.

Removes or masks unescaped LaTeX line comments. Use remove for rendered text and mask when source line/offset relationships must remain meaningful.

Signature ​

ts
function stripLatexComments(
    text: string,
    options?: { mode?: 'remove' | 'mask' }
): string

Modes ​

ModeResult
remove (default)Deletes full comment lines and inline comments for preview text
maskReplaces each comment body with %, preserving line count and TeX comment semantics

Returns ​

A new source string. Escaped \\% sequences are preserved.

Call relationships ​

  • Called by: the early legacy comment-cleanup rule and source-stable metadata/scanner paths.
  • Independent from: skipLatexWhitespace, which advances an index without rewriting text.
ts
stripLatexComments('Text % hidden\nNext');
// 'Text Next'

stripLatexComments('Text % hidden\nNext', { mode: 'mask' });
// 'Text %\nNext'

Choose mask when offsets or line mappings must remain meaningful.

See also ​

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