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-09-14 13:43:48 -04:00
|
|
|
if !exists('b:current_syntax')
|
|
|
|
let b:current_syntax = 'tex'
|
|
|
|
elseif b:current_syntax !=# 'tex'
|
2015-04-01 02:26:19 -04:00
|
|
|
echoerr 'vimtex syntax error: please report issue!'
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2016-01-07 17:18:37 -05:00
|
|
|
" Perform spell checking when there is no syntax
|
|
|
|
" - This will enable spell checking e.g. in toplevel of included files
|
|
|
|
syntax spell toplevel
|
|
|
|
|
2016-02-11 17:01:13 -05:00
|
|
|
" {{{1 General match improvements
|
|
|
|
|
|
|
|
syntax match texInputFile /\\includepdf\%(\[.\{-}\]\)\=\s*{.\{-}}/
|
|
|
|
\ contains=texStatement,texInputCurlies,texInputFileOpt
|
|
|
|
|
2015-12-06 16:31:18 -05:00
|
|
|
" {{{1 Italic font, bold font and conceals
|
|
|
|
|
2016-05-03 13:38:54 -04:00
|
|
|
if get(g:, 'tex_fast', 'b') =~# 'b'
|
|
|
|
let conceal = (has('conceal') && get(g:, 'tex_conceal', 'b') =~# 'b')
|
|
|
|
\ ? 'concealends' : ''
|
|
|
|
|
|
|
|
for [style, group, commands] in [
|
|
|
|
\ ['texItalStyle', 'texItalGroup', ['emph', 'textit']],
|
|
|
|
\ ['texBoldStyle', 'texBoldGroup', ['textbf']],
|
|
|
|
\]
|
|
|
|
for cmd in commands
|
|
|
|
execute 'syntax region' style 'matchgroup=texTypeStyle'
|
|
|
|
\ 'start="\\' . cmd . '\s*{" end="}"'
|
2016-07-14 13:23:45 -04:00
|
|
|
\ 'contains=@Spell,@' . group
|
2016-05-03 13:38:54 -04:00
|
|
|
\ conceal
|
|
|
|
endfor
|
|
|
|
execute 'syntax cluster texMatchGroup add=' . style
|
2015-12-06 16:31:18 -05:00
|
|
|
endfor
|
2016-05-03 13:38:54 -04:00
|
|
|
endif
|
2015-09-25 16:57:01 -04:00
|
|
|
|
|
|
|
" }}}1
|
2016-03-23 17:21:37 -04:00
|
|
|
" {{{1 Add syntax highlighting for \url, \href, \hyperref
|
|
|
|
|
2015-09-19 15:57:47 -04:00
|
|
|
syntax match texStatement '\\url\ze[^\ta-zA-Z]' nextgroup=texUrlVerb
|
|
|
|
syntax region texUrlVerb matchgroup=Delimiter
|
|
|
|
\ start='\z([^\ta-zA-Z]\)' end='\z1' contained
|
|
|
|
|
2016-03-23 17:22:29 -04:00
|
|
|
syntax match texStatement '\\url\ze\s*{' nextgroup=texUrl
|
|
|
|
syntax region texUrl matchgroup=Delimiter start='{' end='}' contained
|
|
|
|
|
|
|
|
syntax match texStatement '\\href' nextgroup=texHref
|
2015-09-19 15:57:47 -04:00
|
|
|
syntax region texHref matchgroup=Delimiter start='{' end='}' contained
|
2015-08-28 15:05:39 -04:00
|
|
|
\ nextgroup=texHrefLinkText
|
2015-09-19 15:57:47 -04:00
|
|
|
syntax region texHrefLinkText matchgroup=Delimiter start='{' end='}' contained
|
2015-08-28 15:05:39 -04:00
|
|
|
\ contains=@Spell
|
|
|
|
|
2016-03-23 17:21:37 -04:00
|
|
|
syntax match texStatement '\\hyperref' nextgroup=texHyperref
|
|
|
|
syntax region texHyperref matchgroup=Delimiter start='\[' end='\]' contained
|
|
|
|
|
2015-08-28 15:05:39 -04:00
|
|
|
highlight link texUrl Function
|
2015-09-19 15:57:47 -04:00
|
|
|
highlight link texUrlVerb texUrl
|
2015-08-28 15:05:39 -04:00
|
|
|
highlight link texHref texUrl
|
|
|
|
highlight link texHrefLinkText texSectionZone
|
2016-03-23 17:21:37 -04:00
|
|
|
highlight link texHyperref texRefZone
|
2015-08-28 15:05:39 -04:00
|
|
|
|
|
|
|
" }}}1
|
|
|
|
" {{{1 Improve support for cite commands
|
2016-05-03 13:38:54 -04:00
|
|
|
if get(g:, 'tex_fast', 'r') =~# 'r'
|
|
|
|
syntax match texStatement
|
|
|
|
\ "\\\%(auto\|text\)\?cite\%([tp]\*\?\|author\)\?"
|
|
|
|
\ nextgroup=texRefOption,texCite
|
|
|
|
endif
|
2013-11-03 05:49:18 -05:00
|
|
|
|
2015-08-28 15:05:39 -04:00
|
|
|
" }}}1
|
|
|
|
" {{{1 Add support for cleveref package
|
2016-05-03 13:38:54 -04:00
|
|
|
if get(g:, 'tex_fast', 'r') =~# 'r'
|
|
|
|
syntax region texRefZone matchgroup=texStatement
|
|
|
|
\ start="\\\(\(label\)\?c\(page\)\?\|C\|auto\)ref{"
|
|
|
|
\ end="}\|%stopzone\>"
|
|
|
|
\ contains=@texRefGroup
|
|
|
|
|
|
|
|
" \crefrange, \cpagerefrange (these commands expect two arguments)
|
|
|
|
syntax match texStatement
|
|
|
|
\ '\\c\(page\)\?refrange\>'
|
|
|
|
\ nextgroup=texRefRangeStart skipwhite skipnl
|
|
|
|
syntax region texRefRangeStart
|
|
|
|
\ start="{"rs=s+1 end="}"
|
|
|
|
\ matchgroup=Delimiter
|
|
|
|
\ contained contains=texRefZone
|
|
|
|
\ nextgroup=texRefRangeEnd skipwhite skipnl
|
|
|
|
syntax region texRefRangeEnd
|
|
|
|
\ start="{"rs=s+1 end="}"
|
|
|
|
\ matchgroup=Delimiter
|
|
|
|
\ contained contains=texRefZone
|
|
|
|
|
|
|
|
highlight link texRefRangeStart texRefZone
|
|
|
|
highlight link texRefRangeEnd texRefZone
|
|
|
|
endif
|
2014-02-09 09:44:55 -05:00
|
|
|
|
2015-08-28 15:05:39 -04:00
|
|
|
" }}}1
|
|
|
|
" {{{1 Add support for listings package
|
2014-12-25 14:35:47 -05:00
|
|
|
syntax region texZone
|
2015-06-17 14:51:18 -04:00
|
|
|
\ 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*\(\[.*\]\)\={.\{-}}"
|
|
|
|
|
2015-06-17 14:51:18 -04:00
|
|
|
" }}}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
|
2015-06-17 14:51:18 -04:00
|
|
|
\ start="\\begin{dot2tex}"rs=s
|
|
|
|
\ end="\\end{dot2tex}"re=e
|
2014-12-25 14:35:47 -05:00
|
|
|
\ keepend
|
|
|
|
\ transparent
|
2015-06-17 14:51:18 -04:00
|
|
|
\ contains=texBeginEnd,@DOT
|
2015-04-01 02:26:19 -04:00
|
|
|
let b:current_syntax = 'tex'
|
2014-12-08 14:44:17 -05:00
|
|
|
|
2016-02-16 13:37:58 -05:00
|
|
|
" }}}1
|
|
|
|
" {{{1 Nested syntax highlighting for lualatex
|
|
|
|
unlet b:current_syntax
|
|
|
|
syntax include @LUA syntax/lua.vim
|
|
|
|
syntax region texZone
|
2016-02-16 14:35:40 -05:00
|
|
|
\ start='\\begin{luacode\*\?}'rs=s
|
|
|
|
\ end='\\end{luacode\*\?}'re=e
|
|
|
|
\ keepend
|
|
|
|
\ transparent
|
|
|
|
\ contains=texBeginEnd,@LUA
|
2016-02-16 13:37:58 -05:00
|
|
|
syntax region texZone
|
2016-02-16 14:35:40 -05:00
|
|
|
\ start='\\\(directlua\|luadirect\){'rs=s
|
|
|
|
\ end='}'re=e
|
|
|
|
\ keepend
|
|
|
|
\ transparent
|
|
|
|
\ contains=texBeginEnd,@LUA
|
2016-02-16 13:37:58 -05:00
|
|
|
let b:current_syntax = 'tex'
|
|
|
|
|
2015-06-17 15:05:40 -04:00
|
|
|
" }}}1
|
|
|
|
" {{{1 Nested syntax highlighting for minted
|
2015-10-24 18:07:10 -04:00
|
|
|
|
|
|
|
" First set all minted environments to listings
|
|
|
|
syntax region texZone
|
|
|
|
\ start="\\begin{minted}\_[^}]\{-}{\w\+}"rs=s
|
|
|
|
\ end="\\end{minted}"re=e
|
|
|
|
\ keepend
|
|
|
|
\ contains=texMinted
|
|
|
|
|
|
|
|
" Next add nested syntax support for desired languages
|
2015-08-03 15:51:37 -04:00
|
|
|
for entry in get(g:, 'vimtex_syntax_minted', [])
|
2015-06-17 15:05:40 -04:00
|
|
|
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)
|
2015-07-04 03:36:32 -04:00
|
|
|
|
2015-07-05 15:30:47 -04:00
|
|
|
"
|
|
|
|
" 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
|
2015-06-17 15:05:40 -04:00
|
|
|
endfor
|
|
|
|
let b:current_syntax = 'tex'
|
|
|
|
|
2015-07-05 15:30:47 -04:00
|
|
|
syntax match texMinted '\\begin{minted}\_[^}]\{-}{\w\+}'
|
2015-07-04 03:36:32 -04:00
|
|
|
\ contains=texBeginEnd,texMintedName
|
2015-07-05 15:30:47 -04:00
|
|
|
syntax match texMinted '\\end{minted}'
|
2015-07-04 03:36:32 -04:00
|
|
|
\ contains=texBeginEnd
|
2015-10-20 17:24:51 -04:00
|
|
|
syntax match texMintedName '{\w\+}' contained
|
2015-06-17 15:05:40 -04:00
|
|
|
|
|
|
|
highlight link texMintedName texBeginEndName
|
|
|
|
|
2015-06-17 14:51:18 -04:00
|
|
|
" }}}1
|
|
|
|
|
2014-12-08 14:44:17 -05:00
|
|
|
" vim: fdm=marker sw=2
|