7

Adding additional highlighted keywords in Emacs+AUCTeX messes up conventional highlighting. My code:

(defvar my-new-face (make-face 'my-new-face))
(defvar my-another-new-face (make-face 'my-another-new-face))
(set-face-background 'my-new-face "Aquamarine")
(set-face-foreground 'my-new-face "Black")
(set-face-background 'my-another-new-face "Plum")
(set-face-foreground 'my-another-new-face "Black")


(font-lock-add-keywords
'latex-mode
'(("\\\\quad" 1 my-new-face prepend)
 ("\\\\label" 1 my-another-new-face prepend)))

Any suggestions how can I overcome this. Adding user keyword classes in Auctex customization menu doesn't highlight them in math-mode.

1 Answer 1

4

The code provided is "almost" OK: the error is that there are no subexpressions in the regular expressions for \quad and \label, so its an error to refer to subexpression 1: one should either use subexpression 0, i.e. the full regular expression, or define a subexpression. More explicitly:

(font-lock-add-keywords
 'latex-mode
 '(("\\\\quad" 0 my-new-face prepend)
  ("\\\\label" 0 my-another-new-face prepend)))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .