5

I have recently been trying auctex 11.88 on emacs 24.4(win7+mac). it's great so far!

I used to have the following in my .emacs emacs file when I was using auctex11.87 (I bumped into it on stackexchange somewhere)

(setq reftex-label-alist
  '(
    ("theorem" ?h "thm:" "~\\ref{%s}" t  ("theorem" "th."))
    ("lemma" ?l "lem:" "~\\ref{%s}" t  ("lemma" "lem." ))
    ("exercise" ?x "ex:" "~\\ref{%s}" t  ("exercise" "ex." ))
    ("question" ?q "ques:" "~\\ref{%s}" t  ("question" "q." ))
    ))

(add-hook 'LaTeX-mode-hook
   (lambda ()
     (LaTeX-add-environments
       '("lemma" LaTeX-env-label)
       '("exercise" LaTeX-env-label)
       '("theorem" LaTeX-env-label)
       '("question" LaTeX-env-label)
       )))

(setq  reftex-insert-label-flags '("s" "ft"))

It automatically generates a label when I insert a newly defined environment, say, when I run C-c C-e exercise RET, I get

\begin{exercise}
  \label{ex:1}
  (cursor here)
\end{exercise}

now in auctex11.88 I can only get

\begin{exercise}
  (cursor here)
\end{exercise}

I need to further run C-c ( to add \label{ex:1} there.

I'm not sure if the lisp code I was using gets out dated. I tried executing the short piece (LaTeX-env-label "exercise"). In auctex11.87 I get the desired result, but not in auctex11.88.

Please advise! Thanks very much!

BTW, is it really a bug which is early mentioned in the mail or should we adjust something else in auctex11.88? Some new feature + backward compatibility issue is mentioned in mailing list I'm not an expert on this, could anyone elaborate? thanks a lot!

6

AUCTeX and RefTeX are two separated and independent packages, one can be used without the other. AUCTeX has some facilities about labels and citations management, RefTeX is much better in doing this.

Not everyone uses RefTeX and there has been a change in AUCTeX 11.88 to let users choose which labels should be inserted. This selection is independent from RefTeX, but as a side effect people need to customize another AUCTeX (not RefTeX) variable: LaTeX-label-alist. Here is its description in the manual

User Option: LaTeX-label-alist

List the prefixes to be used for the label of each supported environment.

This is an alist whose car is the environment name, and the cdr either the prefix or a symbol referring to one.

If the name is not found, or if the cdr is nil, no label is automatically inserted for that environment.

If you want to automatically insert a label for a environment but with an empty prefix, use the empty string "" as the cdr of the corresponding entry.

So you should also add an entry to LaTeX-label-alist for the excercise environment. In your .emacs, replace the add-hook with this one

(add-hook
 'LaTeX-mode-hook
 (lambda ()
   (LaTeX-add-environments
    '("lemma" LaTeX-env-label)
    '("exercise" LaTeX-env-label)
    '("theorem" LaTeX-env-label)
    '("question" LaTeX-env-label))
   (add-to-list 'LaTeX-label-alist '("exercise" . "ex:"))))

To avoid confusion: AUCTeX decide whether the label should be inserted or not looking at LaTeX-label-alist, but if RefTeX is enabled, and in particular if LaTeX-label-function is reftex-label, the insertion of the label is transferred to RefTeX and the label actually inserted is chosen by the value of a RefTeX variable, reftex-label-alist.

For RefTeX users the value of the CDR of the exercise entry in LaTeX-label-alist is almost useless, the important it's that it's a valid string.

The point of customizing LaTeX-label-alist is to have the same behavior for RefTeX and non-RefTeX users.


For clarity, this is the minimal .emacs I used for testing:

;; Enable RefTeX automatically in AUCTeX buffers.
(autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
(add-hook 'TeX-mode-hook
      (lambda ()
        (turn-on-reftex)))
(setq reftex-plug-into-AUCTeX t)

;; RefTeX-related settings.
(setq
 reftex-label-alist
 '(("theorem" ?h "thm:" "~\\ref{%s}" t  ("theorem" "th."))
   ("lemma" ?l "lem:" "~\\ref{%s}" t  ("lemma" "lem." ))
   ("exercise" ?x "ex:" "~\\ref{%s}" t  ("exercise" "ex." ))
   ("question" ?q "ques:" "~\\ref{%s}" t  ("question" "q." )))
 reftex-insert-label-flags '("s" "ft"))

;; AUCTeX-related settings.
(add-hook
 'LaTeX-mode-hook
 (lambda ()
   (LaTeX-add-environments
    '("lemma" LaTeX-env-label)
    '("exercise" LaTeX-env-label)
    '("theorem" LaTeX-env-label)
    '("question" LaTeX-env-label))
   (add-to-list 'LaTeX-label-alist '("exercise" . "ex:"))))
  • Many thanks! But still no luck...I added what you suggested (almost) (add-to-list 'LaTeX-label-alist '("exercise" . "exx:")), but restarting emacs give me the error Symbol's value as variable is void: LaTeX-label-alist, and reloading the .emacs buffer did not casue any trouble. I checked that the variable 'LaTeX-label-alist is now changed with ("exercise" . "exx:") added. But back in the tex file C-c C-e exercise RET still does not work. Could you please look into this again? thanks. – davyjones Dec 13 '14 at 11:50
  • @davyjones There were two errors: I mistyped the name of the environment, and the exercise entry was added before the variable has been defined, that's why you got the void variable error, thanks for having pointed out it! I keep forgetting about it :-( Now it should work ;-) – giordano Dec 13 '14 at 12:19
  • the void error seems to go away after adding (require 'latex). I noticed the typo. But I never get the prompt for label after inserting environment. Even if I add label afterwards, I never get exx:1 as expected. Is anthing else need to be taken care of? thanks! – davyjones Dec 13 '14 at 12:24
  • @giodano, btw, I tried lgathered rgathered multlined in the bug report. None of them prompt for label. When I try to add label by C-c (, it prompt the section option sec:. Not sure if it's related. Also, trying (setq LaTeX-label-alist (append '( ("lemma" . "lemm:") ("exercise" . "exx:") ) LaTeX-label-alist)) does not work either. Thanks! – davyjones Dec 13 '14 at 12:36
  • Remove the require, it's not needed at all. If you use RefTeX, the inserting of the label is demanded to RefTeX and the actual label is inserted by RefTeX (so the final label prefix is chosen by RefTeX), the entry in LaTeX-label-alist is needed to decide whether a label should be inserted or not, the value of the prefix is not really important when you use RefTeX, the important is that's non nil. – giordano Dec 13 '14 at 12:37

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.