3

It would be better to have uniform syntax highlighting for both \citep and \cite as it appears quite a lot in my manuscript.

I tried to implement what was suggested in here like so

(setq font-latex-match-reference-keywords
  '(
    ("citeauthor" "[{")
    ("citep" "[{")))

The above lines were added to my ~\.emacs\init.el file. Though it works for \citeauthor, it doesn't effect \citep which still appears sedated.

Is there a solution to make this work?

  • 1
    Are you using natbib or biblatex? And which AUCTeX version do you have installed? – Arash Esbati Apr 12 '17 at 06:44
  • 1
    @ArashEsbati, the AUCTeX version is 11.88; I'm running pdflatex without natbib package. I'm working with elsarticle class and I doubt it uses biblatex. – Ébe Isaac Apr 12 '17 at 08:38

1 Answers1

4

There are 2 solutions for your question.

Prerequisite

Update AUCTeX to latest version 11.90. I suggest you do it via ELPA as described in the manual. If you do so, please also read Quick Start. And definitely put this in your init file:

(setq TeX-parse-self t)

Quick fix solution

elsarticle.cls internally loads natbib, graphicx and some other packages. AUCTeX does not parse the .cls file to be aware of this. You can give AUCTeX a hint by loading these packages again in the preamble of your .tex file. With TeX-parse-self set to t, AUCTeX loads its support files (jargon: style files) for these packages and your file will look like this:

enter image description here

Also note that now you get auto-completion support for macros provided by natbib when you hit C-c C-m citep RET. Things get even better if you use RefTeX.

Long-term solution

This includes writing an AUCTeX support file elsarticle.el. For what you're asking, the following lines will be sufficient:

;;; elsarticle.el --- AUCTeX style for `elsarticle.cls'

(TeX-add-style-hook
 "elsarticle"
 (lambda ()
   (TeX-run-style-hooks "natbib" "graphicx" "geometry")))

Customize the variable TeX-style-private to a directory of your choice, e.g.

(setq TeX-style-private (expand-file-name "~/.emacs.d/auctex-styles"))

Save elsarticle.el in that directory, restart Emacs and load your .tex file. This should then work without reloading natbib and graphicx in your preamble.

Arash Esbati
  • 7,416
  • Updating AUCTeX through ELPA solved the problem ((setq TeX-parse-self t) was in my init.el all the time). So guess that this was some sort of bug in the 11.88 version. Thank you very much. – Ébe Isaac Apr 12 '17 at 10:18
  • For me it works by putting the (TeX-add-style-hook ...) for the custom dtx file in my .emacs. – Christian Herenz Oct 08 '19 at 01:00
  • @ChristianHerenz - This is exactly what I don't recommend: Polluting a .emacs with code where AUCTeX provides a clear interface for. – Arash Esbati Oct 10 '19 at 19:37
  • For me it appears much easier to have just one file that I sync between all my machines that contains ALL my settings and customisations. Note that I forgot that the construct needs to be put in the (with-eval-after-load "tex" ... ) construct. – Christian Herenz Oct 11 '19 at 21:30