vimtex/after/syntax/tex.vim

121 lines
3.6 KiB
VimL
Raw Normal View History

2015-03-07 17:02:15 -05:00
" vimtex - LaTeX plugin for Vim
2014-07-22 18:08:57 -04:00
"
" Maintainer: Karl Yngve Lervåg
" Email: karl.yngve@gmail.com
"
2015-04-01 02:26:19 -04:00
if !exists('b:current_syntax') || b:current_syntax !=# 'tex'
echoerr 'vimtex syntax error: please report issue!'
finish
endif
" Better support for cite commands
" \cite, \citep, \citet, \citeauthor, ...
2014-12-25 14:35:47 -05:00
syntax match texRefZone
2014-07-30 04:59:56 -04:00
\ "\\\%(auto\|text\)\?cite\%([tp]\*\?\|author\)\?"
\ nextgroup=texRefOption,texCite
2015-03-23 14:17:34 -04:00
" Add support for cleveref package
" \Cref, \cref, \cpageref, \labelcref, \labelcpageref
2014-12-25 14:35:47 -05:00
syntax region texRefZone matchgroup=texStatement
2015-03-12 04:56:24 -04:00
\ start="\\\(\(label\)\?c\(page\)\?\|C\|auto\)ref{"
2013-10-05 07:53:42 -04:00
\ end="}\|%stopzone\>"
\ contains=@texRefGroup
" \crefrange, \cpagerefrange (these commands expect two arguments)
2014-12-25 14:35:47 -05:00
syntax match texStatement
\ '\\c\(page\)\?refrange\>'
2013-10-17 07:33:52 -04:00
\ nextgroup=texRefRangeStart skipwhite skipnl
2014-12-25 14:35:47 -05:00
syntax region texRefRangeStart
2013-10-17 07:33:52 -04:00
\ start="{"rs=s+1 end="}"
\ matchgroup=Delimiter
\ contained contains=texRefZone
\ nextgroup=texRefRangeEnd skipwhite skipnl
2014-12-25 14:35:47 -05:00
syntax region texRefRangeEnd
2013-10-17 07:33:52 -04:00
\ start="{"rs=s+1 end="}"
\ matchgroup=Delimiter
\ contained contains=texRefZone
2014-12-25 14:35:47 -05:00
highlight link texRefRangeStart texRefZone
highlight link texRefRangeEnd texRefZone
2014-02-09 09:44:55 -05:00
" {{{1 Support for listings package
2014-12-25 14:35:47 -05:00
syntax region texZone
\ start="\\begin{lstlisting}"rs=s
\ end="\\end{lstlisting}\|%stopzone\>"re=e
\ keepend
\ contains=texBeginEnd
2014-12-25 14:35:47 -05:00
syntax match texInputFile
2014-06-04 08:53:49 -04:00
\ "\\lstinputlisting\s*\(\[.*\]\)\={.\{-}}"
2014-02-09 09:44:55 -05:00
\ contains=texStatement,texInputCurlies,texInputFileOpt
2014-12-25 14:35:47 -05:00
syntax match texZone "\\lstinline\s*\(\[.*\]\)\={.\{-}}"
" }}}1
" {{{1 Nested syntax highlighting for dot
2015-04-01 02:26:19 -04:00
unlet b:current_syntax
2014-12-25 14:35:47 -05:00
syntax include @DOT syntax/dot.vim
syntax region texZone
\ start="\\begin{dot2tex}"rs=s
\ end="\\end{dot2tex}"re=e
2014-12-25 14:35:47 -05:00
\ keepend
\ transparent
\ contains=texBeginEnd,@DOT
2015-04-01 02:26:19 -04:00
let b:current_syntax = 'tex'
2014-12-08 14:44:17 -05:00
" }}}1
" {{{1 Nested syntax highlighting for minted
for entry in get(g:, 'vimtex_syntax_minted', [])
let lang = entry.lang
let syntax = get(entry, 'syntax', lang)
unlet b:current_syntax
execute 'syntax include @' . toupper(lang) 'syntax/' . syntax . '.vim'
if has_key(entry, 'ignore')
execute 'syntax cluster' toupper(lang)
\ 'remove=' . join(entry.ignore, ',')
endif
execute 'syntax region texZone'
\ 'start="\\begin{minted}\_[^}]\{-}{' . lang . '}"rs=s'
\ 'end="\\end{minted}"re=e'
\ 'keepend'
\ 'transparent'
\ 'contains=texMinted,@' . toupper(lang)
"
" Support for custom environment names
"
for env in get(entry, 'environments', [])
execute 'syntax region texZone'
\ 'start="\\begin{' . env . '}"rs=s'
\ 'end="\\end{' . env . '}"re=e'
\ 'keepend'
\ 'transparent'
\ 'contains=texBeginEnd,@' . toupper(lang)
" Match starred environments with options
execute 'syntax region texZone'
\ 'start="\\begin{' . env . '\*}\s*{\_.\{-}}"rs=s'
\ 'end="\\end{' . env . '\*}"re=e'
\ 'keepend'
\ 'transparent'
\ 'contains=texMintedStarred,texBeginEnd,@' . toupper(lang)
execute 'syntax match texMintedStarred'
\ '"\\begin{' . env . '\*}\s*{\_.\{-}}"'
\ 'contains=texBeginEnd,texDelimiter'
endfor
endfor
let b:current_syntax = 'tex'
syntax match texMinted '\\begin{minted}\_[^}]\{-}{\w\+}'
\ contains=texBeginEnd,texMintedName
syntax match texMinted '\\end{minted}'
\ contains=texBeginEnd
syntax match texMintedName '{\w\+}'
highlight link texMintedName texBeginEndName
" }}}1
2014-12-08 14:44:17 -05:00
" vim: fdm=marker sw=2