# latex-mode / font-lock: any way to obtain more than three (3) levels of highlighting?

With latex-mode, is there any way to obtain more than three (3) levels of highlighting?

I would like to control more than three levels of highlighting, however, it appears as though latex-mode may be limited to three (3) levels. I say this because Emacs complains when attempting a fourth level -- Error during redisplay: (jit-lock-function 1) signaled (wrong-type-argument listp prepend). The following is just an example of an attempt to control four (4) levels, which gave the error message listed above.

(defvar lawlist-face-a (make-face 'lawlist-face-a))
(set-face-attribute 'lawlist-face-a nil :foreground "orange")

(defvar lawlist-face-b (make-face 'lawlist-face-b))
(set-face-attribute 'lawlist-face-b nil :foreground "cyan")

(defvar lawlist-face-c (make-face 'lawlist-face-c))
(set-face-attribute 'lawlist-face-c nil :foreground "blue")

(defvar lawlist-face-d (make-face 'lawlist-face-d))
(set-face-attribute 'lawlist-face-d nil :foreground "red")

("\$$\\\\begin\\|\\\\end\$$\$$\{\$$\$$document\$$\$$\}\$$" (1 lawlist-face-a) (2 lawlist-face-b) (3 lawlist-face-c) (4 lawlist-face-d) prepend)

))


I tried adding (setq font-lock-support-mode 'lazy-lock-mode), which caused a freeze. I also tried adding (setq font-lock-maximum-decoration t), which didn't seem to have any appreciable effect.

-

The prepend atom needs to be outside the quoted list, as the last argument to font-lock-add-keywords:
(font-lock-add-keywords
'(("\$$\\\\begin\\|\\\\end\$$\$$\{\$$\$$document\$$\$$\}\$$" (1 lawlist-face-a) (2 lawlist-face-b) (3 lawlist-face-c) (4 lawlist-face-d)))

I've noticed today that adding the letter t following each custom face is necessary sometimes if there are other definitions that potentially conflict -- e.g., begin is, of course, one of the most common commands and the custom colors needed that extra t to make everything work correctly. –  lawlist May 20 '13 at 2:22
You're confusing two things here. The third argument to font-lock-add-keywords controls how these keywords are added to the existing ones. By using a non-nil (and not set) the keywords are appended to the existing set, i.e. the opposite of prepend. On the other hand, prepend can be used inside a rule to tell font-lock to add it's colors in front of other existing colors, however, you need to specify it for each highlight rule as in (1 lawlist-face-a prepend) (2 lawlist-face-b prepend) .... –  Lindydancer May 20 '13 at 9:26
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 1, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.6754631996154785, "perplexity": 6426.175701400651}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2015-18/segments/1429246643283.35/warc/CC-MAIN-20150417045723-00183-ip-10-235-10-82.ec2.internal.warc.gz"}