Skip to content
Karl Yngve Lervåg edited this page Aug 21, 2022 · 5 revisions

From version 2.0, Vimtex provides a full syntax plugin for LaTeX files. The changes allow much finer as well as more consistent control over the syntax highlighting. However, it should be stressed that Vimtex v2.0 syntax groups are not named the same as the built-in syntax highlighting. This brings breaking changes e.g. for configuration or plugins that rely on the syntax groups names.

This wiki page aims to both give some hints on how to customize the syntax highlighting and to show some ways to alleivate the breaking changes.

Patching incompatible syntax group names

The following is a listing that one may use to avoid these incompatibilities:

highlight link texMathZoneV texMathZoneLI
highlight link texMathZoneW texMathZoneLD
highlight link texMathZoneX texMathZoneTI
highlight link texMathZoneY texMathZoneTD
highlight link texMathZoneG texMathZoneEnv
highlight link texMathZoneGS texMathZoneEnvStarred
highlight link texMathZoneZ texMathZoneEnsured

highlight link texStatement texCmd

Customized syntax highlight

Vimtex now provides a comprehensive set of syntax groups that can be used for fine-tuning syntax highlighting of TeX files to your own tastes. The reference for the core syntax groups can be found in :help vimtex-syntax-reference.

The following snippet can serve as a basis for your own customization. You can put it in your init.vim or in a colorscheme file. It's written for neovim with termguicolors set, but should be easy to adapt for Vim.

set background=dark

function! s:highlight(group, guifg, guibg, attr)
  let l:cmd = 'highlight ' . a:group
  if a:guifg != ''
    let l:cmd .= ' guifg=' . a:guifg
  endif
  if a:guibg != ''
    let l:cmd .= ' guibg=' . a:guibg
  endif
  if a:attr != ''
    let l:cmd .= ' gui='   . a:attr
  endif
  execute l:cmd
endfunction

let s:polar1  = '#161821'
let s:polar2  = '#2E3440'
let s:polar3  = '#3B4252'
let s:polar4  = '#6B7089'
let s:snow1   = '#C6C8D1'
let s:snow2   = '#D8DEE9'
let s:snow3   = '#E5E9F0'
let s:frost1  = '#8FBCBB'
let s:frost2  = '#88C0D0'
let s:frost3  = '#81A1C1'
let s:frost4  = '#5E81AC'
let s:aurora1 = '#E27878'
let s:aurora2 = '#E2A478'
let s:aurora3 = '#EBCB8B'
let s:aurora4 = '#A3BE8C'
let s:aurora5 = '#A093C7'

" basic groups
call s:hi('texCmd', s:frost3,  '', '')
call s:hi('texArg', s:aurora3, '', '')
call s:hi('texOpt', s:frost2,  '', '')

" sectioning etc.
call s:hi('texCmdPart',      s:aurora2, '', '')
call s:hi('texPartArgTitle', s:aurora3, '', '')
call s:hi('texCmdTitle',     s:aurora2, '', '')
call s:hi('texCmdAuthor',    s:aurora2, '', '')
call s:hi('texTitleArg',     s:aurora3, '', 'bold')
call s:hi('texAuthorArg',    s:aurora3, '', 'italic')
call s:hi('texFootnoteArg',  s:snow1,   '', 'italic')

" environments
call s:hi('texCmdEnv',     s:frost3,  '', '')
call s:hi('texEnvArgName', s:aurora2, '', '')
call s:hi('texEnvOpt',     s:aurora3, '', '')

" math
call s:hi('texMathZone',        s:frost1, '', '')
call s:hi('texMathCmd',         s:frost2, '', '')
call s:hi('texMathDelim',       s:frost2, '', '')
call s:hi('texMathDelimZone',   s:frost3, '', '')
call s:hi('texMathCmdEnv',      s:frost3, '', '')
call s:hi('texMathEnvArgName',  s:frost3, '', '')
hi! link texCmdMathText texCmdMathEnv
hi! link texCmdMathEnv  texMathCmdEnv

" references
call s:hi('texCmdRef', s:frost3,  '', '')
call s:hi('texRefArg', s:aurora4, '', '')
call s:hi('texRefOpt', s:aurora5, '', '')
call s:hi('texUrlArg', s:frost4,  '', 'underline')
hi! link texCmdCRef     texCmdRef
hi! link texHrefArgLink texUrlArg
hi! link texHrefArgText texOpt

" symbols
call s:hi('texSymbol',      s:aurora5, '', '')
call s:hi('texSpecialChar', s:frost3,  '', '')
hi! link texDelim       texSymbol
hi! link texTabularChar texSymbol

" files
call s:hi('texFileArg', s:aurora5, '', '')
call s:hi('texFileOpt', s:frost2,  '', '')

" bib
call s:hi('bibType',     s:aurora2, '', '')
call s:hi('bibKey',      s:aurora4, '', '')
call s:hi('bibEntryKw',  s:frost1,  '', '')
call s:hi('bibVariable', s:aurora3, '', '')
Clone this wiki locally