Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>TeXPtxSnipsNew to Visual Studio Code? Get it now.
TeXPtxSnips

TeXPtxSnips

Kyle Monette

|
37 installs
| (0) | Free
Snippets for LaTeX and PreTeXt documents.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Version Version Version

TeXPtxSnips

Snippet engine for LaTeX and PreTeXt in VS Code.

Forked from HyperSnips V2 (itself descended from hsnips and UltiSnips) to fix a handful of tabstop bugs and add PreTeXt support.

Quick start

Run TeXPtxSnips: Open Snippets Directory from the Command Palette, then add a file named after the language you want: latex.snips, pretext.snips, or all.snips for snippets shared across both. A minimal example:

snippet mk "inline math" A
\$$1\$
endsnippet

Type mk in a .tex file and it expands immediately, cursor left between the two $. Save the file (or run TeXPtxSnips: Reload Snippets) to pick up changes.

The .snips file format

Snippets

snippet trigger "description" flags
body text with $1 $2 tabstops
endsnippet

trigger is a bare word (mk) or a backtick-delimited regex (`([a-zA-Z])(\d)`), matched against the text right before the cursor. Capture groups are available in the body as m[1], m[2], etc.

The body uses standard VS Code snippet syntax: $1, ${1}, ${1:default text}, $0 for the final cursor position. Escape a literal $, \, or } as \$, \\, \}.

Flags

Flag Meaning
A Expand immediately on match, no Tab needed.
i Match anywhere, including mid-word.
w Don't match right after a letter, digit, or underscore. Default when i/w are both omitted.
b Only match at the start of a line (whitespace before it is fine).
m Only match inside math mode.
h Hide from the completion list; still expands via A or Tab.

i, w only apply to bare-word triggers — a regex trigger's pattern is the whole word-boundary condition. b applies to both: even for a regex trigger, it independently requires nothing but whitespace before the match. In a regex trigger, ^ only matches at column 0; use b to also allow leading whitespace.

Code blocks

Splice in JavaScript between double backticks; assign to rv to produce output (a block that never assigns rv inserts nothing):

snippet `([a-zA-Z])(\d)` "auto subscript" Am
``rv = m[1] + '_' + m[2]``
endsnippet

Available inside: m (regex capture groups), w (workspace path), path (current file path). rv is spliced in as-is, so it can contain real snippet syntax (rv = '\\frac{' + m[1] + '}{$1}$0') — escape any $ you don't want treated as a tabstop.

global blocks and priority

global
function today() {
	return new Date().toISOString().slice(0, 10);
}
endglobal

snippet date "today's date" A
``rv = today()``$0
endsnippet

A global block runs once on load; its functions and constants are visible to every code block in the file. priority N applies to the single snippet that follows it (default 0). When several snippets match at the cursor, the highest priority wins; on equal priority, snippets from the language's own file win over all.snips, then whichever is defined first.

Syntax highlighting

.snips files get their own highlighting out of the box — triggers, flags, tabstops, and code blocks (with real JavaScript inside).

Math mode

The m flag gates a snippet on math context.

In .tex files, that's $...$, $$...$$, \(...\), \[...\], or a math environment (equation, align, etc.).

In .ptx files, that's the body of a math element — <m>, <me>, <men>, <md>, <mdn>, <mrow>.

Multi-field snippets

Two or more tabstops (\frac{$1}{$2}) get a real native Tab session, as does a snippet using a mirrored tabstop (\begin{$1}...\end{$1}), a choice, or a variable. Anything else (zero or one tabstop) is inserted as plain text with the cursor placed directly (a tabstop's default text is selected, as in a native snippet), indented to match the line just like a native snippet, which is what lets several A-flagged shortcuts chain inside one $...$.

Manual expansion

A snippet without A doesn't expand as you type — press Tab right after typing it. When an inline suggestion (e.g. Copilot's grey text) is showing, Tab accepts that instead.

Commands and settings

  • TeXPtxSnips: Reload Snippets — re-read all .snips files (also happens automatically on save).
  • TeXPtxSnips: Open Snippets Directory — create (if needed) and reveal the snippets folder.
  • texptxsnips.snippetsDir — override the snippets folder (a relative path, like ~, starts from your home folder). Defaults to a texptxsnips folder inside your editor's own User settings folder (e.g. ~/Library/Application Support/Code/User/texptxsnips for VS Code on macOS, or the Code - Insiders / VSCodium / Cursor equivalent).
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft