summaryrefslogtreecommitdiffstats
path: root/kate/data/latex.xml
blob: f138b53d939e8a6dae2ea53bb8b326fc47bcdb60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<language name="LaTeX" version="1.47" section="Markup" kateversion="2.3" priority="10" extensions="*.tex;*.ltx;*.dtx;*.sty;*.cls;*.bbx;*.cbx;*.lbx;" mimetype="text/x-tex" casesensitive="1" author="Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net)+Holger Danielsson (holger.danielsson@versanet.de)+Michel Ludwig (michel.ludwig@kdemail.net)+Thomas Braun (thomas.braun@virtuell-zuhause.de)" license="LGPL" >
  <highlighting>
    <contexts>
      <!-- Normal text -->
      <context name="Normal Text" attribute="Normal Text" lineEndContext="#stay">
        <RegExpr String="\\begin(?=[^a-zA-Z])" attribute="Structure" context="FindBeginEnvironment" beginRegion="block" />
        <RegExpr String="\\end(?=[^a-zA-Z])" attribute="Structure" context="FindEndEnvironment" />
	<RegExpr String="\\(cite|parencite|autocite|Autocite|citetitle)\*(?=[^a-zA-Z])" attribute="Structure" context="Label"/>
	<RegExpr String="\\(cites|Cites|parencites|Parencites|autocites|Autocites|supercites|footcites|Footcites)(?=[^a-zA-Z])" attribute="Structure" context="FancyLabel"/>
	<RegExpr String="\\(cite|nocite|Cite|parencite|Parencite|footcite|Footcite|textcite|Textcite|supercite|autocite|Autocite|citeauthor|Citeauthor|citetitle|citeyear|citeurl|nocite|fullcite|footfullcite)(?=[^a-zA-Z])" attribute="Structure" context="Label"/>
	<RegExpr String="\\(subref\*?|cref\*?|label|pageref|autoref|ref|vpageref|vref|pagecite|eqref)(?=[^a-zA-Z])" attribute="Structure" context="Label"/>
        <RegExpr String="\\(part|chapter|section|subsection|subsubsection|paragraph|subparagraph)\*?\s*(?=[\{\[])" attribute="Structure" context="Sectioning"/>
        <RegExpr String="\\(footnote)\*?\s*(?=[\{\[])" attribute="Keyword" context="Footnoting"/>
	<RegExpr String="\\(renewcommand|providenewcommand|newcommand)\*?(?=[^a-zA-Z])" attribute="Keyword" context="NewCommand"/>
        <RegExpr String="\\(e|g|x)?def(?=[^a-zA-Z])" attribute="Keyword" context="DefCommand"/>
	<RegExpr String="&lt;&lt;.*&gt;&gt;=" attribute="Normal Text" context="NoWeb" />
        <StringDetect String="\(" attribute="Math" context="MathMode" />
        <StringDetect String="\[" attribute="Math" context="MathModeEquation" beginRegion="mathMode" />
	<StringDetect String="\iffalse" attribute="Comment" context="Multiline Comment"/>
	<StringDetect String="\ensuremath{" attribute="Math" context="MathModeEnsure"/>
        <DetectChar char="\" attribute="Keyword" context="ContrSeq"/>
        <StringDetect String="$$" attribute="Math" context="MathModeDisplay" beginRegion="mathMode" />
        <DetectChar char="$" attribute="Math" context="MathMode" />
        <RegExpr String="%\s*BEGIN.*$" attribute="Region Marker" context="#stay" beginRegion="regionMarker" firstNonSpace="true" />
        <RegExpr String="%\s*END.*$" attribute="Region Marker" context="#stay" endRegion="regionMarker" firstNonSpace="true" />
        <DetectChar char="%" attribute="Comment" context="Comment"/>
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
      </context>

	<!-- NoWeb -->
      <context name="NoWeb" attribute="Normal Text" lineEndContext="#stay" >
	<RegExpr String="^\s*@\s*" attribute="Normal Text" context="#pop" />
      </context>

      <!-- LaTeX sectioning commands -->
      <context name="Sectioning" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
        <RegExpr String="\[[^\]]*\]" attribute="Normal Text" context="#stay"/>
        <DetectChar char=" " attribute="Normal Text" context="#stay"/>
        <DetectChar char="{" attribute="Normal Text" context="SectioningInside"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop"/>
        <DetectChar char="%" attribute="Comment" context="Comment"/>
      </context>
      <context name="SectioningInside" attribute="Structure Text" lineEndContext="#stay">
        <DetectChar char="{" attribute="Normal Text" context="SectioningInside"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop"/>
        <StringDetect String="\(" attribute="Structure Math" context="SectioningMathMode" />
        <DetectChar char="\" attribute="Structure Keyword" context="SectioningContrSeq"/>
        <DetectChar char="$" attribute="Structure Math" context="SectioningMathMode" />
        <DetectChar char="%" attribute="Comment" context="Comment"/>
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
      </context>
      <context name="SectioningContrSeq" attribute="Keyword" lineEndContext="#pop">
         <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="[a-zA-Z]+(\+?|\*{0,3})" attribute="Structure Keyword" context="#pop"/>
        <RegExpr String="[^a-zA-Z]" attribute="Structure Keyword" context="#pop" />
      </context>
      <context name="SectioningMathMode" attribute="Structure Math" lineEndContext="#stay">
        <StringDetect String="$$" attribute="Error" context="#stay" />
        <DetectChar char="$" attribute="Structure Math" context="#pop" />
        <Detect2Chars char="\" char1=")" attribute="Structure Math" context="#pop" />
        <Detect2Chars char="\" char1="]" attribute="Error" context="#stay" />
        <DetectChar char="\" attribute="Structure Keyword Mathmode" context="SectioningMathContrSeq"/>
        <DetectChar char="%" attribute="Comment" context="Comment"/>
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
      </context>
      <context name="SectioningMathContrSeq" attribute="Structure Keyword Mathmode" lineEndContext="#pop">
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="[a-zA-Z]+\*?" attribute="Structure Keyword Mathmode" context="#pop"/>
        <RegExpr String="[^a-zA-Z]" attribute="Structure Keyword Mathmode" context="#pop" /> 
      </context>

      <!-- LaTeX Footnote commands -->
      <context name="Footnoting" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
        <RegExpr String="\[[^\]]*\]" attribute="Normal Text" context="#stay"/>
        <DetectChar char=" " attribute="Normal Text" context="#stay"/>
        <DetectChar char="{" attribute="Normal Text" context="FootnotingInside"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop"/>
        <DetectChar char="%" attribute="Comment" context="Comment"/>
      </context>
      <context name="FootnotingInside" attribute="Normal Text" lineEndContext="#stay">
        <DetectChar char="{" attribute="Normal Text" context="FootnotingInside"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop"/>
        <StringDetect String="\(" attribute="Math" context="FootnotingMathMode" />
        <DetectChar char="$" attribute="Math" context="FootnotingMathMode" />
        <IncludeRules context="Normal Text" />
      </context>
      <context name="FootnotingMathMode" attribute="Math" lineEndContext="#stay">
        <StringDetect String="$$" attribute="Error" context="#stay" />
        <DetectChar char="$" attribute="Math" context="#pop" />
        <Detect2Chars char="\" char1=")" attribute="Math" context="#pop" />
        <Detect2Chars char="\" char1="]" attribute="Error" context="#stay" />
        <IncludeRules context="MathMode" />
      </context>

      <!-- LaTeX commands \newcommand and \renewcommand -->
      <context name="NewCommand" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
        <RegExpr String="\s*\{\s*\\[a-zA-Z]+\s*\}(\[\d\](\[[^\]]*\])?)?\{" attribute="Normal Text" context="CommandParameterStart"/>
        <DetectChar char="}" attribute="Error" context="#pop"/>
      </context>

      <!-- LaTeX command \def -->
      <context name="DefCommand" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
        <RegExpr String="\s*\\[a-zA-Z]+[^\{]*\{" attribute="Normal Text" context="CommandParameterStart"/>
        <DetectChar char="}" attribute="Error" context="#pop"/>
      </context>

      <!-- parse command argument -->
      <context name="CommandParameterStart" attribute="Normal Text" lineEndContext="#stay">
        <DetectChar char="{" attribute="Normal Text" context="CommandParameter"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop#pop"/>
        <RegExpr String="\\." attribute="Normal Text" context="#stay" />
        <DetectChar char="%" attribute="Comment" context="Comment"/>
      </context>
      <context name="CommandParameter" attribute="Normal Text" lineEndContext="#stay">
        <DetectChar char="{" attribute="Normal Text" context="CommandParameter"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop"/>
        <RegExpr String="\\." attribute="Normal Text" context="#stay" />
        <DetectChar char="%" attribute="Comment" context="Comment"/>
      </context>

      <!-- LaTeX command in text mode -->
      <context name="ContrSeq" attribute="Keyword" lineEndContext="#pop">
        <StringDetect String="verb*" attribute="Keyword" context="Verb"/>
        <RegExpr String="(Verb|verb|lstinline)(?=[^a-zA-Z])" attribute="Keyword" context="Verb"/>
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="[a-zA-Z@]+(\+?|\*{0,3})" attribute="Keyword" context="#pop"/>
        <RegExpr String="[^a-zA-Z]" attribute="Keyword" context="#pop" />
      </context>
      <context name="ToEndOfLine" attribute="Normal Text" lineEndContext="#pop">
      </context>

      <!-- verb command -->
      <context name="Verb" attribute="Verbatim" lineEndContext="#pop#pop" >
        <RegExpr String="(.)" attribute="Normal Text" dynamic="true" context="VerbEnd" />
      </context>
      <context name="VerbEnd" attribute="Verbatim" lineEndContext="#pop#pop#pop" dynamic="true" >
        <StringDetect String="%1" attribute="Normal Text" context="#pop#pop#pop" dynamic="true" />
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="[^%1\xd7]*" attribute="Verbatim" context="#stay" dynamic="true" />
      </context>

      <!-- label -->
      <context name="Label" attribute="Normal Text" lineEndContext="#stay">
        <RegExpr String="\s*\{\s*" attribute="Normal Text" context="LabelParameter"/>
        <RegExpr String="\s*\[\s*" attribute="Normal Text" context="LabelOption"/>
        <RegExpr String="[^\[\{]+" attribute="Error" context="#stay"/>
      </context>

      <context name="LabelOption" attribute="Normal Text" lineEndContext="#stay">
        <StringDetect String="\(" attribute="Math" context="MathMode" />
        <DetectChar char="\" attribute="Keyword" context="ContrSeq"/>
        <DetectChar char="$" attribute="Math" context="MathMode" />
        <DetectChar char="%" attribute="Comment" context="Comment"/>
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="\s*\]\s*" attribute="Normal Text" context="#pop"/>
      </context>

      <context name="LabelParameter" attribute="Environment" lineEndContext="#stay">
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="\s*\}\s*" attribute="Normal Text" context="#pop#pop"/>
      </context>

      <!-- labels from biblatex commands -->
      <context name="FancyLabel" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop">
	      <RegExpr String="\s*\{\s*" attribute="Normal Text" context="FancyLabelParameter"/>
	      <RegExpr String="\s*\[\s*" attribute="Normal Text" context="LabelOption"/>
	      <RegExpr String="\s*\(\s*" attribute="Normal Text" context="FancyLabelRoundBrackets"/>
      </context>

      <context name="FancyLabelParameter" attribute="Environment" lineEndContext="#stay">
	      <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
	      <RegExpr String="\s*\}\s*" attribute="Normal Text" context="#pop"/>
      </context>

      <context name="FancyLabelRoundBrackets" attribute="Normal Text" lineEndContext="#stay">
	      <StringDetect String="\(" attribute="Math" context="MathMode" />
	      <DetectChar char="\" attribute="Keyword" context="ContrSeq"/>
	      <DetectChar char="$" attribute="Math" context="MathMode" />
	      <DetectChar char="%" attribute="Comment" context="Comment"/>
	      <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
	      <RegExpr String="\s*\)\s*" attribute="Normal Text" context="#pop"/>
      </context>

      <!-- end of an environment -->
      <context name="FindEndEnvironment" attribute="Normal Text" lineEndContext="#stay">
        <DetectChar char="{" attribute="Normal Text" context="EndEnvironment"/>
        <RegExpr String="\S" attribute="Normal Text" context="#pop"/>
      </context>

      <context name="EndEnvironment" attribute="Environment" lineEndContext="#stay">
        <RegExpr String="[a-zA-Z]" attribute="Environment" context="EndLatexEnv"/>
        <RegExpr String="\s+" attribute="Error" context="#pop"/>
        <RegExpr String="[^a-zA-Z]" attribute="Error" context="#pop"/>
      </context>

       <context name="EndLatexEnv" attribute="Environment" lineEndContext="#stay">
        <DetectChar char="}" attribute="Normal Text" endRegion="block" context="#pop#pop#pop"/>
        <RegExpr String="[a-zA-Z]+(\*)?" attribute="Environment" context="#stay"/>
        <RegExpr String="\s+" attribute="Error" context="#stay"/>
        <RegExpr String="[a-zA-Z]" attribute="Error" context="#pop#pop#pop"/>
      </context>

      <!-- start of an environment -->
      <context name="FindBeginEnvironment" attribute="Normal Text" lineEndContext="#stay">
        <DetectChar char="{" attribute="Normal Text" context="BeginEnvironment"/>
        <RegExpr String="\S" attribute="Normal Text" context="#pop"/>
      </context>

      <!-- filter the environment name and check the type -->
      <context name="BeginEnvironment" attribute="Environment" lineEndContext="#stay">
        <RegExpr String="(lstlisting|(B|L)?Verbatim)" attribute="Environment" context="VerbatimEnvParam"/>
        <RegExpr String="(verbatim|boxedverbatim)" attribute="Environment" context="VerbatimEnv"/>
        <RegExpr String="comment" attribute="Environment" context="CommentEnv"/>
        <RegExpr String="(alignat|xalignat|xxalignat)" attribute="Environment" context="MathEnvParam"/>
        <RegExpr String="(equation|displaymath|eqnarray|subeqnarray|math|multline|gather|align|flalign|IEEEeqnarray|IEEEeqnarraybox|smallmatrix|pmatrix|bmatrix|Bmatrix|vmatrix|Vmatrix)" attribute="Environment" context="MathEnv"/>
        <RegExpr String="(tabularx|tabular|supertabular|mpsupertabular|xtabular|mpxtabular|longtable)" attribute="Environment" context="TabEnv"/>
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="[a-zA-Z]" attribute="Environment" context="LatexEnv"/>
        <RegExpr String="\s+" attribute="Error" context="#pop"/>
        <RegExpr String="[^a-zA-Z\xd7]" attribute="Error" context="#pop"/>
      </context>

      <!-- environment type 1: normal -->
      <context name="LatexEnv" attribute="Environment" lineEndContext="#stay">
        <DetectChar char="}" attribute="Normal Text" context="#pop#pop#pop"/>
        <RegExpr String="[a-zA-Z]+" attribute="Environment" context="#stay"/>
        <RegExpr String="\s+" attribute="Error" context="#stay"/>
       <IncludeRules context="EnvCommon" />
      </context>

      <!-- environment type 2: verbatim without parameter -->
      <context name="VerbatimEnv" attribute="Environment" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop#pop#pop">
        <DetectChar char="}" attribute="Normal Text" context="Verbatim"/>
        <RegExpr String="[a-zA-Z]" attribute="Environment" lookAhead="true" context="#pop"/>
        <IncludeRules context="EnvCommon" />
       </context>

      <!-- environment type 3: verbatim with optional parameter -->
      <context name="VerbatimEnvParam" attribute="Normal Text" lineEndContext="#stay">
        <Detect2Chars char="}" char1="[" attribute="Normal Text" context="#stay" />
        <DetectChar char="}" attribute="Normal Text" context="Verbatim"/>
        <DetectChar char="]" attribute="Normal Text" context="Verbatim"/>
      </context>

      <!-- parse verbatim text -->
      <context name="Verbatim" attribute="Verbatim" lineEndContext="#stay">
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="\\end(?=\s*\{(verbatim|lstlisting|boxedverbatim|(B|L)?Verbatim)\*?\})" attribute="Structure"  context="VerbFindEnd"/>
      </context>

      <!-- end of verbatim environment -->
      <context name="VerbFindEnd" attribute="Normal Text" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
        <RegExpr String="\s*\{" attribute="Normal Text" context="#stay"/>
        <RegExpr String="(verbatim|lstlisting|boxedverbatim|(B|L)?Verbatim)\*?" attribute="Environment" context="#stay"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop#pop#pop#pop#pop" endRegion="block"/>
      </context>

      <!-- begin comment environment  -->
      <context name="CommentEnv" attribute="Environment" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop#pop#pop">
        <DetectChar char="}" attribute="Normal Text" context="BlockComment"/>
        <RegExpr String="[a-zA-Z]" attribute="Environment" lookAhead="true" context="#pop"/>
        <IncludeRules context="EnvCommon" />
       </context>

      <!-- parse comment text -->
      <context name="BlockComment" attribute="Comment" lineEndContext="#stay">
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="\\end(?=\s*\{comment\*?\})" attribute="Structure" context="CommFindEnd"/>
      </context>

      <!-- end of comment environment -->
      <context name="CommFindEnd" attribute="Normal Text" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
        <RegExpr String="\s*\{" attribute="Normal Text" context="#stay"/>
        <RegExpr String="comment\*?" attribute="Environment" context="#stay"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop#pop#pop#pop#pop" endRegion="block"/>
      </context>

      <!-- environment type 4: math environment with its own mathmode -->
      <context name="MathEnv" attribute="Environment" lineEndContext="#stay">
        <DetectChar char="}" attribute="Normal Text" context="MathModeEnv"/>
        <RegExpr String="[a-zA-Z]" attribute="Environment" lookAhead="true" context="#pop"/>
        <IncludeRules context="EnvCommon" />
      </context>

      <!-- environment type 5: math environment with its own mathmode and parameter -->
      <context name="MathEnvParam" attribute="Normal Text" lineEndContext="#stay">
        <RegExpr String="\}\{[^\}]*\}" attribute="Normal Text" context="MathModeEnv"/>
        <DetectChar char="}" attribute="Normal Text" context="MathModeEnv"/>
        <RegExpr String="[a-zA-Z]" attribute="Environment" lookAhead="true" context="#pop"/>
        <IncludeRules context="EnvCommon" />
      </context>

      <!-- environment common -->
      <context name="EnvCommon" attribute="Environment" lineEndContext="#stay">
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="\*(?=\})" attribute="Environment" context="#stay"/>
        <RegExpr String="\*[^\}]*" attribute="Error" context="#pop#pop#pop"/>
        <RegExpr String="[^a-zA-Z\xd7][^\}]*" attribute="Error" context="#pop#pop#pop"/>
      </context>

      <!-- parse math environment -->
      <context name="MathModeEnv" attribute="Math" lineEndContext="#stay">
	<RegExpr String="\\begin(?=[^a-zA-Z])" attribute="Structure" context="FindBeginEnvironment" beginRegion="block"/>
	<RegExpr String="\\end(?=[^a-zA-Z])" attribute="Structure" context="MathFindEnd"/>
        <StringDetect String="\(" attribute="Error" context="#stay" />
        <StringDetect String="\[" attribute="Error" context="#stay" />
        <StringDetect String="\)" attribute="Error" context="#stay" />
        <StringDetect String="\]" attribute="Error" context="#stay" />
        <RegExpr String="\\(text|intertext|mbox)\s*(?=\{)" attribute="Keyword Mathmode" context="MathModeText" />
        <DetectChar char="\" attribute="Keyword Mathmode" context="MathContrSeq"/>
        <StringDetect String="$$" attribute="Error" context="#stay" />
        <DetectChar char="$" attribute="Error" context="#stay" />
        <DetectChar char="%" attribute="Comment" context="Comment"/>
	<DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="%\s*BEGIN.*$" attribute="Region Marker" context="#stay" beginRegion="regionMarker" firstNonSpace="true"/>
        <RegExpr String="%\s*END.*$" attribute="Region Marker" context="#stay" endRegion="regionMarker" firstNonSpace="true"/>
      </context>

      <!-- end of math environment -->
      <context name="MathFindEnd" attribute="Normal Text" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
        <RegExpr String="\s*\{" attribute="Normal Text" context="#stay"/>
        <RegExpr String="(equation|displaymath|eqnarray|subeqnarray|math|multline|gather|align|flalign|alignat|xalignat|xxalignat|IEEEeqnarray|IEEEeqnarraybox|smallmatrix|pmatrix|bmatrix|Bmatrix|vmatrix|Vmatrix)\*?" attribute="Environment" context="#stay"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop#pop#pop#pop#pop"  endRegion="block"/>
      </context>

          <!-- environment type 9: tabular -->
      <context name="TabEnv" attribute="Environment" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop#pop#pop">
        <DetectChar char="}" attribute="Normal Text" context="Tab"/>
        <RegExpr String="[a-zA-Z]" attribute="Environment" lookAhead="true" context="#pop"/>
        <IncludeRules context="EnvCommon" />
       </context>

      <!-- parse tabular text -->
      <context name="Tab" attribute="Tab" lineEndContext="#stay">
	<DetectChar char="&amp;" attribute="Ampersand" context="#stay"/>
	<StringDetect String="@{" attribute="Column Separator" context="Column Separator"/>
        <RegExpr String="\\end(?=\s*\{(tabularx|tabular|supertabular|mpsupertabular|xtabular|mpxtabular|longtable)\*?\})" attribute="Structure"  context="TabFindEnd"/>
	<IncludeRules context="Normal Text" />
      </context>
      
      <context name="Column Separator" attribute="Column Separator" lineEndContext="#stay">
	      <DetectChar char="{" attribute="Column Separator" context="Column Separator"/>
	      <DetectChar char="}" attribute="Column Separator" context="#pop"/>
	      <RegExpr String="." attribute="Column Separator"  context="#stay"/> 
<!-- 	 the last regexp is very stupid. Suggestions are welcome! Fallthrough did not help-->
      </context>

      <!-- end of tabular environment -->
      <context name="TabFindEnd" attribute="Normal Text" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
        <RegExpr String="\s*\{" attribute="Normal Text" context="#stay"/>
        <RegExpr String="(tabularx|tabular|supertabular|mpsupertabular|xtabular|mpxtabular|longtable)\*?" attribute="Environment" context="#stay"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop#pop#pop#pop#pop" endRegion="block"/>
      </context>

      <!-- math mode: starting with $ or \( -->
      <context name="MathMode" attribute="Math" lineEndContext="#stay">
        <StringDetect String="$$" attribute="Error" context="#stay" />
        <DetectChar char="$" attribute="Math" context="#pop" />
        <Detect2Chars char="\" char1=")" attribute="Math" context="#pop" />
        <Detect2Chars char="\" char1="]" attribute="Error" context="#stay" />
        <IncludeRules context="MathModeCommon" />
      </context>

      <!-- math mode: starting with $$ -->
      <context name="MathModeDisplay" attribute="Math" lineEndContext="#stay">
        <StringDetect String="$$" attribute="Math" context="#pop" endRegion="mathMode" />
        <DetectChar char="$" attribute="Error" context="#stay" />
        <Detect2Chars char="\" char1="]" attribute="Error" context="#stay" />
        <Detect2Chars char="\" char1=")" attribute="Error" context="#stay" />
        <IncludeRules context="MathModeCommon" />
      </context>

      <!-- math mode: starting with \[ -->
      <context name="MathModeEquation" attribute="Math" lineEndContext="#stay">
        <Detect2Chars char="\" char1="]" attribute="Math" context="#pop" endRegion="mathMode" />
        <StringDetect String="$$" attribute="Error" context="#stay" />
        <DetectChar char="$" attribute="Error" context="#stay" />
        <Detect2Chars char="\" char1=")" attribute="Error" context="#stay" />
        <IncludeRules context="MathModeCommon" />
      </context>

      <!-- math mode: \ensuremath{...} !-->
      <context name="MathModeEnsure" attribute="Math" lineEndContext="#stay">
	      <DetectChar char="{" attribute="Math" context="MathModeEnsure" />
	      <DetectChar char="}" attribute="Math" context="#pop" />
	      <IncludeRules context="MathModeCommon" />
      </context>

      <!-- math mode common -->
      <context name="MathModeCommon" attribute="Math" lineEndContext="#stay">
        <RegExpr String="\\(begin|end)\s*\{(equation|displaymath|eqnarray|subeqnarray|math|multline|gather|align|flalign|alignat|xalignat|xxalignat|IEEEeqnarray)\*?\}" attribute="Error" context="#stay"/>
	<RegExpr String="\\begin(?=[^a-zA-Z])" attribute="Keyword Mathmode" context="#stay" beginRegion="block" />
	<RegExpr String="\\end(?=[^a-zA-Z])" attribute="Keyword Mathmode" context="#stay" endRegion="block" />
        <RegExpr String="\\(text|intertext|mbox)\s*(?=\{)" attribute="Keyword Mathmode" context="MathModeText" />
        <DetectChar char="\" attribute="Keyword Mathmode" context="MathContrSeq"/>
        <DetectChar char="%" attribute="Comment" context="Comment"/>
        <RegExpr String="%\s*BEGIN.*$" attribute="Region Marker" context="#stay" beginRegion="regionMarker" firstNonSpace="true"/>
        <RegExpr String="%\s*END.*$" attribute="Region Marker" context="#stay" endRegion="regionMarker" firstNonSpace="true"/>
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
      </context>

      <!-- command in mathmode -->
      <context name="MathContrSeq" attribute="Keyword Mathmode" lineEndContext="#pop">
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <RegExpr String="[a-zA-Z]+\*?" attribute="Keyword Mathmode" context="#pop"/>
        <RegExpr String="[^a-zA-Z]" attribute="Keyword Mathmode" context="#pop" /> 
      </context>

      <!-- text in mathmode -->
      <context name="MathModeText" attribute="Normal Text" lineEndContext="#stay" >
         <DetectChar char="{" attribute="Normal Text" context="MathModeTextParameterStart"/>
      </context>

      <context name="MathModeTextParameterStart" attribute="Normal Text" lineEndContext="#stay" >
        <RegExpr String="\\." attribute="Normal Text" context="#stay"/> 
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
	<RegExpr String="\$.*\$" minimal="true" attribute="Math" context="#stay"/>
        <DetectChar char="{" attribute="Normal Text" context="MathModeTextParameter"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop#pop"/>
        <DetectChar char="%" attribute="Comment" context="Comment"/>
      </context>

      <context name="MathModeTextParameter" attribute="Normal Text" lineEndContext="#stay" >
        <RegExpr String="\\." attribute="Normal Text" context="#stay"/> 
        <DetectChar char="{" attribute="Normal Text" context="MathModeTextParameter"/>
        <DetectChar char="}" attribute="Normal Text" context="#pop"/>
        <DetectChar char="&#xd7;" attribute="Bullet" context="#stay"/>
        <DetectChar char="%" attribute="Comment" context="Comment"/>
      </context>

     <!--    iffalse aka multiline comment    -->
	<context name="Multiline Comment" attribute="Comment" lineEndContext="#stay">
		<StringDetect String="\fi" attribute="Comment" context="#pop"/>
		<StringDetect String="\else" attribute="Comment" context="#pop"/>
	</context>

     <!-- comment -->
      <context name="Comment" attribute="Comment" lineEndContext="#pop">
      	<RegExpr String="(FIXME|TODO):?" attribute="Alert" context="#stay"/>
	<StringDetect String="\KileResetHL" attribute="Comment" context="Normal Text"/>
	<StringDetect String="\KateResetHL" attribute="Comment" context="Normal Text"/>
      </context>
    </contexts>

    <itemDatas>
      <itemData name="Normal Text" defStyleNum="dsNormal"/>
      <itemData name="Keyword" defStyleNum="dsNormal" color="#800000" selColor="#60FFFF" bold="0" italic="0" spellChecking="false"/>
      <itemData name="Comment" defStyleNum="dsComment"/>
      <itemData name="Error" defStyleNum="dsAlert" spellChecking="false"/>
      <itemData name="Math" defStyleNum="dsNormal" color="#00A000" selColor="#FF40FF"  bold="0" italic="0" spellChecking="false"/>
      <itemData name="Structure" defStyleNum="dsNormal" color="#F00000" selColor="#80FFD0" bold="0" italic="0" spellChecking="false"/>
      <itemData name="Keyword Mathmode" defStyleNum="dsNormal" color="#606000" selColor="#FFD0FF" bold="0" italic="0" spellChecking="false"/>
      <itemData name="Environment" defStyleNum="dsNormal" color="#0000D0" selColor="#FFFF90" bold="0" italic="0" spellChecking="false"/>
      <itemData name="Verbatim" defStyleNum="dsNormal" color="#a08000" selColor="#80D0FF" bold="0" italic="0" spellChecking="false"/>
      <itemData name="Region Marker" defStyleNum="dsRegionMarker" spellChecking="false"/>
      <itemData name="Bullet" defStyleNum="dsNormal" color="#FF00C4" bold="1" underline="1" spellChecking="false"/>
      <itemData name="Ampersand" defStyleNum="dsNormal" color="#002793" bold="1" spellChecking="false"/>
      <itemData name="Column Separator" defStyleNum="dsNormal" color="#002793" spellChecking="false"/>
      <itemData name="Alert" defStyleNum="dsAlert" spellChecking="false"/>
      <itemData name="Structure Text" defStyleNum="dsNormal" color="#000000" selColor="#FFFFFF" bold="1" italic="0"/>
      <itemData name="Structure Keyword" defStyleNum="dsNormal" color="#800000" selColor="#60FFFF" bold="1" italic="0" spellChecking="false"/>
      <itemData name="Structure Math" defStyleNum="dsNormal" color="#00A000" selColor="#FF40FF"  bold="1" italic="0"/>
      <itemData name="Structure Keyword Mathmode" defStyleNum="dsNormal" color="#606000" selColor="#FFD0FF" bold="1" italic="0" spellChecking="false"/>
    </itemDatas>
  </highlighting>

  <general>
    <keywords weakDeliminator="\" wordWrapDeliminator=",{}[]"/>
    <comments>
      <comment name="singleLine" start="%" />
    </comments>
  </general>

  <spellchecking>
    <configuration encodingReplacementPolicy="EncodeWhenPresent"/>
    <encodings>
      <encoding char="&#192;" string="\`{A}" />
      <encoding char="&#192;" string="\`A" />
      <encoding char="&#193;" string="\'{A}" />
      <encoding char="&#193;" string="\'A" />
      <encoding char="&#194;" string="\^{A}" />
      <encoding char="&#194;" string="\^A" />
      <encoding char="&#195;" string="\~{A}" />
      <encoding char="&#195;" string="\~A" />
      <encoding char="&#196;" string="\&#34;{A}" />
      <encoding char="&#196;" string="\&#34;A" />
      <encoding char="&#197;" string="\AA{}" />
      <encoding char="&#198;" string="\AE{}" />
      <encoding char="&#199;" string="\c{C}" />
      <encoding char="&#200;" string="\`{E}" />
      <encoding char="&#200;" string="\`E" />
      <encoding char="&#201;" string="\'{E}" />
      <encoding char="&#201;" string="\'E" />
      <encoding char="&#202;" string="\^{E}" />
      <encoding char="&#202;" string="\^E" />
      <encoding char="&#203;" string="\&#34;{E}" />
      <encoding char="&#203;" string="\&#34;E" />
      <encoding char="&#204;" string="\`{I}" />
      <encoding char="&#204;" string="\`I" />
      <encoding char="&#205;" string="\'{I}" />
      <encoding char="&#205;" string="\'I" />
      <encoding char="&#206;" string="\^{I}" />
      <encoding char="&#206;" string="\^I" />
      <encoding char="&#207;" string="\&#34;{I}" />
      <encoding char="&#207;" string="\&#34;I" />
      <encoding char="&#208;" string="\DH{}" />
      <encoding char="&#209;" string="\~{N}" />
      <encoding char="&#209;" string="\~N" />
      <encoding char="&#210;" string="\`{O}" />
      <encoding char="&#210;" string="\`O" />
      <encoding char="&#211;" string="\'{O}" />
      <encoding char="&#211;" string="\'O" />
      <encoding char="&#212;" string="\^{O}" />
      <encoding char="&#212;" string="\^O" />
      <encoding char="&#213;" string="\~{O}" />
      <encoding char="&#213;" string="\~O" />
      <encoding char="&#214;" string="\&#34;{O}" />
      <encoding char="&#214;" string="\&#34;O" />
      <encoding char="&#216;" string="\O{}" />
      <encoding char="&#217;" string="\`{U}" />
      <encoding char="&#217;" string="\`U" />
      <encoding char="&#218;" string="\'{U}" />
      <encoding char="&#218;" string="\'U" />
      <encoding char="&#219;" string="\^{U}" />
      <encoding char="&#219;" string="\^U" />
      <encoding char="&#220;" string="\&#34;{U}" />
      <encoding char="&#220;" string="\&#34;U" />
      <encoding char="&#221;" string="\'{Y}" />
      <encoding char="&#221;" string="\'Y" />
      <encoding char="&#222;" string="\TH{}" />
      <encoding char="&#223;" string="\ss{}" />
      <encoding char="&#224;" string="\`{a}" />
      <encoding char="&#224;" string="\`a" />
      <encoding char="&#225;" string="\'{a}" />
      <encoding char="&#225;" string="\'a" />
      <encoding char="&#226;" string="\^{a}" />
      <encoding char="&#226;" string="\^a" />
      <encoding char="&#227;" string="\~{a}" />
      <encoding char="&#227;" string="\~a" />
      <encoding char="&#228;" string="\&#34;{a}" />
      <encoding char="&#228;" string="\&#34;a" />
      <encoding char="&#229;" string="\aa{}" />
      <encoding char="&#230;" string="\ae{}" />
      <encoding char="&#231;" string="\c{c}" />
      <encoding char="&#232;" string="\`{e}" />
      <encoding char="&#232;" string="\`e" />
      <encoding char="&#233;" string="\'{e}" />
      <encoding char="&#233;" string="\'e" />
      <encoding char="&#234;" string="\^{e}" />
      <encoding char="&#234;" string="\^e" />
      <encoding char="&#235;" string="\&#34;{e}" />
      <encoding char="&#235;" string="\&#34;e" />
      <encoding char="&#236;" string="\`{i}" />
      <encoding char="&#236;" string="\`i" />
      <encoding char="&#237;" string="\'{i}" />
      <encoding char="&#237;" string="\'i" />
      <encoding char="&#238;" string="\^{i}" />
      <encoding char="&#238;" string="\^i" />
      <encoding char="&#239;" string="\&#34;{i}" />
      <encoding char="&#239;" string="\&#34;i" />
      <encoding char="&#240;" string="\dh{}" />
      <encoding char="&#241;" string="\~{n}" />
      <encoding char="&#241;" string="\~n" />
      <encoding char="&#242;" string="\`{o}" />
      <encoding char="&#242;" string="\`o" />
      <encoding char="&#243;" string="\'{o}" />
      <encoding char="&#243;" string="\'o" />
      <encoding char="&#244;" string="\^{o}" />
      <encoding char="&#244;" string="\^o" />
      <encoding char="&#245;" string="\~{o}" />
      <encoding char="&#245;" string="\~o" />
      <encoding char="&#246;" string="\&#34;{o}" />
      <encoding char="&#246;" string="\&#34;o" />
      <encoding char="&#248;" string="\o{}" />
      <encoding char="&#249;" string="\`{u}" />
      <encoding char="&#249;" string="\`u" />
      <encoding char="&#250;" string="\'{u}" />
      <encoding char="&#250;" string="\'u" />
      <encoding char="&#251;" string="\^{u}" />
      <encoding char="&#251;" string="\^u" />
      <encoding char="&#252;" string="\&#34;{u}" />
      <encoding char="&#252;" string="\&#34;u" />
      <encoding char="&#253;" string="\'{y}" />
      <encoding char="&#253;" string="\'y" />
      <encoding char="&#254;" string="\th{}" />
      <encoding char="&#255;" string="\&#34;{y}" />
      <encoding char="&#255;" string="\&#34;y" />
      <encoding string="''" ignored="true" />
    </encodings>
  </spellchecking>
</language>