summaryrefslogtreecommitdiff
path: root/macros/optex/base/hisyntax-tex.opm
blob: 583676a2ca431c871e6e80c5a69be2e9ced97a93 (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
%% This is part of the OpTeX project, see http://petr.olsak.net/optex

\_codedecl\_hisyntaxtex {Syntax highlighting for TeX sources <2020-04-03>} 

\_newtoks\_hisyntaxtex  \_newtoks\_hicolorstex

\_global\_hicolorstex={%  colors in TeX codes 
   \_hicolor S \Blue    % control sequences
   \_hicolor B \Magenta % {, }, $
   \_hicolor C \Green   % comments
}
\_global\_hisyntaxtex={
   \_the\_hicolorstex
   \_replthis{\_string\%}{\y{_createcs}{\_csstring\%}}
   \_replfromto{\_csstring\%}{^^J}{\x C{\_csstring\%#1}^^J}
   \_replthis{\_string\\}{\y{_createcs}{\_csstring\\}}
   \_replthis{\_string\{}{\y{_createcs}{\_csstring\{}}
   \_replthis{\_string\}}{\y{_createcs}{\_csstring\}}}
   \_replthis{\_string\$}{\y{_createcs}{\_csstring\$}}
   \_replthis{\_csstring\\}{\y{_createcs}}
   \_replthis{\_csstring\{}{\x B{\_csstring\{}}
   \_replthis{\_csstring\}}{\x B{\_csstring\}}}
   \_replthis{\_csstring\$}{\x B{\_csstring\$}}
}
\_gdef\_createcs#1{\_def\_csletters{#1}%
   \_ifcat a\_noexpand#1\_afterfi{\_futurelet\_next\_createcsA}%
   \_else \_ea\_createcsF \_fi
}
\_gdef\_createcsA{\_ifcat a\_noexpand\_next \_ea\_createcsB \_else \_ea\_createcsF \_fi}
\_gdef\_createcsB#1{\_addto\_csletters{#1}\_futurelet\_next\_createcsA}
\_gdef\_createcsF{\z S{\_csstring\\\_csletters}}
\_gdef\_createbb{\_ea\_createcs\_csstring\\}

\_endcode %------------------------------------------------

The `\_createcs` reads next tokens as the tokenizer does it until the name
of a control sequence is read. It is saved to the `\_csletters` macro and
the macro \_createcsF prints it.