2

I want the commands \largerpage and \addlines to be displayed in red (font-latex-match-warning-keywords) but cannot figure out how to do this. I found several posts, but non of this seems to work.

This is what I tried:

;; \font-latex-warning-face
(setq font-latex-match-warning-keywords
    '(
        ("addlines" "") 
    )
)

 (font-lock-add-keywords nil '(("\\(addlines\\) \\(largerpage\\)" 
                                 0
                                 'font-latex-warning-face)))

(font-lock-add-keywords 'latex-mode '(("addlines" 
                                            0
                                            'font-latex-warning-face)))

I am using GNU Emacs 24.5.1.

Stefan Müller
  • 303
  • 3
  • 8

2 Answers2

3

I found the solution: https://www.emacswiki.org/emacs/AddKeywords

(font-lock-add-keywords 'latex-mode
                        '(("addlines" . font-lock-warning-face)
                          ("largerpage" . font-lock-warning-face)))
Stefan Müller
  • 303
  • 3
  • 8
  • Shouldn't that be `"\\\\addlines"` and `"\\\\largerpage"` to add the leading (single) slash (doubly escaped)? I wanted to add `\cli{}` as a keywaord (command) and without slashes, any `cli` substring is coloured. – AstroFloyd Jul 27 '21 at 18:47
0

The documentation suggests to use the customization group font-lock-keywords. First visit a latex file to ensure AUCTeX is loaded, then do M-x customize-group font-latex-keywords, navigate to Font Latex Match Warning Keywords, INSert your keywords, apply Save for future sessions and restart emacs.

If the customization group is unknown, do M-: (require 'font-latex) first. (It's not clear to me when/why it's necessary.)

JeanPierre
  • 7,323
  • 1
  • 18
  • 37