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
|
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class TeX < RegexLexer
title "TeX"
desc "The TeX typesetting system"
tag 'tex'
aliases 'TeX', 'LaTeX', 'latex'
filenames '*.tex', '*.aux', '*.toc', '*.sty', '*.cls'
mimetypes 'text/x-tex', 'text/x-latex'
def self.detect?(text)
return true if text =~ /\A\s*\\(documentclass|input|documentstyle|relax|ProvidesPackage|ProvidesClass)/
end
command = /\\([a-z]+|\s+|.)/i
state :general do
rule %r/%.*$/, Comment
rule %r/[{}&_^]/, Punctuation
end
state :root do
rule %r/\\\[/, Punctuation, :displaymath
rule %r/\\\(/, Punctuation, :inlinemath
rule %r/\$\$/, Punctuation, :displaymath
rule %r/\$/, Punctuation, :inlinemath
rule %r/\\(begin|end)\{.*?\}/, Name::Tag
rule %r/(\\verb)\b(\S)(.*?)(\2)/ do
groups Name::Builtin, Keyword::Pseudo, Str::Other, Keyword::Pseudo
end
rule command, Keyword, :command
mixin :general
rule %r/[^\\$%&_^{}]+/, Text
end
state :math do
rule command, Name::Variable
mixin :general
rule %r/[0-9]+/, Num
rule %r/[-=!+*\/()\[\]]/, Operator
rule %r/[^=!+*\/()\[\]\\$%&_^{}0-9-]+/, Name::Builtin
end
state :inlinemath do
rule %r/\\\)/, Punctuation, :pop!
rule %r/\$/, Punctuation, :pop!
mixin :math
end
state :displaymath do
rule %r/\\\]/, Punctuation, :pop!
rule %r/\$\$/, Punctuation, :pop!
rule %r/\$/, Name::Builtin
mixin :math
end
state :command do
rule %r/\[.*?\]/, Name::Attribute
rule %r/\*/, Keyword
rule(//) { pop! }
end
end
end
end
|