]> git.madduck.net Git - etc/vim.git/blob - .vim/syntax/tex.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

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