Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: TeX |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 3 | " Maintainer: Dr. Charles E. Campbell, Jr. <NdrchipO@ScampbellPfamily.AbizM> |
Bram Moolenaar | cc016f5 | 2005-12-10 20:23:46 +0000 | [diff] [blame] | 4 | " Last Change: Dec 07, 2005 |
| 5 | " Version: 31 |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 6 | " URL: http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | f1f8bc5 | 2005-03-07 23:20:08 +0000 | [diff] [blame] | 56 | " Determine whether or not to use "*.sty" mode {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | f1f8bc5 | 2005-03-07 23:20:08 +0000 | [diff] [blame] | 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") |
Bram Moolenaar | ab19481 | 2005-09-14 21:40:12 +0000 | [diff] [blame] | 76 | let g:tex_fold_enabled= 0 |
Bram Moolenaar | f1f8bc5 | 2005-03-07 23:20:08 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
| 100 | if !exists("g:tex_no_error") |
| 101 | syn cluster texCmdGroup add=texMathError |
| 102 | endif |
| 103 | syn cluster texEnvGroup contains=texMatcher,texMathDelim,texSpecialChar,texStatement |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 106 | syn cluster texRefGroup contains=texMatcher,texComment,texDelimiter |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 127 | endif |
| 128 | |
| 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 |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 137 | syn region texParen start="(" end=")" contains=@texMatchGroup,@Spell |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
| 147 | |
| 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 |
| 159 | |
| 160 | " TeX/LaTeX delimiters: {{{1 |
| 161 | syn match texDelimiter "&" |
| 162 | syn match texDelimiter "\\\\" |
| 163 | |
| 164 | " Tex/Latex Options: {{{1 |
| 165 | syn match texOption "[^\\]\zs#\d\+\|^#\d\+" |
| 166 | |
| 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\)$" |
| 179 | |
| 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 |
| 184 | |
| 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 |
| 188 | |
| 189 | " TeX input: {{{1 |
| 190 | syn match texInput "\\input\s\+[a-zA-Z/.0-9_^]\+"hs=s+7 contains=texStatement |
| 191 | syn match texInputFile "\\include\(graphics\|list\)\=\(\[.\{-}\]\)\=\s*{.\{-}}" contains=texStatement,texInputCurlies |
| 192 | syn match texInputFile "\\\(epsfig\|input\|usepackage\)\s*\(\[.*\]\)\={.\{-}}" contains=texStatement,texInputCurlies,texInputFileOpt |
| 193 | syn match texInputCurlies "[{}]" contained |
| 194 | syn region texInputFileOpt matchgroup=Delimiter start="\[" end="\]" contained |
| 195 | |
| 196 | " Type Styles (LaTeX 2.09): {{{1 |
| 197 | syn match texTypeStyle "\\rm\>" |
| 198 | syn match texTypeStyle "\\em\>" |
| 199 | syn match texTypeStyle "\\bf\>" |
| 200 | syn match texTypeStyle "\\it\>" |
| 201 | syn match texTypeStyle "\\sl\>" |
| 202 | syn match texTypeStyle "\\sf\>" |
| 203 | syn match texTypeStyle "\\sc\>" |
| 204 | syn match texTypeStyle "\\tt\>" |
| 205 | |
| 206 | " Type Styles: attributes, commands, families, etc (LaTeX2E): {{{1 |
| 207 | syn match texTypeStyle "\\textbf\>" |
| 208 | syn match texTypeStyle "\\textit\>" |
| 209 | syn match texTypeStyle "\\textmd\>" |
| 210 | syn match texTypeStyle "\\textrm\>" |
| 211 | syn match texTypeStyle "\\textsc\>" |
| 212 | syn match texTypeStyle "\\textsf\>" |
| 213 | syn match texTypeStyle "\\textsl\>" |
| 214 | syn match texTypeStyle "\\texttt\>" |
| 215 | syn match texTypeStyle "\\textup\>" |
| 216 | syn match texTypeStyle "\\emph\>" |
| 217 | |
| 218 | syn match texTypeStyle "\\mathbb\>" |
| 219 | syn match texTypeStyle "\\mathbf\>" |
| 220 | syn match texTypeStyle "\\mathcal\>" |
| 221 | syn match texTypeStyle "\\mathfrak\>" |
| 222 | syn match texTypeStyle "\\mathit\>" |
| 223 | syn match texTypeStyle "\\mathnormal\>" |
| 224 | syn match texTypeStyle "\\mathrm\>" |
| 225 | syn match texTypeStyle "\\mathsf\>" |
| 226 | syn match texTypeStyle "\\mathtt\>" |
| 227 | |
| 228 | syn match texTypeStyle "\\rmfamily\>" |
| 229 | syn match texTypeStyle "\\sffamily\>" |
| 230 | syn match texTypeStyle "\\ttfamily\>" |
| 231 | |
| 232 | syn match texTypeStyle "\\itshape\>" |
| 233 | syn match texTypeStyle "\\scshape\>" |
| 234 | syn match texTypeStyle "\\slshape\>" |
| 235 | syn match texTypeStyle "\\upshape\>" |
| 236 | |
| 237 | syn match texTypeStyle "\\bfseries\>" |
| 238 | syn match texTypeStyle "\\mdseries\>" |
| 239 | |
| 240 | " Some type sizes: {{{1 |
| 241 | syn match texTypeSize "\\tiny\>" |
| 242 | syn match texTypeSize "\\scriptsize\>" |
| 243 | syn match texTypeSize "\\footnotesize\>" |
| 244 | syn match texTypeSize "\\small\>" |
| 245 | syn match texTypeSize "\\normalsize\>" |
| 246 | syn match texTypeSize "\\large\>" |
| 247 | syn match texTypeSize "\\Large\>" |
| 248 | syn match texTypeSize "\\LARGE\>" |
| 249 | syn match texTypeSize "\\huge\>" |
| 250 | syn match texTypeSize "\\Huge\>" |
| 251 | |
| 252 | " Spacecodes (TeX'isms): {{{1 |
| 253 | " \mathcode`\^^@="2201 \delcode`\(="028300 \sfcode`\)=0 \uccode`X=`X \lccode`x=`x |
| 254 | syn match texSpaceCode "\\\(math\|cat\|del\|lc\|sf\|uc\)code`"me=e-1 nextgroup=texSpaceCodeChar |
| 255 | syn match texSpaceCodeChar "`\\\=.\(\^.\)\==\(\d\|\"\x\{1,6}\|`.\)" contained |
| 256 | |
| 257 | " Sections, subsections, etc: {{{1 |
Bram Moolenaar | f1f8bc5 | 2005-03-07 23:20:08 +0000 | [diff] [blame] | 258 | if g:tex_fold_enabled && has("folding") |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 259 | syn region texDocZone matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}' fold keepend contains=@texFoldGroup,@texDocGroup,@Spell |
| 260 | syn region texPartZone matchgroup=texSection start='\\part\>' end='\n\ze\s*\\part\>' fold keepend contains=@texFoldGroup,@texPartGroup,@Spell |
| 261 | syn region texChapterZone matchgroup=texSection start='\\chapter\>' end='\n\ze\s*\\chapter\>' fold keepend contains=@texFoldGroup,@texChapterGroup,@Spell |
| 262 | syn region texSectionZone matchgroup=texSection start='\\section\>' end='\n\ze\s*\\section\>' fold keepend contains=@texFoldGroup,@texSectionGroup,@Spell |
| 263 | syn region texSubSectionZone matchgroup=texSection start='\\subsection\>' end='\n\ze\s*\\subsection\>' fold keepend contains=@texFoldGroup,@texSubSectionGroup,@Spell |
| 264 | syn region texSubSubSectionZone matchgroup=texSection start='\\subsubsection\>' end='\n\ze\s*\\subsubsection\>' fold keepend contains=@texFoldGroup,@texSubSubSectionGroup,@Spell |
| 265 | syn region texParaZone matchgroup=texSection start='\\paragraph\>' end='\n\ze\s*\\paragraph\>' fold keepend contains=@texFoldGroup,@texParaGroup,@Spell |
| 266 | syn region texSubParaZone matchgroup=texSection start='\\subparagraph\>' end='\n\ze\s*\\subparagraph\>' fold keepend contains=@texFoldGroup,@Spell |
| 267 | syn region texTitle matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}' fold contains=@texFoldGroup,@Spell |
| 268 | syn region texAbstract matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}' fold contains=@texFoldGroup,@Spell |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 269 | else |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 270 | syn region texDocZone matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}' keepend contains=@texFoldGroup,@texDocGroup,@Spell |
| 271 | syn region texPartZone matchgroup=texSection start='\\part\>' end='\n\ze\s*\\part\>' keepend contains=@texFoldGroup,@texPartGroup,@Spell |
| 272 | syn region texChapterZone matchgroup=texSection start='\\chapter\>' end='\n\ze\s*\\chapter\>' keepend contains=@texFoldGroup,@texChapterGroup,@Spell |
| 273 | syn region texSectionZone matchgroup=texSection start='\\section\>' end='\n\ze\s*\\section\>' keepend contains=@texFoldGroup,@texSectionGroup,@Spell |
| 274 | syn region texSubSectionZone matchgroup=texSection start='\\subsection\>' end='\n\ze\s*\\subsection\>' keepend contains=@texFoldGroup,@texSubSectionGroup,@Spell |
| 275 | syn region texSubSubSectionZone matchgroup=texSection start='\\subsubsection\>' end='\n\ze\s*\\subsubsection\>' keepend contains=@texFoldGroup,@texSubSubSectionGroup,@Spell |
| 276 | syn region texParaZone matchgroup=texSection start='\\paragraph\>' end='\n\ze\s*\\paragraph\>' keepend contains=@texFoldGroup,@texParaGroup,@Spell |
| 277 | syn region texSubParaZone matchgroup=texSection start='\\subparagraph\>' end='\n\ze\s*\\subparagraph\>' keepend contains=@texFoldGroup,@Spell |
| 278 | syn region texTitle matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}' contains=@texFoldGroup,@Spell |
| 279 | syn region texAbstract matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}' contains=@texFoldGroup,@Spell |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 280 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 281 | |
| 282 | " Bad Math (mismatched): {{{1 |
| 283 | if !exists("tex_no_math") |
| 284 | syn match texBadMath "\\end\s*{\s*\(array\|gathered\|bBpvV]matrix\|split\|subequations\|smallmatrix\|xxalignat\)\s*}" |
| 285 | syn match texBadMath "\\end\s*{\s*\(align\|alignat\|displaymath\|displaymath\|eqnarray\|equation\|flalign\|gather\|math\|multline\|xalignat\)\*\=\s*}" |
| 286 | syn match texBadMath "\\[\])]" |
| 287 | endif |
| 288 | |
| 289 | " Math Zones: {{{1 |
| 290 | if !exists("tex_no_math") |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 291 | " TexNewMathZone: function creates a mathzone with the given suffix and mathzone name. {{{2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 292 | " Starred forms are created if starform is true. Starred |
| 293 | " forms have syntax group and synchronization groups with a |
| 294 | " "S" appended. Handles: cluster, syntax, sync, and HiLink. |
| 295 | fun! TexNewMathZone(sfx,mathzone,starform) |
| 296 | let grpname = "texMathZone".a:sfx |
| 297 | let syncname = "texSyncMathZone".a:sfx |
| 298 | exe "syn cluster texMathZones add=".grpname |
| 299 | exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\s*}'."'".' keepend contains=@texMathZoneGroup' |
| 300 | exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"' |
| 301 | exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"' |
| 302 | exe 'HiLink '.grpname.' texMath' |
| 303 | if a:starform |
| 304 | let grpname = "texMathZone".a:sfx.'S' |
| 305 | let syncname = "texSyncMathZone".a:sfx.'S' |
| 306 | exe "syn cluster texMathZones add=".grpname |
| 307 | exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\*\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\*\s*}'."'".' keepend contains=@texMathZoneGroup' |
| 308 | exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"' |
| 309 | exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"' |
| 310 | exe 'HiLink '.grpname.' texMath' |
| 311 | endif |
| 312 | endfun |
| 313 | |
| 314 | " Standard Math Zones: {{{2 |
| 315 | call TexNewMathZone("A","align",1) |
| 316 | call TexNewMathZone("B","alignat",1) |
| 317 | call TexNewMathZone("C","displaymath",1) |
| 318 | call TexNewMathZone("D","eqnarray",1) |
| 319 | call TexNewMathZone("E","equation",1) |
| 320 | call TexNewMathZone("F","flalign",1) |
| 321 | call TexNewMathZone("G","gather",1) |
| 322 | call TexNewMathZone("H","math",1) |
| 323 | call TexNewMathZone("I","multline",1) |
| 324 | call TexNewMathZone("J","subequations",0) |
| 325 | call TexNewMathZone("K","xalignat",1) |
| 326 | call TexNewMathZone("L","xxalignat",0) |
| 327 | |
| 328 | " Inline Math Zones: {{{2 |
| 329 | syn region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)\|%stopzone\>" keepend contains=@texMathZoneGroup |
| 330 | syn region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]\|%stopzone\>" keepend contains=@texMathZoneGroup |
| 331 | syn region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>" contains=@texMathZoneGroup |
| 332 | syn region texMathZoneY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" end="%stopzone\>" keepend contains=@texMathZoneGroup |
| 333 | syn region texMathZoneZ matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" end="%stopzone\>" contains=@texMathZoneGroup |
| 334 | |
| 335 | syn match texMathOper "[_^=]" contained |
| 336 | |
| 337 | " \left..something.. and \right..something.. support: {{{2 |
| 338 | syn match texMathDelimBad contained "\S" |
| 339 | syn match texMathDelim contained "\\\(left\|right\|[bB]igg\=[lr]\)\>" skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad |
| 340 | syn match texMathDelim contained "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\=vert\>" |
| 341 | syn match texMathDelim contained "\\lefteqn\>" |
| 342 | syn match texMathDelimSet2 contained "\\" nextgroup=texMathDelimKey,texMathDelimBad |
| 343 | syn match texMathDelimSet1 contained "[<>()[\]|/.]\|\\[{}|]" |
| 344 | syn keyword texMathDelimKey contained backslash lceil lVert rgroup uparrow |
| 345 | syn keyword texMathDelimKey contained downarrow lfloor rangle rmoustache Uparrow |
| 346 | syn keyword texMathDelimKey contained Downarrow lgroup rbrace rvert updownarrow |
| 347 | syn keyword texMathDelimKey contained langle lmoustache rceil rVert Updownarrow |
| 348 | syn keyword texMathDelimKey contained lbrace lvert rfloor |
| 349 | endif |
| 350 | |
| 351 | " Special TeX characters ( \$ \& \% \# \{ \} \_ \S \P ) : {{{1 |
| 352 | syn match texSpecialChar "\\[$&%#{}_]" |
| 353 | if b:tex_stylish |
| 354 | syn match texSpecialChar "\\[SP@][^a-zA-Z@]"me=e-1 |
| 355 | else |
| 356 | syn match texSpecialChar "\\[SP@]\A"me=e-1 |
| 357 | endif |
| 358 | syn match texSpecialChar "\\\\" |
| 359 | if !exists("tex_no_math") |
| 360 | syn match texOnlyMath "[_^]" |
| 361 | endif |
| 362 | syn match texSpecialChar "\^\^[0-9a-f]\{2}\|\^\^\S" |
| 363 | |
| 364 | " Comments: {{{1 |
| 365 | " Normal TeX LaTeX : %.... |
| 366 | " Documented TeX Format: ^^A... -and- leading %s (only) |
| 367 | syn cluster texCommentGroup contains=texTodo,@Spell |
| 368 | syn case ignore |
| 369 | syn keyword texTodo contained combak fixme todo |
| 370 | syn case match |
| 371 | if b:extfname == "dtx" |
| 372 | syn match texComment "\^\^A.*$" contains=@texCommentGroup |
| 373 | syn match texComment "^%\+" contains=@texCommentGroup |
| 374 | else |
| 375 | syn match texComment "%.*$" contains=@texCommentGroup |
| 376 | endif |
| 377 | |
| 378 | " Separate lines used for verb` and verb# so that the end conditions {{{1 |
| 379 | " will appropriately terminate. Ideally vim would let me save a |
| 380 | " character from the start pattern and re-use it in the end-pattern. |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 381 | syn region texZone start="\\begin{verbatim}" end="\\end{verbatim}\|%stopzone\>" contains=@Spell |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 382 | if version < 600 |
| 383 | syn region texZone start="\\verb\*\=`" end="`\|%stopzone\>" |
| 384 | syn region texZone start="\\verb\*\=#" end="#\|%stopzone\>" |
| 385 | else |
| 386 | if b:tex_stylish |
| 387 | syn region texZone start="\\verb\*\=\z([^\ta-zA-Z@]\)" end="\z1\|%stopzone\>" |
| 388 | else |
| 389 | syn region texZone start="\\verb\*\=\z([^\ta-zA-Z]\)" end="\z1\|%stopzone\>" |
| 390 | endif |
| 391 | endif |
| 392 | |
| 393 | " Tex Reference Zones: {{{1 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 394 | syn region texZone matchgroup=texStatement start="@samp{" end="}\|%stopzone\>" contains=@texRefGroup |
| 395 | syn region texRefZone matchgroup=texStatement start="\\nocite{" end="}\|%stopzone\>" contains=@texRefGroup |
| 396 | syn region texRefZone matchgroup=texStatement start="\\bibliography{" end="}\|%stopzone\>" contains=@texRefGroup |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 397 | syn region texRefZone matchgroup=texStatement start="\\label{" end="}\|%stopzone\>" contains=@texRefGroup |
| 398 | syn region texRefZone matchgroup=texStatement start="\\\(page\|eq\)ref{" end="}\|%stopzone\>" contains=@texRefGroup |
| 399 | syn region texRefZone matchgroup=texStatement start="\\v\=ref{" end="}\|%stopzone\>" contains=@texRefGroup |
Bram Moolenaar | cc016f5 | 2005-12-10 20:23:46 +0000 | [diff] [blame] | 400 | syn match texRefZone '\\cite\%([tp]\*\=\)\=' nextgroup=texRefOption,texCite |
| 401 | syn region texRefOption contained matchgroup=Delimiter start='\[' end=']' contains=@texRefGroup nextgroup=texRefOption,texCite |
| 402 | syn region texCite contained matchgroup=Delimiter start='{' end='}' contains=@texRefGroup |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 403 | |
| 404 | " Handle newcommand, newenvironment : {{{1 |
| 405 | syn match texNewCmd "\\newcommand\>" nextgroup=texCmdName skipwhite skipnl |
| 406 | syn region texCmdName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texCmdArgs,texCmdBody skipwhite skipnl |
| 407 | syn region texCmdArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]" nextgroup=texCmdBody skipwhite skipnl |
| 408 | syn region texCmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=Delimiter end="}" contains=@texCmdGroup |
| 409 | syn match texNewEnv "\\newenvironment\>" nextgroup=texEnvName skipwhite skipnl |
| 410 | syn region texEnvName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvBgn skipwhite skipnl |
| 411 | syn region texEnvBgn contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvEnd skipwhite skipnl contains=@texEnvGroup |
| 412 | syn region texEnvEnd contained matchgroup=Delimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=@texEnvGroup |
| 413 | |
| 414 | " Definitions/Commands: {{{1 |
| 415 | syn match texDefCmd "\\def\>" nextgroup=texDefName skipwhite skipnl |
| 416 | if b:tex_stylish |
| 417 | syn match texDefName contained "\\[a-zA-Z@]\+" nextgroup=texDefParms,texCmdBody skipwhite skipnl |
| 418 | syn match texDefName contained "\\[^a-zA-Z@]" nextgroup=texDefParms,texCmdBody skipwhite skipnl |
| 419 | else |
| 420 | syn match texDefName contained "\\\a\+" nextgroup=texDefParms,texCmdBody skipwhite skipnl |
| 421 | syn match texDefName contained "\\\A" nextgroup=texDefParms,texCmdBody skipwhite skipnl |
| 422 | endif |
| 423 | syn match texDefParms contained "#[^{]*" contains=texDefParm nextgroup=texCmdBody skipwhite skipnl |
| 424 | syn match texDefParm contained "#\d\+" |
| 425 | |
| 426 | " TeX Lengths: {{{1 |
| 427 | syn match texLength "\<\d\+\(\.\d\+\)\=\s*\(true\)\=\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" |
| 428 | |
| 429 | " TeX String Delimiters: {{{1 |
| 430 | syn match texString "\(``\|''\|,,\)" |
| 431 | |
| 432 | " LaTeX synchronization: {{{1 |
| 433 | syn sync maxlines=200 |
| 434 | syn sync minlines=50 |
| 435 | |
| 436 | syn sync match texSyncStop groupthere NONE "%stopzone\>" |
| 437 | |
| 438 | " Synchronization: {{{1 |
| 439 | " The $..$ and $$..$$ make for impossible sync patterns |
| 440 | " (one can't tell if a "$$" starts or stops a math zone by itself) |
| 441 | " The following grouptheres coupled with minlines above |
| 442 | " help improve the odds of good syncing. |
| 443 | if !exists("tex_no_math") |
| 444 | syn sync match texSyncMathZoneA groupthere NONE "\\end{abstract}" |
| 445 | syn sync match texSyncMathZoneA groupthere NONE "\\end{center}" |
| 446 | syn sync match texSyncMathZoneA groupthere NONE "\\end{description}" |
| 447 | syn sync match texSyncMathZoneA groupthere NONE "\\end{enumerate}" |
| 448 | syn sync match texSyncMathZoneA groupthere NONE "\\end{itemize}" |
| 449 | syn sync match texSyncMathZoneA groupthere NONE "\\end{table}" |
| 450 | syn sync match texSyncMathZoneA groupthere NONE "\\end{tabular}" |
| 451 | syn sync match texSyncMathZoneA groupthere NONE "\\\(sub\)*section\>" |
| 452 | endif |
| 453 | |
| 454 | " Highlighting: {{{1 |
| 455 | if did_tex_syntax_inits == 1 |
| 456 | let did_tex_syntax_inits= 2 |
| 457 | " TeX highlighting groups which should share similar highlighting |
| 458 | if !exists("g:tex_no_error") |
| 459 | if !exists("tex_no_math") |
| 460 | HiLink texBadMath texError |
| 461 | HiLink texMathDelimBad texError |
| 462 | HiLink texMathError texError |
| 463 | if !b:tex_stylish |
| 464 | HiLink texOnlyMath texError |
| 465 | endif |
| 466 | endif |
| 467 | HiLink texError Error |
| 468 | endif |
| 469 | |
Bram Moolenaar | cc016f5 | 2005-12-10 20:23:46 +0000 | [diff] [blame] | 470 | HiLink texCite texRefZone |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 471 | HiLink texDefCmd texDef |
| 472 | HiLink texDefName texDef |
| 473 | HiLink texDocType texCmdName |
| 474 | HiLink texDocTypeArgs texCmdArgs |
| 475 | HiLink texInputFileOpt texCmdArgs |
| 476 | HiLink texInputCurlies texDelimiter |
| 477 | HiLink texLigature texSpecialChar |
| 478 | if !exists("tex_no_math") |
| 479 | HiLink texMathDelimSet1 texMathDelim |
| 480 | HiLink texMathDelimSet2 texMathDelim |
| 481 | HiLink texMathDelimKey texMathDelim |
| 482 | HiLink texMathMatcher texMath |
| 483 | HiLink texMathZoneW texMath |
| 484 | HiLink texMathZoneX texMath |
| 485 | HiLink texMathZoneY texMath |
| 486 | HiLink texMathZoneZ texMath |
| 487 | endif |
| 488 | HiLink texSectionMarker texCmdName |
| 489 | HiLink texSectionName texSection |
| 490 | HiLink texSpaceCode texStatement |
| 491 | HiLink texTypeSize texType |
| 492 | HiLink texTypeStyle texType |
| 493 | |
| 494 | " Basic TeX highlighting groups |
| 495 | HiLink texCmdArgs Number |
| 496 | HiLink texCmdName Statement |
| 497 | HiLink texComment Comment |
| 498 | HiLink texDef Statement |
| 499 | HiLink texDefParm Special |
| 500 | HiLink texDelimiter Delimiter |
| 501 | HiLink texInput Special |
| 502 | HiLink texInputFile Special |
| 503 | HiLink texLength Number |
| 504 | HiLink texMath Special |
| 505 | HiLink texMathDelim Statement |
| 506 | HiLink texMathOper Operator |
| 507 | HiLink texNewCmd Statement |
| 508 | HiLink texNewEnv Statement |
| 509 | HiLink texOption Number |
| 510 | HiLink texRefZone Special |
| 511 | HiLink texSection PreCondit |
| 512 | HiLink texSpaceCodeChar Special |
| 513 | HiLink texSpecialChar SpecialChar |
| 514 | HiLink texStatement Statement |
| 515 | HiLink texString String |
| 516 | HiLink texTodo Todo |
| 517 | HiLink texType Type |
| 518 | HiLink texZone PreCondit |
| 519 | |
| 520 | delcommand HiLink |
| 521 | endif |
| 522 | |
| 523 | " Current Syntax: {{{1 |
| 524 | unlet b:extfname |
| 525 | let b:current_syntax = "tex" |
| 526 | " vim: ts=8 fdm=marker |