vim 中的 LaTeX 部分突出显示
在 LaTeX 中,一个部分看起来像:
\section{Section Title}
我想突出显示这些部分或部分标题。我尝试将以下内容放入 ~/.vim/bundle/latexrc/after/syntax/tex.vim
中:(
syn match texSectioning "\\section\>" skipwhite nextgroup=texSectioningTitle
syn region texSectioningTitle contained matchgroup=Delimiter start='{' end='}' contains=@texSectioningGroup
syn cluster texSectioningGroup contains=texMatcher,texComment,texDelimiter
请注意,默认的 tex.vim 不处理这种语法
语法文件。它只定义了“部分区域”,这对我来说几乎毫无价值。)
然后我在我的配色方案中定义了以下内容:
hi texSectioning gui=bold guifg=red
什么也没有发生;也就是说,部分标题在我的 LaTeX 代码中不会显示为红色(即使在我完全重新加载文件之后)。
我对 vim 的语法如何工作以及如何调试它完全感到困惑。
编辑 更多信息:它有时有效,有时无效。 完全不可预测。可能是什么问题?病原?还有别的事吗?我完全困惑了。
In LaTeX, a section looks like:
\section{Section Title}
I would like to highlight such sections, or section titles. I tried to put the following in ~/.vim/bundle/latexrc/after/syntax/tex.vim
:
syn match texSectioning "\\section\>" skipwhite nextgroup=texSectioningTitle
syn region texSectioningTitle contained matchgroup=Delimiter start='{' end='}' contains=@texSectioningGroup
syn cluster texSectioningGroup contains=texMatcher,texComment,texDelimiter
(Note that this kind of syntax is not handled by the default tex.vim
syntax file. It only defines "section zones", which are pretty much worthless for me.)
I then define the following in my color scheme:
hi texSectioning gui=bold guifg=red
And nothing happens; that is, section titles do not appear in red in my LaTeX code (even after I reloaded the file completely).
I am totally confused as to how vim's syntax work, and how to debug it.
Edit
Some more information: it sometimes works and sometimes not. Completely unpredictable. What could be the problem? Pathogen? Something else? I'm completely puzzled.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您已经定义了新的语法项
texSectioning
、texSectioningTitle
和texSectioningGroup
,但尚未将它们链接到突出显示组,因此 Vim 不会知道如何显示它们。尝试添加这些行:Statement
、String
和Comment
颜色由您正在使用的颜色方案定义。这些只是示例:您可以将它们替换为在 colorscheme 文件中定义的任何组。You have defined the new syntax items
texSectioning
,texSectioningTitle
andtexSectioningGroup
, but you have not linked them to a highlighting group, so Vim doesn't know how to display them. Try adding these lines:The
Statement
,String
andComment
colourings are defining by the colourscheme you are using. These are just examples: you can replace them with any group defined in the colourscheme file.答案如下:tex.vim 将文本划分为多个区域,其中的语法必须显式允许。关键元素是该命令:
这对 vim 来说,在 texChapterGroup 内,允许使用语法簇 texSectioningGroup 。接下来要做的就是照常定义该集群。
另一个细节是区域
texSectioningTitle
必须被包含
,否则它将匹配 LaTeX 中的任意对{}
。所以一个完整的解决方案是这样的:
编辑 这就是为什么行为显然是不可预测的:vim 不会读取整个文件来找出语法。因此,在足够大的章节中,我的节语法将起作用,因为 vim 没有走得足够远,无法看到它位于章节区域中。
Here is the answer: the tex.vim divides the text in zones, in which the syntax must be explicitly allowed. The key element is that command:
This says to vim that inside a
texChapterGroup
, the syntax clustertexSectioningGroup
is allowed. The next thing to do is simply to define that cluster as usual.Another detail is that the region
texSectioningTitle
must becontained
, otherwise it will match arbitrary pairs of{}
in LaTeX.So a complete solution goes like this:
Edit Here is why the behaviour was apparently unpredictable: vim does not read the entire file to figure out the syntax. So in a big enough chapter, my section syntax would work because vim did not go far enough to see it was in a chapter zone.
只是为了更新信息以轻松突出显示部分。使用 containsin 意味着所有其他语法匹配都包含此新语法匹配。然后只需定义您想要的颜色即可。
或者,可以将简单的新语法匹配添加到 texFoldGroup 中,以便在块文档内进行评估。
Just to update the information to highlight section easily. Using containedin means that all the other syntax matches contains this new syntax match. Then just define the color you want.
Alternatively, a simple new syntax match could be added to the texFoldGroup in order to be evaluated inside the the block document.