2

When inserting a reference in a LaTeX document (using Auctex) I normally type:

\cite{joebob_2010}

where "\cite" shows up in blue font, while "joebob_2010" shows up reddish/purple. I like this coloring. However, when I use

\citep{joebob_2010}

all text shows up white.

In my .emacs file I put:

(add-hook 'LaTeX-mode-hook
    (lambda ()
      (font-lock-add-keywords nil   '(("\\(\\\\citep\\)\\s-*{" 1 font-lock-keyword-face t)))
      (font-lock-add-keywords nil   '(("\\(\\\\citet\\)\\s-*{" 1 font-lock-keyword-face t)))
      ))

This changed the color of "\citep" to blue, but the reference to "joebob_2010" remains white. Can I modify this to have the same coloring as "\cite{joebob_2010}"?

EDIT/SOLUTION

I posted a bug report to the gnu group for Auctex and found out there was no bug after all. The following solution works. In the .emacs file, put:

;; set special font highlighting for \cite* commands
(add-hook 'LaTeX-mode-hook
     (lambda ()
       (font-lock-add-keywords nil  '(("\\(\\\\citep\\)\\s-*{" 1 font-lock-keyword-face t)))
       (font-lock-add-keywords nil  '(("\\(\\\\citet\\)\\s-*{" 1 font-lock-keyword-face t)))
       (font-latex-add-keywords '(("citep" "*[[{")) 'reference)
       (font-latex-add-keywords '(("citet" "*[[{")) 'reference)
       ))

Adding the keywords at the end is the key.

8
  • Replace your code with (setq TeX-parse-self t)in your init file and restart Emacs. Auctex should then load the relevant style (natbib.el or biblatex.el) and fontify the macros respectively. Oct 6, 2016 at 4:20
  • Thanks, but that did not work. Using this solution not even the "\citep" is colored. I searched around and was able to find the natbib.el file, but not the bitlatex.el. Would you suggest that some configuration needs changed?
    – tnknepp
    Oct 6, 2016 at 12:59
  • Which AUCTeX version are you using? I suggest you update to latest version and check that biblatex.el is in a path mentioned in TeX-style-path variable. The easiest way is to use elpa to update AUCTeX. Oct 6, 2016 at 19:01
  • Strange. I am running 11.89.5 and my biblatex.el file is in the TeX-style-path. If you have any more suggestions I would love to hear them, but, since this is an aesthetics issue I can just let it go for now...though it will continue to bug me.
    – tnknepp
    Oct 6, 2016 at 19:51
  • My last bet is that you open your file and hit C-c C-n. You are missing a lot of features provided by that style; you should get it running. Oct 6, 2016 at 20:20

1 Answer 1

3

You can find the solution in the manual ((info "(auctex)Fontification of macros")):

Highlighting of macros can be customized by adapting keyword lists which can be found in the customization group font-latex-keywords.

Thus you have to issue M-x customize-group RET font-latex-keywords RET and then add to the "Font Latex Match Reference Keywords" variable the new entry with citep as "keyword" field and *[[{ as "format" field.

In alternative, you can add the following lines to your init file:

(add-hook
 'LaTeX-mode-hook
 (lambda ()
   (font-latex-add-keywords '(("citep" "*[[{")) 'reference)
   (font-latex-add-keywords '(("citet" "*[[{")) 'reference)))

Cross-reference: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24667

0

Your Answer

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

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