buff-ver.mkxl /size: 39 Kb    last modification: 2025-02-21 11:03
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}{autosuffix}
19
20\unprotect
21
22\startcontextdefinitioncode
23
24\definesystemattribute[verbatimline][public]
25
26\appendtoks
27    \c_attr_verbatimline\attributeunsetvalue
28\to \everyforgetall
29
30%D Initializations.
31
32\installcorenamespace{typinglines}
33\installcorenamespace{typingspace}
34
35\newtoks\everyinitializeverbatim
36
37\appendtoks
38    \expand\everyresettypesetting
39    \resetfontfeature
40    \resetcharacterspacing
41    \resetbreakpoints
42    \nohyphencollapsing
43    % we figured this out when discussions the math manual:
44    \parpasses\zerocount
45    \noexpansion
46    \noprotrusion
47    % so far
48\to \everyinitializeverbatim
49
50\permanent\protected\def\setverbatimspaceskip % to be checked: must happen after font switch
51  {\spaceskip\scaledfontcharwd\font`x\relax
52   \xspaceskip\spaceskip}
53
54\defcsname\??typinglines\v!no        \endcsname{\buff_verbatim_ignore_hyphens}
55\defcsname\??typinglines\v!normal    \endcsname{\buff_verbatim_ignore_hyphens}
56\defcsname\??typinglines\v!yes       \endcsname{\buff_verbatim_obey_breakpoints}
57\defcsname\??typinglines\v!hyphenated\endcsname{\buff_verbatim_obey_hyphens}
58
59\defcsname\??typingspace\v!on        \endcsname{\enforced\let\obeyedspace\specialcontrolspace}
60\defcsname\??typingspace\v!stretch   \endcsname{\enforced\let\obeyedspace\specialstretchedspace}
61\letcsname\??typingspace\v!normal    \endcsname\donothing
62\defcsname\??typingspace\v!fixed     \endcsname{\enforced\let\obeyedspace\specialfixedspace}
63\defcsname\??typingspace\v!character \endcsname{\enforced\chardef\obeyedspace\spaceasciicode}
64
65\protected\def\buff_verbatim_obey_hyphens
66  {}
67
68\protected\def\buff_verbatim_obey_breakpoints
69  {\nohyphens
70   \veryraggedright}
71
72\protected\def\buff_verbatim_ignore_hyphens
73  {\nohyphens}
74
75\def\buff_verbatim_initialize_type_one
76  {\enforced\let\obeylines\ignorelines
77   \edef\p_buff_option{\typeparameter\c!option}%
78   \ifx\p_buff_option\v!none
79     \usetypestyleandcolor\c!style\c!color
80   \orelse\ifempty\p_buff_option
81     \usetypestyleandcolor\c!style\c!color
82   \else
83     \usetypestyleparameter\c!style % no color
84   \fi
85   \setcatcodetable\vrbcatcodes}
86
87\def\buff_verbatim_initialize_type_two
88  {\spaceskip.5\emwidth\relax
89   \enforced\let\obeyedspace\specialobeyedspace
90   \enforced\let\controlspace\specialcontrolspace
91   \begincsname\??typinglines\typeparameter\c!lines\endcsname
92   \begincsname\??typingspace\typeparameter\c!space\endcsname
93   \relax\expand\everyinitializeverbatim\relax
94   \usesetupsparameter\typeparameter\relax}
95
96\permanent\protected\def\doinitializeverbatim % for use elsewhere .. temp hack (see lxml-ini)
97  {\buff_verbatim_initialize_type_one
98   \buff_verbatim_initialize_type_two}
99
100\let\buff_verbatim_set_line_margin\relax
101
102\def\buff_verbatim_set_line_margin_indeed % we could expand this once
103  {\hskip\doifelseoddpage\d_buff_lines_odd_margin\d_buff_lines_even_margin\relax}
104
105\newconditional\c_buff_lines_as_paragraph
106
107\newdimension\d_buff_lines_even_margin
108\newdimension\d_buff_lines_odd_margin
109
110\def\buff_verbatim_initialize_typing_one
111  {\usebodyfontparameter\typingparameter
112   \d_buff_lines_odd_margin {\typingparameter\c!oddmargin }%
113   \d_buff_lines_even_margin{\typingparameter\c!evenmargin}%
114   \ifzerodim\d_buff_lines_odd_margin\else
115     \let\buff_verbatim_set_line_margin\buff_verbatim_set_line_margin_indeed
116   \fi
117   \ifzerodim\d_buff_lines_even_margin\else
118     \let\buff_verbatim_set_line_margin\buff_verbatim_set_line_margin_indeed
119   \fi
120   \ifrelax\buff_verbatim_set_line_margin
121     \doadaptleftskip{\typingparameter\c!margin}%
122   \fi
123   \edef\p_buff_option{\typingparameter\c!option}%
124   \ifx\p_buff_option\v!none
125     \usetypingstyleandcolor\c!style\c!color
126   \orelse\ifempty\p_buff_option
127     \usetypingstyleandcolor\c!style\c!color
128   \else
129     \usetypingstyleparameter\c!style % no color !
130   \fi
131 % \usealignparameter\typingparameter
132   \hbadnessmode\overfullbadnessmodecode % we don't care about underfull and tight can't happen
133   \edef\p_align{\typingparameter\c!align}%
134   \unless\ifconditional\c_buff_lines_as_paragraph
135     \dousealignparameter\p_align
136   \orelse\ifx\p_align\v!hangleft
137     \dousealignparameter{\v!hangleft range}%
138   \orelse\ifx\p_align\v!hangright
139     \dousealignparameter{\v!hangright range}%
140   \else
141     \dousealignparameter\p_align
142   \fi}
143
144\def\buff_verbatim_initialize_typing_two
145  {\spaceskip.5\emwidth\relax
146   \enforced\let\obeyedspace\specialobeyedspace
147   \enforced\let\controlspace\specialcontrolspace
148   \begincsname\??typinglines\typingparameter\c!lines\endcsname
149   \begincsname\??typingspace\typingparameter\c!space\endcsname
150   \relax\expand\everyinitializeverbatim\relax
151   \usesetupsparameter\typingparameter\relax}
152
153%D \macros
154%D   {definetype,setuptype}
155%D
156%D Specific inline verbatim commands can be defined with the following command.
157
158\installcorenamespace{type}
159
160\installcommandhandler \??type {type} \??type
161
162\appendtoks
163    \frozen\instance\protected\edefcsname\currenttype\endcsname{\buff_verbatim_type{\currenttype}}%
164\to \everydefinetype
165
166\appendtoks
167   \buff_verbatim_initialize_visualizer{\typeparameter\c!option}%
168\to \everysetuptype
169
170%D \macros
171%D   {definetyping,setuptyping}
172%D
173%D For most users the standard \type {\start}||\type {\stop}||pair will suffice, but
174%D for documentation purposes the next definition command can be of use:
175%D
176%D \starttyping
177%D \definetyping[extratyping][margin=3em]
178%D
179%D \startextratyping
180%D these extra ones are indented by 1 em
181%D \stopextratyping
182%D \stoptyping
183%D
184%D The definitions default to the standard typing values.
185
186\installcorenamespace{typing}
187
188\installcommandhandler \??typing {typing} \??typing
189
190\appendtoks
191    \frozen\protected\instance\edefcsname\e!start\currenttyping\endcsname{\buff_verbatim_typing_start{\currenttyping}{\currenttyping}}%
192    \frozen\protected\instance\edefcsname\e!stop \currenttyping\endcsname{\buff_verbatim_typing_stop}%
193    \ifempty\currenttypingparent
194      \normalexpanded{\definelinenumbering[\currenttyping]}%
195    \else
196      \normalexpanded{\definelinenumbering[\currenttyping][\currenttypingparent]}%
197    \fi
198\to \everydefinetyping
199
200\appendtoks
201   \buff_verbatim_initialize_visualizer{\typingparameter\c!option}% we can check at the tex end
202\to \everysetuptyping
203
204\def\buff_verbatim_initialize_visualizer#1%
205  {\ifproductionrun\clf_loadvisualizer{#1}\fi}
206
207\permanent\protected\def\doifelsevisualizer#1%
208  {\clf_doifelsevisualizer{#1}}
209
210\aliased\let\doifvisualizerelse\doifelsevisualizer
211
212%D Verbatim command are very sensitive to argument processing, which is a direct
213%D result of the \CATCODES\ being fixed at reading time.
214%D
215%D Typesetting inline verbatim can be accomplished by \type {\type}, which in this
216%D sentence was typeset by saying just \type {\type {\type}}, which in turn was
217%D typeset by \unknown. Using the normal grouping characters \type {{}} is the most
218%D natural way of using this command.
219%D
220%D A second, more or less redundant, alternative is delimiting the argument with an
221%D own character. This method was implemented in the context of a publication in the
222%D \MAPS, where this way of delimiting is recognized by \LATEX\ users.
223%D
224%D The third, more original alternative, is the one using \type {<<} and \type {>>}
225%D as delimiters. This alternative can be used in situations where slanted
226%D typeseting is needed.
227%D
228%D \macros
229%D   {type}
230%D
231%D We define \type {\type} as a protected command. This command has several
232%D invocations: grouped, wirt boundary characters, and with font switches.
233%D
234%D \starttyping
235%D normal: \par \type{xx<<..xx..<<xx <<xx>> >>..>>xx} \par \type<<....>> \par \type<<..<<xx>>..>> \par
236%D normal: \par \type{xx<..xx..<xx <slanted> >..>xx} \par \type{<....>} \par \type{<..<xx>..>}
237%D \setuptype[option=slanted]
238%D slanted: \par \type{xx<<..sl..<<xx <<sl>> xx>>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<<sl>>..>> \par
239%D slanted: \par \type{xx<<..sl..<xx <sl> xx>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<sl>..>> \par
240%D \setuptype[option=none]
241%D none: \par \type{xx<<..xx..<<xx <<xx>> >>..>>xx} \par \type<<....>> \par \type<<..<<xx>>..>> \par
242%D \stoptyping
243%D
244%D When writing the manual to \CONTEXT\ and documenting this source we needed to
245%D typeset \type {<<} and \type {>>}. Because we wanted to do this in the natural
246%D way, we've adapted the original definition a bit. This implementation went
247%D through several live cycles. The final implementation looks a bit further and
248%D treats the lone \type {<<} and \type {>>} a bit different. The \type {\null}
249%D prevents ligatures, which unfortunately turn up in Lucida fonts.
250%D
251%D The following lines show what happens when we set \type {option=commands}.
252%D
253%D \startbuffer
254%D \starttyping
255%D test//test test/BTEX \footnote{test test test}/ETEX test
256%D test//test test/BTEX \footnote{test test test}/ETEX  test
257%D test test test/BTEX \bf(nota bene)/ETEX test
258%D test test test /BTEX \bf(nota bene)/ETEX  test
259%D \stoptyping
260%D \stopbuffer
261%D
262%D % \bgroup\setuptyping[option=commands]\getbuffer\egroup
263%D
264%D this was keyed in as:
265%D
266%D \typebuffer
267
268% Beware, the command is supposed to do something like \framed and not manipulate
269% content i.e. it gets no argument but something b/egrouped instead:
270
271\def\buff_verbatim_left_of_type
272  {\typeparameter\c!left
273   \typeparameter\c!command\bgroup}
274
275\def\buff_verbatim_right_of_type
276  {\egroup
277   \typeparameter\c!right}
278
279\permanent\protected\def\type{\buff_verbatim_type\empty}
280\permanent\protected\def\typ {\buff_verbatim_typ \empty}
281
282\protected\def\buff_verbatim_type#1%
283  {\dontleavehmode
284   \bgroup
285   \cdef\currenttype{#1}%
286   \buff_verbatim_type_indeed}
287
288\def\buff_verbatim_typ#1%
289  {\dontleavehmode
290   \bgroup
291   \cdef\currenttype{#1}%
292   \lettypeparameter\c!lines\v!hyphenated
293   \enforced\let\specialobeyedspace\specialstretchedspace
294   \buff_verbatim_type_indeed}
295
296\tolerant\def\buff_verbatim_type_indeed[#S#1]%
297  {\ifarguments\or\setupcurrenttype[#1]\fi
298   \buff_verbatim_left_of_type
299   \futureexpand\bgroup\buff_verbatim_type_a\buff_verbatim_type_one}
300
301\def\buff_verbatim_type_one
302  {\catcode\lessthanasciicode\othercatcode % old precaution
303   \catcode\morethanasciicode\othercatcode % old precaution
304   \futureexpandis<\buff_verbatim_type_b\buff_verbatim_type_c}
305
306\def\buff_verbatim_type_three
307  {\if\next<%
308     \expandafter\buff_verbatim_type_b
309   \else
310     \expandafter\buff_verbatim_type_c
311   \fi}
312
313\def\buff_verbatim_type_a
314  {\buff_verbatim_initialize_type_one
315   \setcatcodetable\tpacatcodes
316   \buff_verbatim_type_normal}
317
318\def\buff_verbatim_type_b#1%
319  {\buff_verbatim_initialize_type_one
320   \setcatcodetable\tpbcatcodes
321   \buff_verbatim_type_nested}
322
323\def\buff_verbatim_type_c#1%
324  {\buff_verbatim_initialize_type_one
325   \setcatcodetable\vrbcatcodes
326   \def\next##1#1{\buff_verbatim_type_normal{##1}}%
327   \next}
328
329\def\buff_verbatim_type_normal#1%
330  {\buff_verbatim_initialize_type_two
331   \dostarttaggedchained\t!verbatim\currenttype\currenttype\??type
332   \clf_type
333     data    {\protecteddetokenize{#1}}%
334     tab     {\typeparameter\c!tab}%
335     method  {\p_buff_option}%
336     compact {\typeparameter\c!compact}% % none | all | last (all needed in tabulate etc for manuals)
337     escape  {\typeparameter\c!escape}%  % new but rather useless imo (escaping in general is not used much)
338   % nature  {inline}% is default
339   \relax
340   \dostoptagged
341   \buff_verbatim_right_of_type
342   \egroup}
343
344\def\buff_verbatim_type_nested#1%
345  {\buff_verbatim_initialize_type_two
346   \dostarttaggedchained\t!verbatim\currenttype\currenttype\??type
347   \clf_type
348     data   {\detokenize{#1}}%
349%      data    {\protecteddetokenize{#1}}%
350     tab    {\typeparameter\c!tab}%
351     method {\p_buff_option}% % extra visualizer (maybe: nested,\typeparameter\c!option)
352     escape {\typeparameter\c!escape}%  % new but rather useless imo (escaping in general is not used much)
353   % nature {inline}% is default
354     method {nested}%
355   \relax
356   \dostoptagged
357   \buff_verbatim_right_of_type
358   \egroup
359   \gobbleoneargument} % grab last >
360
361%D The \type {compact} option can come in handy in the case of inline argument passing
362%D
363%D \starttyping
364%D \definetype[TeXcodeA][option=TEX]
365%D \definetype[TeXcodeB][option=TEX,compact=all]
366%D \definetype[TeXcodeC][option=TEX,compact=absolute]
367%D
368%D \def\argA#1{\TeXcodeA{{#1}}}
369%D \def\argB#1{\TeXcodeB{{#1}}}
370%D \def\argC#1{\TeXcodeC{{#1}}}
371%D \stoptyping
372
373%D \macros
374%D   {obeyhyphens,obeybreakpoints}
375%D
376%D Although it's not clear from the macros, one character trait of this macros,
377%D which are build on top of the support module, is that they don't hyphenate. We
378%D therefore offer the alternative \type{\typ}. The current implementation works all
379%D right, but a decent hyphenation support of \type{\tt} text will be implemented
380%D soon.
381
382\permanent\protected\def\specialfixedspace     {\kern\interwordspace\relax}
383\permanent\protected\def\specialobeyedspace    {\hskip\interwordspace\relax} % better than spaceskip
384\permanent\protected\def\specialstretchedspace {\hskip.5\interwordspace\s!plus.125\interwordspace\relax} % \interwordstretch can be zero
385\permanent\protected\def\specialcontrolspace   {\normalcontrolspace\allowbreak} % uses fallback
386
387\permanent\protected\def\explicitfixedspace    {\asciispacechar}
388\permanent\protected\def\explicitobeyedspace   {\asciispacechar\allowbreak}
389\permanent\protected\def\explicitstretchedspace{\asciispacechar\hskip\zeropoint\s!plus.125\interwordspace\relax}%
390\permanent\protected\def\explicitcontrolspace  {\optionalcontrolspace\allowbreak} % uses asciispace
391
392\appendtoks
393    \enforced\protected\def\obeyedspace{\hskip\zeroskip\relax\asciispacechar\hskip\zeroskip\relax}%
394\to \everyenableelements
395
396\permanent\protected\def\obeyhyphens
397  {\enforced\let\obeyedspace \specialobeyedspace % maybe \specialstretchedspace
398   \enforced\let\controlspace\specialcontrolspace
399   \spaceskip.25\emwidth\relax} % hm a bit of stretch !
400
401\permanent\protected\def\obeybreakpoints
402  {\ignorehyphens
403   \veryraggedright}
404
405\permanent\protected\def\ignorehyphens
406  {\nohyphens
407   \enforced\let\obeyedspace \specialobeyedspace
408   \enforced\let\controlspace\specialcontrolspace
409   \spaceskip.5\emwidth\relax}
410
411%D \macros
412%D   {tex,arg,mat,dis,astype}
413%D
414%D Sometimes, for instance when we pass verbatim text as an argument, the fixed
415%D \CATCODES\ interfere with our wishes. An experimental implementation of character
416%D by character processing of verbatim text did overcome this limitation, but we've
417%D decided not to use that slow and sometimes troublesome solution. Instead we stick
418%D to some 'old' \CONTEXT\ macros for typesetting typical \TEX\ characters.
419
420\immutable\def\lesscharacter    {<} % obsolete
421\immutable\def\morecharacter    {>} % obsolete
422
423\immutable\let\texescape        \textbackslash
424\immutable\let\leftargument     \textbraceleft
425\immutable\let\rightargument    \textbraceright
426\immutable\let\inlinemathmarker \textdollar
427\immutable\def\displaymathmarker{\textdollar\textdollar}
428
429\def\buff_verbatim_special_type#1#2#% # gobbles spaces
430  {\dontleavehmode\bgroup
431   \buff_verbatim_initialize_type_one
432   \catcode\leftbraceasciicode \begingroupcatcode
433   \catcode\rightbraceasciicode\endgroupcatcode
434   #1%
435   \bgroup % else wrong font for #2
436   \aftergroup#2%
437   \aftergroup\egroup
438   \let\nexttoken}
439
440\mutable\protected\def\tex{\buff_verbatim_special_type\texescape        \relax}
441\mutable\protected\def\arg{\buff_verbatim_special_type\leftargument     \rightargument}
442\mutable\protected\def\mat{\buff_verbatim_special_type\inlinemathmarker \inlinemathmarker}
443\mutable\protected\def\dis{\buff_verbatim_special_type\displaymathmarker\displaymathmarker}
444
445\aliased\let\normaltexttex\tex
446\aliased\let\normaltextarg\arg
447\aliased\let\normaltextmat\mat
448\aliased\let\normaltextdis\dis
449
450\permanent\protected\def\astype
451  {\dontleavehmode
452   \bgroup\usetypestyleandcolor\c!style\c!color\let\nexttoken}
453
454\permanent\protected\def\asciistr#1% used in some old styles
455  {\dontleavehmode\begingroup
456   \dostarttaggednodetail\t!verbatim
457   \usetypestyleandcolor\c!style\c!color\detokenize{#1}%
458   \dostoptagged
459   \endgroup}
460
461%D The basic display verbatim commands are defined in an indirect way. As we
462%D will see, they are a specific case of a more general mechanism.
463
464\mutable\let\beginofverbatimlines\relax % hooks
465\mutable\let\endofverbatimlines  \relax % hooks
466
467\protected\def\buff_verbatim_typing_start#1#2% tricky non standard lookahead
468  {\begingroup
469   \cdef\currenttyping       {#1}%
470   \edef\currenttypingwrapper{#2}%
471   \begingroup
472   \obeylines % alternatively \future.. could *not* ignore newlines
473   \futureexpandis[\buff_verbatim_typing_start_yes\buff_verbatim_typing_start_nop}
474
475\def\buff_verbatim_typing_start_yes[#S#1]%
476  {\endgroup
477   \ifhastok={#1}%
478     \setupcurrenttyping[#1]%
479   \orelse\ifcstok{#1}\v!continue
480     \lettypingparameter\c!continue\v!yes
481   \fi
482   \typingparameter\c!before\relax % moved down
483   \startpacked[\v!blank]%         % moved down
484   \buff_verbatim_setup_keep_together
485   \buff_verbatim_setup_line_numbering
486   \buff_verbatim_initialize_typing_one
487   \normalexpanded{\buff_verbatim_type_block{\e!start\currenttypingwrapper}{\e!stop\currenttypingwrapper}}}
488
489\def\buff_verbatim_typing_start_nop
490  {\endgroup
491   \typingparameter\c!before\relax
492   \startpacked[\v!blank]%
493   \buff_verbatim_setup_keep_together
494   \buff_verbatim_setup_line_numbering
495   \buff_verbatim_initialize_typing_one
496   \normalexpanded{\buff_verbatim_type_block{\e!start\currenttypingwrapper}{\e!stop \currenttypingwrapper}}}
497
498%D \start \showmakeup[vpenalty]
499%D \starttyping[keeptogether=paragraph]
500%D test test
501%D test test
502%D test test
503%D test test
504%D \stoptyping
505%D \stop
506
507\protected\def\buff_verbatim_setup_keep_together
508  {\ifcstok{\typingparameter\c!keeptogether}\v!yes
509     \c_buff_lines_as_paragraph \conditionalfalse
510     \c_buff_optimize_linebreaks\conditionaltrue
511  %\orelse\ifcstok{\typingparameter\c!keeptogether}\v!paragraph
512   \orelse\iflastnamedcs\v!paragraph
513     \c_buff_lines_as_paragraph \conditionaltrue
514     \c_buff_optimize_linebreaks\conditionalfalse
515   \else
516     \c_buff_lines_as_paragraph \conditionalfalse
517     \c_buff_optimize_linebreaks\conditionalfalse
518   \fi}
519
520\protected\def\buff_verbatim_type_block#1#2%
521  {\normalexpanded{\buff_pickup
522     {_typing_}%
523     {#1}%
524     {#2}%
525     {}%
526     {\buff_verbatim_type_block_verbatim_indeed{#1}{#2}}%
527     \ifcstok{\typingparameter\c!strip}\v!no\zerocount\else\plusone\fi}}
528
529\protected\def\buff_verbatim_type_block_verbatim_indeed#1#2%
530  {\buff_verbatim_initialize_typing_two
531   \dostarttaggedchained\t!verbatimblock\currenttyping\currenttyping\??typing
532   \beginofverbatimlines
533   \dostarttaggednodetail\t!verbatimlines
534   \clf_typebuffer
535     name    {_typing_}%
536     strip   {\typingparameter\c!strip}%
537     range   {\typingparameter\c!range}%
538     tab     {\typingparameter\c!tab}%
539     par     {\typingparameter\c!paragraph}%
540     method  {\p_buff_option}%
541     escape  {\typingparameter\c!escape}%
542     nature  {display}%
543   \relax
544   \dostoptagged
545   \endofverbatimlines
546   \dostoptagged
547   \begincsname#2\endcsname}
548
549\protected\def\buff_verbatim_typing_stop
550  {\stoppacked
551   \typingparameter\c!after\relax
552   \useindentnextparameter\typingparameter
553   \endgroup
554   \dorechecknextindentation}
555
556\permanent\protected\def\startnamedtyping[#1]%
557  {\buff_verbatim_typing_start{#1}\e!namedtyping}
558
559\permanent\let\stopnamedtyping\buff_verbatim_typing_stop
560
561%D Line numbering for files is combined with filtering, while display verbatim has
562%D the ability to continue.
563%D
564%D \starttyping
565%D \typefile[numbering=file,start=10,stop=12]{test.tex}
566%D
567%D \definetyping[code][numbering=line]
568%D
569%D \starttext
570%D \startcode
571%D ...
572%D ...
573%D \stopcode
574%D
575%D \startcode[start=continue]
576%D ...
577%D ...
578%D \stopcode
579%D
580%D \startcode[start=10]
581%D ...
582%D \stopcode
583%D \stoptyping
584
585%D Ranges:
586%D
587%D \starttyping
588%D % label:start:one
589%D
590%D \def\MyMacro
591%D   {just an example}
592%D
593%D % label:stop:one
594%D
595%D \starttext
596%D
597%D % \typefile[file][range={3,6}] {whatever.tex}
598%D % \typefile[file][range={3,+2}]{whatever.tex}
599%D
600%D \typefile[file][range={label:start:one,label:stop:one}]{whatever.tex}
601%D
602%D \stoptext
603%D \stoptyping
604
605%D \macros
606%D   {typefile}
607%D
608%D Typesetting files verbatim (for the moment) only supports colorization of \TEX\
609%D sources as valid option. The other setup values are inherited from display
610%D verbatim. The implementation of \type {\typefile} is straightforward:
611
612% [category] [settings] {name} % for historic reasons, all filenames are {}
613
614\mutable\lettonothing\currenttypingfile
615
616\appendtoks
617    \frozen\protected\instance\edefcsname\e!type\currenttyping\v!file\endcsname{\typefile[\currenttyping]}%
618\to \everydefinetyping
619
620\permanent\tolerant\protected\def\typefile[#S#1]#*[#S#2]#:#3%
621  {\begingroup
622   \ifparameter#2\or
623     \setuptyping[#1][#2]%
624     \buff_verbatim_type_file_checked{#1}{#3}%
625   \orelse\ifparameter#1\or
626     \ifhastok={#1}%
627       \setuptyping[\v!file][#1]%
628       \buff_verbatim_type_file_checked\v!file{#3}%
629     \else
630       \buff_verbatim_type_file_checked{#1}{#3}%
631     \fi
632   \else
633     \buff_verbatim_type_file_checked\v!file{#3}%
634   \fi
635   \useindentnextparameter\typingparameter % needs checking
636   \endgroup
637   \dorechecknextindentation} % needs checking
638
639\def\buff_verbatim_type_file_checked#1#2%
640  {\doifelsetypingfile{#2}
641     {\buff_verbatim_type_file_indeed{#1}\currenttypingfile}
642     {\showmessage\m!verbatims1{#2}}}
643
644\permanent\protected\def\doifelsetypingfile#1%
645  {\edef\currenttypingfile{\locfilename{#1}}%
646   \ifempty\currenttypingfile
647     \edef\currenttypingfile{\locfilename{#1.tex}}% downward compatible
648   \fi
649   \ifempty\currenttypingfile
650     \expandafter\secondoftwoarguments
651   \else
652     \expandafter\firstoftwoarguments
653   \fi}
654
655\aliased\let\doiftypingfileelse\doifelsetypingfile
656
657\def\buff_verbatim_type_file_indeed#1#2% category name
658  {\cdef\currenttyping{#1}%
659   \typingparameter\c!before\relax
660   \startpacked[\v!blank]
661   \buff_verbatim_setup_keep_together
662   \buff_verbatim_setup_line_numbering
663   \buff_verbatim_initialize_typing_one
664   \buff_verbatim_initialize_typing_two
665   \dostarttaggedchained\t!verbatimblock\currenttyping\currenttyping\??typing
666   \beginofverbatimlines
667   \dostarttaggednodetail\t!verbatimlines
668   \clf_typefile
669      name   {#2}%
670      strip  {\typingparameter\c!strip}%
671      range  {\typingparameter\c!range}%
672      regime {\currentregime}%
673      tab    {\typingparameter\c!tab}%
674      method {\p_buff_option}%
675      nature {display}%
676   \relax
677   \dostoptagged
678   \endofverbatimlines
679   \dostoptagged
680   \stoppacked
681   \typingparameter\c!after\relax}
682
683%D Line numbering:
684
685\newconditional\verbatimnumberinglines
686
687\permanent\protected\def\beginofverbatimlinenumbering
688  {\startlinenumbering
689     [\currenttyping]%
690     [\c!continue=\typingparameter\c!continue,
691        \c!method=\v!type,
692         \c!start=\typingparameter\c!start,
693          \c!stop=\typingparameter\c!stop, % ?
694          \c!step=\typingparameter\c!step]}
695
696\permanent\protected\def\endofverbatimlinenumbering
697  {\stoplinenumbering}
698
699\def\buff_verbatim_setup_line_numbering
700  {\ifdefined\startlinenumbering
701     \edef\p_numbering{\typingparameter\c!numbering}%
702     \ifx\p_numbering\v!file
703       \setuplinenumbering[\currenttyping][\c!method=\v!file]%
704       \verbatimnumberinglines\conditionaltrue
705     \orelse\ifx\p_numbering\v!line
706       \verbatimnumberinglines\conditionaltrue
707     \else
708       \verbatimnumberinglines\conditionalfalse
709     \fi
710     \ifconditional\verbatimnumberinglines
711       \enforced\let\beginofverbatimlines\beginofverbatimlinenumbering
712       \enforced\let\endofverbatimlines  \endofverbatimlinenumbering
713     \fi
714   \fi}
715
716%D \macros
717%D   {filename}
718%D
719%D Typesetting filenames in monospaced fonts is possible with
720%D
721%D \starttyping
722%D \filename{here/there/filename.suffix}
723%D \stoptyping
724%D
725%D The definition is not that spectacular.
726
727\permanent\protected\def\filename#1{{\tttf\hyphenatedfilename{#1}}}
728
729%D \macros
730%D   {verbatim}
731%d
732%D And a bonus macro, an unexpanded detokenize:
733
734\permanent\protected\def\verbatim#1{\detokenize{#1}}
735
736%D The setups for display verbatim and file verbatim are shared. One can adapt the
737%D extra defined typing environments, but they also default to the values below.
738%D Watch the alternative escape character.
739
740% \tttf   gives problems with {\tx \type...}
741% \tt\tf  does not adapt to e.g. \bf
742
743\setuptyping
744  [\c!before=\blank,
745   \c!after=\blank,
746  %\c!keeptogether=yes, % this will become default (when tested enough)
747  %\c!bodyfont=,
748  %\c!color=,
749   \c!space=\v!off,
750   \c!lines=\v!no,
751   \c!page=\v!no,
752   \c!tab=\v!yes, % what is this: \s!ascii ?
753   \c!option=\v!none,
754   \c!text=\v!no,
755   \c!style=\tt,
756   \c!indentnext=\v!yes,
757   \c!margin=\zeropoint,
758   \c!evenmargin=\zeropoint,
759   \c!oddmargin=\zeropoint,
760   \c!blank=\v!line,
761  %\c!escape=, % yes | no | {START,STOP} | default when yes: {BTEX,ETEX}
762   \c!numbering=\v!no,
763  %\c!range=,
764   \c!start=1,
765  %\c!stop=,
766   \c!step=1,
767  %\c!continue=,
768   \c!strip=\v!no] % auto or number
769
770\definetyping[\v!typing]
771
772% the \zeropoint forces the number to the margin but also works ok in text
773
774\setuplinenumbering[\v!typing][\c!location=\v!left,\c!width=\zeropoint]
775
776\setuptyping       [\v!file]  [\s!parent=\??typing       \v!typing] % we don't want \start..\stop overload
777\setuplinenumbering[\v!file]  [\s!parent=\??linenumbering\v!typing]
778
779\setuptyping       [\v!buffer][\s!parent=\??typing       \v!file]   % we don't want \start..\stop overload
780\setuplinenumbering[\v!buffer][\s!parent=\??linenumbering\v!file]
781
782%D The setups for inline verbatim default to:
783
784\setuptype
785  [\c!space=\v!off,
786   \c!lines=\v!no,
787  %\c!color=,
788   \c!style=\tt,
789  %\c!option=\v!normal,
790   \c!page=\v!no,
791   \c!tab=\v!yes,
792   \c!compact=\v!all]
793
794%D Buffers
795
796% [name] [settings] | [name] | [settings]
797
798\permanent\protected\def\typebuffer
799  {\begingroup
800   \let\currenttyping\v!buffer
801   \buff_verbatim_type_buffer}
802
803\permanent\protected\def\typedefinedbuffer[#1]%
804  {\buff_verbatim_type_defined_buffer[\v!buffer][\thedefinedbuffer{#1}]}%
805
806% \appendtoks
807%     \frozen\instance\protected\edefcsname\e!type\currentbuffer\endcsname
808%       {\buff_verbatim_type_defined_buffer[\v!buffer][\currentdefinedbuffer]}%
809% \to \everydefinebuffer
810
811\appendtoks
812    \frozen\instance\protected\edefcsname\e!type\currentbuffer\endcsname
813      {\buff_verbatim_type_defined_buffer[\currentbuffer][\currentdefinedbuffer]}%
814\to \everydefinebuffer
815
816\appendtoks % \e!buffer
817    \frozen\instance\protected\edefcsname\e!type\currenttyping\v!buffer\endcsname
818      {\buff_verbatim_type_buffer_class{\currenttyping}}%
819\to \everydefinetyping
820
821\tolerant\protected\def\buff_verbatim_type_buffer[#S#1]#*[#S#2]%
822  {\ifarguments
823     \buff_verbatim_type_buffer_indeed\currenttyping\empty% []
824   \or
825     \ifhastok={#1}%
826       \setupcurrenttyping[#1]%
827       \buff_verbatim_type_buffer_indeed\currenttyping\empty% [settings]
828     \else
829       \processcommalist[#1]{\buff_verbatim_type_buffer_indeed\currenttyping}% [name]
830     \fi
831   \or
832     \setupcurrenttyping[#2]%
833     \processcommalist[#1]{\buff_verbatim_type_buffer_indeed\currenttyping}% [name] [settings]
834   \fi
835   \useindentnextparameter\typingparameter
836   \endgroup
837   \dorechecknextindentation}
838
839\protected\def\buff_verbatim_type_buffer_class#1%
840  {\begingroup
841   \cdef\currenttyping{#1}%
842   \buff_verbatim_type_buffer}
843
844\tolerant\protected\def\buff_verbatim_type_defined_buffer[#1]#*[#2]#*[#S#3]% category name settings
845  {\begingroup
846   \cdef\currenttyping{\namedbufferparameter{#1}\c!category}%
847   \ifempty\currenttyping
848     \let\currenttyping\v!buffer
849   \fi
850   \ifhastok={#3}%
851     \setupcurrenttyping[#3]%
852   \orelse\ifempty{#3}\else
853     \cdef\currenttyping{#3}
854   \fi
855   \buff_verbatim_type_buffer_indeed{\currenttyping}{#2}%
856   \useindentnextparameter\typingparameter
857   \endgroup
858   \dorechecknextindentation}
859
860\protected\def\buff_verbatim_type_buffer_indeed#1#2% category name
861  {\cdef\currenttyping{#1}%
862   \typingparameter\c!before\relax
863   \startpacked[\v!blank]
864   \buff_verbatim_setup_keep_together
865   \buff_verbatim_setup_line_numbering
866   \buff_verbatim_initialize_typing_one
867   \buff_verbatim_initialize_typing_two
868   \dostarttaggedchained\t!verbatimblock{#1}{#1}\??typing
869   \beginofverbatimlines
870   \dostarttaggednodetail\t!verbatimlines
871   \clf_typebuffer
872     name   {#2}%
873     strip  {\typingparameter\c!strip}%
874     range  {\typingparameter\c!range}%
875     regime {\currentregime}%
876     tab    {\typingparameter\c!tab}%
877     par    {\typingparameter\c!paragraph}%
878     method {\p_buff_option}%
879     escape {\typingparameter\c!escape}%
880     nature {display}%
881   \relax
882   \dostoptagged
883   \endofverbatimlines
884   \dostoptagged
885   \stoppacked
886   \typingparameter\c!after\relax}
887
888\permanent\tolerant\protected\def\typeinlinebuffer[#S#1]#,[#S#2]%
889  {\dontleavehmode
890   \begingroup
891   \enforced\let\setupcurrenttyping\setupcurrenttype % a terrible hack but it saves code
892   \lettonothing\currenttype
893   \ifparameters
894     \buff_verbatim_type_buffer_indeed_inline\currenttyping\empty% []
895   \or
896     \ifhastok={#1}%
897       \setupcurrenttyping[#1]%
898       \buff_verbatim_type_buffer_indeed_inline\currenttyping\empty% [settings]
899     \else
900       \processcommalist[#1]{\buff_verbatim_type_buffer_indeed_inline\currenttyping}% [name]
901     \fi
902   \or
903     \setupcurrenttyping[#2]%
904     \processcommalist[#1]{\buff_verbatim_type_buffer_indeed_inline\currenttyping}% [name] [settings]
905   \fi
906   \endgroup}
907
908\protected\def\buff_verbatim_type_buffer_indeed_inline#1#2% category name
909  {\cdef\currenttype{#1}%
910   \buff_verbatim_initialize_type_one
911   \expand\everyinitializeverbatim % \buff_verbatim_initialize_type_two
912   \dostarttaggedchained\t!verbatim\currenttype\currenttype\??type
913   \clf_typebuffer
914     name   {#2}%
915     strip  {\v!yes}%
916     regime {\currentregime}%
917     method {\p_buff_option}%
918     nature {inline}% is default anyway
919   \relax
920   \dostoptagged}
921
922% get     : before/after of buffer
923% typing  : before/after of typing
924% process : no before/after (special case anyway)
925
926% the next one is obsolete (bad name and used nowhere) so if it stays
927% the name will change
928
929\permanent\tolerant\protected\def\processbuffer[#S#1]#*[#S#2]%
930  {\writestatus{nota bene}{\string\processbuffer\space is obsolete}%
931   \begingroup
932   \ifarguments
933     \buff_verbatim_process_indeed\v!buffer\empty% []
934   \or
935     \ifhastok={#1}%
936       \setuptyping[\v!buffer][#1]%
937       \buff_verbatim_process_indeed\v!buffer\empty% [settings]
938     \else
939       \processcommalist[#1]{\buff_verbatim_process_indeed\v!buffer}% [name]
940     \fi
941   \or
942     \setuptyping[\v!buffer][#2]%
943     \processcommalist[#1]{\buff_verbatim_process_indeed\v!buffer}% [name] [settings]
944   \fi
945   \endgroup}
946
947\def\buff_verbatim_process_indeed#1#2%
948  {\cdef\currenttyping{#1}%
949   \clf_processbuffer
950     name   {#2}%
951     strip  {\typingparameter\c!strip}%
952     tab    {\typingparameter\c!tab}%
953   % par    {\typingparameter\c!paragraph}%
954   % method {\p_buff_option}%
955     nature {direct}%
956   \relax}
957
958% so far for obsolete
959
960% line numbering, keep broken lines together
961
962\newinteger\nofverbatimlines
963
964% \protected\def\buff_verbatim_begin_of_line
965%   {\ifconditional\verbatimnumberinglines
966%      \global\advanceby\nofverbatimlines\plusone
967%      \c_attr_verbatimline\nofverbatimlines
968%    \fi
969%    \noindent
970%    \buff_verbatim_set_line_margin
971%    \expand\everyline % maybe also after starttagged
972%    \strut % after starttagged, else break !
973%    \dostarttaggednodetail\t!verbatimline}
974
975% \protected\def\buff_verbatim_end_of_line
976%   {\dostoptagged
977%   %\obeyedline % is actually \par here
978%    \ifconditional\c_buff_lines_as_paragraph
979%      \parbreak
980%    \else
981%      \par
982%    \fi
983%    \ifconditional\verbatimnumberinglines
984%      \c_attr_verbatimline\attributeunsetvalue
985%    \fi}
986
987% \protected\def\buff_verbatim_end_of_line
988%   {\dostoptagged
989%   %\obeyedline % is actually \par here
990%    \ifconditional\c_buff_lines_as_paragraph
991%      \parbreak
992%    \else
993%      \par
994%      \buff_verbatim_inject_breaks % new because now widowpenalties apply to the par
995%    \fi
996%    \ifconditional\verbatimnumberinglines
997%      \c_attr_verbatimline\attributeunsetvalue
998%    \fi}
999
1000% \protected\def\buff_verbatim_empty_line
1001%   {\dostoptagged
1002%    \ifconditional\verbatimnumberinglines
1003%      \par\strut\par % this will be an option where we use a signal instead of a strut
1004%    \else
1005%      \blank[\typingparameter\c!blank]%
1006%    \fi
1007%    \dostarttaggednodetail\t!verbatimlines}
1008
1009% hooks (todo: frozen):
1010
1011% see (1), which is why \par is needed:
1012%
1013% \starttyping
1014% line 01
1015% line 02
1016% .... (add lines)
1017% line 22
1018% line 23
1019% \stoptyping
1020
1021\newinteger    \c_buff_verbatim_noflines
1022\newinteger    \c_buff_verbatim_current
1023\newconditional\c_buff_optimize_linebreaks
1024
1025\permanent\protected\def\doverbatimspace           {\obeyedspace}
1026
1027\permanent\protected\def\doinlineverbatimstart     {}
1028\permanent\protected\def\doinlineverbatimstop      {}
1029\permanent\protected\def\doinlineverbatimbeginline {}
1030\permanent\protected\def\doinlineverbatimnewline   {\obeyedspace}
1031\permanent\protected\def\doinlineverbatimemptyline {\obeyedspace}
1032
1033% \permanent\protected\def\dodisplayverbatimstart    {\advanceby\c_buff_verbatim_current\plusone
1034%                                                     \buff_verbatim_begin_of_line}
1035% \permanent\protected\def\dodisplayverbatimstop     {\buff_verbatim_end_of_line}
1036% \permanent\protected\def\dodisplayverbatimemptyline{\buff_verbatim_empty_line}
1037% \permanent\protected\def\dodisplayverbatimbeginline{\advanceby\c_buff_verbatim_current\plusone
1038%                                                     \buff_verbatim_begin_of_line}
1039% \permanent\protected\def\dodisplayverbatimnewline  {\buff_verbatim_end_of_line
1040%                                                     \ifconditional\c_buff_optimize_linebreaks
1041%                                                       \par % needed see (1), if issue then rely on vbreak
1042%                                                       \buff_verbatim_inject_breaks
1043%                                                     \orelse\ifconditional\c_buff_lines_as_paragraph
1044%                                                         % we need to find a bordercase but no crlf here
1045%                                                     \else
1046%                                                       \parbreak
1047%                                                     \fi}
1048
1049% \permanent\protected\def\dodisplayverbatimstart    {\starthangrange}
1050% \permanent\protected\def\dodisplayverbatimemptyline{\stophangrange
1051%                                                     \blank[\typingparameter\c!blank]%
1052%                                                     \starthangrange}
1053% \permanent\protected\def\dodisplayverbatimstop     {\stophangrange}
1054% \permanent\protected\def\dodisplayverbatimbeginline{\starthangrangestep}
1055% \permanent\protected\def\dodisplayverbatimnewline  {\stophangrangestep}
1056
1057%D \starttyping
1058%D \showmakeup[vpenalty,line,par]
1059%D
1060%D \widowpenalties 3 3000 2000 1000
1061%D \clubpenalties  3   30   20   10
1062%D
1063%D % \widowpenalties 3 options \largestspecificationoptioncode 3000 2000 1000
1064%D % \clubpenalties  3 options \largestspecificationoptioncode   30   20   10
1065%D
1066%D \startbuffer
1067%D test test test test test test and more test test test test test test test and more test
1068%D test test test test test test and more test test test test test test test and more test
1069%D
1070%D test test test test test test and more test test test test test test test and more test
1071%D test test test test test test and more test test test test test test test and more test
1072%D \stopbuffer
1073%D
1074%D \typebuffer[keeptogether=paragraph,align=hangright]
1075%D \typebuffer[keeptogether=paragraph,align=hangleft]
1076%D \stoptyping
1077
1078
1079% test
1080%
1081% \starttyping
1082% first
1083% second second
1084% third third third
1085% fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth
1086% fifth
1087% sixth
1088% \stoptyping
1089%
1090% test
1091%
1092% \starttyping
1093% first
1094% second second
1095% third third third
1096% fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth
1097% fifth
1098% sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth sixth
1099% \stoptyping
1100%
1101% test
1102
1103\permanent\protected\def\dodisplayverbatimstart
1104  {\advanceby\c_buff_verbatim_current\plusone
1105   \ifconditional\verbatimnumberinglines
1106     \global\advanceby\nofverbatimlines\plusone
1107     \c_attr_verbatimline\nofverbatimlines
1108   \fi
1109   \ifconditional\c_buff_lines_as_paragraph
1110     \buff_verbatim_set_line_margin
1111     \starthangrange
1112   \else
1113     \noindent
1114     \buff_verbatim_set_line_margin
1115   \fi
1116   \expand\everyline % maybe also after starttagged
1117   \dostarttaggednodetail\t!verbatimline
1118   \strut}
1119
1120\permanent\protected\def\dodisplayverbatimstop
1121  {\dostoptagged
1122   \ifconditional\c_buff_lines_as_paragraph
1123     \stophangrange % new because now widowpenalties apply to the par
1124   \orelse\ifconditional\c_buff_optimize_linebreaks
1125     \par
1126     \buff_verbatim_inject_breaks
1127   \else
1128     \par
1129   \fi
1130   \ifconditional\verbatimnumberinglines
1131     \c_attr_verbatimline\attributeunsetvalue
1132   \fi}
1133
1134\permanent\protected\def\dodisplayverbatimemptyline
1135  {\dostoptagged
1136   \ifconditional\c_buff_lines_as_paragraph
1137     \stophangrange
1138   \fi
1139   \ifconditional\verbatimnumberinglines
1140     \par\strut\par % this will be an option where we use a signal instead of a strut
1141   \else
1142     \blank[\typingparameter\c!blank]%
1143   \fi
1144   \ifconditional\c_buff_lines_as_paragraph
1145     \starthangrange
1146   \fi
1147   \dostarttaggednodetail\t!verbatimlines}
1148
1149\permanent\protected\def\dodisplayverbatimbeginline
1150  {\advanceby\c_buff_verbatim_current\plusone
1151   \ifconditional\verbatimnumberinglines
1152     \global\advanceby\nofverbatimlines\plusone
1153     \c_attr_verbatimline\nofverbatimlines
1154   \fi
1155   \ifconditional\c_buff_lines_as_paragraph
1156     \starthangrangestep
1157     \buff_verbatim_set_line_margin
1158   \else
1159     \noindent
1160     \buff_verbatim_set_line_margin
1161   \fi
1162   \expand\everyline
1163   \dostarttaggednodetail\t!verbatimline
1164   \strut}
1165
1166\permanent\protected\def\dodisplayverbatimnewline
1167  {\dostoptagged
1168   \ifconditional\c_buff_lines_as_paragraph
1169     \stophangrangestep
1170   \orelse\ifconditional\c_buff_optimize_linebreaks
1171     \par % needed see (1), if issue then rely on \vbreak or \parbreak
1172     \buff_verbatim_inject_breaks
1173   \else
1174     \par
1175   \fi
1176   \ifconditional\verbatimnumberinglines
1177     \c_attr_verbatimline\attributeunsetvalue
1178   \fi}
1179
1180\protected\def\buff_verbatim_inject_breaks % will become obsolete and single widow/club penalty driven
1181  {\ifnum\c_buff_verbatim_current=\plusone
1182     \nobreak % \novbreak
1183   \orelse\ifnum\c_buff_verbatim_noflines=\plusthree
1184     \nobreak % \novbreak
1185   \orelse\ifnum\c_buff_verbatim_current={\c_buff_verbatim_noflines-\plusone}%
1186     \nobreak % \novbreak
1187   \fi}
1188
1189\permanent\protected\def\dodisplayverbatiminitialize#1%
1190  {\forgetparindent % maybe more
1191   \c_buff_verbatim_noflines#1\relax
1192   \c_buff_verbatim_current\zerocount}
1193
1194\loadmarkfile{buff-imp-default}    % preloaded as otherwise spurious spaces inline due to loading
1195\loadmarkfile{buff-imp-nested}     % preloaded as otherwise spurious spaces inline due to loading
1196\loadmarkfile{buff-imp-escaped}    % for completeness
1197
1198%D To be considered:
1199
1200% \installcorenamespace{visualizer}
1201%
1202% \installcommandhandler \??visualizer {visualizer} \??visualizer
1203%
1204% \appendtoks
1205%     \frozen\instanceprotected\edefcsname\currentvisualizer\endcsname{\buff_verbatim_visualize{\currentvisualizer}}%
1206% \to \everydefinevisualizer
1207%
1208% \protected\def\buff_verbatim_visualize#1%
1209%   {\bgroup
1210%    \def\currentvisualizer{#1}%
1211%    \usevisualizerstyleandcolor\c!style\c!color
1212%    \let\next}
1213
1214% in footnotes no longer needed as we can preroll
1215
1216\appendtoks
1217  % \enforced\def\type#1{\detokenize\expandafter{\csstring#1}}% \protecteddetokenize
1218    \enforced\def\type#1{\detokenize{#1}}% \protecteddetokenize fails
1219    \enforced\def\tex #1{\letterbackslash#1}%
1220\to \everysimplifycommands
1221
1222\stopcontextdefinitioncode
1223
1224%D This is \type {\asciimode} without the double comment hackery:
1225
1226\permanent\protected\def\literalmode{\setcatcodetable\txtcatcodes}
1227
1228\protect \endinput
1229