6

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.

3

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)))

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.