vimmarkdownvim-syntax-highlightingmultimarkdown

Vim maths syntax highlighting


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?


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.