Merged from the latest developing branch.
[MacVim/KaoriYa.git] / runtime / syntax / tex.vim
blob1393a5826ab807cf64f8b479181e566deba1ad57
1 " Vim syntax file
2 " Language:     TeX
3 " Maintainer:   Dr. Charles E. Campbell, Jr. <NdrchipO@ScampbellPfamily.AbizM>
4 " Last Change:  Jun 03, 2008
5 " Version:      41
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  set 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 texRefGroup         contains=texMatcher,texComment,texDelimiter
107 if !exists("tex_no_math")
108  syn cluster texMathZones       contains=texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ
109  syn cluster texMatchGroup      add=@texMathZones
110  syn cluster texMathDelimGroup  contains=texMathDelimBad,texMathDelimKey,texMathDelimSet1,texMathDelimSet2
111  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
112  syn cluster texMathZoneGroup   contains=texComment,texDelimiter,texLength,texMathDelim,texMathMatcher,texMathOper,texRefZone,texSpecialChar,texStatement,texTypeSize,texTypeStyle
113  if !exists("g:tex_no_error")
114   syn cluster texMathMatchGroup add=texMathError
115   syn cluster texMathZoneGroup  add=texMathError
116  endif
117  syn cluster texMathZoneGroup add=@NoSpell
118  " following used in the \part \chapter \section \subsection \subsubsection
119  " \paragraph \subparagraph \author \title highlighting
120  syn cluster texDocGroup                contains=texPartZone,@texPartGroup
121  syn cluster texPartGroup               contains=texChapterZone,texSectionZone,texParaZone
122  syn cluster texChapterGroup            contains=texSectionZone,texParaZone
123  syn cluster texSectionGroup            contains=texSubSectionZone,texParaZone
124  syn cluster texSubSectionGroup         contains=texSubSubSectionZone,texParaZone
125  syn cluster texSubSubSectionGroup      contains=texParaZone
126  syn cluster texParaGroup               contains=texSubParaZone
127 endif
129 " Try to flag {} and () mismatches: {{{1
130 if !exists("g:tex_no_error")
131  syn region texMatcher          matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]"      end="}"         contains=@texMatchGroup,texError
132  syn region texMatcher          matchgroup=Delimiter start="\["                         end="]"         contains=@texMatchGroup,texError
133 else
134  syn region texMatcher          matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]"      end="}"         contains=@texMatchGroup
135  syn region texMatcher          matchgroup=Delimiter start="\["                         end="]"         contains=@texMatchGroup
136 endif
137 syn region texParen             start="("                                               end=")"         contains=@texMatchGroup,@Spell
138 if !exists("g:tex_no_error")
139  syn match  texError            "[}\])]"
140 endif
141 if !exists("tex_no_math")
142  if !exists("g:tex_no_error")
143   syn match  texMathError       "}"     contained
144  endif
145  syn region texMathMatcher      matchgroup=Delimiter start="{"  skip="\\\\\|\\}"  end="}" end="%stopzone\>" contained contains=@texMathMatchGroup
146 endif
148 " TeX/LaTeX keywords: {{{1
149 " Instead of trying to be All Knowing, I just match \..alphameric..
150 " Note that *.tex files may not have "@" in their \commands
151 if exists("g:tex_tex") || b:tex_stylish
152   syn match texStatement        "\\[a-zA-Z@]\+"
153 else
154   syn match texStatement        "\\\a\+"
155   if !exists("g:tex_no_error")
156    syn match texError           "\\\a*@[a-zA-Z@]*"
157   endif
158 endif
160 " TeX/LaTeX delimiters: {{{1
161 syn match texDelimiter          "&"
162 syn match texDelimiter          "\\\\"
164 " Tex/Latex Options: {{{1
165 syn match texOption     "[^\\]\zs#\d\+\|^#\d\+"
167 " texAccent (tnx to Karim Belabas) avoids annoying highlighting for accents: {{{1
168 if b:tex_stylish
169   syn match texAccent           "\\[bcdvuH][^a-zA-Z@]"me=e-1
170   syn match texLigature         "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)[^a-zA-Z@]"me=e-1
171 else
172   syn match texAccent           "\\[bcdvuH]\A"me=e-1
173   syn match texLigature         "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)\A"me=e-1
174 endif
175 syn match texAccent             "\\[bcdvuH]$"
176 syn match texAccent             +\\[=^.\~"`']+
177 syn match texAccent             +\\['=t'.c^ud"vb~Hr]{\a}+
178 syn match texLigature           "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)$"
180 " \begin{}/\end{} section markers: {{{1
181 syn match  texSectionMarker     "\\begin\>\|\\end\>" nextgroup=texSectionName
182 syn region texSectionName       matchgroup=Delimiter start="{" end="}"  contained nextgroup=texSectionModifier
183 syn region texSectionModifier   matchgroup=Delimiter start="\[" end="]" contained
185 " \documentclass, \documentstyle, \usepackage: {{{1
186 syn match  texDocType           "\\documentclass\>\|\\documentstyle\>\|\\usepackage\>"  nextgroup=texSectionName,texDocTypeArgs
187 syn region texDocTypeArgs       matchgroup=Delimiter start="\[" end="]"                 contained       nextgroup=texSectionName
189 " Preamble syntax-based folding support: {{{1
190 if g:tex_fold_enabled && has("folding")
191  syn region texPreamble transparent fold        start='\zs\\documentclass\>' end='\ze\\begin{document}' contains=@texMatchGroup
192 endif
194 " TeX input: {{{1
195 syn match texInput              "\\input\s\+[a-zA-Z/.0-9_^]\+"hs=s+7                            contains=texStatement
196 syn match texInputFile          "\\include\(graphics\|list\)\=\(\[.\{-}\]\)\=\s*{.\{-}}"        contains=texStatement,texInputCurlies
197 syn match texInputFile          "\\\(epsfig\|input\|usepackage\)\s*\(\[.*\]\)\={.\{-}}"         contains=texStatement,texInputCurlies,texInputFileOpt
198 syn match texInputCurlies       "[{}]"                                                          contained
199 syn region texInputFileOpt      matchgroup=Delimiter start="\[" end="\]"                        contained
201 " Type Styles (LaTeX 2.09): {{{1
202 syn match texTypeStyle          "\\rm\>"
203 syn match texTypeStyle          "\\em\>"
204 syn match texTypeStyle          "\\bf\>"
205 syn match texTypeStyle          "\\it\>"
206 syn match texTypeStyle          "\\sl\>"
207 syn match texTypeStyle          "\\sf\>"
208 syn match texTypeStyle          "\\sc\>"
209 syn match texTypeStyle          "\\tt\>"
211 " Type Styles: attributes, commands, families, etc (LaTeX2E): {{{1
212 syn match texTypeStyle          "\\textbf\>"
213 syn match texTypeStyle          "\\textit\>"
214 syn match texTypeStyle          "\\textmd\>"
215 syn match texTypeStyle          "\\textrm\>"
216 syn match texTypeStyle          "\\textsc\>"
217 syn match texTypeStyle          "\\textsf\>"
218 syn match texTypeStyle          "\\textsl\>"
219 syn match texTypeStyle          "\\texttt\>"
220 syn match texTypeStyle          "\\textup\>"
221 syn match texTypeStyle          "\\emph\>"
223 syn match texTypeStyle          "\\mathbb\>"
224 syn match texTypeStyle          "\\mathbf\>"
225 syn match texTypeStyle          "\\mathcal\>"
226 syn match texTypeStyle          "\\mathfrak\>"
227 syn match texTypeStyle          "\\mathit\>"
228 syn match texTypeStyle          "\\mathnormal\>"
229 syn match texTypeStyle          "\\mathrm\>"
230 syn match texTypeStyle          "\\mathsf\>"
231 syn match texTypeStyle          "\\mathtt\>"
233 syn match texTypeStyle          "\\rmfamily\>"
234 syn match texTypeStyle          "\\sffamily\>"
235 syn match texTypeStyle          "\\ttfamily\>"
237 syn match texTypeStyle          "\\itshape\>"
238 syn match texTypeStyle          "\\scshape\>"
239 syn match texTypeStyle          "\\slshape\>"
240 syn match texTypeStyle          "\\upshape\>"
242 syn match texTypeStyle          "\\bfseries\>"
243 syn match texTypeStyle          "\\mdseries\>"
245 " Some type sizes: {{{1
246 syn match texTypeSize           "\\tiny\>"
247 syn match texTypeSize           "\\scriptsize\>"
248 syn match texTypeSize           "\\footnotesize\>"
249 syn match texTypeSize           "\\small\>"
250 syn match texTypeSize           "\\normalsize\>"
251 syn match texTypeSize           "\\large\>"
252 syn match texTypeSize           "\\Large\>"
253 syn match texTypeSize           "\\LARGE\>"
254 syn match texTypeSize           "\\huge\>"
255 syn match texTypeSize           "\\Huge\>"
257 " Spacecodes (TeX'isms): {{{1
258 " \mathcode`\^^@="2201  \delcode`\(="028300  \sfcode`\)=0 \uccode`X=`X  \lccode`x=`x
259 syn match texSpaceCode          "\\\(math\|cat\|del\|lc\|sf\|uc\)code`"me=e-1 nextgroup=texSpaceCodeChar
260 syn match texSpaceCodeChar    "`\\\=.\(\^.\)\==\(\d\|\"\x\{1,6}\|`.\)"  contained
262 " Sections, subsections, etc: {{{1
263 if g:tex_fold_enabled && has("folding")
264  syn region texDocZone                  matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}'                                                                                 fold contains=@texFoldGroup,@texDocGroup,@Spell
265  syn region texPartZone                 matchgroup=texSection start='\\part\>'                   end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)'                                                              fold contains=@texFoldGroup,@texPartGroup,@Spell
266  syn region texChapterZone              matchgroup=texSection start='\\chapter\>'                end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)'                                                   fold contains=@texFoldGroup,@texChapterGroup,@Spell
267  syn region texSectionZone              matchgroup=texSection start='\\section\>'                end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                                        fold contains=@texFoldGroup,@texSectionGroup,@Spell
268  syn region texSubSectionZone           matchgroup=texSection start='\\subsection\>'             end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                              fold contains=@texFoldGroup,@texSubSectionGroup,@Spell
269  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
270  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
271  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
272  syn region texTitle                    matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}'                                                                                                        fold contains=@texFoldGroup,@Spell
273  syn region texAbstract                 matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}'                                                                                 fold contains=@texFoldGroup,@Spell
274 else
275  syn region texDocZone                  matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}'                                                                                 contains=@texFoldGroup,@texDocGroup,@Spell
276  syn region texPartZone                 matchgroup=texSection start='\\part\>'                   end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)'                                                              contains=@texFoldGroup,@texPartGroup,@Spell
277  syn region texChapterZone              matchgroup=texSection start='\\chapter\>'                end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)'                                                   contains=@texFoldGroup,@texChapterGroup,@Spell
278  syn region texSectionZone              matchgroup=texSection start='\\section\>'                end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                                        contains=@texFoldGroup,@texSectionGroup,@Spell
279  syn region texSubSectionZone           matchgroup=texSection start='\\subsection\>'             end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                              contains=@texFoldGroup,@texSubSectionGroup,@Spell
280  syn region texSubSubSectionZone        matchgroup=texSection start='\\subsubsection\>'          end='\ze\s*\\\%(\%(sub\)\{,2}section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                           contains=@texFoldGroup,@texSubSubSectionGroup,@Spell
281  syn region texParaZone                 matchgroup=texSection start='\\paragraph\>'              end='\ze\s*\\\%(paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'                  contains=@texFoldGroup,@texParaGroup,@Spell
282  syn region texSubParaZone              matchgroup=texSection start='\\subparagraph\>'           end='\ze\s*\\\%(\%(sub\)\=paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)'        contains=@texFoldGroup,@Spell
283  syn region texTitle                    matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}'                                                                                                        contains=@texFoldGroup,@Spell
284  syn region texAbstract                 matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}'                                                                                 contains=@texFoldGroup,@Spell
285 endif
287 " Bad Math (mismatched): {{{1
288 if !exists("tex_no_math")
289  syn match texBadMath           "\\end\s*{\s*\(array\|gathered\|bBpvV]matrix\|split\|subequations\|smallmatrix\|xxalignat\)\s*}"
290  syn match texBadMath           "\\end\s*{\s*\(align\|alignat\|displaymath\|displaymath\|eqnarray\|equation\|flalign\|gather\|math\|multline\|xalignat\)\*\=\s*}"
291  syn match texBadMath           "\\[\])]"
292 endif
294 " Math Zones: {{{1
295 if !exists("tex_no_math")
296  " TexNewMathZone: function creates a mathzone with the given suffix and mathzone name. {{{2
297  "                 Starred forms are created if starform is true.  Starred
298  "                 forms have syntax group and synchronization groups with a
299  "                 "S" appended.  Handles: cluster, syntax, sync, and HiLink.
300  fun! TexNewMathZone(sfx,mathzone,starform)
301    let grpname  = "texMathZone".a:sfx
302    let syncname = "texSyncMathZone".a:sfx
303    if g:tex_fold_enabled
304     let foldcmd= " fold"
305    else
306     let foldcmd= ""
307    endif
308    exe "syn cluster texMathZones add=".grpname
309    exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\s*}'."'".' keepend contains=@texMathZoneGroup'.foldcmd
310    exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
311    exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
312    exe 'HiLink '.grpname.' texMath'
313    if a:starform
314     let grpname  = "texMathZone".a:sfx.'S'
315     let syncname = "texSyncMathZone".a:sfx.'S'
316     exe "syn cluster texMathZones add=".grpname
317     exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\*\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\*\s*}'."'".' keepend contains=@texMathZoneGroup'.foldcmd
318     exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
319     exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
320     exe 'HiLink '.grpname.' texMath'
321    endif
322  endfun
324  " Standard Math Zones: {{{2
325  call TexNewMathZone("A","align",1)
326  call TexNewMathZone("B","alignat",1)
327  call TexNewMathZone("C","displaymath",1)
328  call TexNewMathZone("D","eqnarray",1)
329  call TexNewMathZone("E","equation",1)
330  call TexNewMathZone("F","flalign",1)
331  call TexNewMathZone("G","gather",1)
332  call TexNewMathZone("H","math",1)
333  call TexNewMathZone("I","multline",1)
334  call TexNewMathZone("J","subequations",0)
335  call TexNewMathZone("K","xalignat",1)
336  call TexNewMathZone("L","xxalignat",0)
338  " Inline Math Zones: {{{2
339  syn region texMathZoneV        matchgroup=Delimiter start="\\("        matchgroup=Delimiter end="\\)\|%stopzone\>"     keepend contains=@texMathZoneGroup
340  syn region texMathZoneW        matchgroup=Delimiter start="\\\["       matchgroup=Delimiter end="\\]\|%stopzone\>"     keepend contains=@texMathZoneGroup
341  syn region texMathZoneX        matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>"       contains=@texMathZoneGroup
342  syn region texMathZoneY        matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" end="%stopzone\>"     keepend         contains=@texMathZoneGroup
343  syn region texMathZoneZ        matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" end="%stopzone\>"      contains=@texMathZoneGroup
345  syn match texMathOper          "[_^=]" contained
347  " \left..something.. and \right..something.. support: {{{2
348  syn match   texMathDelimBad    contained               "\S"
349  syn match   texMathDelim       contained               "\\\(left\|right\|[bB]igg\=[lr]\)\>"    skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad
350  syn match   texMathDelim       contained               "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\=vert\>"
351  syn match   texMathDelim       contained               "\\lefteqn\>"
352  syn match   texMathDelimSet2   contained       "\\"            nextgroup=texMathDelimKey,texMathDelimBad
353  syn match   texMathDelimSet1   contained       "[<>()[\]|/.]\|\\[{}|]"
354  syn keyword texMathDelimKey    contained       backslash       lceil           lVert           rgroup          uparrow
355  syn keyword texMathDelimKey    contained       downarrow       lfloor          rangle          rmoustache      Uparrow
356  syn keyword texMathDelimKey    contained       Downarrow       lgroup          rbrace          rvert           updownarrow
357  syn keyword texMathDelimKey    contained       langle          lmoustache      rceil           rVert           Updownarrow
358  syn keyword texMathDelimKey    contained       lbrace          lvert           rfloor
359 endif
361 " Special TeX characters  ( \$ \& \% \# \{ \} \_ \S \P ) : {{{1
362 syn match texSpecialChar        "\\[$&%#{}_]"
363 if b:tex_stylish
364   syn match texSpecialChar      "\\[SP@][^a-zA-Z@]"me=e-1
365 else
366   syn match texSpecialChar      "\\[SP@]\A"me=e-1
367 endif
368 syn match texSpecialChar        "\\\\"
369 if !exists("tex_no_math")
370  syn match texOnlyMath          "[_^]"
371 endif
372 syn match texSpecialChar        "\^\^[0-9a-f]\{2}\|\^\^\S"
374 " Comments: {{{1
375 "    Normal TeX LaTeX     :   %....
376 "    Documented TeX Format:  ^^A...     -and-   leading %s (only)
377 if !exists("g:tex_comment_nospell") || !g:tex_comment_nospell
378  syn cluster texCommentGroup    contains=texTodo,@Spell
379 else
380  syn cluster texCommentGroup    contains=texTodo,@NoSpell
381 endif
382 syn case ignore
383 syn keyword texTodo             contained               combak  fixme   todo    xxx
384 syn case match
385 if b:extfname == "dtx"
386   syn match texComment          "\^\^A.*$"      contains=@texCommentGroup
387   syn match texComment          "^%\+"          contains=@texCommentGroup
388 else
389   if g:tex_fold_enabled
390    " allows syntax-folding of 2 or more contiguous comment lines
391    " single-line comments are not folded
392    syn match  texComment        "%.*$"          contains=@texCommentGroup
393    syn region texComment        start="^\zs\s*%.*\_s*%" skip="^\s*%"    end='^\ze\s*[^%]' fold
394   else
395    syn match texComment         "%.*$"          contains=@texCommentGroup
396   endif
397 endif
399 " Separate lines used for verb` and verb# so that the end conditions {{{1
400 " will appropriately terminate.  Ideally vim would let me save a
401 " character from the start pattern and re-use it in the end-pattern.
402 syn region texZone              start="\\begin{verbatim}"               end="\\end{verbatim}\|%stopzone\>"      contains=@Spell
403 " listings package:
404 syn region texZone              start="\\begin{lstlisting}"             end="\\end{lstlisting}\|%stopzone\>"    contains=@Spell
405 " moreverb package:
406 syn region texZone              start="\\begin{verbatimtab}"            end="\\end{verbatimtab}\|%stopzone\>"   contains=@Spell
407 syn region texZone              start="\\begin{verbatimwrite}"          end="\\end{verbatimwrite}\|%stopzone\>" contains=@Spell
408 syn region texZone              start="\\begin{boxedverbatim}"          end="\\end{boxedverbatim}\|%stopzone\>" contains=@Spell
409 if version < 600
410  syn region texZone             start="\\verb\*\=`"                     end="`\|%stopzone\>"
411  syn region texZone             start="\\verb\*\=#"                     end="#\|%stopzone\>"
412 else
413   if b:tex_stylish
414     syn region texZone          start="\\verb\*\=\z([^\ta-zA-Z@]\)"     end="\z1\|%stopzone\>"
415   else
416     syn region texZone          start="\\verb\*\=\z([^\ta-zA-Z]\)"      end="\z1\|%stopzone\>"
417   endif
418 endif
420 " Tex Reference Zones: {{{1
421 syn region texZone              matchgroup=texStatement start="@samp{"                  end="}\|%stopzone\>"    contains=@texRefGroup
422 syn region texRefZone           matchgroup=texStatement start="\\nocite{"               end="}\|%stopzone\>"    contains=@texRefGroup
423 syn region texRefZone           matchgroup=texStatement start="\\bibliography{"         end="}\|%stopzone\>"    contains=@texRefGroup
424 syn region texRefZone           matchgroup=texStatement start="\\label{"                end="}\|%stopzone\>"    contains=@texRefGroup
425 syn region texRefZone           matchgroup=texStatement start="\\\(page\|eq\)ref{"      end="}\|%stopzone\>"    contains=@texRefGroup
426 syn region texRefZone           matchgroup=texStatement start="\\v\=ref{"               end="}\|%stopzone\>"    contains=@texRefGroup
427 syn match  texRefZone           '\\cite\%([tp]\*\=\)\=' nextgroup=texRefOption,texCite
428 syn region texRefOption contained       matchgroup=Delimiter start='\[' end=']'         contains=@texRefGroup   nextgroup=texRefOption,texCite
429 syn region texCite      contained       matchgroup=Delimiter start='{' end='}'          contains=@texRefGroup
431 " Handle newcommand, newenvironment : {{{1
432 syn match  texNewCmd                            "\\newcommand\>"                        nextgroup=texCmdName skipwhite skipnl
433 syn region texCmdName contained matchgroup=Delimiter start="{"rs=s+1  end="}"           nextgroup=texCmdArgs,texCmdBody skipwhite skipnl
434 syn region texCmdArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]"           nextgroup=texCmdBody skipwhite skipnl
435 syn region texCmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]"        matchgroup=Delimiter end="}" contains=@texCmdGroup
436 syn match  texNewEnv                            "\\newenvironment\>"                    nextgroup=texEnvName skipwhite skipnl
437 syn region texEnvName contained matchgroup=Delimiter start="{"rs=s+1  end="}"           nextgroup=texEnvBgn skipwhite skipnl
438 syn region texEnvBgn  contained matchgroup=Delimiter start="{"rs=s+1  end="}"           nextgroup=texEnvEnd skipwhite skipnl contains=@texEnvGroup
439 syn region texEnvEnd  contained matchgroup=Delimiter start="{"rs=s+1  end="}"           skipwhite skipnl contains=@texEnvGroup
441 " Definitions/Commands: {{{1
442 syn match texDefCmd                             "\\def\>"                               nextgroup=texDefName skipwhite skipnl
443 if b:tex_stylish
444   syn match texDefName contained                "\\[a-zA-Z@]\+"                         nextgroup=texDefParms,texCmdBody skipwhite skipnl
445   syn match texDefName contained                "\\[^a-zA-Z@]"                          nextgroup=texDefParms,texCmdBody skipwhite skipnl
446 else
447   syn match texDefName contained                "\\\a\+"                                nextgroup=texDefParms,texCmdBody skipwhite skipnl
448   syn match texDefName contained                "\\\A"                                  nextgroup=texDefParms,texCmdBody skipwhite skipnl
449 endif
450 syn match texDefParms  contained                "#[^{]*"        contains=texDefParm     nextgroup=texCmdBody skipwhite skipnl
451 syn match  texDefParm  contained                "#\d\+"
453 " TeX Lengths: {{{1
454 syn match  texLength            "\<\d\+\([.,]\d\+\)\=\s*\(true\)\=\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>"
456 " TeX String Delimiters: {{{1
457 syn match texString             "\(``\|''\|,,\)"
459 " LaTeX synchronization: {{{1
460 syn sync maxlines=200
461 syn sync minlines=50
463 syn  sync match texSyncStop                     groupthere NONE         "%stopzone\>"
465 " Synchronization: {{{1
466 " The $..$ and $$..$$ make for impossible sync patterns
467 " (one can't tell if a "$$" starts or stops a math zone by itself)
468 " The following grouptheres coupled with minlines above
469 " help improve the odds of good syncing.
470 if !exists("tex_no_math")
471  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{abstract}"
472  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{center}"
473  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{description}"
474  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{enumerate}"
475  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{itemize}"
476  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{table}"
477  syn sync match texSyncMathZoneA                groupthere NONE         "\\end{tabular}"
478  syn sync match texSyncMathZoneA                groupthere NONE         "\\\(sub\)*section\>"
479 endif
481 " Highlighting: {{{1
482 if did_tex_syntax_inits == 1
483  let did_tex_syntax_inits= 2
484   " TeX highlighting groups which should share similar highlighting
485   if !exists("g:tex_no_error")
486    if !exists("tex_no_math")
487     HiLink texBadMath           texError
488     HiLink texMathDelimBad      texError
489     HiLink texMathError         texError
490     if !b:tex_stylish
491       HiLink texOnlyMath        texError
492     endif
493    endif
494    HiLink texError              Error
495   endif
497   HiLink texCite                texRefZone
498   HiLink texDefCmd              texDef
499   HiLink texDefName             texDef
500   HiLink texDocType             texCmdName
501   HiLink texDocTypeArgs         texCmdArgs
502   HiLink texInputFileOpt        texCmdArgs
503   HiLink texInputCurlies        texDelimiter
504   HiLink texLigature            texSpecialChar
505   if !exists("tex_no_math")
506    HiLink texMathDelimSet1      texMathDelim
507    HiLink texMathDelimSet2      texMathDelim
508    HiLink texMathDelimKey       texMathDelim
509    HiLink texMathMatcher        texMath
510    HiLink texMathZoneW          texMath
511    HiLink texMathZoneX          texMath
512    HiLink texMathZoneY          texMath
513    HiLink texMathZoneV          texMath
514    HiLink texMathZoneZ          texMath
515   endif
516   HiLink texSectionMarker       texCmdName
517   HiLink texSectionName         texSection
518   HiLink texSpaceCode           texStatement
519   HiLink texTypeSize            texType
520   HiLink texTypeStyle           texType
522    " Basic TeX highlighting groups
523   HiLink texCmdArgs             Number
524   HiLink texCmdName             Statement
525   HiLink texComment             Comment
526   HiLink texDef                 Statement
527   HiLink texDefParm             Special
528   HiLink texDelimiter           Delimiter
529   HiLink texInput               Special
530   HiLink texInputFile           Special
531   HiLink texLength              Number
532   HiLink texMath                Special
533   HiLink texMathDelim           Statement
534   HiLink texMathOper            Operator
535   HiLink texNewCmd              Statement
536   HiLink texNewEnv              Statement
537   HiLink texOption              Number
538   HiLink texRefZone             Special
539   HiLink texSection             PreCondit
540   HiLink texSpaceCodeChar       Special
541   HiLink texSpecialChar         SpecialChar
542   HiLink texStatement           Statement
543   HiLink texString              String
544   HiLink texTodo                Todo
545   HiLink texType                Type
546   HiLink texZone                PreCondit
548   delcommand HiLink
549 endif
551 " Current Syntax: {{{1
552 unlet b:extfname
553 let   b:current_syntax = "tex"
554 " vim: ts=8 fdm=marker