Is it possible to get VIM to recognize syntax changes inside a particular region? Specifically, I am trying to get LaTeX3's \ExplSyntaxOn
...\ExplSyntaxOff
syntax to be highlighted, but only
inside a particular region. The \makeatletter
...\makeatother
syntax region would be similar.
Here is an example file to highlight:
\documentclass{article}
\ExplSyntaxOn
\tl_new:N \l_@@_local_var_tl
\tl_new:N \g_@@_global_var_tl
\tl_if_eq:nnTF {\l_@@_local_var_tl} {\g_@@_global_var_tl}
{ Hello, world! }
{ Goodbye, world! }
\ExplSyntaxOff
\begin{document}
\ExplSyntaxOn
\tl_new:N \l_@@_local_var_tl
\tl_new:N \g_@@_global_var_tl
\tl_if_eq:nnTF {\l_@@_local_var_tl} {\g_@@_global_var_tl}
{ Hello, world! }
{ Goodbye, world! }
\ExplSyntaxOff
\end{document}
I tried this so far (in ~/.vim/after/syntax/tex.vim):
syntax region texLaTeX3Zone matchgroup=texStatement start="\\ExplSyntaxOn\>"
\ end="\\ExplSyntaxOff\>" skip="[^\\]%.*\\ExplSyntaxOff" transparent
\ keepend
syntax match texLaTeX3DefCmd "\\[a-zA-Z_:@]\+" nextgroup=texDefParms,texCmdBody
\ skipwhite skipnl contained containedin=texLaTeX3Zone
highlight link texLaTeX3DefCmd texStatement
However, anything that is inside braces (which is region texCmdBody
) or after \begin{document}
(which is region texDocZone
), or any other region for that matter, doesn't get highlighted properly.
It doesn't work to leave contained
off, as that would make it match everywhere, even outside the region, and it doesn't work to use containedin=ALL
, because then it highlights it in other regions that are not contained within texLaTeX3Zone.
Short of making the new highlighting part of every region in the document---I only want it between \ExplSyntaxOn
and \ExplSyntaxOff
---is there a way to do this?