I'm trying to add some syntax support for LaTeX3. There are huge commands containing _, so I change the match pattern of texStatement in ~/.vim/syntax/tex.vim

syn match texStatement /\\[a-zA-Z@_:]\+/ contained

I have a piece of tex code

  a + b = c

Before I add tex.vim, the syntax stack of \end is

['texDocZone', 'texMathZoneC', 'texStatement']

After is

['texDocZone', 'texStatement']

texMathZone is lost and then cause problem when I use contex command in ultisnip.


2 Answers 2


It is not straightforward to change the built-in syntax to support LaTeX3. One may attempt to change the texStatement match rules as suggested here: "Vim Configuration for expl3". However, it will not work perfectly, because syntax matching is a complex beast. In particular, the rules are applied in the reverse order of definition, which means that if you overrule the texStatement rules, they will suddenly match more often. This (at least in part) explains your issue.

One possibility is to use the plugin vim-expl3, which adds its own syntax rules. However, yuu need to add rules to load it yourself (it is not automatically loaded for tex files).

Another alternative is to use Vimtex. I added support for syntax highlighting of LaTeX3 syntax to Vimtex with the v2.0 release. This was added as a result of this issue.


Redefine various texMathZones after

syn match texStatement /\\[a-zA-Z@_:]\+/ contained
call TexNewMathZone("A","displaymath",1)
call TexNewMathZone("B","eqnarray",1)
call TexNewMathZone("C","equation",1)
call TexNewMathZone('AmsA', 'align', 1)
call TexNewMathZone('AmsB', 'alignat', 1)
call TexNewMathZone('AmsD', 'flalign', 1)
call TexNewMathZone('AmsC', 'gather', 1)
call TexNewMathZone('AmsD', 'multline', 1)
call TexNewMathZone('AmsE', 'xalignat', 1)
call TexNewMathZone('AmsF', 'xxalignat', 0)
call TexNewMathZone('AmsG', 'mathpar', 1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.