I ended up editing the AUCTeX
file font-latex.el
. I did not find a way to change this via my personal configuration file. Roughly, I had to (1) alter the order in which "ocurrences" of font-latex-sedate-face
and font-latex-math-face
are added in a list and (2) change what the function font-latex-match-simple-command
finds by editing the variable font-latex-match-simple-exclude-list
. When the editing of font-latex.el
is done, I needed only to recompile the package. [If you are a Doom Emacs user, running doom build
(usually run after upgrading Emacs) takes care of that.]
(1) In font-latex.el
, in the end of the definition of the function font-latex-make-user-keywords
we have:
(dolist (item
'((font-latex-match-math-env
(0 'font-latex-warning-face t t)
(1 'font-latex-math-face append t))
(font-latex-match-math-envII
(1 'font-latex-math-face append t))
(font-latex-match-simple-command
(0 'font-latex-sedate-face append))
(font-latex-match-script
(1 (font-latex-script (match-beginning 0)) append))
(font-latex-match-script-chars
(1 (font-latex-script-char (match-beginning 1)) prepend))))
(add-to-list 'font-latex-keywords-2 item t))
I reordered this so that the result of the search done by the function font-latex-match-simple-command
receiving the face font-latex-sedate-face
takes precendence over the result of the searches font-latex-match-math-env
and font-latex-match-math-envII
receiving the face font-latex-warning-face
.
Remark: changing append
to prepend
in
font-latex-match-simple-command
(0 'font-latex-sedate-face append))
does force font-latex-sedate-face
precedence over font-latex-math-face
. However, it establishes precedence over other faces which we would not like it to override such as comments or the \foo
commands known by AUCTeX.
(2) I had to edit the variable font-latex-match-simple-exclude-list
adding parentesis and brackets to it:
(defvar font-latex-match-simple-exclude-list
'("%" "-" "," "/" "&" "#" "_" "`" "'" "^" "~" "=" "." "\"" "(" ")" "[" "]"))
The reason is to avoid TeX excerpts like \(X\)
being incorrectly fontified with font-latex-sedate-face
.
append
andprepend
.