buff-ver.mkxl /size: 31 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=buff-ver, % was core-ver
3
%D version=2000.05.09,
4
%D title=\CONTEXT\ Buffer Macros,
5
%D subtitle=Verbatim,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
% check after-first and before-last breaks
15 16
\writestatus
{
loading
}{
ConTeXt
Buffer
Macros
/
Verbatim
}
17 18
\registerctxluafile
{
buff
-
ver
}{}
19 20
\unprotect
21 22
\startcontextdefinitioncode
23 24
\definesystemattribute
[
verbatimline
][
public
]
25 26
\appendtoksonce
27
\c_attr_verbatimline
\attributeunsetvalue
28
\to
\everyforgetall
29 30
%D Initializations.
31 32
\installcorenamespace
{
typinglines
}
33
\installcorenamespace
{
typingspace
}
34
\installcorenamespace
{
typingblank
}
% needs checking ... used?
35 36
\newtoks
\everyinitializeverbatim
37 38
\appendtoks
39
\the
\everyresettypesetting
40
\resetfontfeature
41
\resetcharacterspacing
42
\to
\everyinitializeverbatim
43 44
\unexpanded
\def
\setverbatimspaceskip
% to be checked: must happen after font switch
45
{
\spaceskip\fontcharwd\font
`
x
\relax
46
\xspaceskip\spaceskip
}
47 48
\setvalue
{
\??typinglines\v!no
}{
\buff_verbatim_ignore_hyphens
}
49
\setvalue
{
\??typinglines\v!normal
}{
\buff_verbatim_ignore_hyphens
}
50
\setvalue
{
\??typinglines\v!yes
}{
\buff_verbatim_obey_breakpoints
}
51
\setvalue
{
\??typinglines\v!hyphenated
}{
\buff_verbatim_obey_hyphens
}
52 53
\setvalue
{
\??typingspace\v!on
}{
\let
\obeyedspace
\specialcontrolspace
}
54
\setvalue
{
\??typingspace\v!stretch
}{
\let
\obeyedspace
\specialstretchedspace
}
55
\setvalue
{
\??typingspace\v!normal
}{}
56
\setvalue
{
\??typingspace\v!fixed
}{
\let
\obeyedspace
\specialfixedspace
}
57 58
\setvalue
{
\??typingblank\v!standard
}{
\s_spac_whitespace_parskip
}
59
\setvalue
{
\??typingblank\v!small
}{
\smallskipamount
}
60
\setvalue
{
\??typingblank\v!medium
}{
\medskipamount
}
61
\setvalue
{
\??typingblank\v!big
}{
\bigskipamount
}
62
\setvalue
{
\??typingblank\v!halfline
}{
.
5
\baselineskip
}
63
\setvalue
{
\??typingblank\v!line
}{
\baselineskip
}
64
\setvalue
{
\??typingblank\v!none
}{
\zeropoint
}
65 66
\unexpanded
\def
\buff_verbatim_obey_hyphens
67
{}
68 69
\unexpanded
\def
\buff_verbatim_obey_breakpoints
70
{
\language
\minusone
% tricky as this affects the pagebuilder
71
\veryraggedright
}
72 73
\unexpanded
\def
\buff_verbatim_ignore_hyphens
74
{
\language
\minusone
}
% tricky as this affects the pagebuilder
75 76
\def
\buff_verbatim_initialize_type_one
77
{
\let
\obeylines
\ignorelines
78
\edef
\p_buff_option
{
\typeparameter
\c!option
}
%
79
\ifx
\p_buff_option
\v!none
80
\usetypestyleandcolor
\c!style\c!color
81
\orelse\ifempty
\p_buff_option
82
\usetypestyleandcolor
\c!style\c!color
83
\else
84
\usetypestyleparameter
\c!style
% no color
85
\fi
86
\setcatcodetable
\vrbcatcodes
}
87 88
\def
\buff_verbatim_initialize_type_two
89
{
\spaceskip
.
5
\emwidth
\relax
90
\let
\obeyedspace
\specialobeyedspace
91
\let
\controlspace
\specialcontrolspace
92
\edef
\p_buff_lines
{
\typeparameter
\c!lines
}
%
93
\begincsname
\??typinglines
\p_buff_lines
\endcsname
94
\edef
\p_buff_space
{
\typeparameter
\c!space
}
%
95
\begincsname
\??typingspace
\p_buff_space
\endcsname
96
\relax\the
\everyinitializeverbatim
\relax
}
97 98
\unexpanded
\def
\doinitializeverbatim
% for use elsewhere .. temp hack (see lxml-ini)
99
{
\buff_verbatim_initialize_type_one
100
\buff_verbatim_initialize_type_two
}
101 102
\let
\buff_verbatim_set_line_margin
\relax
103 104
\def
\buff_verbatim_set_line_margin_indeed
105
{
\hskip
\doifelseoddpage
{
\typingparameter
\c!oddmargin
}{
\typingparameter
\c!evenmargin
}
\relax
}
106 107
\def
\buff_verbatim_initialize_typing_one
108
{
\usebodyfontparameter
\typingparameter
109
\scratchskip
\typingparameter
\c!oddmargin
\relax
110
\ifzeropt
\scratchskip
\else
111
\let
\buff_verbatim_set_line_margin
\buff_verbatim_set_line_margin_indeed
112
\fi
113
\scratchskip
\typingparameter
\c!evenmargin
\relax
114
\ifzeropt
\scratchskip
\else
115
\let
\buff_verbatim_set_line_margin
\buff_verbatim_set_line_margin_indeed
116
\fi
117
\ifx
\buff_verbatim_set_line_margin
\relax
118
\doadaptleftskip
{
\typingparameter
\c!margin
}
%
119
\fi
120
\edef
\p_buff_option
{
\typingparameter
\c!option
}
%
121
\ifx
\p_buff_option
\v!none
122
\usetypingstyleandcolor
\c!style\c!color
123
\orelse\ifempty
\p_buff_option
124
\usetypingstyleandcolor
\c!style\c!color
125
\else
126
\usetypingstyleparameter
\c!style
% no color !
127
\fi
128
\usealignparameter
\typingparameter
}
129 130
\def
\buff_verbatim_initialize_typing_two
131
{
\spaceskip
.
5
\emwidth
\relax
132
\let
\obeyedspace
\specialobeyedspace
133
\let
\controlspace
\specialcontrolspace
134
\edef
\p_buff_lines
{
\typingparameter
\c!lines
}
%
135
\begincsname
\??typinglines
\p_buff_lines
\endcsname
136
\edef
\p_buff_space
{
\typingparameter
\c!space
}
%
137
\begincsname
\??typingspace
\p_buff_space
\endcsname
138
\relax\the
\everyinitializeverbatim
\relax
}
139 140
%D \macros
141
%D {definetype,setuptype}
142
%D
143
%D Specific inline verbatim commands can be defined with the following command.
144 145
\installcorenamespace
{
type
}
146 147
\installcommandhandler
\??type
{
type
}
\??type
148 149
\appendtoks
150
\setuevalue
{
\currenttype
}{
\buff_verbatim_type
{
\currenttype
}}
%
151
\to
\everydefinetype
152 153
\appendtoks
154
\buff_verbatim_initialize_visualizer
{
\typeparameter
\c!option
}
%
155
\to
\everysetuptype
156 157
%D \macros
158
%D {definetyping,setuptyping}
159
%D
160
%D For most users the standard \type {\start}||\type {\stop}||pair will suffice, but
161
%D for documentation purposes the next definition command can be of use:
162
%D
163
%D \starttyping
164
%D \definetyping[extratyping][margin=3em]
165
%D
166
%D \startextratyping
167
%D these extra ones are indented by 1 em
168
%D \stopextratyping
169
%D \stoptyping
170
%D
171
%D The definitions default to the standard typing values.
172 173
\installcorenamespace
{
typing
}
174 175
\installcommandhandler
\??typing
{
typing
}
\??typing
176 177
\appendtoks
178
\setuevalue
{
\e!start
\currenttyping
}{
\buff_verbatim_typing_start
{
\currenttyping
}}
%
179
\setuevalue
{
\e!stop
\currenttyping
}{
\buff_verbatim_typing_stop
{
\currenttyping
}}
%
180
\ifempty
\currenttypingparent
181
\normalexpanded
{
\definelinenumbering
[
\currenttyping
]
}
%
182
\else
183
\normalexpanded
{
\definelinenumbering
[
\currenttyping
][
\currenttypingparent
]
}
%
184
\fi
185
\to
\everydefinetyping
186 187
\appendtoks
188
\buff_verbatim_initialize_visualizer
{
\typingparameter
\c!option
}
% we can check at the tex end
189
\to
\everysetuptyping
190 191
\def
\buff_verbatim_initialize_visualizer
#
1
%
192
{
\ifproductionrun
\clf_loadvisualizer
{
#
1
}
\fi
}
193 194
\unexpanded
\def
\doifelsevisualizer
#
1
%
195
{
\clf_doifelsevisualizer
{
#
1
}}
196 197
\let
\doifvisualizerelse
\doifelsevisualizer
198 199
%D Verbatim command are very sensitive to argument processing, which is a direct
200
%D result of the \CATCODES\ being fixed at reading time.
201
%D
202
%D Typesetting inline verbatim can be accomplished by \type {\type}, which in this
203
%D sentence was typeset by saying just \type {\type {\type}}, which in turn was
204
%D typeset by \unknown. Using the normal grouping characters \type {{}} is the most
205
%D natural way of using this command.
206
%D
207
%D A second, more or less redundant, alternative is delimiting the argument with an
208
%D own character. This method was implemented in the context of a publication in the
209
%D \MAPS, where this way of delimiting is recognized by \LATEX\ users.
210
%D
211
%D The third, more original alternative, is the one using \type {<<} and \type {>>}
212
%D as delimiters. This alternative can be used in situations where slanted
213
%D typeseting is needed.
214
%D
215
%D \macros
216
%D {type}
217
%D
218
%D We define \type {\type} as a protected command. This command has several
219
%D invocations: grouped, wirt boundary characters, and with font switches.
220
%D
221
%D \starttyping
222
%D normal: \par \type{xx<<..xx..<<xx <<xx>> >>..>>xx} \par \type<<....>> \par \type<<..<<xx>>..>> \par
223
%D normal: \par \type{xx<..xx..<xx <slanted> >..>xx} \par \type{<....>} \par \type{<..<xx>..>}
224
%D \setuptype[option=slanted]
225
%D slanted: \par \type{xx<<..sl..<<xx <<sl>> xx>>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<<sl>>..>> \par
226
%D slanted: \par \type{xx<<..sl..<xx <sl> xx>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<sl>..>> \par
227
%D \setuptype[option=none]
228
%D none: \par \type{xx<<..xx..<<xx <<xx>> >>..>>xx} \par \type<<....>> \par \type<<..<<xx>>..>> \par
229
%D \stoptyping
230
%D
231
%D When writing the manual to \CONTEXT\ and documenting this source we needed to
232
%D typeset \type {<<} and \type {>>}. Because we wanted to do this in the natural
233
%D way, we've adapted the original definition a bit. This implementation went
234
%D through several live cycles. The final implementation looks a bit further and
235
%D treats the lone \type {<<} and \type {>>} a bit different. The \type {\null}
236
%D prevents ligatures, which unfortunately turn up in Lucida fonts.
237
%D
238
%D The following lines show what happens when we set \type {option=commands}.
239
%D
240
%D \startbuffer
241
%D \starttyping
242
%D test//test test/BTEX \footnote{test test test}/ETEX test
243
%D test//test test/BTEX \footnote{test test test}/ETEX test
244
%D test test test/BTEX \bf(nota bene)/ETEX test
245
%D test test test /BTEX \bf(nota bene)/ETEX test
246
%D \stoptyping
247
%D \stopbuffer
248
%D
249
%D % \bgroup\setuptyping[option=commands]\getbuffer\egroup
250
%D
251
%D this was keyed in as:
252
%D
253
%D \typebuffer
254 255
% Beware, the command is supposed to do something like \framed and not manipulate
256
% content i.e. it gets no argument but something b/egrouped instead:
257 258
\def
\buff_verbatim_left_of_type
259
{
\typeparameter
\c!left
260
\typeparameter
\c!command
\bgroup
}
261 262
\def
\buff_verbatim_right_of_type
263
{
\egroup
264
\typeparameter
\c!right
}
265 266
\unexpanded
\def
\type
{
\buff_verbatim_type
\empty
}
267
\unexpanded
\def
\typ
{
\buff_verbatim_typ
\empty
}
268 269
\unexpanded
\def
\buff_verbatim_type
#
1
%
270
{
\dontleavehmode
271
\bgroup
272
\edef
\currenttype
{
#
1
}
%
273
\doifelsenextoptionalcs
\buff_verbatim_type_yes
\buff_verbatim_type_nop
}
274 275
\def
\buff_verbatim_type_yes
[#
1
]
%
276
{
\setupcurrenttype
[#
1
]
%
277
\buff_verbatim_type_nop
}
278 279
\def
\buff_verbatim_typ
#
1
%
280
{
\dontleavehmode
281
\bgroup
282
\edef
\currenttype
{
#
1
}
%
283
\lettypeparameter
\c!lines\v!hyphenated
284
\let
\specialobeyedspace
\specialstretchedspace
285
\doifelsenextoptionalcs
\buff_verbatim_type_yes
\buff_verbatim_type_nop
}
286 287
\def
\buff_verbatim_type_nop
288
{
\buff_verbatim_left_of_type
289
\futureexpand
\bgroup
\buff_verbatim_type_a
\buff_verbatim_type_one
}
290 291
\def
\buff_verbatim_type_one
292
{
\catcode
`
<=
\othercatcode
% old precaution
293
\catcode
`
>=
\othercatcode
% old precaution
294
\futureexpandis
<
\buff_verbatim_type_b
\buff_verbatim_type_c
}
295 296
\def
\buff_verbatim_type_three
297
{
\if
\next
<
%
298
\expandafter
\buff_verbatim_type_b
299
\else
300
\expandafter
\buff_verbatim_type_c
301
\fi
}
302 303
\def
\buff_verbatim_type_a
304
{
\buff_verbatim_initialize_type_one
305
\setcatcodetable
\tpacatcodes
306
\buff_verbatim_type_normal
}
307 308
\def
\buff_verbatim_type_b
#
1
%
309
{
\buff_verbatim_initialize_type_one
310
\setcatcodetable
\tpbcatcodes
311
\buff_verbatim_type_nested
}
312 313
\def
\buff_verbatim_type_c
#
1
%
314
{
\buff_verbatim_initialize_type_one
315
\setcatcodetable
\vrbcatcodes
316
\def
\next
##
1
#
1
{
\buff_verbatim_type_normal
{
##
1
}}
%
317
\next
}
318 319
\def
\buff_verbatim_type_normal
#
1
%
320
{
\buff_verbatim_initialize_type_two
321
\dostarttaggedchained
\t!verbatim
\currenttype
\??type
322
\clf_type
323
data
{
\detokenize
{
#
1
}}
%
324
tab
{
\typeparameter
\c!tab
}
%
325
method
{
\p_buff_option
}
%
326
compact
{
\typeparameter
\c!compact
}
% % none | all | last (all needed in tabulate etc for manuals)
327
escape
{
\typeparameter
\c!escape
}
% % new but rather useless imo (escaping in general is not used much)
328
% nature {inline}% is default
329
\relax
330
\dostoptagged
331
\buff_verbatim_right_of_type
332
\egroup
}
333 334
\def
\buff_verbatim_type_nested
#
1
%
335
{
\buff_verbatim_initialize_type_two
336
\dostarttaggedchained
\t!verbatim
\currenttype
\??type
337
\clf_type
338
data
{
\detokenize
{
#
1
}}
%
339
tab
{
\typeparameter
\c!tab
}
%
340
method
{
\p_buff_option
}
% % extra visualizer (maybe: nested,\typeparameter\c!option)
341
escape
{
\typeparameter
\c!escape
}
% % new but rather useless imo (escaping in general is not used much)
342
% nature {inline}% is default
343
method
{
nested
}
%
344
\relax
345
\dostoptagged
346
\buff_verbatim_right_of_type
347
\egroup
348
\gobbleoneargument
}
% grab last >
349 350
%D The \type {compact} option can come in handy in the case of inline argument passing
351
%D
352
%D \starttyping
353
%D \definetype[TeXcodeA][option=TEX]
354
%D \definetype[TeXcodeB][option=TEX,compact=all]
355
%D \definetype[TeXcodeC][option=TEX,compact=absolute]
356
%D
357
%D \def\argA#1{\TeXcodeA{{#1}}}
358
%D \def\argB#1{\TeXcodeB{{#1}}}
359
%D \def\argC#1{\TeXcodeC{{#1}}}
360
%D \stoptyping
361 362
%D \macros
363
%D {obeyhyphens,obeybreakpoints}
364
%D
365
%D Although it's not clear from the macros, one character trait of this macros,
366
%D which are build on top of the support module, is that they don't hyphenate. We
367
%D therefore offer the alternative \type{\typ}. The current implementation works all
368
%D right, but a decent hyphenation support of \type{\tt} text will be implemented
369
%D soon.
370 371
\unexpanded
\def
\specialfixedspace
{
\kern
\interwordspace
\relax
}
372
\unexpanded
\def
\specialobeyedspace
{
\hskip
\interwordspace
\relax
}
% better than spaceskip
373
\unexpanded
\def
\specialstretchedspace
{
\hskip
.
5
\interwordspace
\s!plus
.
1
2
5
\interwordspace
\relax
}
% \interwordstretch can be zero
374
\unexpanded
\def
\specialcontrolspace
{
\normalcontrolspace
\allowbreak
}
% uses fallback
375 376
\unexpanded
\def
\explicitfixedspace
{
\asciispacechar
}
377
\unexpanded
\def
\explicitobeyedspace
{
\asciispacechar
\allowbreak
}
378
\unexpanded
\def
\explicitstretchedspace
{
\asciispacechar
\hskip
\zeropoint
\s!plus
.
1
2
5
\interwordspace
\relax
}
%
379
\unexpanded
\def
\explicitcontrolspace
{
\optionalcontrolspace
\allowbreak
}
% uses asciispace
380 381
\appendtoks
382
\unexpanded
\def
\obeyedspace
{
\hskip
\zeropoint\asciispacechar
\hskip
\zeropoint
}
%
383
\to
\everyenableelements
384 385
\unexpanded
\def
\obeyhyphens
386
{
\let
\obeyedspace
\specialobeyedspace
% maybe \specialstretchedspace
387
\let
\controlspace
\specialcontrolspace
388
\spaceskip
.
2
5
\emwidth
\relax
}
% hm a bit of stretch !
389 390
\unexpanded
\def
\obeybreakpoints
391
{
\ignorehyphens
392
\veryraggedright
}
393 394
\unexpanded
\def
\ignorehyphens
395
{
\language
\minusone
% extra bonus, the \null should do the job too
396
\let
\obeyedspace
\specialobeyedspace
397
\let
\controlspace
\specialcontrolspace
398
\spaceskip
.
5
\emwidth
\relax
}
399 400
%D \macros
401
%D {tex,arg,mat,dis,astype}
402
%D
403
%D Sometimes, for instance when we pass verbatim text as an argument, the fixed
404
%D \CATCODES\ interfere with our wishes. An experimental implementation of character
405
%D by character processing of verbatim text did overcome this limitation, but we've
406
%D decided not to use that slow and sometimes troublesome solution. Instead we stick
407
%D to some 'old' \CONTEXT\ macros for typesetting typical \TEX\ characters.
408 409
\def
\lesscharacter
{
<
}
% obsolete
410
\def
\morecharacter
{
>
}
% obsolete
411 412
\let
\texescape
\textbackslash
413
\let
\leftargument
\textbraceleft
414
\let
\rightargument
\textbraceright
415
\let
\inlinemathmarker
\textdollar
416
\def
\displaymathmarker
{
\textdollar\textdollar
}
417 418
\def
\buff_verbatim_special_type
#
1
#
2
#
% # gobbles spaces
419
{
\dontleavehmode
\bgroup
420
\buff_verbatim_initialize_type_one
421
\catcode
\leftbraceasciicode
\begingroupcatcode
422
\catcode
\rightbraceasciicode\endgroupcatcode
423
#
1
%
424
\bgroup
% else wrong font for #2
425
\aftergroup
#
2
%
426
\aftergroup
\egroup
427
\let
\nexttoken
}
428 429
\unexpanded
\def
\tex
{
\buff_verbatim_special_type
\texescape
\relax
}
430
\unexpanded
\def
\arg
{
\buff_verbatim_special_type
\leftargument
\rightargument
}
431
\unexpanded
\def
\mat
{
\buff_verbatim_special_type
\inlinemathmarker
\inlinemathmarker
}
432
\unexpanded
\def
\dis
{
\buff_verbatim_special_type
\displaymathmarker
\displaymathmarker
}
433 434
\let
\normaltexttex
\tex
435
\let
\normaltextarg
\arg
436
\let
\normaltextmat
\mat
437
\let
\normaltextdis
\dis
438 439
\unexpanded
\def
\astype
440
{
\dontleavehmode
441
\bgroup
\usetypestyleandcolor
\c!style\c!color
\let
\nexttoken
}
442 443
\unexpanded
\def
\asciistr
#
1
% used in some old styles
444
{
\dontleavehmode
\begingroup
445
\dostarttagged
\t!verbatim
\empty
446
\usetypestyleandcolor
\c!style\c!color
\detokenize
{
#
1
}
%
447
\dostoptagged
448
\endgroup
}
449 450
%D The basic display verbatim commands are defined in an indirect way. As we
451
%D will see, they are a specific case of a more general mechanism.
452 453
\let
\beginofverbatimlines
\relax
% hooks
454
\let
\endofverbatimlines
\relax
% hooks
455 456
\unexpanded
\def
\buff_verbatim_typing_start
#
1
% tricky non standard lookahead
457
{
\begingroup
458
\edef
\currenttyping
{
#
1
}
%
459
\obeylines
460
\futureexpandis
[
\buff_verbatim_typing_start_yes
\buff_verbatim_typing_start_nop
}
461 462
\unexpanded
\def
\buff_verbatim_setup_keep_together
463
{
\edef
\p_keeptogether
{
\typingparameter
\c!keeptogether
}
%
464
\ifx
\p_keeptogether
\v!yes
465
\settrue
\c_buff_optimize_linebreaks
466
\else
467
\setfalse
\c_buff_optimize_linebreaks
468
\fi
}
469 470
\def
\buff_verbatim_typing_start_nop
471
{
\typingparameter
\c!before
472
\startpacked
[
\v!blank
]
%
473
\buff_verbatim_setup_line_numbering
474
\buff_verbatim_initialize_typing_one
475
\buff_verbatim_setup_keep_together
476
\normalexpanded
{
\buff_verbatim_type_block
{
\e!start
\currenttyping
}{
\e!stop
\currenttyping
}}}
477 478
\def
\buff_verbatim_typing_start_yes
[#
1
]
%
479
{
\typingparameter
\c!before
480
\startpacked
[
\v!blank
]
%
481
\ifcondition
\validassignment
{
#
1
}
%
482
\setupcurrenttyping
[#
1
]
%
483
\else
484
\doif
\v!continue
{
#
1
}{
\lettypingparameter
\c!continue\v!yes
}
%
485
\fi
486
\buff_verbatim_setup_line_numbering
487
\buff_verbatim_initialize_typing_one
488
\buff_verbatim_setup_keep_together
489
\normalexpanded
{
\buff_verbatim_type_block
{
\e!start
\currenttyping
}{
\e!stop
\currenttyping
}}}
490 491
\unexpanded
\def
\buff_verbatim_type_block
#
1
#
2
%
492
{
\edef
\p_strip
{
\typingparameter
\c!strip
}
%
493
\normalexpanded
{
\buff_pickup
494
{
_
typing
_
}
%
495
{
#
1
}
%
496
{
#
2
}
%
497
{}
%
498
{
\buff_verbatim_type_block_verbatim_indeed
{
#
1
}{
#
2
}}
%
499
\ifx
\p_strip
\v!no
\zerocount
\else
\plusone
\fi
}}
500 501
\unexpanded
\def
\buff_verbatim_type_block_verbatim_indeed
#
1
#
2
%
502
{
\buff_verbatim_initialize_typing_two
503
\dostarttaggedchained
\t!verbatimblock
\currenttyping
\??typing
504
\beginofverbatimlines
505
\dostarttagged
\t!verbatimlines
\empty
506
\clf_typebuffer
507
name
{
_
typing
_
}
%
508
strip
{
\typingparameter
\c!strip
}
%
509
range
{
\typingparameter
\c!range
}
%
510
tab
{
\typingparameter
\c!tab
}
%
511
method
{
\p_buff_option
}
%
512
escape
{
\typingparameter
\c!escape
}
%
513
nature
{
display
}
%
514
\relax
515
\dostoptagged
516
\endofverbatimlines
517
\dostoptagged
518
\begincsname
#
2
\endcsname
}
519 520
\unexpanded
\def
\buff_verbatim_typing_stop
#
1
% hm, currenttyping
521
{
\stoppacked
522
\typingparameter
\c!after
523
\useindentnextparameter
\typingparameter
524
\endgroup
525
\dorechecknextindentation
}
526 527
%D Line numbering for files is combined with filtering, while display verbatim has
528
%D the ability to continue.
529
%D
530
%D \starttyping
531
%D \typefile[numbering=file,start=10,stop=12]{test.tex}
532
%D
533
%D \definetyping[code][numbering=line]
534
%D
535
%D \starttext
536
%D \startcode
537
%D ...
538
%D ...
539
%D \stopcode
540
%D
541
%D \startcode[start=continue]
542
%D ...
543
%D ...
544
%D \stopcode
545
%D
546
%D \startcode[start=10]
547
%D ...
548
%D \stopcode
549
%D \stoptyping
550 551
%D Ranges:
552
%D
553
%D \starttyping
554
%D % label:start:one
555
%D
556
%D \def\MyMacro
557
%D {just an example}
558
%D
559
%D % label:stop:one
560
%D
561
%D \starttext
562
%D
563
%D % \typefile[file][range={3,6}] {whatever.tex}
564
%D % \typefile[file][range={3,+2}]{whatever.tex}
565
%D
566
%D \typefile[file][range={label:start:one,label:stop:one}]{whatever.tex}
567
%D
568
%D \stoptext
569
%D \stoptyping
570 571
%D \macros
572
%D {typefile}
573
%D
574
%D Typesetting files verbatim (for the moment) only supports colorization of \TEX\
575
%D sources as valid option. The other setup values are inherited from display
576
%D verbatim. The implementation of \type {\typefile} is straightforward:
577 578
% [category] [settings] {name} % for historic reasons, all filenames are {}
579 580
\unexpanded
\def
\typefile
581
{
\dodoubleempty
\buff_verbatim_type_file
}
582 583
\appendtoks
584
\setuevalue
{
\e!type
\currenttyping
\v!file
}{
\typefile
[
\currenttyping
]
}
%
585
\to
\everydefinetyping
586 587
\def
\buff_verbatim_type_file
[#
1
][#
2
]#
3
%
588
{
\begingroup
589
\ifsecondargument
590
\setuptyping
[#
1
][#
2
]
%
591
\buff_verbatim_type_file_checked
{
#
1
}{
#
3
}
%
592
\orelse
\iffirstargument
593
\ifcondition
\validassignment
{
#
1
}
%
594
\setuptyping
[
\v!file
][#
1
]
%
595
\buff_verbatim_type_file_checked
\v!file
{
#
3
}
%
596
\else
597
\buff_verbatim_type_file_checked
{
#
1
}{
#
3
}
%
598
\fi
599
\else
600
\buff_verbatim_type_file_checked
\v!file
{
#
3
}
%
601
\fi
602
\useindentnextparameter
\typingparameter
% needs checking
603
\endgroup
604
\dorechecknextindentation
}
% needs checking
605 606
\def
\buff_verbatim_type_file_checked
#
1
#
2
%
607
{
\doifelsetypingfile
{
#
2
}
608
{
\buff_verbatim_type_file_indeed
{
#
1
}
\askedtypingfile
}
609
{
\showmessage
\m!verbatims
1
{
#
2
}}}
610 611
\unexpanded
\def
\doifelsetypingfile
#
1
%
612
{
\edef
\askedtypingfile
{
\locfilename
{
#
1
}}
%
613
\ifempty
\askedtypingfile
614
\edef
\askedtypingfile
{
\locfilename
{
#
1
.
tex
}}
% downward compatible
615
\fi
616
\ifempty
\askedtypingfile
617
\expandafter
\secondoftwoarguments
618
\else
619
\expandafter
\firstoftwoarguments
620
\fi
}
621 622
\let
\doiftypingfileelse\doifelsetypingfile
623 624
\def
\buff_verbatim_type_file_indeed
#
1
#
2
% category name
625
{
\edef
\currenttyping
{
#
1
}
%
626
\typingparameter
\c!before
627
\startpacked
[
\v!blank
]
628
\buff_verbatim_setup_line_numbering
629
\buff_verbatim_initialize_typing_one
630
\buff_verbatim_initialize_typing_two
631
\dostarttaggedchained
\t!verbatimblock
\currenttyping
\??typing
632
\beginofverbatimlines
633
\dostarttagged
\t!verbatimlines
\empty
634
\clf_typefile
635
name
{
#
2
}
%
636
strip
{
\typingparameter
\c!strip
}
%
637
range
{
\typingparameter
\c!range
}
%
638
regime
{
\currentregime
}
%
639
tab
{
\typingparameter
\c!tab
}
%
640
method
{
\p_buff_option
}
%
641
nature
{
display
}
%
642
\relax
643
\dostoptagged
644
\endofverbatimlines
645
\dostoptagged
646
\stoppacked
647
\typingparameter
\c!after
}
648 649
%D Line numbering:
650 651
\newconditional
\verbatimnumberinglines
652 653
\def
\beginofverbatimlinenumbering
654
{
\startlinenumbering
655
[
\currenttyping
]
%
656
[
\c!continue
=
\typingparameter
\c!continue
,
657
\c!method
=
\v!type
,
658
\c!start
=
\typingparameter
\c!start
,
659
\c!stop
=
\typingparameter
\c!stop
,
% ?
660
\c!step
=
\typingparameter
\c!step
]
}
661 662
\def
\endofverbatimlinenumbering
663
{
\stoplinenumbering
}
664 665
\def
\buff_verbatim_setup_line_numbering
666
{
\ifdefined
\startlinenumbering
667
\edef
\currenttypingnumbering
{
\typingparameter
\c!numbering
}
%
668
\ifx
\currenttypingnumbering
\v!file
669
\setuplinenumbering
[
\currenttyping
][
\c!method
=
\v!file
]
%
670
\settrue
\verbatimnumberinglines
671
\orelse\ifx
\currenttypingnumbering
\v!line
672
\settrue
\verbatimnumberinglines
673
\else
674
\setfalse
\verbatimnumberinglines
675
\fi
676
\ifconditional
\verbatimnumberinglines
677
\let
\beginofverbatimlines
\beginofverbatimlinenumbering
678
\let
\endofverbatimlines
\endofverbatimlinenumbering
679
\fi
680
\fi
}
681 682
%D \macros
683
%D {filename}
684
%D
685
%D Typesetting filenames in monospaced fonts is possible with
686
%D
687
%D \starttyping
688
%D \filename{here/there/filename.suffix}
689
%D \stoptyping
690
%D
691
%D The definition is not that spectacular.
692 693
\unexpanded
\def
\filename
#
1
{{
\tttf
\hyphenatedfilename
{
#
1
}}}
694 695
%D \macros
696
%D {verbatim}
697
%d
698
%D And a bonus macro, an unexpanded detokenize:
699 700
\unexpanded
\def
\verbatim
#
1
{
\detokenize
{
#
1
}}
701 702
%D The setups for display verbatim and file verbatim are shared. One can adapt the
703
%D extra defined typing environments, but they also default to the values below.
704
%D Watch the alternative escape character.
705 706
% \tttf gives problems with {\tx \type...}
707
% \tt\tf does not adapt to e.g. \bf
708 709
\setuptyping
710
[
\c!before
=
\blank
,
711
\c!after
=
\blank
,
712
%\c!keeptogether=yes, % this will become default (when tested enough)
713
%\c!bodyfont=,
714
%\c!color=,
715
\c!space
=
\v!off
,
716
\c!lines
=
\v!no
,
717
\c!page
=
\v!no
,
718
\c!tab
=
\v!yes
,
% what is this: \s!ascii ?
719
\c!option
=
\v!none
,
720
\c!text
=
\v!no
,
721
\c!style
=
\tt
,
722
\c!indentnext
=
\v!yes
,
723
\c!margin
=
\zeropoint
,
724
\c!evenmargin
=
\zeropoint
,
725
\c!oddmargin
=
\zeropoint
,
726
\c!blank
=
\v!line
,
727
%\c!escape=, % yes | no | {START,STOP} | default when yes: {BTEX,ETEX}
728
\c!numbering
=
\v!no
,
729
%\c!range=,
730
\c!start
=
1
,
731
%\c!stop=,
732
\c!step
=
1
,
733
%\c!continue=,
734
\c!strip
=
\v!no
]
% auto or number
735 736
\definetyping
[
\v!typing
]
737 738
% the \zeropoint forces the number to the margin but also works ok in text
739 740
\setuplinenumbering
[
\v!typing
][
\c!location
=
\v!left
,
\c!width
=
\zeropoint
]
741 742
\setuptyping
[
\v!file
]
[
\s!parent
=
\??typing
\v!typing
]
% we don't want \start..\stop overload
743
\setuplinenumbering
[
\v!file
]
[
\s!parent
=
\??linenumbering\v!typing
]
744 745
\setuptyping
[
\v!buffer
][
\s!parent
=
\??typing
\v!file
]
% we don't want \start..\stop overload
746
\setuplinenumbering
[
\v!buffer
][
\s!parent
=
\??linenumbering\v!file
]
747 748
%D The setups for inline verbatim default to:
749 750
\setuptype
751
[
\c!space
=
\v!off
,
752
\c!lines
=
\v!no
,
753
%\c!color=,
754
\c!style
=
\tt
,
755
%\c!option=\v!normal,
756
\c!page
=
\v!no
,
757
\c!tab
=
\v!yes
,
758
\c!compact
=
\v!all
]
759 760
%D Buffers
761 762
% [name] [settings] | [name] | [settings]
763 764
% \unexpanded\def\typebuffer
765
% {\dodoubleempty\buff_verbatim_type_buffer}
766 767
\unexpanded
\def
\typebuffer
768
{
\begingroup
769
\let
\currenttyping
\v!buffer
770
\dodoubleempty
\buff_verbatim_type_buffer
}
771 772
\unexpanded
\def
\buff_verbatim_type_defined_buffer
773
{
\dotripleempty
\buff_verbatim_type_defined_buffer_indeed
}
774 775
\unexpanded
\def
\typedefinedbuffer
[#
1
]
%
776
{
\buff_verbatim_type_defined_buffer
[
\v!buffer
][
\thedefinedbuffer
{
#
1
}
]
}
%
777 778
\appendtoks
779
\setuevalue
{
\e!type
\currentbuffer
}{
\buff_verbatim_type_defined_buffer
[
\v!buffer
][
\currentdefinedbuffer
]
}
%
780
\to
\everydefinebuffer
781 782
\appendtoks
% \e!buffer
783
\setuevalue
{
\e!type
\currenttyping
\v!buffer
}{
\buff_verbatim_type_buffer_class
{
\currenttyping
}}
%
784
\to
\everydefinetyping
785 786
\unexpanded
\def
\buff_verbatim_type_buffer
[#
1
][#
2
]
%
787
{
\ifsecondargument
788
\setupcurrenttyping
[#
2
]
%
789
\processcommalist
[#
1
]
{
\buff_verbatim_type_buffer_indeed
\currenttyping
}
% [name] [settings]
790
\orelse
\iffirstargument
791
\ifcondition
\validassignment
{
#
1
}
%
792
\setupcurrenttyping
[#
1
]
%
793
\buff_verbatim_type_buffer_indeed
\currenttyping
\empty
% [settings]
794
\else
795
\processcommalist
[#
1
]
{
\buff_verbatim_type_buffer_indeed
\currenttyping
}
% [name]
796
\fi
797
\else
798
\buff_verbatim_type_buffer_indeed
\currenttyping
\empty
% []
799
\fi
800
\endgroup
801
\dorechecknextindentation
}
802 803
\unexpanded
\def
\buff_verbatim_type_buffer_class
#
1
%
804
{
\begingroup
805
\edef
\currenttyping
{
#
1
}
%
806
\dodoubleempty
\buff_verbatim_type_buffer
}
807 808
\unexpanded
\def
\buff_verbatim_type_defined_buffer_indeed
[#
1
][#
2
][#
3
]
% category name settings
809
{
\begingroup
810
\ifthirdargument
811
\setuptyping
[#
1
][#
3
]
%
812
\fi
813
\buff_verbatim_type_buffer_indeed
{
#
1
}{
#
2
}
%
814
\endgroup
}
815 816
\unexpanded
\def
\buff_verbatim_type_buffer_indeed
#
1
#
2
% category name
817
{
\edef
\currenttyping
{
#
1
}
%
818
\typingparameter
\c!before
819
\startpacked
[
\v!blank
]
820
\buff_verbatim_setup_line_numbering
821
\buff_verbatim_initialize_typing_one
822
\buff_verbatim_initialize_typing_two
823
\dostarttaggedchained
\t!verbatimblock
{
#
1
}
\??typing
824
\beginofverbatimlines
825
\dostarttagged
\t!verbatimlines
\empty
826
\clf_typebuffer
827
name
{
#
2
}
%
828
strip
{
\typingparameter
\c!strip
}
%
829
range
{
\typingparameter
\c!range
}
%
830
regime
{
\currentregime
}
%
831
tab
{
\typingparameter
\c!tab
}
%
832
method
{
\p_buff_option
}
%
833
escape
{
\typingparameter
\c!escape
}
%
834
nature
{
display
}
%
835
\relax
836
\dostoptagged
837
\endofverbatimlines
838
\dostoptagged
839
\stoppacked
840
\typingparameter
\c!after
841
\dorechecknextindentation
}
842 843
\unexpanded
\def
\typeinlinebuffer
844
{
\dontleavehmode
845
\begingroup
846
\let
\buff_verbatim_type_buffer_indeed
\buff_verbatim_type_buffer_indeed_inline
847
\let
\setupcurrenttyping
\setupcurrenttype
% a terrible hack but it saves code
848
\let
\currenttype
\empty
849
\dodoubleempty
\buff_verbatim_type_buffer
}
850 851
\unexpanded
\def
\buff_verbatim_type_buffer_indeed_inline
#
1
#
2
% category name
852
{
\edef
\currenttype
{
#
1
}
%
853
\buff_verbatim_initialize_type_one
854
\dostarttaggedchained
\t!verbatim
\currenttype
\??type
855
\clf_typebuffer
856
name
{
#
2
}
%
857
strip
{
\v!yes
}
%
858
regime
{
\currentregime
}
%
859
method
{
\p_buff_option
}
%
860
nature
{
inline
}
% is default anyway
861
\relax
862
\dostoptagged
}
863 864
% get : before/after of buffer
865
% typing : before/after of typing
866
% process : no before/after (special case anyway)
867 868
% the next one is obsolete (bad name and used nowhere) so if it stays
869
% the name will change
870 871
\unexpanded
\def
\processbuffer
872
{
\writestatus
{
nota
bene
}{
\string
\processbuffer
\space
is
obsolete
}
%
873
\dodoubleempty
\buff_verbatim_process
}
874 875
\def
\buff_verbatim_process
[#
1
][#
2
]
%
876
{
\begingroup
877
\ifsecondargument
878
\setuptyping
[
\v!buffer
][#
2
]
%
879
\processcommalist
[#
1
]
{
\buff_verbatim_process_indeed
\v!buffer
}
% [name] [settings]
880
\orelse
\iffirstargument
881
\ifcondition
\validassignment
{
#
1
}
%
882
\setuptyping
[
\v!buffer
][#
1
]
%
883
\buff_verbatim_process_indeed
\v!buffer
\empty
% [settings]
884
\else
885
\processcommalist
[#
1
]
{
\buff_verbatim_process_indeed
\v!buffer
}
% [name]
886
\fi
887
\else
888
\buff_verbatim_process_indeed
\v!buffer
\empty
% []
889
\fi
890
\endgroup
}
891 892
\def
\buff_verbatim_process_indeed
#
1
#
2
%
893
{
\edef
\currenttyping
{
#
1
}
%
894
\clf_processbuffer
895
name
{
#
2
}
%
896
strip
{
\typingparameter
\c!strip
}
%
897
tab
{
\typingparameter
\c!tab
}
%
898
% method {\p_buff_option}%
899
nature
{
direct
}
%
900
\relax
}
901 902
% so far for obsolete
903 904
% line numbering, keep broken lines together
905 906
\newcount
\nofverbatimlines
907 908
\unexpanded
\def
\buff_verbatim_begin_of_line
909
{
\ifconditional
\verbatimnumberinglines
910
\global\advance
\nofverbatimlines
\plusone
911
\c_attr_verbatimline
\nofverbatimlines
912
\fi
913
\noindent
914
\buff_verbatim_set_line_margin
915
\the
\everyline
% maybe also after starttagged
916
\strut
% after starttagged, else break !
917
\dostarttagged
\t!verbatimline
\empty
918
}
919 920
\unexpanded
\def
\buff_verbatim_end_of_line
921
{
\dostoptagged
922
\obeyedline
% still needed?
923
\par
924
\ifconditional
\verbatimnumberinglines
925
\c_attr_verbatimline
\attributeunsetvalue
926
\fi
}
927 928
\unexpanded
\def
\buff_verbatim_empty_line
929
{
\dostoptagged
930
\ifconditional
\verbatimnumberinglines
931
\par
\strut
\par
% this will be an option where we use a signal instead of a strut
932
\else
933
\blank
[
\typingparameter
\c!blank
]
%
934
\fi
935
\dostarttagged
\t!verbatimlines
\empty
}
936 937
% hooks:
938 939
\newcount
\c_buff_verbatim_noflines
940
\newcount
\c_buff_verbatim_current
941
\newconditional
\c_buff_optimize_linebreaks
942 943
\def
\doverbatimspace
{
\obeyedspace
}
944 945
\unexpanded
\def
\doinlineverbatimstart
{}
946
\unexpanded
\def
\doinlineverbatimstop
{}
947
\unexpanded
\def
\doinlineverbatimbeginline
{}
948
\unexpanded
\def
\doinlineverbatimnewline
{
\obeyedspace
}
949
\unexpanded
\def
\doinlineverbatimemptyline
{
\obeyedspace
}
950 951
\unexpanded
\def
\dodisplayverbatimstart
{
\advance
\c_buff_verbatim_current
\plusone
952
\buff_verbatim_begin_of_line
}
953
\unexpanded
\def
\dodisplayverbatimstop
{
\buff_verbatim_end_of_line
}
954
\unexpanded
\def
\dodisplayverbatimbeginline
{
\advance
\c_buff_verbatim_current
\plusone
955
\buff_verbatim_begin_of_line
}
956
\unexpanded
\def
\dodisplayverbatimnewline
{
\buff_verbatim_end_of_line
957
\par
958
\ifconditional
\c_buff_optimize_linebreaks
959
\buff_verbatim_inject_breaks
960
\fi
}
961
\unexpanded
\def
\dodisplayverbatimemptyline
{
\buff_verbatim_empty_line
}
962 963
\unexpanded
\def
\buff_verbatim_inject_breaks
964
{
\ifnum
\c_buff_verbatim_current
=
\plusone
965
\nobreak
966
\orelse\ifnum
\c_buff_verbatim_noflines
=
\plusthree
967
\nobreak
968
\orelse\ifnum
\c_buff_verbatim_current
=
\numexpr
\c_buff_verbatim_noflines
-
\plusone
\relax
969
\nobreak
970
\fi
}
971 972
\unexpanded
\def
\dodisplayverbatiminitialize
#
1
%
973
{
\forgetparindent
% maybe more
974
\c_buff_verbatim_noflines
#
1
\relax
975
\c_buff_verbatim_current
\zerocount
}
976 977
\loadmarkfile
{
buff
-
imp
-
default
}
% preloaded as otherwise spurious spaces inline due to loading
978
\loadmarkfile
{
buff
-
imp
-
nested
}
% preloaded as otherwise spurious spaces inline due to loading
979
\loadmarkfile
{
buff
-
imp
-
escaped
}
% for completeness
980 981
%D To be considered:
982 983
% \installcorenamespace{visualizer}
984
%
985
% \installcommandhandler \??visualizer {visualizer} \??visualizer
986
%
987
% \appendtoks
988
% \setuevalue{\currentvisualizer}{\buff_verbatim_visualize{\currentvisualizer}}%
989
% \to \everydefinevisualizer
990
%
991
% \unexpanded\def\buff_verbatim_visualize#1%
992
% {\bgroup
993
% \def\currentvisualizer{#1}%
994
% \usevisualizerstyleandcolor\c!style\c!color
995
% \let\next}
996 997
\appendtoks
998
%def\type#1{\letterbackslash\checkedstrippedcsname#1}% or maybe detokenize
999
\def
\type
#
1
{
\detokenize\expandafter
{
\csstring
#
1
}}
% or maybe detokenize
1000
\def
\tex
#
1
{
\letterbackslash
#
1
}
%
1001
\to
\everysimplifycommands
1002 1003
\stopcontextdefinitioncode
1004 1005
%D This is \type {\asciimode} without the double comment hackery:
1006 1007
\unexpanded
\def
\literalmode
{
\setcatcodetable
\txtcatcodes
}
1008 1009
\protect
\endinput
1010