luasnip-latex-snippets.nvim icon indicating copy to clipboard operation
luasnip-latex-snippets.nvim copied to clipboard

Idea: Dynamic Snippets For `/newcommand`(s) Defined In File

Open michaelfortunato opened this issue 9 months ago • 2 comments

I often create a few \newcommand(s) in the current tex file I am working on. I was thinking a cool feature could be to create a snippet that would read the \newcommand it found in the current file and expand to one of them.

For instance, say I have the tex file with two \newcommand(s) defined.

% ...
\newcommand{\plusbinomial}[2]{(#1 + #2)^2}
\newcommand{\z}[1]{W^{\[#1\]}\a^\{#1 - 1\} + b^\{#1\}}
% ...

It would be cool if I could type cmd1, and have a snippet that expands to \plusbinomial{}{} and cmd2 expand to \z{}.

What do you think?

michaelfortunato avatar Feb 20 '25 00:02 michaelfortunato

Reminds me I need to make some snippets for \newcommand and \NewDocumentCommand and the like, so I'll do that first.

At least for me I'd find the snippets pretty helpful but maybe with the following changes:

  • Defining a file where the \newcommands are located, as I usually have these in my preamble
  • Adding a comment defining the trigger - cmd1 and cmd2 might be hard to remember
% ...
\newcommand{\plusbinomial}[2]{(#1 + #2)^2} % trig1
\newcommand{\z}[1]{W^{\[#1\]}\a^\{#1 - 1\} + b^\{#1\}} % trig2
% ...

I think this should be pretty feasible to implement with some time, but I don't think I'll be able to get to it for a while.

evesdropper avatar Feb 21 '25 19:02 evesdropper

Definitely! Yeah I thought about making a pull request here too, but I'll need to find time after the quarter. Cool to know you think it would be helpful too. Thanks. Edit: Moved to typst!

michaelfortunato avatar Feb 21 '25 19:02 michaelfortunato