Debian Codegraph @

texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarymath.code.tex

raw
1 % Copyright 2019 by Mark Wibrow
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10 \usetikzlibrary{fpu}
11
12 \edef\tikz@math@at@catcode{\the\catcode`\@}%
13 \catcode`\@=11
14
15 \def\tikz@math@gobblespaces#1{\pgfutil@ifnextchar x{#1}{#1}}%
16
17 \def\tikz@math@meaning@macro{macro}%
18 \def\tikz@math@meaning@dimen{dimen}%
19 \def\tikz@math@meaning@count{count}%
20 \def\tikz@math@meaning@null{null}%
21
22 \def\tikz@math@getmeaning#1{\expandafter\tikz@math@@getmeaning\meaning#1\tikz@math@getmeaning@stop}%
23
24 \def\tikz@math@@getmeaning#1#2#3#4#5\tikz@math@getmeaning@stop{%
25 \if#1u% undefined
26 \let\tikz@math@meaning=\tikz@math@meaning@macro%
27 \else%
28 \if#1m%
29 \let\tikz@math@meaning=\tikz@math@meaning@macro%
30 \else%
31 \if#2d%
32 \let\tikz@math@meaning=\tikz@math@meaning@dimen%
33 \else%
34 \if#2c%
35 \let\tikz@math@meaning=\tikz@math@meaning@count%
36 \else%
37 \if#3k% A skip. Treat like a dimen.
38 \let\tikz@math@meaning=\tikz@math@meaning@dimen%
39 \else%
40 \let\tikz@math@meaning=\tikz@math@meaning@null%
41 \fi%
42 \fi%
43 \fi%
44 \fi%
45 \fi%
46 }%
47
48 \def\tikz@math@firstoftwo#1#2{#1}%
49 \def\tikz@math@secondoftwo#1#2{#2}%
50
51
52 \def\tikz@math@getvarstring#1{%
53 \begingroup%
54 \escapechar=-1\relax%
55 \expandafter\tikz@math@@getvarstring\string#1\tikz@math}%
56
57 \def\tikz@math@@getvarstring#1\tikz@math#2{%
58 \endgroup%
59 \def#2{#1}%
60 }%
61
62 \long\def\tikz@math@collecttosemicolon@other#1#2;{%
63 \def\tikz@math@collected{#2}#1}%
64 \def\tikz@math@semicolon@other{;}%
65
66 {\catcode`\;=13
67 \long\gdef\tikz@math@collecttosemicolon@active#1#2;{%
68 \def\tikz@math@collected{#2}#1}%
69 \gdef\tikz@math@semicolon@active{;}%
70 }%
71
72
73 \def\tikz@math@setvartype#1#2{%
74 \expandafter\let\csname tikz@math@var@vartype@\string#1\endcsname=#2%
75 }%
76
77
78 \def\tikz@math@getvartype#1#2{%
79 \def\tikz@math@marshal{\let#1=}%
80 \expandafter\tikz@math@marshal\csname
81 tikz@math@var@vartype@\string#2\endcsname%
82 }%
83
84
85
86 \def\tikz@math@ifvarcoordinate#1{%
87 \expandafter\ifx\csname
88 tikz@math@var@vartype@\string#1\endcsname\tikz@math@keyword@coordinate%
89 \let\tikz@math@next=\tikz@math@firstoftwo%
90 \else%
91 \let\tikz@math@next=\tikz@math@secondoftwo%
92 \fi%
93 \tikz@math@next%
94 }%
95
96 \def\tikz@math@ifvarinteger#1{%
97 \expandafter\ifx\csname
98 tikz@math@var@vartype@\string#1\endcsname\tikz@math@keyword@integer%
99 \let\tikz@math@next=\tikz@math@firstoftwo%
100 \else%
101 \let\tikz@math@next=\tikz@math@secondoftwo%
102 \fi%
103 \tikz@math@next%
104 }%
105
106
107 \def\tikz@math@setvarindexed#1{%
108 \expandafter\let\csname
109 tikz@math@var@subtype@\string#1\endcsname=\tikz@math@subtype@indexed%
110 }%
111
112 \def\tikz@math@clearvarindexed#1{%
113 \expandafter\let\csname tikz@math@var@subtype@\string#1\endcsname=\relax%
114 }%
115
116 \def\tikz@math@ifvarindexed#1{%
117 \expandafter\ifx\csname tikz@math@var@subtype@\string#1\endcsname\relax%
118 \let\tikz@math@next=\tikz@math@secondoftwo%
119 \else%
120 \let\tikz@math@next=\tikz@math@firstoftwo%
121 \fi%
122 \tikz@math@next%
123 }%
124
125 \def\tikz@math@stop{@}%
126
127 \let\tikz@math@parse@hook@before=\pgfutil@empty
128 \let\tikz@math@parse@hook@after=\pgfutil@empty
129
130 \def\tikz@math{%
131 \ifnum\catcode`\;=13\relax%
132 \let\tikz@math@semicolon=\tikz@math@semicolon@active%
133 \let\tikz@math@collecttosemicolon=\tikz@math@collecttosemicolon@active%
134 \else%
135 \let\tikz@math@semicolon=\tikz@math@semicolon@other%
136 \let\tikz@math@collecttosemicolon=\tikz@math@collecttosemicolon@other%
137 \fi%
138 \tikz@math@parse@hook@before%
139 \tikz@@math}%
140
141
142
143
144 \long\def\tikz@@math#1{%
145 \def\tikz@math@marshal{\tikz@math@parse#1}%
146 \expandafter\expandafter\expandafter\tikz@math@marshal\expandafter\tikz@math@stop\tikz@math@semicolon}%
147
148 \def\tikz@math@parse{\pgfutil@ifnextchar\bgroup\tikz@math@@parse@bgroup\tikz@math@@parse@nobgroup}%
149
150
151 \def\tikz@math@@parse@bgroup{%
152 \tikz@math@collecttosemicolon{%
153 % MW: Don't know how reliable this test is.
154 \ifx\pgf@selectfontorig\tikz@math@undefined%
155 \begingroup\tikz@math@collected\endgroup%
156 \else%
157 \begingroup\csname nullfont\endcsname\tikz@math@collected\endgroup%
158 \fi\tikz@math@parse}}%
159
160
161
162 \def\tikz@math@@parse@nobgroup{\tikz@math@collecttosemicolon{\tikz@math@@parse@@nobgroup}}%
163
164 \def\tikz@math@@parse@@nobgroup{%
165 \let\tikz@math@tmp=\tikz@math@collected%
166 \ifx\tikz@math@tmp\tikz@math@stop%
167 \def\tikz@math@next{\expandafter\tikz@math@parse@finish\tikz@math@semicolon}%
168 \else%
169 \def\tikz@math@next{\expandafter\expandafter\expandafter\tikz@math@parse@keyword@check\expandafter\tikz@math@tmp\tikz@math@semicolon}%
170 \fi%
171 \tikz@math@next%
172 }%
173
174 \def\tikz@math@parse@finish{%
175 \tikz@math@collecttosemicolon{\tikz@math@parse@hook@after}%
176 }%
177
178
179
180 \newif\iftikz@math@let
181 \def\tikz@math@parse@keyword@check#1{%
182 \tikz@math@letfalse%
183 \tikz@math@getmeaning{#1}%
184 \ifx\tikz@math@meaning\tikz@math@meaning@null%
185 \let\tikz@math@next=\tikz@math@parse@keyword%
186 \else%
187 \let\tikz@math@next=\tikz@math@parse@nokeyword%
188 \fi%
189 \tikz@math@next#1}%
190
191
192 \def\tikz@math@parse@keyword{%
193 \let\tikz@math@parsed@keyword=\pgfutil@empty%
194 \futurelet\tikz@math@parse@token\tikz@math@@parse@keyword}%
195
196 \def\tikz@math@@parse@keyword{%
197 \ifx\tikz@math@parse@token\pgfutil@sptoken%
198 \let\tikz@math@next=\tikz@math@@@parse@keyword%
199 \else%
200 \ifx\tikz@math@parse@token(%
201 \let\tikz@math@next=\tikz@math@@@parse@keyword%
202 \else%
203 \ifx\tikz@math@parse@token\bgroup%
204 \let\tikz@math@next=\tikz@math@@@parse@keyword%
205 \else%
206 \let\tikz@math@next=\tikz@math@@@@parse@keyword%
207 \fi%
208 \fi%
209 \fi%
210 \tikz@math@next}%
211
212 \def\tikz@math@error#1{\pgfutil@packageerror{tikz}{tikz math library: #1}{}}%
213
214 \def\tikz@math@@@parse@keyword{%
215 \expandafter\ifx\csname tikz@math@process@keyword@\tikz@math@parsed@keyword\endcsname\relax%
216 \expandafter\ifx\csname pgfmath\tikz@math@parsed@keyword\endcsname\relax%
217 \tikz@math@error{Unknown function or keyword '\tikz@math@parsed@keyword'}%
218 \else%
219 \def\tikz@math@next{\tikz@math@collecttosemicolon{\tikz@math@function@noassign}}%
220 \fi%
221 \else%
222 \expandafter\def\expandafter\tikz@math@next\expandafter{\csname tikz@math@process@keyword@\tikz@math@parsed@keyword\endcsname}%
223 \fi%
224 \tikz@math@next}%
225
226 \def\tikz@math@@@@parse@keyword#1{%
227 \edef\tikz@math@parsed@keyword{\tikz@math@parsed@keyword#1}%
228 \futurelet\tikz@math@parse@token\tikz@math@@parse@keyword%
229 }%
230
231 \def\tikz@math@function@noassign{%
232 \pgfmathparse{\tikz@math@parsed@keyword\tikz@math@collected}%
233 \tikz@math@parse%
234 }%
235
236
237
238
239 \def\tikz@math@process@keyword@count{\tikz@math@collecttosemicolon{\tikz@math@process@keyword@@count}}%
240 \def\tikz@math@process@keyword@@count{%
241 \def\tikz@math@assign@register{\csname newcount\endcsname}%
242 \expandafter\tikz@math@gobblespaces\expandafter\tikz@math@process@registers\tikz@math@collected,@,}%
243
244 \def\tikz@math@process@keyword@length{\tikz@math@collecttosemicolon{\tikz@math@process@keyword@@length}}%
245 \def\tikz@math@process@keyword@@length{%
246 \def\tikz@math@assign@register{\csname newdimen\endcsname}%
247 \expandafter\tikz@math@gobblespaces\expandafter\tikz@math@process@registers\tikz@math@collected,@,}%
248
249
250 \def\tikz@math@process@registers#1#2,{%
251 \def\tikz@math@var{#1}%
252 \ifx\tikz@math@var\tikz@math@stop%
253 \let\tikz@math@next=\tikz@math@parse%
254 \else%
255 \tikz@math@assign@register#1\relax%
256 \let\tikz@math@next=\tikz@math@process@registers%
257 \fi%
258 \tikz@math@gobblespaces\tikz@math@next%
259 }%
260
261
262 \def\tikz@math@process@keyword@if#1then{%
263 \def\tikz@math@if@condition{#1}%
264 \tikz@math@gobblespaces\tikz@math@parse@if@iftrue%
265 }%
266 \def\tikz@math@parse@if@iftrue#1{%
267 \def\tikz@math@if@trueaction{#1}%
268 \pgfutil@ifnextchar e{\tikz@math@parse@else}{\tikz@math@if@doif}}%
269
270 \def\tikz@math@parse@else else{\tikz@math@gobblespaces\tikz@math@if@doifelse}%
271
272 \def\tikz@math@if@doif{\tikz@math@collecttosemicolon{\tikz@math@if@@doif}}%
273
274 \def\tikz@math@if@@doif{%
275 \pgfmathparse{\tikz@math@if@condition}%
276 \ifpgfmathfloatparseactive%
277 \pgfmathfloattofixed{\pgfmathresult}%
278 \fi%
279 \ifdim\pgfmathresult pt=0pt\relax%
280 \else%
281 \expandafter\tikz@math\expandafter{\tikz@math@if@trueaction}%
282 \fi%
283 \tikz@math@parse%
284 }%
285 \def\tikz@math@if@doifelse{\tikz@math@collecttosemicolon{\tikz@math@if@@doifelse}}%
286 \def\tikz@math@if@@doifelse{%
287 \pgfmathparse{\tikz@math@if@condition}%
288 \ifpgfmathfloatparseactive%
289 \pgfmathfloattofixed{\pgfmathresult}%
290 \fi%
291 \let\tikz@math@if@falseaction=\tikz@math@collected%
292 \ifdim\pgfmathresult pt=0pt\relax%
293 \expandafter\tikz@math\expandafter{\tikz@math@if@falseaction}%
294 \else%
295 \expandafter\tikz@math\expandafter{\tikz@math@if@trueaction}%
296 \fi%
297 \tikz@math@parse%
298 }%
299 \def\tikz@math@process@keyword@let{%
300 \tikz@math@lettrue%
301 \tikz@math@gobblespaces\tikz@math@parse@nokeyword%
302 }%
303
304
305 \def\tikz@math@parse@nokeyword#1{%
306 \def\tikz@math@var{#1}%
307 \tikz@math@getvarstring{#1}\tikz@math@varstring%
308 \let\tikz@math@vartype=\pgfutil@empty%
309 \ifx\tikz@math@var\tikz@math@stop%
310 \let\tikz@math@next=\tikz@math@parse@finish%
311 \else%
312 \ifx\tikz@math@semicolon\tikz@math@var%
313 \let\tikz@math@next=\tikz@math@parse%
314 \else%
315 \let\tikz@math@next=\tikz@math@parse@index@check%
316 \fi%
317 \fi%
318 \tikz@math@next}%
319
320 \def\tikz@math@parse@index@check{%
321 \pgfutil@ifnextchar={\tikz@math@parse@noindex}{\tikz@math@parse@index}}%
322
323 \def\tikz@math@parse@noindex{%
324 \expandafter\tikz@math@clearvarindexed\tikz@math@var%
325 \let\tikz@math@current@index=\pgfutil@empty%
326 \tikz@math@parse@afterindex%
327 }%
328
329 \def\tikz@math@parse@index#1{%
330 \def\tikz@math@tmp{#1}%
331 \expandafter\tikz@math@setvarindexed\tikz@math@var% {}
332 \edef\tikz@math@current@index{#1}%
333 \tikz@math@parse@afterindex%
334 }%
335 \def\tikz@math@parse@afterindex#1={\tikz@math@gobblespaces\tikz@math@parse@assignment}%
336
337 \def\tikz@math@parse@assignment{\tikz@math@collecttosemicolon{\tikz@math@parse@@assignment}}%
338 \def\tikz@math@parse@@assignment{%
339 \expandafter\expandafter\expandafter\tikz@math@doassignment\expandafter\expandafter\expandafter%
340 {\expandafter\tikz@math@var\expandafter}\expandafter{\tikz@math@collected}%
341 \tikz@math@parse%
342 }%
343
344 \def\tikz@math@dollar@char{$}%
345 \def\tikz@math@dollar@char{$}% For annoying syntax highlighters
346
347 \def\tikz@math@doassignment#1#2{%
348 \tikz@math@ifvarcoordinate{#1}{%
349 \def\tikz@math@var{#1}% Unfortunately, we must do this again.
350 \tikz@math@getvarstring{#1}\tikz@math@varstring% And this
351 \expandafter\pgfutil@in@\tikz@math@dollar@char{#2}%
352 \edef\tikz@math@expression{#2}%
353 \ifpgfutil@in@%
354 \expandafter\tikz@scan@one@point\expandafter\tikz@math@assign@coordinate\tikz@math@expression%
355 \else%
356 \expandafter\ifx\csname tikz@library@calc@loaded\endcsname\relax%
357 \expandafter\tikz@scan@one@point\expandafter\tikz@math@assign@coordinate\tikz@math@expression%
358 \else%
359 \expandafter\tikz@scan@one@point\expandafter\tikz@math@assign@coordinate\expandafter%
360 (\expandafter$\tikz@math@expression$)%
361 \fi%
362 \fi%
363 }{%
364 \iftikz@math@let% Not really a let
365 \ifx\tikz@math@current@index\pgfutil@empty%
366 \edef#1{#2}%
367 \else%
368 \edef\tikz@math@tmp{#2}%
369 \expandafter\expandafter\expandafter\tikz@math@assign@index\expandafter\expandafter\expandafter%
370 {\expandafter\tikz@math@varstring\expandafter}\expandafter{\tikz@math@tmp}%
371 \fi%
372 \tikz@math@letfalse%
373 \else%
374 \ifx\tikz@math@current@index\pgfutil@empty%
375 \tikz@math@getmeaning{#1}%
376 \ifx\tikz@math@meaning\tikz@math@meaning@dimen%
377 \pgfmathsetlength{#1}{#2}%
378 \let\tikz@math@last@assigned@value=\pgfmathresult%
379 \else%
380 \ifx\tikz@math@meaning\tikz@math@meaning@count%
381 \pgfmathsetcount{#1}{#2}%
382 \let\tikz@math@last@assigned@value=\pgfmathresult%
383 \else%
384 \tikz@math@ifvarinteger{#1}{\pgfmathparse{int(#2)}}{\pgfmathparse{#2}}%
385 \let\tikz@math@last@assigned@value=\pgfmathresult%
386 \let#1=\pgfmathresult%
387 \fi%
388 \fi%
389 \else%
390 \tikz@math@ifvarinteger{#1}{\pgfmathparse{int(#2)}}{\pgfmathparse{#2}}%
391 \expandafter\tikz@math@assign@index\expandafter{\tikz@math@varstring}\pgfmathresult%
392 \let\tikz@math@last@assigned@value=\pgfmathresult%
393 \fi%
394 \fi%
395 }%
396 }%
397
398
399
400 \def\tikz@math@assign@index#1#2{%
401 \expandafter\def\csname#1\endcsname##1{\csname
402 tikz@math@var@indexed@#1@##1\endcsname}%
403 \expandafter\edef\csname
404 tikz@math@var@indexed@#1@\tikz@math@current@index\endcsname{#2}\relax%
405 }%
406
407
408
409 \def\tikz@math@assign@coordinate#1{%
410 \pgf@process{#1}%
411 \ifx\tikz@math@current@index\pgfutil@empty%
412 \expandafter\edef\csname\tikz@math@varstring\endcsname{\the\pgf@x,\the\pgf@y}%
413 \expandafter\edef\csname\tikz@math@varstring x\endcsname{\the\pgf@x}%
414 \expandafter\edef\csname\tikz@math@varstring y\endcsname{\the\pgf@y}%
415 \else%
416 \expandafter\tikz@math@assign@index\expandafter{\tikz@math@varstring}{\the\pgf@x,\the\pgf@y}%
417 \expandafter\tikz@math@assign@index\expandafter{\tikz@math@varstring x}{\the\pgf@x}%
418 \expandafter\tikz@math@assign@index\expandafter{\tikz@math@varstring y}{\the\pgf@y}%
419 \fi%
420 }%
421
422
423
424 \def\tikz@math@keyword@coordinate{coordinate}%
425 \def\tikz@math@process@keyword@coordinate{%
426 \let\tikz@math@vartype=\tikz@math@keyword@coordinate%
427 \tikz@math@gobblespaces\tikz@math@process@vartypes%
428 }%
429
430 \def\tikz@math@keyword@integer{integer}%
431 \def\tikz@math@process@keyword@integer{%
432 \let\tikz@math@vartype=\tikz@math@keyword@integer%
433 \tikz@math@gobblespaces\tikz@math@process@vartypes%
434 }%
435 \def\tikz@math@process@keyword@int{%
436 \tikz@math@process@keyword@integer%
437 }%
438
439 \def\tikz@math@keyword@real{real}%
440 \def\tikz@math@process@keyword@real{%
441 \let\tikz@math@vartype=\tikz@math@keyword@real%
442 \tikz@math@gobblespaces\tikz@math@process@vartypes%
443 }%
444
445 \def\tikz@math@process@keyword@point{\tikz@math@process@keyword@coordinate}%
446
447
448 \def\tikz@math@process@vartypes{\tikz@math@collecttosemicolon{\tikz@math@process@@vartypes}}%
449
450 \def\tikz@math@process@@vartypes{%
451 \expandafter\tikz@math@@process@vartypes\tikz@math@collected,@,\tikz@math%
452 }%
453
454 \def\tikz@math@@process@vartypes#1#2,{%
455 \def\tikz@math@var{#1}%
456 \tikz@math@getvarstring{#1}\tikz@math@varstring%
457 \ifx\tikz@math@var\tikz@math@stop%
458 \let\tikz@math@next=\tikz@math@@@process@vartypes%
459 \else%
460 \expandafter\tikz@math@setvartype\tikz@math@var\tikz@math@vartype%
461 \def\tikz@math@next{\tikz@math@gobblespaces\tikz@math@@process@vartypes}%
462 \fi%
463 \tikz@math@next%
464 }%
465
466 \def\tikz@math@process@keyword@print{\tikz@math@collecttosemicolon{\tikz@math@process@keyword@@print}}%
467 \def\tikz@math@process@keyword@@print{%
468 \begingroup\tikz@math@collected\endgroup\tikz@math@parse%
469 }%
470
471 \def\tikz@math@@@process@vartypes#1\tikz@math{%
472 \tikz@math@parse%
473 }%
474
475 \newcount\tikz@math@for@depth
476
477 \def\tikz@math@for@namedef#1{\expandafter\def\csname tikz@math@for@def@#1@\the\tikz@math@for@depth\endcsname}%
478 \def\tikz@math@for@nameedef#1{\expandafter\edef\csname tikz@math@for@def@#1@\the\tikz@math@for@depth\endcsname}%
479 \def\tikz@math@for@namelet#1{\expandafter\let\csname tikz@math@for@def@#1@\the\tikz@math@for@depth\endcsname}%
480
481 \def\tikz@math@for@namegetvalue#1#2{%
482 \def\tikz@math@marshal{\let#2=}%
483 \expandafter\tikz@math@marshal\csname tikz@math@for@def@#1@\the\tikz@math@for@depth\endcsname}%
484
485 \def\tikz@math@process@keyword@for{%
486 \tikz@math@for%
487 }%
488
489 \def\tikz@math@for@external{%
490 \ifnum\catcode`\;=13\relax%
491 \let\tikz@math@semicolon=\tikz@math@semicolon@active%
492 \let\tikz@math@collecttosemicolon=\tikz@math@collecttosemicolon@active%
493 \else%
494 \let\tikz@math@semicolon=\tikz@math@semicolon@other%
495 \let\tikz@math@collecttosemicolon=\tikz@math@collecttosemicolon@other%
496 \fi
497 \advance\tikz@math@for@depth by1\relax%
498 \tikz@math@for@namedef{execute}{\tikz@math@for@external@execute}%
499 \tikz@math@for@namedef{finished}{\relax}%
500 \tikz@math@gobblespaces\tikz@math@for@parsevar}%
501
502 \def\tikz@math@for@external@execute#1{#1}%
503
504 \def\tikz@math@for{%
505 \advance\tikz@math@for@depth by1\relax%
506 \tikz@math@for@namedef{execute}{\tikz@math}%
507 \tikz@math@for@namedef{finished}{\tikz@math@parse}%
508 \tikz@math@gobblespaces\tikz@math@for@parsevar}%
509
510
511 \def\tikz@math@for@parsevar#1{%
512 \tikz@math@for@namedef{var}{#1}%
513 \tikz@math@for@parsein}%
514
515 \def\tikz@math@getindex#1{%
516 \tikz@math@@getindex#1\tikz@math@getindex\tikz@math@@getindex%
517 }%
518
519 \def\tikz@math@@getindex#1#2\tikz@math@@getindex{#1}%
520
521 \def\tikz@math@for@parsein#1in{%
522 \def\tikz@math@tmp{#1}%
523 \ifx\tikz@math@tmp\pgfutil@empty%
524 \tikz@math@for@namedef{index}{}%
525 \else%
526 \tikz@math@for@nameedef{index}{\tikz@math@getindex{#1}}%
527 \fi%
528 \tikz@math@gobblespaces\tikz@math@for@parselist%
529 }%
530
531
532 \long\def\tikz@math@for@parselist#1{%
533 \edef\tikz@math@for@list{#1}%
534 \tikz@math@gobblespaces{%
535 \tikz@math@collecttosemicolon{\tikz@math@for@parseaction}}}%
536
537 \def\tikz@math@for@parseaction{%
538 \tikz@math@for@namedef{prevvalue}{}%
539 \tikz@math@for@namedef{prevprevvalue}{}%
540 \tikz@math@for@namelet{action}=\tikz@math@collected%
541 \expandafter\tikz@math@for@scan\tikz@math@for@list,\tikz@math,\tikz@@math%
542 }%
543
544 \def\tikz@math@token{\tikz@math}%
545
546
547 \def\tikz@math@for@scan#1,{%
548 \def\tikz@math@for@value{#1}%
549 \ifx\tikz@math@for@value\tikz@math@token%
550 \let\tikz@math@next=\tikz@math@for@scan@end%
551 \else%
552 \ifx\tikz@math@for@value\pgfutil@empty%
553 \let\tikz@math@next=\tikz@math@for@scan@end%
554 \else%
555 \pgfutil@in@{...}{#1}%
556 \ifpgfutil@in@%
557 \let\tikz@math@next=\tikz@math@for@scan@dots%
558 \else%
559 \tikz@math@for@namegetvalue{var}{\tikz@math@var}%
560 \tikz@math@for@namegetvalue{index}{\tikz@math@current@index}%
561 \tikz@math@for@namegetvalue{action}{\tikz@math@action}%
562 \expandafter\tikz@math@getvarstring\expandafter{\tikz@math@var}\tikz@math@varstring%
563 \expandafter\tikz@math@doassignment\expandafter{\tikz@math@var}{#1}%
564 \tikz@math@for@namelet{value}=\tikz@math@last@assigned@value%
565 \tikz@math@for@namegetvalue{execute}{\tikz@math@execute}%
566 \expandafter\tikz@math@execute\expandafter{\tikz@math@action}%
567 \tikz@math@for@namegetvalue{prevvalue}{\tikz@math@prevvalue}%
568 \tikz@math@for@namelet{prevprevvalue}=\tikz@math@prevvalue%
569 \tikz@math@for@namegetvalue{value}{\tikz@math@value}%
570 \tikz@math@for@namelet{prevvalue}=\tikz@math@value%
571 \let\tikz@math@next=\tikz@math@for@scan%
572 \fi%
573 \fi%
574 \fi%
575 \tikz@math@next%
576 }%
577
578 \newdimen\tikz@math@dimen
579
580 \def\tikz@math@for@scan@dots#1,{%
581 \pgfmathparse{#1}\let\tikz@math@value=\pgfmathresult%
582 \tikz@math@for@nameedef{endvalue}{\tikz@math@value}%
583 \tikz@math@for@namegetvalue{prevvalue}{\tikz@math@prevvalue}%
584 \tikz@math@for@namegetvalue{prevprevvalue}{\tikz@math@prevprevvalue}%
585 \tikz@math@dimen=\tikz@math@prevvalue pt\relax%
586 \ifx\tikz@math@prevprevvalue\pgfutil@empty%
587 \ifdim\tikz@math@prevvalue pt<\tikz@math@value pt\relax%%
588 \def\tikz@math@step{1pt}%
589 \else%
590 \def\tikz@math@step{-1pt}%
591 \fi%
592 \else%
593 \tikz@math@dimen=\tikz@math@prevvalue pt\relax%
594 \advance\tikz@math@dimen by-\tikz@math@prevprevvalue pt\relax%
595 \edef\tikz@math@step{\the\tikz@math@dimen}%
596 \fi%
597 \ifdim\tikz@math@step<0pt\relax%
598 \tikz@math@for@namedef{comparitor}{<}%
599 \else%
600 \tikz@math@for@namedef{comparitor}{>}%
601 \fi%
602 \tikz@math@for@nameedef{step}{\tikz@math@step}%
603 \tikz@math@for@doloop%
604 }%
605
606 \def\tikz@math@for@doloop{%
607 \tikz@math@for@namegetvalue{prevvalue}{\tikz@math@prevvalue}%
608 \tikz@math@for@namegetvalue{step}{\tikz@math@step}%
609 \tikz@math@for@namegetvalue{comparitor}{\tikz@math@comparitor}%
610 \tikz@math@for@namegetvalue{endvalue}{\tikz@math@endvalue}%
611 \tikz@math@dimen=\tikz@math@prevvalue pt\relax%
612 \advance\tikz@math@dimen by\tikz@math@step\relax%
613 \ifdim\tikz@math@dimen\tikz@math@comparitor\tikz@math@endvalue pt\relax%
614 \let\tikz@math@next=\tikz@math@for@endloop%
615 \else%
616 \tikz@math@for@nameedef{value}{\pgfmath@tonumber{\tikz@math@dimen}}%
617 \tikz@math@for@namegetvalue{var}{\tikz@math@var}%
618 \expandafter\tikz@math@getvarstring\expandafter{\tikz@math@var}\tikz@math@varstring%
619 \tikz@math@for@namegetvalue{index}{\tikz@math@current@index}%
620 \tikz@math@for@namegetvalue{action}{\tikz@math@action}%
621 \tikz@math@for@namegetvalue{value}{\tikz@math@value}%
622 \expandafter\expandafter\expandafter\tikz@math@doassignment\expandafter\expandafter\expandafter%
623 {\expandafter\tikz@math@var\expandafter}\expandafter{\tikz@math@value}%
624 \tikz@math@for@namegetvalue{execute}{\tikz@math@execute}%
625 \expandafter\tikz@math@execute\expandafter{\tikz@math@action}%
626 \tikz@math@for@namegetvalue{prevvalue}{\tikz@math@prevvalue}%
627 \tikz@math@for@namelet{prevprevvalue}=\tikz@math@prevvalue%
628 \tikz@math@for@namegetvalue{value}{\tikz@math@value}%
629 \tikz@math@for@namelet{prevvalue}=\tikz@math@value%
630 \let\tikz@math@next=\tikz@math@for@doloop%
631 \fi%
632 \tikz@math@next%
633 }%
634
635 \def\tikz@math@for@endloop{%
636 \tikz@math@for@scan}%
637
638
639
640
641 \def\tikz@math@for@scan@end#1\tikz@@math{%
642 \tikz@math@for@namegetvalue{finished}{\tikz@math@next}%
643 \advance\tikz@math@for@depth by-1\relax%
644 \tikz@math@next}%
645
646
647
648
649
650 \def\tikz@math@process@keyword@return{%
651 \tikz@math@collecttosemicolon{\pgfmathparse{\tikz@math@collected}\tikz@math@parse}}%
652
653 \def\tikz@math@process@keyword@function{\tikz@math@collecttosemicolon{\tikz@math@process@keyword@@function}}%
654 \def\tikz@math@process@keyword@@function{%
655 \let\tikz@math@function@name=\pgfutil@empty%
656 \let\tikz@math@function@arguments=\pgfutil@empty%
657 \let\tikz@math@function@body=\pgfutil@empty%
658 \expandafter\expandafter\expandafter\tikz@math@@declarefunction\expandafter\tikz@math@collected\tikz@math@semicolon%
659 }%
660
661 \def\tikz@math@@declarefunction{%
662 \pgfutil@ifnextchar\bgroup\tikz@math@@@collectbody\tikz@math@@@declarefunction}%
663
664
665 \def\tikz@math@@@declarefunction#1{%
666 \if#1(%)
667 \let\tikz@math@next=\tikz@math@@@collectarguments%
668 \else%
669 \expandafter\def\expandafter\tikz@math@function@name\expandafter{\tikz@math@function@name#1}%
670 \let\tikz@math@next=\tikz@math@@declarefunction%
671 \fi%
672 \tikz@math@next%
673 }%
674 \def\tikz@math@@@collectarguments#1){%
675 \def\tikz@math@function@arguments{#1}%
676 \tikz@math@@declarefunction%
677 }%
678
679 \newtoks\tikz@math@toks
680 \tikz@math@toks={#}%
681 \edef\tikz@math@char@hash{\the\tikz@math@toks}%
682 \tikz@math@toks={}%
683
684 \def\tikz@math@@@collectbody{\tikz@math@collecttosemicolon{\tikz@math@@@@collectbody}}%
685
686 \def\tikz@math@@@@collectbody{%
687 \tikz@math@toks={}%
688 \c@pgf@counta=0\relax%
689 \ifx\tikz@math@function@arguments\pgfutil@empty%
690 \else%
691 \expandafter\tikz@math@createargumentlist\tikz@math@function@arguments,,%
692 \expandafter\tikz@math@addto@toks\expandafter{\tikz@math@collected}%
693 \fi%
694 \edef\tikz@math@local@temp{%
695 \noexpand\pgfmathdeclarefunction{\tikz@math@function@name}{\the\c@pgf@counta}%
696 {\noexpand\def\noexpand\return{0}\noexpand\tikz@math{\the\tikz@math@toks}}%
697 }%
698 \tikz@math@local@temp
699 \tikz@math@parse%
700 }%
701
702 \def\tikz@math@addto@toks#1{%
703 \expandafter\tikz@math@toks\expandafter{\the\tikz@math@toks#1}}%
704
705 \def\tikz@math@createargumentlist{%
706 \pgfutil@ifnextchar
707 x\tikz@math@@createargumentlist\tikz@math@@createargumentlist}%
708
709 \def\tikz@math@comma{,}%
710 \def\tikz@math@@createargumentlist#1,{%
711 \def\tikz@math@tmp{#1}%
712 \ifx\tikz@math@tmp\pgfutil@empty%
713 \let\tikz@math@next=\relax%
714 \else%
715 \advance\c@pgf@counta by1\relax%
716 \tikz@math@addto@toks{#1=}%
717 \expandafter\expandafter\expandafter\tikz@math@addto@toks\expandafter\expandafter\expandafter%
718 {\expandafter\tikz@math@char@hash\the\c@pgf@counta;}%
719 \let\tikz@math@next=\tikz@math@createargumentlist%
720 \fi%
721 \tikz@math@next%
722 }%
723
724
725
726 \let\tikzmath=\tikz@math
727 \tikzset{evaluate/.code={\tikz@math{#1}}}%
728 \let\tikzmathfor=\tikz@math@for@external
729
730
731 \catcode`\@=\tikz@math@at@catcode\relax