Merge branch 'vim-with-runtime' into feat/quickfix-title
[vim_extended.git] / runtime / syntax / tex.vim
blob6235df118c8849669998a0b1720c3daa480c0e10
1 " Vim syntax file
2 " Language:     TeX
3 " Maintainer:   Dr. Charles E. Campbell, Jr. <NdrchipO@ScampbellPfamily.AbizM>
4 " Last Change:  Apr 14, 2010
5 " Version:      47
6 " URL:          http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
8 " Notes: {{{1
10 " 1. If you have a \begin{verbatim} that appears to overrun its boundaries,
11 "    use %stopzone.
13 " 2. Run-on equations ($..$ and $$..$$, particularly) can also be stopped
14 "    by suitable use of %stopzone.
16 " 3. If you have a slow computer, you may wish to modify
18 "       syn sync maxlines=200
19 "       syn sync minlines=50
21 "    to values that are more to your liking.
23 " 4. There is no match-syncing for $...$ and $$...$$; hence large
24 "    equation blocks constructed that way may exhibit syncing problems.
25 "    (there's no difference between begin/end patterns)
27 " 5. If you have the variable "g:tex_no_error" defined then none of the
28 "    lexical error-checking will be done.
30 "    ie. let g:tex_no_error=1
32 " Version Clears: {{{1
33 " For version 5.x: Clear all syntax items
34 " For version 6.x: Quit when a syntax file was already loaded
35 if version < 600
36   syntax clear
37 elseif exists("b:current_syntax")
38   finish
39 endif
41 " Define the default highlighting. {{{1
42 " For version 5.7 and earlier: only when not done already
43 " For version 5.8 and later: only when an item doesn't have highlighting yet
44 if version >= 508 || !exists("did_tex_syntax_inits")
45  let did_tex_syntax_inits = 1
46  if version < 508
47   command -nargs=+ HiLink hi link <args>
48  else
49   command -nargs=+ HiLink hi def link <args>
50  endif
51 endif
52 if exists("g:tex_tex") && !exists("g:tex_no_error")
53  let g:tex_no_error= 1
54 endif
56 " Determine whether or not to use "*.sty" mode {{{1
57 " The user may override the normal determination by setting
58 "   g:tex_stylish to 1      (for    "*.sty" mode)
59 "    or to           0 else (normal "*.tex" mode)
60 " or on a buffer-by-buffer basis with b:tex_stylish
61 let b:extfname=expand("%:e")
62 if exists("g:tex_stylish")
63  let b:tex_stylish= g:tex_stylish
64 elseif !exists("b:tex_stylish")
65  if b:extfname == "sty" || b:extfname == "cls" || b:extfname == "clo" || b:extfname == "dtx" || b:extfname == "ltx"
66   let b:tex_stylish= 1
67  else
68   let b:tex_stylish= 0
69  endif
70 endif
72 " handle folding {{{1
73 if !exists("g:tex_fold_enabled")
74  let g:tex_fold_enabled= 0
75 elseif g:tex_fold_enabled && !has("folding")
76  let g:tex_fold_enabled= 0
77  echomsg "Ignoring g:tex_fold_enabled=".g:tex_fold_enabled."; need to re-compile vim for +fold support"
78 endif
79 if g:tex_fold_enabled && &fdm == "manual"
80  setl fdm=syntax
81 endif
83 " (La)TeX keywords: only use the letters a-zA-Z {{{1
84 " but _ is the only one that causes problems.
85 if version < 600
86   set isk-=_
87   if b:tex_stylish
88     set isk+=@
89   endif
90 else
91   setlocal isk-=_
92   if b:tex_stylish
93     setlocal isk+=@
94   endif
95 endif
97 " Clusters: {{{1
98 " --------
99 syn cluster texCmdGroup         contains=texCmdBody,texComment,texDefParm,texDelimiter,texDocType,texInput,texLength,texLigature,texMathDelim,texMathOper,texNewCmd,texNewEnv,texRefZone,texSection,texSectionMarker,texSectionName,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle
100 if !exists("g:tex_no_error")
101  syn cluster texCmdGroup        add=texMathError
102 endif
103 syn cluster texEnvGroup         contains=texMatcher,texMathDelim,texSpecialChar,texStatement
104 syn cluster texFoldGroup        contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMatcher,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texSectionMarker,texSectionZone,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texTitle,texAbstract
105 syn cluster texMatchGroup       contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMatcher,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,texInputFile,texOption,@Spell
106 syn cluster texStyleGroup       contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,texInputFile,texOption,texStyleStatement,@Spell,texStyleMatcher
107 syn cluster texRefGroup         contains=texMatcher,texComment,texDelimiter
108 if !exists("tex_no_math")
109  syn cluster texMathZones       contains=texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ
110  syn cluster texMatchGroup      add=@texMathZones
111  syn cluster texMathDelimGroup  contains=texMathDelimBad,texMathDelimKey,texMathDelimSet1,texMathDelimSet2
112  syn cluster texMathMatchGroup  contains=@texMathZones,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMathDelim,texMathMatcher,texMathOper,texNewCmd,texNewEnv,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone
113  syn cluster texMathZoneGroup   contains=texComment,texDelimiter,texLength,texMathDelim,texMathMatcher,texMathOper,texRefZone,texSpecialChar,texStatement,texTypeSize,texTypeStyle
114  if !exists("g:tex_no_error")
115   syn cluster texMathMatchGroup add=texMathError
116   syn cluster texMathZoneGroup  add=texMathError
117  endif
118  syn cluster texMathZoneGroup add=@NoSpell
119  " following used in the \part \chapter \section \subsection \subsubsection
120  " \paragraph \subparagraph \author \title highlighting
121  syn cluster texDocGroup                contains=texPartZone,@texPartGroup
122  syn cluster texPartGroup               contains=texChapterZone,texSectionZone,texParaZone
123  syn cluster texChapterGroup            contains=texSectionZone,texParaZone
124  syn cluster texSectionGroup            contains=texSubSectionZone,texParaZone
125  syn cluster texSubSectionGroup         contains=texSubSubSectionZone,texParaZone
126  syn cluster texSubSubSectionGroup      contains=texParaZone
127  syn cluster texParaGroup               contains=texSubParaZone
128 endif
130 " Try to flag {} and () mismatches: {{{1
131 if !exists("g:tex_no_error")
132  syn region texMatcher          matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]"      end="}"         contains=@texMatchGroup,texError
133  syn region texMatcher          matchgroup=Delimiter start="\["                         end="]"         contains=@texMatchGroup,texError
134 else
135  syn region texMatcher          matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]"      end="}"         contains=@texMatchGroup
136  syn region texMatcher          matchgroup=Delimiter start="\["                         end="]"         contains=@texMatchGroup
137 endif
138 syn region texParen             start="("                                               end=")"         contains=@texMatchGroup,@Spell
139 if !exists("g:tex_no_error")
140  syn match  texError            "[}\])]"
141 endif
142 if !exists("tex_no_math")
143  if !exists("g:tex_no_error")
144   syn match  texMathError       "}"     contained
145  endif
146  syn region texMathMatcher      matchgroup=Delimiter start="{"  skip="\\\\\|\\}"  end="}" end="%stopzone\>" contained contains=@texMathMatchGroup
147 endif
149 " TeX/LaTeX keywords: {{{1
150 " Instead of trying to be All Knowing, I just match \..alphameric..
151 " Note that *.tex files may not have "@" in their \commands
152 if exists("g:tex_tex") || b:tex_stylish
153   syn match texStatement        "\\[a-zA-Z@]\+"
154 else
155   syn match texStatement        "\\\a\+"
156   if !exists("g:tex_no_error")
157    syn match texError           "\\\a*@[a-zA-Z@]*"
158   endif
159 endif
161 " TeX/LaTeX delimiters: {{{1
162 syn match texDelimiter          "&"
163 syn match texDelimiter          "\\\\"
165 " Tex/Latex Options: {{{1
166 syn match texOption     "[^\\]\zs#\d\+\|^#\d\+"
168 " texAccent (tnx to Karim Belabas) avoids annoying highlighting for accents: {{{1
169 if b:tex_stylish
170   syn match texAccent           "\\[bcdvuH][^a-zA-Z@]"me=e-1
171   syn match texLigature         "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)[^a-zA-Z@]"me=e-1
172 else
173   syn match texAccent           "\\[bcdvuH]\A"me=e-1
174   syn match texLigature         "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)\A"me=e-1
175 endif
176 syn match texAccent             "\\[bcdvuH]$"
177 syn match texAccent             +\\[=^.\~"`']+
178 syn match texAccent             +\\['=t'.c^ud"vb~Hr]{\a}+
179 syn match texLigature           "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)$"
181 " \begin{}/\end{} section markers: {{{1
182 syn match  texSectionMarker     "\\begin\>\|\\end\>" nextgroup=texSectionName
183 syn region texSectionName       matchgroup=Delimiter start="{" end="}"  contained       nextgroup=texSectionModifier    contains=texComment
184 syn region texSectionModifier   matchgroup=Delimiter start="\[" end="]" contained       contains=texComment
186 " \documentclass, \documentstyle, \usepackage: {{{1
187 syn match  texDocType           "\\documentclass\>\|\\documentstyle\>\|\\usepackage\>"  nextgroup=texSectionName,texDocTypeArgs
188 syn region texDocTypeArgs       matchgroup=Delimiter start="\[" end="]"                 contained       nextgroup=texSectionName        contains=texComment
190 " Preamble syntax-based folding support: {{{1
191 if g:tex_fold_enabled && has("folding")
192  syn region texPreamble transparent fold        start='\zs\\documentclass\>' end='\ze\\begin{document}' contains=texStyle,@texMatchGroup
193 endif
195 " TeX input: {{{1
196 syn match texInput              "\\input\s\+[a-zA-Z/.0-9_^]\+"hs=s+7                            contains=texStatement
197 syn match texInputFile          "\\include\(graphics\|list\)\=\(\[.\{-}\]\)\=\s*{.\{-}}"        contains=texStatement,texInputCurlies,texInputFileOpt
198 syn match texInputFile          "\\\(epsfig\|input\|usepackage\)\s*\(\[.*\]\)\={.\{-}}"         contains=texStatement,texInputCurlies,texInputFileOpt
199 syn match texInputCurlies       "[{}]"                                                          contained
200 syn region texInputFileOpt      matchgroup=Delimiter start="\[" end="\]"                        contained       contains=texComment
202 " Type Styles (LaTeX 2.09): {{{1
203 syn match texTypeStyle          "\\rm\>"
204 syn match texTypeStyle          "\\em\>"
205 syn match texTypeStyle          "\\bf\>"
206 syn match texTypeStyle          "\\it\>"
207 syn match texTypeStyle          "\\sl\>"
208 syn match texTypeStyle          "\\sf\>"
209 syn match texTypeStyle          "\\sc\>"
210 syn match texTypeStyle          "\\tt\>"
212 " Type Styles: attributes, commands, families, etc (LaTeX2E): {{{1
213 syn match texTypeStyle          "\\textbf\>"
214 syn match texTypeStyle          "\\textit\>"
215 syn match texTypeStyle          "\\textmd\>"
216 syn match texTypeStyle          "\\textrm\>"
217 syn match texTypeStyle          "\\textsc\>"
218 syn match texTypeStyle          "\\textsf\>"
219 syn match texTypeStyle          "\\textsl\>"
220 syn match texTypeStyle          "\\texttt\>"
221 syn match texTypeStyle          "\\textup\>"
222 syn match texTypeStyle          "\\emph\>"
224 syn match texTypeStyle          "\\mathbb\>"
225 syn match texTypeStyle          "\\mathbf\>"
226 syn match texTypeStyle          "\\mathcal\>"
227 syn match texTypeStyle          "\\mathfrak\>"
228 syn match texTypeStyle          "\\mathit\>"
229 syn match texTypeStyle          "\\mathnormal\>"
230 syn match texTypeStyle          "\\mathrm\>"
231 syn match texTypeStyle          "\\mathsf\>"
232 syn match texTypeStyle          "\\mathtt\>"
234 syn match texTypeStyle          "\\rmfamily\>"
235 syn match texTypeStyle          "\\sffamily\>"
236 syn match texTypeStyle          "\\ttfamily\>"
238 syn match texTypeStyle          "\\itshape\>"
239 syn match texTypeStyle          "\\scshape\>"
240 syn match texTypeStyle          "\\slshape\>"
241 syn match texTypeStyle          "\\upshape\>"
243 syn match texTypeStyle          "\\bfseries\>"
244 syn match texTypeStyle          "\\mdseries\>"
246 " Some type sizes: {{{1
247 syn match texTypeSize           "\\tiny\>"
248 syn match texTypeSize           "\\scriptsize\>"
249 syn match texTypeSize           "\\footnotesize\>"
250 syn match texTypeSize           "\\small\>"
251 syn match texTypeSize           "\\normalsize\>"
252 syn match texTypeSize           "\\large\>"
253 syn match texTypeSize           "\\Large\>"
254 syn match texTypeSize           "\\LARGE\>"
255 syn match texTypeSize           "\\huge\>"
256 syn match texTypeSize           "\\Huge\>"
258 " Spacecodes (TeX'isms): {{{1
259 " \mathcode`\^^@="2201  \delcode`\(="028300  \sfcode`\)=0 \uccode`X=`X  \lccode`x=`x
260 syn match texSpaceCode          "\\\(math\|cat\|del\|lc\|sf\|uc\)code`"me=e-1 nextgroup=texSpaceCodeChar
261 syn match texSpaceCodeChar    "`\\\=.\(\^.\)\==\(\d\|\"\x\{1,6}\|`.\)"  contained
263 " Sections, subsections, etc: {{{1
264 if g:tex_fold_enabled && has("folding")
265  syn region texDocZone                  matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}'                                                                                 fold contains=@texFoldGroup,@texDocGroup,@Spell
266  syn region texPartZone                 matchgroup=texSection start='\\part\>'                   end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)'                                                              fold contains=@texFoldGroup,@texPartGroup,@Spell
267  syn region texChapterZone              matchgroup=texSection start='\\chapter\>'                end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)'                                                   fold contains=@texFoldGroup,@texChapterGroup,@Spell
268  syn region texSectionZone              matchgroup=texSection start='\\section\>'                end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                                        fold contains=@texFoldGroup,@texSectionGroup,@Spell
269  syn region texSubSectionZone           matchgroup=texSection start='\\subsection\>'             end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                              fold contains=@texFoldGroup,@texSubSectionGroup,@Spell
270  syn region texSubSubSectionZone        matchgroup=texSection start='\\subsubsection\>'          end='\ze\s*\\\%(\%(sub\)\{,2}section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                           fold contains=@texFoldGroup,@texSubSubSectionGroup,@Spell
271  syn region texParaZone                 matchgroup=texSection start='\\paragraph\>'              end='\ze\s*\\\%(paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                  fold contains=@texFoldGroup,@texParaGroup,@Spell
272  syn region texSubParaZone              matchgroup=texSection start='\\subparagraph\>'           end='\ze\s*\\\%(\%(sub\)\=paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'        fold contains=@texFoldGroup,@Spell
273  syn region texTitle                    matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}'                                                                                                        fold contains=@texFoldGroup,@Spell
274  syn region texAbstract                 matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}'                                                                                 fold contains=@texFoldGroup,@Spell
275 else
276  syn region texDocZone                  matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}'                                                                                 contains=@texFoldGroup,@texDocGroup,@Spell
277  syn region texPartZone                 matchgroup=texSection start='\\part\>'                   end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)'                                                              contains=@texFoldGroup,@texPartGroup,@Spell
278  syn region texChapterZone              matchgroup=texSection start='\\chapter\>'                end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)'                                                   contains=@texFoldGroup,@texChapterGroup,@Spell
279  syn region texSectionZone              matchgroup=texSection start='\\section\>'                end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                                        contains=@texFoldGroup,@texSectionGroup,@Spell
280  syn region texSubSectionZone           matchgroup=texSection start='\\subsection\>'             end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                              contains=@texFoldGroup,@texSubSectionGroup,@Spell
281  syn region texSubSubSectionZone        matchgroup=texSection start='\\subsubsection\>'          end='\ze\s*\\\%(\%(sub\)\{,2}section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                           contains=@texFoldGroup,@texSubSubSectionGroup,@Spell
282  syn region texParaZone                 matchgroup=texSection start='\\paragraph\>'              end='\ze\s*\\\%(paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                  contains=@texFoldGroup,@texParaGroup,@Spell
283  syn region texSubParaZone              matchgroup=texSection start='\\subparagraph\>'           end='\ze\s*\\\%(\%(sub\)\=paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'        contains=@texFoldGroup,@Spell
284  syn region texTitle                    matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}'                                                                                                        contains=@texFoldGroup,@Spell
285  syn region texAbstract                 matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}'                                                                                 contains=@texFoldGroup,@Spell
286 endif
288 " Bad Math (mismatched): {{{1
289 if !exists("tex_no_math")
290  syn match texBadMath           "\\end\s*{\s*\(array\|gathered\|bBpvV]matrix\|split\|subequations\|smallmatrix\|xxalignat\)\s*}"
291  syn match texBadMath           "\\end\s*{\s*\(align\|alignat\|displaymath\|displaymath\|eqnarray\|equation\|flalign\|gather\|math\|multline\|xalignat\)\*\=\s*}"
292  syn match texBadMath           "\\[\])]"
293 endif
295 " Math Zones: {{{1
296 if !exists("tex_no_math")
297  " TexNewMathZone: function creates a mathzone with the given suffix and mathzone name. {{{2
298  "                 Starred forms are created if starform is true.  Starred
299  "                 forms have syntax group and synchronization groups with a
300  "                 "S" appended.  Handles: cluster, syntax, sync, and HiLink.
301  fun! TexNewMathZone(sfx,mathzone,starform)
302    let grpname  = "texMathZone".a:sfx
303    let syncname = "texSyncMathZone".a:sfx
304    if g:tex_fold_enabled
305     let foldcmd= " fold"
306    else
307     let foldcmd= ""
308    endif
309    exe "syn cluster texMathZones add=".grpname
310    exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\s*}'."'".' keepend contains=@texMathZoneGroup'.foldcmd
311    exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
312    exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
313    exe 'hi def link '.grpname.' texMath'
314    if a:starform
315     let grpname  = "texMathZone".a:sfx.'S'
316     let syncname = "texSyncMathZone".a:sfx.'S'
317     exe "syn cluster texMathZones add=".grpname
318     exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\*\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\*\s*}'."'".' keepend contains=@texMathZoneGroup'.foldcmd
319     exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
320     exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
321     exe 'hi def link '.grpname.' texMath'
322    endif
323  endfun
325  " Standard Math Zones: {{{2
326  call TexNewMathZone("A","align",1)
327  call TexNewMathZone("B","alignat",1)
328  call TexNewMathZone("C","displaymath",1)
329  call TexNewMathZone("D","eqnarray",1)
330  call TexNewMathZone("E","equation",1)
331  call TexNewMathZone("F","flalign",1)
332  call TexNewMathZone("G","gather",1)
333  call TexNewMathZone("H","math",1)
334  call TexNewMathZone("I","multline",1)
335  call TexNewMathZone("J","subequations",0)
336  call TexNewMathZone("K","xalignat",1)
337  call TexNewMathZone("L","xxalignat",0)
339  " Inline Math Zones: {{{2
340  syn region texMathZoneV        matchgroup=Delimiter start="\\("        matchgroup=Delimiter end="\\)\|%stopzone\>"     keepend contains=@texMathZoneGroup
341  syn region texMathZoneW        matchgroup=Delimiter start="\\\["       matchgroup=Delimiter end="\\]\|%stopzone\>"     keepend contains=@texMathZoneGroup
342  syn region texMathZoneX        matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>"       contains=@texMathZoneGroup
343  syn region texMathZoneY        matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" end="%stopzone\>"     keepend         contains=@texMathZoneGroup
344  syn region texMathZoneZ        matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" end="%stopzone\>"      contains=@texMathZoneGroup
346  syn match texMathOper          "[_^=]" contained
348  " \left..something.. and \right..something.. support: {{{2
349  syn match   texMathDelimBad    contained               "\S"
350  syn match   texMathDelim       contained               "\\\(left\|right\|[bB]igg\=[lr]\)\>"    skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad
351  syn match   texMathDelim       contained               "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\=vert\>"
352  syn match   texMathDelim       contained               "\\lefteqn\>"
353  syn match   texMathDelimSet2   contained       "\\"            nextgroup=texMathDelimKey,texMathDelimBad
354  syn match   texMathDelimSet1   contained       "[<>()[\]|/.]\|\\[{}|]"
355  syn keyword texMathDelimKey    contained       backslash       lceil           lVert           rgroup          uparrow
356  syn keyword texMathDelimKey    contained       downarrow       lfloor          rangle          rmoustache      Uparrow
357  syn keyword texMathDelimKey    contained       Downarrow       lgroup          rbrace          rvert           updownarrow
358  syn keyword texMathDelimKey    contained       langle          lmoustache      rceil           rVert           Updownarrow
359  syn keyword texMathDelimKey    contained       lbrace          lvert           rfloor
360 endif
362 " Special TeX characters  ( \$ \& \% \# \{ \} \_ \S \P ) : {{{1
363 syn match texSpecialChar        "\\[$&%#{}_]"
364 if b:tex_stylish
365   syn match texSpecialChar      "\\[SP@][^a-zA-Z@]"me=e-1
366 else
367   syn match texSpecialChar      "\\[SP@]\A"me=e-1
368 endif
369 syn match texSpecialChar        "\\\\"
370 if !exists("tex_no_math")
371  syn match texOnlyMath          "[_^]"
372 endif
373 syn match texSpecialChar        "\^\^[0-9a-f]\{2}\|\^\^\S"
375 " Comments: {{{1
376 "    Normal TeX LaTeX     :   %....
377 "    Documented TeX Format:  ^^A...     -and-   leading %s (only)
378 if !exists("g:tex_comment_nospell") || !g:tex_comment_nospell
379  syn cluster texCommentGroup    contains=texTodo,@Spell
380 else
381  syn cluster texCommentGroup    contains=texTodo,@NoSpell
382 endif
383 syn case ignore
384 syn keyword texTodo             contained               combak  fixme   todo    xxx
385 syn case match
386 if b:extfname == "dtx"
387   syn match texComment          "\^\^A.*$"      contains=@texCommentGroup
388   syn match texComment          "^%\+"          contains=@texCommentGroup
389 else
390   if g:tex_fold_enabled
391    " allows syntax-folding of 2 or more contiguous comment lines
392    " single-line comments are not folded
393    syn match  texComment        "%.*$"          contains=@texCommentGroup
394    syn region texComment        start="^\zs\s*%.*\_s*%" skip="^\s*%"    end='^\ze\s*[^%]' fold
395   else
396    syn match texComment         "%.*$"          contains=@texCommentGroup
397   endif
398 endif
400 " Separate lines used for verb` and verb# so that the end conditions {{{1
401 " will appropriately terminate.  Ideally vim would let me save a
402 " character from the start pattern and re-use it in the end-pattern.
403 syn region texZone              start="\\begin{[vV]erbatim}"            end="\\end{[vV]erbatim}\|%stopzone\>"   contains=@Spell
404 " listings package:
405 syn region texZone              start="\\begin{lstlisting}"             end="\\end{lstlisting}\|%stopzone\>"    contains=@Spell
406 " moreverb package:
407 syn region texZone              start="\\begin{verbatimtab}"            end="\\end{verbatimtab}\|%stopzone\>"   contains=@Spell
408 syn region texZone              start="\\begin{verbatimwrite}"          end="\\end{verbatimwrite}\|%stopzone\>" contains=@Spell
409 syn region texZone              start="\\begin{boxedverbatim}"          end="\\end{boxedverbatim}\|%stopzone\>" contains=@Spell
410 if version < 600
411  syn region texZone             start="\\verb\*\=`"                     end="`\|%stopzone\>"
412  syn region texZone             start="\\verb\*\=#"                     end="#\|%stopzone\>"
413 else
414   if b:tex_stylish
415     syn region texZone          start="\\verb\*\=\z([^\ta-zA-Z@]\)"     end="\z1\|%stopzone\>"
416   else
417     syn region texZone          start="\\verb\*\=\z([^\ta-zA-Z]\)"      end="\z1\|%stopzone\>"
418   endif
419 endif
421 " Tex Reference Zones: {{{1
422 syn region texZone              matchgroup=texStatement start="@samp{"                  end="}\|%stopzone\>"    contains=@texRefGroup
423 syn region texRefZone           matchgroup=texStatement start="\\nocite{"               end="}\|%stopzone\>"    contains=@texRefGroup
424 syn region texRefZone           matchgroup=texStatement start="\\bibliography{"         end="}\|%stopzone\>"    contains=@texRefGroup
425 syn region texRefZone           matchgroup=texStatement start="\\label{"                end="}\|%stopzone\>"    contains=@texRefGroup
426 syn region texRefZone           matchgroup=texStatement start="\\\(page\|eq\)ref{"      end="}\|%stopzone\>"    contains=@texRefGroup
427 syn region texRefZone           matchgroup=texStatement start="\\v\=ref{"               end="}\|%stopzone\>"    contains=@texRefGroup
428 syn match  texRefZone           '\\cite\%([tp]\*\=\)\=' nextgroup=texRefOption,texCite
429 syn region texRefOption contained       matchgroup=Delimiter start='\[' end=']'         contains=@texRefGroup   nextgroup=texRefOption,texCite
430 syn region texCite      contained       matchgroup=Delimiter start='{' end='}'          contains=@texRefGroup
432 " Handle newcommand, newenvironment : {{{1
433 syn match  texNewCmd                            "\\newcommand\>"                        nextgroup=texCmdName skipwhite skipnl
434 syn region texCmdName contained matchgroup=Delimiter start="{"rs=s+1  end="}"           nextgroup=texCmdArgs,texCmdBody skipwhite skipnl
435 syn region texCmdArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]"           nextgroup=texCmdBody skipwhite skipnl
436 syn region texCmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]"        matchgroup=Delimiter end="}" contains=@texCmdGroup
437 syn match  texNewEnv                            "\\newenvironment\>"                    nextgroup=texEnvName skipwhite skipnl
438 syn region texEnvName contained matchgroup=Delimiter start="{"rs=s+1  end="}"           nextgroup=texEnvBgn skipwhite skipnl
439 syn region texEnvBgn  contained matchgroup=Delimiter start="{"rs=s+1  end="}"           nextgroup=texEnvEnd skipwhite skipnl contains=@texEnvGroup
440 syn region texEnvEnd  contained matchgroup=Delimiter start="{"rs=s+1  end="}"           skipwhite skipnl contains=@texEnvGroup
442 " Definitions/Commands: {{{1
443 syn match texDefCmd                             "\\def\>"                               nextgroup=texDefName skipwhite skipnl
444 if b:tex_stylish
445   syn match texDefName contained                "\\[a-zA-Z@]\+"                         nextgroup=texDefParms,texCmdBody skipwhite skipnl
446   syn match texDefName contained                "\\[^a-zA-Z@]"                          nextgroup=texDefParms,texCmdBody skipwhite skipnl
447 else
448   syn match texDefName contained                "\\\a\+"                                nextgroup=texDefParms,texCmdBody skipwhite skipnl
449   syn match texDefName contained                "\\\A"                                  nextgroup=texDefParms,texCmdBody skipwhite skipnl
450 endif
451 syn match texDefParms  contained                "#[^{]*"        contains=texDefParm     nextgroup=texCmdBody skipwhite skipnl
452 syn match  texDefParm  contained                "#\d\+"
454 " TeX Lengths: {{{1
455 syn match  texLength            "\<\d\+\([.,]\d\+\)\=\s*\(true\)\=\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>"
457 " TeX String Delimiters: {{{1
458 syn match texString             "\(``\|''\|,,\)"
460 " makeatletter -- makeatother sections
461 if !exists("g:tex_no_error")
462  syn region texStyle                    matchgroup=texStatement start='\\makeatletter' end='\\makeatother'      contains=@texStyleGroup contained
463  syn match  texStyleStatement           "\\[a-zA-Z@]\+" contained
464  syn region texStyleMatcher             matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]"      end="}"         contains=@texStyleGroup,texError        contained
465  syn region texStyleMatcher             matchgroup=Delimiter start="\["                         end="]"         contains=@texStyleGroup,texError        contained
466 endif
468 " LaTeX synchronization: {{{1
469 syn sync maxlines=200
470 syn sync minlines=50
472 syn  sync match texSyncStop                     groupthere NONE         "%stopzone\>"
474 " Synchronization: {{{1
475 " The $..$ and $$..$$ make for impossible sync patterns
476 " (one can't tell if a "$$" starts or stops a math zone by itself)
477 " The following grouptheres coupled with minlines above
478 " help improve the odds of good syncing.
479 if !exists("tex_no_math")
480  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{abstract}"
481  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{center}"
482  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{description}"
483  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{enumerate}"
484  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{itemize}"
485  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{table}"
486  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{tabular}"
487  syn sync match texSyncMathZoneA                groupthere NONE         "\\\(sub\)*section\>"
488 endif
490 " Highlighting: {{{1
491 if did_tex_syntax_inits == 1
492  let did_tex_syntax_inits= 2
493   " TeX highlighting groups which should share similar highlighting
494   if !exists("g:tex_no_error")
495    if !exists("tex_no_math")
496     HiLink texBadMath           texError
497     HiLink texMathDelimBad      texError
498     HiLink texMathError         texError
499     if !b:tex_stylish
500       HiLink texOnlyMath        texError
501     endif
502    endif
503    HiLink texError              Error
504   endif
506   HiLink texCite                texRefZone
507   HiLink texDefCmd              texDef
508   HiLink texDefName             texDef
509   HiLink texDocType             texCmdName
510   HiLink texDocTypeArgs         texCmdArgs
511   HiLink texInputFileOpt        texCmdArgs
512   HiLink texInputCurlies        texDelimiter
513   HiLink texLigature            texSpecialChar
514   if !exists("tex_no_math")
515    HiLink texMathDelimSet1      texMathDelim
516    HiLink texMathDelimSet2      texMathDelim
517    HiLink texMathDelimKey       texMathDelim
518    HiLink texMathMatcher        texMath
519    HiLink texMathZoneV          texMath
520    HiLink texMathZoneW          texMath
521    HiLink texMathZoneX          texMath
522    HiLink texMathZoneY          texMath
523    HiLink texMathZoneV          texMath
524    HiLink texMathZoneZ          texMath
525   endif
526   HiLink texSectionMarker       texCmdName
527   HiLink texSectionName         texSection
528   HiLink texSpaceCode           texStatement
529   HiLink texStyleStatement      texStatement
530   HiLink texTypeSize            texType
531   HiLink texTypeStyle           texType
533    " Basic TeX highlighting groups
534   HiLink texCmdArgs             Number
535   HiLink texCmdName             Statement
536   HiLink texComment             Comment
537   HiLink texDef                 Statement
538   HiLink texDefParm             Special
539   HiLink texDelimiter           Delimiter
540   HiLink texInput               Special
541   HiLink texInputFile           Special
542   HiLink texLength              Number
543   HiLink texMath                Special
544   HiLink texMathDelim           Statement
545   HiLink texMathOper            Operator
546   HiLink texNewCmd              Statement
547   HiLink texNewEnv              Statement
548   HiLink texOption              Number
549   HiLink texRefZone             Special
550   HiLink texSection             PreCondit
551   HiLink texSpaceCodeChar       Special
552   HiLink texSpecialChar         SpecialChar
553   HiLink texStatement           Statement
554   HiLink texString              String
555   HiLink texTodo                Todo
556   HiLink texType                Type
557   HiLink texZone                PreCondit
559   delcommand HiLink
560 endif
562 " Current Syntax: {{{1
563 unlet b:extfname
564 let   b:current_syntax = "tex"
565 " vim: ts=8 fdm=marker