自定义LaTeX评论环境的Emacs语法高亮显示

时间:2013-09-04 18:16:26

标签: emacs syntax-highlighting auctex

我已经定义了一个自定义评论环境(通过\usepackage{verbatim}):

\newenvironment{customComment}[1]
    {
    \noindent{\textsc{Commented bloc}: #1}}
    \comment}
        Commented block
    {\endcomment}

我想要做的是突出显示\ begin ... \ end {customComment}的内容:

  1. 作为已存在的环境(font-lock-comment-face可能但未找到任何工作示例);或
  2. 通过完整的字体/背景等自定义。
  3. 已经尝试过来自heredefvar...解决方案和(此次类似的命令this example

    如果您找到的解决方案只需要编辑.emacs or adding a。el`(我已经加载了这些customComments),那就太棒了。

2 个答案:

答案 0 :(得分:1)

如果原始海报(或其他任何人)可能有兴趣突出显示打开/关闭LaTeX代码之间出现的文本,以下是一些示例。活性成分是正则表达式(\\(.\\|\n\\)+?\\),它可能是其他类似的东西,但需要有效地做同样的事情。以下示例设置为突出显示LaTeX艺术家皱眉的引号之间的文本,粗体命令,下划线和使用名为ulem的tex包的双下划线,粗体和下划线,并且我投入了一个开头/ end document示例,以便原始海报(或其他任何人)可以组合这些示例来创建他/她自己。

注意:由于定义变得更加复杂并且倾向于与其他定义重叠,它们出现的顺序可能很关键 - 即,一个定义可能胜过另一个定义。

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

  (list (concat "\\(\"\\)\\(\\(.\\|\n\\)+?\\)\\(\"\\)")
    '(1 lawlist-super-orange t)
    '(2 lawlist-super-cyan t)
    '(4 lawlist-super-orange t))

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

  (list (concat "\\(\\\\uline\\|\\\\uuline\\)\\(\{\\)\\(\\(.\\|\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))

  (list (concat "\\(\\\\begin\\|\\\\end\\)\\(\{\\)\\(document\\)\\(\}\\)")
    '(1 lawlist-super-orange t)
    '(2 lawlist-super-SeaGreen t)
    '(3 lawlist-super-HotPink1 t)
    '(4 lawlist-super-SeaGreen t))

   ))


(defvar lawlist-regular (make-face 'lawlist-regular))
(set-face-attribute 'lawlist-regular nil
  :background "white" :foreground "black")

(defvar lawlist-bold (make-face 'lawlist-bold))
(set-face-attribute 'lawlist-bold nil
  :background "white" :foreground "black" :bold t)

(defvar lawlist-bold-underline (make-face 'lawlist-bold-underline))
(set-face-attribute 'lawlist-bold-underline nil
  :background "white" :foreground "black" :bold t :underline "black")

(defvar lawlist-underline (make-face 'lawlist-underline))
(set-face-attribute 'lawlist-underline nil
  :background "white" :foreground "black" :underline "black")

(defvar lawlist-bumble-bee (make-face 'lawlist-bumble-bee))
(set-face-attribute 'lawlist-bumble-bee nil
  :background "black" :foreground "yellow" :bold t :underline "red")

(defvar lawlist-red (make-face 'lawlist-red))
(set-face-attribute 'lawlist-red nil
  :background "white" :foreground "red" :bold t)

(defvar lawlist-blue (make-face 'lawlist-blue))
(set-face-attribute 'lawlist-blue nil
  :background "white" :foreground "blue" :bold t)

(defvar lawlist-green (make-face 'lawlist-green))
(set-face-attribute 'lawlist-green nil
  :background "white" :foreground "green3" :bold t)

(defvar lawlist-orange (make-face 'lawlist-orange))
(set-face-attribute 'lawlist-orange nil
  :background "white" :foreground "orange" :bold t)

(defvar lawlist-purple (make-face 'lawlist-purple))
(set-face-attribute 'lawlist-purple nil
  :background "white" :foreground "purple" :bold t)

(defvar lawlist-pink (make-face 'lawlist-pink))
(set-face-attribute 'lawlist-pink nil
  :background "white" :foreground "pink" :bold t)

(defvar lawlist-super-orange (make-face 'lawlist-super-orange))
(set-face-attribute 'lawlist-super-orange nil
  :background "white" :foreground "orange" :bold t :underline nil)

(defvar lawlist-super-cyan (make-face 'lawlist-super-cyan))
(set-face-attribute 'lawlist-super-cyan nil
  :background "white" :foreground "cyan" :bold t :underline nil)

(defvar lawlist-super-blue (make-face 'lawlist-super-blue))
(set-face-attribute 'lawlist-super-blue nil
  :background "white" :foreground "blue" :bold t :underline nil)

(defvar lawlist-super-red (make-face 'lawlist-super-red))
(set-face-attribute 'lawlist-super-red nil
  :background "white" :foreground "red" :bold t :underline nil)

(defvar lawlist-super-purple (make-face 'lawlist-super-purple))
(set-face-attribute 'lawlist-super-purple nil
  :background "white" :foreground "purple" :bold t :underline nil)

(defvar lawlist-super-HotPink1 (make-face 'lawlist-super-HotPink1))
(set-face-attribute 'lawlist-super-HotPink1 nil
  :background "white" :foreground "HotPink1" :bold t :underline nil)

(defvar lawlist-super-SeaGreen (make-face 'lawlist-super-SeaGreen))
(set-face-attribute 'lawlist-super-SeaGreen nil
  :background "white" :foreground "SeaGreen" :bold t :underline nil)

答案 1 :(得分:1)

在Emacs中内置的tex模式中,您可以通过将您的环境添加到tex-verbatim-environments来实现。