Suppose I have a lot of small text snippets (including some LaTeX-code).

Now I want to create a LaTeX document with emacs which includes some of the text snippets. I know yasnippet which can expand keywords to the snipped but that's not what I want. Instead I am looking for something like this:

  • Invoke an emacs command insert-snippet
  • Then I can browse, search filter and select one (or at best also multiple snippets)
  • The snippets should not be copied to the file but included via an LaTeX input statement say \input{snippet1} (or if multiples are selected: \input{snippet1} \input{snippet5}.

If I edit the main file and point is on say \input{snippet3} there should be a command to view the content of this snippet (any maybe replace it by another one).

The approach described above seems to require that each snippet is saved in a separate file - otherwise the \input statement wouldn't work. However this seems to make it harder to edit the snippets. Maybe one option would be to edit them using the multifiles package (then you can edit them just as they where one file) or just grep them with helm-do-grep and browse it with executing helm-persistent-action...

Another idea would be to use another command instead of \input like \ExecuteMetaData[inputfile]{mytag1} from the catchfilebetweentags package. Then you could store them in one file.

Another option would be to store the snippets in one file like

Snippet Text

Some text or comments.

Snippet Text

And then input \mysnippet2 instead of \input{mysnippet2}.

If no library exists which does what I want, what would you suggest where to start to realize this by myself?

  • This sounds like a project for an entire library dedicated to this feature, and not within the scope of something that is answerable within this forum unless the library already exists. The library browse-kill-ring uses a list to generate possible insertions, and it may be possible to borrow some of that functionality by gathering the contents of the snippets and offering them as options. I'm not suggesting that browse-kill-ring is the answer -- I'm only suggesting that seeing what makes it tick might be helpful when creating your own library. – lawlist Jul 23 '16 at 16:13
  • @lawlist Yes the question is not about programming a new library but maybe there is one which does this to 90% and with some modifications it does what I want. – student Jul 23 '16 at 16:16
  • Do you think that also reftex (inserting bibtex citations) could be a starting point? – student Jul 24 '16 at 7:19
  • Perhaps another forum participant can comment on the idea of borrowing the functionality of reftex (inerting bibtex citations); however, I am not familiar with that aspect of the AUCTeX library. – lawlist Jul 24 '16 at 15:08

This might do what you want: store your 'snippeds' in a .tex file, and use use AucTex's auto-complete to look them up for you.

e.g., main.tex:



``\mysnippedA'' is a macro. I have a second macro: \mysnippedB.



Snipped Text

More snipped text!

You need to set a few variables to get the files parsed (i.e., so AucTex knows which macros to complete):

 (setq TeX-parse-self t) ; Enable parse on load.
 (setq TeX-auto-save t)

Alternatively, you can call C-c C-n to manually reparse the files.

Once that's done, C-c C-m or C-c RETURN, (TeX-insert-macro) will prompt you for macro name completions, which now include your custom definitions.

More details in the AucTex Manual: (auctex) Completion, (auctex) Parsing Files,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.