1 # Copyright (c) 2005 - 2006 Hans Jeuken. All rights reserved.
2 # This program is free software; you can redistribute it and/or
3 # modify it under the same terms as Perl itself.
5 # This file was generated from the 'latex.xml' file of the syntax highlight
6 # engine of the kate text editor (http://www.kate-editor.org
10 #kate author Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net)
11 #generated: Sun Feb 3 22:02:05 2008, localtime
13 package Syntax::Highlight::Engine::Kate::LaTeX;
15 our $VERSION = '0.06';
19 use base('Syntax::Highlight::Engine::Kate::Template');
23 my $class = ref($proto) || $proto;
24 my $self = $class->SUPER::new(@_);
26 'Comment' => 'Comment',
27 'Environment' => 'DataType',
28 'Keyword' => 'Keyword',
29 'Keyword Mathmode' => 'Reserved',
31 'Normal Text' => 'Normal',
32 'Region Marker' => 'RegionMarker',
33 'Structure' => 'String',
34 'Verbatim' => 'BString',
38 callback => \&parseComment,
39 attribute => 'Comment',
43 callback => \&parseContrSeq,
44 attribute => 'Keyword',
48 callback => \&parseEnvironment,
49 attribute => 'Environment',
51 'FindEnvironment' => {
52 callback => \&parseFindEnvironment,
53 attribute => 'Normal Text',
56 callback => \&parseLabel,
57 attribute => 'Normal Text',
58 lineending => '#pop#pop',
59 fallthrough => '#pop#pop',
62 callback => \&parseMathContrSeq,
63 attribute => 'Keyword Mathmode',
67 callback => \&parseMathEnv,
68 attribute => 'Environment',
71 callback => \&parseMathFindEnd,
72 attribute => 'Normal Text',
74 fallthrough => '#pop',
77 callback => \&parseMathMode,
81 callback => \&parseMathModeEnv,
85 callback => \&parseNormalText,
86 attribute => 'Normal Text',
89 callback => \&parseToEndOfLine,
90 attribute => 'Normal Text',
94 callback => \&parseVerb,
95 attribute => 'Verbatim',
97 fallthrough => '#pop',
100 callback => \&parseVerbFindEnd,
101 attribute => 'Normal Text',
102 lineending => '#pop',
103 fallthrough => '#pop',
106 callback => \&parseVerbatim,
107 attribute => 'Verbatim',
110 callback => \&parseVerbatimEnv,
111 attribute => 'Environment',
114 $self->deliminators('\\s||\\.|\\(|\\)|:|\\!|\\+|,|-|<|=|>|\\%|\\&|\\*|\\/|;|\\?|\\[|\\]|\\^|\\{|\\||\\}|\\~|\\\\');
115 $self->basecontext('Normal Text');
116 $self->keywordscase(1);
118 bless ($self, $class);
127 my ($self, $text) = @_;
132 my ($self, $text) = @_;
134 # attribute => 'Keyword'
136 # type => 'StringDetect'
137 if ($self->testStringDetect($text, 'verb*', 0, 0, 0, undef, 0, 'Verb', 'Keyword')) {
141 # attribute => 'Keyword'
143 # type => 'StringDetect'
144 if ($self->testStringDetect($text, 'verb', 0, 0, 0, undef, 0, 'Verb', 'Keyword')) {
147 # String => '[a-zA-Z]+'
148 # attribute => 'Keyword'
151 if ($self->testRegExpr($text, '[a-zA-Z]+', 0, 0, 0, undef, 0, '#pop', 'Keyword')) {
154 # String => '[^a-zA-Z]'
155 # attribute => 'Keyword'
158 if ($self->testRegExpr($text, '[^a-zA-Z]', 0, 0, 0, undef, 0, '#pop', 'Keyword')) {
164 sub parseEnvironment {
165 my ($self, $text) = @_;
166 # attribute => 'Normal Text'
168 # context => '#pop#pop'
169 # type => 'DetectChar'
170 if ($self->testDetectChar($text, '}', 0, 0, 0, undef, 0, '#pop#pop', 'Normal Text')) {
173 # attribute => 'Normal Text'
175 # context => '#pop#pop'
176 # type => 'DetectChar'
177 if ($self->testDetectChar($text, ']', 0, 0, 0, undef, 0, '#pop#pop', 'Normal Text')) {
180 # String => '(semiverbatim|verbatim|lstlisting|boxedverbatim|Verbatim)\*?'
181 # attribute => 'Environment'
182 # context => 'VerbatimEnv'
184 if ($self->testRegExpr($text, '(semiverbatim|verbatim|lstlisting|boxedverbatim|Verbatim)\\*?', 0, 0, 0, undef, 0, 'VerbatimEnv', 'Environment')) {
187 # String => '(equation|displaymath|eqnarray|subeqnarray|math|multline|gather|align|alignat|flalign)\*?'
188 # attribute => 'Environment'
189 # context => 'MathEnv'
191 if ($self->testRegExpr($text, '(equation|displaymath|eqnarray|subeqnarray|math|multline|gather|align|alignat|flalign)\\*?', 0, 0, 0, undef, 0, 'MathEnv', 'Environment')) {
197 sub parseFindEnvironment {
198 my ($self, $text) = @_;
199 # attribute => 'Normal Text'
201 # context => 'Environment'
202 # type => 'DetectChar'
203 if ($self->testDetectChar($text, '{', 0, 0, 0, undef, 0, 'Environment', 'Normal Text')) {
207 # attribute => 'Normal Text'
210 if ($self->testRegExpr($text, '\\S', 0, 0, 0, undef, 0, '#pop', 'Normal Text')) {
217 my ($self, $text) = @_;
218 # String => '\s*\{\s*'
219 # attribute => 'Normal Text'
222 if ($self->testRegExpr($text, '\\s*\\{\\s*', 0, 0, 0, undef, 0, '#stay', 'Normal Text')) {
225 # String => '[^\}\{]+'
226 # attribute => 'Environment'
229 if ($self->testRegExpr($text, '[^\\}\\{]+', 0, 0, 0, undef, 0, '#stay', 'Environment')) {
232 # String => '\s*\}\s*'
233 # attribute => 'Normal Text'
236 if ($self->testRegExpr($text, '\\s*\\}\\s*', 0, 0, 0, undef, 0, '#pop', 'Normal Text')) {
242 sub parseMathContrSeq {
243 my ($self, $text) = @_;
244 # String => '[a-zA-Z]+'
245 # attribute => 'Keyword Mathmode'
248 if ($self->testRegExpr($text, '[a-zA-Z]+', 0, 0, 0, undef, 0, '#pop', 'Keyword Mathmode')) {
251 # String => '[^a-zA-Z]'
252 # attribute => 'Keyword Mathmode'
255 if ($self->testRegExpr($text, '[^a-zA-Z]', 0, 0, 0, undef, 0, '#pop', 'Keyword Mathmode')) {
262 my ($self, $text) = @_;
263 # attribute => 'Normal Text'
265 # context => 'MathModeEnv'
266 # type => 'DetectChar'
267 if ($self->testDetectChar($text, '}', 0, 0, 0, undef, 0, 'MathModeEnv', 'Normal Text')) {
271 # attribute => 'Normal Text'
274 if ($self->testRegExpr($text, '\\S', 0, 0, 0, undef, 0, '#pop', 'Normal Text')) {
280 sub parseMathFindEnd {
281 my ($self, $text) = @_;
282 # attribute => 'Normal Text'
285 # type => 'DetectChar'
286 if ($self->testDetectChar($text, '{', 0, 0, 0, undef, 0, '#stay', 'Normal Text')) {
289 # String => '[a-zA-Z]*(equation|displaymath|eqnarray|subeqnarray|math|multline|gather|align|alignat|flalign)\*?'
290 # attribute => 'Environment'
293 if ($self->testRegExpr($text, '[a-zA-Z]*(equation|displaymath|eqnarray|subeqnarray|math|multline|gather|align|alignat|flalign)\\*?', 0, 0, 0, undef, 0, '#stay', 'Environment')) {
296 # type => 'DetectSpaces'
297 if ($self->testDetectSpaces($text, 0, undef, 0, '#stay', undef)) {
300 # attribute => 'Normal Text'
302 # context => '#pop#pop#pop#pop#pop'
303 # endRegion => 'block'
304 # type => 'DetectChar'
305 if ($self->testDetectChar($text, '}', 0, 0, 0, undef, 0, '#pop#pop#pop#pop#pop', 'Normal Text')) {
312 my ($self, $text) = @_;
313 # attribute => 'Math'
317 # endRegion => 'mathMode'
318 # type => 'Detect2Chars'
319 if ($self->testDetect2Chars($text, '\\', ']', 0, 0, 0, undef, 0, '#pop', 'Math')) {
322 # attribute => 'Math'
326 # endRegion => 'mathMode'
327 # type => 'Detect2Chars'
328 if ($self->testDetect2Chars($text, '\\', ')', 0, 0, 0, undef, 0, '#pop', 'Math')) {
331 # String => '\\begin(?=[^a-zA-Z])'
332 # attribute => 'Keyword Mathmode'
333 # beginRegion => 'block'
336 if ($self->testRegExpr($text, '\\\\begin(?=[^a-zA-Z])', 0, 0, 0, undef, 0, '#stay', 'Keyword Mathmode')) {
339 # String => '\\end(?=[^a-zA-Z])'
340 # attribute => 'Keyword Mathmode'
342 # endRegion => 'block'
344 if ($self->testRegExpr($text, '\\\\end(?=[^a-zA-Z])', 0, 0, 0, undef, 0, '#stay', 'Keyword Mathmode')) {
347 # attribute => 'Keyword Mathmode'
349 # context => 'MathContrSeq'
350 # type => 'DetectChar'
351 if ($self->testDetectChar($text, '\\', 0, 0, 0, undef, 0, 'MathContrSeq', 'Keyword Mathmode')) {
355 # attribute => 'Math'
357 # endRegion => 'mathMode'
358 # type => 'StringDetect'
359 if ($self->testStringDetect($text, '$$', 0, 0, 0, undef, 0, '#pop', 'Math')) {
362 # attribute => 'Math'
365 # endRegion => 'mathMode'
366 # type => 'DetectChar'
367 if ($self->testDetectChar($text, '$', 0, 0, 0, undef, 0, '#pop', 'Math')) {
370 # String => '%\s*BEGIN.*$'
371 # attribute => 'Region Marker'
372 # beginRegion => 'regionMarker'
374 # firstNonSpace => 'true'
376 if ($self->testRegExpr($text, '%\\s*BEGIN.*$', 0, 0, 0, undef, 1, '#stay', 'Region Marker')) {
379 # String => '%\s*END.*$'
380 # attribute => 'Region Marker'
382 # endRegion => 'regionMarker'
383 # firstNonSpace => 'true'
385 if ($self->testRegExpr($text, '%\\s*END.*$', 0, 0, 0, undef, 1, '#stay', 'Region Marker')) {
388 # attribute => 'Comment'
390 # context => 'Comment'
391 # type => 'DetectChar'
392 if ($self->testDetectChar($text, '%', 0, 0, 0, undef, 0, 'Comment', 'Comment')) {
398 sub parseMathModeEnv {
399 my ($self, $text) = @_;
400 # String => '\\end(?=\s*\{\s*[a-zA-Z]*(equation|displaymath|eqnarray|subeqnarray|math|multline|gather|align|alignat|flalign)\*?\s*\})'
401 # attribute => 'Structure'
402 # context => 'MathFindEnd'
404 if ($self->testRegExpr($text, '\\\\end(?=\\s*\\{\\s*[a-zA-Z]*(equation|displaymath|eqnarray|subeqnarray|math|multline|gather|align|alignat|flalign)\\*?\\s*\\})', 0, 0, 0, undef, 0, 'MathFindEnd', 'Structure')) {
407 # String => '\\begin(?=[^a-zA-Z])'
408 # attribute => 'Keyword Mathmode'
409 # beginRegion => 'block'
412 if ($self->testRegExpr($text, '\\\\begin(?=[^a-zA-Z])', 0, 0, 0, undef, 0, '#stay', 'Keyword Mathmode')) {
415 # String => '\\end(?=[^a-zA-Z])'
416 # attribute => 'Keyword Mathmode'
418 # endRegion => 'block'
420 if ($self->testRegExpr($text, '\\\\end(?=[^a-zA-Z])', 0, 0, 0, undef, 0, '#stay', 'Keyword Mathmode')) {
424 # attribute => 'Math'
425 # beginRegion => 'mathMode'
426 # context => 'MathMode'
427 # type => 'StringDetect'
428 if ($self->testStringDetect($text, '\\(', 0, 0, 0, undef, 0, 'MathMode', 'Math')) {
432 # attribute => 'Math'
433 # beginRegion => 'mathMode'
434 # context => 'MathMode'
435 # type => 'StringDetect'
436 if ($self->testStringDetect($text, '\\[', 0, 0, 0, undef, 0, 'MathMode', 'Math')) {
439 # attribute => 'Keyword Mathmode'
441 # context => 'MathContrSeq'
442 # type => 'DetectChar'
443 if ($self->testDetectChar($text, '\\', 0, 0, 0, undef, 0, 'MathContrSeq', 'Keyword Mathmode')) {
447 # attribute => 'Math'
448 # beginRegion => 'mathMode'
449 # context => 'MathMode'
450 # type => 'StringDetect'
451 if ($self->testStringDetect($text, '$$', 0, 0, 0, undef, 0, 'MathMode', 'Math')) {
454 # attribute => 'Math'
455 # beginRegion => 'mathMode'
457 # context => 'MathMode'
458 # type => 'DetectChar'
459 if ($self->testDetectChar($text, '$', 0, 0, 0, undef, 0, 'MathMode', 'Math')) {
462 # String => '%\s*BEGIN.*$'
463 # attribute => 'Region Marker'
464 # beginRegion => 'regionMarker'
466 # firstNonSpace => 'true'
468 if ($self->testRegExpr($text, '%\\s*BEGIN.*$', 0, 0, 0, undef, 1, '#stay', 'Region Marker')) {
471 # String => '%\s*END.*$'
472 # attribute => 'Region Marker'
474 # endRegion => 'regionMarker'
475 # firstNonSpace => 'true'
477 if ($self->testRegExpr($text, '%\\s*END.*$', 0, 0, 0, undef, 1, '#stay', 'Region Marker')) {
480 # attribute => 'Comment'
482 # context => 'Comment'
483 # type => 'DetectChar'
484 if ($self->testDetectChar($text, '%', 0, 0, 0, undef, 0, 'Comment', 'Comment')) {
490 sub parseNormalText {
491 my ($self, $text) = @_;
492 # String => '\\begin(?=[^a-zA-Z])'
493 # attribute => 'Structure'
494 # beginRegion => 'block'
495 # context => 'FindEnvironment'
497 if ($self->testRegExpr($text, '\\\\begin(?=[^a-zA-Z])', 0, 0, 0, undef, 0, 'FindEnvironment', 'Structure')) {
500 # String => '\\end(?=[^a-zA-Z])'
501 # attribute => 'Structure'
502 # context => 'FindEnvironment'
503 # endRegion => 'block'
505 if ($self->testRegExpr($text, '\\\\end(?=[^a-zA-Z])', 0, 0, 0, undef, 0, 'FindEnvironment', 'Structure')) {
508 # String => '\\(label|pageref|ref|cite)(?=[^a-zA-Z])'
509 # attribute => 'Structure'
512 if ($self->testRegExpr($text, '\\\\(label|pageref|ref|cite)(?=[^a-zA-Z])', 0, 0, 0, undef, 0, 'Label', 'Structure')) {
515 # String => '\\(part|chapter|section|subsection|subsubsection|paragraph|subparagraph)(?=[^a-zA-Z])'
516 # attribute => 'Structure'
519 if ($self->testRegExpr($text, '\\\\(part|chapter|section|subsection|subsubsection|paragraph|subparagraph)(?=[^a-zA-Z])', 0, 0, 0, undef, 0, '#stay', 'Structure')) {
522 # String => '\renewcommand'
523 # attribute => 'Keyword'
524 # context => 'ToEndOfLine'
525 # type => 'StringDetect'
526 if ($self->testStringDetect($text, '\\renewcommand', 0, 0, 0, undef, 0, 'ToEndOfLine', 'Keyword')) {
529 # String => '\newcommand'
530 # attribute => 'Keyword'
531 # context => 'ToEndOfLine'
532 # type => 'StringDetect'
533 if ($self->testStringDetect($text, '\\newcommand', 0, 0, 0, undef, 0, 'ToEndOfLine', 'Keyword')) {
537 # attribute => 'Math'
538 # beginRegion => 'mathMode'
539 # context => 'MathMode'
540 # type => 'StringDetect'
541 if ($self->testStringDetect($text, '\\(', 0, 0, 0, undef, 0, 'MathMode', 'Math')) {
545 # attribute => 'Math'
546 # beginRegion => 'mathMode'
547 # context => 'MathMode'
548 # type => 'StringDetect'
549 if ($self->testStringDetect($text, '\\[', 0, 0, 0, undef, 0, 'MathMode', 'Math')) {
552 # attribute => 'Keyword'
554 # context => 'ContrSeq'
555 # type => 'DetectChar'
556 if ($self->testDetectChar($text, '\\', 0, 0, 0, undef, 0, 'ContrSeq', 'Keyword')) {
560 # attribute => 'Math'
561 # beginRegion => 'mathMode'
562 # context => 'MathMode'
563 # type => 'StringDetect'
564 if ($self->testStringDetect($text, '$$', 0, 0, 0, undef, 0, 'MathMode', 'Math')) {
567 # attribute => 'Math'
568 # beginRegion => 'mathMode'
570 # context => 'MathMode'
571 # type => 'DetectChar'
572 if ($self->testDetectChar($text, '$', 0, 0, 0, undef, 0, 'MathMode', 'Math')) {
575 # String => '%\s*BEGIN.*$'
576 # attribute => 'Region Marker'
577 # beginRegion => 'regionMarker'
579 # firstNonSpace => 'true'
581 if ($self->testRegExpr($text, '%\\s*BEGIN.*$', 0, 0, 0, undef, 1, '#stay', 'Region Marker')) {
584 # String => '%\s*END.*$'
585 # attribute => 'Region Marker'
587 # endRegion => 'regionMarker'
588 # firstNonSpace => 'true'
590 if ($self->testRegExpr($text, '%\\s*END.*$', 0, 0, 0, undef, 1, '#stay', 'Region Marker')) {
593 # attribute => 'Comment'
595 # context => 'Comment'
596 # type => 'DetectChar'
597 if ($self->testDetectChar($text, '%', 0, 0, 0, undef, 0, 'Comment', 'Comment')) {
603 sub parseToEndOfLine {
604 my ($self, $text) = @_;
609 my ($self, $text) = @_;
610 # String => '(.).*\1'
611 # attribute => 'Verbatim'
612 # context => '#pop#pop'
615 if ($self->testRegExpr($text, '(.).*?\\1', 0, 0, 0, undef, 0, '#pop#pop', 'Verbatim')) {
621 sub parseVerbFindEnd {
622 my ($self, $text) = @_;
623 # attribute => 'Normal Text'
626 # type => 'DetectChar'
627 if ($self->testDetectChar($text, '{', 0, 0, 0, undef, 0, '#stay', 'Normal Text')) {
630 # String => '(semiverbatim|verbatim|lstlisting|boxedverbatim|Verbatim)\*?'
631 # attribute => 'Environment'
634 if ($self->testRegExpr($text, '(semiverbatim|verbatim|lstlisting|boxedverbatim|Verbatim)\\*?', 0, 0, 0, undef, 0, '#stay', 'Environment')) {
637 # attribute => 'Normal Text'
639 # context => '#pop#pop#pop#pop#pop'
640 # endRegion => 'block'
641 # type => 'DetectChar'
642 if ($self->testDetectChar($text, '}', 0, 0, 0, undef, 0, '#pop#pop#pop#pop#pop', 'Normal Text')) {
649 my ($self, $text) = @_;
650 # String => '\\end(?=\{(semiverbatim|verbatim|lstlisting|boxedverbatim|Verbatim)\*?\})'
651 # attribute => 'Structure'
652 # context => 'VerbFindEnd'
654 if ($self->testRegExpr($text, '\\\\end(?=\\{(semiverbatim|verbatim|lstlisting|boxedverbatim|Verbatim)\\*?\\})', 0, 0, 0, undef, 0, 'VerbFindEnd', 'Structure')) {
660 sub parseVerbatimEnv {
661 my ($self, $text) = @_;
662 # attribute => 'Normal Text'
665 # type => 'DetectChar'
666 if ($self->testDetectChar($text, '*', 0, 0, 0, undef, 0, '#stay', 'Normal Text')) {
669 # attribute => 'Normal Text'
671 # context => 'Verbatim'
672 # type => 'DetectChar'
673 if ($self->testDetectChar($text, '}', 0, 0, 0, undef, 0, 'Verbatim', 'Normal Text')) {
677 # attribute => 'Normal Text'
680 if ($self->testRegExpr($text, '\\S', 0, 0, 0, undef, 0, '#pop', 'Normal Text')) {
693 Syntax::Highlight::Engine::Kate::LaTeX - a Plugin for LaTeX syntax highlighting
697 require Syntax::Highlight::Engine::Kate::LaTeX;
698 my $sh = new Syntax::Highlight::Engine::Kate::LaTeX([
703 Syntax::Highlight::Engine::Kate::LaTeX is a plugin module that provides syntax highlighting
704 for LaTeX to the Syntax::Haghlight::Engine::Kate highlighting engine.
706 This code is generated from the syntax definition files used
708 It works quite fine, but can use refinement and optimization.
710 It inherits Syntax::Higlight::Engine::Kate::Template. See also there.
716 Hans Jeuken (haje <at> toneel <dot> demon <dot> nl)
722 Unknown. If you find any, please contact the author