-
Notifications
You must be signed in to change notification settings - Fork 18
/
chapter14.tex
668 lines (629 loc) · 22.4 KB
/
chapter14.tex
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
% -*- coding: utf-8 -*-
\documentclass{book}
\input{preamble}
\setcounter{chapter}{13}
\begin{document}
%\chapter{Token Lists}\label{token}
\chapter{Token Lists}\label{token}
%\TeX\ has only one type of data structure: the \indextermsub{token}{list}
%There are token list registers that are available to the user,
%and \TeX\ has some special token lists: the \cs{every...}
%variables, \cs{errhelp}, and \cs{output}.
\TeX\ has only one type of data structure: the \indextermsub{token}{list}
There are token list registers that are available to the user,
and \TeX\ has some special token lists: the \cs{every...}
variables, \cs{errhelp}, and \cs{output}.
%\label{cschap:toks}\label{cschap:toksdef}\label{cschap:newtoks}
%\begin{inventory}
%\item [\cs{toks}]
% Prefix for a token list register.
\label{cschap:toks}\label{cschap:toksdef}\label{cschap:newtoks}
\begin{inventory}
\item [\cs{toks}]
Prefix for a token list register.
%\item [\cs{toksdef}]
% Define a control sequence to be a synonym for
% a~\cs{toks} register.
\item [\cs{toksdef}]
Define a control sequence to be a synonym for
a~\cs{toks} register.
%\item [\cs{newtoks}]
% Macro that allocates a token list register.
\item [\cs{newtoks}]
Macro that allocates a token list register.
%\end{inventory}
\end{inventory}
%%\point Token lists
%\section{Token lists}
%\point Token lists
\section{Token lists}
%Token lists are the only type of data structure that \TeX\ knows.
%They can contain character tokens and control sequence tokens.
%Spaces in a token list are significant.
%The only operations on token lists are assignment and
%unpacking.
Token lists are the only type of data structure that \TeX\ knows.
They can contain character tokens and control sequence tokens.
Spaces in a token list are significant.
The only operations on token lists are assignment and
unpacking.
%\TeX\ has 256 token list registers \verb|\toks|$nnn$ that can be
%allocated using the macro \verb|\newtoks|, or explicitly
%assigned by \cs{toksdef}; see below.
\TeX\ has 256 token list registers \verb|\toks|$nnn$ that can be
allocated using the macro \verb|\newtoks|, or explicitly
assigned by \cs{toksdef}; see below.
%%\point Use of token lists
%\section{Use of token lists}
%\point Use of token lists
\section{Use of token lists}
%Token lists are assigned by a \gr{variable assignment},
%which is in this case takes one of the forms
%\begin{disp}\gr{token variable}\gr{equals}\gr{general text}\nl
% \gr{token variable}\gr{equals}\gr{filler}\gr{token variable}\end{disp}
%Here a \gr{token variable} is an explicit \cs{toks}$nnn$
%register, something that has been defined to such a register
%by \cs{toksdef} (probably hidden in \cs{newtoks}),
%or one of the special \gr{token parameter}
%lists below.
%A~\gr{general text} has an explicit closing brace, but the
%open brace can be implicit.
Token lists are assigned by a \gr{variable assignment},
which is in this case takes one of the forms
\begin{disp}\gr{token variable}\gr{equals}\gr{general text}\nl
\gr{token variable}\gr{equals}\gr{filler}\gr{token variable}\end{disp}
Here a \gr{token variable} is an explicit \cs{toks}$nnn$
register, something that has been defined to such a register
by \cs{toksdef} (probably hidden in \cs{newtoks}),
or one of the special \gr{token parameter}
lists below.
A~\gr{general text} has an explicit closing brace, but the
open brace can be implicit.
%Examples of token lists are (the first two lines are equivalent):
%\begin{verbatim}
%\toks0=\bgroup \a \b cd}
%\toks0={\a \b cd}
%\toks1=\toks2
%\end{verbatim}
Examples of token lists are (the first two lines are equivalent):
\begin{verbatim}
\toks0=\bgroup \a \b cd}
\toks0={\a \b cd}
\toks1=\toks2
\end{verbatim}
%Unpacking a token list is done by the command \cs{the}:
%the expansion of \cs{the}\gr{token variable} is the
%sequence of tokens that was in the token list.
Unpacking a token list is done by the command \cs{the}:
the expansion of \cs{the}\gr{token variable} is the
sequence of tokens that was in the token list.
%Token lists have a special behaviour in \cs{edef}:
%when prefixed by \verb|\the| they are unpacked,
%but the resulting tokens
%are not evaluated further. Thus
%\begin{verbatim}
%\toks0={\a \b} \edef\SomeCs{\the\toks0}
%\end{verbatim}
%gives
%\begin{verbatim}
%\SomeCs: macro:-> \a \b
%\end{verbatim}
%This is in contrast to what happens ordinarily in an~\cs{edef};
%see page~\pageref{expand:edef}.
Token lists have a special behaviour in \cs{edef}:
when prefixed by \verb|\the| they are unpacked,
but the resulting tokens
are not evaluated further. Thus
\begin{verbatim}
\toks0={\a \b} \edef\SomeCs{\the\toks0}
\end{verbatim}
gives
\begin{verbatim}
\SomeCs: macro:-> \a \b
\end{verbatim}
This is in contrast to what happens ordinarily in an~\cs{edef};
see page~\pageref{expand:edef}.
%%\point \gr{token parameter}
%\section{\gr{token parameter}}
%\point \gr{token parameter}
\section{\gr{token parameter}}
%There are in \TeX\ a number of token lists that are automatically
%inserted at certain points. These \gr{token parameter}s are
%the following:
%\begin{description} \item [\cs{output}]
% this token list is inserted
% whenever \TeX\ decides it has sufficient material for a page,
% or when the user forces activation by a penalty~$\leq-10\,000$
% in vertical mode
% (see Chapter~\ref{output});
%\item [\cs{everypar}]
% is inserted when \TeX\ switches from external or internal
% vertical mode to unrestricted horizontal mode
% (see Chapter~\ref{par:start});
%\item [\cs{everymath}]
% is inserted after a single math-shift character that starts
% a formula;
%\item [\cs{everydisplay}]
% is inserted after a double math-shift character that starts
% a display formula;
%\item [\cs{everyhbox}]
% is inserted when an \cs{hbox} begins (see Chapter~\ref{boxes});
%\item [\cs{everyvbox}]
% is inserted when a vertical box begins (see Chapter~\ref{boxes});
%\item [\cs{everyjob}]
% is inserted when a job begins (see Chapter~\ref{run});
%\item [\cs{everycr}]
% is inserted in alignments after \cs{cr} or a non-redundant
% \cs{crcr} (see Chapter~\ref{align});
%\item [\cs{errhelp}]
% contains tokens to supplement an \cs{errmessage}
% (see Chapter~\ref{error}).
%\end{description}
There are in \TeX\ a number of token lists that are automatically
inserted at certain points. These \gr{token parameter}s are
the following:
\begin{description} \item [\cs{output}]
this token list is inserted
whenever \TeX\ decides it has sufficient material for a page,
or when the user forces activation by a penalty~$\leq-10\,000$
in vertical mode
(see Chapter~\ref{output});
\item [\cs{everypar}]
is inserted when \TeX\ switches from external or internal
vertical mode to unrestricted horizontal mode
(see Chapter~\ref{par:start});
\item [\cs{everymath}]
is inserted after a single math-shift character that starts
a formula;
\item [\cs{everydisplay}]
is inserted after a double math-shift character that starts
a display formula;
\item [\cs{everyhbox}]
is inserted when an \cs{hbox} begins (see Chapter~\ref{boxes});
\item [\cs{everyvbox}]
is inserted when a vertical box begins (see Chapter~\ref{boxes});
\item [\cs{everyjob}]
is inserted when a job begins (see Chapter~\ref{run});
\item [\cs{everycr}]
is inserted in alignments after \cs{cr} or a non-redundant
\cs{crcr} (see Chapter~\ref{align});
\item [\cs{errhelp}]
contains tokens to supplement an \cs{errmessage}
(see Chapter~\ref{error}).
\end{description}
%A \gr{token parameter} behaves the same as an explicit \cs{toks}$nnn$
%list, or a quantity defined by \cs{toksdef}.
A \gr{token parameter} behaves the same as an explicit \cs{toks}$nnn$
list, or a quantity defined by \cs{toksdef}.
%%\point Token list registers
%\section{Token list registers}
%\point Token list registers
\section{Token list registers}
%Token lists can be stored in \csidx{toks} registers:
%\begin{Disp}\cs{toks}\gr{8-bit number}\end{Disp}
%which is a \gr{token variable}.
%Synonyms for token list registers can be made by the \gr{registerdef}
%command \csidx{toksdef} in a \gr{shorthand definition}:
%\begin{Disp}\cs{toksdef}\gr{control sequence}\gr{equals}\gr{8-bit number}
%\end{Disp} A control sequence defined this way is called
%a \gr{toksdef token}, and this is also a token variable
%(the remaining third kind of token variable is
%the \gr{token parameter}).
Token lists can be stored in \csidx{toks} registers:
\begin{Disp}\cs{toks}\gr{8-bit number}\end{Disp}
which is a \gr{token variable}.
Synonyms for token list registers can be made by the \gr{registerdef}
command \csidx{toksdef} in a \gr{shorthand definition}:
\begin{Disp}\cs{toksdef}\gr{control sequence}\gr{equals}\gr{8-bit number}
\end{Disp} A control sequence defined this way is called
a \gr{toksdef token}, and this is also a token variable
(the remaining third kind of token variable is
the \gr{token parameter}).
%The plain \TeX\ macro \csidx{newtoks} uses \cs{toksdef} to
%allocate unused token list registers. This macro is \cs{outer}.
The plain \TeX\ macro \csidx{newtoks} uses \cs{toksdef} to
allocate unused token list registers. This macro is \cs{outer}.
%\section{Examples}
\section{Examples}
%Token lists are probably among the least obvious components
%of \TeX: most \TeX\ users will never find occasion for their use,
%but format designers and other macro writers
%can find interesting applications.
%Following are some examples of the sorts of things that can be
%done with token lists.
Token lists are probably among the least obvious components
of \TeX: most \TeX\ users will never find occasion for their use,
but format designers and other macro writers
can find interesting applications.
Following are some examples of the sorts of things that can be
done with token lists.
%%\spoint Operations on token lists: stack macros
%\subsection{Operations on token lists: stack macros}
%\spoint Operations on token lists: stack macros
\subsection{Operations on token lists: stack macros}
%The number of primitive operations available for token lists is
%\howto Stack macros\par
%rather limited: assignment and unpacking. However, these are
%sufficient to implement other operations such as appending.
The number of primitive operations available for token lists is
\howto Stack macros\par
rather limited: assignment and unpacking. However, these are
sufficient to implement other operations such as appending.
%Let us say we have allocated a token register
%\begin{verbatim}
%\newtoks\list \list={\c}
%\end{verbatim}
%and we want to add tokens to it,
%\alt
%using the syntax
%\begin{verbatim}
%\Prepend \a \b (to:)\list
%\end{verbatim}
%such that
%\begin{verbatim}
%\showthe\list
%\end{verbatim}
%gives
%\begin{verbatim}
%> \a \b \c .
%\end{verbatim}
%For this the original list has to be unpacked, and
%\alt
%the new tokens followed by the old contents have to assigned
%again to the register. Unpacking can be done with \cs{the}
%inside an \cs{edef}, so we arrive at the following macro:
%\begin{verbatim}
%\def\Prepend#1(to:)#2{\toks0={#1}%
% \edef\act{\noexpand#2={\the\toks0 \the#2}}%
% \act}
%\end{verbatim}
%Note that the tokens that are to be added are first packed
%\alt
%into a temporary token list, which is then again unpacked
%inside the \cs{edef}. Including them directly would have
%led to their expansion.
Let us say we have allocated a token register
\begin{verbatim}
\newtoks\list \list={\c}
\end{verbatim}
and we want to add tokens to it,
\alt
using the syntax
\begin{verbatim}
\Prepend \a \b (to:)\list
\end{verbatim}
such that
\begin{verbatim}
\showthe\list
\end{verbatim}
gives
\begin{verbatim}
> \a \b \c .
\end{verbatim}
For this the original list has to be unpacked, and
\alt
the new tokens followed by the old contents have to assigned
again to the register. Unpacking can be done with \cs{the}
inside an \cs{edef}, so we arrive at the following macro:
\begin{verbatim}
\def\Prepend#1(to:)#2{\toks0={#1}%
\edef\act{\noexpand#2={\the\toks0 \the#2}}%
\act}
\end{verbatim}
Note that the tokens that are to be added are first packed
\alt
into a temporary token list, which is then again unpacked
inside the \cs{edef}. Including them directly would have
led to their expansion.
%Next we want to use token lists as a sort of stack:
%we want a `pop' operation that removes the first element
%from the list. Specifically,
%\begin{verbatim}
%\Pop\list(into:)\first
%\show\first \showthe\list
%\end{verbatim}
%should give
%\begin{verbatim}
%> \first=macro:
%->\a .
%\end{verbatim}
%and for the remaining list
%\begin{verbatim}
%
%> \b \c .
%\end{verbatim}
Next we want to use token lists as a sort of stack:
we want a `pop' operation that removes the first element
from the list. Specifically,
\begin{verbatim}
\Pop\list(into:)\first
\show\first \showthe\list
\end{verbatim}
should give
\begin{verbatim}
> \first=macro:
->\a .
\end{verbatim}
and for the remaining list
\begin{verbatim}
> \b \c .
\end{verbatim}
%Here we make creative use of delimited and undelimited
%parameters. With an \cs{edef} we unpack the list,
%and the auxiliary macro \cs{SplitOff} scoops up the elements
%as one undelimited argument, the first element, and one
%delimited argument, the rest of the elements.
%\begin{verbatim}
%\def\Pop#1(into:)#2{%
% \edef\act{\noexpand\SplitOff\the#1%
% (head:)\noexpand#2(tail:)\noexpand#1}%
% \act}
%\def\SplitOff#1#2(head:)#3(tail:)#4{\def#3{#1}#4={#2}}
%\end{verbatim}
Here we make creative use of delimited and undelimited
parameters. With an \cs{edef} we unpack the list,
and the auxiliary macro \cs{SplitOff} scoops up the elements
as one undelimited argument, the first element, and one
delimited argument, the rest of the elements.
\begin{verbatim}
\def\Pop#1(into:)#2{%
\edef\act{\noexpand\SplitOff\the#1%
(head:)\noexpand#2(tail:)\noexpand#1}%
\act}
\def\SplitOff#1#2(head:)#3(tail:)#4{\def#3{#1}#4={#2}}
\end{verbatim}
%\subsection{Executing token lists}
\subsection{Executing token lists}
%The \cs{the} operation for unpacking token lists was used above
%only inside an \cs{edef}. Used on its own it has the effect
%of feeding the tokens of the list to \TeX's expansion mechanism.
%If the tokens have been added to the list in a uniform syntax,
%this gives rise to some interesting possibilities.
The \cs{the} operation for unpacking token lists was used above
only inside an \cs{edef}. Used on its own it has the effect
of feeding the tokens of the list to \TeX's expansion mechanism.
If the tokens have been added to the list in a uniform syntax,
this gives rise to some interesting possibilities.
%Imagine that we are implementing the bookkeeping of external
%files for a format. Such external files can be used for
%table of contents, list of figures, et cetera.
%If the presence
%of such objects is under the control of the user, we need some
%general routines for opening and closing files, and keeping
%track of what files we have opened at the user's request.
Imagine that we are implementing the bookkeeping of external
files for a format. Such external files can be used for
table of contents, list of figures, et cetera.
If the presence
of such objects is under the control of the user, we need some
general routines for opening and closing files, and keeping
track of what files we have opened at the user's request.
%Here only some routines for bookkeeping will be described.
%Let us say there is a list of auxiliary files, and an auxiliary
%counter:
%\begin{verbatim}
%\newtoks\auxlist \newcount\auxcount
%\end{verbatim}
%First of all there must be an operation to add auxiliary files:
%\begin{verbatim}
%\def\NewAuxFile#1{\AddToAuxList{#1}%
% % plus other actions
% }
%\def\AddToAuxList#1{\let\\=\relax
% \edef\act{\noexpand\auxlist={\the\auxlist \\{#1}}}%
% \act}
%\end{verbatim}
%This adds the name to the list in a uniform format:
%\begin{verbatim}
%\NewAuxFile{toc} \NewAuxFile{lof}
%\showthe\auxlist
%> \\{toc}\\{lof}.
%\end{verbatim}
%using the control sequence \verb>\\> which is left undefined.
Here only some routines for bookkeeping will be described.
Let us say there is a list of auxiliary files, and an auxiliary
counter:
\begin{verbatim}
\newtoks\auxlist \newcount\auxcount
\end{verbatim}
First of all there must be an operation to add auxiliary files:
\begin{verbatim}
\def\NewAuxFile#1{\AddToAuxList{#1}%
% plus other actions
}
\def\AddToAuxList#1{\let\\=\relax
\edef\act{\noexpand\auxlist={\the\auxlist \\{#1}}}%
\act}
\end{verbatim}
This adds the name to the list in a uniform format:
\begin{verbatim}
\NewAuxFile{toc} \NewAuxFile{lof}
\showthe\auxlist
> \\{toc}\\{lof}.
\end{verbatim}
using the control sequence \verb>\\> which is left undefined.
%Now this control sequence can be used for instance to
%count the number of elements in the list:
%\begin{verbatim}
%\def\ComputeLengthOfAuxList{\auxcount=0
% \def\\##1{\advance\auxcount1\relax}%
% \the\auxlist}
%\ComputeLengthOfAuxList \showthe\auxcount
%> 2.
%\end{verbatim}
%Another use of this structure is the following:
%at the end of the job we can now close all auxiliary
%files at once, by
%\begin{verbatim}
%\def\CloseAuxFiles{\def\\##1{\CloseAuxFile{##1}}%
% \the\auxlist}
%\def\CloseAuxFile#1{\message{closing file: #1. }%
% % plus other actions
% }
%\CloseAuxFiles
%\end{verbatim}
%which gives the output
%\begin{verbatim}
%closing file: toc. closing file: lof.
%\end{verbatim}
Now this control sequence can be used for instance to
count the number of elements in the list:
\begin{verbatim}
\def\ComputeLengthOfAuxList{\auxcount=0
\def\\##1{\advance\auxcount1\relax}%
\the\auxlist}
\ComputeLengthOfAuxList \showthe\auxcount
> 2.
\end{verbatim}
Another use of this structure is the following:
at the end of the job we can now close all auxiliary
files at once, by
\begin{verbatim}
\def\CloseAuxFiles{\def\\##1{\CloseAuxFile{##1}}%
\the\auxlist}
\def\CloseAuxFile#1{\message{closing file: #1. }%
% plus other actions
}
\CloseAuxFiles
\end{verbatim}
which gives the output
\begin{verbatim}
closing file: toc. closing file: lof.
\end{verbatim}
%%
%%%% \begin{comment}
%%%%
%%%% % %\spoint Dynamic macro definition
%%%% % \subsection{Dynamic macro definition}
%%%%
%%%% % Unpacking token lists inside an \cs{edef} can be put to a
%%%% % rather ambitious use: dynamic definition of macros.
%%%% % Consider a simple example.
%%%% % \altt
%%%% % We set ourselves the goal of letting
%%%% % the user define macros, without ever having to use \cs{def}.
%%%% % The syntax for this could look like
%%%% \begin{verbatim}
%%%% % \startdefinition
%%%% % \do:this
%%%% % \do:that
%%%% % \define:MyMacro
%%%% % \end{verbatim}
%%%% % such that \verb>\show\MyMacro> gives
%%%% \begin{verbatim}
%%%% % > \MyMacro=macro:
%%%% % ->\this \that .
%%%% % \end{verbatim}
%%%% % An implementation of this uses a token list to collect
%%%% % the commands that the user specifies:
%%%% \begin{verbatim}
%%%% % \newtoks\actionlist
%%%% % \end{verbatim}
%%%% % The first command is easy:
%%%% \begin{verbatim}
%%%% % \def\startdefinition{\actionlist{}}
%%%% % \end{verbatim}
%%%% % Now the \cs{do} command has to hang control sequences
%%%% % in the \cs{actionlist}:
%%%% \begin{verbatim}
%%%% % \def\do:#1 {%
%%%% % \edef\act{\noexpand\appendaction
%%%% % \expandafter\noexpand\csname#1\endcsname}%
%%%% % \act}
%%%% % \end{verbatim}
%%%% % The \cs{edef} is used solely to form the actual control sequence.
%%%% % The next macro uses \cs{edef} to unpack the \cs{actionlist} so far:
%%%% %
%%%% \begin{verbatim}
%%%% % \def\appendaction#1{%
%%%% % \edef\act{\noexpand\actionlist=
%%%% % {\the\actionlist \noexpand#1}}%
%%%% % \act}
%%%% % \end{verbatim}
%%%% % Finally, definition of the user macro also needs an \cs{edef}.
%%%% % Some \cs{expandafter} trickery is necessary here to form
%%%% % the control sequence of the user macro:
%%%% \begin{verbatim}
%%%% % \def\define:#1 {%
%%%% % \expandafter\edef\csname#1\endcsname{\the\actionlist}}
%%%% % \end{verbatim}
%%%%
%%%% % Of course, this is a very simple, rather pointless, example.
%%%% % However, it illustrates an important principle of how
%%%% % token lists can be used to implement another syntax level
%%%% % in \TeX\ (see~\cite{EL}). This principle underlies the
%%%% % \indexterm{Lollipop}
%%%% % `Lollipop' format that was used to typeset this book.
%%%%
%%%% % \end{comment}
%%%% %%%% end of input file [token]
%
%%% \begin{comment}
%%%
%%% % %\spoint Dynamic macro definition
%%% % \subsection{Dynamic macro definition}
%%%
%%% % Unpacking token lists inside an \cs{edef} can be put to a
%%% % rather ambitious use: dynamic definition of macros.
%%% % Consider a simple example.
%%% % \altt
%%% % We set ourselves the goal of letting
%%% % the user define macros, without ever having to use \cs{def}.
%%% % The syntax for this could look like
%%% \begin{verbatim}
%%% % \startdefinition
%%% % \do:this
%%% % \do:that
%%% % \define:MyMacro
%%% % \end{verbatim}
%%% % such that \verb>\show\MyMacro> gives
%%% \begin{verbatim}
%%% % > \MyMacro=macro:
%%% % ->\this \that .
%%% % \end{verbatim}
%%% % An implementation of this uses a token list to collect
%%% % the commands that the user specifies:
%%% \begin{verbatim}
%%% % \newtoks\actionlist
%%% % \end{verbatim}
%%% % The first command is easy:
%%% \begin{verbatim}
%%% % \def\startdefinition{\actionlist{}}
%%% % \end{verbatim}
%%% % Now the \cs{do} command has to hang control sequences
%%% % in the \cs{actionlist}:
%%% \begin{verbatim}
%%% % \def\do:#1 {%
%%% % \edef\act{\noexpand\appendaction
%%% % \expandafter\noexpand\csname#1\endcsname}%
%%% % \act}
%%% % \end{verbatim}
%%% % The \cs{edef} is used solely to form the actual control sequence.
%%% % The next macro uses \cs{edef} to unpack the \cs{actionlist} so far:
%%% %
%%% \begin{verbatim}
%%% % \def\appendaction#1{%
%%% % \edef\act{\noexpand\actionlist=
%%% % {\the\actionlist \noexpand#1}}%
%%% % \act}
%%% % \end{verbatim}
%%% % Finally, definition of the user macro also needs an \cs{edef}.
%%% % Some \cs{expandafter} trickery is necessary here to form
%%% % the control sequence of the user macro:
%%% \begin{verbatim}
%%% % \def\define:#1 {%
%%% % \expandafter\edef\csname#1\endcsname{\the\actionlist}}
%%% % \end{verbatim}
%%%
%%% % Of course, this is a very simple, rather pointless, example.
%%% % However, it illustrates an important principle of how
%%% % token lists can be used to implement another syntax level
%%% % in \TeX\ (see~\cite{EL}). This principle underlies the
%%% % \indexterm{Lollipop}
%%% % `Lollipop' format that was used to typeset this book.
%%%
%%% % \end{comment}
%%% %%%% end of input file [token]
%\endofchapter
\endofchapter
\end{document}