Emacs AUCTeX 宏字体突出显示

4

我最近开始使用优秀的包xargs,其中提供了\newcommandx。它与默认的\newcommand具有类似的语法。我希望font-lock能够反映这一点。我已经尝试过

(custom-set-variables
 '(font-latex-user-keyword-classes
   (quote (("cx" ("newcommandx" "*|{\\[[{")
        (:family "font-lock-type-face") command)))))

但是这只是字体化了命令本身,而不是它的主体(\newcommand'font-lock-function-name-face 来使主体字体化,而在我的情况下是粗体)。我想让 \newcommandx'font-lock-function-name-face 来使其主体字体化。

总结一下问题:如何使 \newcommandx 的字体化与 \newcommand 完全相同(即在我的情况下为粗体)?


我已经根据你的问题更新了答案,并在OSX Mountain Lion上使用Emacs / Aquamacs的夜间构建版本进行了测试。 使用此示例,\newcommandx{cmd}[args]{def}现在的行为类似于\newcommand{cmd}[args]{def}。请参见auctex--11.86内的font-latex.el第301行。 - lawlist
1个回答

5
以下是您可以根据自己的需要进行修改的示例。有关预定义关键字的完整列表,请参见中的280至436行。以下示例用于添加其他关键字和/或定义波浪线/方括号内容的自定义颜色。
;; \EFFECT{[font-lock-function-name-face]}
(setq font-latex-match-function-keywords
    '(
        ("newcommandx" "*|{\\[[{")
    )
 )


;; \EFFECT{[font-lock-constant-face]}
(setq font-latex-match-reference-keywords
    '(
        ("fancypagestyle" "[{")
        ("fancyhead" "[{")
        ("fancyfoot" "[{")
    )
 )


;; \EFFECT{[font-lock-type-face]}
(setq font-latex-match-textual-keywords
    '(
        ("parentext" "{")
        ("hybridblockquote" "[{")
        ("parskip" "")
        ("footskip" "")
    )
)


;; \EFFECT{[font-lock-variable-name-face]}
(setq font-latex-match-variable-keywords
    '(
        ("newgeometry" "[{")
        ("quotingsetup" "[{")
        ("TabPositions" "[{")
        ("rfoot" "")
    )
)


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


;; only affects inside wavy brackets
(setq font-latex-user-keyword-classes
          '(("my-warning-commands"
                (("fixme" "{"))
                (:foreground "purple" :background "yellow")
                command)))

另请参阅: http://www.gnu.org/software/auctex/manual/auctex/Fontification-of-macros.html
我选择了以下方法来自定义所有特殊关键词:
(defvar lawlist-face-01 (make-face 'lawlist-face-01))
(set-face-background 'lawlist-face-01 "black")
(set-face-foreground 'lawlist-face-01 "white")
(set-face-bold-p 'lawlist-face-01 t)
(set-face-italic-p 'lawlist-face-01 t)
(set-face-underline-p 'lawlist-face-01 t)
(set-face-underline 'lawlist-face-01 "yellow")

(defvar lawlist-face-02 (make-face 'lawlist-face-02))
(set-face-attribute 'lawlist-face-02 nil :background "gray" :foreground "red" :font "Courier" :height 180 :bold t :underline "yellow" :italic t)

(font-lock-add-keywords 'latex-mode '(
("\\\\test01\\|insert\\|BUGS\\|FIXME\\|TODO\\|and\\|or\\|not" 0 lawlist-face-01 prepend) ;; 0 = highlight all
("\\\\test02\\|INSERT\\|document-name\\|\\\\begin{document}" 0 lawlist-face-02 prepend) ;; 0 = highlight all
("\\test01{\\([^}]*\\)}" 1 lawlist-face-02 prepend) ;; 1 = colorize contents of wavy brackets
))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接