xref: /vim-8.2.3635/runtime/syntax/tex.vim (revision cfbc5ee4)
1071d4279SBram Moolenaar" Vim syntax file
2071d4279SBram Moolenaar" Language:	TeX
3071d4279SBram Moolenaar" Maintainer:	Dr. Charles E. Campbell, Jr. <[email protected]>
4*cfbc5ee4SBram Moolenaar" Last Change:	Jun 15, 2004
5*cfbc5ee4SBram Moolenaar" Version:	25
6071d4279SBram Moolenaar" URL:		http://www.erols.com/astronaut/vim/index.html#vimlinks_syntax
7071d4279SBram Moolenaar"
8071d4279SBram Moolenaar" Notes: {{{1
9071d4279SBram Moolenaar"
10071d4279SBram Moolenaar" 1. If you have a \begin{verbatim} that appears to overrun its boundaries,
11071d4279SBram Moolenaar"    use %stopzone.
12071d4279SBram Moolenaar"
13071d4279SBram Moolenaar" 2. Run-on equations ($..$ and $$..$$, particularly) can also be stopped
14071d4279SBram Moolenaar"    by suitable use of %stopzone.
15071d4279SBram Moolenaar"
16071d4279SBram Moolenaar" 3. If you have a slow computer, you may wish to modify
17071d4279SBram Moolenaar"
18071d4279SBram Moolenaar"	syn sync maxlines=200
19071d4279SBram Moolenaar"	syn sync minlines=50
20071d4279SBram Moolenaar"
21071d4279SBram Moolenaar"    to values that are more to your liking.
22071d4279SBram Moolenaar"
23071d4279SBram Moolenaar" 4. There is no match-syncing for $...$ and $$...$$; hence large
24071d4279SBram Moolenaar"    equation blocks constructed that way may exhibit syncing problems.
25071d4279SBram Moolenaar"    (there's no difference between begin/end patterns)
26071d4279SBram Moolenaar"
27071d4279SBram Moolenaar" 5. If you have the variable "g:tex_no_error" defined then none of the
28071d4279SBram Moolenaar"    lexical error-checking will be done.
29071d4279SBram Moolenaar"
30071d4279SBram Moolenaar"    ie. let g:tex_no_error=1
31071d4279SBram Moolenaar
32071d4279SBram Moolenaar" Version Clears: {{{1
33071d4279SBram Moolenaar" For version 5.x: Clear all syntax items
34071d4279SBram Moolenaar" For version 6.x: Quit when a syntax file was already loaded
35071d4279SBram Moolenaarif version < 600
36071d4279SBram Moolenaar  syntax clear
37071d4279SBram Moolenaarelseif exists("b:current_syntax")
38071d4279SBram Moolenaar  finish
39071d4279SBram Moolenaarendif
40071d4279SBram Moolenaar
41071d4279SBram Moolenaar" Define the default highlighting. {{{1
42071d4279SBram Moolenaar" For version 5.7 and earlier: only when not done already
43071d4279SBram Moolenaar" For version 5.8 and later: only when an item doesn't have highlighting yet
44071d4279SBram Moolenaarif version >= 508 || !exists("did_tex_syntax_inits")
45071d4279SBram Moolenaar let did_tex_syntax_inits = 1
46071d4279SBram Moolenaar if version < 508
47071d4279SBram Moolenaar  command -nargs=+ HiLink hi link <args>
48071d4279SBram Moolenaar else
49071d4279SBram Moolenaar  command -nargs=+ HiLink hi def link <args>
50071d4279SBram Moolenaar endif
51071d4279SBram Moolenaarendif
52071d4279SBram Moolenaarif exists("g:tex_tex") && !exists("g:tex_no_error")
53071d4279SBram Moolenaar let g:tex_no_error= 1
54071d4279SBram Moolenaarendif
55071d4279SBram Moolenaar
56071d4279SBram Moolenaar" Determine whether or not to use "*.sty" mode
57071d4279SBram Moolenaar" The user may override the normal determination by setting
58071d4279SBram Moolenaar"   g:tex_stylish to 1      (for    "*.sty" mode)
59071d4279SBram Moolenaar"    or to           0 else (normal "*.tex" mode)
60071d4279SBram Moolenaar" or on a buffer-by-buffer basis with b:tex_stylish
61071d4279SBram Moolenaarlet b:extfname=expand("%:e")
62071d4279SBram Moolenaarif exists("g:tex_stylish")
63071d4279SBram Moolenaar let b:tex_stylish= g:tex_stylish
64071d4279SBram Moolenaarelseif !exists("b:tex_stylish")
65071d4279SBram Moolenaar if b:extfname == "sty" || b:extfname == "cls" || b:extfname == "clo" || b:extfname == "dtx" || b:extfname == "ltx"
66071d4279SBram Moolenaar  let b:tex_stylish= 1
67071d4279SBram Moolenaar else
68071d4279SBram Moolenaar  let b:tex_stylish= 0
69071d4279SBram Moolenaar endif
70071d4279SBram Moolenaarendif
71071d4279SBram Moolenaar
72071d4279SBram Moolenaar" (La)TeX keywords: only use the letters a-zA-Z {{{1
73071d4279SBram Moolenaar" but _ is the only one that causes problems.
74071d4279SBram Moolenaarif version < 600
75071d4279SBram Moolenaar  set isk-=_
76071d4279SBram Moolenaar  if b:tex_stylish
77071d4279SBram Moolenaar    set isk+=@
78071d4279SBram Moolenaar  endif
79071d4279SBram Moolenaarelse
80071d4279SBram Moolenaar  setlocal isk-=_
81071d4279SBram Moolenaar  if b:tex_stylish
82071d4279SBram Moolenaar    setlocal isk+=@
83071d4279SBram Moolenaar  endif
84071d4279SBram Moolenaarendif
85071d4279SBram Moolenaar
86071d4279SBram Moolenaar" Clusters: {{{1
87071d4279SBram Moolenaar" --------
88071d4279SBram Moolenaarsyn cluster texCmdGroup		contains=texCmdBody,texComment,texDefParm,texDelimiter,texDocType,texInput,texLength,texLigature,texMathDelim,texMathOper,texNewCmd,texNewEnv,texRefZone,texSection,texSectionMarker,texSectionName,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle
89071d4279SBram Moolenaarif !exists("g:tex_no_error")
90071d4279SBram Moolenaar syn cluster texCmdGroup	add=texMathError
91071d4279SBram Moolenaarendif
92071d4279SBram Moolenaarsyn cluster texEnvGroup		contains=texMatcher,texMathDelim,texSpecialChar,texStatement
93071d4279SBram Moolenaarsyn 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
94*cfbc5ee4SBram Moolenaarsyn cluster texRefGroup		contains=texMatcher,texComment,texDelimiter
95071d4279SBram Moolenaarif !exists("tex_no_math")
96071d4279SBram Moolenaar syn cluster texMathZones	contains=texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ
97071d4279SBram Moolenaar syn cluster texMatchGroup	add=@texMathZones
98071d4279SBram Moolenaar syn cluster texMathDelimGroup	contains=texMathDelimBad,texMathDelimKey,texMathDelimSet1,texMathDelimSet2
99071d4279SBram Moolenaar 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
100071d4279SBram Moolenaar syn cluster texMathZoneGroup	contains=texComment,texDelimiter,texLength,texMathDelim,texMathMatcher,texMathOper,texRefZone,texSpecialChar,texStatement,texTypeSize,texTypeStyle
101071d4279SBram Moolenaar if !exists("g:tex_no_error")
102071d4279SBram Moolenaar  syn cluster texMathMatchGroup	add=texMathError
103071d4279SBram Moolenaar  syn cluster texMathZoneGroup	add=texMathError
104071d4279SBram Moolenaar endif
105071d4279SBram Moolenaarendif
106071d4279SBram Moolenaar
107071d4279SBram Moolenaar" Try to flag {} and () mismatches: {{{1
108071d4279SBram Moolenaarif !exists("g:tex_no_error")
109071d4279SBram Moolenaar syn region texMatcher		matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]"	end="}"		contains=@texMatchGroup,texError
110071d4279SBram Moolenaar syn region texMatcher		matchgroup=Delimiter start="\["				end="]"		contains=@texMatchGroup,texError
111071d4279SBram Moolenaarelse
112071d4279SBram Moolenaar syn region texMatcher		matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]"	end="}"		contains=@texMatchGroup
113071d4279SBram Moolenaar syn region texMatcher		matchgroup=Delimiter start="\["				end="]"		contains=@texMatchGroup
114071d4279SBram Moolenaarendif
115071d4279SBram Moolenaarsyn region texParen		start="("						end=")"		contains=@texMatchGroup
116071d4279SBram Moolenaarif !exists("g:tex_no_error")
117071d4279SBram Moolenaar syn match  texError		"[}\])]"
118071d4279SBram Moolenaarendif
119071d4279SBram Moolenaarif !exists("tex_no_math")
120071d4279SBram Moolenaar if !exists("g:tex_no_error")
121071d4279SBram Moolenaar  syn match  texMathError	"}"	contained
122071d4279SBram Moolenaar endif
123071d4279SBram Moolenaar syn region texMathMatcher	matchgroup=Delimiter start="{"  skip="\\\\\|\\}"  end="}" end="%stopzone\>" contained contains=@texMathMatchGroup
124071d4279SBram Moolenaarendif
125071d4279SBram Moolenaar
126071d4279SBram Moolenaar" TeX/LaTeX keywords: {{{1
127071d4279SBram Moolenaar" Instead of trying to be All Knowing, I just match \..alphameric..
128071d4279SBram Moolenaar" Note that *.tex files may not have "@" in their \commands
129071d4279SBram Moolenaarif exists("g:tex_tex") || b:tex_stylish
130071d4279SBram Moolenaar  syn match texStatement	"\\[a-zA-Z@]\+"
131071d4279SBram Moolenaarelse
132071d4279SBram Moolenaar  syn match texStatement	"\\\a\+"
133071d4279SBram Moolenaar  if !exists("g:tex_no_error")
134071d4279SBram Moolenaar   syn match texError		"\\\a*@[a-zA-Z@]*"
135071d4279SBram Moolenaar  endif
136071d4279SBram Moolenaarendif
137071d4279SBram Moolenaar
138071d4279SBram Moolenaar" TeX/LaTeX delimiters: {{{1
139071d4279SBram Moolenaarsyn match texDelimiter		"&"
140071d4279SBram Moolenaarsyn match texDelimiter		"\\\\"
141071d4279SBram Moolenaar
142071d4279SBram Moolenaar" Tex/Latex Options: {{{1
143071d4279SBram Moolenaarsyn match texOption	"[^\\]\zs#\d\+\|^#\d\+"
144071d4279SBram Moolenaar
145071d4279SBram Moolenaar" texAccent (tnx to Karim Belabas) avoids annoying highlighting for accents: {{{1
146071d4279SBram Moolenaarif b:tex_stylish
147071d4279SBram Moolenaar  syn match texAccent		"\\[bcdvuH][^a-zA-Z@]"me=e-1
148071d4279SBram Moolenaar  syn match texLigature		"\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)[^a-zA-Z@]"me=e-1
149071d4279SBram Moolenaarelse
150071d4279SBram Moolenaar  syn match texAccent		"\\[bcdvuH]\A"me=e-1
151071d4279SBram Moolenaar  syn match texLigature		"\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)\A"me=e-1
152071d4279SBram Moolenaarendif
153071d4279SBram Moolenaarsyn match texAccent		"\\[bcdvuH]$"
154071d4279SBram Moolenaarsyn match texAccent		+\\[=^.\~"`']+
155071d4279SBram Moolenaarsyn match texAccent		+\\['=t'.c^ud"vb~Hr]{\a}+
156071d4279SBram Moolenaarsyn match texLigature		"\\\([ijolL]\|ae\|oe\|ss\|AA\|AE\|OE\)$"
157071d4279SBram Moolenaar
158071d4279SBram Moolenaar" \begin{}/\end{} section markers: {{{1
159071d4279SBram Moolenaarsyn match  texSectionMarker	"\\begin\>\|\\end\>" nextgroup=texSectionName
160071d4279SBram Moolenaarsyn region texSectionName	matchgroup=Delimiter start="{" end="}"  contained nextgroup=texSectionModifier
161071d4279SBram Moolenaarsyn region texSectionModifier	matchgroup=Delimiter start="\[" end="]" contained
162071d4279SBram Moolenaar
163071d4279SBram Moolenaar" \documentclass, \documentstyle, \usepackage: {{{1
164071d4279SBram Moolenaarsyn match  texDocType		"\\documentclass\>\|\\documentstyle\>\|\\usepackage\>"	nextgroup=texSectionName,texDocTypeArgs
165071d4279SBram Moolenaarsyn region texDocTypeArgs	matchgroup=Delimiter start="\[" end="]"			contained	nextgroup=texSectionName
166071d4279SBram Moolenaar
167071d4279SBram Moolenaar" TeX input: {{{1
168071d4279SBram Moolenaarsyn match texInput		"\\input\s\+[a-zA-Z/.0-9_^]\+"hs=s+7				contains=texStatement
169071d4279SBram Moolenaarsyn match texInputFile		"\\include\(graphics\|list\)\=\(\[.\{-}\]\)\=\s*{.\{-}}"	contains=texStatement,texInputCurlies
170071d4279SBram Moolenaarsyn match texInputFile		"\\\(epsfig\|input\|usepackage\)\s*\(\[.*\]\)\={.\{-}}"		contains=texStatement,texInputCurlies,texInputFileOpt
171071d4279SBram Moolenaarsyn match texInputCurlies	"[{}]"								contained
172071d4279SBram Moolenaarsyn region texInputFileOpt	matchgroup=Delimiter start="\[" end="\]"			contained
173071d4279SBram Moolenaar
174071d4279SBram Moolenaar" Type Styles (LaTeX 2.09): {{{1
175071d4279SBram Moolenaarsyn match texTypeStyle		"\\rm\>"
176071d4279SBram Moolenaarsyn match texTypeStyle		"\\em\>"
177071d4279SBram Moolenaarsyn match texTypeStyle		"\\bf\>"
178071d4279SBram Moolenaarsyn match texTypeStyle		"\\it\>"
179071d4279SBram Moolenaarsyn match texTypeStyle		"\\sl\>"
180071d4279SBram Moolenaarsyn match texTypeStyle		"\\sf\>"
181071d4279SBram Moolenaarsyn match texTypeStyle		"\\sc\>"
182071d4279SBram Moolenaarsyn match texTypeStyle		"\\tt\>"
183071d4279SBram Moolenaar
184071d4279SBram Moolenaar" Type Styles: attributes, commands, families, etc (LaTeX2E): {{{1
185071d4279SBram Moolenaarsyn match texTypeStyle		"\\textbf\>"
186071d4279SBram Moolenaarsyn match texTypeStyle		"\\textit\>"
187071d4279SBram Moolenaarsyn match texTypeStyle		"\\textmd\>"
188071d4279SBram Moolenaarsyn match texTypeStyle		"\\textrm\>"
189071d4279SBram Moolenaarsyn match texTypeStyle		"\\textsc\>"
190071d4279SBram Moolenaarsyn match texTypeStyle		"\\textsf\>"
191071d4279SBram Moolenaarsyn match texTypeStyle		"\\textsl\>"
192071d4279SBram Moolenaarsyn match texTypeStyle		"\\texttt\>"
193071d4279SBram Moolenaarsyn match texTypeStyle		"\\textup\>"
194071d4279SBram Moolenaarsyn match texTypeStyle		"\\emph\>"
195071d4279SBram Moolenaar
196071d4279SBram Moolenaarsyn match texTypeStyle		"\\mathbb\>"
197071d4279SBram Moolenaarsyn match texTypeStyle		"\\mathbf\>"
198071d4279SBram Moolenaarsyn match texTypeStyle		"\\mathcal\>"
199071d4279SBram Moolenaarsyn match texTypeStyle		"\\mathfrak\>"
200071d4279SBram Moolenaarsyn match texTypeStyle		"\\mathit\>"
201071d4279SBram Moolenaarsyn match texTypeStyle		"\\mathnormal\>"
202071d4279SBram Moolenaarsyn match texTypeStyle		"\\mathrm\>"
203071d4279SBram Moolenaarsyn match texTypeStyle		"\\mathsf\>"
204071d4279SBram Moolenaarsyn match texTypeStyle		"\\mathtt\>"
205071d4279SBram Moolenaar
206071d4279SBram Moolenaarsyn match texTypeStyle		"\\rmfamily\>"
207071d4279SBram Moolenaarsyn match texTypeStyle		"\\sffamily\>"
208071d4279SBram Moolenaarsyn match texTypeStyle		"\\ttfamily\>"
209071d4279SBram Moolenaar
210071d4279SBram Moolenaarsyn match texTypeStyle		"\\itshape\>"
211071d4279SBram Moolenaarsyn match texTypeStyle		"\\scshape\>"
212071d4279SBram Moolenaarsyn match texTypeStyle		"\\slshape\>"
213071d4279SBram Moolenaarsyn match texTypeStyle		"\\upshape\>"
214071d4279SBram Moolenaar
215071d4279SBram Moolenaarsyn match texTypeStyle		"\\bfseries\>"
216071d4279SBram Moolenaarsyn match texTypeStyle		"\\mdseries\>"
217071d4279SBram Moolenaar
218071d4279SBram Moolenaar" Some type sizes: {{{1
219071d4279SBram Moolenaarsyn match texTypeSize		"\\tiny\>"
220071d4279SBram Moolenaarsyn match texTypeSize		"\\scriptsize\>"
221071d4279SBram Moolenaarsyn match texTypeSize		"\\footnotesize\>"
222071d4279SBram Moolenaarsyn match texTypeSize		"\\small\>"
223071d4279SBram Moolenaarsyn match texTypeSize		"\\normalsize\>"
224071d4279SBram Moolenaarsyn match texTypeSize		"\\large\>"
225071d4279SBram Moolenaarsyn match texTypeSize		"\\Large\>"
226071d4279SBram Moolenaarsyn match texTypeSize		"\\LARGE\>"
227071d4279SBram Moolenaarsyn match texTypeSize		"\\huge\>"
228071d4279SBram Moolenaarsyn match texTypeSize		"\\Huge\>"
229071d4279SBram Moolenaar
230071d4279SBram Moolenaar" Spacecodes (TeX'isms): {{{1
231071d4279SBram Moolenaar" \mathcode`\^^@="2201  \delcode`\(="028300  \sfcode`\)=0 \uccode`X=`X  \lccode`x=`x
232071d4279SBram Moolenaarsyn match texSpaceCode		"\\\(math\|cat\|del\|lc\|sf\|uc\)code`"me=e-1 nextgroup=texSpaceCodeChar
233071d4279SBram Moolenaarsyn match texSpaceCodeChar    "`\\\=.\(\^.\)\==\(\d\|\"\x\{1,6}\|`.\)"	contained
234071d4279SBram Moolenaar
235071d4279SBram Moolenaar" Sections, subsections, etc: {{{1
236071d4279SBram Moolenaarsyn match texSection		"\\\(sub\)*section\*\=\>"
237071d4279SBram Moolenaarsyn match texSection		"\\\(title\|author\|part\|chapter\|paragraph\|subparagraph\)\>"
238071d4279SBram Moolenaarsyn match texSection		"\\begin\s*{\s*abstract\s*}\|\\end\s*{\s*abstract\s*}"
239071d4279SBram Moolenaar
240071d4279SBram Moolenaar" Bad Math (mismatched): {{{1
241071d4279SBram Moolenaarif !exists("tex_no_math")
242071d4279SBram Moolenaar syn match texBadMath		"\\end\s*{\s*\(array\|gathered\|bBpvV]matrix\|split\|subequations\|smallmatrix\|xxalignat\)\s*}"
243071d4279SBram Moolenaar syn match texBadMath		"\\end\s*{\s*\(align\|alignat\|displaymath\|displaymath\|eqnarray\|equation\|flalign\|gather\|math\|multline\|xalignat\)\*\=\s*}"
244071d4279SBram Moolenaar syn match texBadMath		"\\[\])]"
245071d4279SBram Moolenaarendif
246071d4279SBram Moolenaar
247071d4279SBram Moolenaar" Math Zones: {{{1
248071d4279SBram Moolenaarif !exists("tex_no_math")
249071d4279SBram Moolenaar " TexNewMathZone: creates a mathzone with the given suffix and mathzone name. {{{2
250071d4279SBram Moolenaar "                 Starred forms are created if starform is true.  Starred
251071d4279SBram Moolenaar "                 forms have syntax group and synchronization groups with a
252071d4279SBram Moolenaar "                 "S" appended.  Handles: cluster, syntax, sync, and HiLink.
253071d4279SBram Moolenaar fun! TexNewMathZone(sfx,mathzone,starform)
254071d4279SBram Moolenaar   let grpname  = "texMathZone".a:sfx
255071d4279SBram Moolenaar   let syncname = "texSyncMathZone".a:sfx
256071d4279SBram Moolenaar   exe "syn cluster texMathZones add=".grpname
257071d4279SBram Moolenaar   exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\s*}'."'".' keepend contains=@texMathZoneGroup'
258071d4279SBram Moolenaar   exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
259071d4279SBram Moolenaar   exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
260071d4279SBram Moolenaar   exe 'HiLink '.grpname.' texMath'
261071d4279SBram Moolenaar   if a:starform
262071d4279SBram Moolenaar    let grpname  = "texMathZone".a:sfx.'S'
263071d4279SBram Moolenaar    let syncname = "texSyncMathZone".a:sfx.'S'
264071d4279SBram Moolenaar    exe "syn cluster texMathZones add=".grpname
265071d4279SBram Moolenaar    exe 'syn region '.grpname.' start='."'".'\\begin\s*{\s*'.a:mathzone.'\*\s*}'."'".' end='."'".'\\end\s*{\s*'.a:mathzone.'\*\s*}'."'".' keepend contains=@texMathZoneGroup'
266071d4279SBram Moolenaar    exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
267071d4279SBram Moolenaar    exe 'syn sync match '.syncname.' grouphere '.grpname.' "\\begin\s*{\s*'.a:mathzone.'\*\s*}"'
268071d4279SBram Moolenaar    exe 'HiLink '.grpname.' texMath'
269071d4279SBram Moolenaar   endif
270071d4279SBram Moolenaar endfun
271071d4279SBram Moolenaar
272071d4279SBram Moolenaar " Standard Math Zones: {{{2
273071d4279SBram Moolenaar call TexNewMathZone("A","align",1)
274071d4279SBram Moolenaar call TexNewMathZone("B","alignat",1)
275071d4279SBram Moolenaar call TexNewMathZone("C","displaymath",1)
276071d4279SBram Moolenaar call TexNewMathZone("D","eqnarray",1)
277071d4279SBram Moolenaar call TexNewMathZone("E","equation",1)
278071d4279SBram Moolenaar call TexNewMathZone("F","flalign",1)
279071d4279SBram Moolenaar call TexNewMathZone("G","gather",1)
280071d4279SBram Moolenaar call TexNewMathZone("H","math",1)
281071d4279SBram Moolenaar call TexNewMathZone("I","multline",1)
282071d4279SBram Moolenaar call TexNewMathZone("J","subequations",0)
283071d4279SBram Moolenaar call TexNewMathZone("K","xalignat",1)
284071d4279SBram Moolenaar call TexNewMathZone("L","xxalignat",0)
285071d4279SBram Moolenaar
286071d4279SBram Moolenaar " Inline Math Zones: {{{2
287071d4279SBram Moolenaar syn region texMathZoneV	matchgroup=Delimiter start="\\("	matchgroup=Delimiter end="\\)\|%stopzone\>"	keepend contains=@texMathZoneGroup
288071d4279SBram Moolenaar syn region texMathZoneW	matchgroup=Delimiter start="\\\["	matchgroup=Delimiter end="\\]\|%stopzone\>"	keepend contains=@texMathZoneGroup
289071d4279SBram Moolenaar syn region texMathZoneX	matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>"	contains=@texMathZoneGroup
290071d4279SBram Moolenaar syn region texMathZoneY	matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" end="%stopzone\>"	keepend		contains=@texMathZoneGroup
291071d4279SBram Moolenaar syn region texMathZoneZ	matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" end="%stopzone\>"	contains=@texMathZoneGroup
292071d4279SBram Moolenaar
293071d4279SBram Moolenaar syn match texMathOper		"[_^=]" contained
294071d4279SBram Moolenaar
295071d4279SBram Moolenaar " \left..something.. and \right..something.. support: {{{2
296071d4279SBram Moolenaar syn match   texMathDelimBad	contained		"\S"
297071d4279SBram Moolenaar syn match   texMathDelim	contained		"\\\(left\|right\|[bB]igg\=[lr]\)\>"	skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad
298071d4279SBram Moolenaar syn match   texMathDelim	contained		"\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\=vert\>"
299071d4279SBram Moolenaar syn match   texMathDelim	contained		"\\lefteqn\>"
300071d4279SBram Moolenaar syn match   texMathDelimSet2	contained	"\\"		nextgroup=texMathDelimKey,texMathDelimBad
301071d4279SBram Moolenaar syn match   texMathDelimSet1	contained	"[<>()[\]|/.]\|\\[{}|]"
302071d4279SBram Moolenaar syn keyword texMathDelimKey	contained	backslash       lceil           lVert           rgroup          uparrow
303071d4279SBram Moolenaar syn keyword texMathDelimKey	contained	downarrow       lfloor          rangle          rmoustache      Uparrow
304071d4279SBram Moolenaar syn keyword texMathDelimKey	contained	Downarrow       lgroup          rbrace          rvert           updownarrow
305071d4279SBram Moolenaar syn keyword texMathDelimKey	contained	langle          lmoustache      rceil           rVert           Updownarrow
306071d4279SBram Moolenaar syn keyword texMathDelimKey	contained	lbrace          lvert           rfloor
307071d4279SBram Moolenaarendif
308071d4279SBram Moolenaar
309071d4279SBram Moolenaar" Special TeX characters  ( \$ \& \% \# \{ \} \_ \S \P ) : {{{1
310071d4279SBram Moolenaarsyn match texSpecialChar	"\\[$&%#{}_]"
311071d4279SBram Moolenaarif b:tex_stylish
312071d4279SBram Moolenaar  syn match texSpecialChar	"\\[SP@][^a-zA-Z@]"me=e-1
313071d4279SBram Moolenaarelse
314071d4279SBram Moolenaar  syn match texSpecialChar	"\\[SP@]\A"me=e-1
315071d4279SBram Moolenaarendif
316071d4279SBram Moolenaarsyn match texSpecialChar	"\\\\"
317071d4279SBram Moolenaarif !exists("tex_no_math")
318071d4279SBram Moolenaar syn match texOnlyMath		"[_^]"
319071d4279SBram Moolenaarendif
320071d4279SBram Moolenaarsyn match texSpecialChar	"\^\^[0-9a-f]\{2}\|\^\^\S"
321071d4279SBram Moolenaar
322071d4279SBram Moolenaar" Comments: {{{1
323071d4279SBram Moolenaar"    Normal TeX LaTeX     :   %....
324071d4279SBram Moolenaar"    Documented TeX Format:  ^^A...	-and-	leading %s (only)
325071d4279SBram Moolenaarsyn cluster texCommentGroup	contains=texTodo,@Spell
326071d4279SBram Moolenaarsyn case ignore
327071d4279SBram Moolenaarsyn keyword texTodo		contained		combak	fixme	todo
328071d4279SBram Moolenaarsyn case match
329071d4279SBram Moolenaarif b:extfname == "dtx"
330071d4279SBram Moolenaar  syn match texComment		"\^\^A.*$"	contains=@texCommentGroup
331071d4279SBram Moolenaar  syn match texComment		"^%\+"		contains=@texCommentGroup
332071d4279SBram Moolenaarelse
333071d4279SBram Moolenaar  syn match texComment		"%.*$"		contains=@texCommentGroup
334071d4279SBram Moolenaarendif
335071d4279SBram Moolenaar
336071d4279SBram Moolenaar" Separate lines used for verb` and verb# so that the end conditions {{{1
337071d4279SBram Moolenaar" will appropriately terminate.  Ideally vim would let me save a
338071d4279SBram Moolenaar" character from the start pattern and re-use it in the end-pattern.
339071d4279SBram Moolenaarsyn region texZone		start="\\begin{verbatim}"		end="\\end{verbatim}\|%stopzone\>"
340071d4279SBram Moolenaarif version < 600
341071d4279SBram Moolenaar syn region texZone		start="\\verb\*\=`"			end="`\|%stopzone\>"
342071d4279SBram Moolenaar syn region texZone		start="\\verb\*\=#"			end="#\|%stopzone\>"
343071d4279SBram Moolenaarelse
344071d4279SBram Moolenaar  if b:tex_stylish
345071d4279SBram Moolenaar    syn region texZone		start="\\verb\*\=\z([^\ta-zA-Z@]\)"	end="\z1\|%stopzone\>"
346071d4279SBram Moolenaar  else
347071d4279SBram Moolenaar    syn region texZone		start="\\verb\*\=\z([^\ta-zA-Z]\)"	end="\z1\|%stopzone\>"
348071d4279SBram Moolenaar  endif
349071d4279SBram Moolenaarendif
350071d4279SBram Moolenaar
351071d4279SBram Moolenaar" Tex Reference Zones: {{{1
352*cfbc5ee4SBram Moolenaarsyn region texZone		matchgroup=texStatement start="@samp{"			end="}\|%stopzone\>"	contains=@texRefGroup
353*cfbc5ee4SBram Moolenaarsyn region texRefZone		matchgroup=texStatement start="\\nocite{"		end="}\|%stopzone\>"	contains=@texRefGroup
354*cfbc5ee4SBram Moolenaarsyn region texRefZone		matchgroup=texStatement start="\\bibliography{"		end="}\|%stopzone\>"	contains=@texRefGroup
355*cfbc5ee4SBram Moolenaarsyn region texRefZone		matchgroup=texStatement start="\\cite\([tp]\*\=\)\={"	end="}\|%stopzone\>"	contains=@texRefGroup
356*cfbc5ee4SBram Moolenaarsyn region texRefZone		matchgroup=texStatement start="\\label{"		end="}\|%stopzone\>"	contains=@texRefGroup
357*cfbc5ee4SBram Moolenaarsyn region texRefZone		matchgroup=texStatement start="\\\(page\|eq\)ref{"	end="}\|%stopzone\>"	contains=@texRefGroup
358*cfbc5ee4SBram Moolenaarsyn region texRefZone		matchgroup=texStatement start="\\v\=ref{"		end="}\|%stopzone\>"	contains=@texRefGroup
359071d4279SBram Moolenaar
360071d4279SBram Moolenaar" Handle newcommand, newenvironment : {{{1
361071d4279SBram Moolenaarsyn match  texNewCmd				"\\newcommand\>"			nextgroup=texCmdName skipwhite skipnl
362071d4279SBram Moolenaarsyn region texCmdName contained matchgroup=Delimiter start="{"rs=s+1  end="}"		nextgroup=texCmdArgs,texCmdBody skipwhite skipnl
363071d4279SBram Moolenaarsyn region texCmdArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]"		nextgroup=texCmdBody skipwhite skipnl
364071d4279SBram Moolenaarsyn region texCmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]"	matchgroup=Delimiter end="}" contains=@texCmdGroup
365071d4279SBram Moolenaarsyn match  texNewEnv				"\\newenvironment\>"			nextgroup=texEnvName skipwhite skipnl
366071d4279SBram Moolenaarsyn region texEnvName contained matchgroup=Delimiter start="{"rs=s+1  end="}"		nextgroup=texEnvBgn skipwhite skipnl
367071d4279SBram Moolenaarsyn region texEnvBgn  contained matchgroup=Delimiter start="{"rs=s+1  end="}"		nextgroup=texEnvEnd skipwhite skipnl contains=@texEnvGroup
368071d4279SBram Moolenaarsyn region texEnvEnd  contained matchgroup=Delimiter start="{"rs=s+1  end="}"		skipwhite skipnl contains=@texEnvGroup
369071d4279SBram Moolenaar
370071d4279SBram Moolenaar" Definitions/Commands: {{{1
371071d4279SBram Moolenaarsyn match texDefCmd				"\\def\>"				nextgroup=texDefName skipwhite skipnl
372071d4279SBram Moolenaarif b:tex_stylish
373071d4279SBram Moolenaar  syn match texDefName contained		"\\[a-zA-Z@]\+"				nextgroup=texDefParms,texCmdBody skipwhite skipnl
374071d4279SBram Moolenaar  syn match texDefName contained		"\\[^a-zA-Z@]"				nextgroup=texDefParms,texCmdBody skipwhite skipnl
375071d4279SBram Moolenaarelse
376071d4279SBram Moolenaar  syn match texDefName contained		"\\\a\+"				nextgroup=texDefParms,texCmdBody skipwhite skipnl
377071d4279SBram Moolenaar  syn match texDefName contained		"\\\A"					nextgroup=texDefParms,texCmdBody skipwhite skipnl
378071d4279SBram Moolenaarendif
379071d4279SBram Moolenaarsyn match texDefParms  contained		"#[^{]*"	contains=texDefParm	nextgroup=texCmdBody skipwhite skipnl
380071d4279SBram Moolenaarsyn match  texDefParm  contained		"#\d\+"
381071d4279SBram Moolenaar
382071d4279SBram Moolenaar" TeX Lengths: {{{1
383071d4279SBram Moolenaarsyn match  texLength		"\<\d\+\(\.\d\+\)\=\s*\(true\)\=\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>"
384071d4279SBram Moolenaar
385071d4279SBram Moolenaar" TeX String Delimiters: {{{1
386071d4279SBram Moolenaarsyn match texString		"\(``\|''\|,,\)"
387071d4279SBram Moolenaar
388071d4279SBram Moolenaar" LaTeX synchronization: {{{1
389071d4279SBram Moolenaarsyn sync maxlines=200
390071d4279SBram Moolenaarsyn sync minlines=50
391071d4279SBram Moolenaar
392071d4279SBram Moolenaarsyn  sync match texSyncStop			groupthere NONE		"%stopzone\>"
393071d4279SBram Moolenaar
394071d4279SBram Moolenaar" Synchronization: {{{1
395071d4279SBram Moolenaar" The $..$ and $$..$$ make for impossible sync patterns
396071d4279SBram Moolenaar" (one can't tell if a "$$" starts or stops a math zone by itself)
397071d4279SBram Moolenaar" The following grouptheres coupled with minlines above
398071d4279SBram Moolenaar" help improve the odds of good syncing.
399071d4279SBram Moolenaarif !exists("tex_no_math")
400071d4279SBram Moolenaar syn sync match texSyncMathZoneA		groupthere NONE		"\\end{abstract}"
401071d4279SBram Moolenaar syn sync match texSyncMathZoneA		groupthere NONE		"\\end{center}"
402071d4279SBram Moolenaar syn sync match texSyncMathZoneA		groupthere NONE		"\\end{description}"
403071d4279SBram Moolenaar syn sync match texSyncMathZoneA		groupthere NONE		"\\end{enumerate}"
404071d4279SBram Moolenaar syn sync match texSyncMathZoneA		groupthere NONE		"\\end{itemize}"
405071d4279SBram Moolenaar syn sync match texSyncMathZoneA		groupthere NONE		"\\end{table}"
406071d4279SBram Moolenaar syn sync match texSyncMathZoneA		groupthere NONE		"\\end{tabular}"
407071d4279SBram Moolenaar syn sync match texSyncMathZoneA		groupthere NONE		"\\\(sub\)*section\>"
408071d4279SBram Moolenaarendif
409071d4279SBram Moolenaar
410071d4279SBram Moolenaar" Highlighting: {{{1
411071d4279SBram Moolenaarif did_tex_syntax_inits == 1
412071d4279SBram Moolenaar let did_tex_syntax_inits= 2
413071d4279SBram Moolenaar  " TeX highlighting groups which should share similar highlighting
414071d4279SBram Moolenaar  if !exists("g:tex_no_error")
415071d4279SBram Moolenaar   if !exists("tex_no_math")
416071d4279SBram Moolenaar    HiLink texBadMath		texError
417071d4279SBram Moolenaar    HiLink texMathDelimBad	texError
418071d4279SBram Moolenaar    HiLink texMathError		texError
419071d4279SBram Moolenaar    if !b:tex_stylish
420071d4279SBram Moolenaar      HiLink texOnlyMath	texError
421071d4279SBram Moolenaar    endif
422071d4279SBram Moolenaar   endif
423071d4279SBram Moolenaar   HiLink texError		Error
424071d4279SBram Moolenaar  endif
425071d4279SBram Moolenaar
426071d4279SBram Moolenaar  HiLink texDefCmd		texDef
427071d4279SBram Moolenaar  HiLink texDefName		texDef
428071d4279SBram Moolenaar  HiLink texDocType		texCmdName
429071d4279SBram Moolenaar  HiLink texDocTypeArgs		texCmdArgs
430071d4279SBram Moolenaar  HiLink texInputFileOpt	texCmdArgs
431071d4279SBram Moolenaar  HiLink texInputCurlies	texDelimiter
432071d4279SBram Moolenaar  HiLink texLigature		texSpecialChar
433071d4279SBram Moolenaar  if !exists("tex_no_math")
434071d4279SBram Moolenaar   HiLink texMathDelimSet1	texMathDelim
435071d4279SBram Moolenaar   HiLink texMathDelimSet2	texMathDelim
436071d4279SBram Moolenaar   HiLink texMathDelimKey	texMathDelim
437071d4279SBram Moolenaar   HiLink texMathMatcher	texMath
438071d4279SBram Moolenaar   HiLink texMathZoneW		texMath
439071d4279SBram Moolenaar   HiLink texMathZoneX		texMath
440071d4279SBram Moolenaar   HiLink texMathZoneY		texMath
441071d4279SBram Moolenaar   HiLink texMathZoneZ		texMath
442071d4279SBram Moolenaar  endif
443071d4279SBram Moolenaar  HiLink texSectionMarker	texCmdName
444071d4279SBram Moolenaar  HiLink texSectionName		texSection
445071d4279SBram Moolenaar  HiLink texSpaceCode		texStatement
446071d4279SBram Moolenaar  HiLink texTypeSize		texType
447071d4279SBram Moolenaar  HiLink texTypeStyle		texType
448071d4279SBram Moolenaar
449071d4279SBram Moolenaar   " Basic TeX highlighting groups
450071d4279SBram Moolenaar  HiLink texCmdArgs		Number
451071d4279SBram Moolenaar  HiLink texCmdName		Statement
452071d4279SBram Moolenaar  HiLink texComment		Comment
453071d4279SBram Moolenaar  HiLink texDef			Statement
454071d4279SBram Moolenaar  HiLink texDefParm		Special
455071d4279SBram Moolenaar  HiLink texDelimiter		Delimiter
456071d4279SBram Moolenaar  HiLink texInput		Special
457071d4279SBram Moolenaar  HiLink texInputFile		Special
458071d4279SBram Moolenaar  HiLink texLength		Number
459071d4279SBram Moolenaar  HiLink texMath		Special
460071d4279SBram Moolenaar  HiLink texMathDelim		Statement
461071d4279SBram Moolenaar  HiLink texMathOper		Operator
462071d4279SBram Moolenaar  HiLink texNewCmd		Statement
463071d4279SBram Moolenaar  HiLink texNewEnv		Statement
464071d4279SBram Moolenaar  HiLink texOption		Number
465071d4279SBram Moolenaar  HiLink texRefZone		Special
466071d4279SBram Moolenaar  HiLink texSection		PreCondit
467071d4279SBram Moolenaar  HiLink texSpaceCodeChar	Special
468071d4279SBram Moolenaar  HiLink texSpecialChar		SpecialChar
469071d4279SBram Moolenaar  HiLink texStatement		Statement
470071d4279SBram Moolenaar  HiLink texString		String
471071d4279SBram Moolenaar  HiLink texTodo		Todo
472071d4279SBram Moolenaar  HiLink texType		Type
473071d4279SBram Moolenaar  HiLink texZone		PreCondit
474071d4279SBram Moolenaar
475071d4279SBram Moolenaar  delcommand HiLink
476071d4279SBram Moolenaarendif
477071d4279SBram Moolenaar
478071d4279SBram Moolenaar" Current Syntax: {{{1
479071d4279SBram Moolenaarunlet b:extfname
480071d4279SBram Moolenaarlet   b:current_syntax = "tex"
481071d4279SBram Moolenaar" vim: ts=8 fdm=marker
482