summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/magazines/mag-1102-mkiv.tex
blob: ad9dcc5f9bfe30f8b6cb43634f0c843073192d45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
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
% language=uk

% author    : Hans Hagen
% copyright : PRAGMA ADE & ConTeXt Development Team
% license   : Creative Commons Attribution ShareAlike 4.0 International
% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
% origin    : the ConTeXt distribution
%
% comment   : Because this manual is distributed with TeX distributions it comes with a rather
%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
%             that they describe. Using parts of the content otherwise can therefore conflict
%             with existing functionality and we cannot be held responsible for that. Many of
%             the manuals contain characteristic graphics and personal notes or examples that
%             make no sense when used out-of-context.
%
% comment   : Some chapters might have been published in TugBoat, the NTG Maps, the ConTeXt
%             Group journal or otherwise. Thanks to the editors for corrections. Also thanks
%             to users for testing, feedback and corrections.

\usemodule[mag-01,abr-02]

\startbuffer[abstract]
    A not so widely known feature of the verbatim handler in \CONTEXT\ is the
    ability to add comments in another style and \MKIV\ even offers a bit more.
    Here some examples are shown.
\stopbuffer

\startdocument
  [title={Annotated Verbatim},
   author=Hans Hagen,
   affiliation=PRAGMA ADE,
   date=July 2011,
   number=1102 \MKIV]

\definetextbackground
  [example]
  [frame=on,
   framecolor=darkblue,
   location=paragraph,
   leftoffset=1ex,
   topoffset=1ex,
   bottomoffset=1ex]

Annotating verbatim content is done using a mechanism called escaping. For such
special cases it's often best to define a specific instance.

\startbuffer[define]
\definetyping
  [annotatedtyping]
  [escape=/,
   color=darkblue,
   before=,
   after=]
\stopbuffer

\startbuffer[example]
\startannotatedtyping
bla = test               /bgroup /sl oeps /egroup
                         /bgroup /bf some more /egroup
    | another test
    | somethingverylong  /bgroup /it oeps /egroup
\stopannotatedtyping
\stopbuffer

\typebuffer[define,example][option=TEX] \getbuffer[define]

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

In this example the \type {/} now serves as an escape character. Of course you
can also use the normal backslash but then you need to use a command to specify
it.

\startbuffer[setup]
\setuptyping
  [annotatedtyping]
  [escape=\letterbackslash]
\stopbuffer

\typebuffer[setup][option=TEX] \getbuffer[setup]

Now we can say:

\startbuffer[example]
\startannotatedtyping
bla = test               \bgroup \sl oeps \egroup
                         \bgroup \bf some more \egroup
    | another test
    | somethingverylong  \bgroup \it oeps \egroup
\stopannotatedtyping
\stopbuffer

\typebuffer[example][option=TEX]

and get:

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

You can also define an end symbol:

\startbuffer[setup]
\setuptyping
  [annotatedtyping]
  [escape={//,*},
   color=darkblue]

\definestartstop
  [cmt]
  [style=\rm\bf]
\stopbuffer

\typebuffer[setup][option=TEX] \getbuffer[setup]

Here the \type {//} starts the annotation and \type {*} ends it.

\startbuffer[example]
\startannotatedtyping
bla = test               // \black // \cmt{oeps} *
                         // \black // \cmt{some more} *
    | another test
    | somethingverylong  // \black // \cmt{oeps} *
\stopannotatedtyping
\stopbuffer

\typebuffer[example][option=TEX]

Contrary to the first example, all text in the annotation is treated as \TEX\
input:

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

You can consider using more balanced tagging, as in:

\startbuffer[setup]
\setuptyping
  [annotatedtyping]
  [escape={<<,>>},
   color=darkblue]
\stopbuffer

\typebuffer[example][option=TEX]

Watch how we limit the annotation to part of the text:

\startbuffer[example]
\startannotatedtyping
bla = test               << \rm\bf first  >> test
                         << \rm\bf second >> test
    | test
    | somethingverylong  << \rm\bf fourth >> test
\stopannotatedtyping
\stopbuffer

\typebuffer[example][option=TEX]

The \type {test} a the end of the lines is verbatim again.

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

If no end symbol is given, the end of the line is used instead:

\startbuffer[setup]
\setuptyping
  [annotatedtyping]
  [escape={//,},
   color=darkblue]
\stopbuffer

\typebuffer[setup][option=TEX] \getbuffer[setup]

Watch out: here we use \type {{//,}} and not just \type {//} (which would trigger
the escaped variant).

\definestartstop[cmt][style=\rm\bf]

\startbuffer[example]
\startannotatedtyping
bla = test               // \black // \cmt{oeps}
                         // \black // \cmt{some more}
    | test
    | somethingverylong  // \black // \cmt{oeps}
\stopannotatedtyping
\stopbuffer

\typebuffer[example][option=TEX]

The result is:

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

This can also be done easier by abusing the \type {style} option of \type {cmt}:

\startbuffer[setup]
\definestartstop
  [cmt]
  [color=black,
   style=\black //\rm\bf\space]
\stopbuffer

\typebuffer[setup][option=TEX] \getbuffer[setup]

When we give:

\startbuffer[example]
\startannotatedtyping
bla = test               // \cmt{oeps}
                         // \cmt{some more}
    | test
    | somethingverylong  // \cmt{oeps}
\stopannotatedtyping
\stopbuffer

\typebuffer[example][option=TEX]

We get:

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

For cases like this, where we want to specify a somewhat detailed way to deal
with a situation, we can use processors: \footnote {More mechanisms in \CONTEXT\
\MKIV\ will use that feature.}

\startbuffer[setup]
\defineprocessor
  [escape]
  [style=bold,
   color=black,
   left=(,right=)]
\stopbuffer

\typebuffer[setup][option=TEX] \getbuffer[setup]

The previous definition of the annotation now becomes:

\startbuffer[setup]
\setuptyping
  [annotatedtyping]
  [escape=escape->{//,},
   color=darkblue]
\stopbuffer

\typebuffer[setup][option=TEX] \getbuffer[setup]

This time no commands are needed in the annotation:

\startbuffer[example]
\startannotatedtyping
bla = test               // first
                         // second
    | test
    | somethingverylong  // fourth
\stopannotatedtyping
\stopbuffer

\typebuffer[example][option=TEX]

The processor is applied to all text following the \type {//}. Spaces before the
text are stripped.

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

As some characters are special to \TEX, sometimes you need to escape the boundary
sequence:

\startbuffer[setup]
\defineprocessor
  [myescape]
  [style=\rm\tf,
   color=black]

\setuptyping
  [annotatedtyping]
  [escape=myescape->{\letterhash\letterhash,},
   color=darkgreen]
\stopbuffer

\typebuffer[setup][option=TEX] \getbuffer[setup]

All text between the double hashes and the end of the line is now treated as
annotation:

\startbuffer[example]
\startannotatedtyping
bla = test               ## first \bf test
                         ## second \sl test
    | test
    | somethingverylong  ## third \it test
\stopannotatedtyping
\stopbuffer

\typebuffer[example][option=TEX]

So we get:

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

We can beautify \TEX\ commenting as follows:

\startbuffer[setup]
\defineprocessor
  [comment]
  [style=\rm,
   color=black,
   left={\tttf\letterpercent\space}]

\setuptyping
  [annotatedtyping]
  [escape=comment->{\letterpercent\letterpercent,},
   color=darkblue]
\stopbuffer

\typebuffer[setup][option=TEX] \getbuffer[setup]

Here the double comments are turned into a single one and the text after it is
typeset in a regular font:

\startbuffer[example]
\startannotatedtyping
bla = test               %% first \bf test
                         %% second \sl test
    | test
    | somethingverylong  %% third \it test
\stopannotatedtyping
\stopbuffer

\typebuffer[example][option=TEX]

This gives:

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

It is possible to define several escapes. Let's start with the delimited variant:

\startbuffer[setup]
\defineprocessor
  [escape_a]
  [style=bold,
   color=darkred,
   left=(,
   right=)]

\defineprocessor
  [escape_b]
  [style=bold,
   color=darkgreen,
   left=(,
   right=)]

\setuptyping
  [annotatedtyping]
  [escape={escape_a->{[[,]]},escape_b->{[(,)]}},
   color=darkblue]
\stopbuffer

\typebuffer[setup][option=TEX] \getbuffer[setup]

We can now alternate comments:

\startbuffer[example]
\startannotatedtyping
bla = test               [[ first  ]] test [( first  )]
                         [[ second ]] test [( second )]
    | test
    | somethingverylong  [[ fourth ]] test [( fourth )]
\stopannotatedtyping
\stopbuffer

\typebuffer[example][option=TEX]

When typeset this looks as follows:

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

The line terminated variant can also have multiple escapes.

\startbuffer[setup]
\defineprocessor
  [annotated_bf]
  [style=\rm\bf,
   color=darkred]

\defineprocessor
  [annotated_bs]
  [style=\rm\bs,
   color=darkyellow]

\setuptyping
  [annotatedtyping]
  [escape={annotated_bf->{!bf,},annotated_bs->{!bs,}},
   color=darkblue]
\stopbuffer

\typebuffer[setup][option=TEX] \getbuffer[setup]

So this time we have two ways to enter regular \TEX\ mode:

\startbuffer[example]
\startannotatedtyping
bla = test               !bf one {\em again}
                         !bs two {\em again}
    | test
    | somethingverylong  !bf three {\em again}
\stopannotatedtyping
\stopbuffer

\typebuffer[example][option=TEX]

These somewhat meaningful tags result in:

\starttextbackground[example]
    \getbuffer[example]
\stoptextbackground

\stopdocument