1package t
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Tex lexer.
9var TeX = internal.Register(MustNewLexer(
10 &Config{
11 Name: "TeX",
12 Aliases: []string{"tex", "latex"},
13 Filenames: []string{"*.tex", "*.aux", "*.toc"},
14 MimeTypes: []string{"text/x-tex", "text/x-latex"},
15 },
16 Rules{
17 "general": {
18 {`%.*?\n`, Comment, nil},
19 {`[{}]`, NameBuiltin, nil},
20 {`[&_^]`, NameBuiltin, nil},
21 },
22 "root": {
23 {`\\\[`, LiteralStringBacktick, Push("displaymath")},
24 {`\\\(`, LiteralString, Push("inlinemath")},
25 {`\$\$`, LiteralStringBacktick, Push("displaymath")},
26 {`\$`, LiteralString, Push("inlinemath")},
27 {`\\([a-zA-Z]+|.)`, Keyword, Push("command")},
28 {`\\$`, Keyword, nil},
29 Include("general"),
30 {`[^\\$%&_^{}]+`, Text, nil},
31 },
32 "math": {
33 {`\\([a-zA-Z]+|.)`, NameVariable, nil},
34 Include("general"),
35 {`[0-9]+`, LiteralNumber, nil},
36 {`[-=!+*/()\[\]]`, Operator, nil},
37 {`[^=!+*/()\[\]\\$%&_^{}0-9-]+`, NameBuiltin, nil},
38 },
39 "inlinemath": {
40 {`\\\)`, LiteralString, Pop(1)},
41 {`\$`, LiteralString, Pop(1)},
42 Include("math"),
43 },
44 "displaymath": {
45 {`\\\]`, LiteralString, Pop(1)},
46 {`\$\$`, LiteralString, Pop(1)},
47 {`\$`, NameBuiltin, nil},
48 Include("math"),
49 },
50 "command": {
51 {`\[.*?\]`, NameAttribute, nil},
52 {`\*`, Keyword, nil},
53 Default(Pop(1)),
54 },
55 },
56))