2013-05-20 67 views
1

我無法定義彼此不衝突的粗體和下劃線組合。單個下劃線勝過粗體和下劃線的一部分。有關如何區分它們以避免衝突的任何想法?我想保留每個LaTeX命令作爲單獨的顏色。LaTeX/font-lock - 着色粗體/下劃線;膽大;下劃線

粗體&下劃線:{\bf\uline{insert-text}}

下劃線:\uline{insert-text}

[注1:我不使用\underline,因爲它不能正確地換行多行]

[注2:可變碼對於插入文本也應該允許我強調某些關鍵字落在該可變代碼內。]

[註釋3:同樣的問題可能會出現用粗體發生分開:{\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 

)) 
+0

嗯。在'init.el'中改變'\ uline {insert-text}'的定義順序,使它位於'{\ bf \ uline {insert-text}}'之前可能已經成功了。我不知道我明白爲什麼,但它似乎有效。換句話說,切換兩個列表的順序。 。 。連接定義似乎可以解決問題。 – lawlist

+0

我會在第二天左右發佈答案。'init.el'中條目的順序很重要,但我並不完全理解爲什麼是這種情況。 – lawlist

回答

0

在其中條目顯示將(在某些情況下)控制是否後續條目王牌先前條目的順序。以下示例使用特定的順序,以便後續組勝過先前組 - lawlist-keywords將在LaTeX代碼的變量文本區域內突出顯示。這個例子中沒有包括面孔的定義 - 這些也必須闡明。

(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 

)) 
1

在你的規則,你已經在你的規則中指定的「T」爲「重寫」標誌:

(1 lawlist-regular t) 

的「T」的含義是,以取代現有fontification。

相反,嘗試:

(1 larlist-regular append) 

這會將新fontification添加到現有的。

從Emacs的可變font-lock-keywords的文檔:

MATCH高亮應該是以下形式:

(SUBEXP面名[OVERRIDE [LAXMATCH]])

[... ]

OVERRIDE和LAXMATCH是標誌。如果OVERRIDE是t,現有的 可以被覆蓋。如果keep,只有不是已經形成 的部分被突出顯示。如果prependappend,現有的 分成合並與新的,其中新的或現有的分別優先。

+0

非常感謝。我用/不用't'標誌做了一些試驗,還用了'append'這個詞。爲了處理我定義的類似定義之間的各種衝突,我的字體鎖定義正在發展並變得更加複雜,並且與AUCTeX包中包含的定義衝突。在這一點上,我的偏好是完全控制自己的定義,排除AUCTeX - 但是,我想讓這個軟件包保持活躍狀態​​。在這個特定的線程中的問題最終是按時間順序排列的,即順序很重要。 – lawlist