Vim: customize tex equation highlight

Issue

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

Solution

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?!

Answered By – Ingo Karkat

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.