summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/verb-tex.mkii
blob: 75e99fcefde7eb46d0bb762f2195e49583ca155b (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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
%D \module
%D   [       file=verb-tex,
%D        version=1997.12.22,
%D          title=\CONTEXT\ Verbatim Macros,
%D       subtitle=Pretty \TEX\ verbatim,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Verbatim Macros / Pretty TEX Verbatim}

%D The original module \type{supp-ver} had the \TEX\
%D interpreter built in. The current implementation is more
%D natural and less complicated.

%D \startTEX
%D \definetyping[niceTEX][option=TEX,paletpalet=graypretty]
%D
%D \startniceTEX
%D \message{A vivid look at TeX}
%D \stopniceTEX
%D \stopTEX

\unprotect

%D \macros
%D   {ifsplitTEXparameters}
%D
%D The mechanism described here, is meant to be used with
%D color. It is nevertheless possible to use different fonts
%D instead of distinctive colors. When using color, it's better
%D to end parameter mode after the \type{#}. When on the
%D other hand we use a slanted typeface for the hashmark, then
%D a slanted number looks better.

\doglobal\newif\ifsplitTEXparameters \global\splitTEXparameterstrue

%D \macros
%D   {ifsplitTEXcontrols}
%D
%D With \type{\splittexcontrols} we can influence the way
%D control characters are processed in macro names. By default,
%D the \type{^^} part is uncolored. When this boolean is set to
%D false, they get the same color as the other characters.

\doglobal\newif\ifsplitTEXcontrols \global\splitTEXcontrolstrue

%D The next boolean is used for internal purposes only and
%D keeps track of the length of the name. Because two||character
%D sequences starting with a backslash are always seen as a
%D command.

\doglobal\newif\iffirstinTEXcommand

%D We use a maximum of four colors because more colors will
%D distract too much. In the following table we show the
%D logical names of the colors, their color and \cap{RGB} values.
%D
%D \placetable{geen}
%D \starttable[|l|l|c|c|c|c|]
%D \HL
%D \FC\bf identifier \MC\bf color \MC\bf r \MC\bf g \MC\bf b \MC\bf bw \LC\SR
%D \HL
%D \FC prettyone     \MC red      \MC 0.9  \MC 0.0  \MC 0.0  \MC 0.30  \LC\FR
%D \FC prettytwo     \MC green    \MC 0.0  \MC 0.8  \MC 0.0  \MC 0.45  \LC\MR
%D \FC prettythree   \MC yellow   \MC 0.0  \MC 0.0  \MC 0.9  \MC 0.60  \LC\MR
%D \FC prettyfour    \MC blue     \MC 0.8  \MC 0.8  \MC 0.6  \MC 0.75  \LC\LR
%D \HL
%D \stoptable
%D
%D Outside \CONTEXT\ these colors are defined in
%D \type{verb-ini}, in \CONTEXT\ their definitions can be found
%D in \type{core-ver}, where in fact we use the color palet
%D mechanism. That way we can use different schemes i a quite
%D natural way.

\gdef\setupprettyTEXtype
  {\def\prettyidentifier{TEX}%
   \global\inTEXcommandfalse
   \global\firstinTEXcommandfalse
   \global\inTEXparameterfalse
   \TEXsetcontrols
   \TEXsethandlers
   \TEXsetspecials}

\gdef\TEXsetcontrols
  {\saveprettycontrols
   \everyprettyend
     {\TEXendofcommand
      \TEXendofparameter}%
   \def\obeyedspace
     {\TEXendofcommand
      \TEXendofparameter
      \oldobeyedspace}%
   \def\flushrestofverbatimline
     {\TEXendofcommand
      \TEXendofparameter}%
   \let\obeytabs=\ignoretabs}

\gdef\TEXsetspecials
  {\setpretty`\$=1 \setpretty`\{=1 \setpretty`\}=1
   \setpretty`\[=2 \setpretty`\]=2 \setpretty`\(=2 \setpretty`\)=2
   \setpretty`\==2 \setpretty`\<=2 \setpretty`\>=2 \setpretty`\"=2
   \setpretty`\-=3 \setpretty`\+=3 \setpretty`\/=3
   \setpretty`\|=3 \setpretty`\%=3 \setpretty`\'=3 \setpretty`\`=3
   \setpretty`\_=3 \setpretty`\&=3 \setpretty`\~=3
   \setpretty`\.=4 \setpretty`\,=4 \setpretty`\:=4 \setpretty`\;=4 \setpretty`\*=4
   \setpretty`\#=5
   \setpretty`\1=6 \setpretty`\2=6 \setpretty`\3=6 \setpretty`\4=6 \setpretty`\5=6
   \setpretty`\6=6 \setpretty`\7=6 \setpretty`\8=6 \setpretty`\9=6 \setpretty`\0=6
   \setpretty`\\=7
   \setpretty`\^=8
   \setpretty`\A=9 \setpretty`\B=9 \setpretty`\C=9 \setpretty`\D=9 \setpretty`\E=9
   \setpretty`\F=9 \setpretty`\G=9 \setpretty`\H=9 \setpretty`\I=9 \setpretty`\J=9
   \setpretty`\K=9 \setpretty`\L=9 \setpretty`\M=9 \setpretty`\N=9 \setpretty`\O=9
   \setpretty`\P=9 \setpretty`\Q=9 \setpretty`\R=9 \setpretty`\S=9 \setpretty`\T=9
   \setpretty`\U=9 \setpretty`\V=9 \setpretty`\W=9 \setpretty`\X=9 \setpretty`\Y=9
   \setpretty`\Z=9
   \setpretty`\a=9 \setpretty`\b=9 \setpretty`\c=9 \setpretty`\d=9 \setpretty`\e=9
   \setpretty`\f=9 \setpretty`\g=9 \setpretty`\h=9 \setpretty`\i=9 \setpretty`\j=9
   \setpretty`\k=9 \setpretty`\l=9 \setpretty`\m=9 \setpretty`\n=9 \setpretty`\o=9
   \setpretty`\p=9 \setpretty`\q=9 \setpretty`\r=9 \setpretty`\s=9 \setpretty`\t=9
   \setpretty`\u=9 \setpretty`\v=9 \setpretty`\w=9 \setpretty`\x=9 \setpretty`\y=9
   \setpretty`\z=9
   \setpretty`\?=9 \setpretty`\!=9 \setpretty`\@=9
   \setpretty`\%=0 }

\gdef\TEXsethandlers
  {\installprettyhandler 1 \TEXtypeone
   \installprettyhandler 2 \TEXtypetwo
   \installprettyhandler 3 \TEXtypethree
   \installprettyhandler 4 \TEXtypefour
   \installprettyhandler 5 \TEXtypefive
   \installprettyhandler 6 \TEXtypesix
   \installprettyhandler 7 \TEXtypeseven
   \installprettyhandler 8 \TEXtypeeight
   \installprettyhandler 9 \TEXtypenine
   \installprettyhandler 0 \TEXtypezero}

\doglobal\newif\ifinTEXcommand
\doglobal\newif\ifinTEXparameter

\gdef\TEXbeginofcommand
  {\TEXendofparameter
   \ifinTEXcommand
   \else
     \global\inTEXcommandtrue
     \global\firstinTEXcommandtrue
     \beginofpretty[\!!prettytwo]%
   \fi}

\gdef\TEXendofcommand
  {\ifinTEXcommand
     \endofpretty
     \global\inTEXcommandfalse
     \global\firstinTEXcommandfalse
   \fi}

\gdef\TEXbeginofparameter
  {\TEXendofcommand
   \ifinTEXparameter
   \else
     \global\inTEXparametertrue
     \beginofpretty[\!!prettythree]%
   \fi}

\gdef\TEXendofparameter
  {\ifinTEXparameter
     \endofpretty
     \global\inTEXparameterfalse
   \fi}

\gdef\ifnotfirstinTEXcommand#1
  {\iffirstinTEXcommand
     \getpretty{#1}%
     \TEXendofcommand
   \else}

\gdef\TEXtypeone#1%
  {\ifnotfirstinTEXcommand#1
     \TEXendofcommand
     \TEXendofparameter
     \beginofpretty[\!!prettyone]\getpretty{#1}\endofpretty
   \fi}

\gdef\TEXtypetwo#1%
  {\ifnotfirstinTEXcommand#1
     \TEXendofcommand
     \TEXendofparameter
     \beginofpretty[\!!prettythree]\getpretty{#1}\endofpretty
   \fi}

\gdef\TEXtypethree#1%
  {\ifnotfirstinTEXcommand#1
     \TEXendofcommand
     \TEXendofparameter
     \beginofpretty[\!!prettyfour]\getpretty{#1}\endofpretty
   \fi}

\gdef\TEXtypefour#1%
  {\ifnotfirstinTEXcommand#1
     \TEXendofcommand
     \TEXendofparameter
     \getpretty{#1}%
   \fi}

\gdef\TEXtypefive#1%
  {\ifnotfirstinTEXcommand#1
     \TEXbeginofparameter
     \getpretty{#1}%
   \fi}

\gdef\TEXtypesix#1%
  {\ifnotfirstinTEXcommand#1
     \ifinTEXparameter
       \ifsplitTEXparameters
         \TEXendofparameter
         \getpretty{#1}%
       \else
         \getpretty{#1}%
         \TEXendofparameter
       \fi
     \else
       \TEXendofcommand
       \getpretty{#1}%
     \fi
   \fi}

\gdef\TEXtypeseven#1%
  {\ifnotfirstinTEXcommand#1
     \TEXbeginofcommand
     \getpretty{#1}%
   \fi}

\gdef\TEXtypeeightA#1#2%
  {\getprettydata{#2}%
   \ifnum\prettytype=80
     \TEXendofparameter
     \ifsplitTEXcontrols
       \ifinTEXcommand
         \def\next{\TEXendofcommand\getpretty{#1}\getpretty{#1}\TEXbeginofcommand}%
       \else
         \def\next{\getpretty{#1}\getpretty{#1}}%
       \fi
     \else
       \def\next{\getpretty{#1}\getpretty{#1}}%
     \fi
   \else
     \def\next{\TEXtypeeightB{#1}#2}%
   \fi
   \next}

\gdef\TEXtypeeightB
  {\TEXendofparameter
   \ifinTEXcommand
     \firstinTEXcommandfalse
     \expandafter\getpretty
   \else
     \expandafter\TEXtypethree
   \fi}

\gdef\TEXtypeeight
  {\handlenextnextpretty\TEXtypeeightA\TEXtypeeightB}

\gdef\TEXtypenine
  {\TEXendofparameter
   \global\firstinTEXcommandfalse
   \getpretty}

%\gdef\TEXtypezero
%  {\disableprettyafterwards % only when enabled of course
%   \ifnewpretty\expandafter\handlenewpretty\fi\TEXtypethree}

\long\gdef\naturalTEXtext#1#2\relax% local alternative for \naturaltextext
  {\convertargument#2\to\ascii
   \doifinstringelse{\letterpercent}{\ascii}
     {\long\def\next{\TEXtypethree{#1}#2\relax}}
    %{\long\def\next{\bgroup\prettynaturalfont\restorecatcodes\scantokens{\ignorespaces#2}\egroup}}%
     {\long\def\next{\bgroup\prettynaturalfont{\restorecatcodes\scantokens{\ignorespaces#2}}\egroup}}%
   \next}

\gdef\TEXtypezero
  {\ifnaturaltextext
     \expandafter\naturalTEXtext
   \else
     \disableprettyafterwards % only when enabled of course
     \expandafter\handlenewpretty\expandafter\TEXtypethree
   \fi}

\protect \endinput