summaryrefslogtreecommitdiffstats
path: root/autoload/vimtex/syntax/load.vim
blob: 3b61d88699f7aa45b922178953f0785af1d3c7ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1

" vimtex - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve Lervåg
" Email:      karl.yngve@gmail.com
"

function! vimtex#syntax#load#general() abort " {{{1
  if !exists('b:vimtex_syntax') | return | endif

  " I don't see why we can't match Math zones in the MatchNMGroup
  if !exists('g:tex_no_math')
    syntax cluster texMatchNMGroup add=@texMathZones
  endif

  " Todo elements
  syntax match texStatement '\\todo\w*' contains=texTodo
  syntax match texTodo '\\todo\w*'

  " Fix strange mistake in main syntax file where \usepackage is added to the
  " texInputFile group
  syntax match texDocType /\\usepackage\>/
        \ nextgroup=texBeginEndName,texDocTypeArgs

  " Improve support for italic font, bold font and some conceals
  if get(g:, 'tex_fast', 'b') =~# 'b'
    let s:conceal = (has('conceal') && get(g:, 'tex_conceal', 'b') =~# 'b')
          \ ? 'concealends' : ''

    for [s:style, s:group, s:commands] in [
          \ ['texItalStyle', 'texItalGroup', ['emph', 'textit']],
          \ ['texBoldStyle', 'texBoldGroup', ['textbf']],
          \]
      for s:cmd in s:commands
        execute 'syntax region' s:style 'matchgroup=texTypeStyle'
              \ 'start="\\' . s:cmd . '\s*{" end="}"'
              \ 'contains=@Spell,@' . s:group
              \ s:conceal
      endfor
      execute 'syntax cluster texMatchGroup add=' . s:style
    endfor
  endif

  " Allow arguments in newenvironments
  syntax region texEnvName contained matchgroup=Delimiter
        \ start="{"rs=s+1  end="}"
        \ nextgroup=texEnvBgn,texEnvArgs contained skipwhite skipnl
  syntax region texEnvArgs contained matchgroup=Delimiter
        \ start="\["rs=s+1 end="]"
        \ nextgroup=texEnvBgn,texEnvArgs skipwhite skipnl
  syntax cluster texEnvGroup add=texDefParm,texNewEnv,texComment

  " Add support for \renewenvironment and \renewcommand
  syntax match texNewEnv "\\renewenvironment\>"
        \ nextgroup=texEnvName skipwhite skipnl
  syntax match texNewCmd "\\renewcommand\>"
        \ nextgroup=texCmdName skipwhite skipnl

  " Match nested DefParms
  syntax match texDefParmNested contained "##\+\d\+"
  highlight def link texDefParmNested Identifier
  syntax cluster texEnvGroup add=texDefParmNested
  syntax cluster texCmdGroup add=texDefParmNested
endfunction

" }}}1
function! vimtex#syntax#load#packages() abort " {{{1
  if !exists('b:vimtex_syntax') | return | endif

  try
    call vimtex#syntax#p#{b:vimtex.documentclass}#load()
  catch /E117:/
  endtry

  for l:pkg in map(keys(b:vimtex.packages), "substitute(v:val, '-', '_', 'g')")
    try
      call vimtex#syntax#p#{l:pkg}#load()
    catch /E117:/
    endtry
  endfor

  for l:pkg in g:vimtex_syntax_autoload_packages
    try
      call vimtex#syntax#p#{l:pkg}#load()
    catch /E117:/
      call vimtex#log#warning('Syntax package does not exist: ' . l:pkg,
            \ 'Please see :help g:vimtex_syntax_autoload_packages')
    endtry
  endfor
endfunction

" }}}1

endif