1" Vim syntax file 2" Language: TeX 3" Maintainer: Dr. Charles E. Campbell, Jr. <[email protected]> 4" Last Change: Jun 24, 2010 5" Version: 48 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 35if version < 600 36 syntax clear 37elseif exists("b:current_syntax") 38 finish 39endif 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 44if 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 51endif 52if exists("g:tex_tex") && !exists("g:tex_no_error") 53 let g:tex_no_error= 1 54endif 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 61let b:extfname=expand("%:e") 62if exists("g:tex_stylish") 63 let b:tex_stylish= g:tex_stylish 64elseif !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 70endif 71 72" handle folding {{{1 73if !exists("g:tex_fold_enabled") 74 let g:tex_fold_enabled= 0 75elseif 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" 78endif 79if g:tex_fold_enabled && &fdm == "manual" 80 setl fdm=syntax 81endif 82 83" (La)TeX keywords: only use the letters a-zA-Z {{{1 84" but _ is the only one that causes problems. 85if version < 600 86 set isk-=_ 87 if b:tex_stylish 88 set isk+=@ 89 endif 90else 91 setlocal isk-=_ 92 if b:tex_stylish 93 setlocal isk+=@ 94 endif 95endif 96 97" Clusters: {{{1 98" -------- 99syn cluster texCmdGroup contains=texCmdBody,texComment,texDefParm,texDelimiter,texDocType,texInput,texLength,texLigature,texMathDelim,texMathOper,texNewCmd,texNewEnv,texRefZone,texSection,texSectionMarker,texSectionName,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle 100if !exists("g:tex_no_error") 101 syn cluster texCmdGroup add=texMathError 102endif 103syn cluster texEnvGroup contains=texMatcher,texMathDelim,texSpecialChar,texStatement 104syn 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 105syn 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 106syn 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 107syn cluster texRefGroup contains=texMatcher,texComment,texDelimiter 108if !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 if has("conceal") && &enc == 'utf-8' 129 syn cluster texMathZoneGroup add=texGreek,texSuperscript,texSubscript 130 syn cluster texMathMatchGroup add=texGreek,texSuperscript,texSubscript 131 endif 132endif 133 134" Try to flag {} and () mismatches: {{{1 135if !exists("g:tex_no_error") 136 syn region texMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=@texMatchGroup,texError 137 syn region texMatcher matchgroup=Delimiter start="\[" end="]" contains=@texMatchGroup,texError 138else 139 syn region texMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=@texMatchGroup 140 syn region texMatcher matchgroup=Delimiter start="\[" end="]" contains=@texMatchGroup 141endif 142syn region texParen start="(" end=")" contains=@texMatchGroup,@Spell 143if !exists("g:tex_no_error") 144 syn match texError "[}\])]" 145endif 146if !exists("tex_no_math") 147 if !exists("g:tex_no_error") 148 syn match texMathError "}" contained 149 endif 150 syn region texMathMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}" end="%stopzone\>" contained contains=@texMathMatchGroup 151endif 152 153" TeX/LaTeX keywords: {{{1 154" Instead of trying to be All Knowing, I just match \..alphameric.. 155" Note that *.tex files may not have "@" in their \commands 156if exists("g:tex_tex") || b:tex_stylish 157 syn match texStatement "\\[a-zA-Z@]\+" 158else 159 syn match texStatement "\\\a\+" 160 if !exists("g:tex_no_error") 161 syn match texError "\\\a*@[a-zA-Z@]*" 162 endif 163endif 164 165" TeX/LaTeX delimiters: {{{1 166syn match texDelimiter "&" 167syn match texDelimiter "\\\\" 168 169" Tex/Latex Options: {{{1 170syn match texOption "[^\\]\zs#\d\+\|^#\d\+" 171 172" texAccent (tnx to Karim Belabas) avoids annoying highlighting for accents: {{{1 173if b:tex_stylish 174 syn match texAccent "\\[bcdvuH][^a-zA-Z@]"me=e-1 175 syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)[^a-zA-Z@]"me=e-1 176else 177 syn match texAccent "\\[bcdvuH]\A"me=e-1 178 syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)\A"me=e-1 179endif 180syn match texAccent "\\[bcdvuH]$" 181syn match texAccent +\\[=^.\~"`']+ 182syn match texAccent +\\['=t'.c^ud"vb~Hr]{\a}+ 183syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)$" 184 185" \begin{}/\end{} section markers: {{{1 186syn match texSectionMarker "\\begin\>\|\\end\>" nextgroup=texSectionName 187syn region texSectionName matchgroup=Delimiter start="{" end="}" contained nextgroup=texSectionModifier contains=texComment 188syn region texSectionModifier matchgroup=Delimiter start="\[" end="]" contained contains=texComment 189 190" \documentclass, \documentstyle, \usepackage: {{{1 191syn match texDocType "\\documentclass\>\|\\documentstyle\>\|\\usepackage\>" nextgroup=texSectionName,texDocTypeArgs 192syn region texDocTypeArgs matchgroup=Delimiter start="\[" end="]" contained nextgroup=texSectionName contains=texComment 193 194" Preamble syntax-based folding support: {{{1 195if g:tex_fold_enabled && has("folding") 196 syn region texPreamble transparent fold start='\zs\\documentclass\>' end='\ze\\begin{document}' contains=texStyle,@texMatchGroup 197endif 198 199" TeX input: {{{1 200syn match texInput "\\input\s\+[a-zA-Z/.0-9_^]\+"hs=s+7 contains=texStatement 201syn match texInputFile "\\include\(graphics\|list\)\=\(\[.\{-}\]\)\=\s*{.\{-}}" contains=texStatement,texInputCurlies,texInputFileOpt 202syn match texInputFile "\\\(epsfig\|input\|usepackage\)\s*\(\[.*\]\)\={.\{-}}" contains=texStatement,texInputCurlies,texInputFileOpt 203syn match texInputCurlies "[{}]" contained 204syn region texInputFileOpt matchgroup=Delimiter start="\[" end="\]" contained contains=texComment 205 206" Type Styles (LaTeX 2.09): {{{1 207syn match texTypeStyle "\\rm\>" 208syn match texTypeStyle "\\em\>" 209syn match texTypeStyle "\\bf\>" 210syn match texTypeStyle "\\it\>" 211syn match texTypeStyle "\\sl\>" 212syn match texTypeStyle "\\sf\>" 213syn match texTypeStyle "\\sc\>" 214syn match texTypeStyle "\\tt\>" 215 216" Type Styles: attributes, commands, families, etc (LaTeX2E): {{{1 217syn match texTypeStyle "\\textbf\>" 218syn match texTypeStyle "\\textit\>" 219syn match texTypeStyle "\\textmd\>" 220syn match texTypeStyle "\\textrm\>" 221syn match texTypeStyle "\\textsc\>" 222syn match texTypeStyle "\\textsf\>" 223syn match texTypeStyle "\\textsl\>" 224syn match texTypeStyle "\\texttt\>" 225syn match texTypeStyle "\\textup\>" 226syn match texTypeStyle "\\emph\>" 227 228syn match texTypeStyle "\\mathbb\>" 229syn match texTypeStyle "\\mathbf\>" 230syn match texTypeStyle "\\mathcal\>" 231syn match texTypeStyle "\\mathfrak\>" 232syn match texTypeStyle "\\mathit\>" 233syn match texTypeStyle "\\mathnormal\>" 234syn match texTypeStyle "\\mathrm\>" 235syn match texTypeStyle "\\mathsf\>" 236syn match texTypeStyle "\\mathtt\>" 237 238syn match texTypeStyle "\\rmfamily\>" 239syn match texTypeStyle "\\sffamily\>" 240syn match texTypeStyle "\\ttfamily\>" 241 242syn match texTypeStyle "\\itshape\>" 243syn match texTypeStyle "\\scshape\>" 244syn match texTypeStyle "\\slshape\>" 245syn match texTypeStyle "\\upshape\>" 246 247syn match texTypeStyle "\\bfseries\>" 248syn match texTypeStyle "\\mdseries\>" 249 250" Some type sizes: {{{1 251syn match texTypeSize "\\tiny\>" 252syn match texTypeSize "\\scriptsize\>" 253syn match texTypeSize "\\footnotesize\>" 254syn match texTypeSize "\\small\>" 255syn match texTypeSize "\\normalsize\>" 256syn match texTypeSize "\\large\>" 257syn match texTypeSize "\\Large\>" 258syn match texTypeSize "\\LARGE\>" 259syn match texTypeSize "\\huge\>" 260syn match texTypeSize "\\Huge\>" 261 262" Spacecodes (TeX'isms): {{{1 263" \mathcode`\^^@="2201 \delcode`\(="028300 \sfcode`\)=0 \uccode`X=`X \lccode`x=`x 264syn match texSpaceCode "\\\(math\|cat\|del\|lc\|sf\|uc\)code`"me=e-1 nextgroup=texSpaceCodeChar 265syn match texSpaceCodeChar "`\\\=.\(\^.\)\==\(\d\|\"\x\{1,6}\|`.\)" contained 266 267" Sections, subsections, etc: {{{1 268if g:tex_fold_enabled && has("folding") 269 syn region texDocZone matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}' fold contains=@texFoldGroup,@texDocGroup,@Spell 270 syn region texPartZone matchgroup=texSection start='\\part\>' end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)' fold contains=@texFoldGroup,@texPartGroup,@Spell 271 syn region texChapterZone matchgroup=texSection start='\\chapter\>' end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)' fold contains=@texFoldGroup,@texChapterGroup,@Spell 272 syn region texSectionZone matchgroup=texSection start='\\section\>' end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' fold contains=@texFoldGroup,@texSectionGroup,@Spell 273 syn region texSubSectionZone matchgroup=texSection start='\\subsection\>' end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' fold contains=@texFoldGroup,@texSubSectionGroup,@Spell 274 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 275 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 276 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 277 syn region texTitle matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}' fold contains=@texFoldGroup,@Spell 278 syn region texAbstract matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}' fold contains=@texFoldGroup,@Spell 279else 280 syn region texDocZone matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}' contains=@texFoldGroup,@texDocGroup,@Spell 281 syn region texPartZone matchgroup=texSection start='\\part\>' end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texPartGroup,@Spell 282 syn region texChapterZone matchgroup=texSection start='\\chapter\>' end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texChapterGroup,@Spell 283 syn region texSectionZone matchgroup=texSection start='\\section\>' end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSectionGroup,@Spell 284 syn region texSubSectionZone matchgroup=texSection start='\\subsection\>' end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSubSectionGroup,@Spell 285 syn region texSubSubSectionZone matchgroup=texSection start='\\subsubsection\>' end='\ze\s*\\\%(\%(sub\)\{,2}section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSubSubSectionGroup,@Spell 286 syn region texParaZone matchgroup=texSection start='\\paragraph\>' end='\ze\s*\\\%(paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texParaGroup,@Spell 287 syn region texSubParaZone matchgroup=texSection start='\\subparagraph\>' end='\ze\s*\\\%(\%(sub\)\=paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@Spell 288 syn region texTitle matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}' contains=@texFoldGroup,@Spell 289 syn region texAbstract matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}' contains=@texFoldGroup,@Spell 290endif 291 292" Bad Math (mismatched): {{{1 293if !exists("tex_no_math") 294 syn match texBadMath "\\end\s*{\s*\(array\|gathered\|bBpvV]matrix\|split\|subequations\|smallmatrix\|xxalignat\)\s*}" 295 syn match texBadMath "\\end\s*{\s*\(align\|alignat\|displaymath\|displaymath\|eqnarray\|equation\|flalign\|gather\|math\|multline\|xalignat\)\*\=\s*}" 296 syn match texBadMath "\\[\])]" 297endif 298 299" Math Zones: {{{1 300if !exists("tex_no_math") 301 " TexNewMathZone: function creates a mathzone with the given suffix and mathzone name. {{{2 302 " Starred forms are created if starform is true. Starred 303 " forms have syntax group and synchronization groups with a 304 " "S" appended. Handles: cluster, syntax, sync, and HiLink. 305 fun! TexNewMathZone(sfx,mathzone,starform) 306 let grpname = "texMathZone".a:sfx 307 let syncname = "texSyncMathZone".a:sfx 308 if g:tex_fold_enabled 309 let foldcmd= " fold" 310 else 311 let foldcmd= "" 312 endif 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'.foldcmd 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 'hi def link '.grpname.' texMath' 318 if a:starform 319 let grpname = "texMathZone".a:sfx.'S' 320 let syncname = "texSyncMathZone".a:sfx.'S' 321 exe "syn cluster texMathZones add=".grpname 322 exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\*\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\*\s*}'."'".' keepend contains=@texMathZoneGroup'.foldcmd 323 exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"' 324 exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"' 325 exe 'hi def link '.grpname.' texMath' 326 endif 327 endfun 328 329 " Standard Math Zones: {{{2 330 call TexNewMathZone("A","align",1) 331 call TexNewMathZone("B","alignat",1) 332 call TexNewMathZone("C","displaymath",1) 333 call TexNewMathZone("D","eqnarray",1) 334 call TexNewMathZone("E","equation",1) 335 call TexNewMathZone("F","flalign",1) 336 call TexNewMathZone("G","gather",1) 337 call TexNewMathZone("H","math",1) 338 call TexNewMathZone("I","multline",1) 339 call TexNewMathZone("J","subequations",0) 340 call TexNewMathZone("K","xalignat",1) 341 call TexNewMathZone("L","xxalignat",0) 342 343 " Inline Math Zones: {{{2 344 syn region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)\|%stopzone\>" keepend contains=@texMathZoneGroup 345 syn region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]\|%stopzone\>" keepend contains=@texMathZoneGroup 346 syn region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>" contains=@texMathZoneGroup 347 syn region texMathZoneY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" end="%stopzone\>" keepend contains=@texMathZoneGroup 348 syn region texMathZoneZ matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" end="%stopzone\>" contains=@texMathZoneGroup 349 350 syn match texMathOper "[_^=]" contained 351 352 " \left..something.. and \right..something.. support: {{{2 353 syn match texMathDelimBad contained "\S" 354 syn match texMathDelim contained "\\\(left\|right\|[bB]igg\=[lr]\)\>" skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad 355 syn match texMathDelim contained "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\=vert\>" 356 syn match texMathDelim contained "\\lefteqn\>" 357 syn match texMathDelimSet2 contained "\\" nextgroup=texMathDelimKey,texMathDelimBad 358 syn match texMathDelimSet1 contained "[<>()[\]|/.]\|\\[{}|]" 359 syn keyword texMathDelimKey contained backslash lceil lVert rgroup uparrow 360 syn keyword texMathDelimKey contained downarrow lfloor rangle rmoustache Uparrow 361 syn keyword texMathDelimKey contained Downarrow lgroup rbrace rvert updownarrow 362 syn keyword texMathDelimKey contained langle lmoustache rceil rVert Updownarrow 363 syn keyword texMathDelimKey contained lbrace lvert rfloor 364endif 365 366" Special TeX characters ( \$ \& \% \# \{ \} \_ \S \P ) : {{{1 367syn match texSpecialChar "\\[$&%#{}_]" 368if b:tex_stylish 369 syn match texSpecialChar "\\[SP@][^a-zA-Z@]"me=e-1 370else 371 syn match texSpecialChar "\\[SP@]\A"me=e-1 372endif 373syn match texSpecialChar "\\\\" 374if !exists("tex_no_math") 375 syn match texOnlyMath "[_^]" 376endif 377syn match texSpecialChar "\^\^[0-9a-f]\{2}\|\^\^\S" 378 379" Comments: {{{1 380" Normal TeX LaTeX : %.... 381" Documented TeX Format: ^^A... -and- leading %s (only) 382if !exists("g:tex_comment_nospell") || !g:tex_comment_nospell 383 syn cluster texCommentGroup contains=texTodo,@Spell 384else 385 syn cluster texCommentGroup contains=texTodo,@NoSpell 386endif 387syn case ignore 388syn keyword texTodo contained combak fixme todo xxx 389syn case match 390if b:extfname == "dtx" 391 syn match texComment "\^\^A.*$" contains=@texCommentGroup 392 syn match texComment "^%\+" contains=@texCommentGroup 393else 394 if g:tex_fold_enabled 395 " allows syntax-folding of 2 or more contiguous comment lines 396 " single-line comments are not folded 397 syn match texComment "%.*$" contains=@texCommentGroup 398 syn region texComment start="^\zs\s*%.*\_s*%" skip="^\s*%" end='^\ze\s*[^%]' fold 399 else 400 syn match texComment "%.*$" contains=@texCommentGroup 401 endif 402endif 403 404" Separate lines used for verb` and verb# so that the end conditions {{{1 405" will appropriately terminate. Ideally vim would let me save a 406" character from the start pattern and re-use it in the end-pattern. 407syn region texZone start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}\|%stopzone\>" contains=@Spell 408" listings package: 409syn region texZone start="\\begin{lstlisting}" end="\\end{lstlisting}\|%stopzone\>" contains=@Spell 410" moreverb package: 411syn region texZone start="\\begin{verbatimtab}" end="\\end{verbatimtab}\|%stopzone\>" contains=@Spell 412syn region texZone start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}\|%stopzone\>" contains=@Spell 413syn region texZone start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}\|%stopzone\>" contains=@Spell 414if version < 600 415 syn region texZone start="\\verb\*\=`" end="`\|%stopzone\>" 416 syn region texZone start="\\verb\*\=#" end="#\|%stopzone\>" 417else 418 if b:tex_stylish 419 syn region texZone start="\\verb\*\=\z([^\ta-zA-Z@]\)" end="\z1\|%stopzone\>" 420 else 421 syn region texZone start="\\verb\*\=\z([^\ta-zA-Z]\)" end="\z1\|%stopzone\>" 422 endif 423endif 424 425" Tex Reference Zones: {{{1 426syn region texZone matchgroup=texStatement start="@samp{" end="}\|%stopzone\>" contains=@texRefGroup 427syn region texRefZone matchgroup=texStatement start="\\nocite{" end="}\|%stopzone\>" contains=@texRefGroup 428syn region texRefZone matchgroup=texStatement start="\\bibliography{" end="}\|%stopzone\>" contains=@texRefGroup 429syn region texRefZone matchgroup=texStatement start="\\label{" end="}\|%stopzone\>" contains=@texRefGroup 430syn region texRefZone matchgroup=texStatement start="\\\(page\|eq\)ref{" end="}\|%stopzone\>" contains=@texRefGroup 431syn region texRefZone matchgroup=texStatement start="\\v\=ref{" end="}\|%stopzone\>" contains=@texRefGroup 432syn match texRefZone '\\cite\%([tp]\*\=\)\=' nextgroup=texRefOption,texCite 433syn region texRefOption contained matchgroup=Delimiter start='\[' end=']' contains=@texRefGroup nextgroup=texRefOption,texCite 434syn region texCite contained matchgroup=Delimiter start='{' end='}' contains=@texRefGroup 435 436" Handle newcommand, newenvironment : {{{1 437syn match texNewCmd "\\newcommand\>" nextgroup=texCmdName skipwhite skipnl 438syn region texCmdName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texCmdArgs,texCmdBody skipwhite skipnl 439syn region texCmdArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]" nextgroup=texCmdBody skipwhite skipnl 440syn region texCmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=Delimiter end="}" contains=@texCmdGroup 441syn match texNewEnv "\\newenvironment\>" nextgroup=texEnvName skipwhite skipnl 442syn region texEnvName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvBgn skipwhite skipnl 443syn region texEnvBgn contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvEnd skipwhite skipnl contains=@texEnvGroup 444syn region texEnvEnd contained matchgroup=Delimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=@texEnvGroup 445 446" Definitions/Commands: {{{1 447syn match texDefCmd "\\def\>" nextgroup=texDefName skipwhite skipnl 448if b:tex_stylish 449 syn match texDefName contained "\\[a-zA-Z@]\+" nextgroup=texDefParms,texCmdBody skipwhite skipnl 450 syn match texDefName contained "\\[^a-zA-Z@]" nextgroup=texDefParms,texCmdBody skipwhite skipnl 451else 452 syn match texDefName contained "\\\a\+" nextgroup=texDefParms,texCmdBody skipwhite skipnl 453 syn match texDefName contained "\\\A" nextgroup=texDefParms,texCmdBody skipwhite skipnl 454endif 455syn match texDefParms contained "#[^{]*" contains=texDefParm nextgroup=texCmdBody skipwhite skipnl 456syn match texDefParm contained "#\d\+" 457 458" TeX Lengths: {{{1 459syn match texLength "\<\d\+\([.,]\d\+\)\=\s*\(true\)\=\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" 460 461" TeX String Delimiters: {{{1 462syn match texString "\(``\|''\|,,\)" 463 464" makeatletter -- makeatother sections 465if !exists("g:tex_no_error") 466 syn region texStyle matchgroup=texStatement start='\\makeatletter' end='\\makeatother' contains=@texStyleGroup contained 467 syn match texStyleStatement "\\[a-zA-Z@]\+" contained 468 syn region texStyleMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=@texStyleGroup,texError contained 469 syn region texStyleMatcher matchgroup=Delimiter start="\[" end="]" contains=@texStyleGroup,texError contained 470endif 471 472" support for 473if has("conceal") && &enc == 'utf-8' 474 syn match texGreek '\\alpha\>' contained conceal cchar=α 475 syn match texGreek '\\beta\>' contained conceal cchar=β 476 syn match texGreek '\\gamma\>' contained conceal cchar=γ 477 syn match texGreek '\\delta\>' contained conceal cchar=δ 478 syn match texGreek '\\epsilon\>' contained conceal cchar=ϵ 479 syn match texGreek '\\varepsilon\>' contained conceal cchar=ε 480 syn match texGreek '\\zeta\>' contained conceal cchar=ζ 481 syn match texGreek '\\eta\>' contained conceal cchar=η 482 syn match texGreek '\\theta\>' contained conceal cchar=θ 483 syn match texGreek '\\vartheta\>' contained conceal cchar=ϑ 484 syn match texGreek '\\kappa\>' contained conceal cchar=κ 485 syn match texGreek '\\lambda\>' contained conceal cchar=λ 486 syn match texGreek '\\mu\>' contained conceal cchar=μ 487 syn match texGreek '\\nu\>' contained conceal cchar=ν 488 syn match texGreek '\\xi\>' contained conceal cchar=ξ 489 syn match texGreek '\\pi\>' contained conceal cchar=π 490 syn match texGreek '\\varpi\>' contained conceal cchar=ϖ 491 syn match texGreek '\\rho\>' contained conceal cchar=ρ 492 syn match texGreek '\\varrho\>' contained conceal cchar=ϱ 493 syn match texGreek '\\sigma\>' contained conceal cchar=σ 494 syn match texGreek '\\varsigma\>' contained conceal cchar=ς 495 syn match texGreek '\\tau\>' contained conceal cchar=τ 496 syn match texGreek '\\upsilon\>' contained conceal cchar=υ 497 syn match texGreek '\\phi\>' contained conceal cchar=φ 498 syn match texGreek '\\varphi\>' contained conceal cchar=ϕ 499 syn match texGreek '\\chi\>' contained conceal cchar=χ 500 syn match texGreek '\\psi\>' contained conceal cchar=ψ 501 syn match texGreek '\\omega\>' contained conceal cchar=ω 502 syn match texGreek '\\Gamma\>' contained conceal cchar=Γ 503 syn match texGreek '\\Delta\>' contained conceal cchar=Δ 504 syn match texGreek '\\Theta\>' contained conceal cchar=Θ 505 syn match texGreek '\\Lambda\>' contained conceal cchar=Λ 506 syn match texGreek '\\Xi\>' contained conceal cchar=Χ 507 syn match texGreek '\\Pi\>' contained conceal cchar=Π 508 syn match texGreek '\\Sigma\>' contained conceal cchar=Σ 509 syn match texGreek '\\Upsilon\>' contained conceal cchar=Υ 510 syn match texGreek '\\Phi\>' contained conceal cchar=Φ 511 syn match texGreek '\\Psi\>' contained conceal cchar=Ψ 512 syn match texGreek '\\Omega\>' contained conceal cchar=Ω 513 syn match texSuperscript '\^0' contained conceal cchar=⁰ 514 syn match texSuperscript '\^1' contained conceal cchar=¹ 515 syn match texSuperscript '\^2' contained conceal cchar=² 516 syn match texSuperscript '\^3' contained conceal cchar=³ 517 syn match texSuperscript '\^4' contained conceal cchar=⁴ 518 syn match texSuperscript '\^5' contained conceal cchar=⁵ 519 syn match texSuperscript '\^6' contained conceal cchar=⁶ 520 syn match texSuperscript '\^7' contained conceal cchar=⁷ 521 syn match texSuperscript '\^8' contained conceal cchar=⁸ 522 syn match texSuperscript '\^9' contained conceal cchar=⁹ 523 syn match texSuperscript '\^a' contained conceal cchar=ᵃ 524 syn match texSuperscript '\^b' contained conceal cchar=ᵇ 525 syn match texSuperscript '\^c' contained conceal cchar=ᶜ 526 syn match texSuperscript '\^d' contained conceal cchar=ᵈ 527 syn match texSuperscript '\^e' contained conceal cchar=ᵉ 528 syn match texSuperscript '\^f' contained conceal cchar=ᶠ 529 syn match texSuperscript '\^g' contained conceal cchar=ᵍ 530 syn match texSuperscript '\^h' contained conceal cchar=ʰ 531 syn match texSuperscript '\^i' contained conceal cchar=ⁱ 532 syn match texSuperscript '\^j' contained conceal cchar=ʲ 533 syn match texSuperscript '\^k' contained conceal cchar=ᵏ 534 syn match texSuperscript '\^l' contained conceal cchar=ˡ 535 syn match texSuperscript '\^m' contained conceal cchar=ᵐ 536 syn match texSuperscript '\^n' contained conceal cchar=ⁿ 537 syn match texSuperscript '\^o' contained conceal cchar=ᵒ 538 syn match texSuperscript '\^p' contained conceal cchar=ᵖ 539 syn match texSuperscript '\^r' contained conceal cchar=ʳ 540 syn match texSuperscript '\^s' contained conceal cchar=ˢ 541 syn match texSuperscript '\^t' contained conceal cchar=ᵗ 542 syn match texSuperscript '\^u' contained conceal cchar=ᵘ 543 syn match texSuperscript '\^v' contained conceal cchar=ᵛ 544 syn match texSuperscript '\^w' contained conceal cchar=ʷ 545 syn match texSuperscript '\^x' contained conceal cchar=ˣ 546 syn match texSuperscript '\^y' contained conceal cchar=ʸ 547 syn match texSuperscript '\^z' contained conceal cchar=ᶻ 548 syn match texSuperscript '\^A' contained conceal cchar=ᴬ 549 syn match texSuperscript '\^B' contained conceal cchar=ᴮ 550 syn match texSuperscript '\^D' contained conceal cchar=ᴰ 551 syn match texSuperscript '\^E' contained conceal cchar=ᴱ 552 syn match texSuperscript '\^G' contained conceal cchar=ᴳ 553 syn match texSuperscript '\^H' contained conceal cchar=ᴴ 554 syn match texSuperscript '\^I' contained conceal cchar=ᴵ 555 syn match texSuperscript '\^J' contained conceal cchar=ᴶ 556 syn match texSuperscript '\^K' contained conceal cchar=ᴷ 557 syn match texSuperscript '\^L' contained conceal cchar=ᴸ 558 syn match texSuperscript '\^M' contained conceal cchar=ᴹ 559 syn match texSuperscript '\^N' contained conceal cchar=ᴺ 560 syn match texSuperscript '\^O' contained conceal cchar=ᴼ 561 syn match texSuperscript '\^P' contained conceal cchar=ᴾ 562 syn match texSuperscript '\^R' contained conceal cchar=ᴿ 563 syn match texSuperscript '\^T' contained conceal cchar=ᵀ 564 syn match texSuperscript '\^U' contained conceal cchar=ᵁ 565 syn match texSuperscript '\^W' contained conceal cchar=ᵂ 566 syn match texSubscript '_0' contained conceal cchar=₀ 567 syn match texSubscript '_1' contained conceal cchar=₁ 568 syn match texSubscript '_2' contained conceal cchar=₂ 569 syn match texSubscript '_3' contained conceal cchar=₃ 570 syn match texSubscript '_4' contained conceal cchar=₄ 571 syn match texSubscript '_5' contained conceal cchar=₅ 572 syn match texSubscript '_6' contained conceal cchar=₆ 573 syn match texSubscript '_7' contained conceal cchar=₇ 574 syn match texSubscript '_8' contained conceal cchar=₈ 575 syn match texSubscript '_9' contained conceal cchar=₉ 576 syn match texSubscript '_a' contained conceal cchar=ₐ 577 syn match texSubscript '_e' contained conceal cchar=ₑ 578 syn match texSubscript '_i' contained conceal cchar=ᵢ 579 syn match texSubscript '_o' contained conceal cchar=ₒ 580 syn match texSubscript '_u' contained conceal cchar=ᵤ 581endif 582 583" --------------------------------------------------------------------- 584" LaTeX synchronization: {{{1 585syn sync maxlines=200 586syn sync minlines=50 587 588syn sync match texSyncStop groupthere NONE "%stopzone\>" 589 590" Synchronization: {{{1 591" The $..$ and $$..$$ make for impossible sync patterns 592" (one can't tell if a "$$" starts or stops a math zone by itself) 593" The following grouptheres coupled with minlines above 594" help improve the odds of good syncing. 595if !exists("tex_no_math") 596 syn sync match texSyncMathZoneA groupthere NONE "\\end{abstract}" 597 syn sync match texSyncMathZoneA groupthere NONE "\\end{center}" 598 syn sync match texSyncMathZoneA groupthere NONE "\\end{description}" 599 syn sync match texSyncMathZoneA groupthere NONE "\\end{enumerate}" 600 syn sync match texSyncMathZoneA groupthere NONE "\\end{itemize}" 601 syn sync match texSyncMathZoneA groupthere NONE "\\end{table}" 602 syn sync match texSyncMathZoneA groupthere NONE "\\end{tabular}" 603 syn sync match texSyncMathZoneA groupthere NONE "\\\(sub\)*section\>" 604endif 605 606" --------------------------------------------------------------------- 607" Highlighting: {{{1 608if did_tex_syntax_inits == 1 609 let did_tex_syntax_inits= 2 610 " TeX highlighting groups which should share similar highlighting 611 if !exists("g:tex_no_error") 612 if !exists("tex_no_math") 613 HiLink texBadMath texError 614 HiLink texMathDelimBad texError 615 HiLink texMathError texError 616 if !b:tex_stylish 617 HiLink texOnlyMath texError 618 endif 619 endif 620 HiLink texError Error 621 endif 622 623 HiLink texCite texRefZone 624 HiLink texDefCmd texDef 625 HiLink texDefName texDef 626 HiLink texDocType texCmdName 627 HiLink texDocTypeArgs texCmdArgs 628 HiLink texInputFileOpt texCmdArgs 629 HiLink texInputCurlies texDelimiter 630 HiLink texLigature texSpecialChar 631 if !exists("tex_no_math") 632 HiLink texMathDelimSet1 texMathDelim 633 HiLink texMathDelimSet2 texMathDelim 634 HiLink texMathDelimKey texMathDelim 635 HiLink texMathMatcher texMath 636 HiLink texMathZoneV texMath 637 HiLink texMathZoneW texMath 638 HiLink texMathZoneX texMath 639 HiLink texMathZoneY texMath 640 HiLink texMathZoneV texMath 641 HiLink texMathZoneZ texMath 642 endif 643 HiLink texSectionMarker texCmdName 644 HiLink texSectionName texSection 645 HiLink texSpaceCode texStatement 646 HiLink texStyleStatement texStatement 647 HiLink texTypeSize texType 648 HiLink texTypeStyle texType 649 650 " Basic TeX highlighting groups 651 HiLink texCmdArgs Number 652 HiLink texCmdName Statement 653 HiLink texComment Comment 654 HiLink texDef Statement 655 HiLink texDefParm Special 656 HiLink texDelimiter Delimiter 657 HiLink texInput Special 658 HiLink texInputFile Special 659 HiLink texLength Number 660 HiLink texMath Special 661 HiLink texMathDelim Statement 662 HiLink texMathOper Operator 663 HiLink texNewCmd Statement 664 HiLink texNewEnv Statement 665 HiLink texOption Number 666 HiLink texRefZone Special 667 HiLink texSection PreCondit 668 HiLink texSpaceCodeChar Special 669 HiLink texSpecialChar SpecialChar 670 HiLink texStatement Statement 671 HiLink texString String 672 HiLink texTodo Todo 673 HiLink texType Type 674 HiLink texZone PreCondit 675 676 delcommand HiLink 677endif 678 679" Current Syntax: {{{1 680unlet b:extfname 681let b:current_syntax = "tex" 682" vim: ts=8 fdm=marker 683