In Vim, I want the syntax
\begin{pycode}
...
\end{pycode}
to syntax highlight the content inside the environment in Python, and the syntax
(#TeX
r"""
...
""")
to syntax highlight the content inside the string in TeX.
So I do the following
put in
.vim/after/syntax/tex.vim
:call SyntaxRange#Include('\\begin{pycode}', '\\end{pycode}', 'python', 'Statement')
put in
.vim/after/syntax/python.vim
:call SyntaxRange#Include( '(#TeX\n\s*[rfb]\?"""' , '""")' , 'tex')
Each of them work fine without the other, but including both gives a lot of errors such as...
E132: Function call depth is higher than 'maxfuncdepth'
E169: Command too recursive
How can I fix it?
I do want to be able to nest the highlighting:
\begin{pycode}
# this part is highlighted as Python
print(#TeX
r"""
% this part is highlighted as TeX
\relax
""")
\end{pycode}
If allowing arbitrary nesting is not possible then at least 1 layer of nesting should be allowed?
By the way I was using SyntaxRange
plugin, but without that the equivalent vim commands are
syntax include @synIncludeTex syntax/tex.vim
syntax region synIncludeTex keepend start="(#TeX\n\s*[rfb]\?\"\"\"" end="\"\"\")" containedin=ALL contains=@synIncludeTex
syntax include @synIncludePython syntax/python.vim
syntax region synIncludePython matchgroup=Statement keepend start="\\begin{pycode}" end="\\end{pycode}" containedin=ALL contains=@synIncludePython