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
|
% Copyright 2022 by Qrrbrbirlbel
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
%% foreach
%% http://tex.stackexchange.com/a/126418/16595
%% instead of \foreach \var in {start, start + delta, ..., end}
%% this allows to use \foreach[use int={start to end step delta}] without(!) a list in {}
%% the values start, end and delta are evaluated by PGFmath at the start of the loop.
%% In addition to use int, there's also use float.
\newif\iftikzext@pgf@foreach@no@list
\pgfqkeys{/pgf/foreach}{
normal list/.code={%
\tikzext@pgf@foreach@no@listfalse
\def\pgffor@scan{\pgfutil@ifnextchar({\pgffor@scanround}{\pgffor@scanone}}%
},
no separator/.code={% token for token
\def\pgffor@scan@custom##1{%
\def\pgffor@value{##1}%
\pgffor@scanned
}%
\def\pgffor@scan@custom@comma,{%
\pgfutil@ifnextchar\pgffor@stop
\pgffor@scanone
{\pgffor@scan@custom,}%
}%
\def\pgffor@scan{%
\pgfutil@ifnextchar,%
\pgffor@scan@custom@comma
{%
\pgfutil@ifnextchar\pgffor@stop
\pgffor@scanone
\pgffor@scan@custom
}%
}%
},
use int/.code={%
\tikzext@pgf@foreach@no@list@parse@to\pgfmathtruncatemacro#1\pgffor@stop
},
use float/.code={%
\tikzext@pgf@foreach@no@list@parse@to\pgfmathsetmacro#1\pgffor@stop
}
}
\def\tikzext@pgf@foreach@no@list@parse@to#1#2to#3\pgffor@stop{%
\tikzext@pgf@foreach@no@listtrue
#1\foreachStart{#2}%
\pgfutil@in@{step}{#3}
\ifpgfutil@in@
\tikzext@pgf@foreach@no@list@parse@step{#1}#3\pgffor@stop
\else
\tikzext@pgf@foreach@no@list@parse@step{#1}#3step1\pgffor@stop
\fi
\edef\tikzext@pgf@foreach@no@list@list{\foreachStart,\foreachSecond,...,\foreachEnd}%
}
\def\tikzext@pgf@foreach@no@list@parse@step#1#2step#3\pgffor@stop{%
#1\foreachEnd{#2}%
#1\foreachSecond{\foreachStart+#3}%
}
\def\pgffor@vars{%
\pgfutil@ifnextchar i{\pgffor@@vars@end}{%
\pgfutil@ifnextchar[{\pgffor@@vars@opt}{%]
\pgfutil@ifnextchar/{\pgffor@@vars@slash@gobble}{%
\iftikzext@pgf@foreach@no@list\expandafter\pgfutil@firstoftwo\else
\expandafter\pgfutil@secondoftwo\fi
{\tikzext@pgf@foreach@no@listfalse\pgffor@macro@list\tikzext@pgf@foreach@no@list@list}
{\pgffor@@vars}}}}}%
\endinput
|