TeXPtxSnipsSnippet 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 startRun TeXPtxSnips: Open Snippets Directory from the Command Palette, then add a file named after the language you want:
Type The
|
| 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
.snipsfiles (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 atexptxsnipsfolder inside your editor's ownUsersettings folder (e.g.~/Library/Application Support/Code/User/texptxsnipsfor VS Code on macOS, or theCode - Insiders/VSCodium/Cursorequivalent).


