Debian Codegraph @

texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex

raw
1
2 \newdimen\pgfmath@dimen
3 \newcount\pgfmath@count
4 \newbox\pgfmath@box
5 \newtoks\pgfmath@toks
6
7 \newif\ifpgfmath@quickparse
8 \newif\ifpgfmathfloat
9 \newif\ifpgfmathunitsdeclared
10 \newif\ifpgfmathmathunitsdeclared
11 \newif\ifpgfmathignoreunitscale
12
13 \let\pgfmath@protected@edef=\edef
14 \ifcsname protected@edef\endcsname
15 \let\pgfmath@protected@edef=\protected@edef
16 \fi
17
18 \def\pgfmathprint#1{\pgfmathparse{#1}\pgfmathresult}
19
20 \def\pgfmathparse{%
21 \begingroup
22 \pgfmath@catcodes
23 \pgfmath@quickparsefalse
24 % Test for the fpu library
25 \ifpgfmathfloat
26 \let\pgfmath@parse@next=\pgfmathfloatparsenumber
27 \else
28 \let\pgfmath@parse@next=\pgfmathparse@
29 \fi
30 \pgfmath@parse@next}
31
32 \begingroup
33 \lccode`\~=`\"
34 \lowercase{\endgroup
35 \def\pgfmath@catcodes{%
36 \catcode`\==12 %
37 \catcode`\,=12 %
38 \catcode`\|=12 %
39 \catcode`\&=12 %
40 \let~\pgfmath@char@quote
41 }}%
42
43 \def\pgfmathqparse{%
44 \begingroup
45 \pgfmath@catcodes
46 \pgfmath@quickparsetrue
47 \pgfmathparse@}
48
49 \def\pgfmathparse@#1{%
50 % No (math) units yet.
51 \global\pgfmathunitsdeclaredfalse
52 \global\pgfmathmathunitsdeclaredfalse
53 % Expand expression so any remaining CSs are registers
54 % or box dimensions (i.e. |\wd|, |\ht|, |\dp|).
55 \pgfmath@protected@edef\pgfmath@expression{#1}%
56 %
57 \expandafter\pgfmathparse@trynumber@loop\pgfmath@expression\pgfmath@parse@stop
58 %
59 % this here is the _real_ parser. it is invoked by
60 % \pgfmathparse@trynumber@loop if that says "this is no number"
61 %\pgfmathparse@@\pgfmath@parse@stop%
62 }
63
64 \def\pgfmath@parse@stop{\pgfmath@parse@stop}% equals only itself
65
66 \def\pgfmathparse@trynumber@token{numeric}
67 \begingroup
68 \def\\{\global\let\pgf@let@space@token= } \\ % now, \pgf@let@space@token is a space token
69 \endgroup
70
71 % This a "fast-lane": if the expressions consist merely of number
72 % tokens, we can simply return the number as-is.
73 %
74 % This is significantly faster and should resemble the 80% use-case.
75 %
76 % #1 a single token
77 \def\pgfmathparse@trynumber@loop{%
78 \futurelet\pgfmath@token@let\pgfmathparse@trynumber@loop@
79 }%
80 \def\pgfmathparse@trynumber@loop@#1{%
81 \ifx\pgfmath@token@let\pgf@let@space@token
82 % Hm. we found a white space... and we have no support for
83 % trimming. That means we have to assume that the white space
84 % occurred somewhere in the middle - and fall back to the
85 % expensive method.
86 \def\pgfmath@parse@next{\pgfmathparse@@#1}%
87 \else
88 \ifx\pgfmath@token@let\bgroup%
89 % oh! We found '{' #1.
90 % Well, these braces appear to be special; fall back to
91 % the complicated routine...
92 \let\pgfmath@parse@next=\pgfmathparse@@
93 \else
94 \ifx\pgfmath@token@let\pgfmath@parse@stop
95 % Ah: we have passed the check! The expression consists only
96 % of 0123456789. , so do not parse anything and return it
97 % as-is!
98 \let\pgfmath@parse@next=\pgfmathparse@expression@is@number
99 \else
100 \expandafter\ifx\csname pgfmath@token@\pgfmathparse@trynumber@token @\string#1\endcsname\relax%
101 % hm. It is none of 0123456789.
102 \let\pgfmath@parse@next=\pgfmathparse@@
103 \else
104 % continue... we only found one of 0123456789. so
105 % far...
106 \let\pgfmath@parse@next=\pgfmathparse@trynumber@loop
107 \fi
108 \fi
109 \fi
110 \fi
111 \pgfmath@parse@next
112 }%
113
114 \def\pgfmathparse@expression@is@number{%
115 \let\pgfmathresult=\pgfmath@expression
116 \pgfmath@smuggleone\pgfmathresult%
117 \endgroup
118 \ignorespaces
119 }%
120 \def\pgfmathparse@@#1\pgfmath@parse@stop{%
121 % We are inside a group (opened in |\pgfmathparse| or
122 % |\pgfmathqparse|).
123 % Stuff for calc compatibility.
124 \let\real=\pgfmath@calc@real
125 \let\minof=\pgfmath@calc@minof
126 \let\maxof=\pgfmath@calc@maxof
127 \let\ratio=\pgfmath@calc@ratio
128 \let\widthof=\pgfmath@calc@widthof
129 \let\heightof=\pgfmath@calc@heightof
130 \let\depthof=\pgfmath@calc@depthof
131 % Restore font (defined in pgfmathutil.code.tex)
132 \pgfmath@selectfont
133 % Set up stack.
134 \pgfmath@stack@operation={{}{}{}}%
135 \pgfmath@stack@operand={{}{}{}}%
136 \let\pgfmath@stack@operation@top=\pgfmath@stack@empty
137 \let\pgfmath@stack@operand@top=\pgfmath@stack@empty
138 % An expression always begins with an operand.
139 \expandafter\pgfmath@bgroup@strip\expandafter{\pgfmath@expression}%
140 % |\pgfmath@bgroup@stripped| is the result of
141 % |\pgfmath@bgroup@strip|
142 \expandafter\pgfmath@parse@@operand\pgfmath@bgroup@stripped @@@@\pgfmath@parse@stop%
143 }
144
145 \def\pgfmath@parse@end#1\pgfmath@parse@stop{%
146 \pgfmathpostparse
147 \pgfmath@smuggleone\pgfmathresult%
148 \endgroup
149 \ignorespaces}
150
151 \let\pgfmathpostparse=\relax
152
153 % For compatibility with older version.
154 %
155 \def\pgfmathscaleresult{%
156 \ifpgfmathunitsdeclared
157 \else
158 \ifpgfmathignoreunitscale
159 \else
160 \afterassignment\pgfmath@gobbletilpgfmath@%
161 \pgfmath@x\pgfmathresultunitscale pt\relax\pgfmath@%
162 \expandafter\pgfmath@x\pgfmathresult\pgfmath@x%
163 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}%
164 \fi
165 \fi
166 }
167
168 \def\pgfmathsetresultunitscale#1{\def\pgfmathresultunitscale{#1}}
169
170 \def\pgfmathresultunitscale{1}
171
172
173 % A utility function which evaluates expression '#1' and invokes '#2'
174 % if the expression is true and '#3' if it is false.
175 \def\pgfmathifexpression#1#2#3{%
176 \pgfmathparse{#1}%
177 \pgfmath@iftrue{#2}{#3}%
178 }%
179 % Executes '#1' if \pgfmathresult is 'true', '#2' otherwise.
180 % WARNING : overwritten in fpu lib!
181 \def\pgfmath@iftrue{%
182 \ifdim\pgfmathresult pt=1.0pt %
183 \let\pgfmath@next=\pgfutil@firstoftwo
184 \else
185 \let\pgfmath@next=\pgfutil@secondoftwo
186 \fi
187 \pgfmath@next%
188 }%
189
190 % Stuff for computability with the calc package.
191 %
192 \def\pgfmath@calc@real#1{#1}
193 \def\pgfmath@calc@minof#1#2{min(#1,#2)}
194 \def\pgfmath@calc@maxof#1#2{max(#1,#2)}
195 \def\pgfmath@calc@ratio#1#2{#1/#2}
196 \def\pgfmath@calc@widthof#1{width("#1")}
197 \def\pgfmath@calc@heightof#1{height("#1")}
198 \def\pgfmath@calc@depthof#1{depth("#1")}
199
200 \def\pgfmath@bgroup{\string\pgfmath@bgroup}
201 \def\pgfmath@egroup{\string\pgfmath@egroup}
202 \def\pgfmath@egroup@token{\pgfmath@egroup}
203
204 \def\pgfmath@text@@{@}
205 \def\pgfmath@text@operator{operator}
206 \def\pgfmath@text@function{function}
207 \def\pgfmath@dots{...}
208 \def\pgfmath@char@zero{0}
209 \def\pgfmath@char@quote{"}
210 \def\pgfmath@char@exclamation{!}
211 \def\pgfmath@char@plus{+}
212 \def\pgfmath@char@minus{-}
213 \def\pgfmath@char@period{.}
214 \def\pgfmath@char@leftangle{<}
215 \def\pgfmath@char@leftbracket{[}
216 \pgfmath@toks={#}
217 \edef\pgfmath@char@hash{\the\pgfmath@toks}
218
219 \def\pgfmath@tokens@make#1#2{%
220 % Defines for each token or balanced text in |#2| a control sequence
221 % |\pgfmath@token@<#1>@\string<one token from #2>| and stores |#2|
222 % in it.
223 \def\pgfmath@prefix{#1}%
224 % Note the empty group |{}| at the end that ends the loop in
225 % |\pgfmath@token@@make|.
226 \expandafter\pgfmath@tokens@@make#2{}}
227
228 \def\pgfmath@tokens@@make#1{%
229 \def\pgfmath@token{#1}%
230 \ifx\pgfmath@token\pgfmath@empty
231 % End of loop: all tokens or balanced texts were parsed.
232 \else
233 \pgfmath@namedef{pgfmath@token@\pgfmath@prefix @\string#1}{#1}%
234 \expandafter\pgfmath@tokens@@make%
235 \fi}
236
237 \pgfmath@tokens@make{box}{\wd\ht\dp}
238 \ifx\dimexpr\@undefined\else % needed for classic tex
239 \pgfmath@tokens@make{dimexpr}{\dimexpr\glueexpr}
240 \fi
241 \pgfmath@tokens@make{unit}{{bp}{cc}{cm}{dd}{em}{ex}{in}{mm}{pc}{pt}{sp}}
242 \ifx\pdftexversion\@undefined\else % for pdfTeX
243 \pgfmath@tokens@make{unit}{{nc}{nd}{px}}
244 \fi
245 \ifx\directlua\@undefined\else % for LuaTeX
246 \pgfmath@tokens@make{unit}{{nc}{nd}{px}}
247 \fi
248 \ifx\kanjiskip\@undefined\else % for pTeX, upTeX
249 \pgfmath@tokens@make{unit}{{H}{Q}{zh}{zw}}
250 \fi
251 %
252 \pgfmath@tokens@make{mathunit}{{mu}}
253 \pgfmath@tokens@make{numeric}{.0123456789}
254 \pgfmath@tokens@make{number}{0123456789}
255 \pgfmath@tokens@make{functional}{_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}
256 \pgfmath@tokens@make{exponent}{eE}
257 \pgfmath@tokens@make{group}{{()}{[]}{\pgfmath@bgroup\pgfmath@egroup}}
258 \pgfmath@tokens@make{specials}{@)]\pgfmath@egroup}
259 \pgfmath@tokens@make{hexadecimal}{0123456789ABCDEFabcdef}
260 \pgfmath@tokens@make{octal}{01234567}
261 \pgfmath@tokens@make{binary}{01}
262
263 \pgfmath@namedef{pgfmath@base@0x}{16}
264 \pgfmath@namedef{pgfmath@base@0X}{16}
265 \pgfmath@namedef{pgfmath@base@0b}{2}
266 \pgfmath@namedef{pgfmath@base@0B}{2}
267
268 % Determine if a register is a count or a dimension/skip register.
269 \newif\ifpgfmath@dimen@
270 \def\pgfmath@dimen@#1{%
271 \begingroup
272 \afterassignment\pgfmath@dimen@@%
273 #1=0.0pt\relax\pgfmath@}
274 \def\pgfmath@dimen@@#1#2\pgfmath@{%
275 \endgroup
276 \ifx#1.%
277 \pgfmath@dimen@false
278 \else
279 \pgfmath@dimen@true
280 \fi}
281
282 \def\pgfmath@parse@ifbgroup#1#2{%
283 \let\pgfmath@parse@bgroup@after=#1%
284 \let\pgfmath@parse@nobgroup@after=#2%
285 \futurelet\pgfmath@token@let%
286 \pgfmath@parse@@ifbgroup}
287
288 \def\pgfmath@parse@@ifbgroup{%
289 \ifx\pgfmath@token@let\bgroup
290 \let\pgfmath@parse@next=\pgfmath@parse@@@ifbgroup
291 \else
292 % |\pgfmath@sptoken| defined in \file{pgfmathutil.code.tex}.
293 \ifx\pgfmath@token@let\pgfmath@sptoken
294 \let\pgfmath@parse@next=\pgfmath@parse@@@@ifbgroup
295 \else
296 \let\pgfmath@parse@next=\pgfmath@parse@nobgroup@after
297 \fi
298 \fi
299 \pgfmath@parse@next}
300
301 % TT: If false, octal parsing is switched off (needed for time parsing)
302 \newif\ifpgfmath@octalparsing
303 \pgfmath@octalparsingtrue
304
305 % I (CJ) *think* it replaces |{| and |}| by |\pgfmath@bgroup| and
306 % |\pgfmath@egroup|?
307 \def\pgfmath@parse@@@ifbgroup#1{%
308 \pgfmath@parse@bgroup@after\pgfmath@bgroup#1\pgfmath@egroup}
309
310 {
311 \def\:{\pgfmath@parse@@@@ifbgroup}
312 \expandafter\gdef\: {\futurelet\pgfmath@token@let\pgfmath@parse@@ifbgroup}
313 }
314
315 % Parse an operand.
316 \def\pgfmath@parse@operand{%
317 \expandafter\pgfmath@parse@@operand\pgfmath@token@next}
318
319 % This is the entry point for the parser. It is called at the end of
320 % |\pgfmathparse@| with the following syntax
321 % |\expandafter\pgfmath@parse@@operand\pgfmath@bgroup@stripped
322 % @@@@\pgfmath@parse@stop|.
323 % Note: we are inside a group.
324 \def\pgfmath@parse@@operand{%
325 \pgfmath@parse@ifbgroup{\pgfmath@parse@@operand}{\pgfmath@parse@@operand@}}
326
327 % An operand is
328 % * |+| (unary plus),
329 % * |-| (unary minus),
330 % * a prefix operator
331 \def\pgfmath@parse@@operand@#1{%
332 \def\pgfmath@token{#1}%
333 \ifx\pgfmath@token\pgfmath@char@plus
334 % Unary (prefix) plus
335 \let\pgfmath@parse@next=\pgfmath@parse@@operand%
336 \else
337 \ifx\pgfmath@token\pgfmath@char@minus
338 % Unary (prefix) minus
339 \pgfmath@stack@push@operation{neg}%
340 \let\pgfmath@parse@next=\pgfmath@parse@@operand
341 \else
342 % See |\pgfmathdeclareoperator| (below). Note that |+| and |-|
343 % that are also declared as operators have been tested before so
344 % they should never be parsed as binary (infix) operator at this stage.
345 \expandafter\ifx\csname pgfmath@operation@\expandafter\string\pgfmath@token @prefix\endcsname\pgfmath@token
346 \let\pgfmath@parse@next=\pgfmath@parse@prefix@operator
347 \else
348 \ifpgfmath@quickparse
349 \let\pgfmath@parse@next=\pgfmath@qparse@operand
350 \else
351 \let\pgfmath@number=\pgfmath@empty
352 \expandafter\ifx\csname pgfmath@token@functional@\string#1\endcsname\relax%
353 \let\pgfmath@base=\pgfmath@empty%
354 \let\pgfmath@token@next=\pgfmath@token%
355 \if\noexpand#10% Check for octal prefix.
356 \ifpgfmath@octalparsing%
357 \def\pgfmath@base{8}%
358 \fi%
359 \fi%
360 \let\pgfmath@parse@next=\pgfmath@parse@number%
361 \else%
362 \let\pgfmath@function=\pgfmath@token%
363 \let\pgfmath@parse@next=\pgfmath@parse@function%
364 \fi%
365 \fi%
366 \fi%
367 \fi%
368 \fi%
369 \pgfmath@parse@next%
370 }
371
372 % Parse prefix operators.
373 %
374 \def\pgfmath@parse@prefix@operator{%
375 \ifx\pgfmath@token\pgfmath@char@quote% Quote character.
376 \let\pgfmath@parse@next=\pgfmath@parse@operand@quote%
377 \else%
378 \ifx\pgfmath@token\pgfmath@char@exclamation% Prefix !.
379 \pgfmath@stack@push@operation{not}%
380 \let\pgfmath@parse@next=\pgfmath@parse@@operand%
381 \else% Anything else, just push and hope.
382 \expandafter\pgfmath@stack@push@operation\expandafter{\pgfmath@token}%
383 \let\pgfmath@parse@next=\pgfmath@parse@@operand%
384 \fi%
385 \fi%
386 \pgfmath@parse@next%
387 }%
388
389
390 % Quote part of an expression.
391 %
392 \def\pgfmath@parse@operand@quote#1"{%
393 \def\pgfmathresult{#1}%
394 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
395 \pgfmath@parse@@operator%
396 }
397
398 % Quick operand parsing. Should always have units.
399 % No functions, base conversion, quoting or scientific notation
400 % are permitted.
401 \def\pgfmath@qparse@operand{%
402 \afterassignment\pgfmath@qparse@@operand%
403 \pgfmath@dimen\pgfmath@token}
404 \def\pgfmath@qparse@@operand{%
405 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
406 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
407 \pgfmath@parse@@operator%
408 }
409
410 % Parse a number, which can take the form:
411 %
412 % 1. An integer, or a decimal, with or without units.
413 % 2. A dimension/skip or a count register.
414 % 3. A dimension register preceded by a number or count register.
415 % 4. A box dimension (e.g., \wd\mybox).
416 % 5. A box dimension preceded by a number or a count register.
417 % 6. Scientific notation (e.g., 1.234567e-10).
418 % 7. A binary, hexadecimal, or octal number.
419 %
420 \def\pgfmath@parse@number{\pgfmath@parse@ifbgroup{\pgfmath@parse@number}{\pgfmath@parse@number@}}
421 \def\pgfmath@parse@number@#1{%
422 \let\pgfmath@token=\pgfmath@token@next%
423 \def\pgfmath@token@next{#1}%
424 \pgfmath@parse@@number}
425
426 \def\pgfmath@parse@@number{%
427 \ifx\pgfmath@token\pgfmath@egroup@token%
428 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmath@number}%
429 \let\pgfmath@parse@next=\pgfmath@parse@@@operator%
430 \else%
431 \expandafter\ifcat\expandafter\noexpand\pgfmath@token\relax% A CS?
432 \expandafter\ifx\csname pgfmath@token@dimexpr@\expandafter\string\pgfmath@token\endcsname\relax%
433 \expandafter\ifx\pgfmath@token\numexpr%
434 \let\pgfmath@parse@next=\pgfmath@parse@numexpr%
435 \else%
436 \expandafter\ifx\pgfmath@token\muexpr%
437 \let\pgfmath@parse@next=\pgfmath@parse@muexpr%
438 \else%
439 \expandafter\ifx\csname pgfmath@token@box@\expandafter\string\pgfmath@token\endcsname\relax%
440 % So, is the CS is a dimension or a count register?
441 \expandafter\pgfmath@dimen@\pgfmath@token%
442 \ifpgfmath@dimen@% A dimension register.
443 \global\pgfmathunitsdeclaredtrue%
444 \pgfmath@dimen=\pgfmath@number\pgfmath@token%
445 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
446 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
447 \let\pgfmath@parse@next=\pgfmath@parse@operator%
448 \else% A count register.
449 \pgfmath@count=\pgfmath@token%
450 \expandafter\def\expandafter\pgfmath@number\expandafter{\the\pgfmath@count}%
451 \expandafter\ifcat\expandafter\noexpand\pgfmath@token@next\relax%
452 % A CS following a count register should be \wd, \ht or \dp.
453 \let\pgfmath@parse@next=\pgfmath@parse@number%
454 \else%
455 \let\pgfmathresult=\pgfmath@number%
456 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
457 \let\pgfmath@parse@next=\pgfmath@parse@operator%
458 \fi%
459 \fi%
460 \else%
461 % This should be a box specification, for example, 0.5\wd\mybox.
462 \global\pgfmathunitsdeclaredtrue%
463 \pgfmath@dimen=\pgfmath@number\pgfmath@token\pgfmath@token@next%
464 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
465 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
466 \let\pgfmath@parse@next=\pgfmath@parse@@operator%
467 \fi%
468 \fi%
469 \fi%
470 \else%
471 \global\pgfmathunitsdeclaredtrue%
472 \let\pgfmath@parse@next=\pgfmath@parse@dimexpr%
473 \fi%
474 \else%
475 \expandafter\ifx\csname pgfmath@token@numeric@\expandafter\string\pgfmath@token\endcsname\relax%
476 % It isn't numeric (i.e., 012345679.), so it might be units...
477 % first double-character units...
478 \expandafter\ifx\csname pgfmath@token@unit@\expandafter\string\pgfmath@token\expandafter\string\pgfmath@token@next\endcsname\relax%
479 % then single-character units...
480 \expandafter\ifx\csname pgfmath@token@unit@\expandafter\string\pgfmath@token\endcsname\relax%
481 % ...or the exponent characters...
482 \expandafter\ifx\csname pgfmath@token@exponent@\expandafter\string\pgfmath@token\endcsname\relax%
483 % ...or a base prefix...
484 \expandafter\ifx\csname pgfmath@base@\expandafter\pgfmath@number\expandafter\string\pgfmath@token\endcsname\relax%
485 % ...or a math unit...
486 \expandafter\ifx\csname pgfmath@token@mathunit@\expandafter\string\pgfmath@token\expandafter\string\pgfmath@token@next\endcsname\relax%
487 % ...none of the above...
488 \ifx\pgfmath@base\pgfmath@empty%
489 \let\pgfmathresult=\pgfmath@number%
490 \else%
491 \ifx\pgfmath@number\pgfmath@char@zero%
492 \let\pgfmathresult=\pgfmath@number%
493 \else%
494 % Convert from octal.
495 \expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\pgfmath@number}{8}{10}%
496 \fi%
497 \fi%
498 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
499 \let\pgfmath@parse@next=\pgfmath@parse@@@operator%
500 \else%
501 % ...here, it is a math unit (mu). Treat it as a pt.
502 \global\pgfmathunitsdeclaredtrue%
503 \global\pgfmathmathunitsdeclaredtrue%
504 \pgfmath@dimen=\pgfmath@number pt\relax%
505 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
506 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
507 \let\pgfmath@parse@next=\pgfmath@parse@@operator%
508 \fi%
509 \else%
510 % ...here, it is a base prefix 0x, 0X, 0b or 0B
511 \expandafter\let\expandafter\pgfmath@base\expandafter=%
512 \csname pgfmath@base@\expandafter\pgfmath@number\expandafter\string\pgfmath@token\endcsname%
513 \let\pgfmath@parse@next=\pgfmath@parse@base%
514 \fi%
515 \else% ... and here, it is the exponent characters.
516 \let\pgfmath@parse@next=\pgfmath@parse@exponent%
517 \fi%
518 \else% ...but here it is single-character units.
519 \global\pgfmathunitsdeclaredtrue%
520 \pgfmath@dimen=\pgfmath@number\pgfmath@token\relax%
521 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
522 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
523 \let\pgfmath@parse@next=\pgfmath@parse@@operator%
524 \fi%
525 \else% ...but here it is double-character units.
526 \global\pgfmathunitsdeclaredtrue%
527 \pgfmath@dimen=\pgfmath@number\pgfmath@token\pgfmath@token@next\relax%
528 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
529 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
530 \let\pgfmath@parse@next=\pgfmath@parse@@operator%
531 \fi%
532 \else% It is numeric.
533 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\pgfmath@number%
534 \expandafter\expandafter\expandafter{\expandafter\pgfmath@number\pgfmath@token}%
535 \ifx\pgfmath@token\pgfmath@char@period%
536 \let\pgfmath@base=\pgfmath@empty%
537 \fi%
538 \let\pgfmath@parse@next=\pgfmath@parse@number%
539 \fi%
540 \fi%
541 \fi%
542 \pgfmath@parse@next%
543 }
544
545
546 % Parse a \dimexpr
547 \def\pgfmath@parse@dimexpr{%
548 \afterassignment\pgfmath@parse@dimexpr@%
549 \expandafter\expandafter\expandafter\pgfmath@dimen\expandafter\pgfmath@token\pgfmath@token@next%
550 }
551 \def\pgfmath@parse@dimexpr@{%
552 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}%
553 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
554 \pgfmath@parse@@operator%
555 }
556
557
558 % Parse a \muexpr
559 \def\pgfmath@parse@muexpr{%
560 \begingroup%
561 \afterassignment\pgfmath@parse@muexpr@%
562 \expandafter\expandafter\expandafter\muskip\expandafter\expandafter\expandafter0\expandafter\pgfmath@token\expandafter\pgfmath@token@next%
563 }
564 \def\pgfmath@parse@muexpr@{%
565 \expandafter\endgroup%
566 \expandafter\edef\expandafter\pgfmathresult\expandafter{\expandafter\pgfMATH@STRIPMU\the\muskip0}%
567 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
568 \pgfmath@parse@@operator%
569 }
570
571 {
572 \catcode`\m=12
573 \catcode`\u=12
574 \gdef\pgfMATH@STRIPMU#1mu{#1}
575 }
576
577
578 % Parse a \numexpr
579 \def\pgfmath@parse@numexpr{%
580 \afterassignment\pgfmath@parse@numexpr@%
581 \expandafter\expandafter\expandafter\pgfmath@count\expandafter\pgfmath@token\pgfmath@token@next%
582 }
583 \def\pgfmath@parse@numexpr@#1{%
584 \expandafter\def\expandafter\pgfmath@number\expandafter{\the\pgfmath@count}%
585 \def\pgfmath@token@next{#1}%
586 \expandafter\ifcat\expandafter\noexpand\pgfmath@token@next\relax%
587 % A CS following a count register should be \wd, \ht or \dp.
588 \let\pgfmath@parse@next=\pgfmath@parse@number%
589 \else%
590 \let\pgfmathresult=\pgfmath@number%
591 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
592 \let\pgfmath@parse@next=\pgfmath@parse@operator%
593 \fi%
594 \pgfmath@parse@next%
595 }
596
597
598 % Parse the exponent of a number.
599 %
600 % REMARK: this method will be overwritten by the FPU library. Please
601 % keep changes consistent...
602 \def\pgfmath@parse@exponent{%
603 \afterassignment\pgfmath@parse@@exponent%
604 \pgfmath@count\pgfmath@token@next}
605 \def\pgfmath@parse@@exponent{%
606 \pgfmathscientific{\pgfmath@number}{\the\pgfmath@count}%
607 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
608 \pgfmath@parse@@operator%
609 }
610
611 % Parse binary or hexadecimal numbers (octal numbers done elsewhere).
612 %
613 \def\pgfmath@parse@base{%
614 \ifnum\pgfmath@base=2\relax%
615 \let\pgfmath@parse@next=\pgfmath@parse@binary%
616 \else%
617 \ifnum\pgfmath@base=16\relax%
618 \let\pgfmath@parse@next=\pgfmath@parse@hexadecimal%
619 \else%
620 \pgfmath@error{Unexpected numerical base `\pgfmath@base'}{}%
621 \def\pgfmathresult{0}%
622 \let\pgfmath@parse@next=\pgfmath@parse@end%
623 \fi%
624 \fi%
625 \let\pgfmath@number=\pgfmath@empty%
626 \expandafter\pgfmath@parse@next\pgfmath@token@next%
627 }
628
629 \def\pgfmath@parse@binary#1{%
630 \expandafter\ifx\csname pgfmath@token@binary@#1\endcsname\relax%
631 \expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\pgfmath@number}{2}{10}%
632 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
633 \def\pgfmath@token@next{#1}%
634 \let\pgfmath@parse@next=\pgfmath@parse@operator%
635 \else%
636 \expandafter\def\expandafter\pgfmath@number\expandafter{\pgfmath@number#1}%
637 \let\pgfmath@parse@next=\pgfmath@parse@binary%
638 \fi%
639 \pgfmath@parse@next%
640 }
641
642 \def\pgfmath@parse@hexadecimal#1{%
643 \expandafter\ifx\csname pgfmath@token@hexadecimal@#1\endcsname\relax%
644 \expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\pgfmath@number}{16}{10}%
645 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
646 \def\pgfmath@token@next{#1}%
647 \let\pgfmath@parse@next=\pgfmath@parse@operator%
648 \else%
649 \expandafter\def\expandafter\pgfmath@number\expandafter{\pgfmath@number#1}%
650 \let\pgfmath@parse@next=\pgfmath@parse@hexadecimal%
651 \fi%
652 \pgfmath@parse@next%
653 }
654
655 % Parse a function.
656 %
657 \def\pgfmath@parse@function{\pgfmath@parse@ifbgroup{\pgfmath@parse@function}{\pgfmath@parse@@function}}
658 \def\pgfmath@parse@function@{\futurelet\pgfmath@token@let\pgfmath@parse@@function}
659 \def\pgfmath@parse@@function{%
660 \ifx\pgfmath@token@let\pgfmath@sptoken%
661 \let\pgfmath@token=\pgfmath@empty%
662 \let\pgfmath@parse@next=\pgfmath@parse@@@@function%
663 \else%
664 \let\pgfmath@parse@next=\pgfmath@parse@@@function%
665 \fi%
666 \pgfmath@parse@next}
667
668 \def\pgfmath@parse@@@function#1{%
669 \expandafter\ifx\csname pgfmath@token@functional@\expandafter\string#1\endcsname\relax%
670 \expandafter\ifx\csname pgfmath@token@number@\expandafter\string#1\endcsname\relax%
671 \def\pgfmath@token{#1}% Not from A-Z, a-z, 0-9, or _.
672 \let\pgfmath@parse@next=\pgfmath@parse@@@@function%
673 \else% It is from 0-9.
674 \expandafter\def\expandafter\pgfmath@function\expandafter{\pgfmath@function#1}%
675 \let\pgfmath@parse@next=\pgfmath@parse@function@%
676 \fi%
677 \else% It is from A-Z, a-z, or _.
678 \edef\pgfmath@function{\pgfmath@function#1}%
679 \let\pgfmath@parse@next=\pgfmath@parse@function@%
680 \fi%
681 \pgfmath@parse@next}
682
683 \def\pgfmath@parse@@@@function{%
684 \expandafter\ifx\csname pgfmath@function@\pgfmath@function\endcsname\relax%
685 \pgfmath@error{Unknown function `\pgfmath@function'}{}%
686 \def\pgfmathresult{0}%
687 \let\pgfmath@parse@next=\pgfmath@parse@end%
688 \else%
689 \expandafter\ifnum\csname pgfmath@operation@\pgfmath@function @arity\endcsname=0\relax%
690 % Functions with zero arity are called directly.
691 \csname pgfmath\pgfmath@function @\endcsname%
692 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
693 \let\pgfmath@parse@next=\pgfmath@parse@@operator%
694 \else% Otherwise, they are pushed onto the operator stack
695 \expandafter\pgfmath@stack@push@operation\expandafter{\pgfmath@function}%
696 \let\pgfmath@parse@next=\pgfmath@parse@@operand%
697 \fi%
698 \fi%
699 \expandafter\pgfmath@parse@next\pgfmath@token}
700
701 % Parse an operator.
702 %
703 \def\pgfmath@parse@operator{\pgfmath@parse@ifbgroup{\pgfmath@parse@operator}{\pgfmath@parse@operator@}}%
704 \def\pgfmath@parse@operator@#1{% Get one token.
705 \let\pgfmath@token=\pgfmath@token@next%
706 \def\pgfmath@token@next{#1}%
707 \pgfmath@parse@@@operator}
708
709 \def\pgfmath@parse@@operator{\pgfmath@parse@ifbgroup{\pgfmath@parse@@operator}{\pgfmath@parse@@operator@}}%
710 \def\pgfmath@parse@@operator@#1{% Get first token...
711 \def\pgfmath@token{#1}%
712 \pgfmath@parse@ifbgroup{\pgfmath@parse@@operator@@}{\pgfmath@parse@@operator@@}}%
713 \def\pgfmath@parse@@operator@@#1{% ...and second token.
714 \def\pgfmath@token@next{#1}%
715 \pgfmath@parse@@@operator}
716
717 \def\pgfmath@parse@@@operator{%
718 \expandafter\ifx\csname pgfmath@operator@\expandafter\string\pgfmath@token\expandafter\string\pgfmath@token@next\endcsname\relax%
719 % Not a double character operator.
720 \expandafter\ifx\csname pgfmath@operator@\expandafter\string\pgfmath@token\endcsname\relax%
721 % Not a single character operator.
722 \pgfmath@error{Unknown operator `\pgfmath@token' or `\pgfmath@token\pgfmath@token@next'}{}%
723 \def\pgfmathresult{0}%
724 \let\pgfmath@parse@next=\pgfmath@parse@end%
725 \else%
726 \expandafter\pgfmath@operation@process\expandafter{\pgfmath@token}%
727 \ifx\pgfmath@token\pgfmath@text@@%
728 \let\pgfmath@parse@next=\pgfmath@parse@end%
729 \else%
730 \expandafter\ifx\csname pgfmath@operation@\expandafter\string\pgfmath@token @postfix\endcsname\pgfmath@token%
731 % Postfix operators are followed by an operator.
732 \ifx\pgfmath@token@next\pgfmath@char@leftbracket% Except [.
733 \let\pgfmath@parse@next=\pgfmath@parse@operand%
734 \else%
735 \let\pgfmath@parse@next=\pgfmath@parse@operator%
736 \fi%
737 \else%
738 % Any other operator is followed by an operand.
739 \let\pgfmath@parse@next=\pgfmath@parse@operand%
740 \fi%
741 \fi%
742 \fi%
743 \else%
744 % A double character operator...
745 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter%
746 \pgfmath@token\expandafter\expandafter\expandafter%
747 {\expandafter\pgfmath@token\pgfmath@token@next}%
748 \expandafter\pgfmath@operation@process\expandafter{\pgfmath@token}%
749 % ...is always followed by an operand.
750 \let\pgfmath@parse@next=\pgfmath@parse@@operand%
751 \fi%
752 \pgfmath@parse@next%
753 }
754
755
756 % Process an operation.
757 %
758 \def\pgfmath@operation@process#1{%
759 \def\pgfmath@operator{#1}%
760 \ifx\pgfmath@stack@operation@top\pgfmath@stack@empty%
761 \else%
762 \pgfmath@operation@@process%
763 \fi%
764 \expandafter\ifx\csname pgfmath@token@specials@#1\endcsname\relax%
765 \pgfmath@stack@push@operation{#1}%
766 \fi%
767 }
768
769 % Process the operation stack.
770 %
771 \def\pgfmath@operation@@process{%
772 \ifx\pgfmath@stack@operation@top\pgfmath@stack@empty%
773 \let\pgfmath@parse@next=\relax%
774 \else%
775 \ifnum\csname pgfmath@operation@\pgfmath@operator @precedence\endcsname>%
776 \csname pgfmath@operation@\pgfmath@stack@operation@top @precedence\endcsname\relax%
777 % If the precedence of the scanned operator is greater than the
778 % precedence of the operator at the top of the stack, do nothing.
779 \let\pgfmath@parse@next=\relax%
780 \else%
781 \let\pgfmath@stack@operation@last=\pgfmath@stack@operation@top%
782 \expandafter\ifx\csname pgfmath@operator@\pgfmath@stack@operation@top\endcsname\relax%
783 \pgfmath@function@@@process%
784 \else%
785 \pgfmath@operator@@@process%
786 \fi%
787 \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}%
788 \expandafter\ifx\csname pgfmath@token@group@\pgfmath@stack@operation@last\pgfmath@operator\endcsname\relax%
789 \let\pgfmath@parse@next=\pgfmath@operation@@process%
790 \else%
791 \let\pgfmath@parse@next=\relax%
792 \fi%
793 \fi%
794 \fi%
795 \pgfmath@parse@next%
796 }
797
798 % Process an operator.
799 %
800 \def\pgfmath@operator@@@process{% Process an operator.
801 \pgfmath@stack@pop@operation\pgfmath@@operator%
802 \pgfmath@stack@pop@operand\pgfmath@operand@a%
803 \ifcase\csname pgfmath@operation@\pgfmath@@operator @arity\endcsname\relax%
804 % Zero arity operators (!).
805 \or%
806 \pgfmath@operator@@@@process{\pgfmath@operand@a}%
807 \or%
808 \pgfmath@stack@pop@operand\pgfmath@operand@b%
809 \pgfmath@operator@@@@process{\pgfmath@operand@b}{\pgfmath@operand@a}%
810 \or%
811 \pgfmath@stack@pop@operand\pgfmath@operand@b%
812 \expandafter\pgfmath@operator@@@@process\expandafter%
813 {\expandafter\pgfmath@operand@b\expandafter}\pgfmath@operand@a%
814 \else%
815 % No operators with more than tenary arity.
816 \fi%
817 }
818
819 \def\pgfmath@operator@@@@process{%
820 \csname pgfmath%
821 \csname pgfmath@operation@\pgfmath@@operator @name\endcsname%
822 @\endcsname}
823
824 % Process a function.
825 %
826 \def\pgfmath@function@@@process{% Process a function.
827 \ifnum\csname pgfmath@operation@\pgfmath@stack@operation@top @arity\endcsname>0\relax%
828 \pgfmath@stack@pop@operation\pgfmath@@function%
829 \pgfmath@stack@pop@operand\pgfmath@@operand%
830 \ifnum\csname pgfmath@operation@\pgfmath@@function @arity\endcsname>1\relax%
831 \ifnum\csname pgfmath@operation@\pgfmath@@function @arity\endcsname>9\relax%
832 \csname pgfmath\pgfmath@@function @\endcsname{\pgfmath@@operand}%
833 \else%
834 \expandafter\pgfmath@function@@@@process\pgfmath@@operand%
835 \fi
836 \else%
837 \expandafter\pgfmath@function@@@@process\expandafter{\pgfmath@@operand}%
838 \fi%
839 \fi%
840 }
841
842 \def\pgfmath@function@@@@process{\csname pgfmath\pgfmath@@function @\endcsname}
843
844 % Stack.
845 %
846 \newtoks\pgfmath@stack@operand
847 \newtoks\pgfmath@stack@operation
848 \let\pgfmath@stack@empty=\pgfmath@empty
849
850 \def\pgfmath@stack@push#1#2{%
851 \def\pgfmath@stack@top{#2}%
852 \expandafter\expandafter\expandafter#1%
853 \expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter%
854 {\expandafter\pgfmath@stack@top\expandafter}\the#1}}%
855
856 \def\pgfmath@stack@pop#1#2{\expandafter\pgfmath@stack@@pop\the#1\pgfmath@stack@stop{#1}{#2}}
857 \def\pgfmath@stack@@pop#1#2#3\pgfmath@stack@stop#4#5{\def#5{#1}#4={{#2}#3}\def\pgfmath@stack@top{#2}}
858
859 \def\pgfmath@stack@push@operation#1{%
860 \pgfmath@stack@push\pgfmath@stack@operation{#1}%
861 \let\pgfmath@stack@operation@top=\pgfmath@stack@top}
862
863 \def\pgfmath@stack@pop@operation#1{%
864 \pgfmath@stack@pop\pgfmath@stack@operation{#1}%
865 \let\pgfmath@stack@operation@top=\pgfmath@stack@top}
866
867 % REMARK: This method will be overwritten by the FPU library. Please
868 % keep any changes consistent.
869 \def\pgfmath@stack@push@operand#1{%
870 \pgfmath@stack@push\pgfmath@stack@operand{#1}%
871 \let\pgfmath@stack@operand@top=\pgfmath@stack@top}
872
873 \def\pgfmath@stack@pop@operand#1{%
874 \pgfmath@stack@pop\pgfmath@stack@operand{#1}%
875 \let\pgfmath@stack@operand@top=\pgfmath@stack@top}
876
877
878 % Declare an operator for the parser.
879 %
880 % It is not recommended that new operators be created as
881 % the parser is not fully robust for arbitrary operators.
882 %
883 \def\pgfmathdeclareoperator#1#2#3#4#5{%
884 \ifx\pgfmath@operatorlist\pgfutil@empty
885 \edef\pgfmath@operatorlist{{\string#1}}%
886 \else
887 \edef\pgfmath@operatorlist{\pgfmath@operatorlist,{\string#1}}%
888 \fi
889 \pgfmath@namedef{pgfmath@operator@\string#1}{#1}%
890 \pgfmath@namedef{pgfmath@operation@\string#1@name}{#2}%
891 \pgfmath@namedef{pgfmath@operation@\string#1@arity}{#3}%
892 \pgfmath@namedef{pgfmath@operation@\string#1@#4}{#1}%
893 \pgfmath@namedef{pgfmath@operation@\string#1@precedence}{#5}%
894 }
895
896 \def\pgfmath@operatorlist{}
897
898 \pgfmathdeclareoperator{+}{add} {2}{infix}{500}
899 \pgfmathdeclareoperator{-}{subtract}{2}{infix}{500}
900 \pgfmathdeclareoperator{*}{multiply}{2}{infix}{700}
901 \pgfmathdeclareoperator{/}{divide} {2}{infix}{700}
902 \pgfmathdeclareoperator{^}{pow} {2}{infix}{900}
903
904 \pgfmathdeclareoperator{<} {} {1}{prefix} {1}
905
906 \pgfmathdeclareoperator{>} {greater} {2}{infix} {250}
907 \pgfmathdeclareoperator{<} {less} {2}{infix} {250}
908 \pgfmathdeclareoperator{==}{equal} {2}{infix} {250}
909 \pgfmathdeclareoperator{>=}{notless} {2}{infix} {250}
910 \pgfmathdeclareoperator{<=}{notgreater}{2}{infix} {250}
911 \pgfmathdeclareoperator{&&}{and} {2}{infix} {200}
912 \pgfmathdeclareoperator{||}{or} {2}{infix} {200}
913 \pgfmathdeclareoperator{!=}{notequal} {2}{infix} {250}
914 \pgfmathdeclareoperator{!} {not} {1}{prefix}{975}
915 \pgfmathdeclareoperator{?} {ifthenelse}{3}{infix} {100}
916 \pgfmathdeclareoperator{:} {@@collect} {2}{infix}{101}
917
918 \pgfmathdeclareoperator{!}{factorial}{1}{postfix}{800}% Must be defined after prefix ! operator.
919 \pgfmathdeclareoperator{r}{deg} {1}{postfix}{600}
920
921 \pgfmathdeclareoperator{,}{@collect} {2}{infix} {10}
922 \pgfmathdeclareoperator{[}{@startindex}{2}{prefix} {7}
923 \pgfmathdeclareoperator{]}{@endindex} {0}{postfix}{6}
924 \pgfmathdeclareoperator{(}{@startgroup}{1}{prefix} {5}
925 \pgfmathdeclareoperator{)}{@endgroup} {0}{postfix}{4}
926
927 \pgfmathdeclareoperator{\pgfmath@bgroup}{@startarray}{1}{prefix} {3}
928 \pgfmathdeclareoperator{\pgfmath@egroup}{@endarray} {1}{postfix}{2}%
929
930 % Special operators.
931 \pgfmathdeclareoperator{"}{}{1}{prefix}{1}
932 \pgfmathdeclareoperator{@}{}{0}{postfix}{0}
933
934 % Internal functions.
935
936 % Begin and end parenthesis ().
937 %
938 \def\pgfmath@startgroup@#1{\pgfmath@protected@edef\pgfmathresult{#1}}
939 \def\pgfmath@endgroup@{}% Never actually called.
940
941 % Begin and end array access [].
942 %
943 \def\pgfmath@startindex@#1#2{%
944 \expandafter\pgfmatharray@#1{#2}%
945 \expandafter\pgfmath@bgroup@strip\expandafter{\pgfmathresult}%
946 \ifx\pgfmath@token@let\bgroup%
947 \expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{\pgfmathresult}}%
948 \fi}
949 \def\pgfmath@endindex@{}% Never actually called.
950
951 % Begin and end array {}.
952 %
953 \def\pgfmath@startarray@#1{\expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{#1}}}
954 \def\pgfmath@endarray@#1{\expandafter\def\expandafter\pgfmathresult\expandafter{#1}}% Never actually called.
955
956
957 \def\pgfmath@@collect@#1#2{%
958 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter%
959 \pgfmathresult\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter%
960 {\expandafter#1\expandafter}\expandafter{#2}}%
961 }
962 % Collect items separated by ,.
963 %
964 \def\pgfmath@collect@#1#2{%
965 \expandafter\def\expandafter\pgfmath@collect@original\expandafter{#1}%
966 \expandafter\pgfmath@bgroup@strip\expandafter{#1}%
967 \ifx\pgfmath@token@let\bgroup%
968 \ifx\pgfmath@collect@original\pgfmath@bgroup@stripped%
969 \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmath@bgroup@stripped}%
970 \else%
971 \expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{\pgfmath@bgroup@stripped}}%
972 \fi%
973 \else%
974 \expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{\pgfmath@bgroup@stripped}}%
975 \fi%
976 \expandafter\pgfmath@bgroup@strip\expandafter{#2}%
977 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter%
978 \pgfmathresult\expandafter\expandafter\expandafter%
979 {\expandafter\pgfmathresult\expandafter{\pgfmath@bgroup@stripped}}%
980 }
981
982 % Strip braces from a token sequence.
983 %
984 \def\pgfmath@bgroup@strip#1{%
985 \def\pgfmath@bgroup@strip@last{#1}%
986 \pgfmath@bgroup@@strip{#1}\pgfmath@\pgfmath@@\pgfmath@@@}
987
988 \def\pgfmath@bgroup@strip@#1{%
989 \def\pgfmath@bgroup@strip@last{#1}%
990 \pgfmath@bgroup@@strip#1\pgfmath@\pgfmath@@\pgfmath@@@}
991
992 \def\pgfmath@bgroup@pgfmath@{\pgfmath@}
993
994 \def\pgfmath@bgroup@@strip{%
995 \futurelet\pgfmath@token@let\pgfmath@bgroup@@@strip}
996
997 \def\pgfmath@bgroup@@@strip#1#2#3\pgfmath@@@{%
998 \ifx\pgfmath@token@let\bgroup
999 \def\pgfmath@bgroup@test{#2}%
1000 \ifx\pgfmath@bgroup@test\pgfmath@bgroup@pgfmath@
1001 \def\pgfmath@next{\pgfmath@bgroup@strip@{#1}}%
1002 \else
1003 \let\pgfmath@bgroup@stripped=\pgfmath@bgroup@strip@last
1004 \let\pgfmath@next=\relax
1005 \fi
1006 \else
1007 \pgfmath@bgroup@@@@strip#1#2#3%
1008 \let\pgfmath@next=\relax
1009 \fi
1010 \pgfmath@next}
1011
1012 \def\pgfmath@bgroup@@@@strip#1\pgfmath@\pgfmath@@{%
1013 \def\pgfmath@bgroup@stripped{#1}}
1014
1015 % Local Variables:
1016 % tab-width: 2
1017 % End: