Recently, I noticed that the VS Code extension for the Typst LSP added support for textmate scopes
, which means that I can now use HyperSnips snippets for my Typst files! 1 On another note, there’s also support now for contexts with the typst.vim
plugin in Neovim, just like in the vimtex plugin
. Now making it possible to have UltiSnips and LuaSnip work with Typst files as well.
Seeing as writing snippets for Typst is now possible with Neovim and/or VS Code. I set out last night to convert some of the snippets in Gilles Castel’s original blog post on his LaTeX snippets that I found useful for my own use.
In the process of porting over the snippets from \(\LaTeX\) to Typst, a lot of the snippets in Castel’s post are not applicable anymore just because Typst’s syntax is far easier, brief, and more convenient to write. For example, the fraction snippet in \(\LaTeX\) which involves using /
and regex in order to transform the 1/2
way of writing fractions into proper \(\LaTeX\) syntax is no longer necessary in Typst because fractions are now just 1/2
in Typst literally.2
Links #
These snippets are hacky and unpolished. They’re provided as is so use them at your own risk. The Typst snippets I made are available in my dotfiles repository:
Caveats #
A caveat for the HyperSnips snippets is that there is no such thing as a “VISUAL
” mode in VS Code like in Vim/Neovim, so the snippets that rely on it won’t work. To work around this, I used a suggested solution in the HyperSnips repo which makes use of the VS Code API which replaces the VISUAL
mode with TextMate’s TM_SELECTED_TEXT
variable.5
-
HyperSnips is a snippet engine for VS Code heavily inspired by vim’s UltiSnips. ↩︎
-
Scoping is also done, as you would expect, with parentheses which is good and a lot like written math instead of numerous curly brackets. ↩︎
-
These snippets require some reworking in order to work with the updates to the Typst LSP in VS Code. ↩︎
-
An example is this snippet which surrounds selected text with parentheses. ↩︎