1
votes

I'm having trouble defining bold and underline combinations that do not conflict with each other. A single underline trumps part of the bold and underline. Any ideas regarding how to distinguish them so that they do not conflict? I'd like to keep each of the LaTeX commands as separate colors.

Bold & Underline: {\bf\uline{insert-text}}

Underline: \uline{insert-text}

[NOTE 1: I don't use \underline because it cannot wrap multiple lines correctly.]

[NOTE 2: The variable code for insert-text should also permit me to highlight certain keywords that fall within that variable code.]

[NOTE 3: The same problem will likely happen with bold separately: {\bf insert-text}]

(font-lock-add-keywords 'latex-mode (list

    (list (concat "\\(\{\\)\\(\\\\bf\\)\\(\\\\uline\\)\\(\{\\)\\(\\(.\\|\n\\)+?\\)\\(\}\\)\\(\}\\)")
        '(1 lawlist-regular t)
        '(2 lawlist-red t)
        '(3 lawlist-blue t)
        '(4 lawlist-regular t)
        '(5 lawlist-bold-underline t)
        '(7 lawlist-regular t)
        '(8 lawlist-regular t))

    (list (concat "\\(\\\\uline\\)\\(\{\\)\\(\\(.\\|\n\\)+?\\)\\(\}\\)")
        '(1 lawlist-green t)
        '(2 lawlist-regular t)
        '(3 lawlist-underline t)
        '(5 lawlist-regular t))

    lawlist-keywords

))
2
Hmmm. Changing the definition order of \uline{insert-text} so that it precedes {\bf\uline{insert-text}} in the init.el may have done the trick. I'm not sure I understand why, but it appears to work. In other words, switching the order of the two list . . . concat definitions seems to resolve the issue. - lawlist
I'll post an answer in the next day or so. Order of the entries in the init.el matters, although I do not fully understand why that is the case. - lawlist

2 Answers

1
votes

In your rules, you have specified 't' as the 'OVERRIDE' flag in your rules:

(1 lawlist-regular t)

The meaning of 't' is to replace the existing fontification.

Instead, try:

(1 larlist-regular append)

This will add the new fontification to the existing.

From the documentation of the Emacs variable font-lock-keywords:

MATCH-HIGHLIGHT should be of the form:

(SUBEXP FACENAME [OVERRIDE [LAXMATCH]])

[...]

OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification can be overwritten. If keep, only parts not already fontified are highlighted. If prepend or append, existing fontification is merged with the new, in which the new or existing fontification, respectively, takes precedence.

0
votes

The order in which the entries appear will (under some circumstances) control whether subsequent entries trump prior entries. The following example uses a specific order so that subsequent groups trump prior groups -- lawlist-keywords will appear highlighted within the variable text area of the LaTeX code. The definition for the faces has not been included in this example -- those would also have to be set forth.

(defvar lawlist-keywords
    (list (concat "\\b\\(?:"
          (regexp-opt (list "FIXME" "TODO" "BUGS"))
          "\\)\\b") 0 'lawlist-red t))

 (font-lock-add-keywords 'latex-mode (list

    (list (concat "\\(\{\\)\\(\\\\bf\\)\\(\\(.\\|\n\\)+?\\)\\(\}\\)")
       '(1 lawlist-regular t)
       '(2 lawlist-purple t)
       '(3 lawlist-bold t)
       '(5 lawlist-regular t))

    (list (concat "\\(\\\\uline\\)\\(\{\\)\\(\\(.\\|\n\\)+?\\)\\(\}\\)")
        '(1 lawlist-green t)
        '(2 lawlist-regular t)
        '(3 lawlist-underline t)
        '(5 lawlist-regular t))

    (list (concat "\\(\{\\)\\(\\\\bf\\)\\(\\\\uline\\)\\(\{\\)\\(\\(.\\|\n\\)+?\\)\\(\}\\)\\(\}\\)")
        '(1 lawlist-regular t)
        '(2 lawlist-red t)
        '(3 lawlist-blue t)
        '(4 lawlist-regular t)
        '(5 lawlist-bold-underline t)
        '(7 lawlist-regular t)
        '(8 lawlist-regular t))

    lawlist-keywords

))