blob: 44d39c75b6a995df0ea4cdd38c1431eadad61455 (
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
|
% Copyright 2007 Mark Wibrow
%
% but subject to the LaTeX Project Public License
% (http://www.latex-project.org/lppl.txt)
%
% and the GNU Public License
% (http://www.gnu.org/licenses/gpl.txt)
%
% This file defines utilities common to the \pgfmath files.
%
% Version 1.414213 29/9/2007
\def\pgfmathincluded{}
% \pgfmath@ensureregister
%
% Ensure a control sequence exists as a TeX count/dimen register.
%
% #1 - count or dimen.
% #2 - a control sequence.
%
\def\pgfmath@ensureregister#1#2{%
\begingroup%
\setbox0=\hbox\bgroup\begingroup% In case #2 is a defined macro. Unlikely, but you never know...
\afterassignment\pgfmath@@ensureregister%
\noexpand#20.0pt\let\pgfmath@temp\relax\relax\pgfmath@#2#1\pgfmath@}
\def\pgfmath@@ensureregister#1#2\pgfmath@#3#4#5\pgfmath@{%
\endgroup\egroup%
\endgroup%
\ifx#4c%
\ifx#1.% Already a count register.
\else%
\csname newcount\endcsname#3% This gets round \outer in plain TeX.
\fi%
\else%
\ifx#4d%
\ifx\let#1% Already a dimen register.
\else%
\csname newdimen\endcsname#3%
\fi%
\fi%
\fi%
}
% Check registers exist. If not, create them.
%
\pgfmath@ensureregister{dimen}{\pgf@x}
\pgfmath@ensureregister{dimen}{\pgf@xa}
\pgfmath@ensureregister{dimen}{\pgf@xb}
\pgfmath@ensureregister{dimen}{\pgf@xc}
\pgfmath@ensureregister{dimen}{\pgf@y}
\pgfmath@ensureregister{dimen}{\pgf@ya}
\pgfmath@ensureregister{dimen}{\pgf@yb}
\pgfmath@ensureregister{dimen}{\pgf@yc}
\pgfmath@ensureregister{dimen}{\pgfutil@tempdima}
\pgfmath@ensureregister{dimen}{\pgfutil@tempdimb}
\pgfmath@ensureregister{count}{\c@pgf@counta}
\pgfmath@ensureregister{count}{\c@pgf@countb}
\pgfmath@ensureregister{count}{\c@pgf@countc}
\pgfmath@ensureregister{count}{\c@pgf@countd}
\pgfmath@ensureregister{count}{\pgfutil@tempcnta}
\pgfmath@ensureregister{count}{\pgfutil@tempcntb}
% Alias for \pgfmath.
%
\let\pgfmath@x\pgf@x
\let\pgfmath@xa\pgf@xa
\let\pgfmath@xb\pgf@xb
\let\pgfmath@xc\pgf@xc
\let\pgfmath@y\pgf@y
\let\pgfmath@ya\pgf@ya
\let\pgfmath@yb\pgf@yb
\let\pgfmath@yc\pgf@yc
\let\pgfmath@tempdima\pgfutil@tempdima
\let\pgfmath@tempdimb\pgfutil@tempdimb
\let\c@pgfmath@counta\c@pgf@counta
\let\c@pgfmath@countb\c@pgf@countb
\let\c@pgfmath@countc\c@pgf@countc
\let\c@pgfmath@countd\c@pgf@countd
\let\pgfmath@tempcnta\pgfutil@tempcnta
\let\pgfmath@tempcntb\pgfutil@tempcntb
% Now check if pgfutil and pgf@sys stuff exists. If it does, fine.
% Just \let pgfmath versions. If not, define pgfmath versions (Arghhh).
%
% \...ifnextchar
%
\ifx\pgfutil@ifnextchar\pgfmath@undefined%
\long\def\pgfmath@ifnextchar#1#2#3{%
\let\pgfmath@reserved@d#1%
\def\pgfmath@reserved@a{#2}%
\def\pgfmath@reserved@b{#3}%
\futurelet\pgfmath@let@token\pgfmath@ifnch}
\def\pgfmath@ifnch{%
\ifx\pgfmath@let@token\pgfmath@sptoken%
\let\pgfmath@reserved@c\pgfmath@xifnch%
\else%
\ifx\pgfmath@let@token\pgfmath@reserved@d%
\let\pgfmath@reserved@c\pgfmath@reserved@a%
\else%
\let\pgfmath@reserved@c\pgfmath@reserved@b%
\fi%
\fi%
\pgfmath@reserved@c}
{%
\def\:{\global\let\pgfmath@sptoken= } \:
\def\:{\pgfmath@xifnch} \expandafter\gdef\: {\futurelet\pgfmath@let@token\pgfmath@ifnch}
}%
\else%
\let\pgfmath@ifnextchar\pgfutil@ifnextchar%
% Still need to define \pgfmath@sptoken (cannot \let).
{%
\def\:{\global\let\pgfmath@sptoken= } \:
}%
\fi%
% \...ifundefined
%
\ifx\pgfutil@ifundefined\pgfmath@undefined%
\long\def\pgfmath@ifundefined#1{%
\expandafter\ifx\csname#1\endcsname\relax%
\expandafter\pgfmath@firstoftwo%
\else%
\expandafter\pgfmath@secondoftwo%
\fi}%
\else%
\let\pgfmath@ifundefined\pgfutil@ifundefined%
\fi%
% \...selectfont
%
\ifx\pgfutil@selectfont\pgfmath@undefined%
\ifx\selectfont\pgfmath@undefined%
\let\pgfmath@selectfont\rm% Plain TeX and ConTeXt.
\else%
\let\pgfmath@selectfont\selectfont% LaTeX.
\fi%
\else%
\let\pgfmath@selectfont\pgfutil@selectfont%
\fi%
% New definition easier than fussing around with let.
%
\newif\ifpgfmath@in@
\def\pgfmath@in@#1#2{%
\def\pgfmath@in@@##1#1##2##3\pgfmath@in@@{%
\ifx\pgfmath@in@##2\pgfmath@in@false\else\pgfmath@in@true\fi}%
\pgfmath@in@@#2#1\pgfmath@in@\pgfmath@in@@}
% \...tonumber
%
\ifx\pgf@sys@tonumber\pgfmath@undefined%
{\catcode`\p=12\catcode`\t=12\gdef\Pgf@geT#1pt{#1}}
\def\pgfmath@tonumber#1{\expandafter\Pgf@geT\the#1}
\else%
\let\pgfmath@tonumber\pgf@sys@tonumber%
\fi%
% \PackageWarning and \PackageError
%
\ifx\PackageWarning\pgfmath@undefined
\def\pgfmath@PackageWarning#1#2{\immediate\write-1{Package #1: Warning! #2.}}%
\else%
\let\pgfmath@PackageWarning\PackageWarning%
\fi%
\ifx\PackageError\pgfmath@undefined
\def\pgfmath@PackageError#1#2#3{\errmessage{Package #1 Error: #2.}}%
\else%
\let\pgfmath@PackageError\PackageError%
\fi%
\def\pgfmath@error#1#2{%
\pgfmath@PackageError{PGF Math}{%
#1%
\pgfutil@ifundefined{pgfmath@expression}{}{ (in '\pgfmath@expression')}%
}{#2}%
}
\def\pgfmath@warning#1{%
\pgfmath@PackageWarning{PGF Math}{%
#1%
\pgfutil@ifundefined{pgfmath@expression}{}{ (in '\pgfmath@expression')}%
}%
}
% \pgfmath@pt
%
% Needed to test for 'pt' resulting from expansion using \the.
%
{\catcode`\p=12\catcode`\t=12\gdef\PgfmaTh@PT{pt}}
\edef\pgfmath@pt{\PgfmaTh@PT}%
% \pgfmath@empty
%
% A handy macro.
%
\def\pgfmath@empty{}
\def\pgfmath@firstoftwo#1#2{#1}
\def\pgfmath@secondoftwo#1#2{#2}
% \pgfmath@gobbletilpgfmath@
%
% Gobble stream until \pgfmath@ {which is undefined}.
%
\def\pgfmath@gobbletilpgfmath@#1\pgfmath@{}
\def\pgfmath@gobbleone#1{}%
\def\pgfmath@namedef#1{\expandafter\def\csname#1\endcsname}
\def\pgfmath@nameedef#1{\expandafter\edef\csname#1\endcsname}
% \pgfmathloop
%
% A version of the standard TeX and LaTeX
% \loop, with an additional macro \pgfmathcounter
% (which is *not* a TeX counter) which keeps
% track of the iterations.
%
\newif\ifpgfmathcontinueloop
\def\pgfmathloop#1\repeatpgfmathloop{%
\def\pgfmathcounter{1}%
\def\pgfmath@iterate{%
#1\relax%
{% Do this inside a group, just in case...
\c@pgfmath@counta\pgfmathcounter%
\advance\c@pgfmath@counta1\relax%
\xdef\pgfmathloop@temp{\the\c@pgfmath@counta}%
}%
\edef\pgfmathcounter{\pgfmathloop@temp}%
\expandafter\pgfmath@iterate\fi}%
\pgfmath@iterate\let\pgfmath@iterate\relax}
\let\repeatpgfmathloop\fi
\def\pgfmathbreakloop{\let\pgfmath@iterate\relax}%
% \pgfmath@returnone
%
% #1 - a dimension representing a number or dimension.
%
% Changed by TT: made faster and simpler since it is used
% *heavily*. #1 must be something that can be assigned to a
% dimension.
%
\def\pgfmath@returnone#1\endgroup{%
\pgfmath@x#1%
\edef\pgfmath@temp{\pgfmath@tonumber{\pgfmath@x}}%
\expandafter\endgroup\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmath@temp}%
}
\let\pgfmathreturn=\pgfmath@returnone
% \pgfmath@smuggleone
%
% Smuggle a macro outside a group.
%
% Changed by TT: Speedup by insisting, that smuggleone is directly
% followed by \endgroup
%
\def\pgfmath@smuggleone#1\endgroup{%
\expandafter\endgroup\expandafter\def\expandafter#1\expandafter{#1}}
\let\pgfmathsmuggle=\pgfmath@smuggleone
|