1

So first, i define new environment (or new theorem) like

\newtheorem{cor}{Corollary}

For convenience, I want

C-c C-e cor RET

then it display

\begin{cor}
\label{cor:*document name*:number}

\end{cor}

For align environment, it really did auto labeling but for others i don't know how to do

I manage to do config label prefix rule ( if i do C-c ( inside cor enviroment then \label{cor:*document name*:number} appears) ,which is already nice but typing C-c ( every time is time-consuming i think.

I thought it will be cool that emacs automatically create label for thm,cor,prop...etc just like equation

Plz help me

  • Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}. Off-topic: you could use code style button – Bobyandbob Aug 9 '17 at 8:27
  • @Bobyandbob an MWE does not really make sense here, as this is not really a LaTeX problem, but rather a question for an editor. – daleif Aug 9 '17 at 8:33
  • 1
    You are probably more likely to get help on this issue, if you ask on the auctex/reftex (this part is reftex domain) mailing list, se gnu.org/software/auctex/mailing-lists.html – daleif Aug 9 '17 at 8:35
  • thanks! i thought it is related to latex but as i see your responses it might be not. It is a problem somewhere between emacs and latex... tricky. If anyone has a idea, plz continue to reply. Ah, and i will follow MWE next time. It's my first time to post, sorry for that. – Agisak Aug 9 '17 at 10:14
1

You can tell Emacs to do what you want by making additions to the variables LaTeX-label-alist and reftex-label-alist. I don't recommend putting these changes in your .emacs, I would add them as local variables to your .tex file (or even better write your own AUCTeX style file for it).

Your file can look like this -- note that I use ntheorem for new definition:

\documentclass{article}

\usepackage{ntheorem}
\newtheorem{cor}{Corollary}

\begin{document}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% eval: (add-to-list 'LaTeX-label-alist '("cor" . "cor:"))
%%% eval: (add-to-list 'reftex-label-alist '("cor" ?c "cor:%f:" "~\ref{%s}" nil ("Corollary" "corollary") nil))
%%% End:

When you load this file, Emacs will ask you if you want to apply the local variables, say y. Next, hit C-c C-n to parse the file and enter C-c C-e cor RET RET. The result should look like this:

enter image description here

Please read RefTeX manual regarding the details about reftex-label-alist.

  • thanks. What i want to find is LaTeX-label-alist! ( I think the second "cor:" must be the prefix rule for labeling but i strongly guess that reftex overwrite it to cor:%f:) Also, i could learn file variable( local variable) in emacs this time. Really appreciate. – Agisak Aug 16 '17 at 11:29

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.