| 1 |
%% This is part of the OpTeX project, see http://petr.olsak.net/optex |
| 2 |
|
| 3 |
\_codedecl\_hisyntaxtex {Syntax highlighting for TeX sources <2020-04-03>} |
| 4 |
|
| 5 |
\_newtoks\_hisyntaxtex \_newtoks\_hicolorstex |
| 6 |
|
| 7 |
\_global\_hicolorstex={% colors in TeX codes |
| 8 |
\_hicolor S \Blue % control sequences |
| 9 |
\_hicolor B \Magenta % {, }, $ |
| 10 |
\_hicolor C \Green % comments |
| 11 |
} |
| 12 |
\_global\_hisyntaxtex={ |
| 13 |
\_the\_hicolorstex |
| 14 |
\_replthis{\_string\%}{\y{_createcs}{\_csstring\%}} |
| 15 |
\_replfromto{\_csstring\%}{^^J}{\x C{\_csstring\%#1}^^J} |
| 16 |
\_replthis{\_string\\}{\y{_createcs}{\_csstring\\}} |
| 17 |
\_replthis{\_string\{}{\y{_createcs}{\_csstring\{}} |
| 18 |
\_replthis{\_string\}}{\y{_createcs}{\_csstring\}}} |
| 19 |
\_replthis{\_string\$}{\y{_createcs}{\_csstring\$}} |
| 20 |
\_replthis{\_csstring\\}{\y{_createcs}} |
| 21 |
\_replthis{\_csstring\{}{\x B{\_csstring\{}} |
| 22 |
\_replthis{\_csstring\}}{\x B{\_csstring\}}} |
| 23 |
\_replthis{\_csstring\$}{\x B{\_csstring\$}} |
| 24 |
} |
| 25 |
\_gdef\_createcs#1{\_def\_csletters{#1}% |
| 26 |
\_ifcat a\_noexpand#1\_afterfi{\_futurelet\_next\_createcsA}% |
| 27 |
\_else \_ea\_createcsF \_fi |
| 28 |
} |
| 29 |
\_gdef\_createcsA{\_ifcat a\_noexpand\_next \_ea\_createcsB \_else \_ea\_createcsF \_fi} |
| 30 |
\_gdef\_createcsB#1{\_addto\_csletters{#1}\_futurelet\_next\_createcsA} |
| 31 |
\_gdef\_createcsF{\z S{\_csstring\\\_csletters}} |
| 32 |
\_gdef\_createbb{\_ea\_createcs\_csstring\\} |
| 33 |
|
| 34 |
\_endcode %------------------------------------------------ |
| 35 |
|
| 36 |
The `\_createcs` reads next tokens as the tokenizer does it until the name |
| 37 |
of a control sequence is read. It is saved to the `\_csletters` macro and |
| 38 |
the macro \_createcsF prints it. |