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 |
Require a word boundary before the trigger. 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, b only apply to bare-word triggers — a regex trigger's pattern is the whole boundary condition.
Code blocks
Splice in JavaScript between double backticks; assign to rv to produce output:
snippet `([a-zA-Z])(\d)` "auto subscript" wAm
``rv = m[1] + '_' + m[2]``
endsnippet
Available inside: m (regex capture groups), t (tabstop contents), 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, higher wins on a tie).
File naming and merging
A file's name (minus .snips) is matched against the document's language ID — latex.snips for .tex, pretext.snips for .ptx. all.snips applies everywhere.
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 LaTeX math context — $...$, $$...$$, \(...\), \[...\], or a math environment (equation, align, cases, pmatrix, ...) — including \text{} correctly switching back to prose mid-formula.
Multi-field snippets
Two or more tabstops (\frac{$1}{$2}) get a real native Tab session. Zero or one tabstop is inserted as plain text with the cursor placed directly, 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.
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. Defaults to atexptxsnipsfolder alongside VS Code's ownUserdirectory.


