12

Sorry if this is the wrong place to ask this, I'm new to the site :/

My issue is this: when editing in vim, my syntax file highlights underscores and carets when found in non-math text, which is fine, except vim doesn't recognize that "align" is a math environment. What do I need to do to fix this?

how do I fix this??

  • 1
    Welcome to TeX.SX! Even if you're using vim. ;-) – egreg Feb 19 '18 at 0:36
  • Do you have a file called ~/.vim/syntax/tex.vim (assuming you have a Unix-like system, I don't know what it's called on Windows)? The math-mode syntax is in the Math Zones sections. It's probably simplest to search the file for an environment name that you know does work (such as displaymath or equation) and add similar entries for align. (You might be able to get more help at vi.stackexchange.com) – Nicola Talbot Feb 19 '18 at 13:04
  • @ egreg Thanks for the welcome! @NicolaTalbot Thanks for the suggestion. I don't have my own syntax file, but one is located in /usr/share/vim/syntax/tex.vim. What confuses me is this: "align" is already defined as a math zone in the syntax file, and I see no significant differences between the code in the syntax file involving "equation" and that involving "align." Yet "equation" actually gets highlighted correctly while "align" doesn't. What could be happening? – Henry Wang Feb 19 '18 at 19:23
  • @HenryWang Does your tex.vim file have any version details at the start of it? I think there are various tex.vim files around. Maybe you have a different one to me. Mine is dated Jun 24, 2013 version 79 with the URL drchip.org/astronaut/vim/index.html#SYNTAX_TEX – Nicola Talbot Feb 19 '18 at 20:11
  • @NicolaTalbot Yeah, I think mine is different. My tex.vim file contains the lines " Last Change: Jun 11, 2015 and " Version: 87. – Henry Wang Feb 19 '18 at 21:54
12

Sometime around 2017 (I think), Dr. Chip decided that base-vim should only support syntax highlighting for base-latex. It is necessary to add in support for syntax highlighting for things available in latex packages (such as amsmath, which is what provides the align environment).

But this is very easy, and Dr. Chip includes syntax files for amsmath (and a few other packages) on his website.

In order to use these, you do the following. I will assume that you want to install additional highlighting to cover the align environment. As this comes from amsmath, we will add additional amsmath highlighting support. Then you

  1. Get http://www.drchip.org/astronaut/vim/vbafiles/amsmath.vba.gz from Dr. Chip
  2. The file is in vimball format, and the easiest way to extract it is to open it with vim and follow instructions (which probably say :so %).
  3. Move and rename amsmath.vba to ~/.vim/after/syntax/tex/amsmath.vim (or the corresponding location on your machine). One can also run :so % from amsmath.vba, this will automatically make ~/.vim/after/syntax/tex/amsmath.vim (and works if moving the amsmath.vba doesn't)

It is also possible to do this directly from your vimrc by making new "math zones" (and this is mostly what amsmath.vim does anyway). See :h tex-math for more.

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.