【问题标题】:Vim maths syntax highlightingVim 数学语法高亮
【发布时间】:2012-11-28 17:48:07
【问题描述】:

我正在尝试改进 Markdown 文档中数学的语法突出显示。

Multimarkdown 使用方括号 \\[ .. \\]\\( .. \\) 分别表示显示和内联数学。我想用 TeX 突出显示这些内容。

这是我目前所得到的:

syntax include @tex syntax/tex.vim
syn region displaymaths matchgroup=mkdMaths start = "\\\\\[" end="\\\\\]" contains=@tex
syn region inlinemaths matchgroup=mkdMaths start = "\\\\(" end="\\\\)" contains=@tex
hi def link mkdMaths SpecialComment

问题是括号内的内容没有被 tex.vim 当作数学运算,因为它没有包含在 $ .. $ 中。有没有办法解决这个问题?我想我想在这里使用的是 syntax/tex.vim 中的 texMath 组。

有什么方法可以强制将括号中的内容解释为 Tex 数学?

【问题讨论】:

  • 如果将contains=@tex 替换为contains=@texMathZoneGroup 会发生什么?
  • 有效,谢谢。文档确实说这会起作用,但是在阅读了几次后我没有想到!
  • 啊,很好,所以我的预感是对的。我添加了一个更详细的答案。请接受它:-)

标签: vim markdown vim-syntax-highlighting multimarkdown


【解决方案1】:

:syntax include @tex syntax/tex.vim 为您提供了一个 @tex 语法集群,可在包含 Tex 的区域中使用,但您实际上想要引用 tex.vim 中存在的特定集群 @texMathZoneGroup

由于没有嵌套语法簇,你可以直接通过contains=@texMathZoneGroup引用。

【讨论】:

  • 对于 2021 年使用 vimtex 的任何人,请使用 contains=@texClusterMath
【解决方案2】:
syntax include syntax/tex.vim
syn region displaymaths matchgroup=mkdMaths start = "\\\\\[" end="\\\\\]" contains=@texMathZoneGroup
syn region inlinemaths matchgroup=mkdMaths start = "\\\\(" end="\\\\)" contains=@texMathZoneGroup
hi def link mkdMaths SpecialComment

vim 文档 (:help syn-include) 实际上非常清楚地说明了这一点(尽管也许可以举个例子):

如果包含的语法文件中的顶级语法项是 包含在包含语法中的区域内,您可以使用 ":syntax include" 命令:

n:sy[ntax] include [@{grouplist-name}] {file-name}

如果要从包含的语法文件中包含特定的顶级语法项“foo”,则需要在 syn region 命令中包含 contains=@foo

包含文件中声明的所有语法项都将具有 添加了“包含”标志。此外,如果指定了组列表, 包含文件中的所有顶级语法项都将添加到 那个列表。

所以我的问题中的@tex grouplist-name 不需要指定。但是,如果我的文档中有较大的 TeX 区域,则需要指定,因为它可以访问包含的语法文件的命名空间,这样contains=@tex 将根据包含的所有规则突出显示整个区域语法文件。

【讨论】:

    猜你喜欢
    • 2012-08-16
    • 2014-11-14
    • 2011-01-19
    • 2015-08-08
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 2013-08-01
    相关资源
    最近更新 更多