0

I have started using Emacs a couple weeks ago and so far I got it to do pretty much everything I wanted. Recently, I started using Emacs and AUCTeX to write a GUI specification document. For each GUI element I have a corresponding LaTeX snippet that I can insert in the specification to start from, like this, for example:

\item \texttt{Button}
    \begin{description}
        \item[Label]    Here I add a description for the wanted button label...
        \item[Readonly] etc...
        \item[Enabled]
        \item[Visible]
        \item[Tooltip]
        \item[Alternate control]
        \item[Events]
        \item[Misc]
    \end{description}

To include it in the specification, I cut and paste it from another document. Copying and pasting works, but is tedious. What I would like to achieve with Emacs and AUCTeX is to type, from within Emacs, something like M-x button so that it adds the corresponding code snippet directly from the current cursor position. I'd like this snippet to be available only when a .tex file is opened.

How can I do this?

1

Check out YASnippet Emacs package. M-x package-install RET yasnippet. Might find this useful or just Google for examples: tutorial Once installed and you have (yas-global-mode t) in your .emacs file, it will show a menu bar YASnippet.

Once YASnippet is installed try this. Save the following in a file ~/.emacs.d/snippets/latex-mode/test.yasnippet

# -*- mode: snippet -*-
# name: test
# key: test_
# --
\item \texttt{Button}
    \begin{description}
        \item[Label]     ${1:Add description}
        \item[Readonly] etc...
        \item[Enabled]
        \item[Visible]
        \item[Tooltip]
        \item[Alternate control]
        \item[Events]
        \item[Misc]
    \end{description}$0

Then when you type "test_" TAB it should insert your code at point. Once you type in your description press TAB it will take you to the end of your code. The $1, $2, etc is the location of the cursor after each TAB, $0 is last TAB.

  • The tutorial looks promising! – BobMorane Jan 3 '18 at 10:19
  • This works very well. – BobMorane Jan 3 '18 at 10:32

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.