blob: 8f34b1a6feb26a71d438b21acd5d51cc76700822 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: TeX
Bram Moolenaar488c6512005-08-11 20:09:58 +00003" Maintainer: Dr. Charles E. Campbell, Jr. <NdrchipO@ScampbellPfamily.AbizM>
Bram Moolenaar5aae4192010-08-03 23:00:38 +02004" Last Change: Aug 03, 2010
5" Version: 54
Bram Moolenaar488c6512005-08-11 20:09:58 +00006" URL: http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
Bram Moolenaar071d4272004-06-13 20:20:40 +00007"
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
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +020040scriptencoding utf-8
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
42" Define the default highlighting. {{{1
43" For version 5.7 and earlier: only when not done already
44" For version 5.8 and later: only when an item doesn't have highlighting yet
45if version >= 508 || !exists("did_tex_syntax_inits")
46 let did_tex_syntax_inits = 1
47 if version < 508
48 command -nargs=+ HiLink hi link <args>
49 else
50 command -nargs=+ HiLink hi def link <args>
51 endif
52endif
53if exists("g:tex_tex") && !exists("g:tex_no_error")
54 let g:tex_no_error= 1
55endif
56
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +020057" let user determine which classes of concealment will be supported
58" a=accents/ligatures m=math symbols g=Greek s=superscripts/subscripts
59if !exists("g:tex_conceal")
60 let s:tex_conceal= 'amgs'
61else
62 let s:tex_conceal= g:tex_conceal
63endif
64
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +000065" Determine whether or not to use "*.sty" mode {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000066" The user may override the normal determination by setting
67" g:tex_stylish to 1 (for "*.sty" mode)
68" or to 0 else (normal "*.tex" mode)
69" or on a buffer-by-buffer basis with b:tex_stylish
70let b:extfname=expand("%:e")
71if exists("g:tex_stylish")
72 let b:tex_stylish= g:tex_stylish
73elseif !exists("b:tex_stylish")
74 if b:extfname == "sty" || b:extfname == "cls" || b:extfname == "clo" || b:extfname == "dtx" || b:extfname == "ltx"
75 let b:tex_stylish= 1
76 else
77 let b:tex_stylish= 0
78 endif
79endif
80
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +000081" handle folding {{{1
82if !exists("g:tex_fold_enabled")
83 let g:tex_fold_enabled= 0
84elseif g:tex_fold_enabled && !has("folding")
Bram Moolenaarab194812005-09-14 21:40:12 +000085 let g:tex_fold_enabled= 0
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +000086 echomsg "Ignoring g:tex_fold_enabled=".g:tex_fold_enabled."; need to re-compile vim for +fold support"
87endif
88if g:tex_fold_enabled && &fdm == "manual"
Bram Moolenaar00a927d2010-05-14 23:24:24 +020089 setl fdm=syntax
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +000090endif
91
Bram Moolenaar071d4272004-06-13 20:20:40 +000092" (La)TeX keywords: only use the letters a-zA-Z {{{1
93" but _ is the only one that causes problems.
94if version < 600
95 set isk-=_
96 if b:tex_stylish
97 set isk+=@
98 endif
99else
100 setlocal isk-=_
101 if b:tex_stylish
102 setlocal isk+=@
103 endif
104endif
105
106" Clusters: {{{1
107" --------
108syn cluster texCmdGroup contains=texCmdBody,texComment,texDefParm,texDelimiter,texDocType,texInput,texLength,texLigature,texMathDelim,texMathOper,texNewCmd,texNewEnv,texRefZone,texSection,texSectionMarker,texSectionName,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle
109if !exists("g:tex_no_error")
110 syn cluster texCmdGroup add=texMathError
111endif
112syn cluster texEnvGroup contains=texMatcher,texMathDelim,texSpecialChar,texStatement
Bram Moolenaar488c6512005-08-11 20:09:58 +0000113syn 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 Moolenaar5b8d8fd2005-08-16 23:01:50 +0000114syn 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 Moolenaar5c736222010-01-06 20:54:52 +0100115syn 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
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000116syn cluster texRefGroup contains=texMatcher,texComment,texDelimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000117if !exists("tex_no_math")
118 syn cluster texMathZones contains=texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ
119 syn cluster texMatchGroup add=@texMathZones
120 syn cluster texMathDelimGroup contains=texMathDelimBad,texMathDelimKey,texMathDelimSet1,texMathDelimSet2
121 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
Bram Moolenaar611df5b2010-07-26 22:51:56 +0200122 syn cluster texMathZoneGroup contains=texComment,texDelimiter,texLength,texMathDelim,texMathMatcher,texMathOper,texMathSymbol,texRefZone,texSpecialChar,texStatement,texTypeSize,texTypeStyle
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123 if !exists("g:tex_no_error")
124 syn cluster texMathMatchGroup add=texMathError
125 syn cluster texMathZoneGroup add=texMathError
126 endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000127 syn cluster texMathZoneGroup add=@NoSpell
128 " following used in the \part \chapter \section \subsection \subsubsection
129 " \paragraph \subparagraph \author \title highlighting
130 syn cluster texDocGroup contains=texPartZone,@texPartGroup
131 syn cluster texPartGroup contains=texChapterZone,texSectionZone,texParaZone
132 syn cluster texChapterGroup contains=texSectionZone,texParaZone
133 syn cluster texSectionGroup contains=texSubSectionZone,texParaZone
134 syn cluster texSubSectionGroup contains=texSubSubSectionZone,texParaZone
135 syn cluster texSubSubSectionGroup contains=texParaZone
136 syn cluster texParaGroup contains=texSubParaZone
Bram Moolenaarb2c03502010-07-02 20:20:09 +0200137 if has("conceal") && &enc == 'utf-8'
Bram Moolenaare0021c72010-07-28 17:25:21 +0200138 syn cluster texMathZoneGroup add=texGreek,texSuperscript,texSubscript,texMathSymbol
139 syn cluster texMathMatchGroup add=texGreek,texSuperscript,texSubscript,texMathSymbol
Bram Moolenaarb2c03502010-07-02 20:20:09 +0200140 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141endif
142
143" Try to flag {} and () mismatches: {{{1
144if !exists("g:tex_no_error")
145 syn region texMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=@texMatchGroup,texError
146 syn region texMatcher matchgroup=Delimiter start="\[" end="]" contains=@texMatchGroup,texError
147else
148 syn region texMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=@texMatchGroup
149 syn region texMatcher matchgroup=Delimiter start="\[" end="]" contains=@texMatchGroup
150endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000151syn region texParen start="(" end=")" contains=@texMatchGroup,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000152if !exists("g:tex_no_error")
153 syn match texError "[}\])]"
154endif
155if !exists("tex_no_math")
156 if !exists("g:tex_no_error")
157 syn match texMathError "}" contained
158 endif
159 syn region texMathMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}" end="%stopzone\>" contained contains=@texMathMatchGroup
160endif
161
162" TeX/LaTeX keywords: {{{1
163" Instead of trying to be All Knowing, I just match \..alphameric..
164" Note that *.tex files may not have "@" in their \commands
165if exists("g:tex_tex") || b:tex_stylish
166 syn match texStatement "\\[a-zA-Z@]\+"
167else
168 syn match texStatement "\\\a\+"
169 if !exists("g:tex_no_error")
170 syn match texError "\\\a*@[a-zA-Z@]*"
171 endif
172endif
173
174" TeX/LaTeX delimiters: {{{1
175syn match texDelimiter "&"
176syn match texDelimiter "\\\\"
177
178" Tex/Latex Options: {{{1
179syn match texOption "[^\\]\zs#\d\+\|^#\d\+"
180
181" texAccent (tnx to Karim Belabas) avoids annoying highlighting for accents: {{{1
182if b:tex_stylish
183 syn match texAccent "\\[bcdvuH][^a-zA-Z@]"me=e-1
184 syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)[^a-zA-Z@]"me=e-1
185else
186 syn match texAccent "\\[bcdvuH]\A"me=e-1
187 syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)\A"me=e-1
188endif
189syn match texAccent "\\[bcdvuH]$"
190syn match texAccent +\\[=^.\~"`']+
191syn match texAccent +\\['=t'.c^ud"vb~Hr]{\a}+
192syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)$"
193
194" \begin{}/\end{} section markers: {{{1
195syn match texSectionMarker "\\begin\>\|\\end\>" nextgroup=texSectionName
Bram Moolenaar5c736222010-01-06 20:54:52 +0100196syn region texSectionName matchgroup=Delimiter start="{" end="}" contained nextgroup=texSectionModifier contains=texComment
197syn region texSectionModifier matchgroup=Delimiter start="\[" end="]" contained contains=texComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198
199" \documentclass, \documentstyle, \usepackage: {{{1
200syn match texDocType "\\documentclass\>\|\\documentstyle\>\|\\usepackage\>" nextgroup=texSectionName,texDocTypeArgs
Bram Moolenaar5c736222010-01-06 20:54:52 +0100201syn region texDocTypeArgs matchgroup=Delimiter start="\[" end="]" contained nextgroup=texSectionName contains=texComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000202
Bram Moolenaara9a568c2006-03-14 23:04:27 +0000203" Preamble syntax-based folding support: {{{1
204if g:tex_fold_enabled && has("folding")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100205 syn region texPreamble transparent fold start='\zs\\documentclass\>' end='\ze\\begin{document}' contains=texStyle,@texMatchGroup
Bram Moolenaara9a568c2006-03-14 23:04:27 +0000206endif
207
Bram Moolenaar071d4272004-06-13 20:20:40 +0000208" TeX input: {{{1
209syn match texInput "\\input\s\+[a-zA-Z/.0-9_^]\+"hs=s+7 contains=texStatement
Bram Moolenaar5c736222010-01-06 20:54:52 +0100210syn match texInputFile "\\include\(graphics\|list\)\=\(\[.\{-}\]\)\=\s*{.\{-}}" contains=texStatement,texInputCurlies,texInputFileOpt
Bram Moolenaar071d4272004-06-13 20:20:40 +0000211syn match texInputFile "\\\(epsfig\|input\|usepackage\)\s*\(\[.*\]\)\={.\{-}}" contains=texStatement,texInputCurlies,texInputFileOpt
212syn match texInputCurlies "[{}]" contained
Bram Moolenaar5c736222010-01-06 20:54:52 +0100213syn region texInputFileOpt matchgroup=Delimiter start="\[" end="\]" contained contains=texComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000214
215" Type Styles (LaTeX 2.09): {{{1
216syn match texTypeStyle "\\rm\>"
217syn match texTypeStyle "\\em\>"
218syn match texTypeStyle "\\bf\>"
219syn match texTypeStyle "\\it\>"
220syn match texTypeStyle "\\sl\>"
221syn match texTypeStyle "\\sf\>"
222syn match texTypeStyle "\\sc\>"
223syn match texTypeStyle "\\tt\>"
224
225" Type Styles: attributes, commands, families, etc (LaTeX2E): {{{1
226syn match texTypeStyle "\\textbf\>"
227syn match texTypeStyle "\\textit\>"
228syn match texTypeStyle "\\textmd\>"
229syn match texTypeStyle "\\textrm\>"
230syn match texTypeStyle "\\textsc\>"
231syn match texTypeStyle "\\textsf\>"
232syn match texTypeStyle "\\textsl\>"
233syn match texTypeStyle "\\texttt\>"
234syn match texTypeStyle "\\textup\>"
235syn match texTypeStyle "\\emph\>"
236
237syn match texTypeStyle "\\mathbb\>"
238syn match texTypeStyle "\\mathbf\>"
239syn match texTypeStyle "\\mathcal\>"
240syn match texTypeStyle "\\mathfrak\>"
241syn match texTypeStyle "\\mathit\>"
242syn match texTypeStyle "\\mathnormal\>"
243syn match texTypeStyle "\\mathrm\>"
244syn match texTypeStyle "\\mathsf\>"
245syn match texTypeStyle "\\mathtt\>"
246
247syn match texTypeStyle "\\rmfamily\>"
248syn match texTypeStyle "\\sffamily\>"
249syn match texTypeStyle "\\ttfamily\>"
250
251syn match texTypeStyle "\\itshape\>"
252syn match texTypeStyle "\\scshape\>"
253syn match texTypeStyle "\\slshape\>"
254syn match texTypeStyle "\\upshape\>"
255
256syn match texTypeStyle "\\bfseries\>"
257syn match texTypeStyle "\\mdseries\>"
258
259" Some type sizes: {{{1
260syn match texTypeSize "\\tiny\>"
261syn match texTypeSize "\\scriptsize\>"
262syn match texTypeSize "\\footnotesize\>"
263syn match texTypeSize "\\small\>"
264syn match texTypeSize "\\normalsize\>"
265syn match texTypeSize "\\large\>"
266syn match texTypeSize "\\Large\>"
267syn match texTypeSize "\\LARGE\>"
268syn match texTypeSize "\\huge\>"
269syn match texTypeSize "\\Huge\>"
270
271" Spacecodes (TeX'isms): {{{1
272" \mathcode`\^^@="2201 \delcode`\(="028300 \sfcode`\)=0 \uccode`X=`X \lccode`x=`x
273syn match texSpaceCode "\\\(math\|cat\|del\|lc\|sf\|uc\)code`"me=e-1 nextgroup=texSpaceCodeChar
274syn match texSpaceCodeChar "`\\\=.\(\^.\)\==\(\d\|\"\x\{1,6}\|`.\)" contained
275
276" Sections, subsections, etc: {{{1
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000277if g:tex_fold_enabled && has("folding")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000278 syn region texDocZone matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}' fold contains=@texFoldGroup,@texDocGroup,@Spell
279 syn region texPartZone matchgroup=texSection start='\\part\>' end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)' fold contains=@texFoldGroup,@texPartGroup,@Spell
280 syn region texChapterZone matchgroup=texSection start='\\chapter\>' end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)' fold contains=@texFoldGroup,@texChapterGroup,@Spell
281 syn region texSectionZone matchgroup=texSection start='\\section\>' end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' fold contains=@texFoldGroup,@texSectionGroup,@Spell
282 syn region texSubSectionZone matchgroup=texSection start='\\subsection\>' end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' fold contains=@texFoldGroup,@texSubSectionGroup,@Spell
283 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
284 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
285 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
286 syn region texTitle matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}' fold contains=@texFoldGroup,@Spell
287 syn region texAbstract matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}' fold contains=@texFoldGroup,@Spell
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000288else
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000289 syn region texDocZone matchgroup=texSection start='\\begin\s*{\s*document\s*}' end='\\end\s*{\s*document\s*}' contains=@texFoldGroup,@texDocGroup,@Spell
290 syn region texPartZone matchgroup=texSection start='\\part\>' end='\ze\s*\\\%(part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texPartGroup,@Spell
291 syn region texChapterZone matchgroup=texSection start='\\chapter\>' end='\ze\s*\\\%(chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texChapterGroup,@Spell
292 syn region texSectionZone matchgroup=texSection start='\\section\>' end='\ze\s*\\\%(section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSectionGroup,@Spell
293 syn region texSubSectionZone matchgroup=texSection start='\\subsection\>' end='\ze\s*\\\%(\%(sub\)\=section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSubSectionGroup,@Spell
294 syn region texSubSubSectionZone matchgroup=texSection start='\\subsubsection\>' end='\ze\s*\\\%(\%(sub\)\{,2}section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texSubSubSectionGroup,@Spell
295 syn region texParaZone matchgroup=texSection start='\\paragraph\>' end='\ze\s*\\\%(paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@texParaGroup,@Spell
296 syn region texSubParaZone matchgroup=texSection start='\\subparagraph\>' end='\ze\s*\\\%(\%(sub\)\=paragraph\>\|\%(sub\)*section\>\|chapter\>\|part\>\|end\s*{\s*document\s*}\)' contains=@texFoldGroup,@Spell
297 syn region texTitle matchgroup=texSection start='\\\%(author\|title\)\>\s*{' end='}' contains=@texFoldGroup,@Spell
298 syn region texAbstract matchgroup=texSection start='\\begin\s*{\s*abstract\s*}' end='\\end\s*{\s*abstract\s*}' contains=@texFoldGroup,@Spell
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000299endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000300
301" Bad Math (mismatched): {{{1
302if !exists("tex_no_math")
303 syn match texBadMath "\\end\s*{\s*\(array\|gathered\|bBpvV]matrix\|split\|subequations\|smallmatrix\|xxalignat\)\s*}"
304 syn match texBadMath "\\end\s*{\s*\(align\|alignat\|displaymath\|displaymath\|eqnarray\|equation\|flalign\|gather\|math\|multline\|xalignat\)\*\=\s*}"
305 syn match texBadMath "\\[\])]"
306endif
307
308" Math Zones: {{{1
309if !exists("tex_no_math")
Bram Moolenaar488c6512005-08-11 20:09:58 +0000310 " TexNewMathZone: function creates a mathzone with the given suffix and mathzone name. {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311 " Starred forms are created if starform is true. Starred
312 " forms have syntax group and synchronization groups with a
313 " "S" appended. Handles: cluster, syntax, sync, and HiLink.
314 fun! TexNewMathZone(sfx,mathzone,starform)
315 let grpname = "texMathZone".a:sfx
316 let syncname = "texSyncMathZone".a:sfx
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000317 if g:tex_fold_enabled
318 let foldcmd= " fold"
319 else
320 let foldcmd= ""
321 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322 exe "syn cluster texMathZones add=".grpname
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000323 exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\s*}'."'".' keepend contains=@texMathZoneGroup'.foldcmd
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324 exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
325 exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100326 exe 'hi def link '.grpname.' texMath'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000327 if a:starform
328 let grpname = "texMathZone".a:sfx.'S'
329 let syncname = "texSyncMathZone".a:sfx.'S'
330 exe "syn cluster texMathZones add=".grpname
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000331 exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\*\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\*\s*}'."'".' keepend contains=@texMathZoneGroup'.foldcmd
Bram Moolenaar071d4272004-06-13 20:20:40 +0000332 exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
333 exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100334 exe 'hi def link '.grpname.' texMath'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000335 endif
336 endfun
337
338 " Standard Math Zones: {{{2
339 call TexNewMathZone("A","align",1)
340 call TexNewMathZone("B","alignat",1)
341 call TexNewMathZone("C","displaymath",1)
342 call TexNewMathZone("D","eqnarray",1)
343 call TexNewMathZone("E","equation",1)
344 call TexNewMathZone("F","flalign",1)
345 call TexNewMathZone("G","gather",1)
346 call TexNewMathZone("H","math",1)
347 call TexNewMathZone("I","multline",1)
348 call TexNewMathZone("J","subequations",0)
349 call TexNewMathZone("K","xalignat",1)
350 call TexNewMathZone("L","xxalignat",0)
351
352 " Inline Math Zones: {{{2
Bram Moolenaare0021c72010-07-28 17:25:21 +0200353 if has("conceal") && &enc == 'utf-8'
354 syn region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)\|%stopzone\>" keepend concealends contains=@texMathZoneGroup
355 syn region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]\|%stopzone\>" keepend concealends contains=@texMathZoneGroup
356 syn region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>" concealends contains=@texMathZoneGroup
357 syn region texMathZoneY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" end="%stopzone\>" concealends keepend contains=@texMathZoneGroup
358 else
359 syn region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)\|%stopzone\>" keepend contains=@texMathZoneGroup
360 syn region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]\|%stopzone\>" keepend contains=@texMathZoneGroup
361 syn region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>" contains=@texMathZoneGroup
362 syn region texMathZoneY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" end="%stopzone\>" keepend contains=@texMathZoneGroup
363 endif
Bram Moolenaarb2c03502010-07-02 20:20:09 +0200364 syn region texMathZoneZ matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" end="%stopzone\>" contains=@texMathZoneGroup
Bram Moolenaar071d4272004-06-13 20:20:40 +0000365
366 syn match texMathOper "[_^=]" contained
367
368 " \left..something.. and \right..something.. support: {{{2
369 syn match texMathDelimBad contained "\S"
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200370 if has("conceal") && &enc == 'utf-8' && s:tex_conceal =~ 'm'
371 syn match texMathDelim contained "\\left\\{\>" skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad contains=texMathSymbol cchar={
372 syn match texMathDelim contained "\\right\\}\>" skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad contains=texMathSymbol cchar=}
373 else
374 syn match texMathDelim contained "\\\(left\|right\)\>" skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad
375 endif
376 syn match texMathDelim contained "\\\([bB]igg\=[lr]\)\>" skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377 syn match texMathDelim contained "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\=vert\>"
378 syn match texMathDelim contained "\\lefteqn\>"
379 syn match texMathDelimSet2 contained "\\" nextgroup=texMathDelimKey,texMathDelimBad
380 syn match texMathDelimSet1 contained "[<>()[\]|/.]\|\\[{}|]"
381 syn keyword texMathDelimKey contained backslash lceil lVert rgroup uparrow
382 syn keyword texMathDelimKey contained downarrow lfloor rangle rmoustache Uparrow
383 syn keyword texMathDelimKey contained Downarrow lgroup rbrace rvert updownarrow
384 syn keyword texMathDelimKey contained langle lmoustache rceil rVert Updownarrow
385 syn keyword texMathDelimKey contained lbrace lvert rfloor
386endif
387
388" Special TeX characters ( \$ \& \% \# \{ \} \_ \S \P ) : {{{1
389syn match texSpecialChar "\\[$&%#{}_]"
390if b:tex_stylish
391 syn match texSpecialChar "\\[SP@][^a-zA-Z@]"me=e-1
392else
393 syn match texSpecialChar "\\[SP@]\A"me=e-1
394endif
395syn match texSpecialChar "\\\\"
396if !exists("tex_no_math")
397 syn match texOnlyMath "[_^]"
398endif
399syn match texSpecialChar "\^\^[0-9a-f]\{2}\|\^\^\S"
400
401" Comments: {{{1
402" Normal TeX LaTeX : %....
403" Documented TeX Format: ^^A... -and- leading %s (only)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000404if !exists("g:tex_comment_nospell") || !g:tex_comment_nospell
405 syn cluster texCommentGroup contains=texTodo,@Spell
406else
407 syn cluster texCommentGroup contains=texTodo,@NoSpell
408endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409syn case ignore
Bram Moolenaar18144c82006-04-12 21:52:12 +0000410syn keyword texTodo contained combak fixme todo xxx
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411syn case match
412if b:extfname == "dtx"
413 syn match texComment "\^\^A.*$" contains=@texCommentGroup
414 syn match texComment "^%\+" contains=@texCommentGroup
415else
Bram Moolenaarfd2ac762006-03-01 22:09:21 +0000416 if g:tex_fold_enabled
417 " allows syntax-folding of 2 or more contiguous comment lines
418 " single-line comments are not folded
419 syn match texComment "%.*$" contains=@texCommentGroup
420 syn region texComment start="^\zs\s*%.*\_s*%" skip="^\s*%" end='^\ze\s*[^%]' fold
421 else
422 syn match texComment "%.*$" contains=@texCommentGroup
423 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000424endif
425
426" Separate lines used for verb` and verb# so that the end conditions {{{1
427" will appropriately terminate. Ideally vim would let me save a
428" character from the start pattern and re-use it in the end-pattern.
Bram Moolenaar5c736222010-01-06 20:54:52 +0100429syn region texZone start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}\|%stopzone\>" contains=@Spell
Bram Moolenaarc1e37902006-04-18 21:55:01 +0000430" listings package:
431syn region texZone start="\\begin{lstlisting}" end="\\end{lstlisting}\|%stopzone\>" contains=@Spell
432" moreverb package:
433syn region texZone start="\\begin{verbatimtab}" end="\\end{verbatimtab}\|%stopzone\>" contains=@Spell
434syn region texZone start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}\|%stopzone\>" contains=@Spell
435syn region texZone start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}\|%stopzone\>" contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000436if version < 600
437 syn region texZone start="\\verb\*\=`" end="`\|%stopzone\>"
438 syn region texZone start="\\verb\*\=#" end="#\|%stopzone\>"
439else
440 if b:tex_stylish
441 syn region texZone start="\\verb\*\=\z([^\ta-zA-Z@]\)" end="\z1\|%stopzone\>"
442 else
443 syn region texZone start="\\verb\*\=\z([^\ta-zA-Z]\)" end="\z1\|%stopzone\>"
444 endif
445endif
446
447" Tex Reference Zones: {{{1
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000448syn region texZone matchgroup=texStatement start="@samp{" end="}\|%stopzone\>" contains=@texRefGroup
449syn region texRefZone matchgroup=texStatement start="\\nocite{" end="}\|%stopzone\>" contains=@texRefGroup
450syn region texRefZone matchgroup=texStatement start="\\bibliography{" end="}\|%stopzone\>" contains=@texRefGroup
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000451syn region texRefZone matchgroup=texStatement start="\\label{" end="}\|%stopzone\>" contains=@texRefGroup
452syn region texRefZone matchgroup=texStatement start="\\\(page\|eq\)ref{" end="}\|%stopzone\>" contains=@texRefGroup
453syn region texRefZone matchgroup=texStatement start="\\v\=ref{" end="}\|%stopzone\>" contains=@texRefGroup
Bram Moolenaarcc016f52005-12-10 20:23:46 +0000454syn match texRefZone '\\cite\%([tp]\*\=\)\=' nextgroup=texRefOption,texCite
455syn region texRefOption contained matchgroup=Delimiter start='\[' end=']' contains=@texRefGroup nextgroup=texRefOption,texCite
456syn region texCite contained matchgroup=Delimiter start='{' end='}' contains=@texRefGroup
Bram Moolenaar071d4272004-06-13 20:20:40 +0000457
458" Handle newcommand, newenvironment : {{{1
459syn match texNewCmd "\\newcommand\>" nextgroup=texCmdName skipwhite skipnl
460syn region texCmdName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texCmdArgs,texCmdBody skipwhite skipnl
461syn region texCmdArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]" nextgroup=texCmdBody skipwhite skipnl
462syn region texCmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=Delimiter end="}" contains=@texCmdGroup
463syn match texNewEnv "\\newenvironment\>" nextgroup=texEnvName skipwhite skipnl
464syn region texEnvName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvBgn skipwhite skipnl
465syn region texEnvBgn contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvEnd skipwhite skipnl contains=@texEnvGroup
466syn region texEnvEnd contained matchgroup=Delimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=@texEnvGroup
467
468" Definitions/Commands: {{{1
469syn match texDefCmd "\\def\>" nextgroup=texDefName skipwhite skipnl
470if b:tex_stylish
471 syn match texDefName contained "\\[a-zA-Z@]\+" nextgroup=texDefParms,texCmdBody skipwhite skipnl
472 syn match texDefName contained "\\[^a-zA-Z@]" nextgroup=texDefParms,texCmdBody skipwhite skipnl
473else
474 syn match texDefName contained "\\\a\+" nextgroup=texDefParms,texCmdBody skipwhite skipnl
475 syn match texDefName contained "\\\A" nextgroup=texDefParms,texCmdBody skipwhite skipnl
476endif
477syn match texDefParms contained "#[^{]*" contains=texDefParm nextgroup=texCmdBody skipwhite skipnl
478syn match texDefParm contained "#\d\+"
479
480" TeX Lengths: {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000481syn match texLength "\<\d\+\([.,]\d\+\)\=\s*\(true\)\=\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000482
483" TeX String Delimiters: {{{1
484syn match texString "\(``\|''\|,,\)"
485
Bram Moolenaar5c736222010-01-06 20:54:52 +0100486" makeatletter -- makeatother sections
487if !exists("g:tex_no_error")
488 syn region texStyle matchgroup=texStatement start='\\makeatletter' end='\\makeatother' contains=@texStyleGroup contained
489 syn match texStyleStatement "\\[a-zA-Z@]\+" contained
490 syn region texStyleMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=@texStyleGroup,texError contained
491 syn region texStyleMatcher matchgroup=Delimiter start="\[" end="]" contains=@texStyleGroup,texError contained
492endif
493
Bram Moolenaar611df5b2010-07-26 22:51:56 +0200494" Conceal mode support (supports set cole=1) {{{1
Bram Moolenaarb2c03502010-07-02 20:20:09 +0200495if has("conceal") && &enc == 'utf-8'
Bram Moolenaar611df5b2010-07-26 22:51:56 +0200496
497 " Math Symbols {{{2
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200498 if s:tex_conceal =~ 'm'
499 syn match texMathSymbol '\\approx\>' contained conceal cchar=≈
500 syn match texMathSymbol '\\ast\>' contained conceal cchar=∗
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200501 syn match texMathSymbol '\\because\>' contained conceal cchar=∵
502 syn match texMathSymbol '\\bigcap\>' contained conceal cchar=∩
503 syn match texMathSymbol '\\bigcup\>' contained conceal cchar=∪
504 syn match texMathSymbol '\\bigodot\>' contained conceal cchar=⊙
505 syn match texMathSymbol '\\bigoplus\>' contained conceal cchar=⊕
506 syn match texMathSymbol '\\bigotimes\>' contained conceal cchar=⊗
507 syn match texMathSymbol '\\bigsqcup\>' contained conceal cchar=⊔
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200508 syn match texMathSymbol '\\bigtriangledown\>' contained conceal cchar=∇
509 syn match texMathSymbol '\\bigvee\>' contained conceal cchar=⋁
510 syn match texMathSymbol '\\bigwedge\>' contained conceal cchar=⋀
511 syn match texMathSymbol '\\blacksquare\>' contained conceal cchar=∎
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200512 syn match texMathSymbol '\\bot\>' contained conceal cchar=⊥
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200513 syn match texMathSymbol '\\cap\>' contained conceal cchar=∩
514 syn match texMathSymbol '\\cdot\>' contained conceal cchar=·
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200515 syn match texMathSymbol '\\cdots\>' contained conceal cchar=⋯
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200516 syn match texMathSymbol '\\circ\>' contained conceal cchar=∘
517 syn match texMathSymbol '\\circledcirc\>' contained conceal cchar=⊚
518 syn match texMathSymbol '\\cong\>' contained conceal cchar=≅
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200519 syn match texMathSymbol '\\coprod\>' contained conceal cchar=∐
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200520 syn match texMathSymbol '\\cup\>' contained conceal cchar=∪
521 syn match texMathSymbol '\\diamond\>' contained conceal cchar=⋄
522 syn match texMathSymbol '\\div\>' contained conceal cchar=÷
523 syn match texMathSymbol '\\doteq\>' contained conceal cchar=≐
524 syn match texMathSymbol '\\dotsb\>' contained conceal cchar=⋯
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200525 syn match texMathSymbol '\\dotsc\>' contained conceal cchar=…
526 syn match texMathSymbol '\\dots\>' contained conceal cchar=…
527 syn match texMathSymbol '\\dotsi\>' contained conceal cchar=⋯
528 syn match texMathSymbol '\\dotso\>' contained conceal cchar=…
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200529 syn match texMathSymbol '\\emptyset\>' contained conceal cchar=∅
530 syn match texMathSymbol '\\equiv\>' contained conceal cchar=≡
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200531 syn match texMathSymbol '\\exists\>' contained conceal cchar=∃
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200532 syn match texMathSymbol '\\forall\>' contained conceal cchar=∀
533 syn match texMathSymbol '\\geq\>' contained conceal cchar=≥
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200534 if &ambw == "double"
535 syn match texMathSymbol '\\gg\>' contained conceal cchar=≫
536 else
537 syn match texMathSymbol '\\gg\>' contained conceal cchar=⟫
538 endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200539 syn match texMathSymbol '\\gtreqless\>' contained conceal cchar=⋛
540 syn match texMathSymbol '\\gtrless\>' contained conceal cchar=≷
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200541 syn match texMathSymbol '\\iiint\>' contained conceal cchar=∭
542 syn match texMathSymbol '\\iint\>' contained conceal cchar=∬
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200543 syn match texMathSymbol '\\Im\>' contained conceal cchar=ℑ
544 syn match texMathSymbol '\\in\>' contained conceal cchar=∈
545 syn match texMathSymbol '\\infty\>' contained conceal cchar=∞
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200546 syn match texMathSymbol '\\int\>' contained conceal cchar=∫
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200547 syn match texMathSymbol '\\lceil\>' contained conceal cchar=⌈
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200548 syn match texMathSymbol '\\ldots\>' contained conceal cchar=…
549 syn match texMathSymbol '\\leftarrow\>' contained conceal cchar=⟵
550 syn match texMathSymbol '\\Leftarrow\>' contained conceal cchar=⟸
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200551 syn match texMathSymbol '\\left(' contained conceal cchar=(
552 syn match texMathSymbol '\\left\[' contained conceal cchar=[
553 syn match texMathSymbol '\\left\\{' contained conceal cchar={
554 syn match texMathSymbol '\\leq\>' contained conceal cchar=≤
555 syn match texMathSymbol '\\leq\>' contained conceal cchar=≤
556 syn match texMathSymbol '\\lesseqgtr\>' contained conceal cchar=⋚
557 syn match texMathSymbol '\\lfloor\>' contained conceal cchar=⌊
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200558 if &ambw == "double"
559 syn match texMathSymbol '\\ll\>' contained conceal cchar=≪
560 else
561 syn match texMathSymbol '\\ll\>' contained conceal cchar=⟪
562 endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200563 syn match texMathSymbol '\\mapsto\>' contained conceal cchar=↦
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200564 syn match texMathSymbol '\\mid\>' contained conceal cchar=∣
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200565 syn match texMathSymbol '\\mp\>' contained conceal cchar=∓
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200566 syn match texMathSymbol '\\nabla\>' contained conceal cchar=∇
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200567 syn match texMathSymbol '\\neq\>' contained conceal cchar=≠
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200568 syn match texMathSymbol '\\nexists\>' contained conceal cchar=∄
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200569 syn match texMathSymbol '\\ngeq\>' contained conceal cchar=≱
570 syn match texMathSymbol '\\ngtr\>' contained conceal cchar=≯
571 syn match texMathSymbol '\\nleq\>' contained conceal cchar=≰
572 syn match texMathSymbol '\\nless\>' contained conceal cchar=≮
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200573 syn match texMathSymbol '\\nmid\>' contained conceal cchar=∤
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200574 syn match texMathSymbol '\\notin\>' contained conceal cchar=∉
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200575 syn match texMathSymbol '\\nsim\>' contained conceal cchar=≁
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200576 syn match texMathSymbol '\\odot\>' contained conceal cchar=⊙
577 syn match texMathSymbol '\\oint\>' contained conceal cchar=∮
578 syn match texMathSymbol '\\oplus\>' contained conceal cchar=⊕
579 syn match texMathSymbol '\\oslash\>' contained conceal cchar=⊘
580 syn match texMathSymbol '\\otimes\>' contained conceal cchar=⊗
581 syn match texMathSymbol '\\partial\>' contained conceal cchar=∂
582 syn match texMathSymbol '\\perp\>' contained conceal cchar=⊥
583 syn match texMathSymbol '\\pm\>' contained conceal cchar=±
584 syn match texMathSymbol '\\prec\>' contained conceal cchar=≺
585 syn match texMathSymbol '\\prod\>' contained conceal cchar=∏
586 syn match texMathSymbol '\\propto\>' contained conceal cchar=∝
587 syn match texMathSymbol '\\rceil\>' contained conceal cchar=⌉
588 syn match texMathSymbol '\\Re\>' contained conceal cchar=ℜ
589 syn match texMathSymbol '\\rfloor\>' contained conceal cchar=⌋
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200590 syn match texMathSymbol '\\rightarrow\>' contained conceal cchar=⟶
591 syn match texMathSymbol '\\Rightarrow\>' contained conceal cchar=⟹
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200592 syn match texMathSymbol '\\right)' contained conceal cchar=)
593 syn match texMathSymbol '\\right]' contained conceal cchar=]
594 syn match texMathSymbol '\\right\\}' contained conceal cchar=}
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200595 syn match texMathSymbol '\\setminus\>' contained conceal cchar=∖
596 syn match texMathSymbol '\\sim\>' contained conceal cchar=∼
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200597 syn match texMathSymbol '\\sqcap\>' contained conceal cchar=⊓
598 syn match texMathSymbol '\\sqcup\>' contained conceal cchar=⊔
599 syn match texMathSymbol '\\subset\>' contained conceal cchar=⊂
600 syn match texMathSymbol '\\subseteq\>' contained conceal cchar=⊆
601 syn match texMathSymbol '\\subsetneq\>' contained conceal cchar=⊊
602 syn match texMathSymbol '\\succ\>' contained conceal cchar=≻
603 syn match texMathSymbol '\\sum\>' contained conceal cchar=∑
604 syn match texMathSymbol '\\supseteq\>' contained conceal cchar=⊇
605 syn match texMathSymbol '\\supsetneq\>' contained conceal cchar=⊋
606 syn match texMathSymbol '\\surd\>' contained conceal cchar=√
607 syn match texMathSymbol '\\therefore\>' contained conceal cchar=∴
608 syn match texMathSymbol '\\times\>' contained conceal cchar=×
609 syn match texMathSymbol '\\to\>' contained conceal cchar=→
610 syn match texMathSymbol '\\trianglelefteq\>' contained conceal cchar=⊴
611 syn match texMathSymbol '\\trianglerighteq\>' contained conceal cchar=⊵
612 syn match texMathSymbol '\\vartriangle\>' contained conceal cchar=∆
613 syn match texMathSymbol '\\vdots\>' contained conceal cchar=⋮
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200614 syn match texMathSymbol '\\vee\>' contained conceal cchar=∨
615 syn match texMathSymbol '\\wedge\>' contained conceal cchar=∧
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200616 endif
Bram Moolenaar611df5b2010-07-26 22:51:56 +0200617
618 " Greek {{{2
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200619 if s:tex_conceal =~ 'g'
620 fun! s:Greek(group,pat,cchar)
621 exe 'syn match '.a:group." '".a:pat."' contained conceal cchar=".a:cchar
622 endfun
623 call s:Greek('texGreek','\\alpha\>' ,'α')
624 call s:Greek('texGreek','\\beta\>' ,'β')
625 call s:Greek('texGreek','\\gamma\>' ,'γ')
626 call s:Greek('texGreek','\\delta\>' ,'δ')
627 call s:Greek('texGreek','\\epsilon\>' ,'ϵ')
628 call s:Greek('texGreek','\\varepsilon\>' ,'ε')
629 call s:Greek('texGreek','\\zeta\>' ,'ζ')
630 call s:Greek('texGreek','\\eta\>' ,'η')
631 call s:Greek('texGreek','\\theta\>' ,'θ')
632 call s:Greek('texGreek','\\vartheta\>' ,'ϑ')
633 call s:Greek('texGreek','\\kappa\>' ,'κ')
634 call s:Greek('texGreek','\\lambda\>' ,'λ')
635 call s:Greek('texGreek','\\mu\>' ,'μ')
636 call s:Greek('texGreek','\\nu\>' ,'ν')
637 call s:Greek('texGreek','\\xi\>' ,'ξ')
638 call s:Greek('texGreek','\\pi\>' ,'π')
639 call s:Greek('texGreek','\\varpi\>' ,'ϖ')
640 call s:Greek('texGreek','\\rho\>' ,'ρ')
641 call s:Greek('texGreek','\\varrho\>' ,'ϱ')
642 call s:Greek('texGreek','\\sigma\>' ,'σ')
643 call s:Greek('texGreek','\\varsigma\>' ,'ς')
644 call s:Greek('texGreek','\\tau\>' ,'τ')
645 call s:Greek('texGreek','\\upsilon\>' ,'υ')
646 call s:Greek('texGreek','\\phi\>' ,'φ')
647 call s:Greek('texGreek','\\varphi\>' ,'ϕ')
648 call s:Greek('texGreek','\\chi\>' ,'χ')
649 call s:Greek('texGreek','\\psi\>' ,'ψ')
650 call s:Greek('texGreek','\\omega\>' ,'ω')
651 call s:Greek('texGreek','\\Gamma\>' ,'Γ')
652 call s:Greek('texGreek','\\Delta\>' ,'Δ')
653 call s:Greek('texGreek','\\Theta\>' ,'Θ')
654 call s:Greek('texGreek','\\Lambda\>' ,'Λ')
655 call s:Greek('texGreek','\\Xi\>' ,'Χ')
656 call s:Greek('texGreek','\\Pi\>' ,'Π')
657 call s:Greek('texGreek','\\Sigma\>' ,'Σ')
658 call s:Greek('texGreek','\\Upsilon\>' ,'Υ')
659 call s:Greek('texGreek','\\Phi\>' ,'Φ')
660 call s:Greek('texGreek','\\Psi\>' ,'Ψ')
661 call s:Greek('texGreek','\\Omega\>' ,'Ω')
662 delfun s:Greek
663 endif
Bram Moolenaar611df5b2010-07-26 22:51:56 +0200664
665 " Superscripts/Subscripts {{{2
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200666 if s:tex_conceal =~ 's'
667 syn region texSuperscript matchgroup=Delimiter start='\^{' end='}' contained concealends contains=texSuperscripts,texStatement
668 syn region texSubscript matchgroup=Delimiter start='_{' end='}' contained concealends contains=texSubscripts,texStatement
669 fun! s:SuperSub(group,leader,pat,cchar)
670 exe 'syn match '.a:group." '".a:leader.a:pat."' contained conceal cchar=".a:cchar
671 exe 'syn match '.a:group."s '".a:pat."' contained conceal cchar=".a:cchar.' nextgroup='.a:group.'s'
672 endfun
673 call s:SuperSub('texSuperscript','\^','0','⁰')
674 call s:SuperSub('texSuperscript','\^','1','¹')
675 call s:SuperSub('texSuperscript','\^','2','²')
676 call s:SuperSub('texSuperscript','\^','3','³')
677 call s:SuperSub('texSuperscript','\^','4','⁴')
678 call s:SuperSub('texSuperscript','\^','5','⁵')
679 call s:SuperSub('texSuperscript','\^','6','⁶')
680 call s:SuperSub('texSuperscript','\^','7','⁷')
681 call s:SuperSub('texSuperscript','\^','8','⁸')
682 call s:SuperSub('texSuperscript','\^','9','⁹')
683 call s:SuperSub('texSuperscript','\^','a','ᵃ')
684 call s:SuperSub('texSuperscript','\^','b','ᵇ')
685 call s:SuperSub('texSuperscript','\^','c','ᶜ')
686 call s:SuperSub('texSuperscript','\^','d','ᵈ')
687 call s:SuperSub('texSuperscript','\^','e','ᵉ')
688 call s:SuperSub('texSuperscript','\^','f','ᶠ')
689 call s:SuperSub('texSuperscript','\^','g','ᵍ')
690 call s:SuperSub('texSuperscript','\^','h','ʰ')
691 call s:SuperSub('texSuperscript','\^','i','ⁱ')
692 call s:SuperSub('texSuperscript','\^','j','ʲ')
693 call s:SuperSub('texSuperscript','\^','k','ᵏ')
694 call s:SuperSub('texSuperscript','\^','l','ˡ')
695 call s:SuperSub('texSuperscript','\^','m','ᵐ')
696 call s:SuperSub('texSuperscript','\^','n','ⁿ')
697 call s:SuperSub('texSuperscript','\^','o','ᵒ')
698 call s:SuperSub('texSuperscript','\^','p','ᵖ')
699 call s:SuperSub('texSuperscript','\^','r','ʳ')
700 call s:SuperSub('texSuperscript','\^','s','ˢ')
701 call s:SuperSub('texSuperscript','\^','t','ᵗ')
702 call s:SuperSub('texSuperscript','\^','u','ᵘ')
703 call s:SuperSub('texSuperscript','\^','v','ᵛ')
704 call s:SuperSub('texSuperscript','\^','w','ʷ')
705 call s:SuperSub('texSuperscript','\^','x','ˣ')
706 call s:SuperSub('texSuperscript','\^','y','ʸ')
707 call s:SuperSub('texSuperscript','\^','z','ᶻ')
708 call s:SuperSub('texSuperscript','\^','A','ᴬ')
709 call s:SuperSub('texSuperscript','\^','B','ᴮ')
710 call s:SuperSub('texSuperscript','\^','D','ᴰ')
711 call s:SuperSub('texSuperscript','\^','E','ᴱ')
712 call s:SuperSub('texSuperscript','\^','G','ᴳ')
713 call s:SuperSub('texSuperscript','\^','H','ᴴ')
714 call s:SuperSub('texSuperscript','\^','I','ᴵ')
715 call s:SuperSub('texSuperscript','\^','J','ᴶ')
716 call s:SuperSub('texSuperscript','\^','K','ᴷ')
717 call s:SuperSub('texSuperscript','\^','L','ᴸ')
718 call s:SuperSub('texSuperscript','\^','M','ᴹ')
719 call s:SuperSub('texSuperscript','\^','N','ᴺ')
720 call s:SuperSub('texSuperscript','\^','O','ᴼ')
721 call s:SuperSub('texSuperscript','\^','P','ᴾ')
722 call s:SuperSub('texSuperscript','\^','R','ᴿ')
723 call s:SuperSub('texSuperscript','\^','T','ᵀ')
724 call s:SuperSub('texSuperscript','\^','U','ᵁ')
725 call s:SuperSub('texSuperscript','\^','W','ᵂ')
726 call s:SuperSub('texSuperscript','\^','+','⁺')
727 call s:SuperSub('texSuperscript','\^','-','⁻')
728 call s:SuperSub('texSuperscript','\^','<','˂')
729 call s:SuperSub('texSuperscript','\^','>','˃')
730 call s:SuperSub('texSuperscript','\^','/','ˊ')
731 call s:SuperSub('texSuperscript','\^','(','⁽')
732 call s:SuperSub('texSuperscript','\^',')','⁾')
733 call s:SuperSub('texSuperscript','\^','\.','˙')
734 call s:SuperSub('texSuperscript','\^','=','˭')
735 call s:SuperSub('texSubscript','_','0','₀')
736 call s:SuperSub('texSubscript','_','1','₁')
737 call s:SuperSub('texSubscript','_','2','₂')
738 call s:SuperSub('texSubscript','_','3','₃')
739 call s:SuperSub('texSubscript','_','4','₄')
740 call s:SuperSub('texSubscript','_','5','₅')
741 call s:SuperSub('texSubscript','_','6','₆')
742 call s:SuperSub('texSubscript','_','7','₇')
743 call s:SuperSub('texSubscript','_','8','₈')
744 call s:SuperSub('texSubscript','_','9','₉')
745 call s:SuperSub('texSubscript','_','a','ₐ')
746 call s:SuperSub('texSubscript','_','e','ₑ')
747 call s:SuperSub('texSubscript','_','i','ᵢ')
748 call s:SuperSub('texSubscript','_','o','ₒ')
749 call s:SuperSub('texSubscript','_','u','ᵤ')
750 call s:SuperSub('texSubscript','_','+','₊')
751 call s:SuperSub('texSubscript','_','-','₋')
752 call s:SuperSub('texSubscript','_','/','ˏ')
753 call s:SuperSub('texSubscript','_','(','₍')
754 call s:SuperSub('texSubscript','_',')','₎')
755 call s:SuperSub('texSubscript','_','\.','‸')
756 call s:SuperSub('texSubscript','_','r','ᵣ')
757 call s:SuperSub('texSubscript','_','v','ᵥ')
758 call s:SuperSub('texSubscript','_','x','ₓ')
759 call s:SuperSub('texSubscript','_','\\beta\>' ,'ᵦ')
760 call s:SuperSub('texSubscript','_','\\delta\>','ᵨ')
761 call s:SuperSub('texSubscript','_','\\phi\>' ,'ᵩ')
762 call s:SuperSub('texSubscript','_','\\gamma\>','ᵧ')
763 call s:SuperSub('texSubscript','_','\\chi\>' ,'ᵪ')
764 delfun s:SuperSub
765 endif
Bram Moolenaar611df5b2010-07-26 22:51:56 +0200766
767 " Accented characters: {{{2
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200768 if s:tex_conceal =~ 'a'
769 if b:tex_stylish
770 syn match texAccent "\\[bcdvuH][^a-zA-Z@]"me=e-1
771 syn match texLigature "\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)[^a-zA-Z@]"me=e-1
772 else
773 fun! s:Accents(chr,...)
774 let i= 1
775 for accent in ["`","\\'","^",'"','\~',"r","v"]
776 if i > a:0
777 break
778 endif
779 if strlen(a:{i}) == 0
780 let i= i + 1
781 continue
782 endif
783 exe "syn match texAccent '\\\\".accent."{".a:chr."}' conceal cchar=".a:{i}
Bram Moolenaare0021c72010-07-28 17:25:21 +0200784 let i= i + 1
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200785 endfor
786 endfun
787 call s:Accents('a','à','á','â','ä','ã','å','ă')
788 call s:Accents('A','À','Á','Â','Ä','Ã','Å','Ă')
789 call s:Accents('C',"" ,'Ć','Ĉ',"" ,"" ,"" ,'Ć')
790 call s:Accents('e','è','é','ê','ë','ẽ',"" ,'ĕ')
791 call s:Accents('E','È','É','Ê','Ë','Ẽ',"" ,'Ė')
792 call s:Accents('i','ì','í','î','ï','ĩ',"" ,"ĭ")
793 call s:Accents('I','Ì','Í','Î','Ï','Ĩ',"" ,'Ĭ')
794 call s:Accents('o','ò','ó','ô','ö','õ',"" ,'ŏ')
795 call s:Accents('O','Ò','Ó','Ô','Ö','Õ',"" ,'Ŏ')
796 call s:Accents('r',"" ,'ŕ',"" ,"" ,"" ,"" ,'ř')
797 call s:Accents('R',"" ,'Ŕ',"" ,"" ,"" ,"" ,'Ř')
798 call s:Accents('s',"" ,'ś','ŝ',"" ,"" ,"" ,'š')
799 call s:Accents('S',"" ,'Ś','Ŝ',"" ,"" ,"" ,'Š')
800 call s:Accents('u','ù','ú','û','ü','ũ',"" ,'ŭ')
801 call s:Accents('U','Ù','Ú','Û','Ü','Ũ',"" ,'Ŭ')
802 call s:Accents('y','ỳ','ý','ŷ','ÿ','ỹ',"" ,"" )
803 call s:Accents('Y','Ỳ','Ý','Ŷ','Ÿ','Ỹ',"" ,"" )
804 delfun s:Accents
805 syn match texAccent '\\aa\>' conceal cchar=å
806 syn match texAccent '\\AA\>' conceal cchar=Å
807 syn match texAccent '\\k{a}' conceal cchar=ą
808 syn match texAccent '\\k{A}' conceal cchar=Ą
809 syn match texAccent '\\c{C}' conceal cchar=Ç
810 syn match texAccent '\\c{c}' conceal cchar=ç
811 syn match texAccent '\\\~{n}' conceal cchar=ñ
812 syn match texAccent '\\\~{N}' conceal cchar=Ñ
813 syn match texAccent '\\o\>' conceal cchar=ø
814 syn match texAccent '\\O\>' conceal cchar=Ø
815 syn match texAccent '\\H{o}' conceal cchar=ő
816 syn match texAccent '\\H{O}' conceal cchar=Ő
817 syn match texAccent '\\c{r}' conceal cchar=ŗ
818 syn match texLigature '\\AE\>' conceal cchar=Æ
819 syn match texLigature '\\ae\>' conceal cchar=æ
820 syn match texLigature '\\oe\>' conceal cchar=œ
821 syn match texLigature '\\OE\>' conceal cchar=Œ
822 syn match texLigature '\\ss\>' conceal cchar=ß
823 endif
Bram Moolenaar611df5b2010-07-26 22:51:56 +0200824 endif
Bram Moolenaarb2c03502010-07-02 20:20:09 +0200825endif
826
827" ---------------------------------------------------------------------
Bram Moolenaar071d4272004-06-13 20:20:40 +0000828" LaTeX synchronization: {{{1
829syn sync maxlines=200
830syn sync minlines=50
831
832syn sync match texSyncStop groupthere NONE "%stopzone\>"
833
834" Synchronization: {{{1
835" The $..$ and $$..$$ make for impossible sync patterns
836" (one can't tell if a "$$" starts or stops a math zone by itself)
837" The following grouptheres coupled with minlines above
838" help improve the odds of good syncing.
839if !exists("tex_no_math")
840 syn sync match texSyncMathZoneA groupthere NONE "\\end{abstract}"
841 syn sync match texSyncMathZoneA groupthere NONE "\\end{center}"
842 syn sync match texSyncMathZoneA groupthere NONE "\\end{description}"
843 syn sync match texSyncMathZoneA groupthere NONE "\\end{enumerate}"
844 syn sync match texSyncMathZoneA groupthere NONE "\\end{itemize}"
845 syn sync match texSyncMathZoneA groupthere NONE "\\end{table}"
846 syn sync match texSyncMathZoneA groupthere NONE "\\end{tabular}"
847 syn sync match texSyncMathZoneA groupthere NONE "\\\(sub\)*section\>"
848endif
849
Bram Moolenaarb2c03502010-07-02 20:20:09 +0200850" ---------------------------------------------------------------------
Bram Moolenaar071d4272004-06-13 20:20:40 +0000851" Highlighting: {{{1
852if did_tex_syntax_inits == 1
853 let did_tex_syntax_inits= 2
854 " TeX highlighting groups which should share similar highlighting
855 if !exists("g:tex_no_error")
856 if !exists("tex_no_math")
857 HiLink texBadMath texError
858 HiLink texMathDelimBad texError
859 HiLink texMathError texError
860 if !b:tex_stylish
861 HiLink texOnlyMath texError
862 endif
863 endif
864 HiLink texError Error
865 endif
866
Bram Moolenaarcc016f52005-12-10 20:23:46 +0000867 HiLink texCite texRefZone
Bram Moolenaar071d4272004-06-13 20:20:40 +0000868 HiLink texDefCmd texDef
869 HiLink texDefName texDef
870 HiLink texDocType texCmdName
871 HiLink texDocTypeArgs texCmdArgs
872 HiLink texInputFileOpt texCmdArgs
873 HiLink texInputCurlies texDelimiter
874 HiLink texLigature texSpecialChar
875 if !exists("tex_no_math")
876 HiLink texMathDelimSet1 texMathDelim
877 HiLink texMathDelimSet2 texMathDelim
878 HiLink texMathDelimKey texMathDelim
879 HiLink texMathMatcher texMath
Bram Moolenaar5c736222010-01-06 20:54:52 +0100880 HiLink texMathZoneV texMath
Bram Moolenaar071d4272004-06-13 20:20:40 +0000881 HiLink texMathZoneW texMath
882 HiLink texMathZoneX texMath
883 HiLink texMathZoneY texMath
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000884 HiLink texMathZoneV texMath
Bram Moolenaar071d4272004-06-13 20:20:40 +0000885 HiLink texMathZoneZ texMath
886 endif
887 HiLink texSectionMarker texCmdName
888 HiLink texSectionName texSection
889 HiLink texSpaceCode texStatement
Bram Moolenaar5c736222010-01-06 20:54:52 +0100890 HiLink texStyleStatement texStatement
Bram Moolenaar071d4272004-06-13 20:20:40 +0000891 HiLink texTypeSize texType
892 HiLink texTypeStyle texType
893
894 " Basic TeX highlighting groups
895 HiLink texCmdArgs Number
896 HiLink texCmdName Statement
897 HiLink texComment Comment
898 HiLink texDef Statement
899 HiLink texDefParm Special
900 HiLink texDelimiter Delimiter
901 HiLink texInput Special
902 HiLink texInputFile Special
903 HiLink texLength Number
904 HiLink texMath Special
905 HiLink texMathDelim Statement
906 HiLink texMathOper Operator
907 HiLink texNewCmd Statement
908 HiLink texNewEnv Statement
909 HiLink texOption Number
910 HiLink texRefZone Special
911 HiLink texSection PreCondit
912 HiLink texSpaceCodeChar Special
913 HiLink texSpecialChar SpecialChar
914 HiLink texStatement Statement
915 HiLink texString String
916 HiLink texTodo Todo
917 HiLink texType Type
918 HiLink texZone PreCondit
919
920 delcommand HiLink
921endif
922
923" Current Syntax: {{{1
924unlet b:extfname
925let b:current_syntax = "tex"
Bram Moolenaar5aae4192010-08-03 23:00:38 +0200926" vim: ts=8 fdm=marker ambw=double