buff-ver.mkiv /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
\else\ifx
\p_buff_option
\empty
82
\usetypestyleandcolor
\c!style\c!color
83
\else
84
\usetypestyleparameter
\c!style
% no color
85
\fi\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
\else\ifx
\p_buff_option
\empty
124
\usetypingstyleandcolor
\c!style\c!color
125
\else
126
\usetypingstyleparameter
\c!style
% no color !
127
\fi\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
\ifx
\currenttypingparent
\empty
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
\futurelet
\next
\buff_verbatim_type_one
}
290 291
\def
\buff_verbatim_type_one
292
{
\ifx
\next
\bgroup
293
\expandafter
\buff_verbatim_type_a
294
\else
295
\expandafter
\buff_verbatim_type_two
296
\fi
}
297 298
\def
\buff_verbatim_type_two
299
{
\catcode
`
<=
\othercatcode
% old precaution
300
\catcode
`
>=
\othercatcode
% old precaution
301
\futurelet
\next
\buff_verbatim_type_three
}
302 303
\def
\buff_verbatim_type_three
304
{
\if
\next
<
%
305
\expandafter
\buff_verbatim_type_b
306
\else
307
\expandafter
\buff_verbatim_type_c
308
\fi
}
309 310
\def
\buff_verbatim_type_a
311
{
\buff_verbatim_initialize_type_one
312
\setcatcodetable
\tpacatcodes
313
\buff_verbatim_type_normal
}
314 315
\def
\buff_verbatim_type_b
#
1
%
316
{
\buff_verbatim_initialize_type_one
317
\setcatcodetable
\tpbcatcodes
318
\buff_verbatim_type_nested
}
319 320
\def
\buff_verbatim_type_c
#
1
%
321
{
\buff_verbatim_initialize_type_one
322
\setcatcodetable
\vrbcatcodes
323
\def
\next
##
1
#
1
{
\buff_verbatim_type_normal
{
##
1
}}
%
324
\next
}
325 326
\def
\buff_verbatim_type_normal
#
1
%
327
{
\buff_verbatim_initialize_type_two
328
\dostarttaggedchained
\t!verbatim
\currenttype
\??type
329
\clf_type
330
data
{
\detokenize
{
#
1
}}
%
331
tab
{
\typeparameter
\c!tab
}
%
332
method
{
\p_buff_option
}
%
333
compact
{
\typeparameter
\c!compact
}
% % none | all | last (all needed in tabulate etc for manuals)
334
escape
{
\typeparameter
\c!escape
}
% % new but rather useless imo (escaping in general is not used much)
335
% nature {inline}% is default
336
\relax
337
\dostoptagged
338
\buff_verbatim_right_of_type
339
\egroup
}
340 341
\def
\buff_verbatim_type_nested
#
1
%
342
{
\buff_verbatim_initialize_type_two
343
\dostarttaggedchained
\t!verbatim
\currenttype
\??type
344
\clf_type
345
data
{
\detokenize
{
#
1
}}
%
346
tab
{
\typeparameter
\c!tab
}
%
347
method
{
\p_buff_option
}
% % extra visualizer (maybe: nested,\typeparameter\c!option)
348
escape
{
\typeparameter
\c!escape
}
% % new but rather useless imo (escaping in general is not used much)
349
% nature {inline}% is default
350
method
{
nested
}
%
351
\relax
352
\dostoptagged
353
\buff_verbatim_right_of_type
354
\egroup
355
\gobbleoneargument
}
% grab last >
356 357
%D The \type {compact} option can come in handy in the case of inline argument passing
358
%D
359
%D \starttyping
360
%D \definetype[TeXcodeA][option=TEX]
361
%D \definetype[TeXcodeB][option=TEX,compact=all]
362
%D \definetype[TeXcodeC][option=TEX,compact=absolute]
363
%D
364
%D \def\argA#1{\TeXcodeA{{#1}}}
365
%D \def\argB#1{\TeXcodeB{{#1}}}
366
%D \def\argC#1{\TeXcodeC{{#1}}}
367
%D \stoptyping
368 369
%D \macros
370
%D {obeyhyphens,obeybreakpoints}
371
%D
372
%D Although it's not clear from the macros, one character trait of this macros,
373
%D which are build on top of the support module, is that they don't hyphenate. We
374
%D therefore offer the alternative \type{\typ}. The current implementation works all
375
%D right, but a decent hyphenation support of \type{\tt} text will be implemented
376
%D soon.
377 378
\unexpanded
\def
\specialfixedspace
{
\kern
\interwordspace
\relax
}
379
\unexpanded
\def
\specialobeyedspace
{
\hskip
\interwordspace
\relax
}
% better than spaceskip
380
\unexpanded
\def
\specialstretchedspace
{
\hskip
.
5
\interwordspace
\s!plus
.
1
2
5
\interwordspace
\relax
}
% \interwordstretch can be zero
381
\unexpanded
\def
\specialcontrolspace
{
\normalcontrolspace
\allowbreak
}
% uses fallback
382 383
\unexpanded
\def
\explicitfixedspace
{
\asciispacechar
}
384
\unexpanded
\def
\explicitobeyedspace
{
\asciispacechar
\allowbreak
}
385
\unexpanded
\def
\explicitstretchedspace
{
\asciispacechar
\hskip
\zeropoint
\s!plus
.
1
2
5
\interwordspace
\relax
}
%
386
\unexpanded
\def
\explicitcontrolspace
{
\optionalcontrolspace
\allowbreak
}
% uses asciispace
387 388
\appendtoks
389
\unexpanded
\def
\obeyedspace
{
\hskip
\zeropoint\asciispacechar
\hskip
\zeropoint
}
%
390
\to
\everyenableelements
391 392
\unexpanded
\def
\obeyhyphens
393
{
\let
\obeyedspace
\specialobeyedspace
% maybe \specialstretchedspace
394
\let
\controlspace
\specialcontrolspace
395
\spaceskip
.
2
5
\emwidth
\relax
}
% hm a bit of stretch !
396 397
\unexpanded
\def
\obeybreakpoints
398
{
\ignorehyphens
399
\veryraggedright
}
400 401
\unexpanded
\def
\ignorehyphens
402
{
\language
\minusone
% extra bonus, the \null should do the job too
403
\let
\obeyedspace
\specialobeyedspace
404
\let
\controlspace
\specialcontrolspace
405
\spaceskip
.
5
\emwidth
\relax
}
406 407
%D \macros
408
%D {tex,arg,mat,dis,astype}
409
%D
410
%D Sometimes, for instance when we pass verbatim text as an argument, the fixed
411
%D \CATCODES\ interfere with our wishes. An experimental implementation of character
412
%D by character processing of verbatim text did overcome this limitation, but we've
413
%D decided not to use that slow and sometimes troublesome solution. Instead we stick
414
%D to some 'old' \CONTEXT\ macros for typesetting typical \TEX\ characters.
415 416
\def
\lesscharacter
{
<
}
% obsolete
417
\def
\morecharacter
{
>
}
% obsolete
418 419
\let
\texescape
\textbackslash
420
\let
\leftargument
\textbraceleft
421
\let
\rightargument
\textbraceright
422
\let
\inlinemathmarker
\textdollar
423
\def
\displaymathmarker
{
\textdollar\textdollar
}
424 425
\def
\buff_verbatim_special_type
#
1
#
2
#
% # gobbles spaces
426
{
\dontleavehmode
\bgroup
427
\buff_verbatim_initialize_type_one
428
\catcode
\leftbraceasciicode
\begingroupcatcode
429
\catcode
\rightbraceasciicode\endgroupcatcode
430
#
1
%
431
\bgroup
% else wrong font for #2
432
\aftergroup
#
2
%
433
\aftergroup
\egroup
434
\let
\nexttoken
}
435 436
\unexpanded
\def
\tex
{
\buff_verbatim_special_type
\texescape
\relax
}
437
\unexpanded
\def
\arg
{
\buff_verbatim_special_type
\leftargument
\rightargument
}
438
\unexpanded
\def
\mat
{
\buff_verbatim_special_type
\inlinemathmarker
\inlinemathmarker
}
439
\unexpanded
\def
\dis
{
\buff_verbatim_special_type
\displaymathmarker
\displaymathmarker
}
440 441
\let
\normaltexttex
\tex
442
\let
\normaltextarg
\arg
443
\let
\normaltextmat
\mat
444
\let
\normaltextdis
\dis
445 446
\unexpanded
\def
\astype
447
{
\dontleavehmode
448
\bgroup
\usetypestyleandcolor
\c!style\c!color
\let
\nexttoken
}
449 450
\unexpanded
\def
\asciistr
#
1
% used in some old styles
451
{
\dontleavehmode
\begingroup
452
\dostarttagged
\t!verbatim
\empty
453
\usetypestyleandcolor
\c!style\c!color
\detokenize
{
#
1
}
%
454
\dostoptagged
455
\endgroup
}
456 457
%D The basic display verbatim commands are defined in an indirect way. As we
458
%D will see, they are a specific case of a more general mechanism.
459 460
\let
\beginofverbatimlines
\relax
% hooks
461
\let
\endofverbatimlines
\relax
% hooks
462 463
\unexpanded
\def
\buff_verbatim_typing_start
#
1
% tricky non standard lookahead
464
{
\begingroup
465
\edef
\currenttyping
{
#
1
}
%
466
\obeylines
467
\futurelet
\nexttoken
\buff_verbatim_typing_start_indeed
}
468 469
\def
\buff_verbatim_typing_start_indeed
470
{
\ifx
\nexttoken
[
%
471
\expandafter
\buff_verbatim_typing_start_yes
472
\else
473
\expandafter
\buff_verbatim_typing_start_nop
474
\fi
}
475 476
\unexpanded
\def
\buff_verbatim_setup_keep_together
477
{
\edef
\p_keeptogether
{
\typingparameter
\c!keeptogether
}
%
478
\ifx
\p_keeptogether
\v!yes
479
\settrue
\c_buff_optimize_linebreaks
480
\else
481
\setfalse
\c_buff_optimize_linebreaks
482
\fi
}
483 484
\def
\buff_verbatim_typing_start_nop
485
{
\typingparameter
\c!before
486
\startpacked
[
\v!blank
]
%
487
\buff_verbatim_setup_line_numbering
488
\buff_verbatim_initialize_typing_one
489
\buff_verbatim_setup_keep_together
490
\normalexpanded
{
\buff_verbatim_type_block
{
\e!start
\currenttyping
}{
\e!stop
\currenttyping
}}}
491 492
\def
\buff_verbatim_typing_start_yes
[#
1
]
%
493
{
\typingparameter
\c!before
494
\startpacked
[
\v!blank
]
%
495
\ifcondition
\validassignment
{
#
1
}
%
496
\setupcurrenttyping
[#
1
]
%
497
\else
498
\doif
\v!continue
{
#
1
}{
\lettypingparameter
\c!continue\v!yes
}
%
499
\fi
500
\buff_verbatim_setup_line_numbering
501
\buff_verbatim_initialize_typing_one
502
\buff_verbatim_setup_keep_together
503
\normalexpanded
{
\buff_verbatim_type_block
{
\e!start
\currenttyping
}{
\e!stop
\currenttyping
}}}
504 505
\unexpanded
\def
\buff_verbatim_type_block
#
1
#
2
%
506
{
\edef
\p_strip
{
\typingparameter
\c!strip
}
%
507
\normalexpanded
{
\buff_pickup
508
{
_
typing
_
}
%
509
{
#
1
}
%
510
{
#
2
}
%
511
{}
%
512
{
\buff_verbatim_type_block_verbatim_indeed
{
#
1
}{
#
2
}}
%
513
\ifx
\p_strip
\v!no
\zerocount
\else
\plusone
\fi
}}
514 515
\unexpanded
\def
\buff_verbatim_type_block_verbatim_indeed
#
1
#
2
%
516
{
\buff_verbatim_initialize_typing_two
517
\dostarttaggedchained
\t!verbatimblock
\currenttyping
\??typing
518
\beginofverbatimlines
519
\dostarttagged
\t!verbatimlines
\empty
520
\clf_typebuffer
521
name
{
_
typing
_
}
%
522
strip
{
\typingparameter
\c!strip
}
%
523
range
{
\typingparameter
\c!range
}
%
524
tab
{
\typingparameter
\c!tab
}
%
525
method
{
\p_buff_option
}
%
526
escape
{
\typingparameter
\c!escape
}
%
527
nature
{
display
}
%
528
\relax
529
\dostoptagged
530
\endofverbatimlines
531
\dostoptagged
532
\begincsname
#
2
\endcsname
}
533 534
\unexpanded
\def
\buff_verbatim_typing_stop
#
1
% hm, currenttyping
535
{
\stoppacked
536
\typingparameter
\c!after
537
\useindentnextparameter
\typingparameter
538
\endgroup
539
\dorechecknextindentation
}
540 541
%D Line numbering for files is combined with filtering, while display verbatim has
542
%D the ability to continue.
543
%D
544
%D \starttyping
545
%D \typefile[numbering=file,start=10,stop=12]{test.tex}
546
%D
547
%D \definetyping[code][numbering=line]
548
%D
549
%D \starttext
550
%D \startcode
551
%D ...
552
%D ...
553
%D \stopcode
554
%D
555
%D \startcode[start=continue]
556
%D ...
557
%D ...
558
%D \stopcode
559
%D
560
%D \startcode[start=10]
561
%D ...
562
%D \stopcode
563
%D \stoptyping
564 565
%D Ranges:
566
%D
567
%D \starttyping
568
%D % label:start:one
569
%D
570
%D \def\MyMacro
571
%D {just an example}
572
%D
573
%D % label:stop:one
574
%D
575
%D \starttext
576
%D
577
%D % \typefile[file][range={3,6}] {whatever.tex}
578
%D % \typefile[file][range={3,+2}]{whatever.tex}
579
%D
580
%D \typefile[file][range={label:start:one,label:stop:one}]{whatever.tex}
581
%D
582
%D \stoptext
583
%D \stoptyping
584 585
%D \macros
586
%D {typefile}
587
%D
588
%D Typesetting files verbatim (for the moment) only supports colorization of \TEX\
589
%D sources as valid option. The other setup values are inherited from display
590
%D verbatim. The implementation of \type {\typefile} is straightforward:
591 592
% [category] [settings] {name} % for historic reasons, all filenames are {}
593 594
\unexpanded
\def
\typefile
595
{
\dodoubleempty
\buff_verbatim_type_file
}
596 597
\appendtoks
598
\setuevalue
{
\e!type
\currenttyping
\v!file
}{
\typefile
[
\currenttyping
]
}
%
599
\to
\everydefinetyping
600 601
\def
\buff_verbatim_type_file
[#
1
][#
2
]#
3
%
602
{
\begingroup
603
\ifsecondargument
604
\setuptyping
[#
1
][#
2
]
%
605
\buff_verbatim_type_file_checked
{
#
1
}{
#
3
}
%
606
\else
\iffirstargument
607
\ifcondition
\validassignment
{
#
1
}
%
608
\setuptyping
[
\v!file
][#
1
]
%
609
\buff_verbatim_type_file_checked
\v!file
{
#
3
}
%
610
\else
611
\buff_verbatim_type_file_checked
{
#
1
}{
#
3
}
%
612
\fi
613
\else
614
\buff_verbatim_type_file_checked
\v!file
{
#
3
}
%
615
\fi\fi
616
\useindentnextparameter
\typingparameter
% needs checking
617
\endgroup
618
\dorechecknextindentation
}
% needs checking
619 620
\def
\buff_verbatim_type_file_checked
#
1
#
2
%
621
{
\doifelsetypingfile
{
#
2
}
622
{
\buff_verbatim_type_file_indeed
{
#
1
}
\askedtypingfile
}
623
{
\showmessage
\m!verbatims
1
{
#
2
}}}
624 625
\unexpanded
\def
\doifelsetypingfile
#
1
%
626
{
\edef
\askedtypingfile
{
\locfilename
{
#
1
}}
%
627
\ifx
\askedtypingfile
\empty
628
\edef
\askedtypingfile
{
\locfilename
{
#
1
.
tex
}}
% downward compatible
629
\fi
630
\ifx
\askedtypingfile
\empty
631
\expandafter
\secondoftwoarguments
632
\else
633
\expandafter
\firstoftwoarguments
634
\fi
}
635 636
\let
\doiftypingfileelse\doifelsetypingfile
637 638
\def
\buff_verbatim_type_file_indeed
#
1
#
2
% category name
639
{
\edef
\currenttyping
{
#
1
}
%
640
\typingparameter
\c!before
641
\startpacked
[
\v!blank
]
642
\buff_verbatim_setup_line_numbering
643
\buff_verbatim_initialize_typing_one
644
\buff_verbatim_initialize_typing_two
645
\dostarttaggedchained
\t!verbatimblock
\currenttyping
\??typing
646
\beginofverbatimlines
647
\dostarttagged
\t!verbatimlines
\empty
648
\clf_typefile
649
name
{
#
2
}
%
650
strip
{
\typingparameter
\c!strip
}
%
651
range
{
\typingparameter
\c!range
}
%
652
regime
{
\currentregime
}
%
653
tab
{
\typingparameter
\c!tab
}
%
654
method
{
\p_buff_option
}
%
655
nature
{
display
}
%
656
\relax
657
\dostoptagged
658
\endofverbatimlines
659
\dostoptagged
660
\stoppacked
661
\typingparameter
\c!after
}
662 663
%D Line numbering:
664 665
\newconditional
\verbatimnumberinglines
666 667
\def
\beginofverbatimlinenumbering
668
{
\startlinenumbering
669
[
\currenttyping
]
%
670
[
\c!continue
=
\typingparameter
\c!continue
,
671
\c!method
=
\v!type
,
672
\c!start
=
\typingparameter
\c!start
,
673
\c!stop
=
\typingparameter
\c!stop
,
% ?
674
\c!step
=
\typingparameter
\c!step
]
}
675 676
\def
\endofverbatimlinenumbering
677
{
\stoplinenumbering
}
678 679
\def
\buff_verbatim_setup_line_numbering
680
{
\ifdefined
\startlinenumbering
681
\edef
\currenttypingnumbering
{
\typingparameter
\c!numbering
}
%
682
\ifx
\currenttypingnumbering
\v!file
683
\setuplinenumbering
[
\currenttyping
][
\c!method
=
\v!file
]
%
684
\settrue
\verbatimnumberinglines
685
\else\ifx
\currenttypingnumbering
\v!line
686
\settrue
\verbatimnumberinglines
687
\else
688
\setfalse
\verbatimnumberinglines
689
\fi\fi
690
\ifconditional
\verbatimnumberinglines
691
\let
\beginofverbatimlines
\beginofverbatimlinenumbering
692
\let
\endofverbatimlines
\endofverbatimlinenumbering
693
\fi
694
\fi
}
695 696
%D \macros
697
%D {filename}
698
%D
699
%D Typesetting filenames in monospaced fonts is possible with
700
%D
701
%D \starttyping
702
%D \filename{here/there/filename.suffix}
703
%D \stoptyping
704
%D
705
%D The definition is not that spectacular.
706 707
\unexpanded
\def
\filename
#
1
{{
\tttf
\hyphenatedfilename
{
#
1
}}}
708 709
%D \macros
710
%D {verbatim}
711
%d
712
%D And a bonus macro, an unexpanded detokenize:
713 714
\unexpanded
\def
\verbatim
#
1
{
\detokenize
{
#
1
}}
715 716
%D The setups for display verbatim and file verbatim are shared. One can adapt the
717
%D extra defined typing environments, but they also default to the values below.
718
%D Watch the alternative escape character.
719 720
% \tttf gives problems with {\tx \type...}
721
% \tt\tf does not adapt to e.g. \bf
722 723
\setuptyping
724
[
\c!before
=
\blank
,
725
\c!after
=
\blank
,
726
%\c!keeptogether=yes, % this will become default (when tested enough)
727
%\c!bodyfont=,
728
%\c!color=,
729
\c!space
=
\v!off
,
730
\c!lines
=
\v!no
,
731
\c!page
=
\v!no
,
732
\c!tab
=
\v!yes
,
% what is this: \s!ascii ?
733
\c!option
=
\v!none
,
734
\c!text
=
\v!no
,
735
\c!style
=
\tt
,
736
\c!indentnext
=
\v!yes
,
737
\c!margin
=
\zeropoint
,
738
\c!evenmargin
=
\zeropoint
,
739
\c!oddmargin
=
\zeropoint
,
740
\c!blank
=
\v!line
,
741
%\c!escape=, % yes | no | {START,STOP} | default when yes: {BTEX,ETEX}
742
\c!numbering
=
\v!no
,
743
%\c!range=,
744
\c!start
=
1
,
745
%\c!stop=,
746
\c!step
=
1
,
747
%\c!continue=,
748
\c!strip
=
\v!no
]
% auto or number
749 750
\definetyping
[
\v!typing
]
751 752
% the \zeropoint forces the number to the margin but also works ok in text
753 754
\setuplinenumbering
[
\v!typing
][
\c!location
=
\v!left
,
\c!width
=
\zeropoint
]
755 756
\setuptyping
[
\v!file
]
[
\s!parent
=
\??typing
\v!typing
]
% we don't want \start..\stop overload
757
\setuplinenumbering
[
\v!file
]
[
\s!parent
=
\??linenumbering\v!typing
]
758 759
\setuptyping
[
\v!buffer
][
\s!parent
=
\??typing
\v!file
]
% we don't want \start..\stop overload
760
\setuplinenumbering
[
\v!buffer
][
\s!parent
=
\??linenumbering\v!file
]
761 762
%D The setups for inline verbatim default to:
763 764
\setuptype
765
[
\c!space
=
\v!off
,
766
\c!lines
=
\v!no
,
767
%\c!color=,
768
\c!style
=
\tt
,
769
%\c!option=\v!normal,
770
\c!page
=
\v!no
,
771
\c!tab
=
\v!yes
,
772
\c!compact
=
\v!all
]
773 774
%D Buffers
775 776
% [name] [settings] | [name] | [settings]
777 778
% \unexpanded\def\typebuffer
779
% {\dodoubleempty\buff_verbatim_type_buffer}
780 781
\unexpanded
\def
\typebuffer
782
{
\begingroup
783
\let
\currenttyping
\v!buffer
784
\dodoubleempty
\buff_verbatim_type_buffer
}
785 786
\unexpanded
\def
\buff_verbatim_type_defined_buffer
787
{
\dotripleempty
\buff_verbatim_type_defined_buffer_indeed
}
788 789
\unexpanded
\def
\typedefinedbuffer
[#
1
]
%
790
{
\buff_verbatim_type_defined_buffer
[
\v!buffer
][
\thedefinedbuffer
{
#
1
}
]
}
%
791 792
\appendtoks
793
\setuevalue
{
\e!type
\currentbuffer
}{
\buff_verbatim_type_defined_buffer
[
\v!buffer
][
\currentdefinedbuffer
]
}
%
794
\to
\everydefinebuffer
795 796
\appendtoks
% \e!buffer
797
\setuevalue
{
\e!type
\currenttyping
\v!buffer
}{
\buff_verbatim_type_buffer_class
{
\currenttyping
}}
%
798
\to
\everydefinetyping
799 800
\unexpanded
\def
\buff_verbatim_type_buffer
[#
1
][#
2
]
%
801
{
\ifsecondargument
802
\setupcurrenttyping
[#
2
]
%
803
\processcommalist
[#
1
]
{
\buff_verbatim_type_buffer_indeed
\currenttyping
}
% [name] [settings]
804
\else
\iffirstargument
805
\ifcondition
\validassignment
{
#
1
}
%
806
\setupcurrenttyping
[#
1
]
%
807
\buff_verbatim_type_buffer_indeed
\currenttyping
\empty
% [settings]
808
\else
809
\processcommalist
[#
1
]
{
\buff_verbatim_type_buffer_indeed
\currenttyping
}
% [name]
810
\fi
811
\else
812
\buff_verbatim_type_buffer_indeed
\currenttyping
\empty
% []
813
\fi\fi
814
\endgroup
815
\dorechecknextindentation
}
816 817
\unexpanded
\def
\buff_verbatim_type_buffer_class
#
1
%
818
{
\begingroup
819
\edef
\currenttyping
{
#
1
}
%
820
\dodoubleempty
\buff_verbatim_type_buffer
}
821 822
\unexpanded
\def
\buff_verbatim_type_defined_buffer_indeed
[#
1
][#
2
][#
3
]
% category name settings
823
{
\begingroup
824
\ifthirdargument
825
\setuptyping
[#
1
][#
3
]
%
826
\fi
827
\buff_verbatim_type_buffer_indeed
{
#
1
}{
#
2
}
%
828
\endgroup
}
829 830
\unexpanded
\def
\buff_verbatim_type_buffer_indeed
#
1
#
2
% category name
831
{
\edef
\currenttyping
{
#
1
}
%
832
\typingparameter
\c!before
833
\startpacked
[
\v!blank
]
834
\buff_verbatim_setup_line_numbering
835
\buff_verbatim_initialize_typing_one
836
\buff_verbatim_initialize_typing_two
837
\dostarttaggedchained
\t!verbatimblock
{
#
1
}
\??typing
838
\beginofverbatimlines
839
\dostarttagged
\t!verbatimlines
\empty
840
\clf_typebuffer
841
name
{
#
2
}
%
842
strip
{
\typingparameter
\c!strip
}
%
843
range
{
\typingparameter
\c!range
}
%
844
regime
{
\currentregime
}
%
845
tab
{
\typingparameter
\c!tab
}
%
846
method
{
\p_buff_option
}
%
847
escape
{
\typingparameter
\c!escape
}
%
848
nature
{
display
}
%
849
\relax
850
\dostoptagged
851
\endofverbatimlines
852
\dostoptagged
853
\stoppacked
854
\typingparameter
\c!after
855
\dorechecknextindentation
}
856 857
\unexpanded
\def
\typeinlinebuffer
858
{
\dontleavehmode
859
\begingroup
860
\let
\buff_verbatim_type_buffer_indeed
\buff_verbatim_type_buffer_indeed_inline
861
\let
\setupcurrenttyping
\setupcurrenttype
% a terrible hack but it saves code
862
\let
\currenttype
\empty
863
\dodoubleempty
\buff_verbatim_type_buffer
}
864 865
\unexpanded
\def
\buff_verbatim_type_buffer_indeed_inline
#
1
#
2
% category name
866
{
\edef
\currenttype
{
#
1
}
%
867
\buff_verbatim_initialize_type_one
868
\dostarttaggedchained
\t!verbatim
\currenttype
\??type
869
\clf_typebuffer
870
name
{
#
2
}
%
871
strip
{
\v!yes
}
%
872
regime
{
\currentregime
}
%
873
method
{
\p_buff_option
}
%
874
nature
{
inline
}
% is default anyway
875
\relax
876
\dostoptagged
}
877 878
% get : before/after of buffer
879
% typing : before/after of typing
880
% process : no before/after (special case anyway)
881 882
% the next one is obsolete (bad name and used nowhere) so if it stays
883
% the name will change
884 885
\unexpanded
\def
\processbuffer
886
{
\writestatus
{
nota
bene
}{
\string
\processbuffer
\space
is
obsolete
}
%
887
\dodoubleempty
\buff_verbatim_process
}
888 889
\def
\buff_verbatim_process
[#
1
][#
2
]
%
890
{
\begingroup
891
\ifsecondargument
892
\setuptyping
[
\v!buffer
][#
2
]
%
893
\processcommalist
[#
1
]
{
\buff_verbatim_process_indeed
\v!buffer
}
% [name] [settings]
894
\else
\iffirstargument
895
\ifcondition
\validassignment
{
#
1
}
%
896
\setuptyping
[
\v!buffer
][#
1
]
%
897
\buff_verbatim_process_indeed
\v!buffer
\empty
% [settings]
898
\else
899
\processcommalist
[#
1
]
{
\buff_verbatim_process_indeed
\v!buffer
}
% [name]
900
\fi
901
\else
902
\buff_verbatim_process_indeed
\v!buffer
\empty
% []
903
\fi\fi
904
\endgroup
}
905 906
\def
\buff_verbatim_process_indeed
#
1
#
2
%
907
{
\edef
\currenttyping
{
#
1
}
%
908
\clf_processbuffer
909
name
{
#
2
}
%
910
strip
{
\typingparameter
\c!strip
}
%
911
tab
{
\typingparameter
\c!tab
}
%
912
% method {\p_buff_option}%
913
nature
{
direct
}
%
914
\relax
}
915 916
% so far for obsolete
917 918
% line numbering, keep broken lines together
919 920
\newcount
\nofverbatimlines
921 922
\unexpanded
\def
\buff_verbatim_begin_of_line
923
{
\ifconditional
\verbatimnumberinglines
924
\global\advance
\nofverbatimlines
\plusone
925
\c_attr_verbatimline
\nofverbatimlines
926
\fi
927
\noindent
928
\buff_verbatim_set_line_margin
929
\the
\everyline
% maybe also after starttagged
930
\strut
% after starttagged, else break !
931
\dostarttagged
\t!verbatimline
\empty
932
}
933 934
\unexpanded
\def
\buff_verbatim_end_of_line
935
{
\dostoptagged
936
\obeyedline
% still needed?
937
\par
938
\ifconditional
\verbatimnumberinglines
939
\c_attr_verbatimline
\attributeunsetvalue
940
\fi
}
941 942
\unexpanded
\def
\buff_verbatim_empty_line
943
{
\dostoptagged
944
\ifconditional
\verbatimnumberinglines
945
\par
\strut
\par
% this will be an option where we use a signal instead of a strut
946
\else
947
\blank
[
\typingparameter
\c!blank
]
%
948
\fi
949
\dostarttagged
\t!verbatimlines
\empty
}
950 951
% hooks:
952 953
\newcount
\c_buff_verbatim_noflines
954
\newcount
\c_buff_verbatim_current
955
\newconditional
\c_buff_optimize_linebreaks
956 957
\def
\doverbatimspace
{
\obeyedspace
}
958 959
\unexpanded
\def
\doinlineverbatimstart
{}
960
\unexpanded
\def
\doinlineverbatimstop
{}
961
\unexpanded
\def
\doinlineverbatimbeginline
{}
962
\unexpanded
\def
\doinlineverbatimnewline
{
\obeyedspace
}
963
\unexpanded
\def
\doinlineverbatimemptyline
{
\obeyedspace
}
964 965
\unexpanded
\def
\dodisplayverbatimstart
{
\advance
\c_buff_verbatim_current
\plusone
966
\buff_verbatim_begin_of_line
}
967
\unexpanded
\def
\dodisplayverbatimstop
{
\buff_verbatim_end_of_line
}
968
\unexpanded
\def
\dodisplayverbatimbeginline
{
\advance
\c_buff_verbatim_current
\plusone
969
\buff_verbatim_begin_of_line
}
970
\unexpanded
\def
\dodisplayverbatimnewline
{
\buff_verbatim_end_of_line
971
\par
972
\ifconditional
\c_buff_optimize_linebreaks
973
\buff_verbatim_inject_breaks
974
\fi
}
975
\unexpanded
\def
\dodisplayverbatimemptyline
{
\buff_verbatim_empty_line
}
976 977
\unexpanded
\def
\buff_verbatim_inject_breaks
978
{
\ifnum
\c_buff_verbatim_current
=
\plusone
979
\nobreak
980
\else\ifnum
\c_buff_verbatim_noflines
=
\plusthree
981
\nobreak
982
\else\ifnum
\c_buff_verbatim_current
=
\numexpr
\c_buff_verbatim_noflines
-
\plusone
\relax
983
\nobreak
984
\fi\fi\fi
}
985 986
\unexpanded
\def
\dodisplayverbatiminitialize
#
1
%
987
{
\forgetparindent
% maybe more
988
\c_buff_verbatim_noflines
#
1
\relax
989
\c_buff_verbatim_current
\zerocount
}
990 991
\loadmarkfile
{
buff
-
imp
-
default
}
% preloaded as otherwise spurious spaces inline due to loading
992
\loadmarkfile
{
buff
-
imp
-
nested
}
% preloaded as otherwise spurious spaces inline due to loading
993
\loadmarkfile
{
buff
-
imp
-
escaped
}
% for completeness
994 995
%D To be considered:
996 997
% \installcorenamespace{visualizer}
998
%
999
% \installcommandhandler \??visualizer {visualizer} \??visualizer
1000
%
1001
% \appendtoks
1002
% \setuevalue{\currentvisualizer}{\buff_verbatim_visualize{\currentvisualizer}}%
1003
% \to \everydefinevisualizer
1004
%
1005
% \unexpanded\def\buff_verbatim_visualize#1%
1006
% {\bgroup
1007
% \def\currentvisualizer{#1}%
1008
% \usevisualizerstyleandcolor\c!style\c!color
1009
% \let\next}
1010 1011
\appendtoks
1012
%def\type#1{\letterbackslash\checkedstrippedcsname#1}% or maybe detokenize
1013
\def
\type
#
1
{
\detokenize\expandafter
{
\csstring
#
1
}}
% or maybe detokenize
1014
\def
\tex
#
1
{
\letterbackslash
#
1
}
%
1015
\to
\everysimplifycommands
1016 1017
\stopcontextdefinitioncode
1018 1019
%D This is \type {\asciimode} without the double comment hackery:
1020 1021
\unexpanded
\def
\literalmode
{
\setcatcodetable
\txtcatcodes
}
1022 1023
\protect
\endinput
1024