summaryrefslogtreecommitdiff
path: root/tex/context/base/mkii/supp-spe.mkii
blob: 4625695c7a268cec09fb0d1ff4f5d380835082b8 (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
%D \module
%D   [       file=supp-spe,
%D        version=1997.07.05,
%D          title=\CONTEXT\ Support Macros,
%D       subtitle=Specials,
%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.

%D This module implements some \type{\special} manipulation
%D macros. I needed these when I implemented the code that
%D handles the conversion of \TPIC\ specials to \PDF\ code.

\ifx \undefined \writestatus           \input supp-mis.tex \relax \fi
\ifx \undefined \redefinespecial \else \expandafter \endinput     \fi

\writestatus{loading}{ConTeXt Support Macros / Specials}

\unprotect

%D When interpreting specials we need to do some basic scanning.
%D For the moment we distinguish between three cases. We need
%D
%D \starttyping
%D \special{tag: arguments}
%D \special{tag arguments}
%D \special{tag}
%D \stoptyping
%D
%D We cannot be sure that the first case isn't
%D
%D \starttyping
%D \special{tag:arguments}
%D \stoptyping
%D
%D So we have to take care of that one too.

%D \macros
%D   {redefinespecial}
%D
%D Specials that are to be interpreted are defined with
%D commands like:
%D
%D \startbuffer[tmp-1]
%D \redefinespecial a: \using#1\endspecial%
%D   {let's execute special 'a:' using '#1'}
%D
%D \redefinespecial a  \using#1\endspecial%
%D   {let's execute special 'a' using '#1'}
%D
%D \redefinespecial a  \using#1\endspecial%
%D   {let's execute special 'a' using nothing}
%D \stopbuffer
%D
%D \typebuffer[tmp-1]
%D
%D The first two always take an argument, the last one not.
%D The definition of this redefinition macro is not that
%D complex. The names are internally tagged with \type{\@rds@}
%D which saves both time and space.

\def\@rds@{@rds@}

\def\redefinespecial #1 {\setvalue{\@rds@#1}}

%D \macros
%D   {mimmickspecials}
%D
%D Mimmicking specials is activated by saying:
%D
%D \starttyping
%D \mimmickspecials
%D \stoptyping
%D
%D This commands redefines the \PLAIN\ \TEX\ primitive
%D \type{\special}.

\def\mimmickspecials
  {\let\special\domimmickspecial}

%D The special mimmicking macro first looks if it can find an
%D colon terminated tag, next it searches for a tag that end
%D with a space. If both cannot find, the tag itself is treated
%D without argument.

\def\domimmickspecial#1%
  {\domimmickcolonspecial#1:\relax/:\relax/\end}

\def\domimmickcolonspecial#1:#2#3:\relax/#4\end
  {\ifx#2\relax
     \domimmickspacespecial#1 \relax/ \relax/\end
   \else
     \dodomimmickspecial#1:\using#2#3\endspecial
   \fi}

\def\domimmickspacespecial#1 #2#3 \relax/#4\end
  {\ifx#2\relax
     \dodomimmickspecial#1\using\endspecial
   \else
     \dodomimmickspecial#1\using#2#3\endspecial
   \fi}

\def\dodomimmickspecial#1\using#2\endspecial
  {\expandafter\ifx\csname\@rds@#1\endcsname\relax % \doifdefinedelse
     \defaultspecial{#1 #2}%
   \else
     %\message{[mimmick special #1 with #2]}%
     \getvalue{\@rds@#1}\using#2\endspecial
   \fi}

%D Now let's show that things work the way we want, using the
%D previous definitions of tag~a.
%D
%D \startbuffer[tmp-2]
%D \mimmickspecials
%D \special{a: 1 2 3 4 5}
%D \special{a: 1 2 3 4 5}
%D \special{a}
%D \stopbuffer
%D
%D \typebuffer[tmp-2]
%D
%D Which results in:
%D
%D \startlines
%D \getbuffer[tmp-1]
%D \getbuffer[tmp-2]
%D \stoplines

%D \macros
%D   {mimmickspecial}
%D
%D When needed, one can call a mimmicked special directly by
%D saying for instance:
%D
%D \starttyping
%D \mimmickspecial a: \using...\endspecial
%D \stoptyping
%D
%D This can be handy when specials have much in common.

\def\mimmickspecial #1 {\getvalue{\@rds@#1}}

%D \macros
%D   {normalspecial,defaultspecial}
%D
%D Unknown specials are passed to the default special handler.
%D One can for instance ignore all further specials by saying
%D \type{\normalspecial}:
%D
%D \starttyping
%D \def\defaultspecial#1{}
%D \stoptyping
%D
%D But here we default to idle.

\let\normalspecial \special
\let\defaultspecial\special

\protect \endinput