Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: customize tex equation highlight

How do I force vim to highlight the following environment:

\begin{dmath*}
  2 + 2
\end{dmath*}

the same way as

\begin{equation*}
 2 + 2
\end{equation*}

?

i.e I want the dmath environments (in its plain and starred versions) to be highlighted the same ways as the equation (plain and starred) environment.

enter image description here

like image 313
petobens Avatar asked Mar 18 '23 17:03

petobens


1 Answers

I pasted your question into Vim, :setf tex, and then used the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin to find out that the corresponding syntax group name is texMathZoneES.

Then I opened $VIMRUNTIME/syntax/tex.vim and searched for it. I didn't find that directly, but something like this:

call TexNewMathZone("E","equation",1)

Then I looked up :help ft-tex-syntax (completed from the command-line via <C-D>), and found under :help tex-math a nice documentation. With that, I created the following solution:

call TexNewMathZone("M","dmath",1)

You can put that into ~/.vim/after/syntax/tex.vim, as suggested, to make it permanent. Easy, isn't it?!

like image 80
Ingo Karkat Avatar answered Apr 02 '23 01:04

Ingo Karkat