Context
For the past 18 months, I've been using the LaTeX Workshop extension of VSCode for all my LaTeXing needs. Up to this point, I've primarily used it for longer-form articles and reports, and sporadically for note-taking purposes in class. I've been able to make it work sufficiently well in real-time so far with just a few custom macros (Linear Algebra typesets pretty easily). However, as I move on to different classes, I'm looking to expand my real-time abilities by implementing Gilles Castel's excellent Vim-based workflow in VSCode. Unfortunately, VSCode seems to obscure or lack (by default) a great deal of the features (especially related to snippets) of which Castel makes use.
My Question
For the purposes of this post, I'd like to focus on his fraction macro (I believe that if I can get this working, I can get much of the rest of it working). Basically, the problem appears to be that VSCode has fairly limited snippets functionality, especially compared to Vim's UltiSnips. Using UltiSnips, Castel has defined an auto-expanding macro (I'm not sure if VSCode supports auto-expanding snippets) that, when a /
is typed, takes the preceding word (or words if parentheses are present) and transforms it into the LaTeX fraction format. For example:
// --> frac{}{}
3/ --> frac{3}{}
4pi^2/ --> frac{4pi^2}{}
(1 + 2 + 3)/ --> frac{1 + 2 + 3}{}
(1 + (2 + 3)/) --> (1 + frac{2 + 3}{})
(1 + (2 + 3))/ --> frac{1 + (2 + 3)}{}
How can I implement this behavior in VSCode?
My Leads
I have spent a significant amount of time researching this, and I have strong reasons to believe that it's possible, and similarly strong reasons to believe that any successful answer to my question is going to have to ELI5 it to me -- this kind of software customization isn't exactly my cup of soup, but I'm definitely willing to learn!
First off, there are two promising VSCode extensions that may be able to implement UltiSnips: Vsnips and HyperSnips. Vsnips looks decent, but it seems to rely on an existing familiarity with UltiSnips and how to configure UltiSnips for your specific computer (if this does end up being important, I use a 2019 MacBook Pro and my software is up to date [macOS Catalina 10.15.5 as of this post]). I haven't been able to figure out even that much with regard to HyperSnips -- neither is very well documented, and none of the documentation is written for readers of my level.
Although I said that VSCode's internal snippets engine appears to be fairly limited, I may be wrong. It seems to interface with another snippets engine called TextMate.
That's all I can think to do for now. If there's any further information that I can provide, please let me know! Thanks!
See Question&Answers more detail:os