blob: 779ef6ae3c7ac9910bd28f8d3c72748abb63599e (
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
|
% MAP.TEX
% Marek Ry\'cko
% Macro \map
% for applying operations to token sequences
% uses SPLIT.TEX
% version 0.0 24.07.1993
% version 0.1 1.5.1996
% -- english description
\def\map
% for each element E of the token list #2
% ``execute'' the token list #1
% possibly making use of the following macros:
% \mappre the token list before E (without E)
% \mapcur the token E
% \mappost the token list after E (without E)
% \mapupto the token list from the beginning till and including E
% \mapfrom the token list from and including E till the end
% \mapent the entire token list
%
% -------------\mapent----------------
% ---\mapfrom---------
% ----\mapupto-----
% ................E...................
% ----\mappre----- ---\mappost--------
%
% |
% |
% \mapcur
%
#1% operation
#2% token list
{{%
\def\mapent{#2}%
\def\mappre{}%
\let\mapfrom\mapent
% \mappre contains already processed sequence
% \mapfrom contains the sequence to be processed
% while nonempty \mapfrom do:
\ifx\empty\mapfrom \mapcontfalse \else \mapconttrue \fi
\loop \ifmapcont
% \mapfrom nonempty, so it can be split:
% split \mapfrom to head and tail:
\split\mapfrom\mapcur\mappost
% set \mapupto as the concatenation of \mappre and \mapcur:
\expandafter\expandafter\expandafter
\def\expandafter\expandafter\expandafter
\mapupto\expandafter\expandafter\expandafter
{\expandafter\mappre\mapcur}%
% execute operation(s):
#1%
% define new values of \mappre and \mapfrom
\expandafter\def\expandafter\mappre\expandafter{\mapupto}%
\expandafter\def\expandafter\mapfrom\expandafter{\mappost}%
% \mappre contains already processed sequence
% \mapfrom contains the sequence to be processed
\ifx\empty\mapfrom \mapcontfalse \else \mapconttrue \fi
\repeat}}%
\newif\ifmapcont
|