3

When inserting the environment equation (by C-c C-e equation) in latex-mode, emacs shows a prompt to insert a label. It is desirable to have the same prompt for a theorem-style environment like lem defined in the document. When I do C-c C-e lem, the environment lem is correctly inserted, but a prompt for setting the label does not appear.

What is the procedure in order to have this prompt?

\documentclass{article}
\usepackage{amsmath,amsthm}

\newtheorem{thm}{Theorem}
\newtheorem{lem}[thm]{Lemma}
\begin{document}
\begin{lem}

\end{lem}

\begin{equation}
  \label{eq:1}

\end{equation}
\end{document}

1 Answer 1

3

If you have an up-to-date version of AUCTeX, say from ELPA, you have 2 choices:

1.) Set something like to this in your init file:

(with-eval-after-load "latex"
  (add-hook 'LaTeX-mode-hook
    (lambda () (add-to-list 'LaTeX-label-alist '("lem" . "lem:"))))
  (when (boundp 'reftex-label-alist)
    (add-to-list 'reftex-label-alist
                 '("lem" ?m "lem:" "~ref{%s}" nil ("Lemma" "lemma") nil))))

2.) Set the information on a per-file basis in the local variables of your .tex file:

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% eval: (add-to-list 'LaTeX-label-alist '("lem" . "lem:"))
%%% eval: (add-to-list 'reftex-label-alist '("lem" ?m "lem:" "~ref{%s}" nil ("Lemma" "lemma") nil))
%%% End:

You need the second eval only when you're using RefTeX.

Then open your .tex file, hit C-c C-n so that AUCTeX parses your lem environment and you should be set.

5
  • 1
    I tested the first solution with auctex 11.89 and emacs 25.1, and after hit of c-c c-n and c-c c-e lem only a prompt for the Heading appears and the prompt for inserting label does not show up.
    – Name
    Commented Nov 22, 2016 at 16:14
  • 1
    Unfortunately the second solution does not for me either.
    – Name
    Commented Nov 22, 2016 at 16:21
  • @Name - For me, it works if I eval (C-x C-e) the two (add-to-list ...) in a .tex file and hit C-c C-n C-c C-e lem RET. What do you see if you hit C-h v LaTeX-environment-list RET and look for the "lem" entry? Also check the values of LaTeX-label-alist and reftex-label-alist when in your .tex file. Do you see the entries for "lem"? Commented Nov 22, 2016 at 17:28
  • Yes I see the entry for "lem" in LaTeX-environment-list.
    – Name
    Commented Nov 23, 2016 at 5:08
  • @Name - I updated my answer: For 1), I had to use LaTeX-mode-hook for LaTeX-label-alist. For 2), a ) went lost while pasting the code for reftex-label-alist. Please check again. Both solutions work for me. Commented Nov 23, 2016 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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