Snippets With Regular Expressions

It’s been years since I wrote about Gilles Castel and his astounding ability to take LaTeX notes so fast that he was able to keep up with the the instructor in his Mathematics classes. Sadly, Castel died in 2022 but his blog—including the two posts [1, 2] that deal with taking Mathematics notes with the associated diagrams—is still up.

Castel used Vim so he didn’t have AUCTeX but he did have a large collection of UltiSnips snippets that he used to make entering LaTeX fast and relatively painless. One feature of UltiSnips that he leveraged was the ability to specify the trigger word with a regular expression. For example, he uses that capability to recognize subscripts so that a2a_2. See his post for other examples.

Naturally, we Emacs nerds went crazy and attempted to replicate his system in Emacs. Karthink had a particularly good solution using AUCTeX, CDLaTeX, and YASnippet. Still it would be nice to be able to specify triggers with a regex.

Over at the Emacs subreddit, nmorazotti has a solution. He’s put together a snippet package, Resnippets.el, that can recognize a regex as a trigger. If you’ve been yearning to try Castel’s approach to taking LaTeX notes, resnippets may be useful.

I won’t be using it for two reasons. First it’s LLM generated and I have a prejudice—rational or not—against AI generated code. Second, and probably more important, is that the snippets are all autoapplied. I HATE that. I want to explicitly invoke the snippet with a Tab. Actually, UltiSnips has this right. By default you invoke its snippet explicitly but you can, on an individual snippet basis, choose to have them invoked automatically.

I don’t know if anyone is still interested in all this but it was fun for me to revisit it.

This entry was posted in General and tagged . Bookmark the permalink.