So on one of my pc's the vim install dos not recognize math environments such as align and equation

Is there a way to turn this on?

  • 1
    Despite my answer below, this is a question about vim's syntax highlighting and not about TeX, imho, so best is asked elsewhere. – Skillmon Jan 30 '18 at 14:29
  • First; Thanks for the answer @Skillmon. I can see where you are comming from, but I there has been questions like this one before (tex.stackexchange.com/questions/347878/…) and i feel i tagged nicely. Just wiered that vim-latex didn't catch it for me. – Thorbjørn E. K. Christensen Jan 30 '18 at 14:36
  • 2
    vim-latexsuite is not there for syntax highlighting, but to give you convenience short cuts to edit tex files faster. – Skillmon Jan 30 '18 at 14:39
  • I thought it did a bit of both worlds, Good to know XD – Thorbjørn E. K. Christensen Jan 30 '18 at 14:40
  • 1
    This may be true, I'm not completely sure. But the original idea is to separate syntax highlighting from other ex commands (you could put any ex commands in a syntax highlighting file). – Skillmon Jan 30 '18 at 14:45

Check if the syntax highlighting rules are up to date. Those should be located under /usr/share/vim/vim80/syntax/tex.vim. In this file there should be a block name Standard Math Zones:. Below that you'll find some lines stating something like:

call TexNewMathZone("A","displaymath",1)

To this block add the environments you find missing. E.g., for align use:

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

If there is no starred form of the environment you want to add, use

call TexNewMathZone(suffix,name,0)


But perhaps you shouldn't make those changes system wide but on a per user basis. So create a copy of the file in /usr/share/... paste it in a folder in $HOME where vim finds it and make those changes there.

If the syntax highlighting is correct on the other machines, maybe copy the files from there to your machine where it fails to highlight correctly.

The default folder for the per-user-basis syntax highlighting would be something like ~/.vim/syntax/. If it doesn't exist, create it and everything should work.

EDIT: Perhaps a better approach is to create a short custom syntax file which sources the system wide one in the beginning and add some stuff there. The setup would then be the following file ~/.vim/syntax/tex.vim:

so $VIMRUNTIME/syntax/tex.vim

" adapt to match your system wide variable in $VIMRUNTIME/syntax/tex.vim
let s:tex_fast= "bcmMprsSvV"

if !exists("g:tex_no_math")
 call TexNewMathZone("E","align",1)

if s:tex_fast =~# 'r'
  syn region texRefZone     matchgroup=texStatement start="\\autoref{"  end="}\|%stopzone\>"    contains=@texRefGroup

In the above I've also added \autoref to the list of known commands for referencing stuff as an example.

I think this should be a better approach since you get bugfixes and new features from updates in your system wide file this way.

Alternatively (but with the same effects) put the file in ~/.vim/after/syntax/ and remove the first line (that's what is suggested in :help latex-syntax).

  • 1
    @ThorbjørnE.K.Christensen not directly in home. But in your $HOME there should be a folder containing vim configuration stuff on a per user basis. I'll edit my answer. – Skillmon Jan 30 '18 at 14:42
  • 1
    @ThorbjørnE.K.Christensen you're welcome. In fact, I was too lazy all the time to fix this on my local machine, too, and now that you've asked I did fix it :) – Skillmon Jan 30 '18 at 14:56
  • 1
    @ThorbjørnE.K.Christensen see my edit... – Skillmon Jan 30 '18 at 15:16
  • 1
    @ThorbjørnE.K.Christensen I hope I understand your comment correctly. The "E" you provide is a suffix -- and that's about it what I understood from taking a quick look at the definition of TexNewMathZone. It is used for some definitions. Perhaps it's best to just use a new one for each environment. – Skillmon Jan 30 '18 at 16:09
  • 1
    @ThorbjørnE.K.Christensen I don't know, if it does work otherwise or not. You might just test it. – Skillmon Jan 30 '18 at 16:22

For some reason, the amsmath environments were recently removed from vim's syntax files and split into a separate package. After downloading that package decompress it and run

$ vim amsmath.vba
:so %

to re-enable amsmath support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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