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