Vim math syntax highlighting

I am trying to improve syntax highlighting in math documents.

Multimarkdown uses the brackets \\[ .. \\] and \\( .. \\) to indicate the display and the built-in math, respectively. I want to highlight their contents using TeX.

Here is what I have so far:

 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 

The problem is that what is inside the brackets is not perceived as math tex.vim, because it is not enclosed in $ .. $ . Is there any way around this? I think this is the texMath group in the /tex.vim syntax that I want to use here.

Is there any way to make the contents of the brackets be interpreted as Tex maths?

+4
source share
2 answers

:syntax include @tex syntax/tex.vim provides you with a @tex syntax cluster for use in regions containing Tex, but you really want to reference a specific cluster existing in tex.vim, @texMathZoneGroup .

Since there is no nesting of syntactic clusters, you can directly refer to it via contains=@texMathZoneGroup .

+2
source
 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 

The vim documentation ( :help syn-include ) actually points this out quite clearly (although perhaps with an example):

If the top-level syntax elements in the included syntax file must be contained within a region in the inclusion syntax, you can use ": include syntax":

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

If you want to include a specific top-level syntax element "foo" in the syntax file, you need to have contains=@foo in the syn region command.

All syntax elements declared in the included file will have the "contained" flag added. In addition, if a list of groups is specified, all the top-level syntax elements in the included file will be added to this list.

Therefore, the name @tex grouplist-name did not need to be indicated in my question. If I had large TeX areas in my documents, this would require guidance because it gives access to the included syntax file namespace, so that contains=@tex will highlight the entire region according to all the rules of the included syntax file.

0
source

All Articles