# Prompt for inserting label when using theorem style environments in latex

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}

$$\label{eq:1}$$
\end{document}


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"
(lambda () (add-to-list 'LaTeX-label-alist '("lem" . "lem:"))))
(when (boundp '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.

• 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
Nov 22 '16 at 16:14
• Unfortunately the second solution does not for me either.
– Name
Nov 22 '16 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"? Nov 22 '16 at 17:28
• Yes I see the entry for "lem" in LaTeX-environment-list.
– Name
Nov 23 '16 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. Nov 23 '16 at 9:22