Question

I'm trying to improve the syntax highlighting of maths in markdown documents.

Multimarkdown uses brackets \\[ .. \\] and \\( .. \\) to indicate display and inline math respectively. I want to highlight the contents of these with TeX.

Here's what I've got 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 isn't picked up as maths by tex.vim because it isn't enclosed in $ .. $. Is there a way I can get around this? I think it is the texMath group in syntax/tex.vim that I want to use here.

Is there some way I can force the contents of the brackets to be interpreted as Tex maths?

Was it helpful?

Solution

The :syntax include @tex syntax/tex.vim gives you a @tex syntax cluster to use in regions containing Tex, but you actually want to refer to a particular cluster existing in tex.vim, @texMathZoneGroup.

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

OTHER TIPS

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 states this quite clearly (although could perhaps do with an example):

If top-level syntax items in the included syntax file are to be contained within a region in the including syntax, you can use the ":syntax include" command:

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

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

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

So the @tex grouplist-name in my question didn't need to be specified. If I were to have larger regions of TeX in my documents though, this would need specifying as it gives access to the namespace of the included syntax file, such that contains=@tex will highlight the entire region according to all of the rules of the included syntax file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top