Debian Codegraph @

texmf-dist/source/latex/forest/forest.dtx

raw
1 % \CheckSum{16651}
2 % \iffalse meta-comment
3 % forest.dtx
4 %% `forest' is a `pgf/tikz'-based package for drawing (linguistic) trees.
5 %%
6 %% Copyright (c) 2012-2017 Saso Zivanovic
7 %% (Sa\v{s}o \v{Z}ivanovi\'{c})
8 %% [email protected]
9 %%
10 %% This work may be distributed and/or modified under the
11 %% conditions of the LaTeX Project Public License, either version 1.3
12 %% of this license or (at your option) any later version.
13 %% The latest version of this license is in
14 %%
15 %% http://www.latex-project.org/lppl.txt
16 %%
17 %% and version 1.3 or later is part of all distributions of LaTeX
18 %% version 2005/12/01 or later.
19 %%
20 %% This work has the LPPL maintenance status `author-maintained'.
21 %%
22 %% This work consists of the following files:
23 %% - forest.dtx: central sources (with rudimentary implementation documentation)
24 %% - forest-libs.dtx: sources and documentation for libraries
25 %% + forest-compat.sty: sources/runtime for compatibility mode
26 %% - forest.ins: produces derived runtime .sty files
27 %% + forest.sty: main package
28 %% + forest-lib-*.sty: libraries (for the list, see forest.ins)
29 %% - forest-doc.tex: central documentation
30 %% - forest-doc.sty: private package needed to compile the documentation
31 %% - forest-index.dtx: sources of indexing package used in the documentation,
32 %% and also part of the documentation itself
33 %% - forest-doc.ins: produces derived .sty files needed to compile the documentation
34 %% - forest-index.sty
35 %% - forest-doc.ist: index style file needed to compile the documentation
36 %% - forest.pdf: documentation of core package implementation
37 %% - forest-doc.pdf: user's guide
38 %% - README
39 %% - LICENCE
40 %% To use the package, only the files marked with + need to be installed.
41 %%
42 %<*driver>
43 \documentclass[a4paper]{ltxdoc}
44
45 \usepackage{forest}
46 \usepackage{forest-doc}
47
48 \usepackage{fullpage}
49 \usepackage{hyperref}
50 \hypersetup{colorlinks=true,linkcolor=blue,citecolor=blue,hyperindex=false}
51 \usepackage{url}
52
53 %\input forest-common
54
55 \begin{document}
56 \DocInput{forest.dtx}
57 \end{document}
58 %</driver>
59 % \fi
60 %
61 % \title{Implementation of \FoRest;, a \PGF;/\TikZ;-based package for drawing linguistic
62 % trees\\\normalsize\forestversion}
63 %
64 % \author{Sa\v so \v Zivanovi\'c\footnote{e-mail:
65 % \href{mailto:[email protected]}{[email protected]}; web:
66 % \href{http://spj.ff.uni-lj.si/zivanovic/}{http://spj.ff.uni-lj.si/zivanovic/}}}
67 %
68 % \settodayfromforestdate
69 %
70 % \maketitle
71 %
72 % This file contains the documented source of \foRest;. If you are searching for the manual, follow
73 % this link to \href{http://mirrors.ctan.org/graphics/pgf/contrib/forest/forest-doc.pdf}{forest-doc.pdf}.
74 %
75 % The latest release of the package, including the sources, can be found on
76 % \href{http://ctan.org/pkg/forest}{CTAN}. For all versions of the package, including any
77 % non-yet-released work in progress, visit \href{https://github.com/sasozivanovic/forest}{\foRest;'s
78 % GitHub repo}. Contributions are welcome.
79 %
80 % A disclaimer: the code could've been much cleaner and better-documented \dots
81 %
82 % \tableofcontents
83 %
84 % \section{Identification}
85 % \begin{macrocode}
86 \ProvidesPackage{forest}[2017/07/14 v2.1.5 Drawing (linguistic) trees]
87
88 \RequirePackage{tikz}[2013/12/13]
89 \usetikzlibrary{shapes}
90 \usetikzlibrary{fit}
91 \usetikzlibrary{calc}
92 \usepgflibrary{intersections}
93
94 \RequirePackage{pgfopts}
95 \RequirePackage{etoolbox}[2010/08/21]
96 \RequirePackage{elocalloc}% for \locbox
97 \RequirePackage{environ}
98 \RequirePackage{xparse}
99
100 \RequirePackage{inlinedef}
101 \newtoks\ID@usercommands{}
102 \newcommand\NewInlineCommand[3][0]{%
103 \newcommand#2[#1]{#3}%
104 \ID@usercommands\xa{%
105 \the\ID@usercommands
106 \ifx\@foo#2%
107 \def\next{\ID@expandunsafe#2}%
108 \fi
109 }%
110 }
111 \def\@ExpandIfTF#1{%
112 \csname
113 % I'm not 100% sure if this plays well in every situation
114 \csname if#1\endcsname
115 @firstoftwo%
116 \else
117 @secondoftwo%
118 \fi
119 \endcsname
120 }
121 \patchcmd{\ID@switch}
122 {\ifcat\noexpand\@foo\space}
123 {\the\ID@usercommands\ifcat\noexpand\@foo\space}
124 {%
125 \NewInlineCommand[2]\ExpandIfT{%
126 \MultiExpand{3}{%
127 \@ExpandIfTF{#1}{#2}{}%
128 }%
129 }
130 \NewInlineCommand[2]\ExpandIfF{%
131 \MultiExpand{3}{%
132 \@ExpandIfTF{#1}{}{#2}%
133 }%
134 }
135 \NewInlineCommand[3]\ExpandIfTF{%
136 \MultiExpand{3}{%
137 \@ExpandIfTF{#1}{#2}{#3}%
138 }%
139 }%
140 \newcommand\InlineNoDef[1]{%
141 \begingroup
142 % Define a few ``quarks''
143 \def\Expand{\Expand}\def\Super{\Super}%
144 \def\UnsafeExpand{\UnsafeExpand}\def\MultiExpand{\MultiExpand}%
145 \def\Recurse{\Recurse}\def\NoExpand{\NoExpand}%
146 \def\Q@END{\Q@END}%
147 % Define a toks register
148 \ID@toks{}%
149 % Signal that we need to look for a star
150 \@testtrue\ID@starfalse\ID@starstarfalse\ID@bangfalse
151 % Start scanning for \def or \gdef
152 \ID@scan#1\Q@END{}%
153 \expandafter\endgroup
154 %\expandafter\@firstofone
155 \the\ID@toks
156 }%
157 }%
158 {%
159 \PackageWarning{forest}{Could not patch inlinedef! Disabling it. Except in some special situations (nested arrays), stuff will probably still work, but there's no guarantee. Please report this situation to the author (but check first if a new version already exists).}{}%
160 \let\Inline\relax
161 \def\Expand#1{#1}%
162 \def\MultiExpand#1#2{#2}%
163 \def\InlineNoDef#1{#1}%
164 \def\ExpandIfT#1#2{\@ExpandIfTF{#1}{#2}{}}%
165 \def\ExpandIfF#1#2{\@ExpandIfTF{#1}{}{#2}}%
166 \def\ExpandIfTF#1#2#3{\@ExpandIfTF{#1}{#2}{#3}}%
167 }
168 % \end{macrocode}
169 %
170 % |/forest| is the root of the key hierarchy.
171 % \begin{macrocode}
172 \pgfkeys{/forest/.is family}
173 \def\forestset#1{\pgfqkeys{/forest}{#1}}
174 % \end{macrocode}
175 %
176 % \section{Package options}
177 % \begin{macrocode}
178 \newif\ifforest@external@
179 \newif\ifforesttikzcshack
180 \newif\ifforest@install@keys@to@tikz@path@
181 \newif\ifforestdebugnodewalks
182 \newif\ifforestdebugdynamics
183 \newif\ifforestdebugprocess
184 \newif\ifforestdebugtemp
185 \newif\ifforestdebug
186 \def\forest@compat{}
187 \forestset{package@options/.cd,
188 external/.is if=forest@external@,
189 tikzcshack/.is if=foresttikzcshack,
190 tikzinstallkeys/.is if=forest@install@keys@to@tikz@path@,
191 compat/.code={\appto\forest@compat{,#1}},
192 compat/.default=most,
193 .unknown/.code={% load library
194 \eappto\forest@loadlibrarieslater{%
195 \noexpand\useforestlibrary{\pgfkeyscurrentname}%
196 \noexpand\forestapplylibrarydefaults{\pgfkeyscurrentname}%
197 }%
198 },
199 debug/.code={\forestdebugtrue\pgfqkeys{/forest/package@options/debug}{#1}},
200 debug/.default={nodewalks,dynamics,process},
201 debug/nodewalks/.is if=forestdebugnodewalks,
202 debug/dynamics/.is if=forestdebugdynamics,
203 debug/process/.is if=forestdebugprocess,
204 }
205 \forest@install@keys@to@tikz@path@true
206 \foresttikzcshacktrue
207 \def\forest@loadlibrarieslater{}
208 \AtEndOfPackage{\forest@loadlibrarieslater}
209 \NewDocumentCommand\useforestlibrary{s O{} m}{%
210 \def\useforestlibrary@@##1{\useforestlibrary@{#2}{##1}}%
211 \forcsvlist\useforestlibrary@@{#3}%
212 \IfBooleanT{#1}{\forestapplylibrarydefaults{#3}}%
213 }
214 \def\useforestlibrary@#1#2{%
215 \RequirePackage[#1]{forest-lib-#2}%
216 \csuse{forest@compat@libraries@#2}%
217 }
218 \def\forestapplylibrarydefaults#1{\forcsvlist\forestapplylibrarydefaults@{#1}}
219 \def\forestapplylibrarydefaults@#1{\forestset{libraries/#1/defaults/.try}}
220 \NewDocumentCommand\ProvidesForestLibrary{m O{}}{%
221 \ProvidesPackage{forest-lib-#1}[#2]%
222 \csdef{forest@libraries@loaded@#1}{}%
223 }
224 \def\forest@iflibraryloaded#1#2#3{\ifcsdef{forest@libraries@loaded@#1}{#2}{#3}}
225 \ProcessPgfPackageOptions{/forest/package@options}
226 % \end{macrocode}
227 % \section{Patches}
228 %
229 % This macro implements a fairly safe patching mechanism: the code is only patched if the original
230 % hasn't changed. If it did change, a warning message is printed. (This produces a spurious warning
231 % when the new version of the code fixes something else too, but what the heck.)
232 %
233 % \begin{macrocode}
234 \def\forest@patch#1#2#3#4#5{%
235 % #1 = cs to be patched
236 % %2 = purpose of the patch
237 % #3 = macro arguments
238 % #4 = original code
239 % #5 = patched code
240 \csdef{forest@original@#1}#3{#4}%
241 \csdef{forest@patched@#1}#3{#5}%
242 \ifcsequal{#1}{forest@original@#1}{%
243 \csletcs{#1}{forest@patched@#1}%
244 }{%
245 \ifcsequal{#1}{forest@patched@#1}{% all is good, the patch is in!
246 }{%
247 \PackageWarning{forest}{Failed patching '\expandafter\string\csname #1\endcsname'. Purpose of the patch: #2}%
248 }%
249 }%
250 }
251 % \end{macrocode}
252 %
253 % Patches for \PGF; 3.0.0 --- required version is [2013/12/13].
254 % \begin{macrocode}
255 \forest@patch{pgfgettransform}{fix a leaking space}{#1}{%
256 \edef#1{{\pgf@pt@aa}{\pgf@pt@ab}{\pgf@pt@ba}{\pgf@pt@bb}{\the\pgf@pt@x}{\the\pgf@pt@y}}
257 }{%
258 \edef#1{{\pgf@pt@aa}{\pgf@pt@ab}{\pgf@pt@ba}{\pgf@pt@bb}{\the\pgf@pt@x}{\the\pgf@pt@y}}%
259 }
260 % \end{macrocode}
261 %
262 % \section{Utilities}
263 %
264 % This is handy.
265 % \begin{macrocode}
266 \def\forest@empty{}
267 % \end{macrocode}
268 %
269 % Escaping |\if|s.
270 % \begin{macrocode}
271 \long\def\@escapeif#1#2\fi{\fi#1}
272 \long\def\@escapeifif#1#2\fi#3\fi{\fi\fi#1}
273 \long\def\@escapeififif#1#2\fi#3\fi#4\fi{\fi\fi\fi#1}
274 % \end{macrocode}
275 %
276 % \begin{macrocode}
277 \def\forest@repeat@n@times#1{% #1=n, #2=code
278 \expandafter\forest@repeat@n@times@\expandafter{\the\numexpr#1}}
279 \def\forest@repeat@n@times@#1{%
280 \ifnum#1>0
281 \@escapeif{%
282 \expandafter\forest@repeat@n@times@@\expandafter{\the\numexpr#1-1}%
283 }%
284 \else
285 \expandafter\@gobble
286 \fi
287 }
288 \def\forest@repeat@n@times@@#1#2{%
289 #2%
290 \forest@repeat@n@times@{#1}{#2}%
291 }
292 % \end{macrocode}
293 %
294 % A factory for creating |\...loop...| macros.
295 % \begin{macrocode}
296 \def\newloop#1{%
297 \count@=\escapechar
298 \escapechar=-1
299 \expandafter\newloop@parse@loopname\string#1\newloop@end
300 \escapechar=\count@
301 }%
302 {\lccode`7=`l \lccode`8=`o \lccode`9=`p
303 \lowercase{\gdef\newloop@parse@loopname#17889#2\newloop@end{%
304 \edef\newloop@marshal{%
305 \noexpand\csdef{#1loop#2}####1\expandafter\noexpand\csname #1repeat#2\endcsname{%
306 \noexpand\csdef{#1iterate#2}{####1\relax\noexpand\expandafter\expandafter\noexpand\csname#1iterate#2\endcsname\noexpand\fi}%
307 \expandafter\noexpand\csname#1iterate#2\endcsname
308 \let\expandafter\noexpand\csname#1iterate#2\endcsname\relax
309 }%
310 }%
311 \newloop@marshal
312 }%
313 }%
314 }%
315 % \end{macrocode}
316 %
317 % Loop that can be arbitrarily nested. (Not in the same macro, however: use another macro for the inner loop.) Usage: |\safeloop_code_\if..._code_\saferepeat|. |\safeloopn| expands to the current repetition number of the innermost group.
318 % \begin{macrocode}
319 \def\newsafeloop#1{%
320 \csdef{safeloop@#1}##1\saferepeat{%
321 \forest@temp@toks{##1}%
322 \csedef{safeiterate@#1}{%
323 \the\forest@temp@toks\relax
324 \noexpand\expandafter
325 \expandonce{\csname safeiterate@#1\endcsname}%
326 \noexpand\fi
327 }%
328 \csuse{safeiterate@#1}%
329 \advance\noexpand\safeloop@depth-1\relax
330 \cslet{safeiterate@#1}\relax
331 }%
332 \expandafter\newif\csname ifsafebreak@\the\safeloop@depth\endcsname
333 }%
334 \newcount\safeloop@depth
335 \def\safeloop{%
336 \advance\safeloop@depth1
337 \ifcsdef{safeloop@\the\safeloop@depth}{}{\expandafter\newsafeloop\expandafter{\the\safeloop@depth}}%
338 \csdef{safeloopn@\the\safeloop@depth}{0}%
339 \csuse{safeloop@\the\safeloop@depth}%
340 \csedef{safeloopn@\the\safeloop@depth}{\number\numexpr\csuse{safeloopn@\the\safeloop@depth}+1}%
341 }
342 \let\saferepeat\fi
343 \def\safeloopn{\csuse{safeloopn@\the\safeloop@depth}}%
344 % \end{macrocode}
345 %
346 % Another safeloop for usage with ``repeat'' / ``while'' // ``until'' keys, so that the user can refer to loop $n$s for outer loops.
347 % \begin{macrocode}
348 \def\newsafeRKloop#1{%
349 \csdef{safeRKloop@#1}##1\safeRKrepeat{%
350 \forest@temp@toks{##1}%
351 \csedef{safeRKiterate@#1}{%
352 \the\forest@temp@toks\relax
353 \noexpand\expandafter
354 \expandonce{\csname safeRKiterate@#1\endcsname}%
355 \noexpand\fi
356 }%
357 \csuse{safeRKiterate@#1}%
358 \advance\noexpand\safeRKloop@depth-1\relax
359 \cslet{safeRKiterate@#1}\relax
360 }%
361 \expandafter\newif\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
362 }%
363 \newcount\safeRKloop@depth
364 \def\safeRKloop{%
365 \advance\safeRKloop@depth1
366 \ifcsdef{safeRKloop@\the\safeRKloop@depth}{}{\expandafter\newsafeRKloop\expandafter{\the\safeRKloop@depth}}%
367 \csdef{safeRKloopn@\the\safeRKloop@depth}{0}%
368 \csuse{safeRKbreak@\the\safeRKloop@depth false}%
369 \csuse{safeRKloop@\the\safeRKloop@depth}%
370 \csedef{safeRKloopn@\the\safeRKloop@depth}{\number\numexpr\csuse{safeRKloopn@\the\safeRKloop@depth}+1}%
371 }
372 \let\safeRKrepeat\fi
373 \def\safeRKloopn{\csuse{safeRKloopn@\the\safeRKloop@depth}}%
374 % \end{macrocode}
375 %
376 % Additional loops (for embedding).
377 % \begin{macrocode}
378 \newloop\forest@loop
379 % \end{macrocode}
380 % New counters, dimens, ifs.
381 % \begin{macrocode}
382 \newdimen\forest@temp@dimen
383 \newcount\forest@temp@count
384 \newcount\forest@n
385 \newif\ifforest@temp
386 \newcount\forest@temp@global@count
387 \newtoks\forest@temp@toks
388 % \end{macrocode}
389 %
390 % Appending and prepending to token lists.
391 % \begin{macrocode}
392 \def\etotoks#1#2{\edef\pot@temp{#2}\expandafter#1\expandafter{\pot@temp}}
393 \def\apptotoks#1#2{\expandafter#1\expandafter{\the#1#2}}
394 \long\def\lapptotoks#1#2{\expandafter#1\expandafter{\the#1#2}}
395 \def\eapptotoks#1#2{\edef\pot@temp{#2}\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter#1\pot@temp}}
396 \def\pretotoks#1#2{\toks@={#2}\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks@\the#1}}
397 \def\epretotoks#1#2{\edef\pot@temp{#2}\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\pot@temp\the#1}}
398 \def\gapptotoks#1#2{\expandafter\global\expandafter#1\expandafter{\the#1#2}}
399 \def\xapptotoks#1#2{\edef\pot@temp{#2}\expandafter\expandafter\expandafter\global\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter#1\pot@temp}}
400 \def\gpretotoks#1#2{\toks@={#2}\expandafter\expandafter\expandafter\global\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks@\the#1}}
401 \def\xpretotoks#1#2{\edef\pot@temp{#2}\expandafter\expandafter\expandafter\global\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\pot@temp\the#1}}
402 % \end{macrocode}
403 %
404 % Expanding number arguments.
405 % \begin{macrocode}
406 \def\expandnumberarg#1#2{\expandafter#1\expandafter{\number#2}}
407 \def\expandtwonumberargs#1#2#3{%
408 \expandafter\expandtwonumberargs@\expandafter#1\expandafter{\number#3}{#2}}
409 \def\expandtwonumberargs@#1#2#3{%
410 \expandafter#1\expandafter{\number#3}{#2}}
411 \def\expandthreenumberargs#1#2#3#4{%
412 \expandafter\expandthreenumberargs@\expandafter#1\expandafter{\number#4}{#2}{#3}}
413 \def\expandthreenumberargs@#1#2#3#4{%
414 \expandafter\expandthreenumberargs@@\expandafter#1\expandafter{\number#4}{#2}{#3}}
415 \def\expandthreenumberargs@@#1#2#3#4{%
416 \expandafter#1\expandafter{\number#4}{#2}{#3}}
417 % \end{macrocode}
418 %
419 % A macro converting all non-alphanumerics (and an initial number) in a string to |__|. |#1| =
420 % string, |#2| = receiving macro. Used for declaring pgfmath functions.
421 % \begin{macrocode}
422 \def\forest@convert@others@to@underscores#1#2{%
423 \def\forest@cotu@result{}%
424 \forest@cotu@first#1\forest@end
425 \let#2\forest@cotu@result
426 }
427 \def\forest@cotu{%
428 \let\forest@cotu@have@num\forest@cotu@have@alpha
429 \futurelet\forest@cotu@nextchar\forest@cotu@checkforspace
430 }
431 \def\forest@cotu@first{%
432 \let\forest@cotu@have@num\forest@cotu@haveother
433 \futurelet\forest@cotu@nextchar\forest@cotu@checkforspace
434 }
435 \def\forest@cotu@checkforspace{%
436 \expandafter\ifx\space\forest@cotu@nextchar
437 \let\forest@cotu@next\forest@cotu@havespace
438 \else
439 \let\forest@cotu@next\forest@cotu@nospace
440 \fi
441 \forest@cotu@next
442 }
443 \def\forest@cotu@havespace#1{%
444 \appto\forest@cotu@result{_}%
445 \forest@cotu#1%
446 }
447 \def\forest@cotu@nospace{%
448 \ifx\forest@cotu@nextchar\forest@end
449 \@escapeif\@gobble
450 \else
451 \@escapeif\forest@cotu@nospaceB
452 \fi
453 }
454 \def\forest@cotu@nospaceB#1{%
455 \ifcat#1a%
456 \let\forest@cotu@next\forest@cotu@have@alpha
457 \else
458 \if!\ifnum9<1#1!\fi
459 \let\forest@cotu@next\forest@cotu@have@num
460 \else
461 \let\forest@cotu@next\forest@cotu@haveother
462 \fi
463 \fi
464 \forest@cotu@next#1%
465 }
466 \def\forest@cotu@have@alpha#1{%
467 \appto\forest@cotu@result{#1}%
468 \forest@cotu
469 }
470 \def\forest@cotu@haveother#1{%
471 \appto\forest@cotu@result{_}%
472 \forest@cotu
473 }
474 % \end{macrocode}
475 %
476 % Additional list macros.
477 % \begin{macrocode}
478 \def\forest@listedel#1#2{% #1 = list, #2 = item
479 \edef\forest@marshal{\noexpand\forest@listdel\noexpand#1{#2}}%
480 \forest@marshal
481 }
482 \def\forest@listcsdel#1#2{%
483 \expandafter\forest@listdel\csname #1\endcsname{#2}%
484 }
485 \def\forest@listcsedel#1#2{%
486 \expandafter\forest@listedel\csname #1\endcsname{#2}%
487 }
488 \edef\forest@restorelistsepcatcode{\noexpand\catcode`|\the\catcode`|\relax}%
489 \catcode`\|=3
490 \gdef\forest@listdel#1#2{%
491 \def\forest@listedel@A##1|#2|##2\forest@END{%
492 \forest@listedel@B##1|##2\forest@END%|
493 }%
494 \def\forest@listedel@B|##1\forest@END{%|
495 \def#1{##1}%
496 }%
497 \expandafter\forest@listedel@A\expandafter|#1\forest@END%|
498 }
499 \forest@restorelistsepcatcode
500 % \end{macrocode}
501 %
502 % Strip (the first level of) braces from all the tokens in the argument.
503 % \begin{macrocode}
504 \def\forest@strip@braces#1{%
505 \forest@strip@braces@A#1\forest@strip@braces@preend\forest@strip@braces@end
506 }
507 \def\forest@strip@braces@A#1#2\forest@strip@braces@end{%
508 #1\ifx\forest@strip@braces@preend#2\else\@escapeif{\forest@strip@braces@A#2\forest@strip@braces@end}\fi
509 }
510 % \end{macrocode}
511 %
512 % Utilities dealing with pgfkeys.
513 % \begin{macrocode}
514 \def\forest@copycommandkey#1#2{% copies command of #1 into #2
515 \pgfkeysifdefined{#1/.@cmd}{}{%
516 \PackageError{forest}{Key #1 is not a command key}{}%
517 }%
518 \pgfkeysgetvalue{#1/.@cmd}\forest@temp
519 \pgfkeyslet{#2/.@cmd}\forest@temp
520 \pgfkeysifdefined{#1/.@args}{%
521 \pgfkeysgetvalue{#1/.@args}\forest@temp
522 \pgfkeyslet{#2/.@args}\forest@temp
523 }{}%
524 \pgfkeysifdefined{#1/.@body}{%
525 \pgfkeysgetvalue{#1/.@body}\forest@temp
526 \pgfkeyslet{#2/.@body}\forest@temp
527 }{}%
528 \pgfkeysifdefined{#1/.@@body}{%
529 \pgfkeysgetvalue{#1/.@@body}\forest@temp
530 \pgfkeyslet{#2/.@@body}\forest@temp
531 }{}%
532 \pgfkeysifdefined{#1/.@def}{%
533 \pgfkeysgetvalue{#1/.@def}\forest@temp
534 \pgfkeyslet{#2/.@def}\forest@temp
535 }{}%
536 }
537 \forestset{
538 copy command key/.code 2 args={\forest@copycommandkey{#1}{#2}},
539 autoforward/.code 2 args={\forest@autoforward{#1}{#2={#1={##1}}}{true}},
540 autoforward'/.code 2 args={\forest@autoforward{#1}{#2-=#1,#2={#1={##1}}}{true}},
541 Autoforward/.code 2 args={\forest@autoforward{#1}{#2}{true}},
542 autoforward register/.code 2 args={\forest@autoforward{#1}{#2={#1={##1}}}{false}},
543 autoforward register'/.code 2 args={\forest@autoforward{#1}{#2-=#1,#2={#1={##1}}}{false}},
544 Autoforward register/.code 2 args={\forest@autoforward{#1}{#2}{false}},
545 copy command key@if it exists/.code 2 args={%
546 \pgfkeysifdefined{#1/.@cmd}{%
547 \forest@copycommandkey{#1}{#2}%
548 }{}%
549 },
550 unautoforward/.style={
551 typeout={unautoforwarding #1},
552 copy command key@if it exists={/forest/autoforwarded #1}{/forest/#1},
553 copy command key@if it exists={/forest/autoforwarded #1+}{/forest/#1+},
554 copy command key@if it exists={/forest/autoforwarded #1-}{/forest/#1-},
555 copy command key@if it exists={/forest/autoforwarded #1*}{/forest/#1*},
556 copy command key@if it exists={/forest/autoforwarded #1:}{/forest/#1:},
557 copy command key@if it exists={/forest/autoforwarded #1'}{/forest/#1'},
558 copy command key@if it exists={/forest/autoforwarded #1+'}{/forest/#1+'},
559 copy command key@if it exists={/forest/autoforwarded #1-'}{/forest/#1-'},
560 copy command key@if it exists={/forest/autoforwarded #1*'}{/forest/#1*'},
561 copy command key@if it exists={/forest/autoforwarded #1:'}{/forest/#1:'},
562 copy command key@if it exists={/forest/autoforwarded +#1}{/forest/+#1},
563 },
564 /handlers/.undef/.code={\csundef{pgfk@\pgfkeyscurrentpath}},
565 undef option/.style={
566 /forest/#1/.undef,
567 /forest/#1/.@cmd/.undef,
568 /forest/#1+/.@cmd/.undef,
569 /forest/#1-/.@cmd/.undef,
570 /forest/#1*/.@cmd/.undef,
571 /forest/#1:/.@cmd/.undef,
572 /forest/#1'/.@cmd/.undef,
573 /forest/#1+'/.@cmd/.undef,
574 /forest/#1-'/.@cmd/.undef,
575 /forest/#1*'/.@cmd/.undef,
576 /forest/#1:'/.@cmd/.undef,
577 /forest/+#1/.@cmd/.undef,
578 /forest/TeX={\patchcmd{\forest@node@init}{\forestoinit{#1}}{}{}{}},
579 },
580 undef register/.style={undef option={#1}},
581 }
582 \def\forest@autoforward#1#2#3{%
583 % #1 = option name
584 % #2 = code of a style taking one arg (new option value),
585 % which expands to whatever should be done with the new value
586 % autoforward(') adds to the keylist (arg#2)
587 % #3 = true=option, false=register
588 \forest@autoforward@createforwarder{}{#1}{}{#2}{#3}%
589 \forest@autoforward@createforwarder{}{#1}{+}{#2}{#3}%
590 \forest@autoforward@createforwarder{}{#1}{-}{#2}{#3}%
591 \forest@autoforward@createforwarder{}{#1}{*}{#2}{#3}%
592 \forest@autoforward@createforwarder{}{#1}{:}{#2}{#3}%
593 \forest@autoforward@createforwarder{}{#1}{'}{#2}{#3}%
594 \forest@autoforward@createforwarder{}{#1}{+'}{#2}{#3}%
595 \forest@autoforward@createforwarder{}{#1}{-'}{#2}{#3}%
596 \forest@autoforward@createforwarder{}{#1}{*'}{#2}{#3}%
597 \forest@autoforward@createforwarder{}{#1}{:'}{#2}{#3}%
598 \forest@autoforward@createforwarder{+}{#1}{}{#2}{#3}%
599 }
600 \def\forest@autoforward@createforwarder#1#2#3#4#5{%
601 % #1=prefix, #2=option name, #3=suffix, #4=macro code (#2 above), #5=option or register
602 \pgfkeysifdefined{/forest/#1#2#3/.@cmd}{%
603 \forest@copycommandkey{/forest/#1#2#3}{/forest/autoforwarded #1#2#3}%
604 \pgfkeyssetvalue{/forest/autoforwarded #1#2#3/option@name}{#2}%
605 \pgfkeysdef{/forest/#1#2#3}{%
606 \pgfkeysalso{autoforwarded #1#2#3={##1}}%
607 \def\forest@temp@macro####1{#4}%
608 \csname forest@temp#5\endcsname
609 \edef\forest@temp@value{\ifforest@temp\expandafter\forestOv\expandafter{\expandafter\forest@setter@node\expandafter}\else\expandafter\forestrv\fi{#2}}%
610 %\expandafter\expandafter\expandafter\pgfkeysalso\expandafter\expandafter\expandafter{\expandafter\forest@temp@macro\expandafter{\forest@temp@value}}% ??? how many expansions are really needed?
611 \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\pgfkeysalso\expandafter\expandafter\expandafter{\expandafter\forest@temp@macro\expandafter{\forest@temp@value}}%
612 }%
613 }{}%
614 }
615 \def\forest@node@removekeysfromkeylist#1#2{% #1 = keys to remove, #2 = option name
616 \edef\forest@marshal{%
617 \noexpand\forest@removekeysfromkeylist{\unexpanded{#1}}{\forestov{#2}}\noexpand\forest@temp@toks}\forest@marshal
618 \forestoeset{#2}{\the\forest@temp@toks}%
619 }
620 \def\forest@removekeysfromkeylist#1#2#3{%
621 % #1 = keys to remove (a keylist: an empty value means remove a key with any value)
622 % #2 = keylist
623 % #3 = toks cs for result
624 \forest@temp@toks{}%
625 \def\forestnovalue{\forestnovalue}%
626 \pgfqkeys{/forest/remove@key@installer}{#1}%
627 \let\forestnovalue\pgfkeysnovaluetext
628 \pgfqkeys{/forest/remove@key}{#2}%
629 \pgfqkeys{/forest/remove@key@uninstaller}{#1}%
630 #3\forest@temp@toks
631 }
632 \def\forest@remove@key@novalue{\forest@remove@key@novalue}%
633 \forestset{
634 remove@key@installer/.unknown/.code={% #1 = (outer) value
635 \def\forest@temp{#1}%
636 \ifx\forest@temp\pgfkeysnovalue@text
637 \pgfkeysdef{/forest/remove@key/\pgfkeyscurrentname}{}%
638 \else
639 \ifx\forest@temp\forestnovalue
640 \expandafter\forest@remove@key@installer@defwithvalue\expandafter{\pgfkeyscurrentname}{\pgfkeysnovalue}%
641 \else
642 \expandafter\forest@remove@key@installer@defwithvalue\expandafter{\pgfkeyscurrentname}{#1}%
643 \fi
644 \fi
645 },
646 remove@key/.unknown/.code={% #1 = (inner) value
647 \expandafter\apptotoks\expandafter\forest@temp@toks\expandafter{\pgfkeyscurrentname={#1},}%
648 },
649 remove@key@uninstaller/.unknown/.code={%
650 \pgfkeyslet{/forest/remove@key/\pgfkeyscurrentname/.@cmd}\@undefined},
651 }
652 \def\forest@remove@key@installer@defwithvalue#1#2{% #1=key name, #2 = outer value
653 \pgfkeysdef{/forest/remove@key/#1}{% ##1 = inner value
654 \def\forest@temp@outer{#2}%
655 \def\forest@temp@inner{##1}%
656 \ifx\forest@temp@outer\forest@temp@inner
657 \else
658 \apptotoks\forest@temp@toks{#1={##1},}%
659 \fi
660 }%
661 }
662 \forestset{
663 show register/.code={%
664 \forestrget{#1}\foresttemp
665 \typeout{Forest register "#1"=\expandafter\detokenize\expandafter{\foresttemp}}%
666 },
667 }
668 % \end{macrocode}
669 % \subsection{Arrays}
670 %
671 % \begin{macrocode}
672 \def\forest@newarray#1{%
673 \forest@tempfalse % non-global
674 {%
675 \escapechar=-1
676 \expandafter\escapechar\expandafter\count@\expandafter
677 }%
678 \expandafter\forest@newarray@\expandafter{\string#1}%
679 }
680 \def\forest@newglobalarray#1{%
681 \forest@temptrue % global
682 {%
683 \escapechar=-1
684 \expandafter\escapechar\expandafter\count@\expandafter
685 }%
686 \expandafter\forest@newarray@\expandafter{\string#1}%
687 }
688 \def\forest@array@empty@error#1{%
689 \PackageError{forest}{Cannot pop from empty array "#1".}{}}%
690 \def\forest@array@oub@error#1#2{%
691 \PackageError{forest}{#2 is out of bounds of array "#1"
692 (\the\csuse{#1M}--\the\csuse{#1N}).}{}}%
693 % \end{macrocode}
694 % Define array macros. For speed, we define most of them to be ``direct'', i.e.\ cointain the resolved control sequences specific to this array.
695 % \begin{macrocode}
696 \def\forest@newarray@#1{%
697 % array bounds: M <= i < N
698 \expandafter\newcount\csname#1M\endcsname
699 \expandafter\newcount\csname#1N\endcsname
700 \csedef{#1clear}{%
701 \ifforest@temp\global\fi\expandonce{\csname#1M\endcsname}0
702 \ifforest@temp\global\fi\expandonce{\csname#1N\endcsname}0
703 }%
704 \csedef{#1ifempty}{%
705 \noexpand\ifnum\expandonce{\csname#1M\endcsname}<\expandonce{\csname#1N\endcsname}\relax
706 \unexpanded{\expandafter\@secondoftwo
707 \else
708 \expandafter\@firstoftwo
709 \fi}%
710 }%
711 \csedef{#1length}{% a numexpr
712 \noexpand\numexpr\expandonce{\csname#1N\endcsname}-\expandonce{\csname#1M\endcsname}\relax
713 }%
714 \csedef{#1checkrange}##1##2{% args can be \numexprs
715 \noexpand\forest@tempfalse
716 \noexpand\ifnum\numexpr##1<\expandonce{\csname#1M\endcsname}\relax
717 \noexpand\forest@temptrue
718 \noexpand\fi
719 \noexpand\ifnum\numexpr##2>\expandonce{\csname#1N\endcsname}\relax
720 \noexpand\forest@temptrue
721 \noexpand\fi
722 \noexpand\ifforest@temp
723 \noexpand\forest@array@oub@error{#1}{Range "\noexpand\number\noexpand\numexpr##1\relax--\noexpand\number\noexpand\numexpr##2\relax"}%
724 \noexpand\fi
725 }%
726 \csedef{#1checkindex}##1{% arg can be a \numexpr
727 \noexpand\forest@tempfalse
728 \noexpand\ifnum\numexpr##1<\expandonce{\csname#1M\endcsname}\relax
729 \noexpand\forest@temptrue
730 \noexpand\fi
731 \noexpand\ifnum\numexpr##1<\expandonce{\csname#1N\endcsname}\relax
732 \noexpand\else
733 \noexpand\forest@temptrue
734 \noexpand\fi
735 \noexpand\ifforest@temp
736 \noexpand\forest@array@oub@error{#1}{Index "\noexpand\number\noexpand\numexpr##1\relax"}%
737 \noexpand\fi
738 }%
739 \csedef{#1get}##1##2{% ##1 = index, ##2 = receiving cs
740 \expandonce{\csname#1checkindex\endcsname}{##1}%
741 \noexpand\letcs##2{#1##1}%
742 }%
743 \csedef{#1get@}##1##2{% ##1 = index, ##2 = receiving cs (don't check bounds)
744 \noexpand\letcs##2{#1##1}%
745 }%
746 \csedef{#1toppop}##1{% ##1 = receiving cs
747 \expandonce{\csname#1ifempty\endcsname}{%
748 \noexpand\forest@array@empty@error{#1}%
749 }{%
750 \ifforest@temp\global\fi\advance\expandonce{\csname#1N\endcsname}-1
751 \noexpand\letcs\noexpand##1{#1\noexpand\the\expandonce{\csname#1N\endcsname}}%
752 }%
753 }%
754 \InlineNoDef{\csdef{#1bottompop}##1{% ##1 = receiving cs
755 \Expand{\csname#1ifempty\endcsname}{%
756 \forest@array@empty@error{#1}%
757 }{%
758 \letcs##1{#1\the\Expand{\csname#1M\endcsname}}%
759 \ExpandIfT{forest@temp}\global\advance\Expand{\csname#1M\endcsname 1}%
760 }%
761 }}%
762 % \csdef{#1bottompop}##1{}% we need this as \Inline chokes on \let\macro=\relax
763 % \expandafter\Inline\expandafter\def\csname#1bottompop\endcsname##1{% ##1 = receiving cs
764 % \Expand{\csname#1ifempty\endcsname}{%
765 % \forest@array@empty@error{#1}%
766 % }{%
767 % \letcs##1{#1\the\Expand{\csname#1M\endcsname}}%
768 % \ExpandIfT{forest@temp}\global\advance\Expand{\csname#1M\endcsname 1}%
769 % }%
770 % }%
771 % \csedef{#1bottompop}##1{% ##1 = receiving cs
772 % \expandonce{\csname#1ifempty\endcsname}{%
773 % \noexpand\forest@array@empty@error{#1}%
774 % }{%
775 % \noexpand\letcs\noexpand##1{#1\noexpand\the\expandonce{\csname#1M\endcsname}}%
776 % \ifforest@temp\global\fi\advance\expandonce{\csname#1M\endcsname}1
777 % }%
778 % }%
779 \csedef{#1setappend}##1{% ##1 = definition
780 \ifforest@temp\noexpand\csxdef\else\noexpand\csedef\fi
781 {#1\noexpand\the\expandonce{\csname#1N\endcsname}}%
782 {\noexpand\unexpanded{##1}}%
783 \ifforest@temp\global\fi\advance\expandonce{\csname#1N\endcsname}1
784 }%
785 \csedef{#1setappend@}##1##2{% ##1 = continue by, ##2 = definition
786 \ifforest@temp\noexpand\csxdef\else\noexpand\csedef\fi
787 {#1\noexpand\the\expandonce{\csname#1N\endcsname}}%
788 {\noexpand\unexpanded{##2}}%
789 \ifforest@temp\global\fi\advance\expandonce{\csname#1N\endcsname}1
790 ##1%
791 }%
792 \csedef{#1setprepend}##1{% ##1 = definition
793 \ifforest@temp\global\fi\advance\expandonce{\csname#1M\endcsname}-1
794 \ifforest@temp\noexpand\csxdef\else\noexpand\csedef\fi
795 {#1\noexpand\the\expandonce{\csname#1M\endcsname}}%
796 {\noexpand\unexpanded{##1}}%
797 }%
798 \csedef{#1esetappend}##1{% ##1 = definition
799 \ifforest@temp\noexpand\csxdef\else\noexpand\csedef\fi{#1\noexpand\the\expandonce{\csname#1N\endcsname}}{##1}%
800 \ifforest@temp\global\fi\advance\expandonce{\csname#1N\endcsname}1
801 }%
802 \csedef{#1esetprepend}##1{% ##1 = definition
803 \ifforest@temp\global\fi\advance\expandonce{\csname#1M\endcsname}-1
804 \ifforest@temp\noexpand\csxdef\else\noexpand\csedef\fi{#1\noexpand\the\expandonce{\csname#1M\endcsname}}{##1}%
805 }%
806 \csedef{#1letappend}##1{% ##1 = cs
807 \ifforest@temp\noexpand\expandafter\noexpand\global\fi\noexpand\expandafter\noexpand\let
808 \noexpand\csname#1\noexpand\the\expandonce{\csname#1N\endcsname}\noexpand\endcsname
809 ##1%
810 \ifforest@temp\global\fi\advance\expandonce{\csname#1N\endcsname}1
811 }%
812 \csedef{#1letprepend}##1{% ##1 = cs
813 \ifforest@temp\global\fi\advance\expandonce{\csname#1M\endcsname}-1
814 \ifforest@temp\noexpand\expandafter\noexpand\global\fi\noexpand\expandafter\noexpand\let
815 \noexpand\csname#1\noexpand\the\expandonce{\csname#1M\endcsname}\noexpand\endcsname
816 ##1%
817 }%
818 % \end{macrocode}
819 % I would love to define these only generically, as they will not be called often, but they need to be expandable. Argh.
820 % right?
821 % \begin{lstlisting}
822 % \def\arrayvalues{% <-- \csedef{#1values}
823 % \expandafter\expandafter\expandafter\arrayvaluesfromrange %\arrayvaluesfromrange <-- \expandonce{\csname#1valuesfromrange\endcsname}
824 % \expandafter\expandafter\expandafter{%
825 % \expandafter\the
826 % \expandafter\arrayM %\arrayM <-- \expandonce{\csname#1M\endcsname}%
827 % \expandafter}%
828 % \expandafter{%
829 % \the\arrayN %\arrayN <-- \expandonce{\csname#1N\endcsname}%
830 % }%
831 % }%
832 % \end{lstlisting}
833 % \begin{macrocode}
834 \csedef{#1values}{%
835 \noexpand\expandafter\noexpand\expandafter\noexpand\expandafter\expandonce{\csname#1valuesfromrange\endcsname}%
836 \noexpand\expandafter\noexpand\expandafter\noexpand\expandafter{%
837 \noexpand\expandafter\noexpand\the
838 \noexpand\expandafter\expandonce{\csname#1M\endcsname}%
839 \noexpand\expandafter}%
840 \noexpand\expandafter{\noexpand\the\expandonce{\csname#1N\endcsname}}%
841 }%
842 % \end{macrocode}
843 % \begin{lstlisting}
844 % \def\arrayvaluesfromrange##1##2{% ##1/##2 = lower/upper bounds (we receive them expanded) <-- \csedef{#1vuesfromrange}
845 % \ifnum##1<##2
846 % {\expandafter\expandonce\expandafter{\csname#1##1\endcsname}}% here we add braces (for the general case, we might want an arbitrary prefix&suffix)
847 % \expandafter\@escapeif\expandafter{\expandafter\arrayvaluesfromrange % <-- \expandonce{\csname#1valuesfromrange\endcsname}%
848 % \expandafter{\number\numexpr##1+1}{##2}}%
849 % \fi
850 % }%
851 % \end{lstlisting}
852 % As we need this to be expandable, we cannot check the range within the macro. You need to to this on your own using |...checkrange| defined above.
853 % \begin{macrocode}
854 \csedef{#1valuesfromrange}##1##2{% ##1/##2 = lower/upper bounds (we receive them expanded)
855 \noexpand\ifnum##1<##2
856 {\noexpand\expandafter\noexpand\expandonce\noexpand\expandafter{\noexpand\csname#1##1\noexpand\endcsname}}% here we add braces (for the general case, we might want an arbitrary prefix&suffix)
857 \noexpand\expandafter\noexpand\@escapeif\noexpand\expandafter{\noexpand\expandafter\expandonce{\csname#1valuesfromrange\endcsname}%
858 \noexpand\expandafter{\noexpand\number\noexpand\numexpr##1+1}{##2}}%
859 \noexpand\fi
860 }%
861 % \end{macrocode}
862 % Puts all items until |\forest@eov| into the array. After that is done, execute |\forest@topextend@next| (Why this macro? So that we can extend the array by tokens never seen before.). This code is difficult and not run often, so it doesn't need specialized control sequences.
863 % \begin{macrocode}
864 \csdef{#1topextend}{\def\forest@array@currentarray{#1}\forest@array@topextend}%
865 }
866 \def\forest@array@topextend{\futurelet\forest@ate@next@token\forest@ate@checkforspace}
867 \def\forest@ate@checkforspace{%
868 \expandafter\ifx\space\forest@ate@next@token
869 \expandafter\forest@ate@havespace
870 \else
871 \expandafter\forest@ate@checkforgroup
872 \fi
873 }
874 \def\forest@ate@havespace{\expandafter\forest@array@topextend\romannumeral-`0}%
875 \def\forest@ate@checkforgroup{%
876 \ifx\forest@ate@next@token\bgroup
877 \expandafter\forest@ate@appendgroup
878 \else
879 \expandafter\forest@ate@checkforeov
880 \fi
881 }
882 \def\forest@ate@appendgroup{%
883 \expandonce{\csname\forest@array@currentarray setappend@\endcsname}\forest@array@topextend
884 }
885 \def\forest@ate@checkforeov{%
886 \ifx\forest@ate@next@token\forest@eov
887 \expandafter\forest@ate@finish
888 \else
889 \expandafter\forest@ate@appendtoken
890 \fi
891 }
892 \def\forest@ate@appendtoken#1{%
893 \expandonce{\csname\forest@array@currentarray setappend\endcsname}{#1}%
894 \forest@array@topextend
895 }
896 \def\forest@ate@finish\forest@eov{\forest@topextend@next}
897 \let\forest@topextend@next\relax
898 \forest@newarray\forest@temparray@
899 \forest@newglobalarray\forest@global@temparray@
900 % \end{macrocode}
901 %
902 %
903 % \subsection{Testing for numbers and dimensions}
904 % \label{sec:is-count-or-dimen}
905 %
906 % Test if the argument is an integer (only base 10) that can be assigned to a \TeX\ count register.
907 % This is supposed to be a fast, not complete test, as anything not recognized as an integer will be
908 % passed on to |pgfmath| (by the code that uses these macros).
909 %
910 % We support |+|s, |-|s and spaces before the number. We don't support count registers.
911 %
912 % Dillema? Should |0abc| be interpreted as \TeX\ style (decimal) or PGF style (octal)? We go for
913 % \TeX\ style.
914 %
915 % The return value will hide in \TeX-style |\if|-macro |\forest@isnum| and counter |\forest@isnum@count|.
916 %
917 % \begin{macrocode}
918 \def\forest@eon{ }
919 \newif\ifforest@isnum@minus
920 \newif\ifforest@isnum
921 \def\forest@isnum#1{%
922 \forest@isnum@minusfalse
923 \let\forest@isnum@next\forest@isnum@finish
924 % \end{macrocode}
925 % Expand in advance, like pgfmath does.
926 % \begin{macrocode}
927 \edef\forest@isnum@temp{#1}%
928 % \end{macrocode}
929 % Add two end-of-value markers. The first one might be eaten by count assignment: that's why there
930 % are two and they expand to a space.
931 % \begin{macrocode}
932 \expandafter\forest@isnum@a\forest@isnum@temp\forest@eon\forest@eon\forest@END
933 \ifforest@isnum
934 \expandafter\@firstoftwo
935 \else
936 \expandafter\@secondoftwo
937 \fi
938 }
939 \def\forest@isnum@a{\futurelet\forest@isnum@token\forest@isnum@b}
940 % \end{macrocode}
941 % Test for three special characters: |-|, |+|, and space.
942 % \begin{macrocode}
943 \def\forest@isnum@minustoggle{%
944 \ifforest@isnum@minus\forest@isnum@minusfalse\else\forest@isnum@minustrue\fi
945 }
946 \def\forest@isnum@b{%
947 \let\forest@next\forest@isnum@p
948 \ifx-\forest@isnum@token
949 \forest@isnum@minustoggle
950 \let\forest@next\forest@isnum@c
951 \else
952 \ifx+\forest@isnum@token
953 \let\forest@next\forest@isnum@c
954 \else
955 \expandafter\ifx\space\forest@isnum@token
956 \let\forest@next\forest@isnum@s
957 \fi
958 \fi
959 \fi
960 \forest@next
961 }
962 % \end{macrocode}
963 % Eat |+| and |-|.
964 % \begin{macrocode}
965 \def\forest@isnum@c#1{\forest@isnum@a}%
966 % \end{macrocode}
967 % Eat the space!
968 % \begin{macrocode}
969 \def\forest@isnum@s#1{\forest@isnum@a#1}%
970 \newcount\forest@isnum@count
971 % \end{macrocode}
972 % Check for |0|. Why? If we have one, we know that the initial argument started with a number, so
973 % we have a chance that it is a number even if our assignment will yield $0$. If we have no |0| and the assignment yields $0$, we know we don't have a number.
974 % \begin{macrocode}
975 \def\forest@isnum@p{%
976 \ifx0\forest@isnum@token
977 \let\forest@next\forest@isnum@next
978 \else
979 \let\forest@next\forest@isnum@nz@
980 \fi
981 \forest@isnumtrue
982 \afterassignment\forest@isnum@q\forest@isnum@count\ifforest@isnum@minus-\fi0%
983 }
984 \def\forest@isnum@q{%
985 \futurelet\forest@isnum@token\forest@next
986 }
987 \def\forest@isnum@nz@{%
988 \ifnum\forest@isnum@count=0
989 \forest@isnumfalse
990 \fi
991 \forest@isnum@next
992 }
993 % \end{macrocode}
994 % This is the end of testing for an integer. If we have left-over stuff (|#1|), this was not a number.
995 % \begin{macrocode}
996 \def\forest@isnum@finish#1\forest@END{%
997 \ifx\forest@isnum@token\forest@eon
998 \else
999 \forest@isnumfalse
1000 \fi
1001 }
1002 % \end{macrocode}
1003 %
1004 % Is it a dimension? We support all \TeX's units but |true| units. Also supported are unitless
1005 % dimensions (i.e.\ decimal numbers), which are interpreted as |pt|s, as in pgfmath.
1006 %
1007 % The return value will hide in \TeX-style |\if|-macro |\forest@isdim| and counter |\forest@isdim@dimen|.
1008 %
1009 % \begin{macrocode}
1010 \newcount\forest@isdim@nonintpart
1011 \newif\ifforest@isdim
1012 \def\forest@isdim#1{%
1013 \forest@isdimfalse
1014 \forest@isnum@minusfalse
1015 \def\forest@isdim@leadingzeros{}%
1016 \forest@isdim@nonintpart=0
1017 \def\forest@isdim@unit{pt}%
1018 \let\forest@isnum@next\forest@isdim@checkfordot
1019 \edef\forest@isnum@temp{#1}%
1020 % \end{macrocode}
1021 % 4 end-of-value markers (|forest@eon|): one can be eaten by number (after the dot), two by a non-existing unit.
1022 % \begin{macrocode}
1023 \expandafter\forest@isnum@a\forest@isnum@temp\forest@eon\forest@eon\forest@eon\forest@eon\forest@END
1024 \ifforest@isdim
1025 \expandafter\@firstoftwo
1026 \else
1027 \expandafter\@secondoftwo
1028 \fi
1029 }
1030 \def\forest@isdim@checkfordot{%
1031 \ifx.\forest@isnum@token
1032 \expandafter\forest@isdim@dot
1033 \else
1034 \ifx,\forest@isnum@token
1035 \expandafter\expandafter\expandafter\forest@isdim@dot
1036 \else
1037 \expandafter\expandafter\expandafter\forest@isdim@nodot
1038 \fi
1039 \fi
1040 }
1041 \def\forest@isdim@nodot{%
1042 \ifforest@isnum
1043 % \end{macrocode}
1044 % No number, no dot, so not a dimension.
1045 % \begin{macrocode}
1046 \expandafter\forest@isdim@checkforunit
1047 \else
1048 \expandafter\forest@isdim@finish@nodim
1049 \fi
1050 }
1051 \def\forest@isdim@dot#1{% #1=. or ,
1052 \futurelet\forest@isnum@token\forest@isdim@collectzero
1053 }
1054 \def\forest@isdim@collectzero{%
1055 \ifx0\forest@isnum@token
1056 \expandafter\forest@isdim@collectzero@
1057 \else
1058 \expandafter\forest@isdim@getnonintpart
1059 \fi
1060 }
1061 \def\forest@isdim@collectzero@#1{% #1 = 0
1062 \appto\forest@isdim@leadingzeros{0}%
1063 \futurelet\forest@isnum@token\forest@isdim@collectzero
1064 }
1065 \def\forest@isdim@getnonintpart{%
1066 \afterassignment\forest@isdim@checkforunit\forest@isdim@nonintpart0%
1067 }
1068 % \end{macrocode}
1069 % Nothing else should be defined in |\forest@unit@| namespace.
1070 % \begin{macrocode}
1071 \def\forest@def@unit#1{\csdef{forest@unit@#1}{#1}}
1072 \forest@def@unit{em}
1073 \forest@def@unit{ex}
1074 \forest@def@unit{pt}
1075 \forest@def@unit{pc}
1076 \forest@def@unit{in}
1077 \forest@def@unit{bp}
1078 \forest@def@unit{cm}
1079 \forest@def@unit{mm}
1080 \forest@def@unit{dd}
1081 \forest@def@unit{cc}
1082 \forest@def@unit{sp}
1083 \def\forest@isdim@checkforunit#1#2{%
1084 \lowercase{\edef\forest@isnum@temp{\detokenize{#1#2}}}%
1085 \ifcsname forest@unit@\forest@isnum@temp\endcsname
1086 \let\forest@isdim@next\forest@isdim@finish@dim
1087 \edef\forest@isdim@unit{\csname forest@unit@\forest@isnum@temp\endcsname}%
1088 \else
1089 \ifx#1\forest@eon
1090 \let\forest@isdim@next\forest@isdim@finish@dim
1091 \else
1092 \let\forest@isdim@next\forest@isdim@finish@nodim
1093 \fi
1094 \fi
1095 \forest@isdim@next
1096 }
1097 \def\forest@isdim@finish@dim{%
1098 \futurelet\forest@isnum@token\forest@isdim@finish@dim@a
1099 }
1100 \def\forest@isdim@finish@dim@a{%
1101 \expandafter\ifx\space\forest@isnum@token
1102 \expandafter\forest@isdim@finish@dim@b
1103 \else
1104 \expandafter\forest@isdim@finish@dim@c
1105 \fi
1106 }
1107 \expandafter\def\expandafter\forest@isdim@finish@dim@b\space{% eat one space
1108 \futurelet\forest@isnum@token\forest@isdim@finish@dim@c
1109 }
1110 \def\forest@isdim@finish@dim@c#1\forest@END{%
1111 \ifx\forest@isnum@token\forest@eon
1112 \forest@isdimtrue
1113 \forest@isdim@dimen\the\forest@isnum@count.\forest@isdim@leadingzeros\the\forest@isdim@nonintpart\forest@isdim@unit\relax
1114 \else
1115 \forest@isdimfalse
1116 \fi
1117 }
1118 \def\forest@isdim@finish@nodim#1\forest@END{%
1119 \forest@isdimfalse
1120 }
1121 \newdimen\forest@isdim@dimen
1122 % \long\def\@firstofthree#1#2#3{#3} % defined by LaTeX
1123 \long\def\@firstofthree#1#2#3{#1}
1124 \long\def\@secondofthree#1#2#3{#2}
1125 \def\forest@isnumdim#1{%
1126 \forest@isdim{#1}{%
1127 \forest@isnumdim@
1128 }{%
1129 \@thirdofthree
1130 }%
1131 }
1132 \def\forest@isnumdim@{%
1133 \ifforest@isnum
1134 \expandafter\@firstofthree
1135 \else
1136 \expandafter\@secondofthree
1137 \fi
1138 }
1139 % \end{macrocode}
1140 %
1141 %
1142 % \subsection{forestmath}
1143 %
1144 % We imitate |pgfmath| a lot, but we remember the type of the result so that we can use \TeX's
1145 % primitives when possible.
1146 % \begin{macrocode}
1147 \def\forestmathtype@generic{_} % generic (token list)
1148 \def\forestmathtype@count{n} % integer
1149 \def\forestmathtype@dimen{d} % a dimension: <decimal> pt
1150 \def\forestmathtype@unitless{P} % <decimal> (a unitless dimension) (P because pgfmath returns such numbers)
1151 \def\forestmathtype@textasc{t} % text (ascending)
1152 \def\forestmathtype@textdesc{T} % text (descending)
1153 \def\forestmathtype@none{} % internal (for requests - means whatever)
1154 \def\forestmathresult{}
1155 \let\forestmathresulttype\forestmathtype@generic
1156 % \end{macrocode}
1157 % |\forest@tryprocess| takes four ``arguments''. The first is a true/false switch telling whether
1158 % to return the full result array in case we have a |.process| expression. The second is a
1159 % forestmath expression, delimited by |\forest@spacegen|: if it starts with a |>|, we take it to be
1160 % a |.process| expression, evaluate it using |\forest@process|, and execute the third argument; it
1161 % it doesn't, we execute the fourth argument.
1162 % \begin{macrocode}
1163 \def\forest@tryprocess#1{%
1164 \def\forest@tryprocess@returnarray{#1}%
1165 \expandafter\forest@tryprocess@a\romannumeral-`0}
1166 \def\forest@tryprocess@a{\futurelet\forest@temp@token\forest@tryprocess@b}
1167 \def\forest@tryprocess@b{%
1168 \ifx>\forest@temp@token
1169 \expandafter\forest@tryprocess@yes
1170 \else
1171 \expandafter\forest@tryprocess@no
1172 \fi
1173 }
1174 \def\forest@spacegen{ \forest@spacegen}
1175 \def\forest@tryprocess@yes#1#2\forest@spacegen{%
1176 \expandafter\forest@process\expandafter{\forest@tryprocess@returnarray}#2\forest@eov
1177 \@firstoftwo
1178 }
1179 \def\forest@tryprocess@no#1\forest@spacegen{\@secondoftwo}
1180 % \end{macrocode}
1181 % Forestmath versions of pgfmath macros. They accept process and pgfmath expressions, as described
1182 % above. In the case of a pgfmath expression, they use |\forest@isnum| and |\forest@isdim| for to
1183 % see if they can avoid pgfmath evaluation. (These checks are generally faster than pgfmath's fast
1184 % track.)
1185 % \begin{macrocode}
1186 \def\forestmathsetcount#1#2{%
1187 \forest@tryprocess{false}#2\forest@spacegen{%
1188 #1=\forest@process@result\relax
1189 }{%
1190 \forestmathsetcount@#1{#2}%
1191 }%
1192 }
1193 \def\forestmathsetcount@#1#2{%
1194 \forest@isnum{#2}{%
1195 #1=\forest@isnum@count
1196 }{%
1197 \pgfmathsetcount#1{#2}%
1198 }%
1199 }
1200 \def\forestmathsetlength#1#2{%
1201 \forest@tryprocess{false}#2\forest@spacegen{%
1202 #1=\forest@process@result\relax
1203 }{%
1204 \forestmathsetlength@#1{#2}%
1205 }%
1206 }
1207 \def\forestmathsetlength@#1#2{%
1208 \forest@isdim{#2}{%
1209 #1=\forest@isdim@dimen
1210 }{%
1211 \pgfmathsetlength#1{#2}%
1212 }%
1213 }
1214 \def\forestmathtruncatemacro#1#2{%
1215 \forest@tryprocess{false}#2\forest@spacegen{%
1216 \forest@temp@count=\forest@process@result\relax
1217 \edef#1{\the\forest@temp@count}%
1218 }{%
1219 \forestmathtruncatemacro@#1{#2}%
1220 }%
1221 }
1222 \def\forestmathtruncatemacro@#1#2{%
1223 \forest@isnum{#2}{%
1224 \edef#1{\the\forest@isnum@count}%
1225 }{%
1226 \pgfmathtruncatemacro#1{#2}%
1227 }%
1228 }
1229 \def\forestmathsetlengthmacro#1#2{%
1230 \forest@tryprocess{false}#2\forest@spacegen{%
1231 \forest@temp@dimen=\forest@process@result\relax
1232 \edef#1{\the\forest@temp@dimen}%
1233 }{%
1234 \forestmathsetlengthmacro@#1{#2}%
1235 }%
1236 }
1237 \def\forestmathsetlengthmacro@#1#2{%
1238 \forest@isdim{#2}{%
1239 \edef#1{\the\forest@isdim@dimen}%
1240 }{%
1241 \pgfmathsetlengthmacro#1{#2}%
1242 }%
1243 }
1244 \def\forestmathsetmacro#1#2{%
1245 \forest@tryprocess{false}#2\forest@spacegen{%
1246 \let#1\forest@process@result
1247 \let\forestmathresulttype\forest@process@result@type
1248 }{%
1249 \forestmathsetmacro@#1{#2}%
1250 \let\forestmathresulttype\forestmathtype@unitless
1251 }%
1252 }
1253 \def\forestmathsetmacro@#1#2{%
1254 \forest@isdim{#2}{%
1255 \edef#1{\expandafter\Pgf@geT\the\forest@isdim@dimen}%
1256 }{%
1257 \pgfmathsetmacro#1{#2}%
1258 }%
1259 }
1260 \def\forestmathparse#1{%
1261 \forest@tryprocess{false}#1\forest@spacegen{%
1262 \let\forestmathresult\forest@process@result
1263 \let\forestmathresulttype\forest@process@result@type
1264 }{%
1265 \forestmathparse@{#1}%
1266 \let\forestmathresulttype\forestmathtype@unitless
1267 }%
1268 }
1269 \def\forestmathparse@#1{%
1270 \forest@isdim{#1}{%
1271 \edef\forestmathresult{\expandafter\Pgf@geT\the\forest@isdim@dimen}%
1272 }{%
1273 \pgfmathsetmacro\forestmathresult{#1}%
1274 }%
1275 }
1276 % \end{macrocode}
1277 % The following macro, which is the only place that sets |\forest@tryprocess|'s |#1| to |true|, is
1278 % actually not used anywhere. It was meant for an argument processor instruction accepting
1279 % \meta{forestmath}, but that got separated into P and p. Not much harm is done by keeping it,
1280 % however, so we do, just in case.
1281 % \begin{macrocode}
1282 %\def\forestmathparse@returnarray#1{% same as above, but returns the result as an array (used only internally)
1283 % \forest@tryprocess{true}#1\forest@spacegen{}{%
1284 % \forestmathparse@{#1}%
1285 % \let\forest@process@result@type\forestmathtype@unitless
1286 % \forest@process@result@clear
1287 % \forest@process@result@letappend\forestmathresult
1288 % }%
1289 %}
1290 % \end{macrocode}
1291 % Evaluates |#1| to a boolean: if true execute |#2|, otherwise |#3|. |#2| and |#3| are \TeX\ code.
1292 % Includes a shortcut for some common values.
1293 % \begin{macrocode}
1294 \csdef{forest@bh@0}{0}
1295 \csdef{forest@bh@false}{0}
1296 \csdef{forest@bh@1}{1}
1297 \csdef{forest@bh@true}{1}
1298 \def\forestmath@if#1{%
1299 \ifcsdef{forest@bh@\detokenize{#1}}{%
1300 \let\forest@next\forestmath@if@fast
1301 }{%
1302 \let\forest@next\forestmath@if@slow
1303 }%
1304 \forest@next{#1}%
1305 \ifnum\forest@temp=0
1306 \expandafter\@secondoftwo
1307 \else
1308 \expandafter\@firstoftwo
1309 \fi
1310 }
1311 \def\forestmath@if@fast#1{\letcs\forest@temp{forest@bh@\detokenize{#1}}}
1312 \def\forestmath@if@slow#1{\forestmathtruncatemacro\forest@temp{#1}}
1313 % \end{macrocode}
1314 % These macros expandably convert a num(n)/dim(d)/unitless dim(P) to a num(n)/dim(d)/unitless
1315 % dim(P).
1316 % \begin{macrocode}
1317 \def\forestmath@convert@fromto#1#2#3{%
1318 \edef\forestmathresult{\csname forestmath@convert@from@#1@to@#2\endcsname{#3}}}
1319 \def\forestmath@convert@from#1{\forestmath@convert@fromto{#1}{\forestmathresulttype}}
1320 \def\forestmath@convert@to{\forestmath@convert@fromto{\forestmathresulttype}}
1321 \def\forestmath@convert@from@n@to@n#1{#1}
1322 \def\forestmath@convert@from@n@to@d#1{#1\pgfmath@pt}
1323 \def\forestmath@convert@from@n@to@P#1{#1}
1324 \def\forestmath@convert@from@d@to@n#1{%
1325 \expandafter\forestmath@convert@uptodot\Pgf@geT#1.\forest@eov}
1326 \def\forestmath@convert@from@d@to@d#1{#1}
1327 \def\forestmath@convert@from@d@to@P#1{\Pgf@geT#1}
1328 \def\forestmath@convert@from@P@to@n#1{%
1329 \forestmath@convert@uptodot#1.\forest@eov}
1330 \def\forestmath@convert@from@P@to@d#1{#1\pgfmath@pt}
1331 \def\forestmath@convert@from@P@to@P#1{#1}
1332 \def\forestmath@convert@uptodot#1.#2\forest@eov{#1}
1333 \def\forestmathzero{\forestmath@convert@from\forestmathtype@count{0}}
1334 % \end{macrocode}
1335 % These defer conversion (see aggregates).
1336 % \begin{macrocode}
1337 \csdef{forestmath@convert@from@n@to@_}#1{\unexpanded{#1}}
1338 \csdef{forestmath@convert@from@d@to@_}#1{\unexpanded{#1}}
1339 \csdef{forestmath@convert@from@P@to@_}#1{\unexpanded{#1}}
1340 % \end{macrocode}
1341 % Sets |\pgfmathresulttype| to the type of |#1|.
1342 % \begin{macrocode}
1343 \def\forestmathsettypefrom#1{%
1344 \forest@isnumdim{%
1345 \let\forestmathresulttype\forestmathtype@count
1346 }{%
1347 \let\forestmathresulttype\forestmathtype@dimen
1348 }{%
1349 \let\forestmathresulttype\forestmathtype@unitless
1350 }%
1351 }
1352 % \end{macrocode}
1353 % The following functions expect numbers or (bare or specified) dimensions as their parameters. The
1354 % version ending in |@| should get the argument type as its first argument; the version without |@|
1355 % uses |\forestmathresulttype|. The result type doesn't need to be changed, obviously.
1356 % \begin{macrocode}
1357 \def\forestmathadd#1#2{\edef\forestmathresult{%
1358 \csname forestmathadd@\forestmathresulttype\endcsname{#1}{#2}}}
1359 \def\forestmathadd@#1#2#3{\edef\forestmathresult{%
1360 \csname forestmathadd@#1\endcsname{#2}{#3}}}
1361 \def\forestmathadd@n#1#2{\the\numexpr#1+#2\relax}
1362 \def\forestmathadd@d#1#2{\the\dimexpr#1+#2\relax}
1363 \def\forestmathadd@P#1#2{\expandafter\Pgf@geT\the\dimexpr#1pt+#2pt\relax}
1364 \def\forestmathmultiply#1#2{%
1365 \csname forestmathmultiply@\forestmathresulttype\endcsname{#1}{#2}}
1366 \def\forestmathmultiply@#1#2#3{%
1367 \csname forestmathmultiply@#1\endcsname{#2}{#3}}
1368 \def\forestmathmultiply@n#1#2{\edef\forestmathresult{%
1369 \the\numexpr#1*#2\relax}}
1370 \def\forestmathmultiply@d#1#2{%
1371 \edef\forestmath@marshal{\forestmathmultiply@d@{#1}{#2}}\forestmath@marshal
1372 }
1373 \def\forestmathmultiply@d@#1#2{%
1374 \edef\forestmath@marshal{%
1375 \noexpand\pgfmathmultiply@{\Pgf@geT#1}{\Pgf@geT#2}%
1376 }\forestmath@marshal
1377 \edef\forestmathresult{\pgfmathresult\pgfmath@pt}%
1378 }
1379 \def\forestmathmultiply@P#1#2{%
1380 \pgfmathmultiply@{#1}{#2}%
1381 \let\forestmathresult\pgfmathresult
1382 }
1383 % \end{macrocode}
1384 % The return type of |forestmathdivide| is the type of the dividend. So, |n| and |d| type can only
1385 % be divided by integers; as |\numexpr| and |\dimexpr| are used, the result is rounded.
1386 % \begin{macrocode}
1387 \def\forestmathdivide#1#2{%
1388 \csname forestmathdivide@\forestmathresulttype\endcsname{#1}{#2}}
1389 \def\forestmathdivide@#1#2#3{%
1390 \csname forestmathdivide@#1\endcsname{#2}{#3}}
1391 \def\forestmathdivide@n#1#2{\edef\forestmathresult{%
1392 \the\numexpr#1/#2\relax}}
1393 \def\forestmathdivide@d#1#2{\edef\forestmathresult{%
1394 \the\dimexpr#1/#2\relax}}
1395 \def\forestmathdivide@P#1#2{%
1396 \edef\forest@marshal{%
1397 \noexpand\pgfmathdivide{+#1}{+#2}%
1398 }\forest@marshal
1399 \let\forestmathresult\pgfmathresult
1400 }
1401 % \end{macrocode}
1402 % Booleans.
1403 % \begin{macrocode}
1404 \def\forestmathtrue{%
1405 \def\forestmathresult{1}%
1406 \let\forestmathresulttype\forestmathtype@count}
1407 \def\forestmathfalse{%
1408 \def\forestmathresult{0}%
1409 \let\forestmathresulttype\forestmathtype@count}
1410 % \end{macrocode}
1411 % Comparisons. |\pdfstrcmp| is used to compare text (types |t| and |T|); note that it expands its
1412 % arguments. |<| and |>| comparison of generic type obviously makes no sense; |=| comparison is
1413 % done using |\ifx|: this is also the reason why these macros are not fully expandable, as we need
1414 % to |\def| the arguments to |\ifx|.
1415 %
1416 % Low level |<|.
1417 % \begin{macrocode}
1418 \def\forestmath@if@lt@n#1#2{\ifnum#1<#2\relax
1419 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1420 \def\forestmath@if@lt@d#1#2{\ifdim#1<#2\relax
1421 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1422 \def\forestmath@if@lt@P#1#2{\ifdim#1pt<#2pt
1423 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1424 \def\forestmath@if@lt@t#1#2{\ifnum\pdfstrcmp{#1}{#2}<0
1425 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1426 \def\forestmath@if@lt@T#1#2{\ifnum\pdfstrcmp{#1}{#2}>0
1427 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1428 \def\forest@cmp@error#1#2{\PackageError{forest}{Comparison
1429 ("<" or ">") of generic type arguments "#1" and "#2"
1430 makes no sense}{Use one of argument processor instructions
1431 "n", "d", "P" or "t" to change the type. Use package option
1432 "debug=process" to see what's happening here.}}
1433 \cslet{forestmath@if@lt@_}\forest@cmp@error
1434 % \end{macrocode}
1435 % Low level |=|.
1436 % \begin{macrocode}
1437 \def\forestmath@if@eq@n#1#2{\ifnum#1=#2\relax
1438 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1439 \def\forestmath@if@eq@d#1#2{\ifdim#1=#2\relax
1440 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1441 \def\forestmath@if@eq@P#1#2{\ifdim#1pt=#2pt
1442 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1443 \def\forestmath@if@eq@t#1#2{\ifnum\pdfstrcmp{#1}{#2}=0
1444 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1445 \let\forestmath@if@eq@T\forestmath@if@eq@t
1446 \csdef{forestmath@if@eq@_}#1#2{%
1447 \def\forestmath@tempa{#1}%
1448 \def\forestmath@tempb{#2}%
1449 \ifx\forestmath@tempa\forestmath@tempb
1450 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1451 % \end{macrocode}
1452 % High level |<|, |>| and |=|.
1453 % \begin{macrocode}
1454 \def\forestmathlt#1#2{%
1455 \csname forestmath@if@lt@\forestmathresulttype\endcsname{#1}{#2}%
1456 \forestmathtrue
1457 \forestmathfalse}
1458 \def\forestmathlt@#1#2#3{%
1459 \csname forestmath@if@lt@#1\endcsname{#2}{#3}%
1460 \forestmathtrue
1461 \forestmathfalse}
1462 \def\forestmathgt#1#2{%
1463 \csname forestmath@if@lt@\forestmathresulttype\endcsname{#2}{#1}%
1464 \forestmathtrue
1465 \forestmathfalse}
1466 \def\forestmathgt@#1#2#3{%
1467 \csname forestmath@if@lt@#1\endcsname{#3}{#2}%
1468 \forestmathtrue
1469 \forestmathfalse}
1470 \def\forestmatheq#1#2{%
1471 \csname forestmath@if@eq@\forestmathresulttype\endcsname{#1}{#2}%
1472 \forestmathtrue
1473 \forestmathfalse}
1474 \def\forestmatheq@#1#2#3{%
1475 \csname forestmath@if@eq@#1\endcsname{#2}{#3}%
1476 \forestmathtrue
1477 \forestmathfalse}
1478 % \end{macrocode}
1479 % Min and max. The complication here is that for numeric/dimension types, we want the empty value to
1480 % signal ``no argument'', i.e.\ the other argument should be the result; this is used in
1481 % aggregates. (For text types, the empty value is obviously the lesser one.) The arguments are expanded.
1482 % \begin{macrocode}
1483 \def\forestmathmin{\forestmath@minmax{min}{\forestmathresulttype}}
1484 \def\forestmathmax{\forestmath@minmax{max}{\forestmathresulttype}}
1485 \def\forestmathmin@{\forestmath@minmax{min}}
1486 \def\forestmathmax@{\forestmath@minmax{max}}
1487 \def\forestmath@minmax#1#2#3#4{% #1=min/max, #2=type, #3,#4=args
1488 \edef\forestmath@tempa{#3}%
1489 \edef\forestmath@tempb{#4}%
1490 \if\relax\detokenize\expandafter{\forestmath@tempa}\relax
1491 \forestmath@minmax@one{#1}{#2}\forestmath@tempb
1492 \else
1493 \if\relax\detokenize\expandafter{\forestmath@tempb}\relax
1494 \forestmath@minmax@one{#1}{#2}\forestmath@tempa
1495 \else
1496 \csname forestmath@#1\endcsname{#2}%
1497 \fi
1498 \fi
1499 }
1500 \def\forestmath@minmax@one#1#2#3{% #1=min/max, #2=type, #3 = the (possibly) non-empty arg
1501 \ifcsname forestmath@#1@one@#2\endcsname
1502 \csname forestmath@#1@one@#2\endcsname#3%
1503 \else
1504 \let\forestmathresult#3%
1505 \fi
1506 }
1507 \def\forestmath@min@one@t#1{\let\forestmathresult\forest@empty}
1508 \def\forestmath@max@one@t#1{\let\forestmathresult#1}
1509 \def\forestmath@min@one@T#1{\let\forestmathresult#1}
1510 \def\forestmath@max@one@T#1{\let\forestmathresult\forest@empty}
1511
1512 \def\forestmath@min#1{% #1 = type
1513 \csname forestmath@if@lt@#1\endcsname\forestmath@tempa\forestmath@tempb
1514 {\let\forestmathresult\forestmath@tempa}%
1515 {\let\forestmathresult\forestmath@tempb}%
1516 }
1517 \def\forestmath@max#1{% #1 = type
1518 \csname forestmath@if@lt@#1\endcsname\forestmath@tempa\forestmath@tempb
1519 {\let\forestmathresult\forestmath@tempb}%
1520 {\let\forestmathresult\forestmath@tempa}%
1521 }
1522 % \end{macrocode}
1523 %
1524 % \subsection{Sorting}
1525 %
1526 % Macro |\forest@sort| is the user interface to sorting.
1527 %
1528 % The user should prepare the data in an arbitrarily encoded
1529 % array,\footnote{In forest, arrays are encoded as families of
1530 % macros. An array-macro name consists of the (optional, but
1531 % recommended) prefix, the index, and the (optional) suffix (e.g.\
1532 % \texttt{$\backslash$forest@42x}). Prefix establishes the ``namespace'',
1533 % while using more than one suffix simulates an array of named tuples.
1534 % The length of the array is stored in macro \texttt{$\backslash$<prefix>n}.}
1535 % and provide the sorting macro (given in |#1|) and the array let
1536 % macro (given in |#2|): these are the only ways in which sorting
1537 % algorithms access the data. Both user-given macros should take two
1538 % parameters, which expand to array indices. The comparison macro
1539 % should compare the given array items and call |\forest@sort@cmp@gt|,
1540 % |\forest@sort@cmp@lt| or |\forest@sort@cmp@eq| to signal that the
1541 % first item is greater than, less than, or equal to the second item.
1542 % The let macro should ``copy'' the contents of the second item onto
1543 % the first item.
1544 %
1545 % The sorting direction is be given in |#3|: it can one of
1546 % |\forest@sort@ascending| and |\forest@sort@descending|. |#4| and
1547 % |#5| must expand to the lower and upper (both inclusive) indices of
1548 % the array to be sorted.
1549 %
1550 % |\forest@sort| is just a wrapper for the central sorting macro
1551 % |\forest@@sort|, storing the comparison macro, the array let macro
1552 % and the direction. The central sorting macro and the
1553 % algorithm-specific macros take only two arguments: the array bounds.
1554 % \begin{macrocode}
1555 \def\forest@sort#1#2#3#4#5{%
1556 \let\forest@sort@cmp#1\relax
1557 \let\forest@sort@let#2\relax
1558 \let\forest@sort@direction#3\relax
1559 \forest@@sort{#4}{#5}%
1560 }
1561 % \end{macrocode}
1562 % The central sorting macro. Here it is decided which sorting
1563 % algorithm will be used: for arrays at least
1564 % |\forest@quicksort@minarraylength| long, quicksort is used;
1565 % otherwise, insertion sort.
1566 % \begin{macrocode}
1567 \def\forest@quicksort@minarraylength{10000}
1568 \def\forest@@sort#1#2{%
1569 \ifnum#1<#2\relax\@escapeif{%
1570 \forest@sort@m=#2
1571 \advance\forest@sort@m -#1
1572 \ifnum\forest@sort@m>\forest@quicksort@minarraylength\relax\@escapeif{%
1573 \forest@quicksort{#1}{#2}%
1574 }\else\@escapeif{%
1575 \forest@insertionsort{#1}{#2}%
1576 }\fi
1577 }\fi
1578 }
1579 % \end{macrocode}
1580 % Various counters and macros needed by the sorting algorithms.
1581 % \begin{macrocode}
1582 \newcount\forest@sort@m\newcount\forest@sort@k\newcount\forest@sort@p
1583 \def\forest@sort@ascending{>}
1584 \def\forest@sort@descending{<}
1585 \def\forest@sort@cmp{%
1586 \PackageError{sort}{You must define forest@sort@cmp function before calling
1587 sort}{The macro must take two arguments, indices of the array
1588 elements to be compared, and return '=' if the elements are equal
1589 and '>'/'<' if the first is greater /less than the secong element.}%
1590 }
1591 \def\forest@sort@cmp@gt{\def\forest@sort@cmp@result{>}}
1592 \def\forest@sort@cmp@lt{\def\forest@sort@cmp@result{<}}
1593 \def\forest@sort@cmp@eq{\def\forest@sort@cmp@result{=}}
1594 \def\forest@sort@let{%
1595 \PackageError{sort}{You must define forest@sort@let function before calling
1596 sort}{The macro must take two arguments, indices of the array:
1597 element 2 must be copied onto element 1.}%
1598 }
1599 % \end{macrocode}
1600 % Quick sort macro (adapted from
1601 % \href{http://www.ctan.org/pkg/laansort}{laansort}).
1602 % \begin{macrocode}
1603 \newloop\forest@sort@loop
1604 \newloop\forest@sort@loopA
1605 \def\forest@quicksort#1#2{%
1606 % \end{macrocode}
1607 % Compute the index of the middle element (|\forest@sort@m|).
1608 % \begin{macrocode}
1609 \forest@sort@m=#2
1610 \advance\forest@sort@m -#1
1611 \ifodd\forest@sort@m\relax\advance\forest@sort@m1 \fi
1612 \divide\forest@sort@m 2
1613 \advance\forest@sort@m #1
1614 % \end{macrocode}
1615 % The pivot element is the median of the first, the middle and the
1616 % last element.
1617 % \begin{macrocode}
1618 \forest@sort@cmp{#1}{#2}%
1619 \if\forest@sort@cmp@result=%
1620 \forest@sort@p=#1
1621 \else
1622 \if\forest@sort@cmp@result>%
1623 \forest@sort@p=#1\relax
1624 \else
1625 \forest@sort@p=#2\relax
1626 \fi
1627 \forest@sort@cmp{\the\forest@sort@p}{\the\forest@sort@m}%
1628 \if\forest@sort@cmp@result<%
1629 \else
1630 \forest@sort@p=\the\forest@sort@m
1631 \fi
1632 \fi
1633 % \end{macrocode}
1634 % Exchange the pivot and the first element.
1635 % \begin{macrocode}
1636 \forest@sort@xch{#1}{\the\forest@sort@p}%
1637 % \end{macrocode}
1638 % Counter |\forest@sort@m| will hold the final location of the pivot
1639 % element.
1640 % \begin{macrocode}
1641 \forest@sort@m=#1\relax
1642 % \end{macrocode}
1643 % Loop through the list.
1644 % \begin{macrocode}
1645 \forest@sort@k=#1\relax
1646 \forest@sort@loop
1647 \ifnum\forest@sort@k<#2\relax
1648 \advance\forest@sort@k 1
1649 % \end{macrocode}
1650 % Compare the pivot and the current element.
1651 % \begin{macrocode}
1652 \forest@sort@cmp{#1}{\the\forest@sort@k}%
1653 % \end{macrocode}
1654 % If the current element is smaller (ascending) or greater
1655 % (descending) than the pivot element, move it into the first part of
1656 % the list, and adjust the final location of the pivot.
1657 % \begin{macrocode}
1658 \ifx\forest@sort@direction\forest@sort@cmp@result
1659 \advance\forest@sort@m 1
1660 \forest@sort@xch{\the\forest@sort@m}{\the\forest@sort@k}
1661 \fi
1662 \forest@sort@repeat
1663 % \end{macrocode}
1664 % Move the pivot element into its final position.
1665 % \begin{macrocode}
1666 \forest@sort@xch{#1}{\the\forest@sort@m}%
1667 % \end{macrocode}
1668 % Recursively call sort on the two parts of the list: elements before
1669 % the pivot are smaller (ascending order) / greater (descending order)
1670 % than the pivot; elements after the pivot are greater (ascending
1671 % order) / smaller (descending order) than the pivot.
1672 % \begin{macrocode}
1673 \forest@sort@k=\forest@sort@m
1674 \advance\forest@sort@k -1
1675 \advance\forest@sort@m 1
1676 \edef\forest@sort@marshal{%
1677 \noexpand\forest@@sort{#1}{\the\forest@sort@k}%
1678 \noexpand\forest@@sort{\the\forest@sort@m}{#2}%
1679 }%
1680 \forest@sort@marshal
1681 }
1682 % We defines the item-exchange macro in terms of the (user-provided)
1683 % array let macro.
1684 % \begin{macrocode}
1685 \def\forest@sort@aux{aux}
1686 \def\forest@sort@xch#1#2{%
1687 \forest@sort@let{\forest@sort@aux}{#1}%
1688 \forest@sort@let{#1}{#2}%
1689 \forest@sort@let{#2}{\forest@sort@aux}%
1690 }
1691 % \end{macrocode}
1692 % Insertion sort.
1693 % \begin{macrocode}
1694 \def\forest@insertionsort#1#2{%
1695 \forest@sort@m=#1
1696 \edef\forest@insertionsort@low{#1}%
1697 \forest@sort@loopA
1698 \ifnum\forest@sort@m<#2
1699 \advance\forest@sort@m 1
1700 \forest@insertionsort@Qbody
1701 \forest@sort@repeatA
1702 }
1703 \newif\ifforest@insertionsort@loop
1704 \def\forest@insertionsort@Qbody{%
1705 \forest@sort@let{\forest@sort@aux}{\the\forest@sort@m}%
1706 \forest@sort@k\forest@sort@m
1707 \advance\forest@sort@k -1
1708 \forest@insertionsort@looptrue
1709 \forest@sort@loop
1710 \ifforest@insertionsort@loop
1711 \forest@insertionsort@qbody
1712 \forest@sort@repeat
1713 \advance\forest@sort@k 1
1714 \forest@sort@let{\the\forest@sort@k}{\forest@sort@aux}%
1715 }
1716 \def\forest@insertionsort@qbody{%
1717 \forest@sort@cmp{\the\forest@sort@k}{\forest@sort@aux}%
1718 \ifx\forest@sort@direction\forest@sort@cmp@result\relax
1719 \forest@sort@p=\forest@sort@k
1720 \advance\forest@sort@p 1
1721 \forest@sort@let{\the\forest@sort@p}{\the\forest@sort@k}%
1722 \advance\forest@sort@k -1
1723 \ifnum\forest@sort@k<\forest@insertionsort@low\relax
1724 \forest@insertionsort@loopfalse
1725 \fi
1726 \else
1727 \forest@insertionsort@loopfalse
1728 \fi
1729 }
1730 % \end{macrocode}
1731 %
1732 % Below, several helpers for writing comparison macros are
1733 % provided. They take take two (pairs of) control sequence names and
1734 % compare their contents.
1735 %
1736 % Compare numbers.
1737 % \begin{macrocode}
1738 \def\forest@sort@cmpnumcs#1#2{%
1739 \ifnum\csname#1\endcsname>\csname#2\endcsname\relax
1740 \forest@sort@cmp@gt
1741 \else
1742 \ifnum\csname#1\endcsname<\csname#2\endcsname\relax
1743 \forest@sort@cmp@lt
1744 \else
1745 \forest@sort@cmp@eq
1746 \fi
1747 \fi
1748 }
1749 % \end{macrocode}
1750 % Compare dimensions.
1751 % \begin{macrocode}
1752 \def\forest@sort@cmpdimcs#1#2{%
1753 \ifdim\csname#1\endcsname>\csname#2\endcsname\relax
1754 \forest@sort@cmp@gt
1755 \else
1756 \ifdim\csname#1\endcsname<\csname#2\endcsname\relax
1757 \forest@sort@cmp@lt
1758 \else
1759 \forest@sort@cmp@eq
1760 \fi
1761 \fi
1762 }
1763 % \end{macrocode}
1764 % Compare points (pairs of dimension) |(#1,#2)| and |(#3,#4)|.
1765 % \begin{macrocode}
1766 \def\forest@sort@cmptwodimcs#1#2#3#4{%
1767 \ifdim\csname#1\endcsname>\csname#3\endcsname\relax
1768 \forest@sort@cmp@gt
1769 \else
1770 \ifdim\csname#1\endcsname<\csname#3\endcsname\relax
1771 \forest@sort@cmp@lt
1772 \else
1773 \ifdim\csname#2\endcsname>\csname#4\endcsname\relax
1774 \forest@sort@cmp@gt
1775 \else
1776 \ifdim\csname#2\endcsname<\csname#4\endcsname\relax
1777 \forest@sort@cmp@lt
1778 \else
1779 \forest@sort@cmp@eq
1780 \fi
1781 \fi
1782 \fi
1783 \fi
1784 }
1785 % \end{macrocode}
1786 %
1787 % The following macro reverses an array. The arguments: |#1| is
1788 % the array let macro; |#2| is the start index (inclusive), and
1789 % |#3| is the end index (exclusive).
1790 % \begin{macrocode}
1791 \def\forest@reversearray#1#2#3{%
1792 \let\forest@sort@let#1%
1793 \c@pgf@countc=#2
1794 \c@pgf@countd=#3
1795 \advance\c@pgf@countd -1
1796 \safeloop
1797 \ifnum\c@pgf@countc<\c@pgf@countd\relax
1798 \forest@sort@xch{\the\c@pgf@countc}{\the\c@pgf@countd}%
1799 \advance\c@pgf@countc 1
1800 \advance\c@pgf@countd -1
1801 \saferepeat
1802 }
1803 % \end{macrocode}
1804 %
1805 % \section{The bracket representation parser}
1806 % \label{imp:bracket}
1807 %
1808 % \subsection{The user interface macros}
1809 %
1810 % Settings.
1811 % \begin{macrocode}
1812 \def\bracketset#1{\pgfqkeys{/bracket}{#1}}%
1813 \bracketset{%
1814 /bracket/.is family,
1815 /handlers/.let/.style={\pgfkeyscurrentpath/.code={\let#1##1}},
1816 opening bracket/.let=\bracket@openingBracket,
1817 closing bracket/.let=\bracket@closingBracket,
1818 action character/.let=\bracket@actionCharacter,
1819 opening bracket=[,
1820 closing bracket=],
1821 action character,
1822 new node/.code n args={3}{% #1=preamble, #2=node spec, #3=cs receiving the id
1823 \forest@node@new#3%
1824 \forestOeset{#3}{given options}{\forest@contentto=\unexpanded{#2}}%
1825 \ifblank{#1}{}{%
1826 \forestrset{preamble}{#1}%
1827 }%
1828 },
1829 set afterthought/.code 2 args={% #1=node id, #2=afterthought
1830 \ifblank{#2}{}{\forestOappto{#1}{given options}{,afterthought={#2}}}%
1831 }
1832 }
1833 % \end{macrocode}
1834 %
1835 % |\bracketParse| is the macro that should be called to parse a
1836 % balanced bracket representation. It takes two parameters: |#1| is the code that will be run
1837 % after parsing the bracket; |#2| is a control sequence that will receive the id of the root of the
1838 % created tree structure. (The bracket representation should follow (after optional spaces), but is
1839 % is not a formal parameter of the macro.)
1840 % \begin{macrocode}
1841 \newtoks\bracket@content
1842 \newtoks\bracket@afterthought
1843 \def\bracketParse#1#2={%
1844 \def\bracketEndParsingHook{#1}%
1845 \def\bracket@saveRootNodeTo{#2}%
1846 % \end{macrocode}
1847 % Content and afterthought will be appended to these macros. (The |\bracket@afterthought| toks register is
1848 % abused for storing the preamble as well --- that's ok, the preamble comes before any afterhoughts.)
1849 % \begin{macrocode}
1850 \bracket@content={}%
1851 \bracket@afterthought={}%
1852 % \end{macrocode}
1853 % The parser can be in three states: in content (0), in afterthought
1854 % (1), or starting (2). While in the content/afterthought state, the
1855 % parser appends all non-control tokens to the content/afterthought macro.
1856 % \begin{macrocode}
1857 \let\bracket@state\bracket@state@starting
1858 \bracket@ignorespacestrue
1859 % \end{macrocode}
1860 % By default, don't expand anything.
1861 % \begin{macrocode}
1862 \bracket@expandtokensfalse
1863 % \end{macrocode}
1864 % We initialize several control sequences that are used to store some
1865 % nodes while parsing.
1866 % \begin{macrocode}
1867 \def\bracket@parentNode{0}%
1868 \def\bracket@rootNode{0}%
1869 \def\bracket@newNode{0}%
1870 \def\bracket@afterthoughtNode{0}%
1871 % \end{macrocode}
1872 % Finally, we start the parser.
1873 % \begin{macrocode}
1874 \bracket@Parse
1875 }
1876 % \end{macrocode}
1877 % The other macro that an end user (actually a power user) can use, is
1878 % actually just a synonym for |\bracket@Parse|. It should be used to
1879 % resume parsing when the action code has finished its work.
1880 % \begin{macrocode}
1881 \def\bracketResume{\bracket@Parse}%
1882 % \end{macrocode}
1883 %
1884 % \subsection{Parsing}
1885 %
1886 % We first check if the next token is a space. Spaces need special
1887 % treatment because they are eaten by both the |\romannumeral| trick
1888 % and \TeX s (undelimited) argument parsing algorithm. If a space is
1889 % found, remember that, eat it up, and restart the parsing.
1890 % \begin{macrocode}
1891 \def\bracket@Parse{%
1892 \futurelet\bracket@next@token\bracket@Parse@checkForSpace
1893 }
1894 \def\bracket@Parse@checkForSpace{%
1895 \expandafter\ifx\space\bracket@next@token\@escapeif{%
1896 \ifbracket@ignorespaces\else
1897 \bracket@haveSpacetrue
1898 \fi
1899 \expandafter\bracket@Parse\romannumeral-`0%
1900 }\else\@escapeif{%
1901 \bracket@Parse@maybeexpand
1902 }\fi
1903 }
1904 % \end{macrocode}
1905 %
1906 % We either fully expand the next token (using a popular \TeX nical
1907 % trick \dots) or don't expand it at all, depending on the state of
1908 % |\ifbracket@expandtokens|.
1909 % \begin{macrocode}
1910 \newif\ifbracket@expandtokens
1911 \def\bracket@Parse@maybeexpand{%
1912 \ifbracket@expandtokens\@escapeif{%
1913 \expandafter\bracket@Parse@peekAhead\romannumeral-`0%
1914 }\else\@escapeif{%
1915 \bracket@Parse@peekAhead
1916 }\fi
1917 }
1918 % \end{macrocode}
1919 % We then look ahead to see what's coming.
1920 % \begin{macrocode}
1921 \def\bracket@Parse@peekAhead{%
1922 \futurelet\bracket@next@token\bracket@Parse@checkForTeXGroup
1923 }
1924 % \end{macrocode}
1925 % If the next token is a begin-group token, we append the whole group to
1926 % the content or afterthought macro, depending on the state.
1927 % \begin{macrocode}
1928 \def\bracket@Parse@checkForTeXGroup{%
1929 \ifx\bracket@next@token\bgroup%
1930 \@escapeif{\bracket@Parse@appendGroup}%
1931 \else
1932 \@escapeif{\bracket@Parse@token}%
1933 \fi
1934 }
1935 % \end{macrocode}
1936 % This is easy: if a control token is found, run the appropriate
1937 % macro; otherwise, append the token to the content or afterthought
1938 % macro, depending on the state.
1939 % \begin{macrocode}
1940 \long\def\bracket@Parse@token#1{%
1941 \ifx#1\bracket@openingBracket
1942 \@escapeif{\bracket@Parse@openingBracketFound}%
1943 \else
1944 \@escapeif{%
1945 \ifx#1\bracket@closingBracket
1946 \@escapeif{\bracket@Parse@closingBracketFound}%
1947 \else
1948 \@escapeif{%
1949 \ifx#1\bracket@actionCharacter
1950 \@escapeif{\futurelet\bracket@next@token\bracket@Parse@actionCharacterFound}%
1951 \else
1952 \@escapeif{\bracket@Parse@appendToken#1}%
1953 \fi
1954 }%
1955 \fi
1956 }%
1957 \fi
1958 }
1959 % \end{macrocode}
1960 % Append the token or group to the content or afterthought macro. If a
1961 % space was found previously, append it as well.
1962 % \begin{macrocode}
1963 \newif\ifbracket@haveSpace
1964 \newif\ifbracket@ignorespaces
1965 \def\bracket@Parse@appendSpace{%
1966 \ifbracket@haveSpace
1967 \ifcase\bracket@state\relax
1968 \eapptotoks\bracket@content\space
1969 \or
1970 \eapptotoks\bracket@afterthought\space
1971 \or
1972 \eapptotoks\bracket@afterthought\space
1973 \fi
1974 \bracket@haveSpacefalse
1975 \fi
1976 }
1977 \long\def\bracket@Parse@appendToken#1{%
1978 \bracket@Parse@appendSpace
1979 \ifcase\bracket@state\relax
1980 \lapptotoks\bracket@content{#1}%
1981 \or
1982 \lapptotoks\bracket@afterthought{#1}%
1983 \or
1984 \lapptotoks\bracket@afterthought{#1}%
1985 \fi
1986 \bracket@ignorespacesfalse
1987 \bracket@Parse
1988 }
1989 \def\bracket@Parse@appendGroup#1{%
1990 \bracket@Parse@appendSpace
1991 \ifcase\bracket@state\relax
1992 \apptotoks\bracket@content{{#1}}%
1993 \or
1994 \apptotoks\bracket@afterthought{{#1}}%
1995 \or
1996 \apptotoks\bracket@afterthought{{#1}}%
1997 \fi
1998 \bracket@ignorespacesfalse
1999 \bracket@Parse
2000 }
2001 % \end{macrocode}
2002 % Declare states.
2003 % \begin{macrocode}
2004 \def\bracket@state@inContent{0}
2005 \def\bracket@state@inAfterthought{1}
2006 \def\bracket@state@starting{2}
2007 % \end{macrocode}
2008 %
2009 % Welcome to the jungle. In the following two macros, new nodes are
2010 % created, content and afterthought are sent to them, parents and
2011 % states are changed\dots\@ Altogether, we distinguish six cases, as
2012 % shown below: in the schemas, we have just crossed the symbol after
2013 % the dots. (In all cases, we reset the |\if| for spaces.)
2014 % \begin{macrocode}
2015 \def\bracket@Parse@openingBracketFound{%
2016 \bracket@haveSpacefalse
2017 \ifcase\bracket@state\relax% in content [ ... [
2018 % \end{macrocode}
2019 % |[...[|: we have just finished gathering the content and are about
2020 % to begin gathering the content of another node. We create a
2021 % new node (and put the content (\dots) into
2022 % it). Then, if there is a parent node, we append the new node to the
2023 % list of its children. Next, since we have just crossed an opening
2024 % bracket, we declare the newly created node to be the parent of the
2025 % coming node. The state does not change. Finally, we continue parsing.
2026 % \begin{macrocode}
2027 \@escapeif{%
2028 \bracket@createNode
2029 \ifnum\bracket@parentNode=0 \else
2030 \forest@node@Append{\bracket@parentNode}{\bracket@newNode}%
2031 \fi
2032 \let\bracket@parentNode\bracket@newNode
2033 \bracket@Parse
2034 }%
2035 \or % in afterthought ] ... [
2036 % \end{macrocode}
2037 % |]...[|: we have just finished gathering the afterthought and are
2038 % about to begin gathering the content of another node. We add the
2039 % afterthought (\dots) to the ``afterthought node'' and change into the
2040 % content state. The parent does not change. Finally, we continue
2041 % parsing.
2042 % \begin{macrocode}
2043 \@escapeif{%
2044 \bracket@addAfterthought
2045 \let\bracket@state\bracket@state@inContent
2046 \bracket@Parse
2047 }%
2048 \else % starting
2049 % \end{macrocode}
2050 % |{start}...[|: we have just started. Nothing to do yet (we couldn't
2051 % have collected any content yet), just get into the content state and
2052 % continue parsing.
2053 % \begin{macrocode}
2054 \@escapeif{%
2055 \let\bracket@state\bracket@state@inContent
2056 \bracket@Parse
2057 }%
2058 \fi
2059 }
2060 \def\bracket@Parse@closingBracketFound{%
2061 \bracket@haveSpacefalse
2062 \ifcase\bracket@state\relax % in content [ ... ]
2063 % \end{macrocode}
2064 % |[...]|: we have just finished gathering the content of a node and
2065 % are about to begin gathering its afterthought. We create a new node
2066 % (and put the content (\dots) into it). If there is no parent node,
2067 % we're done with parsing. Otherwise, we set the newly created
2068 % node to be the ``afterthought node'', i.e.\ the node that will
2069 % receive the next afterthought, change into the afterthought mode,
2070 % and continue parsing.
2071 % \begin{macrocode}
2072 \@escapeif{%
2073 \bracket@createNode
2074 \ifnum\bracket@parentNode=0
2075 \@escapeif\bracketEndParsingHook
2076 \else
2077 \@escapeif{%
2078 \let\bracket@afterthoughtNode\bracket@newNode
2079 \let\bracket@state\bracket@state@inAfterthought
2080 \forest@node@Append{\bracket@parentNode}{\bracket@newNode}%
2081 \bracket@Parse
2082 }%
2083 \fi
2084 }%
2085 \or % in afterthought ] ... ]
2086 % \end{macrocode}
2087 % |]...]|: we have finished gathering an afterthought of some node and
2088 % will begin gathering the afterthought of its parent. We first add
2089 % the afterthought to the afterthought node and set the current parent
2090 % to be the next afterthought node. We change the parent to the
2091 % current parent's parent and check if that node is null. If it is,
2092 % we're done with parsing (ignore the trailing spaces), otherwise we continue.
2093 % \begin{macrocode}
2094 \@escapeif{%
2095 \bracket@addAfterthought
2096 \let\bracket@afterthoughtNode\bracket@parentNode
2097 \edef\bracket@parentNode{\forestOve{\bracket@parentNode}{@parent}}%
2098 \ifnum\bracket@parentNode=0
2099 \expandafter\bracketEndParsingHook
2100 \else
2101 \expandafter\bracket@Parse
2102 \fi
2103 }%
2104 \else % starting
2105 % \end{macrocode}
2106 % |{start}...]|: something's obviously wrong with the input here\dots
2107 % \begin{macrocode}
2108 \PackageError{forest}{You're attempting to start a bracket representation
2109 with a closing bracket}{}%
2110 \fi
2111 }
2112 % \end{macrocode}
2113 %
2114 % The action character code. What happens is determined by the next token.
2115 % \begin{macrocode}
2116 \def\bracket@Parse@actionCharacterFound{%
2117 % \end{macrocode}
2118 % If a braced expression follows, its contents will be fully expanded.
2119 % \begin{macrocode}
2120 \ifx\bracket@next@token\bgroup\@escapeif{%
2121 \bracket@Parse@action@expandgroup
2122 }\else\@escapeif{%
2123 \bracket@Parse@action@notagroup
2124 }\fi
2125 }
2126 \def\bracket@Parse@action@expandgroup#1{%
2127 \edef\bracket@Parse@action@expandgroup@macro{#1}%
2128 \expandafter\bracket@Parse\bracket@Parse@action@expandgroup@macro
2129 }
2130 \let\bracket@action@fullyexpandCharacter+
2131 \let\bracket@action@dontexpandCharacter-
2132 \let\bracket@action@executeCharacter!
2133 \def\bracket@Parse@action@notagroup#1{%
2134 % \end{macrocode}
2135 % If + follows, tokens will be fully expanded from this point on.
2136 % \begin{macrocode}
2137 \ifx#1\bracket@action@fullyexpandCharacter\@escapeif{%
2138 \bracket@expandtokenstrue\bracket@Parse
2139 }\else\@escapeif{%
2140 % \end{macrocode}
2141 % If - follows, tokens will not be expanded from this point on. (This is the default behaviour.)
2142 % \begin{macrocode}
2143 \ifx#1\bracket@action@dontexpandCharacter\@escapeif{%
2144 \bracket@expandtokensfalse\bracket@Parse
2145 }\else\@escapeif{%
2146 % \end{macrocode}
2147 % Inhibit expansion of the next token.
2148 % \begin{macrocode}
2149 \ifx#10\@escapeif{%
2150 \bracket@Parse@appendToken
2151 }\else\@escapeif{%
2152 % \end{macrocode}
2153 % If another action characted follows, we yield the control. The user is
2154 % expected to resume the parser manually, using |\bracketResume|.
2155 % \begin{macrocode}
2156 \ifx#1\bracket@actionCharacter
2157 \else\@escapeif{%
2158 % \end{macrocode}
2159 % Anything else will be expanded once.
2160 % \begin{macrocode}
2161 \expandafter\bracket@Parse#1%
2162 }\fi
2163 }\fi
2164 }\fi
2165 }\fi
2166 }
2167 % \end{macrocode}
2168 %
2169 % \subsection{The tree-structure interface}
2170 %
2171 % This macro creates a new node and sets its content (and preamble, if it's a root node). Bracket
2172 % user must define a 3-arg key |/bracket/new node=|\meta{preamble}\meta{node
2173 % specification}\meta{node cs}. User's key must define \meta{node cs} to be a macro holding the
2174 % node's id.
2175 % \begin{macrocode}
2176 \def\bracket@createNode{%
2177 \ifnum\bracket@rootNode=0
2178 % root node
2179 \bracketset{new node/.expanded=%
2180 {\the\bracket@afterthought}%
2181 {\the\bracket@content}%
2182 \noexpand\bracket@newNode
2183 }%
2184 \bracket@afterthought={}%
2185 \let\bracket@rootNode\bracket@newNode
2186 \expandafter\let\bracket@saveRootNodeTo\bracket@newNode
2187 \else
2188 % other nodes
2189 \bracketset{new node/.expanded=%
2190 {}%
2191 {\the\bracket@content}%
2192 \noexpand\bracket@newNode
2193 }%
2194 \fi
2195 \bracket@content={}%
2196 }
2197 % \end{macrocode}
2198 %
2199 % This macro sets the afterthought. Bracket user must define a 2-arg key
2200 % |/bracket/set_afterthought=|\meta{node id}\meta{afterthought}.
2201 % \begin{macrocode}
2202 \def\bracket@addAfterthought{%
2203 \bracketset{%
2204 set afterthought/.expanded={\bracket@afterthoughtNode}{\the\bracket@afterthought}%
2205 }%
2206 \bracket@afterthought={}%
2207 }
2208 % \end{macrocode}
2209 %
2210 %
2211 % \section{Nodes}
2212 %
2213 % Nodes have numeric ids. The node option values of node $n$ are saved in the |\pgfkeys| tree in
2214 % path |/forest/@node/|$n$.
2215 %
2216 % \subsection{Option setting and retrieval}
2217 %
2218 % Macros for retrieving/setting node options of the current node.
2219 % \begin{macrocode}
2220 % full expansion expands precisely to the value
2221 \def\forestov#1{\expandafter\expandonce\csname fRsT\forest@cn/#1\endcsname}
2222 % full expansion expands all the way
2223 \def\forestove#1{\csname fRsT\forest@cn/#1\endcsname}
2224 % full expansion expands to the cs holding the value
2225 \def\forestom#1{\expandonce{\csname fRsT\forest@cn/#1\endcsname}}
2226 \def\forestoget#1#2{\expandafter\let\expandafter#2\csname fRsT\forest@cn/#1\endcsname}
2227 \def\forestolet#1#2{\expandafter\let\csname fRsT\forest@cn/#1\endcsname#2}
2228 % \def\forestocslet#1#2{%
2229 % \edef\forest@marshal{%
2230 % \noexpand\pgfkeyslet{/forest/@node/\forest@cn/#1}{\expandonce{\csname#2\endcsname}}%
2231 % }\forest@marshal
2232 % }
2233 \def\forestoset#1#2{\expandafter\edef\csname fRsT\forest@cn/#1\endcsname{\unexpanded{#2}}}
2234 \def\forestoeset#1%#2
2235 {\expandafter\edef\csname fRsT\forest@cn/#1\endcsname
2236 %{#2}
2237 }
2238 \def\forestoappto#1#2{%
2239 \forestoeset{#1}{\forestov{#1}\unexpanded{#2}}%
2240 }
2241 \def\forestoifdefined#1%#2#3
2242 {%
2243 \ifcsdef{fRsT\forest@cn/#1}%{#2}{#3}%
2244 }
2245 % \end{macrocode}
2246 % User macros for retrieving node options of the current node.
2247 % \begin{macrocode}
2248 \let\forestoption\forestov
2249 \let\foresteoption\forestove
2250 % \end{macrocode}
2251 % Macros for retrieving node options of a node given by its id.
2252 % \begin{macrocode}
2253 \def\forestOv#1#2{\expandafter\expandonce\csname fRsT#1/#2\endcsname}
2254 \def\forestOve#1#2{\csname fRsT#1/#2\endcsname}
2255 % full expansion expands to the cs holding the value
2256 \def\forestOm#1#2{\expandonce{\csname fRsT#1/#2\endcsname}}
2257 \def\forestOget#1#2#3{\expandafter\let\expandafter#3\csname fRsT#1/#2\endcsname}
2258 \def\forestOlet#1#2#3{\expandafter\let\csname fRsT#1/#2\endcsname#3}
2259 % \def\forestOcslet#1#2#3{%
2260 % \edef\forest@marshal{%
2261 % \noexpand\pgfkeyslet{/forest/@node/#1/#2}{\expandonce{\csname#3\endcsname}}%
2262 % }\forest@marshal
2263 % }
2264 \def\forestOset#1#2#3{\expandafter\edef\csname fRsT#1/#2\endcsname{\unexpanded{#3}}}
2265 \def\forestOeset#1#2%#3
2266 {\expandafter\edef\csname fRsT#1/#2\endcsname
2267 % {#3}
2268 }
2269 \def\forestOappto#1#2#3{%
2270 \forestOeset{#1}{#2}{\forestOv{#1}{#2}\unexpanded{#3}}%
2271 }
2272 \def\forestOeappto#1#2#3{%
2273 \forestOeset{#1}{#2}{\forestOv{#1}{#2}#3}%
2274 }
2275 \def\forestOpreto#1#2#3{%
2276 \forestOeset{#1}{#2}{\unexpanded{#3}\forestOv{#1}{#2}}%
2277 }
2278 \def\forestOepreto#1#2#3{%
2279 \forestOeset{#1}{#2}{#3\forestOv{#1}{#2}}%
2280 }
2281 \def\forestOifdefined#1#2%#3#4
2282 {%
2283 \ifcsdef{fRsT#1/#2}%{#3}{#4}%
2284 }
2285 \def\forestOletO#1#2#3#4{% option #2 of node #1 <-- option #4 of node #3
2286 \forestOget{#3}{#4}\forestoption@temp
2287 \forestOlet{#1}{#2}\forestoption@temp}
2288 \def\forestOleto#1#2#3{%
2289 \forestoget{#3}\forestoption@temp
2290 \forestOlet{#1}{#2}\forestoption@temp}
2291 \def\forestoletO#1#2#3{%
2292 \forestOget{#2}{#3}\forestoption@temp
2293 \forestolet{#1}\forestoption@temp}
2294 \def\forestoleto#1#2{%
2295 \forestoget{#2}\forestoption@temp
2296 \forestolet{#1}\forestoption@temp}
2297 % \end{macrocode}
2298 % Macros for retrieving node options given by \meta{relative node name}|.|\meta{option}.
2299 % \begin{macrocode}
2300 \def\forestRNOget#1#2{% #1=rn!option, #2 = receiving cs
2301 \pgfutil@in@{.}{#1}%
2302 \ifpgfutil@in@
2303 \forestRNOget@rn#2#1\forest@END
2304 \else
2305 \forestoget{#1}#2%
2306 \fi
2307 }
2308 \def\forestRNOget@rn#1#2.#3\forest@END{%
2309 \forest@forthis{%
2310 \forest@nameandgo{#2}%
2311 \forestoget{#3}#1%
2312 }%
2313 }
2314 \def\forestRNO@getvalueandtype#1#2#3{% #1=rn.option, #2,#3 = receiving css
2315 \pgfutil@in@{.}{#1}%
2316 \ifpgfutil@in@
2317 \forestRNO@getvalueandtype@rn#2#3#1\forest@END
2318 \else
2319 \forestoget{#1}#2%
2320 \pgfkeysgetvalue{/forest/#1/@type}#3%
2321 \fi
2322 }
2323 \def\forestRNO@getvalueandtype@rn#1#2#3.#4\forest@END{%
2324 % #1,#2=receiving css, #3=relative node name, #4=option name
2325 \forest@forthis{%
2326 \forest@nameandgo{#3}%
2327 \forestoget{#4}#1%
2328 }%
2329 \pgfkeysgetvalue{/forest/#4/@type}#2%
2330 }
2331 % \end{macrocode}
2332 % Macros for retrieving/setting registers.
2333 % \begin{macrocode}
2334 % full expansion expands precisely to the value
2335 \def\forestrv#1{\expandafter\expandonce\csname fRsT/#1\endcsname}
2336 % full expansion expands all the way
2337 \def\forestrve#1{\csname fRsT/#1\endcsname}
2338 % full expansion expands to the cs holding the value
2339 \def\forestrm#1{\expandonce{\csname fRsT/#1\endcsname}}
2340 \def\forestrget#1#2{\expandafter\let\expandafter#2\csname fRsT/#1\endcsname}
2341 \def\forestrlet#1#2{\expandafter\let\csname fRsT/#1\endcsname#2}
2342 % \def\forestrcslet#1#2{%
2343 % \edef\forest@marshal{%
2344 % \noexpand\pgfkeyslet{/forest/@node/register/#1}{\expandonce{\csname#2\endcsname}}%
2345 % }\forest@marshal
2346 % }
2347 \def\forestrset#1#2{\expandafter\edef\csname fRsT/#1\endcsname{\unexpanded{#2}}}
2348 \def\forestreset#1%#2
2349 {\expandafter\edef\csname fRsT/#1\endcsname}%{#2}
2350 \def\forestrappto#1#2{%
2351 \forestreset{#1}{\forestrv{#1}\unexpanded{#2}}%
2352 }
2353 \def\forestrpreto#1#2{%
2354 \forestreset{#1}{\unexpanded{#2}\forestrv{#1}}%
2355 }
2356 \def\forestrifdefined#1%#2#3
2357 {%
2358 \ifcsdef{fRsT/#1}%{#2}{#3}%
2359 }
2360 % \end{macrocode}
2361 % User macros for retrieving node options of the current node.
2362 % \begin{macrocode}
2363 \def\forestregister#1{\forestrv{#1}}
2364 \def\foresteregister#1{\forestrve{#1}}
2365 % \end{macrocode}
2366 % Node initialization. Node option declarations append to |\forest@node@init|.
2367 % \begin{macrocode}
2368 \def\forest@node@init{%
2369 \forestoset{@parent}{0}%
2370 \forestoset{@previous}{0}% previous sibling
2371 \forestoset{@next}{0}% next sibling
2372 \forestoset{@first}{0}% primary child
2373 \forestoset{@last}{0}% last child
2374 }
2375 \def\forestoinit#1{%
2376 \pgfkeysgetvalue{/forest/#1}\forestoinit@temp
2377 \forestolet{#1}\forestoinit@temp
2378 }
2379 \newcount\forest@node@maxid
2380 \def\forest@node@new#1{% #1 = cs receiving the new node id
2381 \advance\forest@node@maxid1
2382 \forest@fornode{\the\forest@node@maxid}{%
2383 \forest@node@init
2384 \forestoeset{id}{\forest@cn}%
2385 \forest@node@setname{node@\forest@cn}%
2386 \forest@initializefromstandardnode
2387 \edef#1{\forest@cn}%
2388 }%
2389 }
2390 \let\forestoinit@orig\forestoinit
2391 \def\forest@node@copy#1#2{% #1=from node id, cs receiving the new node id
2392 \advance\forest@node@maxid1
2393 \def\forestoinit##1{\ifstrequal{##1}{name}{\forestoset{name}{node@\forest@cn}}{\forestoletO{##1}{#1}{##1}}}%
2394 \forest@fornode{\the\forest@node@maxid}{%
2395 \forest@node@init
2396 \forestoeset{id}{\forest@cn}%
2397 \forest@node@setname{\forest@copy@name@template{\forestOve{#1}{name}}}%
2398 \edef#2{\forest@cn}%
2399 }%
2400 \let\forestoinit\forestoinit@orig
2401 }
2402 \forestset{
2403 copy name template/.code={\def\forest@copy@name@template##1{#1}},
2404 copy name template/.default={node@\the\forest@node@maxid},
2405 copy name template
2406 }
2407 \def\forest@tree@copy#1#2{% #1=from node id, #2=cs receiving the new node id
2408 \forest@node@copy{#1}\forest@node@copy@temp@id
2409 \forest@fornode{\forest@node@copy@temp@id}{%
2410 \expandafter\forest@tree@copy@\expandafter{\forest@node@copy@temp@id}{#1}%
2411 \edef#2{\forest@cn}%
2412 }%
2413 }
2414 \def\forest@tree@copy@#1#2{%
2415 \forest@node@Foreachchild{#2}{%
2416 \expandafter\forest@tree@copy\expandafter{\forest@cn}\forest@node@copy@temp@childid
2417 \forest@node@Append{#1}{\forest@node@copy@temp@childid}%
2418 }%
2419 }
2420 % \end{macrocode}
2421 % Macro |\forest@cn| holds the current node id (a number). Node 0 is a special ``null'' node which
2422 % is used to signal the absence of a node.
2423 % \begin{macrocode}
2424 \def\forest@cn{0}
2425 \forest@node@init
2426 % \end{macrocode}
2427 %
2428 % \subsection{Tree structure}
2429 % Node insertion/removal.
2430 %
2431 % For the lowercase variants, |\forest@cn| is the parent/removed node. For the uppercase variants,
2432 % |#1| is the parent/removed node. For efficiency, the public macros all expand the arguments
2433 % before calling the internal macros.
2434 % \begin{macrocode}
2435 \def\forest@node@append#1{\expandtwonumberargs\forest@node@Append{\forest@cn}{#1}}
2436 \def\forest@node@prepend#1{\expandtwonumberargs\forest@node@Insertafter{\forest@cn}{#1}{0}}
2437 \def\forest@node@insertafter#1#2{%
2438 \expandthreenumberargs\forest@node@Insertafter{\forest@cn}{#1}{#2}}
2439 \def\forest@node@insertbefore#1#2{%
2440 \expandthreenumberargs\forest@node@Insertafter{\forest@cn}{#1}{\forestOve{#2}{@previous}}%
2441 }
2442 \def\forest@node@remove{\expandnumberarg\forest@node@Remove{\forest@cn}}
2443 \def\forest@node@Append#1#2{\expandtwonumberargs\forest@node@Append@{#1}{#2}}
2444 \def\forest@node@Prepend#1#2{\expandtwonumberargs\forest@node@Insertafter{#1}{#2}{0}}
2445 \def\forest@node@Insertafter#1#2#3{% #2 is inserted after #3
2446 \expandthreenumberargs\forest@node@Insertafter@{#1}{#2}{#3}%
2447 }
2448 \def\forest@node@Insertbefore#1#2#3{% #2 is inserted before #3
2449 \expandthreenumberargs\forest@node@Insertafter{#1}{#2}{\forestOve{#3}{@previous}}%
2450 }
2451 \def\forest@node@Remove#1{\expandnumberarg\forest@node@Remove@{#1}}
2452 \def\forest@node@Insertafter@#1#2#3{%
2453 \ifnum\forestOve{#2}{@parent}=0
2454 \else
2455 \PackageError{forest}{Insertafter(#1,#2,#3):
2456 node #2 already has a parent (\forestOve{#2}{@parent})}{}%
2457 \fi
2458 \ifnum#3=0
2459 \else
2460 \ifnum#1=\forestOve{#3}{@parent}
2461 \else
2462 \PackageError{forest}{Insertafter(#1,#2,#3): node #1 is not the parent of the
2463 intended sibling #3 (with parent \forestOve{#3}{@parent})}{}%
2464 \fi
2465 \fi
2466 \forestOeset{#2}{@parent}{#1}%
2467 \forestOeset{#2}{@previous}{#3}%
2468 \ifnum#3=0
2469 \forestOget{#1}{@first}\forest@node@temp
2470 \forestOeset{#1}{@first}{#2}%
2471 \else
2472 \forestOget{#3}{@next}\forest@node@temp
2473 \forestOeset{#3}{@next}{#2}%
2474 \fi
2475 \forestOeset{#2}{@next}{\forest@node@temp}%
2476 \ifnum\forest@node@temp=0
2477 \forestOeset{#1}{@last}{#2}%
2478 \else
2479 \forestOeset{\forest@node@temp}{@previous}{#2}%
2480 \fi
2481 }
2482 \def\forest@node@Append@#1#2{%
2483 \ifnum\forestOve{#2}{@parent}=0
2484 \else
2485 \PackageError{forest}{Append(#1,#2):
2486 node #2 already has a parent (\forestOve{#2}{@parent})}{}%
2487 \fi
2488 \forestOeset{#2}{@parent}{#1}%
2489 \forestOget{#1}{@last}\forest@node@temp
2490 \forestOeset{#1}{@last}{#2}%
2491 \forestOeset{#2}{@previous}{\forest@node@temp}%
2492 \ifnum\forest@node@temp=0
2493 \forestOeset{#1}{@first}{#2}%
2494 \else
2495 \forestOeset{\forest@node@temp}{@next}{#2}%
2496 \fi
2497 }
2498 \def\forest@node@Remove@#1{%
2499 \forestOget{#1}{@parent}\forest@node@temp@parent
2500 \ifnum\forest@node@temp@parent=0
2501 \else
2502 \forestOget{#1}{@previous}\forest@node@temp@previous
2503 \forestOget{#1}{@next}\forest@node@temp@next
2504 \ifnum\forest@node@temp@previous=0
2505 \forestOeset{\forest@node@temp@parent}{@first}{\forest@node@temp@next}%
2506 \else
2507 \forestOeset{\forest@node@temp@previous}{@next}{\forest@node@temp@next}%
2508 \fi
2509 \ifnum\forest@node@temp@next=0
2510 \forestOeset{\forest@node@temp@parent}{@last}{\forest@node@temp@previous}%
2511 \else
2512 \forestOeset{\forest@node@temp@next}{@previous}{\forest@node@temp@previous}%
2513 \fi
2514 \forestOset{#1}{@parent}{0}%
2515 \forestOset{#1}{@previous}{0}%
2516 \forestOset{#1}{@next}{0}%
2517 \fi
2518 }
2519 % \end{macrocode}
2520 % Do some stuff and return to the current node.
2521 % \begin{macrocode}
2522 \def\forest@forthis#1{%
2523 \edef\forest@node@marshal{\unexpanded{#1}\def\noexpand\forest@cn}%
2524 \expandafter\forest@node@marshal\expandafter{\forest@cn}%
2525 }
2526 \def\forest@fornode#1#2{%
2527 \edef\forest@node@marshal{\edef\noexpand\forest@cn{#1}\unexpanded{#2}\def\noexpand\forest@cn}%
2528 \expandafter\forest@node@marshal\expandafter{\forest@cn}%
2529 }
2530 % \end{macrocode}
2531 % Looping methods: children.
2532 % \begin{macrocode}
2533 \def\forest@node@foreachchild#1{\forest@node@Foreachchild{\forest@cn}{#1}}
2534 \def\forest@node@Foreachchild#1#2{%
2535 \forest@fornode{\forestOve{#1}{@first}}{\forest@node@@forselfandfollowingsiblings{#2}}%
2536 }
2537 \def\forest@node@@forselfandfollowingsiblings#1{%
2538 \ifnum\forest@cn=0
2539 \else
2540 \forest@forthis{#1}%
2541 \@escapeif{%
2542 \edef\forest@cn{\forestove{@next}}%
2543 \forest@node@@forselfandfollowingsiblings{#1}%
2544 }%
2545 \fi
2546 }
2547 \def\forest@node@@forselfandfollowingsiblings@reversed#1{%
2548 \ifnum\forest@cn=0
2549 \else
2550 \@escapeif{%
2551 \edef\forest@marshal{%
2552 \noexpand\def\noexpand\forest@cn{\forestove{@next}}%
2553 \noexpand\forest@node@@forselfandfollowingsiblings@reversed{\unexpanded{#1}}%
2554 \noexpand\forest@fornode{\forest@cn}{\unexpanded{#1}}%
2555 }\forest@marshal
2556 }%
2557 \fi
2558 }
2559 \def\forest@node@foreachchild@reversed#1{\forest@node@Foreachchild@reversed{\forest@cn}{#1}}
2560 \def\forest@node@Foreachchild@reversed#1#2{%
2561 \forest@fornode{\forestOve{#1}{@last}}{\forest@node@@forselfandprecedingsiblings@reversed{#2}}%
2562 }
2563 \def\forest@node@@forselfandprecedingsiblings@reversed#1{%
2564 \ifnum\forest@cn=0
2565 \else
2566 \forest@forthis{#1}%
2567 \@escapeif{%
2568 \edef\forest@cn{\forestove{@previous}}%
2569 \forest@node@@forselfandprecedingsiblings@reversed{#1}%
2570 }%
2571 \fi
2572 }
2573 \def\forest@node@@forselfandprecedingsiblings#1{%
2574 \ifnum\forest@cn=0
2575 \else
2576 \@escapeif{%
2577 \edef\forest@marshal{%
2578 \noexpand\def\noexpand\forest@cn{\forestove{@previous}}%
2579 \noexpand\forest@node@@forselfandprecedingsiblings{\unexpanded{#1}}%
2580 \noexpand\forest@fornode{\forest@cn}{\unexpanded{#1}}%
2581 }\forest@marshal
2582 }%
2583 \fi
2584 }
2585 % \end{macrocode}
2586 % Looping methods: (sub)tree and descendants.
2587 % \begin{macrocode}
2588 \def\forest@node@@foreach#1#2#3#4{%
2589 % #1 = do what
2590 % #2 = do that -1=before,1=after processing children
2591 % #3 & #4: normal or reversed order of children?
2592 % #3 = @first/@last
2593 % #4 = \forest@node@@forselfandfollowingsiblings / \forest@node@@forselfandprecedingsiblings@reversed
2594 \ifnum#2<0 \forest@forthis{#1}\fi
2595 \ifnum\forestove{#3}=0
2596 \else\@escapeif{%
2597 \forest@forthis{%
2598 \edef\forest@cn{\forestove{#3}}%
2599 #4{\forest@node@@foreach{#1}{#2}{#3}{#4}}%
2600 }%
2601 }\fi
2602 \ifnum#2>0 \forest@forthis{#1}\fi
2603 }
2604 \def\forest@node@foreach#1{%
2605 \forest@node@@foreach{#1}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}
2606 \def\forest@node@Foreach#1#2{%
2607 \forest@fornode{#1}{\forest@node@@foreach{#2}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
2608 \def\forest@node@foreach@reversed#1{%
2609 \forest@node@@foreach{#1}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}
2610 \def\forest@node@Foreach@reversed#1#2{%
2611 \forest@fornode{#1}{\forest@node@@foreach{#2}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
2612 \def\forest@node@foreach@childrenfirst#1{%
2613 \forest@node@@foreach{#1}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}
2614 \def\forest@node@Foreach@childrenfirst#1#2{%
2615 \forest@fornode{#1}{\forest@node@@foreach{#2}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
2616 \def\forest@node@foreach@childrenfirst@reversed#1{%
2617 \forest@node@@foreach{#1}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}
2618 \def\forest@node@Foreach@childrenfirst@reversed#1#2{%
2619 \forest@fornode{#1}{\forest@node@@foreach{#2}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
2620 \def\forest@node@foreachdescendant#1{%
2621 \forest@node@foreachchild{\forest@node@@foreach{#1}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
2622 \def\forest@node@Foreachdescendant#1#2{%
2623 \forest@node@Foreachchild{#1}{\forest@node@@foreach{#2}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
2624 \def\forest@node@foreachdescendant@reversed#1{%
2625 \forest@node@foreachchild@reversed{\forest@node@@foreach{#1}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
2626 \def\forest@node@Foreachdescendant@reversed#1#2{%
2627 \forest@node@Foreachchild@reversed{#1}{\forest@node@@foreach{#2}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
2628 \def\forest@node@foreachdescendant@childrenfirst#1{%
2629 \forest@node@foreachchild{\forest@node@@foreach{#1}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
2630 \def\forest@node@Foreachdescendant@childrenfirst#1#2{%
2631 \forest@node@Foreachchild{#1}{\forest@node@@foreach{#2}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
2632 \def\forest@node@foreachdescendant@childrenfirst@reversed#1{%
2633 \forest@node@foreachchild@reversed{\forest@node@@foreach{#1}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
2634 \def\forest@node@Foreachdescendant@childrenfirst@reversed#1#2{%
2635 \forest@node@Foreachchild@reversed{#1}{\forest@node@@foreach{#2}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
2636 % \end{macrocode}
2637 % Looping methods: breadth-first.
2638 % \begin{macrocode}
2639 \def\forest@node@foreach@breadthfirst#1#2{% #1 = max level, #2 = code
2640 \forest@node@Foreach@breadthfirst@{\forest@cn}{@first}{@next}{#1}{#2}}
2641 \def\forest@node@foreach@breadthfirst@reversed#1#2{% #1 = max level, #2 = code
2642 \forest@node@Foreach@breadthfirst@{\forest@cn}{@last}{@previous}{#1}{#2}}
2643 \def\forest@node@Foreach@breadthfirst#1#2#3{% #1 = node id, #2 = max level, #3 = code
2644 \forest@node@Foreach@breadthfirst@{#1}{@first}{@next}{#2}{#3}}
2645 \def\forest@node@Foreach@breadthfirst@reversed#1#2#3{% #1 = node id, #2 = max level, #3 = code
2646 \forest@node@Foreach@breadthfirst@{#1}{@last}{@previous}{#2}{#3}}
2647 \def\forest@node@Foreach@breadthfirst@#1#2#3#4#5{%
2648 % #1 = root node,
2649 % #2 = @first/@last, #3 = @next/@previous (must be in sync with #2),
2650 % #4 = max level (< 0 means infinite)
2651 % #5 = code to execute at each node
2652 \forest@node@Foreach@breadthfirst@processqueue{#1,}{#2}{#3}{#4}{#5}%
2653 }
2654 \def\forest@node@Foreach@breadthfirst@processqueue#1#2#3#4#5{%
2655 % #1 = queue,
2656 % #2 = @first/@last, #3 = @next/@previous (must be in sync with #2),
2657 % #4 = max level (< 0 means infinite)
2658 % #5 = code to execute at each node
2659 \ifstrempty{#1}{}{%
2660 \forest@node@Foreach@breadthfirst@processqueue@#1\forest@node@Foreach@breadthfirst@processqueue@
2661 {#2}{#3}{#4}{#5}%
2662 }%
2663 }
2664 \def\forest@node@Foreach@breadthfirst@processqueue@#1,#2\forest@node@Foreach@breadthfirst@processqueue@#3#4#5#6{%
2665 % #1 = first,
2666 % #2 = rest,
2667 % #3 = @first/@last, #4 = next/previous (must be in sync with #2),
2668 % #5 = max level (< 0 means infinite)
2669 % #6 = code to execute at each node
2670 \forest@fornode{#1}{%
2671 #6%
2672 \ifnum#5<0
2673 \forest@node@getlistofchildren\forest@temp{#3}{#4}%
2674 \else
2675 \ifnum\forestove{level}>#5\relax
2676 \def\forest@temp{}%
2677 \else
2678 \forest@node@getlistofchildren\forest@temp{#3}{#4}%
2679 \fi
2680 \fi
2681 \edef\forest@marshal{%
2682 \noexpand\forest@node@Foreach@breadthfirst@processqueue{\unexpanded{#2}\forest@temp}%
2683 {#3}{#4}{#5}{\unexpanded{#6}}%
2684 }\forest@marshal
2685 }%
2686 }
2687 \def\forest@node@getlistofchildren#1#2#3{% #1 = list cs, #2 = @first/@last, #3 = @next/@previous
2688 \forest@node@Getlistofchildren{\forest@cn}{#1}{#2}{#3}%
2689 }
2690 \def\forest@node@Getlistofchildren#1#2#3#4{% #1 = node, #2 = list cs, #3 = @first/@last, #4 = @next/@previous
2691 \def#2{}%
2692 \ifnum\forestove{#3}=0
2693 \else
2694 \eappto#2{\forestOve{#1}{#3},}%
2695 \@escapeif{%
2696 \edef\forest@marshal{%
2697 \noexpand\forest@node@Getlistofchildren@{\forestOve{#1}{#3}}\noexpand#2{#4}%
2698 }\forest@marshal
2699 }%
2700 \fi
2701 }
2702 \def\forest@node@Getlistofchildren@#1#2#3{% #1 = node, #2 = list cs, #3 = @next/@previous
2703 \ifnum\forestOve{#1}{#3}=0
2704 \else
2705 \eappto#2{\forestOve{#1}{#3},}%
2706 \@escapeif{%
2707 \edef\forest@marshal{%
2708 \noexpand\forest@node@Getlistofchildren@{\forestOve{#1}{#3}}\noexpand#2{#3}%
2709 }\forest@marshal
2710 }%
2711 \fi
2712 }
2713 % \end{macrocode}
2714 %
2715 % Compute |n|, |n'|, |n children| and |level|.
2716 % \begin{macrocode}
2717 \def\forest@node@Compute@numeric@ts@info@#1{%
2718 \forest@node@Foreach{#1}{\forest@node@@compute@numeric@ts@info}%
2719 \ifnum\forestOve{#1}{@parent}=0
2720 \else
2721 \forest@fornode{#1}{\forest@node@@compute@numeric@ts@info@nbar}%
2722 % hack: the parent of the node we called the update for gets +1 for n_children
2723 \edef\forest@node@temp{\forestOve{#1}{@parent}}%
2724 \forestOeset{\forest@node@temp}{n children}{%
2725 \number\numexpr\forestOve{\forest@node@temp}{n children}-1%
2726 }%
2727 \fi
2728 \forest@node@Foreachdescendant{#1}{\forest@node@@compute@numeric@ts@info@nbar}%
2729 }
2730 \def\forest@node@@compute@numeric@ts@info{%
2731 \forestoset{n children}{0}%
2732 %
2733 \edef\forest@node@temp{\forestove{@previous}}%
2734 \ifnum\forest@node@temp=0
2735 \forestoset{n}{1}%
2736 \else
2737 \forestoeset{n}{\number\numexpr\forestOve{\forest@node@temp}{n}+1}%
2738 \fi
2739 %
2740 \edef\forest@node@temp{\forestove{@parent}}%
2741 \ifnum\forest@node@temp=0
2742 \forestoset{n}{0}%
2743 \forestoset{n'}{0}%
2744 \forestoset{level}{0}%
2745 \else
2746 \forestOeset{\forest@node@temp}{n children}{%
2747 \number\numexpr\forestOve{\forest@node@temp}{n children}+1%
2748 }%
2749 \forestoeset{level}{%
2750 \number\numexpr\forestOve{\forest@node@temp}{level}+1%
2751 }%
2752 \fi
2753 }
2754 \def\forest@node@@compute@numeric@ts@info@nbar{%
2755 \forestoeset{n'}{\number\numexpr\forestOve{\forestove{@parent}}{n children}-\forestove{n}+1}%
2756 }
2757 \def\forest@node@compute@numeric@ts@info#1{%
2758 \expandnumberarg\forest@node@Compute@numeric@ts@info@{\forest@cn}%
2759 }
2760 \def\forest@node@Compute@numeric@ts@info#1{%
2761 \expandnumberarg\forest@node@Compute@numeric@ts@info@{#1}%
2762 }
2763 % \end{macrocode}
2764 %
2765 % Tree structure queries.
2766 % \begin{macrocode}
2767 \def\forest@node@rootid{%
2768 \expandnumberarg\forest@node@Rootid{\forest@cn}%
2769 }
2770 \def\forest@node@Rootid#1{% #1=node
2771 \ifnum\forestOve{#1}{@parent}=0
2772 #1%
2773 \else
2774 \@escapeif{\expandnumberarg\forest@node@Rootid{\forestOve{#1}{@parent}}}%
2775 \fi
2776 }
2777 \def\forest@node@nthchildid#1{% #1=n
2778 \ifnum#1<1
2779 0%
2780 \else
2781 \expandnumberarg\forest@node@nthchildid@{\number\forestove{@first}}{#1}%
2782 \fi
2783 }
2784 \def\forest@node@nthchildid@#1#2{%
2785 \ifnum#1=0
2786 0%
2787 \else
2788 \ifnum#2>1
2789 \@escapeifif{\expandtwonumberargs
2790 \forest@node@nthchildid@{\forestOve{#1}{@next}}{\numexpr#2-1}}%
2791 \else
2792 #1%
2793 \fi
2794 \fi
2795 }
2796 \def\forest@node@nbarthchildid#1{% #1=n
2797 \expandnumberarg\forest@node@nbarthchildid@{\number\forestove{@last}}{#1}%
2798 }
2799 \def\forest@node@nbarthchildid@#1#2{%
2800 \ifnum#1=0
2801 0%
2802 \else
2803 \ifnum#2>1
2804 \@escapeifif{\expandtwonumberargs
2805 \forest@node@nbarthchildid@{\forestOve{#1}{@previous}}{\numexpr#2-1}}%
2806 \else
2807 #1%
2808 \fi
2809 \fi
2810 }
2811 \def\forest@node@nornbarthchildid#1{%
2812 \ifnum#1>0
2813 \forest@node@nthchildid{#1}%
2814 \else
2815 \ifnum#1<0
2816 \forest@node@nbarthchildid{-#1}%
2817 \else
2818 \forest@node@nornbarthchildid@error
2819 \fi
2820 \fi
2821 }
2822 \def\forest@node@nornbarthchildid@error{%
2823 \PackageError{forest}{In \string\forest@node@nornbarthchildid, n should !=0}{}%
2824 }
2825 \def\forest@node@previousleafid{%
2826 \expandnumberarg\forest@node@Previousleafid{\forest@cn}%
2827 }
2828 \def\forest@node@Previousleafid#1{%
2829 \ifnum\forestOve{#1}{@previous}=0
2830 \@escapeif{\expandnumberarg\forest@node@previousleafid@Goup{#1}}%
2831 \else
2832 \expandnumberarg\forest@node@previousleafid@Godown{\forestOve{#1}{@previous}}%
2833 \fi
2834 }
2835 \def\forest@node@previousleafid@Goup#1{%
2836 \ifnum\forestOve{#1}{@parent}=0
2837 \PackageError{forest}{get previous leaf: this is the first leaf}{}%
2838 \else
2839 \@escapeif{\expandnumberarg\forest@node@Previousleafid{\forestOve{#1}{@parent}}}%
2840 \fi
2841 }
2842 \def\forest@node@previousleafid@Godown#1{%
2843 \ifnum\forestOve{#1}{@last}=0
2844 #1%
2845 \else
2846 \@escapeif{\expandnumberarg\forest@node@previousleafid@Godown{\forestOve{#1}{@last}}}%
2847 \fi
2848 }
2849 \def\forest@node@nextleafid{%
2850 \expandnumberarg\forest@node@Nextleafid{\forest@cn}%
2851 }
2852 \def\forest@node@Nextleafid#1{%
2853 \ifnum\forestOve{#1}{@next}=0
2854 \@escapeif{\expandnumberarg\forest@node@nextleafid@Goup{#1}}%
2855 \else
2856 \expandnumberarg\forest@node@nextleafid@Godown{\forestOve{#1}{@next}}%
2857 \fi
2858 }
2859 \def\forest@node@nextleafid@Goup#1{%
2860 \ifnum\forestOve{#1}{@parent}=0
2861 \PackageError{forest}{get next leaf: this is the last leaf}{}%
2862 \else
2863 \@escapeif{\expandnumberarg\forest@node@Nextleafid{\forestOve{#1}{@parent}}}%
2864 \fi
2865 }
2866 \def\forest@node@nextleafid@Godown#1{%
2867 \ifnum\forestOve{#1}{@first}=0
2868 #1%
2869 \else
2870 \@escapeif{\expandnumberarg\forest@node@nextleafid@Godown{\forestOve{#1}{@first}}}%
2871 \fi
2872 }
2873
2874
2875
2876 \def\forest@node@linearnextid{%
2877 \ifnum\forestove{@first}=0
2878 \expandafter\forest@node@linearnextnotdescendantid
2879 \else
2880 \forestove{@first}%
2881 \fi
2882 }
2883 \def\forest@node@linearnextnotdescendantid{%
2884 \expandnumberarg\forest@node@Linearnextnotdescendantid{\forest@cn}%
2885 }
2886 \def\forest@node@Linearnextnotdescendantid#1{%
2887 \ifnum\forestOve{#1}{@next}=0
2888 \ifnum\forestOve{#1}{@parent}=0
2889 0%
2890 \else
2891 \@escapeifif{\expandnumberarg\forest@node@Linearnextnotdescendantid{\forestOve{#1}{@parent}}}%
2892 \fi
2893 \else
2894 \forestOve{#1}{@next}%
2895 \fi
2896 }
2897 \def\forest@node@linearpreviousid{%
2898 \ifnum\forestove{@previous}=0
2899 \forestove{@parent}%
2900 \else
2901 \forest@node@previousleafid
2902 \fi
2903 }
2904 % \end{macrocode}
2905 % Test if the current node is an ancestor the node given by its id in the first argument. The code graciously deals with circular trees. The second and third argument (not formally present) are the true and the false case code.
2906 % \begin{macrocode}
2907
2908 \def\forest@ifancestorof#1{% is the current node an ancestor of #1? Yes: #2, no: #3
2909 \begingroup
2910 \expandnumberarg\forest@ifancestorof@{\forestOve{#1}{@parent}}%
2911 }
2912 \def\forest@ifancestorof@#1{%
2913 \ifnum#1=0
2914 \def\forest@ifancestorof@next{\expandafter\endgroup\@secondoftwo}%
2915 \else
2916 \ifnum\forest@cn=#1
2917 \def\forest@ifancestorof@next{\expandafter\endgroup\@firstoftwo}%
2918 \else
2919 \ifcsdef{forest@circularity@used#1}{%
2920 % \end{macrocode}
2921 % We have just detected circularity: the potential descendant is in fact an ancestor of itself. Our answer is ``false'': the current node is not an ancestor of the potential descendant.
2922 % \begin{macrocode}
2923 \def\forest@ifancestorof@next{\expandafter\endgroup\@secondoftwo}%
2924 }{%
2925 \csdef{forest@circularity@used#1}{}%
2926 \def\forest@ifancestorof@next{\expandnumberarg\forest@ifancestorof@{\forestOve{#1}{@parent}}}%
2927 }%
2928 \fi
2929 \fi
2930 \forest@ifancestorof@next
2931 }
2932 % \end{macrocode}
2933 % A debug tool which prints out the hierarchy of all nodes.
2934 % \begin{macrocode}
2935 \NewDocumentCommand\forestdebugtypeouttrees{o}{%
2936 \forestdebug@typeouttrees\forest@temp
2937 \typeout{%
2938 \forestdebugtypeouttreesprefix
2939 \IfValueTF{#1}{#1: }{}%
2940 \detokenize\expandafter{\forest@temp}%
2941 \forestdebugtypeouttreessuffix
2942 }%
2943 }
2944 \def\forestdebug@typeouttrees#1{% #1 = cs to store the result
2945 \begingroup
2946 \edef\forest@temp@message{}%
2947 \def\forestdebug@typeouttrees@n{0}%
2948 % \end{macrocode}
2949 % Loop through all known ids. When finding a node that has not been visited yet (probably as a part of a previous tree), find its root and typeout the root's tree.
2950 % \begin{macrocode}
2951 \loop
2952 \ifnum\forestdebug@typeouttrees@n<\forest@node@maxid
2953 \edef\forestdebug@typeouttrees@n{\number\numexpr\forestdebug@typeouttrees@n+1}%
2954 \ifcsdef{forestdebug@typeouttree@used@\forestdebug@typeouttrees@n}{}{%
2955 \forest@fornode{\forestdebug@typeouttrees@n}{%
2956 % \end{macrocode}
2957 % After finding the root, we need to restore our notes about visited nodes.
2958 % \begin{macrocode}
2959 \begingroup
2960 \forestdebug@typeouttrees@findroot
2961 \expandafter\endgroup
2962 \expandafter\edef\expandafter\forest@cn\expandafter{\forest@cn}%
2963 \forestdebug@typeouttree@build
2964 \appto\forest@temp@message{ }%
2965 }%
2966 }%
2967 \repeat
2968 \expandafter\endgroup
2969 \expandafter\def\expandafter#1\expandafter{\forest@temp@message}%
2970 }
2971 \def\forestdebug@typeouttrees@findroot{%
2972 \let\forestdebug@typeouttrees@next\relax
2973 \edef\forestdebug@typeouttrees@parent{\forestOve{\forest@cn}{@parent}}%
2974 \ifnum\forestdebug@typeouttrees@parent=0
2975 \else
2976 \ifcsdef{forestdebug@typeouttree@used@\forest@cn}{}{%
2977 \csdef{forestdebug@typeouttree@used@\forest@cn}{}%
2978 \edef\forest@cn{\forestdebug@typeouttrees@parent}%
2979 \let\forestdebug@typeouttrees@next\forestdebug@typeouttrees@findroot
2980 }%
2981 \fi
2982 \forestdebug@typeouttrees@next
2983 }
2984 \def\forestdebug@typeouttree#1#2{% #1=root id, #2=cs to receive result
2985 \begingroup
2986 \edef\forest@temp@message{}%
2987 \forest@fornode{#1}{\forestdebug@typeouttree@build}%
2988 \expandafter\endgroup
2989 \expandafter\edef\expandafter#2\expandafter{\forest@temp@message}%
2990 }
2991 \NewDocumentCommand\forestdebugtypeouttree{d() O{\forest@cn}}{%
2992 \forestdebug@typeouttree{#2}\forest@temp
2993 \typeout{\IfValueTF{#1}{#1: }{}\forest@temp}%
2994 }
2995 % \end{macrocode}
2996 % Recurse through the tree. If a circularity is detected, mark it with |*| and stop recursion.
2997 % \begin{macrocode}
2998 \def\forestdebug@typeouttree@build{%
2999 \eappto\forest@temp@message{[\forestdebugtypeouttreenodeinfo%]
3000 \ifcsdef{forestdebug@typeouttree@used@\forest@cn}{*}{}%
3001 }%
3002 \ifcsdef{forestdebug@typeouttree@used@\forest@cn}{}{%
3003 \csdef{forestdebug@typeouttree@used@\forest@cn}{}%
3004 \forest@node@foreachchild{\forestdebug@typeouttree@build}%
3005 }%
3006 \eappto\forest@temp@message{%[
3007 ]}%
3008 }
3009 \def\forestdebugtypeouttreenodeinfo{\forest@cn}
3010 \def\forestdebugtypeouttreesprefix{}
3011 \def\forestdebugtypeouttreessuffix{}
3012 % \end{macrocode}
3013 %
3014 %
3015 % \subsection{Node options}
3016 %
3017 % \subsubsection{Option-declaration mechanism}
3018 %
3019 % Common code for declaring options.
3020 % \begin{macrocode}
3021 \def\forest@declarehandler#1#2#3{%#1=handler for specific type,#2=option name,#3=default value
3022 \pgfkeyssetvalue{/forest/#2}{#3}%
3023 \appto\forest@node@init{\forestoinit{#2}}%
3024 \pgfkeyssetvalue{/forest/#2/node@or@reg}{\forest@cn}%
3025 \forest@convert@others@to@underscores{#2}\forest@pgfmathoptionname
3026 \edef\forest@marshal{%
3027 \noexpand#1{/forest/#2}{/forest}{#2}{\forest@pgfmathoptionname}%
3028 }\forest@marshal
3029 }
3030 \def\forest@def@with@pgfeov#1#2{% \pgfeov mustn't occur in the arg of the .code handler!!!
3031 \long\def#1##1\pgfeov{#2}%
3032 }
3033 % \end{macrocode}
3034 % Option-declaration handlers.
3035 % \begin{macrocode}
3036 \def\forest@declaretoks@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
3037 \forest@declaretoks@handler@A{#1}{#2}{#3}{#4}{}%
3038 }
3039 \def\forest@declarekeylist@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
3040 \forest@declaretoks@handler@A{#1}{#2}{#3}{#4}{,}%
3041 \forest@copycommandkey{#1}{#1'}%
3042 \pgfkeyssetvalue{#1'/option@name}{#3}%
3043 \forest@copycommandkey{#1+}{#1}%
3044 \pgfkeysalso{#1-/.code={%
3045 \forest@fornode{\forest@setter@node}{%
3046 \forest@node@removekeysfromkeylist{##1}{#3}%
3047 }}}%
3048 \pgfkeyssetvalue{#1-/option@name}{#3}%
3049 }
3050 \def\forest@declaretoks@handler@A#1#2#3#4#5{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
3051 \pgfkeysalso{%
3052 #1/.code={\forestOset{\forest@setter@node}{#3}{##1}},
3053 #2/if #3/.code n args={3}{%
3054 \forestoget{#3}\forest@temp@option@value
3055 \edef\forest@temp@compared@value{\unexpanded{##1}}%
3056 \ifx\forest@temp@option@value\forest@temp@compared@value
3057 \pgfkeysalso{##2}%
3058 \else
3059 \pgfkeysalso{##3}%
3060 \fi
3061 },
3062 #2/if in #3/.code n args={3}{%
3063 \forestoget{#3}\forest@temp@option@value
3064 \edef\forest@temp@compared@value{\unexpanded{##1}}%
3065 \expandafter\expandafter\expandafter\pgfutil@in@\expandafter\expandafter\expandafter{\expandafter\forest@temp@compared@value\expandafter}\expandafter{\forest@temp@option@value}%
3066 \ifpgfutil@in@
3067 \pgfkeysalso{##2}%
3068 \else
3069 \pgfkeysalso{##3}%
3070 \fi
3071 },
3072 #2/where #3/.style n args={3}{for tree={#2/if #3={##1}{##2}{##3}}},
3073 #2/where in #3/.style n args={3}{for tree={#2/if in #3={##1}{##2}{##3}}}
3074 }%
3075 \ifstrempty{#5}{%
3076 \pgfkeysalso{%
3077 #1+/.code={\forestOappto{\forest@setter@node}{#3}{#5##1}},
3078 #2/+#3/.code={\forestOpreto{\forest@setter@node}{#3}{##1#5}},
3079 }%
3080 }{%
3081 \pgfkeysalso{%
3082 #1+/.code={%
3083 \forestOget{\forest@setter@node}{#3}\forest@temp
3084 \ifdefempty{\forest@temp}{%
3085 \forestOset{\forest@setter@node}{#3}{##1}%
3086 }{%
3087 \forestOappto{\forest@setter@node}{#3}{#5##1}%
3088 }%
3089 },
3090 #2/+#3/.code={%
3091 \forestOget{\forest@setter@node}{#3}\forest@temp
3092 \ifdefempty{\forest@temp}{%
3093 \forestOset{\forest@setter@node}{#3}{##1}%
3094 }{%
3095 \forestOpreto{\forest@setter@node}{#3}{##1#5}%
3096 }%
3097 }%
3098 }%
3099 }%
3100 \pgfkeyssetvalue{#1/option@name}{#3}%
3101 \pgfkeyssetvalue{#1+/option@name}{#3}%
3102 \pgfkeyssetvalue{#2/+#3/option@name}{#3}%
3103 \pgfkeyslet{#1/@type}\forestmathtype@generic % for .process & co
3104 \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@toks{##1}{#3}}%
3105 }
3106 \def\forest@declareautowrappedtoks@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
3107 \forest@declaretoks@handler{#1}{#2}{#3}{#4}%
3108 \forest@copycommandkey{#1}{#1'}%
3109 \pgfkeysalso{#1/.style={#1'/.wrap value={##1}}}%
3110 \pgfkeyssetvalue{#1'/option@name}{#3}%
3111 \forest@copycommandkey{#1+}{#1+'}%
3112 \pgfkeysalso{#1+/.style={#1+'/.wrap value={##1}}}%
3113 \pgfkeyssetvalue{#1+'/option@name}{#3}%
3114 \forest@copycommandkey{#2/+#3}{#2/+#3'}%
3115 \pgfkeysalso{#2/+#3/.style={#2/+#3'/.wrap value={##1}}}%
3116 \pgfkeyssetvalue{#2/+#3'/option@name}{#3}%
3117 }
3118 \def\forest@declarereadonlydimen@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
3119 % this is to have `pt` with the correct category code
3120 \pgfutil@tempdima=\pgfkeysvalueof{/forest/#3}\relax
3121 \edef\forest@marshal{%
3122 \noexpand\pgfkeyssetvalue{/forest/#3}{\the\pgfutil@tempdima}%
3123 }\forest@marshal
3124 \pgfkeysalso{%
3125 #2/if #3/.code n args={3}{%
3126 \forestoget{#3}\forest@temp@option@value
3127 \ifdim\forest@temp@option@value=##1\relax
3128 \pgfkeysalso{##2}%
3129 \else
3130 \pgfkeysalso{##3}%
3131 \fi
3132 },
3133 #2/if #3</.code n args={3}{%
3134 \forestoget{#3}\forest@temp@option@value
3135 \ifdim\forest@temp@option@value>##1\relax
3136 \pgfkeysalso{##3}%
3137 \else
3138 \pgfkeysalso{##2}%
3139 \fi
3140 },
3141 #2/if #3>/.code n args={3}{%
3142 \forestoget{#3}\forest@temp@option@value
3143 \ifdim\forest@temp@option@value<##1\relax
3144 \pgfkeysalso{##3}%
3145 \else
3146 \pgfkeysalso{##2}%
3147 \fi
3148 },
3149 #2/where #3/.style n args={3}{for tree={#2/if #3={##1}{##2}{##3}}},
3150 #2/where #3</.style n args={3}{for tree={#2/if #3<={##1}{##2}{##3}}},
3151 #2/where #3>/.style n args={3}{for tree={#2/if #3>={##1}{##2}{##3}}},
3152 }%
3153 \pgfkeyslet{#1/@type}\forestmathtype@dimen % for .process & co
3154 \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@dimen{##1}{#3}}%
3155 }
3156 \def\forest@declaredimen@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
3157 \forest@declarereadonlydimen@handler{#1}{#2}{#3}{#4}%
3158 \pgfkeysalso{%
3159 #1/.code={%
3160 \forestmathsetlengthmacro\forest@temp{##1}%
3161 \forestOlet{\forest@setter@node}{#3}\forest@temp
3162 },
3163 #1+/.code={%
3164 \forestmathsetlengthmacro\forest@temp{##1}%
3165 \pgfutil@tempdima=\forestove{#3}
3166 \advance\pgfutil@tempdima\forest@temp\relax
3167 \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
3168 },
3169 #1-/.code={%
3170 \forestmathsetlengthmacro\forest@temp{##1}%
3171 \pgfutil@tempdima=\forestove{#3}
3172 \advance\pgfutil@tempdima-\forest@temp\relax
3173 \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
3174 },
3175 #1*/.style={%
3176 #1={#4()*(##1)}%
3177 },
3178 #1:/.style={%
3179 #1={#4()/(##1)}%
3180 },
3181 #1'/.code={%
3182 \pgfutil@tempdima=##1\relax
3183 \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
3184 },
3185 #1'+/.code={%
3186 \pgfutil@tempdima=\forestove{#3}\relax
3187 \advance\pgfutil@tempdima##1\relax
3188 \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
3189 },
3190 #1'-/.code={%
3191 \pgfutil@tempdima=\forestove{#3}\relax
3192 \advance\pgfutil@tempdima-##1\relax
3193 \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
3194 },
3195 #1'*/.style={%
3196 \pgfutil@tempdima=\forestove{#3}\relax
3197 \multiply\pgfutil@tempdima##1\relax
3198 \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
3199 },
3200 #1':/.style={%
3201 \pgfutil@tempdima=\forestove{#3}\relax
3202 \divide\pgfutil@tempdima##1\relax
3203 \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
3204 },
3205 }%
3206 \pgfkeyssetvalue{#1/option@name}{#3}%
3207 \pgfkeyssetvalue{#1+/option@name}{#3}%
3208 \pgfkeyssetvalue{#1-/option@name}{#3}%
3209 \pgfkeyssetvalue{#1*/option@name}{#3}%
3210 \pgfkeyssetvalue{#1:/option@name}{#3}%
3211 \pgfkeyssetvalue{#1'/option@name}{#3}%
3212 \pgfkeyssetvalue{#1'+/option@name}{#3}%
3213 \pgfkeyssetvalue{#1'-/option@name}{#3}%
3214 \pgfkeyssetvalue{#1'*/option@name}{#3}%
3215 \pgfkeyssetvalue{#1':/option@name}{#3}%
3216 }
3217 \def\forest@declarereadonlycount@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
3218 \pgfkeysalso{
3219 #2/if #3/.code n args={3}{%
3220 \forestoget{#3}\forest@temp@option@value
3221 \ifnum\forest@temp@option@value=##1\relax
3222 \pgfkeysalso{##2}%
3223 \else
3224 \pgfkeysalso{##3}%
3225 \fi
3226 },
3227 #2/if #3</.code n args={3}{%
3228 \forestoget{#3}\forest@temp@option@value
3229 \ifnum\forest@temp@option@value>##1\relax
3230 \pgfkeysalso{##3}%
3231 \else
3232 \pgfkeysalso{##2}%
3233 \fi
3234 },
3235 #2/if #3>/.code n args={3}{%
3236 \forestoget{#3}\forest@temp@option@value
3237 \ifnum\forest@temp@option@value<##1\relax
3238 \pgfkeysalso{##3}%
3239 \else
3240 \pgfkeysalso{##2}%
3241 \fi
3242 },
3243 #2/where #3/.style n args={3}{for tree={#2/if #3={##1}{##2}{##3}}},
3244 #2/where #3</.style n args={3}{for tree={#2/if #3<={##1}{##2}{##3}}},
3245 #2/where #3>/.style n args={3}{for tree={#2/if #3>={##1}{##2}{##3}}},
3246 }%
3247 \pgfkeyslet{#1/@type}\forestmathtype@count % for .process & co
3248 \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@count{##1}{#3}}%
3249 }
3250 \def\forest@declarecount@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
3251 \forest@declarereadonlycount@handler{#1}{#2}{#3}{#4}%
3252 \pgfkeysalso{
3253 #1/.code={%
3254 \forestmathtruncatemacro\forest@temp{##1}%
3255 \forestOlet{\forest@setter@node}{#3}\forest@temp
3256 },
3257 #1+/.code={%
3258 \forestmathtruncatemacro\forest@temp{##1}%
3259 \c@pgf@counta=\forestove{#3}\relax
3260 \advance\c@pgf@counta\forest@temp\relax
3261 \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
3262 },
3263 #1-/.code={%
3264 \forestmathtruncatemacro\forest@temp{##1}%
3265 \c@pgf@counta=\forestove{#3}\relax
3266 \advance\c@pgf@counta-\forest@temp\relax
3267 \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
3268 },
3269 #1*/.code={%
3270 \forestmathtruncatemacro\forest@temp{##1}%
3271 \c@pgf@counta=\forestove{#3}\relax
3272 \multiply\c@pgf@counta\forest@temp\relax
3273 \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
3274 },
3275 #1:/.code={%
3276 \forestmathtruncatemacro\forest@temp{##1}%
3277 \c@pgf@counta=\forestove{#3}\relax
3278 \divide\c@pgf@counta\forest@temp\relax
3279 \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
3280 },
3281 #1'/.code={%
3282 \c@pgf@counta=##1\relax
3283 \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
3284 },
3285 #1'+/.code={%
3286 \c@pgf@counta=\forestove{#3}\relax
3287 \advance\c@pgf@counta##1\relax
3288 \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
3289 },
3290 #1'-/.code={%
3291 \c@pgf@counta=\forestove{#3}\relax
3292 \advance\c@pgf@counta-##1\relax
3293 \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
3294 },
3295 #1'*/.style={%
3296 \c@pgf@counta=\forestove{#3}\relax
3297 \multiply\c@pgf@counta##1\relax
3298 \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
3299 },
3300 #1':/.style={%
3301 \c@pgf@counta=\forestove{#3}\relax
3302 \divide\c@pgf@counta##1\relax
3303 \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
3304 },
3305 }%
3306 \pgfkeyssetvalue{#1/option@name}{#3}%
3307 \pgfkeyssetvalue{#1+/option@name}{#3}%
3308 \pgfkeyssetvalue{#1-/option@name}{#3}%
3309 \pgfkeyssetvalue{#1*/option@name}{#3}%
3310 \pgfkeyssetvalue{#1:/option@name}{#3}%
3311 \pgfkeyssetvalue{#1'/option@name}{#3}%
3312 \pgfkeyssetvalue{#1'+/option@name}{#3}%
3313 \pgfkeyssetvalue{#1'-/option@name}{#3}%
3314 \pgfkeyssetvalue{#1'*/option@name}{#3}%
3315 \pgfkeyssetvalue{#1':/option@name}{#3}%
3316 }
3317 % \end{macrocode}
3318 % Nothing else should be defined in this namespace.
3319 % \begin{macrocode}
3320 \def\forest@declareboolean@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
3321 \pgfkeysalso{%
3322 #1/.code={%
3323 \forestmath@if{##1}{%
3324 \def\forest@temp{1}%
3325 }{%
3326 \def\forest@temp{0}%
3327 }%
3328 \forestOlet{\forest@setter@node}{#3}\forest@temp
3329 },
3330 #1/.default=1,
3331 #2/not #3/.code={\forestOset{\forest@setter@node}{#3}{0}},
3332 #2/if #3/.code 2 args={%
3333 \forestoget{#3}\forest@temp@option@value
3334 \ifnum\forest@temp@option@value=0
3335 \pgfkeysalso{##2}%
3336 \else
3337 \pgfkeysalso{##1}%
3338 \fi
3339 },
3340 #2/where #3/.style 2 args={for tree={#2/if #3={##1}{##2}}}
3341 }%
3342 \pgfkeyssetvalue{#1/option@name}{#3}%
3343 \pgfkeyslet{#1/@type}\forestmathtype@count % for .process & co
3344 \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@count{##1}{#3}}%
3345 }
3346 \forestset{
3347 declare toks/.code 2 args={%
3348 \forest@declarehandler\forest@declaretoks@handler{#1}{#2}%
3349 },
3350 declare autowrapped toks/.code 2 args={%
3351 \forest@declarehandler\forest@declareautowrappedtoks@handler{#1}{#2}%
3352 },
3353 declare keylist/.code 2 args={%
3354 \forest@declarehandler\forest@declarekeylist@handler{#1}{#2}%
3355 },
3356 declare readonly dimen/.code 2 args={%
3357 \forestmathsetlengthmacro\forest@temp{#2}%
3358 \edef\forest@marshal{%
3359 \unexpanded{\forest@declarehandler\forest@declarereadonlydimen@handler{#1}}{\forest@temp}%
3360 }\forest@marshal
3361 },
3362 declare dimen/.code 2 args={%
3363 \forestmathsetlengthmacro\forest@temp{#2}%
3364 \edef\forest@marshal{%
3365 \unexpanded{\forest@declarehandler\forest@declaredimen@handler{#1}}{\forest@temp}%
3366 }\forest@marshal
3367 },
3368 declare readonly count/.code 2 args={%
3369 \forestmathtruncatemacro\forest@temp{#2}%
3370 \edef\forest@marshal{%
3371 \unexpanded{\forest@declarehandler\forest@declarereadonlycount@handler{#1}}{\forest@temp}%
3372 }\forest@marshal
3373 },
3374 declare count/.code 2 args={%
3375 \forestmathtruncatemacro\forest@temp{#2}%
3376 \edef\forest@marshal{%
3377 \unexpanded{\forest@declarehandler\forest@declarecount@handler{#1}}{\forest@temp}%
3378 }\forest@marshal
3379 },
3380 declare boolean/.code 2 args={%
3381 \forestmath@if{#2}{%
3382 \def\forest@temp{1}%
3383 }{%
3384 \def\forest@temp{0}%
3385 }%
3386 \edef\forest@marshal{%
3387 \unexpanded{\forest@declarehandler\forest@declareboolean@handler{#1}}{\forest@temp}%
3388 }\forest@marshal
3389 },
3390 % \end{macrocode}
3391 %
3392 % \section{Handlers}
3393 %
3394 % \begin{macrocode}
3395 /handlers/.restore default value/.code={%
3396 \edef\forest@handlers@currentpath{\pgfkeyscurrentpath}%
3397 \pgfkeysgetvalue{\pgfkeyscurrentpath/option@name}\forest@currentoptionname
3398 \pgfkeysgetvalue{/forest/\forest@currentoptionname}\forest@temp
3399 \expandafter\pgfkeysalso\expandafter{\forest@handlers@currentpath/.expand once=\forest@temp}%
3400 },
3401 /handlers/.pgfmath/.code={%
3402 \pgfmathparse{#1}%
3403 \pgfkeysalso{\pgfkeyscurrentpath/.expand once=\pgfmathresult}%
3404 },
3405 /handlers/.wrap value/.code={%
3406 \edef\forest@handlers@wrap@currentpath{\pgfkeyscurrentpath}%
3407 \pgfkeysgetvalue{\forest@handlers@wrap@currentpath/option@name}\forest@currentoptionname
3408 \forestOget{\pgfkeysvalueof{/forest/\forest@currentoptionname/node@or@reg}}{\forest@currentoptionname}\forest@option@value
3409 \forest@def@with@pgfeov\forest@wrap@code{#1}%
3410 \expandafter\edef\expandafter\forest@wrapped@value\expandafter{\expandafter\expandonce\expandafter{\expandafter\forest@wrap@code\forest@option@value\pgfeov}}%
3411 \pgfkeysalso{\forest@handlers@wrap@currentpath/.expand once=\forest@wrapped@value}%
3412 },
3413 /handlers/.option/.code={%
3414 \edef\forest@temp{\pgfkeyscurrentpath}%
3415 \expandafter\forest@handlers@option\expandafter{\forest@temp}{#1}%
3416 },
3417 }
3418 \def\forest@handlers@option#1#2{%#1=pgfkeyscurrentpath,#2=relative node name
3419 \forestRNOget{#2}\forest@temp
3420 \pgfkeysalso{#1/.expand once={\forest@temp}}%
3421 }%
3422 \forestset{
3423 /handlers/.register/.code={%
3424 \edef\forest@marshal{%
3425 \noexpand\pgfkeysalso{\pgfkeyscurrentpath={\forestregister{#1}}}%
3426 }\forest@marshal
3427 },
3428 /handlers/.wrap pgfmath arg/.code 2 args={%
3429 \forestmathparse{#2}\let\forest@wrap@arg@i\forestmathresult
3430 \edef\forest@wrap@args{{\expandonce\forest@wrap@arg@i}}%
3431 \def\forest@wrap@code##1{#1}%
3432 % here we don't call \forest@wrap@pgfmath@args@@@wrapandpasson, as compat-2.0.2-wrappgfmathargs changes that to achieve the old, confusing state of affairs, which *didn't* apply at *1*-arg pgfmath wrapping
3433 \expandafter\expandafter\expandafter\forest@temp@toks\expandafter\expandafter\expandafter{\expandafter\forest@wrap@code\forest@wrap@args}%
3434 \expandafter\pgfkeysalso\expandafter{\expandafter\pgfkeyscurrentpath\expandafter=\expandafter{\the\forest@temp@toks}}%
3435 },
3436 /handlers/.wrap 2 pgfmath args/.code n args={3}{%
3437 \forestmathparse{#2}\let\forest@wrap@arg@i\forestmathresult
3438 \forestmathparse{#3}\let\forest@wrap@arg@ii\forestmathresult
3439 \edef\forest@wrap@args{{\expandonce\forest@wrap@arg@i}{\expandonce\forest@wrap@arg@ii}}%
3440 \def\forest@wrap@code##1##2{#1}%
3441 \forest@wrap@pgfmath@args@@@wrapandpasson
3442 },
3443 /handlers/.wrap 3 pgfmath args/.code n args={4}{%
3444 \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{}{}{}{}{}{3}%
3445 \forest@wrap@n@pgfmath@do{#1}{3}},
3446 /handlers/.wrap 4 pgfmath args/.code n args={5}{%
3447 \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{}{}{}{}{4}%
3448 \forest@wrap@n@pgfmath@do{#1}{4}},
3449 /handlers/.wrap 5 pgfmath args/.code n args={6}{%
3450 \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{#6}{}{}{}{5}%
3451 \forest@wrap@n@pgfmath@do{#1}{5}},
3452 /handlers/.wrap 6 pgfmath args/.code n args={7}{%
3453 \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{#6}{#7}{}{}{6}%
3454 \forest@wrap@n@pgfmath@do{#1}{6}},
3455 /handlers/.wrap 7 pgfmath args/.code n args={8}{%
3456 \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{#6}{#7}{#8}{}{7}%
3457 \forest@wrap@n@pgfmath@do{#1}{7}},
3458 /handlers/.wrap 8 pgfmath args/.code n args={9}{%
3459 \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}{8}%
3460 \forest@wrap@n@pgfmath@do{#1}{8}},
3461 }
3462 \def\forest@wrap@n@pgfmath@args#1#2#3#4#5#6#7#8#9{%
3463 \forestmathparse{#1}\let\forest@wrap@arg@i\forestmathresult
3464 \ifnum#9>1 \forestmathparse{#2}\let\forest@wrap@arg@ii\forestmathresult\fi
3465 \ifnum#9>2 \forestmathparse{#3}\let\forest@wrap@arg@iii\forestmathresult\fi
3466 \ifnum#9>3 \forestmathparse{#4}\let\forest@wrap@arg@iv\forestmathresult\fi
3467 \ifnum#9>4 \forestmathparse{#5}\let\forest@wrap@arg@v\forestmathresult\fi
3468 \ifnum#9>5 \forestmathparse{#6}\let\forest@wrap@arg@vi\forestmathresult\fi
3469 \ifnum#9>6 \forestmathparse{#7}\let\forest@wrap@arg@vii\forestmathresult\fi
3470 \ifnum#9>7 \forestmathparse{#8}\let\forest@wrap@arg@viii\forestmathresult\fi
3471 \edef\forest@wrap@args{%
3472 {\expandonce\forest@wrap@arg@i}
3473 \ifnum#9>1 {\expandonce\forest@wrap@arg@ii}\fi
3474 \ifnum#9>2 {\expandonce\forest@wrap@arg@iii}\fi
3475 \ifnum#9>3 {\expandonce\forest@wrap@arg@iv}\fi
3476 \ifnum#9>4 {\expandonce\forest@wrap@arg@v}\fi
3477 \ifnum#9>5 {\expandonce\forest@wrap@arg@vi}\fi
3478 \ifnum#9>6 {\expandonce\forest@wrap@arg@vii}\fi
3479 \ifnum#9>7 {\expandonce\forest@wrap@arg@viii}\fi
3480 }%
3481 }
3482 \def\forest@wrap@n@pgfmath@do#1#2{%
3483 \ifcase#2\relax
3484 \or\def\forest@wrap@code##1{#1}%
3485 \or\def\forest@wrap@code##1##2{#1}%
3486 \or\def\forest@wrap@code##1##2##3{#1}%
3487 \or\def\forest@wrap@code##1##2##3##4{#1}%
3488 \or\def\forest@wrap@code##1##2##3##4##5{#1}%
3489 \or\def\forest@wrap@code##1##2##3##4##5##6{#1}%
3490 \or\def\forest@wrap@code##1##2##3##4##5##6##7{#1}%
3491 \or\def\forest@wrap@code##1##2##3##4##5##6##7##8{#1}%
3492 \fi
3493 \forest@wrap@pgfmath@args@@@wrapandpasson
3494 }
3495 % \end{macrocode}
3496 % The following macro is redefined by compat key |2.0.2-wrappgfmathargs|.
3497 % \begin{macrocode}
3498 \def\forest@wrap@pgfmath@args@@@wrapandpasson{%
3499 \expandafter\expandafter\expandafter\forest@temp@toks
3500 \expandafter\expandafter\expandafter{%
3501 \expandafter\forest@wrap@code\forest@wrap@args}%
3502 \expandafter\pgfkeysalso\expandafter{%
3503 \expandafter\pgfkeyscurrentpath\expandafter=\expandafter{%
3504 \the\forest@temp@toks}}%
3505 }
3506 % \end{macrocode}
3507 %
3508 % \subsection{.process}
3509 %
3510 % \begin{macrocode}
3511 \def\forest@process@catregime{} % filled by processor defs
3512 \forest@newarray\forest@process@left@ % processed args
3513 \forest@newarray\forest@process@right@ % unprocessed args
3514 \forest@newarray\forest@process@saved@ % used by instructions |S| and |U|
3515 \let\forest@process@savedtype\forestmathtype@none
3516 \forest@newglobalarray\forest@process@result@
3517 \newif\ifforest@process@returnarray@
3518 % \end{macrocode}
3519 % Processing instruction need not (but may) be enclosed in braces.
3520 % \begin{macrocode}
3521 \def\forest@process#1#2#{% #1 = true/false (should we return an array?)
3522 % #2 = processing instructions (if non-empty),
3523 % (initial) args follow
3524 \ifblank{#2}{\forest@process@a{#1}}{\forest@process@a{#1}{#2}}%
3525 }
3526 \Inline\def\forest@process@a#1#2{%
3527 \begingroup
3528 \forest@process@left@clear
3529 \forest@process@right@clear
3530 \forest@process@saved@clear
3531 \let\forest@process@savedtype\forestmathtype@generic
3532 \csname forest@process@returnarray@#1\endcsname
3533 \def\forest@topextend@next{%
3534 \ExpandIfT{forestdebug}{%
3535 \edef\forest@process@debug@args{\unexpanded{#2}}%
3536 \forest@processor@debuginfo@template{Start "\unexpanded{#2}}%
3537 }%
3538 \forest@process@catregime
3539 \endlinechar=-1
3540 \scantokens{#2}%
3541 \forest@process@finish
3542 }%
3543 \forest@process@right@topextend
3544 }
3545 \pgfkeys{%
3546 /handlers/.process/.code={%
3547 \forest@process{true}#1\forest@eov
3548 \edef\forest@marshal{%
3549 \noexpand\pgfkeysalso{\noexpand\pgfkeyscurrentpath=\forest@process@result@values}%
3550 }\forest@marshal
3551 },
3552 /forest/copy command key={/handlers/.process}{/handlers/.process args},
3553 }
3554 \def\forest@process@finish{%
3555 \ifforest@process@returnarray@
3556 \forest@process@finish@array
3557 \else
3558 \forest@process@finish@single
3559 \fi
3560 \global\let\forest@process@result@type\forestmathresulttype
3561 \ifforestdebugprocess\forest@process@debug@end\fi
3562 \endgroup
3563 }
3564 \def\forest@process@finish@single{%
3565 \edef\forest@temp{forest@process@finish@single@%
3566 \the\numexpr\forest@process@left@N-\forest@process@left@M\relax
3567 \the\numexpr\forest@process@right@N-\forest@process@right@M\relax
3568 }%
3569 \ifcsname\forest@temp\endcsname
3570 \csname\forest@temp\endcsname
3571 \global\let\forest@process@result\forest@temp
3572 \else
3573 \forest@process@lengtherror
3574 \fi
3575 }
3576 \csdef{forest@process@finish@single@10}{\forest@process@left@toppop\forest@temp}
3577 \csdef{forest@process@finish@single@01}{\forest@process@right@toppop\forest@temp}
3578 \def\forest@process@finish@array{%
3579 \forest@process@result@clear
3580 \forest@temp@count\forest@process@left@M\relax
3581 \forest@loop
3582 \ifnum\forest@temp@count<\forest@process@left@N\relax
3583 \forest@process@left@get@{\the\forest@temp@count}\forest@temp
3584 \forest@process@result@letappend\forest@temp
3585 \advance\forest@temp@count1
3586 \forest@repeat
3587 \forest@temp@count\forest@process@right@M\relax
3588 \forest@loop
3589 \ifnum\forest@temp@count<\forest@process@right@N\relax
3590 \forest@process@right@get@{\the\forest@temp@count}\forest@temp
3591 \forest@process@result@letappend\forest@temp
3592 \advance\forest@temp@count1
3593 \forest@repeat
3594 }
3595 % \end{macrocode}
3596 % Debugging and error messages.
3597 % \begin{macrocode}
3598 \ifforestdebug
3599 \let\forest@process@d\forest@process@b
3600 \def\forest@process@b#1\forest@eov{% save and print initial arguments
3601 \edef\forest@process@debug@args{\unexpanded{#1}}%
3602 \typeout{[forest .process] Start "\unexpanded{#1}"}%
3603 \forest@process@d#1\forest@eov
3604 }
3605 \fi
3606 \def\forest@process@debug@end{%
3607 \typeout{[forest .process] End "\expandonce{\forest@process@debug@args}" -> "\forest@process@left@values\forest@process@right@values"}%
3608 }
3609 \def\forest@process@lengtherror{%
3610 \PackageError{forest}{%
3611 The ".process" expression was expected to evaluate to a single argument,
3612 but the result is \the\forest@process@result@N
3613 \space items long.}{}%
3614 }
3615 % \end{macrocode}
3616 % Define the definer of processors. First, deal with the catcode of the instruction char.
3617 % \begin{macrocode}
3618 \def\forest@def@processor#1{%
3619 {%
3620 \def\forest@dp@double##1{%
3621 \gdef\forest@global@temp{\forest@def@processor@{#1}{##1}}%
3622 }%
3623 \let\\\forest@dp@double
3624 \catcode`#1=13
3625 \scantokens{\\#1}%
3626 }%
3627 \forest@global@temp
3628 }
3629 \def\forest@def@processor@#1#2{%
3630 % #1 = instruction char (normal catcode), #2 = instruction char (active)
3631 % #3 = default n (optional numeric arg, which precedes any other args;
3632 % if the default is empty, this means no optional n)
3633 % #4 = args spec,
3634 % #5 = code
3635 \eappto\forest@process@catregime{%
3636 \unexpanded{\let#2}\expandonce{\csname forest@processor@#1\endcsname}%
3637 \unexpanded{\catcode`#1=13 }%
3638 }%
3639 \def\forest@def@processor@inschar{#1}%
3640 \forest@def@processor@@
3641 }
3642 % \end{macrocode}
3643 % If |#1| is non-empty, the processor accepts the optional numeric argument: |#1| is the default.
3644 % \begin{macrocode}
3645 \def\forest@def@processor@@#1{%
3646 \ifstrempty{#1}{%
3647 \forest@def@processor@@non
3648 }{%
3649 \def\forest@def@processor@@default@n{#1}%
3650 \forest@def@processor@@n
3651 }%
3652 }
3653 % \end{macrocode}
3654 % We need |\relax| below because the next instruction character might get expanded when assigning the optional numerical argument which is not there.
3655 %
3656 % No optional n:
3657 % \begin{macrocode}
3658 \def\forest@def@processor@@non#1#2{% #1=args spec, #2=code
3659 \csedef{forest@processor@\forest@def@processor@inschar}#1{%
3660 \relax %% we need this (see above)
3661 \unexpanded{#2}%
3662 \expandafter\forest@def@processor@debuginfo\expandafter{%
3663 \expandafter"\forest@def@processor@inschar"\ifstrempty{#1}{}{(#1)}}%
3664 \ignorespaces
3665 }%
3666 }
3667 % \end{macrocode}
3668 % Optional n: |*| after the given default means that the operation should be repeated n times.
3669 % \begin{macrocode}
3670 \def\forest@def@processor@@n{%
3671 \@ifnextchar*%
3672 {\forest@temptrue\forest@def@processor@@n@}%
3673 {\forest@tempfalse\forest@def@processor@@n@@}%
3674 }
3675 \def\forest@def@processor@@n@*{\forest@def@processor@@n@@}
3676 \def\forest@def@processor@@n@@#1#2{% #1=args spec, #2=code
3677 \csedef{forest@processor@\forest@def@processor@inschar}{%
3678 \relax %% we need this (see above)
3679 \noexpand\forestprocess@get@n
3680 {\forest@def@processor@@default@n}%
3681 \expandonce{\csname forest@processor@\forest@def@processor@inschar @\endcsname}%
3682 }%
3683 \ifforest@temp
3684 \csedef{forest@processor@\forest@def@processor@inschar @}{%
3685 \noexpand\forest@repeat@n@times{\forest@process@n}{%
3686 \expandonce{\csname forest@processor@\forest@def@processor@inschar @rep\endcsname}%
3687 }%
3688 }%
3689 \fi
3690 \edef\forest@temp{%
3691 \forest@def@processor@inschar
3692 \ifforest@temp\else\noexpand\the\forest@process@n\fi
3693 "}%
3694 \csedef{forest@processor@\forest@def@processor@inschar @\ifforest@temp rep\fi}#1{%
3695 \unexpanded{#2}%
3696 \expandafter\forest@def@processor@debuginfo\expandafter{%
3697 \forest@temp
3698 \ifstrempty{#1}{}{(#1)}}%
3699 }%
3700 }
3701 \def\forest@def@processor@debuginfo#1{% #1 = instruction call
3702 \ifforestdebug
3703 \expandonce{\forest@processor@debuginfo@template{\space\space After #1}}%
3704 \fi
3705 }
3706 \def\forest@processor@debuginfo@template#1{%
3707 \ifforestdebugprocess
3708 \edef\forest@temp@left{\forest@process@left@values}%
3709 \edef\forest@temp@right{\forest@process@right@values}%
3710 \edef\forest@temp@saved{\forest@process@saved@values}%
3711 \typeout{[forest .process] #1: left="\expandonce{\forest@temp@left}", right="\expandonce{\forest@temp@right}", saved="\expandonce{\forest@temp@saved}", type=\forestmathresulttype}%
3712 \fi
3713 }
3714 % \end{macrocode}
3715 % A helper macro which puts the optional numeric argument into count |\forest@process@n| (default being |#1|) and then executes control sequence |#2|.
3716 % \begin{macrocode}
3717 \newcount\forest@process@n
3718 \def\forestprocess@get@n#1#2{%
3719 \def\forestprocess@default@n{#1}%
3720 \let\forestprocess@after@get@n@#2%
3721 \afterassignment\forestprocess@get@n@\forest@process@n=0%
3722 }
3723 \def\forestprocess@get@n@{%
3724 \ifnum\forest@process@n=0
3725 \forest@process@n\forestprocess@default@n\relax
3726 \fi
3727 \forestprocess@after@get@n@
3728 }
3729 % \end{macrocode}
3730 %
3731 % Definitions of processing instructions. Processors should be defined using |\forest@def@processor|. If they take arguments: yes, they follow, but they were scanned in |\forest@process@catregime|. Processors should manipulate arrays |\forest@process@left@| and |\forest@process@right|. They should set |\def\forestmathresulttype| to |_| not defined, |n| number, |d| dimension, |P| pgfmath or |t| text.
3732 % \begin{macrocode}
3733 \forest@def@processor{_}{1}*{}{% no processing, no type
3734 \forest@process@right@bottompop\forest@temp
3735 \forest@process@left@letappend\forest@temp
3736 }
3737 \forest@def@processor{n}{1}*{}{% numexpr
3738 \forest@process@right@bottompop\forest@temp
3739 \forest@process@left@esetappend{\number\numexpr\forest@temp}%
3740 \let\forestmathresulttype\forestmathtype@count
3741 }
3742 \forest@def@processor{d}{1}*{}{% dimexpr
3743 \forest@process@right@bottompop\forest@temp
3744 \forest@process@left@esetappend{\the\dimexpr\forest@temp}%
3745 \let\forestmathresulttype\forestmathtype@dimen
3746 }
3747 \forest@def@processor{P}{1}*{}{% pgfmath expression
3748 \forest@process@right@bottompop\forest@temp
3749 \pgfmathparse{\forest@temp}%
3750 \forest@process@left@letappend\pgfmathresult
3751 \let\forestmathresulttype\forestmathtype@unitless
3752 }
3753 \forest@def@processor{p}{1}*{}{% process expression
3754 \forest@process@right@bottompop\forest@temp@a
3755 \def\forest@temp{\forest@process{true}}%
3756 \expandafter\forest@temp\forest@temp@a\forest@eov
3757 \let\forest@topextend@next\relax
3758 \edef\forest@temp{\forest@process@result@values}%
3759 \expandafter\forest@process@left@topextend\forest@temp\forest@eov
3760 \let\forestmathresulttype\forest@process@result@type
3761 }
3762 \forest@def@processor{t}{1}*{}{% text
3763 \forest@process@right@bottompop\forest@temp
3764 \forest@process@left@letappend\forest@temp
3765 \let\forestmathresulttype\forestmathtype@textasc
3766 }
3767 \forest@def@processor{-}{}{}{% toggle ascending/descending
3768 \forest@process@left@toppop\forestmathresult
3769 \csname forest@processor@-@\forestmathresulttype\endcsname
3770 \forest@process@left@letappend\forestmathresult
3771 }
3772 \cslet{forest@processor@-@\forestmathtype@generic}\relax
3773 \csdef{forest@processor@-@\forestmathtype@count}{%
3774 \forestmathadd{\forestmathzero}{-\forestmathresult}}
3775 \csletcs{forest@processor@-@\forestmathtype@dimen}
3776 {forest@processor@-@\forestmathtype@count}
3777 \csletcs{forest@processor@-@\forestmathtype@unitless}
3778 {forest@processor@-@\forestmathtype@count}
3779 \csdef{forest@processor@-@\forestmathtype@textasc}{%
3780 \let\forestmathresulttype\forestmathtype@textdesc}
3781 \csdef{forest@processor@-@\forestmathtype@textdesc}{%
3782 \let\forestmathresulttype\forestmathtype@textasc}
3783
3784 \forest@def@processor{c}{}{}{% to lowercase
3785 \forest@process@right@bottompop\forest@temp
3786 \expandafter\lowercase\expandafter{\expandafter\def\expandafter\forest@temp\expandafter{\forest@temp}}%
3787 \forest@process@left@letappend\forest@temp
3788 }
3789 \forest@def@processor{C}{}{}{% to uppercase
3790 \forest@process@right@bottompop\forest@temp
3791 \expandafter\uppercase\expandafter{\expandafter\def\expandafter\forest@temp\expandafter{\forest@temp}}%
3792 \forest@process@left@letappend\forest@temp
3793 }
3794 % \end{macrocode}
3795 % Expansions:
3796 % \begin{macrocode}
3797 \forest@def@processor{x}{}{}{% expand
3798 \forest@process@right@bottompop\forest@temp
3799 \forest@process@left@esetappend{\forest@temp}%
3800 \let\forestmathresulttype\forestmathtype@generic
3801 }
3802 \forest@def@processor{o}{1}{}{% expand once (actually, \forest@count@n times)
3803 \forest@process@right@bottompop\forest@temp
3804 \forest@repeat@n@times{\forest@process@n}{%
3805 \expandafter\expandafter\expandafter\def
3806 \expandafter\expandafter\expandafter\forest@temp
3807 \expandafter\expandafter\expandafter{\forest@temp}%
3808 }%
3809 \expandafter\forest@process@left@setappend\expandafter{\forest@temp}%
3810 \let\forestmathresulttype\forestmathtype@generic
3811 }
3812 % \end{macrocode}
3813 % Access to \foRest; data.
3814 % \begin{macrocode}
3815 \forest@def@processor{O}{1}*{}{% option
3816 \forest@process@right@bottompop\forest@temp
3817 \expandafter\forestRNO@getvalueandtype\expandafter{\forest@temp}\forest@tempvalue\forest@temp@type
3818 \let\forestmathresulttype\forest@temp@type
3819 \forest@process@left@letappend\forest@tempvalue
3820 }
3821 \forest@def@processor{R}{1}*{}{% register
3822 \forest@process@right@bottompop\forest@temp
3823 \forestrget{\forest@temp}\forest@tempvalue
3824 \forest@process@left@letappend\forest@tempvalue
3825 \pgfkeysgetvalue{/forest/\forest@temp/@type}\forest@temp@type
3826 \let\forestmathresulttype\forest@temp@type
3827 }
3828 % \end{macrocode}
3829 % The following processors muck about with the argument / result list.
3830 % \begin{macrocode}
3831 \forest@def@processor{+}{1}*{}{% join processors = pop one from result
3832 \forest@process@left@toppop\forest@temp
3833 \forest@process@right@letprepend\forest@temp
3834 }
3835 \forest@def@processor{u}{}{}{% ungroup: remove braces and leave in the argument list
3836 \forest@process@right@bottompop\forest@temp
3837 \forest@temparray@clear
3838 \let\forestmathresulttype\forestmathtype@generic
3839 \let\forest@topextend@next\forest@processor@u@
3840 \expandafter\forest@temparray@topextend\forest@temp\forest@eov
3841 }
3842 \def\forest@processor@u@{%
3843 \forest@loop
3844 \ifnum\forest@temparray@N>0
3845 \forest@temparray@toppop\forest@temp
3846 \expandafter\forest@process@right@setprepend\expandafter{\forest@temp}%
3847 \forest@repeat
3848 }
3849 \def\forest@process@check@mn#1#2#3#4{%
3850 % #1 = processor, #2 = given n, #3/#4 = lower/upper bound (inclusive)
3851 \ifnum#3>#2\relax
3852 \forest@process@check@n@error{#1}{#2}{#3<=}{<=#4}%
3853 \else
3854 \ifnum#4<#2\relax
3855 \forest@process@check@n@error{#1}{#2}{#3<=}{<=#4}%
3856 \fi
3857 \fi
3858 }
3859 \def\forest@process@check@m#1#2#3{%
3860 % #1 = processor, #2 = given n, #3 = lower bound (inclusive)
3861 \ifnum#2<#3\relax
3862 \forest@process@check@n@error{#1}{#2}{#3<=}{}%
3863 \fi
3864 }
3865 \def\forest@process@check@n@error#1#2#3#4{%
3866 \PackageError{forest}{'.process' instruction '#1' requires a numeric modifier #3n#4, but n="#2" was given.}{}%
3867 }
3868 \newif\ifforest@process@W
3869 \forest@def@processor{w}{1}{}{% consuming wrap: first test 1<=#1<=9
3870 \forest@process@Wtrue
3871 \forest@process@check@mn{w}{0\the\forest@process@n}{1}{9}%
3872 \expandafter\forest@processor@wW@\expandafter{\the\forest@process@n}%
3873 }
3874 \forest@def@processor{W}{1}{}{% nonconsuming wrap: first test 1<=#1<=9
3875 \forest@process@Wfalse
3876 \forest@process@check@mn{W}{0\the\forest@process@n}{1}{9}%
3877 \expandafter\forest@processor@wW@\expandafter{\the\forest@process@n}%
3878 }
3879 \def\forest@processor@wW@#1{%
3880 \forest@process@left@checkindex{\forest@process@left@N-#1}%
3881 \edef\forest@marshal{%
3882 \edef\noexpand\forest@temp@args{%
3883 \noexpand\forest@process@left@valuesfromrange
3884 {\number\numexpr\forest@process@left@N-#1}%
3885 {\the\forest@process@left@N}%
3886 }%
3887 }\forest@marshal
3888 \ifforest@process@W
3889 \advance\forest@process@left@N-#1\relax
3890 \fi
3891 \forest@process@right@bottompop\forest@temp@macrobody
3892 \expandafter\forest@def@n\expandafter\forest@process@temp@macro\expandafter{\expandafter#1\expandafter}\expandafter{\forest@temp@macrobody}%
3893 \expandafter\expandafter\expandafter\forest@process@left@setappend\expandafter\expandafter\expandafter{\expandafter\forest@process@temp@macro\forest@temp@args}%
3894 \let\forestmathresulttype\forestmathtype@generic
3895 }
3896 \def\forest@def@n#1#2{\csname forest@def@n@#2\endcsname#1}
3897 \csdef{forest@def@n@1}#1{\def#1##1}
3898 \csdef{forest@def@n@2}#1{\def#1##1##2}
3899 \csdef{forest@def@n@3}#1{\def#1##1##2##3}
3900 \csdef{forest@def@n@4}#1{\def#1##1##2##3##4}
3901 \csdef{forest@def@n@5}#1{\def#1##1##2##3##4##5}
3902 \csdef{forest@def@n@6}#1{\def#1##1##2##3##4##5##6}
3903 \csdef{forest@def@n@7}#1{\def#1##1##2##3##4##5##6##7}
3904 \csdef{forest@def@n@8}#1{\def#1##1##2##3##4##5##6##7##8}
3905 \csdef{forest@def@n@9}#1{\def#1##1##2##3##4##5##6##7##8##9}
3906 % \end{macrocode}
3907 % Save last |n| arguments from the left side into a special place. |s| deletes them from the left side, |S| keeps them there as well.
3908 % \begin{macrocode}
3909 \forest@def@processor{s}{1}{}{%
3910 \forest@temptrue % delete the originals
3911 \expandafter\forest@processor@save\expandafter{%
3912 \the\numexpr\forest@process@left@N-\forest@process@n}}
3913 \forest@def@processor{S}{1}{}{%
3914 \forest@tempfalse % keep the originals
3915 \expandafter\forest@processor@save\expandafter{%
3916 \the\numexpr\forest@process@left@N-\forest@process@n}}
3917 \def\forest@processor@save#1{%
3918 \forest@process@left@checkindex{#1}%
3919 \forest@temp@count#1
3920 \forest@loop
3921 \ifnum\forest@temp@count<\forest@process@left@N\relax
3922 \forest@process@left@get@{\the\forest@temp@count}\forest@temp
3923 \forest@process@saved@letappend\forest@temp
3924 \advance\forest@temp@count+1
3925 \forest@repeat
3926 \let\forest@process@savedtype\forestmathresulttype
3927 \ifforest@temp
3928 \forest@process@left@N=#1
3929 \fi
3930 }
3931 % \end{macrocode}
3932 % Load |n| arguments from the end of the special place to the left side. If $n=0$, load the entire special place. |l| deletes the args from the special place, |L| keeps them there as well.
3933 % \begin{macrocode}
3934 \forest@def@processor{l}{0}{}{%
3935 \forest@temptrue
3936 \forest@processor@U@@
3937 }
3938 \forest@def@processor{L}{0}{}{%
3939 \forest@tempfalse
3940 \forest@processor@U@@
3941 }
3942
3943 \def\forest@processor@U@@{%
3944 \ifnum\forest@process@n=0
3945 \forest@process@n\forest@process@saved@N\relax
3946 \fi
3947 \expandafter\forest@processor@U@@@\expandafter{%
3948 \the\numexpr\forest@process@saved@N-\forest@process@n}%
3949 }
3950 \def\forest@processor@U@@@#1{%
3951 \forest@temp@count#1
3952 \forest@loop
3953 \ifnum\forest@temp@count<\forest@process@saved@N\relax
3954 \forest@process@saved@get@{\the\forest@temp@count}\forest@temp
3955 \forest@process@left@letappend\forest@temp
3956 \advance\forest@temp@count1
3957 \forest@repeat
3958 \let\forestmathresulttype\forest@process@savedtype
3959 \ifforest@temp
3960 \let\forest@process@savedtype\forestmathtype@none
3961 \forest@process@saved@N#1
3962 \fi
3963 }
3964 % \end{macrocode}
3965 % Boolean operations:
3966 % \begin{macrocode}
3967 \forest@def@processor{&}{2}{}{% and
3968 \def\forest@tempa{1}%
3969 \forest@repeat@n@times{\forest@process@n}{%
3970 \forest@process@left@toppop\forest@tempb
3971 \edef\forest@tempa{\ifnum10<\forest@tempa\forest@tempb\space 1\else0\fi}%
3972 }%
3973 \forest@process@left@esetappend{\forest@tempa}%
3974 \let\forestmathresulttype\forestmathtype@count
3975 }
3976 \forest@def@processor{|}{2}{}{% or
3977 \def\forest@tempa{0}%
3978 \forest@repeat@n@times{\forest@process@n}{%
3979 \forest@process@left@toppop\forest@tempb
3980 \edef\forest@tempa{\ifnum0=\forest@tempa\forest@tempb\space 0\else1\fi}%
3981 }%
3982 \forest@process@left@esetappend{\forest@tempa}%
3983 \let\forestmathresulttype\forestmathtype@count
3984 }
3985 \forest@def@processor{!}{}{}{% not
3986 \forest@process@left@toppop\forest@temp
3987 \forest@process@left@esetappend{\ifnum0=\forest@temp\space 1\else0\fi}%
3988 \let\forestmathresulttype\forestmathtype@count
3989 }
3990 \forest@def@processor{?}{}{}{%
3991 \forest@process@left@toppop\forest@temp
3992 \forest@process@right@bottompop\forest@tempa
3993 \forest@process@right@bottompop\forest@tempb
3994 \ifnum\forest@temp=0
3995 \forest@process@right@letprepend\forest@tempb
3996 \else
3997 \forest@process@right@letprepend\forest@tempa
3998 \fi
3999 \let\forestmathresulttype\forestmathtype@generic
4000 }
4001 % \end{macrocode}
4002 % Comparisons. They automatically determine the type (number, dimen, other) of the arguments, by checking what the last processing instruction was.
4003 % \begin{macrocode}
4004 \forest@def@processor{=}{}{}{%
4005 \forest@process@left@toppop\forest@tempa
4006 \forest@process@left@toppop\forest@tempb
4007 \forest@process@left@esetappend{\ifx\forest@tempa\forest@tempb 1\else0\fi}%
4008 \let\forestmathresulttype\forestmathtype@count
4009 }
4010 \forest@def@processor{<}{}{}{%
4011 \forest@process@left@toppop\forest@tempb
4012 \forest@process@left@toppop\forest@tempa
4013 \ifx\forestmathresulttype\forestmathtype@generic
4014 \forest@cmp@error\forest@tempa\forest@tempb
4015 \else
4016 \forestmathlt{\forest@tempa}{\forest@tempb}%
4017 \forest@process@left@esetappend{\forestmathresult}%
4018 \fi
4019 }
4020 \forest@def@processor{>}{}{}{%
4021 \forest@process@left@toppop\forest@tempb
4022 \forest@process@left@toppop\forest@tempa
4023 \ifx\forestmathresulttype\forestmathtype@generic
4024 \forest@cmp@error\forest@tempa\forest@tempb
4025 \else
4026 \forestmathgt{\forest@tempa}{\forest@tempb}%
4027 \forest@process@left@esetappend{\forestmathresult}%
4028 \fi
4029 }
4030 % \end{macrocode}
4031 % Various.
4032 % \begin{macrocode}
4033 \forest@def@processor{r}{}{}{% reverse keylist
4034 \forest@process@right@bottompop\forest@temp
4035 \expandafter\forest@processor@r@\expandafter{\forest@temp}%
4036 }
4037 \def\forest@processor@r@#1{%
4038 \forest@process@left@esetappend{}%
4039 \def\forest@tempcomma{}%
4040 \pgfqkeys{/forest}{split={#1}{,}{process@rk}}%
4041 \let\forestmathresulttype\forestmathtype@generic
4042 }
4043 \forestset{%
4044 process@rk/.code={%
4045 \forest@process@left@toppop\forest@temp
4046 \forest@temp@toks{#1}%
4047 \forest@process@left@esetappend{\the\forest@temp@toks\forest@tempcomma\expandonce{\forest@temp}}%
4048 \def\forest@tempcomma{,}%
4049 }%
4050 }
4051 % \end{macrocode}
4052 %
4053 % \subsubsection{Registers}
4054 % Register declaration mechanism is an adjusted copy-paste of the option declaration mechanism.
4055 % \begin{macrocode}
4056 \def\forest@pgfmathhelper@register@toks#1#2{% #1 is discarded: it is present only for analogy with options
4057 \forestrget{#2}\pgfmathresult
4058 }
4059 \def\forest@pgfmathhelper@register@dimen#1#2{%
4060 \forestrget{#2}\forest@temp
4061 \edef\pgfmathresult{\expandafter\Pgf@geT\forest@temp}%
4062 }
4063 \def\forest@pgfmathhelper@register@count#1#2{%
4064 \forestrget{#2}\pgfmathresult
4065 }
4066 \def\forest@declareregisterhandler#1#2{%#1=handler for specific type,#2=option name
4067 \pgfkeyssetvalue{/forest/#2/node@or@reg}{}% empty = register (node id=node)
4068 \forest@convert@others@to@underscores{#2}\forest@pgfmathoptionname
4069 \edef\forest@marshal{%
4070 \noexpand#1{/forest/#2}{/forest}{#2}{\forest@pgfmathoptionname}%
4071 }\forest@marshal
4072 }
4073 \def\forest@declaretoksregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
4074 \forest@declaretoksregister@handler@A{#1}{#2}{#3}{#4}{}%
4075 }
4076 \def\forest@declarekeylistregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
4077 \forest@declaretoksregister@handler@A{#1}{#2}{#3}{#4}{,}%
4078 \forest@copycommandkey{#1}{#1'}%
4079 \pgfkeyssetvalue{#1'/option@name}{#3}%
4080 \forest@copycommandkey{#1+}{#1}%
4081 \pgfkeysalso{#1-/.code={%
4082 \forest@fornode{}{%
4083 \forest@node@removekeysfromkeylist{##1}{#3}%
4084 }}}%
4085 \pgfkeyssetvalue{#1-/option@name}{#3}%
4086 }
4087 \def\forest@declaretoksregister@handler@A#1#2#3#4#5{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
4088 \pgfkeysalso{%
4089 #1/.code={\forestrset{#3}{##1}},
4090 #2/if #3/.code n args={3}{%
4091 \forestrget{#3}\forest@temp@option@value
4092 \edef\forest@temp@compared@value{\unexpanded{##1}}%
4093 \ifx\forest@temp@option@value\forest@temp@compared@value
4094 \pgfkeysalso{##2}%
4095 \else
4096 \pgfkeysalso{##3}%
4097 \fi
4098 },
4099 #2/if in #3/.code n args={3}{%
4100 \forestrget{#3}\forest@temp@option@value
4101 \edef\forest@temp@compared@value{\unexpanded{##1}}%
4102 \expandafter\expandafter\expandafter\pgfutil@in@\expandafter\expandafter\expandafter{\expandafter\forest@temp@compared@value\expandafter}\expandafter{\forest@temp@option@value}%
4103 \ifpgfutil@in@
4104 \pgfkeysalso{##2}%
4105 \else
4106 \pgfkeysalso{##3}%
4107 \fi
4108 },
4109 }%
4110 \ifstrempty{#5}{%
4111 \pgfkeysalso{%
4112 #1+/.code={\forestrappto{#3}{#5##1}},
4113 #2/+#3/.code={\forestrpreto{#3}{##1#5}},
4114 }%
4115 }{%
4116 \pgfkeysalso{%
4117 #1+/.code={%
4118 \forestrget{#3}\forest@temp
4119 \ifdefempty{\forest@temp}{%
4120 \forestrset{#3}{##1}%
4121 }{%
4122 \forestrappto{#3}{#5##1}%
4123 }%
4124 },
4125 #2/+#3/.code={%
4126 \forestrget{#3}\forest@temp
4127 \ifdefempty{\forest@temp}{%
4128 \forestrset{#3}{##1}%
4129 }{%
4130 \forestrpreto{#3}{##1#5}%
4131 }%
4132 }%
4133 }%
4134 }%
4135 \pgfkeyssetvalue{#1/option@name}{#3}%
4136 \pgfkeyssetvalue{#1+/option@name}{#3}%
4137 \pgfkeyssetvalue{#2/+#3/option@name}{#3}%
4138 \pgfkeyslet{#1/@type}\forestmathtype@generic % for .process & co
4139 \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@toks{##1}{#3}}%
4140 }
4141 \def\forest@declareautowrappedtoksregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
4142 \forest@declaretoksregister@handler{#1}{#2}{#3}{#4}%
4143 \forest@copycommandkey{#1}{#1'}%
4144 \pgfkeysalso{#1/.style={#1'/.wrap value={##1}}}%
4145 \pgfkeyssetvalue{#1'/option@name}{#3}%
4146 \forest@copycommandkey{#1+}{#1+'}%
4147 \pgfkeysalso{#1+/.style={#1+'/.wrap value={##1}}}%
4148 \pgfkeyssetvalue{#1+'/option@name}{#3}%
4149 \forest@copycommandkey{#2/+#3}{#2/+#3'}%
4150 \pgfkeysalso{#2/+#3/.style={#2/+#3'/.wrap value={##1}}}%
4151 \pgfkeyssetvalue{#2/+#3'/option@name}{#3}%
4152 }
4153 \def\forest@declarereadonlydimenregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
4154 \pgfkeysalso{%
4155 #2/if #3/.code n args={3}{%
4156 \forestrget{#3}\forest@temp@option@value
4157 \ifdim\forest@temp@option@value=##1\relax
4158 \pgfkeysalso{##2}%
4159 \else
4160 \pgfkeysalso{##3}%
4161 \fi
4162 },
4163 #2/if #3</.code n args={3}{%
4164 \forestrget{#3}\forest@temp@option@value
4165 \ifdim\forest@temp@option@value>##1\relax
4166 \pgfkeysalso{##3}%
4167 \else
4168 \pgfkeysalso{##2}%
4169 \fi
4170 },
4171 #2/if #3>/.code n args={3}{%
4172 \forestrget{#3}\forest@temp@option@value
4173 \ifdim\forest@temp@option@value<##1\relax
4174 \pgfkeysalso{##3}%
4175 \else
4176 \pgfkeysalso{##2}%
4177 \fi
4178 },
4179 }%
4180 \pgfkeyslet{#1/@type}\forestmathtype@dimen % for .process & co
4181 \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@dimen{##1}{#3}}%
4182 }
4183 \def\forest@declaredimenregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
4184 \forest@declarereadonlydimenregister@handler{#1}{#2}{#3}{#4}%
4185 \pgfkeysalso{%
4186 #1/.code={%
4187 \forestmathsetlengthmacro\forest@temp{##1}%
4188 \forestrlet{#3}\forest@temp
4189 },
4190 #1+/.code={%
4191 \forestmathsetlengthmacro\forest@temp{##1}%
4192 \pgfutil@tempdima=\forestrve{#3}
4193 \advance\pgfutil@tempdima\forest@temp\relax
4194 \forestreset{#3}{\the\pgfutil@tempdima}%
4195 },
4196 #1-/.code={%
4197 \forestmathsetlengthmacro\forest@temp{##1}%
4198 \pgfutil@tempdima=\forestrve{#3}
4199 \advance\pgfutil@tempdima-\forest@temp\relax
4200 \forestreset{#3}{\the\pgfutil@tempdima}%
4201 },
4202 #1*/.style={%
4203 #1={#4()*(##1)}%
4204 },
4205 #1:/.style={%
4206 #1={#4()/(##1)}%
4207 },
4208 #1'/.code={%
4209 \pgfutil@tempdima=##1\relax
4210 \forestreset{#3}{\the\pgfutil@tempdima}%
4211 },
4212 #1'+/.code={%
4213 \pgfutil@tempdima=\forestrve{#3}\relax
4214 \advance\pgfutil@tempdima##1\relax
4215 \forestreset{#3}{\the\pgfutil@tempdima}%
4216 },
4217 #1'-/.code={%
4218 \pgfutil@tempdima=\forestrve{#3}\relax
4219 \advance\pgfutil@tempdima-##1\relax
4220 \forestreset{#3}{\the\pgfutil@tempdima}%
4221 },
4222 #1'*/.style={%
4223 \pgfutil@tempdima=\forestrve{#3}\relax
4224 \multiply\pgfutil@tempdima##1\relax
4225 \forestreset{#3}{\the\pgfutil@tempdima}%
4226 },
4227 #1':/.style={%
4228 \pgfutil@tempdima=\forestrve{#3}\relax
4229 \divide\pgfutil@tempdima##1\relax
4230 \forestreset{#3}{\the\pgfutil@tempdima}%
4231 },
4232 }%
4233 \pgfkeyssetvalue{#1/option@name}{#3}%
4234 \pgfkeyssetvalue{#1+/option@name}{#3}%
4235 \pgfkeyssetvalue{#1-/option@name}{#3}%
4236 \pgfkeyssetvalue{#1*/option@name}{#3}%
4237 \pgfkeyssetvalue{#1:/option@name}{#3}%
4238 \pgfkeyssetvalue{#1'/option@name}{#3}%
4239 \pgfkeyssetvalue{#1'+/option@name}{#3}%
4240 \pgfkeyssetvalue{#1'-/option@name}{#3}%
4241 \pgfkeyssetvalue{#1'*/option@name}{#3}%
4242 \pgfkeyssetvalue{#1':/option@name}{#3}%
4243 }
4244 \def\forest@declarereadonlycountregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
4245 \pgfkeysalso{
4246 #2/if #3/.code n args={3}{%
4247 \forestrget{#3}\forest@temp@option@value
4248 \ifnum\forest@temp@option@value=##1\relax
4249 \pgfkeysalso{##2}%
4250 \else
4251 \pgfkeysalso{##3}%
4252 \fi
4253 },
4254 #2/if #3</.code n args={3}{%
4255 \forestrget{#3}\forest@temp@option@value
4256 \ifnum\forest@temp@option@value>##1\relax
4257 \pgfkeysalso{##3}%
4258 \else
4259 \pgfkeysalso{##2}%
4260 \fi
4261 },
4262 #2/if #3>/.code n args={3}{%
4263 \forestrget{#3}\forest@temp@option@value
4264 \ifnum\forest@temp@option@value<##1\relax
4265 \pgfkeysalso{##3}%
4266 \else
4267 \pgfkeysalso{##2}%
4268 \fi
4269 },
4270 }%
4271 \pgfkeyslet{#1/@type}\forestmathtype@count % for .process & co
4272 \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@count{##1}{#3}}%
4273 }
4274 \def\forest@declarecountregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
4275 \forest@declarereadonlycountregister@handler{#1}{#2}{#3}{#4}%
4276 \pgfkeysalso{
4277 #1/.code={%
4278 \forestmathtruncatemacro\forest@temp{##1}%
4279 \forestrlet{#3}\forest@temp
4280 },
4281 #1+/.code={%
4282 \forestmathtruncatemacro\forest@temp{##1}%
4283 \c@pgf@counta=\forestrve{#3}\relax
4284 \advance\c@pgf@counta\forest@temp\relax
4285 \forestreset{#3}{\the\c@pgf@counta}%
4286 },
4287 #1-/.code={%
4288 \forestmathtruncatemacro\forest@temp{##1}%
4289 \c@pgf@counta=\forestrve{#3}\relax
4290 \advance\c@pgf@counta-\forest@temp\relax
4291 \forestreset{#3}{\the\c@pgf@counta}%
4292 },
4293 #1*/.code={%
4294 \forestmathtruncatemacro\forest@temp{##1}%
4295 \c@pgf@counta=\forestrve{#3}\relax
4296 \multiply\c@pgf@counta\forest@temp\relax
4297 \forestreset{#3}{\the\c@pgf@counta}%
4298 },
4299 #1:/.code={%
4300 \forestmathtruncatemacro\forest@temp{##1}%
4301 \c@pgf@counta=\forestrve{#3}\relax
4302 \divide\c@pgf@counta\forest@temp\relax
4303 \forestreset{#3}{\the\c@pgf@counta}%
4304 },
4305 #1'/.code={%
4306 \c@pgf@counta=##1\relax
4307 \forestreset{#3}{\the\c@pgf@counta}%
4308 },
4309 #1'+/.code={%
4310 \c@pgf@counta=\forestrve{#3}\relax
4311 \advance\c@pgf@counta##1\relax
4312 \forestreset{#3}{\the\c@pgf@counta}%
4313 },
4314 #1'-/.code={%
4315 \c@pgf@counta=\forestrve{#3}\relax
4316 \advance\c@pgf@counta-##1\relax
4317 \forestreset{#3}{\the\c@pgf@counta}%
4318 },
4319 #1'*/.style={%
4320 \c@pgf@counta=\forestrve{#3}\relax
4321 \multiply\c@pgf@counta##1\relax
4322 \forestreset{#3}{\the\c@pgf@counta}%
4323 },
4324 #1':/.style={%
4325 \c@pgf@counta=\forestrve{#3}\relax
4326 \divide\c@pgf@counta##1\relax
4327 \forestreset{#3}{\the\c@pgf@counta}%
4328 },
4329 }%
4330 \pgfkeyssetvalue{#1/option@name}{#3}%
4331 \pgfkeyssetvalue{#1+/option@name}{#3}%
4332 \pgfkeyssetvalue{#1-/option@name}{#3}%
4333 \pgfkeyssetvalue{#1*/option@name}{#3}%
4334 \pgfkeyssetvalue{#1:/option@name}{#3}%
4335 \pgfkeyssetvalue{#1'/option@name}{#3}%
4336 \pgfkeyssetvalue{#1'+/option@name}{#3}%
4337 \pgfkeyssetvalue{#1'-/option@name}{#3}%
4338 \pgfkeyssetvalue{#1'*/option@name}{#3}%
4339 \pgfkeyssetvalue{#1':/option@name}{#3}%
4340 }
4341 \def\forest@declarebooleanregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
4342 \pgfkeysalso{%
4343 #1/.code={%
4344 \ifcsdef{forest@bh@\detokenize{##1}}{%
4345 \letcs\forest@temp{forest@bh@\detokenize{##1}}%
4346 }{%
4347 \forestmathtruncatemacro\forest@temp{##1}%
4348 \ifx\forest@temp0\else\def\forest@temp{1}\fi
4349 }%
4350 \forestrlet{#3}\forest@temp
4351 },
4352 #1/.default=1,
4353 #2/not #3/.code={\forestrset{#3}{0}},
4354 #2/if #3/.code 2 args={%
4355 \forestrget{#3}\forest@temp@option@value
4356 \ifnum\forest@temp@option@value=1
4357 \pgfkeysalso{##1}%
4358 \else
4359 \pgfkeysalso{##2}%
4360 \fi
4361 },
4362 }%
4363 \pgfkeyssetvalue{#1/option@name}{#3}%
4364 \pgfkeyslet{#1/@type}\forestmathtype@count % for .process & co
4365 \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@count{##1}{#3}}%
4366 }
4367 \forestset{
4368 declare toks register/.code={%
4369 \forest@declareregisterhandler\forest@declaretoksregister@handler{#1}%
4370 \forestset{#1={}}%
4371 },
4372 declare autowrapped toks register/.code={%
4373 \forest@declareregisterhandler\forest@declareautowrappedtoksregister@handler{#1}%
4374 \forestset{#1={}}%
4375 },
4376 declare keylist register/.code={%
4377 \forest@declareregisterhandler\forest@declarekeylistregister@handler{#1}%
4378 \forestset{#1'={}}%
4379 },
4380 declare dimen register/.code={%
4381 \forest@declareregisterhandler\forest@declaredimenregister@handler{#1}%
4382 \forestset{#1'=0pt}%
4383 },
4384 declare count register/.code={%
4385 \forest@declareregisterhandler\forest@declarecountregister@handler{#1}%
4386 \forestset{#1'=0}%
4387 },
4388 declare boolean register/.code={%
4389 \forest@declareregisterhandler\forest@declarebooleanregister@handler{#1}%
4390 \forestset{#1=0}%
4391 },
4392 }
4393 % \end{macrocode}
4394 % Declare some temporary registers.
4395 % \begin{macrocode}
4396 \forestset{
4397 declare toks register=temptoksa,temptoksa={},
4398 declare toks register=temptoksb,temptoksb={},
4399 declare toks register=temptoksc,temptoksc={},
4400 declare toks register=temptoksd,temptoksd={},
4401 declare keylist register=tempkeylista,tempkeylista'={},
4402 declare keylist register=tempkeylistb,tempkeylistb'={},
4403 declare keylist register=tempkeylistc,tempkeylistc'={},
4404 declare keylist register=tempkeylistd,tempkeylistd'={},
4405 declare dimen register=tempdima,tempdima'={0pt},
4406 declare dimen register=tempdimb,tempdimb'={0pt},
4407 declare dimen register=tempdimc,tempdimc'={0pt},
4408 declare dimen register=tempdimd,tempdimd'={0pt},
4409 declare dimen register=tempdimx,tempdimx'={0pt},
4410 declare dimen register=tempdimxa,tempdimxa'={0pt},
4411 declare dimen register=tempdimxb,tempdimxb'={0pt},
4412 declare dimen register=tempdimy,tempdimy'={0pt},
4413 declare dimen register=tempdimya,tempdimya'={0pt},
4414 declare dimen register=tempdimyb,tempdimyb'={0pt},
4415 declare dimen register=tempdiml,tempdiml'={0pt},
4416 declare dimen register=tempdimla,tempdimla'={0pt},
4417 declare dimen register=tempdimlb,tempdimlb'={0pt},
4418 declare dimen register=tempdims,tempdims'={0pt},
4419 declare dimen register=tempdimsa,tempdimsa'={0pt},
4420 declare dimen register=tempdimsb,tempdimsb'={0pt},
4421 declare count register=tempcounta,tempcounta'={0},
4422 declare count register=tempcountb,tempcountb'={0},
4423 declare count register=tempcountc,tempcountc'={0},
4424 declare count register=tempcountd,tempcountd'={0},
4425 declare boolean register=tempboola,tempboola={0},
4426 declare boolean register=tempboolb,tempboolb={0},
4427 declare boolean register=tempboolc,tempboolc={0},
4428 declare boolean register=tempboold,tempboold={0},
4429 }
4430 % \end{macrocode}
4431 % \subsubsection{Declaring options}
4432 %
4433 % \begin{macrocode}
4434 \def\forest@node@Nametoid#1{% #1 = name
4435 \csname forest@id@of@#1\endcsname
4436 }
4437 \def\forest@node@Ifnamedefined#1#2#3{% #1 = name, #2=true,#3=false
4438 \ifcsvoid{forest@id@of@#1}{#3}{#2}%
4439 }
4440 \def\forest@node@setname#1{%
4441 \def\forest@temp@setname{y}%
4442 \def\forest@temp@silent{n}%
4443 \def\forest@temp@propagating{n}%
4444 \forest@node@setnameoralias{#1}%
4445 }
4446 \def\forest@node@setname@silent#1{%
4447 \def\forest@temp@setname{y}%
4448 \def\forest@temp@silent{y}%
4449 \def\forest@temp@propagating{n}%
4450 \forest@node@setnameoralias{#1}%
4451 }
4452 \def\forest@node@setalias#1{%
4453 \def\forest@temp@setname{n}%
4454 \def\forest@temp@silent{n}%
4455 \def\forest@temp@propagating{n}%
4456 \forest@node@setnameoralias{#1}%
4457 }
4458 \def\forest@node@setalias@silent#1{%
4459 \def\forest@temp@setname{n}%
4460 \def\forest@temp@silent{y}%
4461 \def\forest@temp@propagating{n}%
4462 \forest@node@setnameoralias{#1}%
4463 }
4464 \def\forest@node@setnameoralias#1{%
4465 \ifstrempty{#1}{%
4466 \forest@node@setnameoralias{node@\forest@cn}%
4467 }{%
4468 \forest@node@Ifnamedefined{#1}{%
4469 \if y\forest@temp@propagating
4470 % this will find a unique name, eventually:
4471 \@escapeif{\forest@node@setnameoralias{#1@\forest@cn}}%
4472 \else\@escapeif{%
4473 \if y\forest@temp@setname
4474 \edef\forest@marshal{%
4475 \ifstrequal{\forestove{name}}{#1}%
4476 }\forest@marshal{%
4477 % same name, no problem
4478 }{%
4479 \@escapeif{\forest@node@setnameoralias@nameclash{#1}}%
4480 }%
4481 \else\@escapeif{% setting an alias: clashing with alias is not a problem
4482 \forestOget{\forest@node@Nametoid{#1}}{name}\forest@temp
4483 \expandafter\ifstrequal\expandafter{\forest@temp}{#1}{%
4484 \forest@node@setnameoralias@nameclash{#1}%
4485 }{%
4486 \forest@node@setnameoralias@do{#1}%
4487 }%
4488 }\fi
4489 }\fi
4490 }{%
4491 \forest@node@setnameoralias@do{#1}%
4492 }%
4493 }%
4494 }
4495 \def\forest@node@setnameoralias@nameclash#1{%
4496 \if y\forest@temp@silent
4497 \forest@fornode{\forest@node@Nametoid{#1}}{%
4498 \def\forest@temp@propagating{y}%
4499 \forest@node@setnameoralias{}%
4500 }%
4501 \forest@node@setnameoralias@do{#1}%
4502 \else
4503 \PackageError{forest}{Node name "#1" is already used}{}%
4504 \fi
4505 }
4506 \def\forest@node@setnameoralias@do#1{%
4507 \if y\forest@temp@setname
4508 \csdef{forest@id@of@\forestove{name}}{}%
4509 \forestoeset{name}{#1}%
4510 \fi
4511 \csedef{forest@id@of@#1}{\forest@cn}%
4512 }
4513 \forestset{
4514 TeX/.code={#1},
4515 TeX'/.code={\appto\forest@externalize@loadimages{#1}#1},
4516 TeX''/.code={\appto\forest@externalize@loadimages{#1}},
4517 options/.code={\forestset{#1}},
4518 also/.code={\pgfkeysalso{#1}},
4519 typeout/.style={TeX={\typeout{#1}}},
4520 declare toks={name}{},
4521 name/.code={% override the default setter
4522 \forest@fornode{\forest@setter@node}{\forest@node@setname{#1}}%
4523 },
4524 name/.default={},
4525 name'/.code={% override the default setter
4526 \forest@fornode{\forest@setter@node}{\forest@node@setname@silent{#1}}%
4527 },
4528 name'/.default={},
4529 alias/.code={\forest@fornode{\forest@setter@node}{\forest@node@setalias{#1}}},
4530 alias'/.code={\forest@fornode{\forest@setter@node}{\forest@node@setalias@silent{#1}}},
4531 begin draw/.code={\begin{tikzpicture}},
4532 end draw/.code={\end{tikzpicture}},
4533 declare keylist register=default preamble,
4534 default preamble'={},
4535 declare keylist register=preamble,
4536 preamble'={},
4537 declare autowrapped toks={content}{},
4538 % #1 = which option to split, #2 = separator (one char!), #3 = receiving options
4539 split option/.code n args=3{%
4540 \forestRNOget{#1}\forest@temp
4541 \edef\forest@marshal{%
4542 \noexpand\pgfkeysalso{split={\expandonce{\forest@temp}}\unexpanded{{#2}{#3}}}%
4543 }\forest@marshal
4544 },
4545 split register/.code n args=3{% #1 = which register to split, #2 = separator (one char!), #3 = receiving options
4546 \forestrget{#1}\forest@temp
4547 \edef\forest@marshal{%
4548 \noexpand\pgfkeysalso{split={\expandonce{\forest@temp}}\unexpanded{{#2}{#3}}}%
4549 }\forest@marshal
4550 },
4551 TeX={%
4552 \def\forest@split@sourcevalues{}%
4553 \def\forest@split@sourcevalue{}%
4554 \def\forest@split@receivingoptions{}%
4555 \def\forest@split@receivingoption{}%
4556 },
4557 split/.code n args=3{% #1 = string to split, #2 = separator (one char!), #3 = receiving options
4558 \forest@saveandrestoremacro\forest@split@sourcevalues{%
4559 \forest@saveandrestoremacro\forest@split@sourcevalue{%
4560 \forest@saveandrestoremacro\forest@split@receivingoptions{%
4561 \forest@saveandrestoremacro\forest@split@receivingoption{%
4562 \def\forest@split@sourcevalues{#1#2}%
4563 \edef\forest@split@receivingoptions{#3,}%
4564 \def\forest@split@receivingoption{}%
4565 \safeloop
4566 \expandafter\forest@split\expandafter{\forest@split@sourcevalues}{#2}\forest@split@sourcevalue\forest@split@sourcevalues
4567 \ifdefempty\forest@split@receivingoptions{}{%
4568 \expandafter\forest@split\expandafter{\forest@split@receivingoptions}{,}\forest@temp\forest@split@receivingoptions
4569 \ifdefempty\forest@temp{}{\let\forest@split@receivingoption\forest@temp\def\forest@temp{}}%
4570 }%
4571 \edef\forest@marshal{%
4572 \noexpand\pgfkeysalso{\forest@split@receivingoption={\expandonce{\forest@split@sourcevalue}}}%
4573 }\forest@marshal
4574 \ifdefempty\forest@split@sourcevalues{\forest@tempfalse}{\forest@temptrue}%
4575 \ifforest@temp
4576 \saferepeat
4577 }}}}%
4578 },
4579 declare count={grow}{270},
4580 TeX={% a hack for grow-reversed connection, and compass-based grow specification
4581 \forest@copycommandkey{/forest/grow}{/forest/grow@@}%
4582 %\pgfkeysgetvalue{/forest/grow/.@cmd}\forest@temp
4583 %\pgfkeyslet{/forest/grow@@/.@cmd}\forest@temp
4584 },
4585 grow/.style={grow@={#1},reversed=0},
4586 grow'/.style={grow@={#1},reversed=1},
4587 grow''/.style={grow@={#1}},
4588 grow@/.is choice,
4589 grow@/east/.style={/forest/grow@@=0},
4590 grow@/north east/.style={/forest/grow@@=45},
4591 grow@/north/.style={/forest/grow@@=90},
4592 grow@/north west/.style={/forest/grow@@=135},
4593 grow@/west/.style={/forest/grow@@=180},
4594 grow@/south west/.style={/forest/grow@@=225},
4595 grow@/south/.style={/forest/grow@@=270},
4596 grow@/south east/.style={/forest/grow@@=315},
4597 grow@/.unknown/.code={\let\forest@temp@grow\pgfkeyscurrentname
4598 \pgfkeysalso{/forest/grow@@/.expand once=\forest@temp@grow}},
4599 declare boolean={reversed}{0},
4600 declare toks={parent anchor}{},
4601 declare toks={child anchor}{},
4602 declare toks={anchor}{base},
4603 Autoforward={anchor}{
4604 node options-=anchor,
4605 node options+={anchor={##1}}
4606 },
4607 anchor'/.style={anchor@no@compass=true,anchor=#1},
4608 anchor+'/.style={anchor@no@compass=true,anchor+=#1},
4609 anchor-'/.style={anchor@no@compass=true,anchor-=#1},
4610 anchor*'/.style={anchor@no@compass=true,anchor*=#1},
4611 anchor:'/.style={anchor@no@compass=true,anchor:=#1},
4612 anchor'+'/.style={anchor@no@compass=true,anchor'+=#1},
4613 anchor'-'/.style={anchor@no@compass=true,anchor'-=#1},
4614 anchor'*'/.style={anchor@no@compass=true,anchor'*=#1},
4615 anchor':'/.style={anchor@no@compass=true,anchor':=#1},
4616 % /tikz/forest anchor/.style={
4617 % /forest/TeX={\forestanchortotikzanchor{#1}\forest@temp@anchor},
4618 % anchor/.expand once=\forest@temp@anchor
4619 % },
4620 declare toks={calign}{midpoint},
4621 TeX={%
4622 \forest@copycommandkey{/forest/calign}{/forest/calign'}%
4623 },
4624 calign/.is choice,
4625 calign/child/.style={calign'=child},
4626 calign/first/.style={calign'=child,calign primary child=1},
4627 calign/last/.style={calign'=child,calign primary child=-1},
4628 calign with current/.style={for parent/.wrap pgfmath arg={calign=child,calign primary child=##1}{n}},
4629 calign with current edge/.style={for parent/.wrap pgfmath arg={calign=child edge,calign primary child=##1}{n}},
4630 calign/child edge/.style={calign'=child edge},
4631 calign/midpoint/.style={calign'=midpoint},
4632 calign/center/.style={calign'=midpoint,calign primary child=1,calign secondary child=-1},
4633 calign/edge midpoint/.style={calign'=edge midpoint},
4634 calign/fixed angles/.style={calign'=fixed angles},
4635 calign/fixed edge angles/.style={calign'=fixed edge angles},
4636 calign/.unknown/.code={\PackageError{forest}{unknown calign '\pgfkeyscurrentname'}{}},
4637 declare count={calign primary child}{1},
4638 declare count={calign secondary child}{-1},
4639 declare count={calign primary angle}{-35},
4640 declare count={calign secondary angle}{35},
4641 calign child/.style={calign primary child={#1}},
4642 calign angle/.style={calign primary angle={-#1},calign secondary angle={#1}},
4643 declare toks={tier}{},
4644 declare toks={fit}{tight},
4645 declare boolean={ignore}{0},
4646 declare boolean={ignore edge}{0},
4647 no edge/.style={edge'={},ignore edge},
4648 declare keylist={edge}{draw},
4649 declare toks={edge path}{%
4650 \noexpand\path[\forestoption{edge}]%
4651 (\forestOve{\forestove{@parent}}{name}.parent anchor)--(\forestove{name}.child anchor)
4652 % =
4653 % (!u.parent anchor)--(.child anchor)\forestoption{edge label};
4654 \forestoption{edge label};%
4655 },
4656 edge path'/.style={
4657 edge path={%
4658 \noexpand\path[\forestoption{edge}]%
4659 #1%
4660 \forestoption{edge label};
4661 }
4662 },
4663 declare toks={edge label}{},
4664 declare boolean={phantom}{0},
4665 baseline/.style={alias={forest@baseline@node}},
4666 declare readonly count={id}{0},
4667 declare readonly count={n}{0},
4668 declare readonly count={n'}{0},
4669 declare readonly count={n children}{-1},
4670 declare readonly count={level}{-1},
4671 declare dimen=x{0pt},
4672 declare dimen=y{0pt},
4673 declare dimen={s}{0pt},
4674 declare dimen={l}{6ex}, % just in case: should be set by the calibration
4675 declare dimen={s sep}{0.6666em},
4676 declare dimen={l sep}{1ex}, % just in case: calibration!
4677 declare keylist={node options}{anchor=base},
4678 declare toks={tikz}{},
4679 afterthought/.style={tikz+={#1}},
4680 label/.style={tikz+={\path[late options={%
4681 name=\forestoption{name},label={#1}}];}},
4682 pin/.style={tikz+={\path[late options={%
4683 name=\forestoption{name},pin={#1}}];}},
4684 declare toks={content format}{\forestoption{content}},
4685 plain content/.style={content format={\forestoption{content}}},
4686 math content/.style={content format={\noexpand\ensuremath{\forestoption{content}}}},
4687 declare toks={node format}{%
4688 \noexpand\node
4689 (\forestoption{name})%
4690 [\forestoption{node options}]%
4691 {\foresteoption{content format}};%
4692 },
4693 node format'/.style={
4694 node format={\noexpand\node(\forestoption{name})#1;}
4695 },
4696 tabular@environment/.style={content format={%
4697 \noexpand\begin{tabular}[\forestoption{base}]{\forestoption{align}}%
4698 \forestoption{content}%
4699 \noexpand\end{tabular}%
4700 }},
4701 declare toks={align}{},
4702 TeX={%
4703 \forest@copycommandkey{/forest/align}{/forest/align'}%
4704 %\pgfkeysgetvalue{/forest/align/.@cmd}\forest@temp
4705 %\pgfkeyslet{/forest/align'/.@cmd}\forest@temp
4706 },
4707 align/.is choice,
4708 align/.unknown/.code={%
4709 \edef\forest@marshal{%
4710 \noexpand\pgfkeysalso{%
4711 align'={\pgfkeyscurrentname},%
4712 tabular@environment
4713 }%
4714 }\forest@marshal
4715 },
4716 align/center/.style={align'={@{}c@{}},tabular@environment},
4717 align/left/.style={align'={@{}l@{}},tabular@environment},
4718 align/right/.style={align'={@{}r@{}},tabular@environment},
4719 declare toks={base}{t},
4720 TeX={%
4721 \forest@copycommandkey{/forest/base}{/forest/base'}%
4722 %\pgfkeysgetvalue{/forest/base/.@cmd}\forest@temp
4723 %\pgfkeyslet{/forest/base'/.@cmd}\forest@temp
4724 },
4725 base/.is choice,
4726 base/top/.style={base'=t},
4727 base/bottom/.style={base'=b},
4728 base/.unknown/.style={base'/.expand once=\pgfkeyscurrentname},
4729 unknown to/.store in=\forest@unknownto,
4730 unknown to=node options,
4731 unknown key error/.code={\PackageError{forest}{Unknown keyval: \detokenize{#1}}{}},
4732 content to/.store in=\forest@contentto,
4733 content to=content,
4734 .unknown/.code={%
4735 \expandafter\pgfutil@in@\expandafter.\expandafter{\pgfkeyscurrentname}%
4736 \ifpgfutil@in@
4737 \expandafter\forest@relatednode@option@setter\pgfkeyscurrentname=#1\forest@END
4738 \else
4739 \edef\forest@marshal{%
4740 \noexpand\pgfkeysalso{\forest@unknownto={\pgfkeyscurrentname=\unexpanded{#1}}}%
4741 }\forest@marshal
4742 \fi
4743 },
4744 get node boundary/.code={%
4745 \forestoget{@boundary}\forest@node@boundary
4746 \def#1{}%
4747 \forest@extendpath#1\forest@node@boundary{\pgfqpoint{\forestove{x}}{\forestove{y}}}%
4748 },
4749 % get min l tree boundary/.code={%
4750 % \forest@get@tree@boundary{negative}{\the\numexpr\forestove{grow}-90\relax}#1},
4751 % get max l tree boundary/.code={%
4752 % \forest@get@tree@boundary{positive}{\the\numexpr\forestove{grow}-90\relax}#1},
4753 get min s tree boundary/.code={%
4754 \forest@get@tree@boundary{negative}{\forestove{grow}}#1},
4755 get max s tree boundary/.code={%
4756 \forest@get@tree@boundary{positive}{\forestove{grow}}#1},
4757 use as bounding box/.style={%
4758 before drawing tree={
4759 tikz+/.expanded={%
4760 \noexpand\pgfresetboundingbox
4761 \noexpand\useasboundingbox
4762 ($(.anchor)+(\forestoption{min x},\forestoption{min y})$)
4763 rectangle
4764 ($(.anchor)+(\forestoption{max x},\forestoption{max y})$)
4765 ;
4766 }
4767 }
4768 },
4769 use as bounding box'/.style={%
4770 before drawing tree={
4771 tikz+/.expanded={%
4772 \noexpand\pgfresetboundingbox
4773 \noexpand\useasboundingbox
4774 ($(.anchor)+(\forestoption{min x}+\pgfkeysvalueof{/pgf/outer xsep}/2+\pgfkeysvalueof{/pgf/inner xsep},\forestoption{min y}+\pgfkeysvalueof{/pgf/outer ysep}/2+\pgfkeysvalueof{/pgf/inner ysep})$)
4775 rectangle
4776 ($(.anchor)+(\forestoption{max x}-\pgfkeysvalueof{/pgf/outer xsep}/2-\pgfkeysvalueof{/pgf/inner xsep},\forestoption{max y}-\pgfkeysvalueof{/pgf/outer ysep}/2-\pgfkeysvalueof{/pgf/inner ysep})$)
4777 ;
4778 }
4779 }
4780 },
4781 }%
4782 \def\forest@iftikzkey#1#2#3{% #1 = key name, #2 = true code, #3 = false code
4783 \forest@temptrue
4784 \pgfkeysifdefined{/tikz/\pgfkeyscurrentname}{}{%
4785 \pgfkeysifdefined{/tikz/\pgfkeyscurrentname/.@cmd}{}{%
4786 \pgfkeysifdefined{/pgf/\pgfkeyscurrentname}{}{%
4787 \pgfkeysifdefined{/pgf/\pgfkeyscurrentname/.@cmd}{}{%
4788 \forest@tempfalse
4789 }}}}%
4790 \ifforest@temp\@escapeif{#2}\else\@escapeif{#3}\fi
4791 }
4792 \def\forest@ifoptionortikzkey#1#2#3{% #1 = key name, #2 = true code, #3 = false code
4793 \forest@temptrue
4794 \pgfkeysifdefined{/forest/\pgfkeyscurrentname}{}{%
4795 \pgfkeysifdefined{/forest/\pgfkeyscurrentname/.@cmd}{}{%
4796 \forest@iftikzkey{#1}{}{}%
4797 }}%
4798 \ifforest@temp\@escapeif{#2}\else\@escapeif{#3}\fi
4799 }
4800 \def\forest@get@tree@boundary#1#2#3{%#1=pos/neg,#2=grow,#3=receiving cs
4801 \def#3{}%
4802 \forest@node@getedge{#1}{#2}\forest@temp@boundary
4803 \forest@extendpath#3\forest@temp@boundary{\pgfqpoint{\forestove{x}}{\forestove{y}}}%
4804 }
4805 \def\forest@setter@node{\forest@cn}%
4806 \def\forest@relatednode@option@compat@ignoreinvalidsteps#1{#1}
4807 \def\forest@relatednode@option@setter#1.#2=#3\forest@END{%
4808 \forest@forthis{%
4809 \forest@relatednode@option@compat@ignoreinvalidsteps{%
4810 \forest@nameandgo{#1}%
4811 \let\forest@setter@node\forest@cn
4812 }%
4813 }%
4814 \ifnum\forest@setter@node=0
4815 \else
4816 \forestset{#2={#3}}%
4817 \fi
4818 \def\forest@setter@node{\forest@cn}%
4819 }%
4820 \def\forest@split#1#2#3#4{% #1=list (assuming that the list is nonempty and finishes with the separator), #2 = sep, #3 = cs receiving first, #4 = cs receiving last
4821 \def\forest@split@@##1#2##2\forest@split@@##3##4{\def##3{##1}\def##4{##2}}%
4822 \forest@split@@#1\forest@split@@{#3}{#4}}
4823 % \end{macrocode}
4824 %
4825 % \subsubsection{Option propagation}
4826 %
4827 % The propagators targeting single nodes are automatically defined by nodewalk steps definitions.
4828 %
4829 % \begin{macrocode}
4830 \forestset{
4831 for tree'/.style 2 args={#1,for children={for tree'={#1}{#2}},#2},
4832 if/.code n args={3}{%
4833 \forestmathtruncatemacro\forest@temp{#1}%
4834 \ifnum\forest@temp=0
4835 \@escapeif{\pgfkeysalso{#3}}%
4836 \else
4837 \@escapeif{\pgfkeysalso{#2}}%
4838 \fi
4839 },
4840 %LaTeX if/.code n args={3}{#1{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}},
4841 if nodewalk valid/.code n args={3}{%
4842 \forest@forthis{%
4843 \forest@configured@nodewalk{independent}{inherited}{fake}{%
4844 #1,
4845 TeX={\global\let\forest@global@temp\forest@cn}
4846 }{}%
4847 }%
4848 \ifnum\forest@global@temp=0
4849 \@escapeif{\pgfkeysalso{#3}}%
4850 \else
4851 \@escapeif{\pgfkeysalso{#2}}%
4852 \fi
4853 },
4854 if nodewalk empty/.code n args={3}{%
4855 \forest@forthis{%
4856 \forest@configured@nodewalk{independent}{independent}{fake}{%
4857 #1,
4858 TeX={\global\let\forest@global@temp\forest@nodewalk@n},
4859 }{}%
4860 }%
4861 \ifnum\forest@global@temp=0
4862 \@escapeif{\pgfkeysalso{#2}}%
4863 \else
4864 \@escapeif{\pgfkeysalso{#3}}%
4865 \fi
4866 },
4867 if current nodewalk empty/.code 2 args={%
4868 \ifnum\forest@nodewalk@n=0
4869 \@escapeif{\pgfkeysalso{#1}}%
4870 \else
4871 \@escapeif{\pgfkeysalso{#2}}%
4872 \fi
4873 },
4874 where/.style n args={3}{for tree={if={#1}{#2}{#3}}},
4875 where nodewalk valid/.style n args={3}{for tree={if nodewalk valid={#1}{#2}{#3}}},
4876 where nodewalk empty/.style n args={3}{for tree={if nodewalk empty={#1}{#2}{#3}}},
4877 repeat/.code 2 args={%
4878 \forestmathtruncatemacro\forest@temp{#1}%
4879 \expandafter\forest@repeatkey\expandafter{\forest@temp}{#2}%
4880 },
4881 until/.code 2 args={%
4882 \ifstrempty{#1}{%
4883 \forest@untilkey{\ifnum\forest@cn=0\else\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
4884 }{%
4885 \forest@untilkey{\forestmath@if{#1}{\forestloopbreak}{}}{#2}%
4886 }%
4887 },
4888 while/.code 2 args={%
4889 \ifstrempty{#1}{%
4890 \forest@untilkey{\ifnum\forest@cn=0\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
4891 }{%
4892 \forest@untilkey{\forestmath@if{#1}{}{\forestloopbreak}}{#2}%
4893 }%
4894 },
4895 do until/.code 2 args={%
4896 \ifstrempty{#1}{%
4897 \forest@dountilkey{\ifnum\forest@cn=0\else\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
4898 }{%
4899 \forest@dountilkey{\forestmath@if{#1}{\forestloopbreak}{}}{#2}%
4900 }%
4901 },
4902 do while/.code 2 args={%
4903 \ifstrempty{#1}{%
4904 \forest@dountilkey{\ifnum\forest@cn=0\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
4905 }{%
4906 \forest@dountilkey{\forestmath@if{#1}{}{\forestloopbreak}}{#2}%
4907 }%
4908 },
4909 until nodewalk valid/.code 2 args={%
4910 \forest@untilkey{\forest@forthis{%
4911 \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
4912 },
4913 while nodewalk valid/.code 2 args={%
4914 \forest@untilkey{\forest@forthis{%
4915 \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\forestloopbreak\fi}}{}}}{#2}%
4916 },
4917 do until nodewalk valid/.code 2 args={%
4918 \forest@dountilkey{\forest@forthis{%
4919 \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
4920 },
4921 do while nodewalk valid/.code 2 args={%
4922 \forest@dountilkey{\forest@forthis{%
4923 \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\forestloopbreak\fi}}{}}}{#2}%
4924 },
4925 until nodewalk empty/.code 2 args={%
4926 \forest@untilkey{\forest@forthis{%
4927 \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\forestloopbreak\fi}}{}}}{#2}%
4928 },
4929 while nodewalk empty/.code 2 args={%
4930 \forest@untilkey{\forest@forthis{%
4931 \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
4932 },
4933 do until nodewalk empty/.code 2 args={%
4934 \forest@dountilkey{\forest@forthis{%
4935 \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\forestloopbreak\fi}}{}}}{#2}%
4936 },
4937 do while nodewalk empty/.code 2 args={%
4938 \forest@dountilkey{\forest@forthis{%
4939 \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
4940 },
4941 break/.code={\forestloopBreak{#1}},
4942 break/.default=0,
4943 }
4944 \def\forest@repeatkey#1#2{%
4945 \safeRKloop
4946 \ifnum\safeRKloopn>#1\relax
4947 \csuse{safeRKbreak@\the\safeRKloop@depth true}%
4948 \fi
4949 \expandafter\unless\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
4950 \pgfkeysalso{#2}%
4951 \safeRKrepeat
4952 }
4953 \def\forest@untilkey#1#2{% #1 = condition, #2 = keys
4954 \safeRKloop
4955 #1%
4956 \expandafter\unless\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
4957 \pgfkeysalso{#2}%
4958 \safeRKrepeat
4959 }
4960 \def\forest@dountilkey#1#2{% #1 = condition, #2 = keys
4961 \safeRKloop
4962 \pgfkeysalso{#2}%
4963 #1%
4964 \expandafter\unless\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
4965 \safeRKrepeat
4966 }
4967 \def\forestloopbreak{%
4968 \csname safeRKbreak@\the\safeRKloop@depth true\endcsname
4969 }
4970 \def\forestloopBreak#1{%
4971 \csname safeRKbreak@\number\numexpr\the\safeRKloop@depth-#1\relax true\endcsname
4972 }
4973 \def\forestloopcount{%
4974 \csname safeRKloopn@\number\numexpr\the\safeRKloop@depth\endcsname
4975 }
4976 \def\forestloopCount#1{%
4977 \csname safeRKloopn@\number\numexpr\the\safeRKloop@depth-#1\endcsname
4978 }
4979 \pgfmathdeclarefunction{forestloopcount}{1}{%
4980 \edef\pgfmathresult{\forestloopCount{\ifstrempty{#1}{0}{#1}}}%
4981 }
4982 \forest@copycommandkey{/forest/repeat}{/forest/nodewalk/repeat}
4983 \forest@copycommandkey{/forest/while}{/forest/nodewalk/while}
4984 \forest@copycommandkey{/forest/do while}{/forest/nodewalk/do while}
4985 \forest@copycommandkey{/forest/until}{/forest/nodewalk/until}
4986 \forest@copycommandkey{/forest/do until}{/forest/nodewalk/do until}
4987 \forest@copycommandkey{/forest/if}{/forest/nodewalk/if}
4988 \forest@copycommandkey{/forest/if nodewalk valid}{/forest/nodewalk/if nodewalk valid}
4989 %
4990 % \end{macrocode}
4991 %
4992 % \subsection{Aggregate functions}
4993 %
4994 % \begin{macrocode}
4995 \forestset{
4996 aggregate postparse/.is choice,
4997 aggregate postparse/int/.code={%
4998 \let\forest@aggregate@pgfmathpostparse\forest@aggregate@pgfmathpostparse@toint},
4999 aggregate postparse/none/.code={%
5000 \let\forest@aggregate@pgfmathpostparse\relax},
5001 aggregate postparse/print/.code={%
5002 \let\forest@aggregate@pgfmathpostparse\forest@aggregate@pgfmathpostparse@print},
5003 aggregate postparse/macro/.code={%
5004 \let\forest@aggregate@pgfmathpostparse\forest@aggregate@pgfmathpostparse@usemacro},
5005 aggregate postparse macro/.store in=\forest@aggregate@pgfmathpostparse@macro,
5006 }
5007 \def\forest@aggregate@pgfmathpostparse@print{%
5008 \pgfmathprintnumberto{\pgfmathresult}{\pgfmathresult}%
5009 }
5010 \def\forest@aggregate@pgfmathpostparse@toint{%
5011 \expandafter\forest@split\expandafter{\pgfmathresult.}{.}\pgfmathresult\forest@temp
5012 }
5013 \def\forest@aggregate@pgfmathpostparse@usemacro{%
5014 \forest@aggregate@pgfmathpostparse@macro
5015 }
5016 \let\forest@aggregate@pgfmathpostparse\relax
5017 \forestset{
5018 /handlers/.aggregate/.code n args=4{%
5019 % #1 = start value (forestmath)
5020 % #2 = forestmath expression that calculates "aggregate result" at each step
5021 % #3 = forestmath expression that calculates "aggregate result" at the end of the nodewalk
5022 % #4 = nodewalk
5023 \forest@aggregate@handler{\forest@aggregate@generic{#1}{#2}{#3}{#4}}%
5024 },
5025 /handlers/.sum/.code 2 args={% #1=forestmath, #2=nodewalk
5026 \forest@aggregate@handler{\forest@aggregate@sum{#1}{#2}}%
5027 },
5028 /handlers/.count/.code={% #1=nodewalk
5029 \forest@aggregate@handler{\forest@aggregate@count{#1}}%
5030 },
5031 /handlers/.average/.code 2 args={% #1=forestmath, #2=nodewalk
5032 \forest@aggregate@handler{\forest@aggregate@average{#1}{#2}}%
5033 },
5034 /handlers/.product/.code 2 args={% #1=forestmath, #2=nodewalk
5035 \forest@aggregate@handler{\forest@aggregate@product{#1}{#2}}%
5036 },
5037 /handlers/.min/.code 2 args={% #1=forestmath, #2=nodewalk
5038 \forest@aggregate@handler{\forest@aggregate@min{#1}{#2}}%
5039 },
5040 /handlers/.max/.code 2 args={% #1=forestmath, #2=nodewalk
5041 \forest@aggregate@handler{\forest@aggregate@max{#1}{#2}}%
5042 },
5043 declare count register={aggregate n},
5044 declare toks register={aggregate value},
5045 declare toks register={aggregate result},
5046 aggregate result={},
5047 }
5048 \def\forest@aggregate@handler#1{%
5049 \edef\forest@marshal{%
5050 \unexpanded{%
5051 #1%
5052 }{%
5053 \noexpand\pgfkeysalso{\pgfkeyscurrentpath/.register=aggregate result}%
5054 }%
5055 }\forest@marshal
5056 }
5057 \def\forest@aggregate@pgfmathfunction@finish{%
5058 \forestrget{aggregate result}\pgfmathresult
5059 }
5060 \pgfmathdeclarefunction{aggregate}{4}{%
5061 \forest@aggregate@generic{#1}{#2}{#3}{#4}%
5062 \forest@aggregate@pgfmathfunction@finish
5063 }
5064 \pgfmathdeclarefunction{aggregate_count}{1}{%
5065 \forest@aggregate@sum{#1}%
5066 \forest@aggregate@pgfmathfunction@finish
5067 }
5068 \pgfmathdeclarefunction{aggregate_sum}{2}{%
5069 \forest@aggregate@sum{#1}{#2}%
5070 \forest@aggregate@pgfmathfunction@finish
5071 }
5072 \pgfmathdeclarefunction{aggregate_product}{2}{%
5073 \forest@aggregate@product{#1}{#2}%
5074 \forest@aggregate@pgfmathfunction@finish
5075 }
5076 \pgfmathdeclarefunction{aggregate_average}{2}{%
5077 \forest@aggregate@average{#1}{#2}%
5078 \forest@aggregate@pgfmathfunction@finish
5079 }
5080 \pgfmathdeclarefunction{aggregate_min}{2}{%
5081 \forest@aggregate@min{#1}{#2}%
5082 \forest@aggregate@pgfmathfunction@finish
5083 }
5084 \pgfmathdeclarefunction{aggregate_max}{2}{%
5085 \forest@aggregate@max{#1}{#2}%
5086 \forest@aggregate@pgfmathfunction@finish
5087 }
5088 % \end{macrocode}
5089 % Define particular aggregate functions.
5090 % \begin{macrocode}
5091 \def\forest@aggregate#1#2#3#4#5#6{% #1...#5=real args,
5092 % #6=what to do with |aggregate result| register
5093 % #1 = start value (forestmath)
5094 % #2 = forestmath expression that calculates "aggregate current" at each step
5095 % #3 = forestmath expression that calculates "aggregate result" at each step
5096 % #4 = forestmath expression that calculates "aggregate result" at the end of the nodewalk
5097 % #5 = nodewalk
5098 \forest@saveandrestoreregister{aggregate result}{%
5099 \forest@saveandrestoreregister{aggregate n}{%
5100 \forest@aggregate@{#1}{#2}{#3}{#4}{#5}%
5101 #6%
5102 }%
5103 }%
5104 }
5105 \def\forest@aggregate@generic#1#2#3#4{\forest@aggregate
5106 {\forestmathparse{#1}}%
5107 {}%
5108 {\forestmathparse{#2}}%
5109 {\forestmathparse{#3}}%
5110 {#4}%
5111 }
5112 \def\forest@aggregate@sum#1#2{\forest@aggregate
5113 {\forestmath@convert@fromto\forestmathtype@count\forestmathtype@generic{0}}%
5114 {\forestmathparse{#1}}%
5115 {\forestmathadd{\forestregister{aggregate value}}{\forestregister{aggregate result}}}%
5116 {\forestrget{aggregate result}\forestmathresult}%
5117 {#2}%
5118 }
5119 \def\forest@aggregate@count#1{\forest@aggregate
5120 {\def\forestmathresult{0}\let\forestmathresulttype\forestmathtype@count}%
5121 {\def\forestmathresult{1}\let\forestmathresulttype\forestmathtype@count}%
5122 {\edef\forestmathresult{\the\numexpr\forestregister{aggregate result}+1}\let\forestmathresulttype\forestmathtype@count}%
5123 {\forestrget{aggregate result}\forestmathresult\let\forestmathresulttype\forestmathtype@count}%
5124 {#1}%
5125 }
5126 \def\forest@aggregate@average#1#2{\forest@aggregate
5127 {\forestmath@convert@fromto\forestmathtype@count\forestmathtype@generic{0}}%
5128 {\forestmathparse{#1}}%
5129 {\forestmathadd{\forestregister{aggregate value}}{\forestregister{aggregate result}}}%
5130 {\forestmathdivide@P{\forestregister{aggregate result}}{\forestregister{aggregate n}}}%
5131 {#2}%
5132 }
5133 \def\forest@aggregate@product#1#2{\forest@aggregate
5134 {\forestmath@convert@fromto\forestmathtype@count\forestmathtype@generic{1}}%
5135 {\forestmathparse{#1}}%
5136 {\forestmathmultiply{\forestregister{aggregate value}}{\forestregister{aggregate result}}}%
5137 {\forestrget{aggregate result}\forestmathresult}%
5138 {#2}%
5139 }
5140 \def\forest@aggregate@min#1#2{\forest@aggregate
5141 {\def\forestmathresult{}}%
5142 {\forestmathparse{#1}}%
5143 {\forestmathmin{\forestregister{aggregate value}}{\forestregister{aggregate result}}}%
5144 {\forestrget{aggregate result}\forestmathresult}%
5145 {#2}%
5146 }
5147 \def\forest@aggregate@max#1#2{\forest@aggregate
5148 {\def\forestmathresult{}}%
5149 {\forestmathparse{#1}}%
5150 {\forestmathmax{\forestregister{aggregate value}}{\forestregister{aggregate result}}}%
5151 {\forestrget{aggregate result}\forestmathresult}%
5152 {#2}%
5153 }
5154 % \end{macrocode}
5155 % Actual computation.
5156 % \begin{macrocode}
5157 \def\forest@aggregate@#1#2#3#4#5{%
5158 % #1 = start value (forestmath)
5159 % #2 = forestmath expression that calculates "aggregate current" at each step
5160 % #3 = forestmath expression that calculates "aggregate result" at each step
5161 % #4 = forestmath expression that calculates "aggregate result" at the end of the nodewalk
5162 % #5 = nodewalk
5163 #1%
5164 \forestrlet{aggregate result}\forestmathresult
5165 \forestrset{aggregate value}{}%
5166 \forestrset{aggregate n}{0}%
5167 \forest@forthis{%
5168 \forest@nodewalk{#5}{%
5169 TeX={%
5170 \forestreset{aggregate n}{\number\numexpr\forestrv{aggregate n}+1}%
5171 #2%
5172 \forestrlet{aggregate value}\forestmathresult
5173 #3%
5174 \forestrlet{aggregate result}\forestmathresult
5175 }%
5176 }{}%
5177 }%
5178 #4%
5179 \let\forest@temp@pgfmathpostparse\pgfmathpostparse
5180 \let\pgfmathpostparse\forest@aggregate@pgfmathpostparse
5181 \forestmath@convert@to\forestmathtype@dimen{\forestmathresult}%
5182 \pgfmathqparse{\forestmathresult}%
5183 \let\pgfmathpostparse\forest@temp@pgfmathpostparse
5184 \forestrlet{aggregate result}\pgfmathresult
5185 }
5186 % \end{macrocode}
5187 % \subsubsection{\texttt{pgfmath} extensions}
5188 %
5189 % \begin{macrocode}
5190 \pgfmathdeclarefunction{strequal}{2}{%
5191 \ifstrequal{#1}{#2}{\def\pgfmathresult{1}}{\def\pgfmathresult{0}}%
5192 }
5193 \pgfmathdeclarefunction{instr}{2}{%
5194 \pgfutil@in@{#1}{#2}%
5195 \ifpgfutil@in@\def\pgfmathresult{1}\else\def\pgfmathresult{0}\fi
5196 }
5197 \pgfmathdeclarefunction{strcat}{...}{%
5198 \edef\pgfmathresult{\forest@strip@braces{#1}}%
5199 }
5200 \pgfmathdeclarefunction{min_s}{2}{% #1 = node, #2 = context node (for growth rotation)
5201 \forest@forthis{%
5202 \forest@nameandgo{#1}%
5203 \forest@compute@minmax@ls{#2}%
5204 \edef\forest@temp{\forestove{min@s}}%
5205 \edef\pgfmathresult{\expandafter\Pgf@geT\forest@temp}%
5206 }%
5207 }
5208 \pgfmathdeclarefunction{min_l}{2}{% #1 = node, #2 = context node (for growth rotation)
5209 \forest@forthis{%
5210 \forest@nameandgo{#1}%
5211 \forest@compute@minmax@ls{#2}%
5212 \edef\forest@temp{\forestove{min@l}}%
5213 \edef\pgfmathresult{\expandafter\Pgf@geT\forest@temp}%
5214 }%
5215 }
5216 \pgfmathdeclarefunction{max_s}{2}{% #1 = node, #2 = context node (for growth rotation)
5217 \forest@forthis{%
5218 \forest@nameandgo{#1}%
5219 \forest@compute@minmax@ls{#2}%
5220 \edef\forest@temp{\forestove{max@s}}%
5221 \edef\pgfmathresult{\expandafter\Pgf@geT\forest@temp}%
5222 }%
5223 }
5224 \pgfmathdeclarefunction{max_l}{2}{% #1 = node, #2 = context node (for growth rotation)
5225 \forest@forthis{%
5226 \forest@nameandgo{#1}%
5227 \forest@compute@minmax@ls{#2}%
5228 \edef\forest@temp{\forestove{max@l}}%
5229 \edef\pgfmathresult{\expandafter\Pgf@geT\forest@temp}%
5230 }%
5231 }
5232 \def\forest@compute@minmax@ls#1{% #1 = nodewalk; in the context of which node?
5233 {%
5234 \pgftransformreset
5235 \forest@forthis{%
5236 \forest@nameandgo{#1}%
5237 \forest@pgfqtransformrotate{-\forestove{grow}}%
5238 }%
5239 \forestoget{min x}\forest@temp@minx
5240 \forestoget{min y}\forest@temp@miny
5241 \forestoget{max x}\forest@temp@maxx
5242 \forestoget{max y}\forest@temp@maxy
5243 \pgfpointtransformed{\pgfqpoint{\forest@temp@minx}{\forest@temp@miny}}%
5244 \forestoeset{min@l}{\the\pgf@x}%
5245 \forestoeset{min@s}{\the\pgf@y}%
5246 \forestoeset{max@l}{\the\pgf@x}%
5247 \forestoeset{max@s}{\the\pgf@y}%
5248 \pgfpointtransformed{\pgfqpoint{\forest@temp@minx}{\forest@temp@maxy}}%
5249 \ifdim\pgf@x<\forestove{min@l}\relax\forestoeset{min@l}{\the\pgf@x}\fi
5250 \ifdim\pgf@y<\forestove{min@s}\relax\forestoeset{min@s}{\the\pgf@y}\fi
5251 \ifdim\pgf@x>\forestove{max@l}\relax\forestoeset{max@l}{\the\pgf@x}\fi
5252 \ifdim\pgf@y>\forestove{max@s}\relax\forestoeset{max@s}{\the\pgf@y}\fi
5253 \pgfpointtransformed{\pgfqpoint{\forest@temp@maxx}{\forest@temp@miny}}%
5254 \ifdim\pgf@x<\forestove{min@l}\relax\forestoeset{min@l}{\the\pgf@x}\fi
5255 \ifdim\pgf@y<\forestove{min@s}\relax\forestoeset{min@s}{\the\pgf@y}\fi
5256 \ifdim\pgf@x>\forestove{max@l}\relax\forestoeset{max@l}{\the\pgf@x}\fi
5257 \ifdim\pgf@y>\forestove{max@s}\relax\forestoeset{max@s}{\the\pgf@y}\fi
5258 \pgfpointtransformed{\pgfqpoint{\forest@temp@maxx}{\forest@temp@maxy}}%
5259 \ifdim\pgf@x<\forestove{min@l}\relax\forestoeset{min@l}{\the\pgf@x}\fi
5260 \ifdim\pgf@y<\forestove{min@s}\relax\forestoeset{min@s}{\the\pgf@y}\fi
5261 \ifdim\pgf@x>\forestove{max@l}\relax\forestoeset{max@l}{\the\pgf@x}\fi
5262 \ifdim\pgf@y>\forestove{max@s}\relax\forestoeset{max@s}{\the\pgf@y}\fi
5263 % smuggle out
5264 \edef\forest@marshal{%
5265 \noexpand\forestoeset{min@l}{\forestove{min@l}}%
5266 \noexpand\forestoeset{min@s}{\forestove{min@s}}%
5267 \noexpand\forestoeset{max@l}{\forestove{max@l}}%
5268 \noexpand\forestoeset{max@s}{\forestove{max@s}}%
5269 }\expandafter
5270 }\forest@marshal
5271 }
5272 \def\forest@pgfmathhelper@attribute@toks#1#2{%
5273 \forest@forthis{%
5274 \forest@nameandgo{#1}%
5275 \ifnum\forest@cn=0
5276 \def\pgfmathresult{}%
5277 \else
5278 \forestoget{#2}\pgfmathresult
5279 \fi
5280 }%
5281 }
5282 \def\forest@pgfmathhelper@attribute@dimen#1#2{%
5283 \forest@forthis{%
5284 \forest@nameandgo{#1}%
5285 \ifnum\forest@cn=0
5286 \def\pgfmathresult{0}%
5287 \else
5288 \forestoget{#2}\forest@temp
5289 \edef\pgfmathresult{\expandafter\Pgf@geT\forest@temp}%
5290 \fi
5291 }%
5292 }
5293 \def\forest@pgfmathhelper@attribute@count#1#2{%
5294 \forest@forthis{%
5295 \forest@nameandgo{#1}%
5296 \ifnum\forest@cn=0
5297 \def\pgfmathresult{0}%
5298 \else
5299 \forestoget{#2}\pgfmathresult
5300 \fi
5301 }%
5302 }
5303 \pgfmathdeclarefunction*{id}{1}{%
5304 \forest@forthis{%
5305 \forest@nameandgo{#1}%
5306 \let\pgfmathresult\forest@cn
5307 }%
5308 }
5309 % \end{macrocode}
5310 %
5311 % \subsection{Nodewalk}
5312 %
5313 % Setup machinery.
5314 %
5315 % \begin{macrocode}
5316 \def\forest@nodewalk@n{0}
5317 \def\forest@nodewalk@historyback{0,}
5318 \def\forest@nodewalk@historyforward{0,}
5319 \def\forest@nodewalk@origin{0}
5320 \def\forest@nodewalk@config@everystep@independent@before#1{% #1 = every step keylist
5321 \forestrset{every step}{#1}%
5322 }
5323 \def\forest@nodewalk@config@everystep@independent@after{%
5324 \noexpand\forestrset{every step}{\forestrv{every step}}%
5325 }
5326 \def\forest@nodewalk@config@history@independent@before{%
5327 \def\forest@nodewalk@n{0}%
5328 \edef\forest@nodewalk@origin{\forest@cn}%
5329 \def\forest@nodewalk@historyback{0,}%
5330 \def\forest@nodewalk@historyforward{0,}%
5331 }
5332 \def\forest@nodewalk@config@history@independent@after{%
5333 \edef\noexpand\forest@nodewalk@n{\expandonce{\forest@nodewalk@n}}%
5334 \edef\noexpand\forest@nodewalk@origin{\expandonce{\forest@nodewalk@origin}}%
5335 \edef\noexpand\forest@nodewalk@historyback{\expandonce{\forest@nodewalk@historyback}}%
5336 \edef\noexpand\forest@nodewalk@historyforward{\expandonce{\forest@nodewalk@historyforward}}%
5337 }
5338 \def\forest@nodewalk@config@everystep@shared@before#1{}% #1 = every step keylist
5339 \def\forest@nodewalk@config@everystep@shared@after{}
5340 \def\forest@nodewalk@config@history@shared@before{}
5341 \def\forest@nodewalk@config@history@shared@after{}
5342 \def\forest@nodewalk@config@everystep@inherited@before#1{}% #1 = every step keylist
5343 \let\forest@nodewalk@config@everystep@inherited@after\forest@nodewalk@config@everystep@independent@after
5344 \def\forest@nodewalk@config@history@inherited@before{}
5345 \let\forest@nodewalk@config@history@inherited@after\forest@nodewalk@config@history@independent@after
5346 \def\forest@nodewalk#1#2{% #1 = nodewalk, #2 = every step keylist
5347 \forest@configured@nodewalk{independent}{independent}{inherited}{#1}{#2}%
5348 }
5349 \def\forest@configured@nodewalk#1#2#3#4#5{%
5350 % #1 = every step method, #2 = history method, #3 = on invalid
5351 % #4 = nodewalk, #5 = every step keylist
5352 \def\forest@nodewalk@config@everystep@method{#1}%
5353 \def\forest@nodewalk@config@history@method{#2}%
5354 \def\forest@nodewalk@config@oninvalid{#3}%
5355 \forest@Nodewalk{#4}{#5}%
5356 }
5357 \def\forest@nodewalk@oninvalid@inherited@text{inherited}
5358 \def\forest@Nodewalk#1#2{% #1 = nodewalk, #2 = every step keylist
5359 \ifx\forest@nodewalk@config@oninvalid\forest@nodewalk@oninvalid@inherited@text
5360 \edef\forest@nodewalk@config@oninvalid{\forest@nodewalk@oninvalid}%
5361 \fi
5362 \edef\forest@nw@marshal{%
5363 \noexpand\pgfqkeys{/forest/nodewalk}{\unexpanded{#1}}%
5364 \csname forest@nodewalk@config@everystep@\forest@nodewalk@config@everystep@method @after\endcsname
5365 \csname forest@nodewalk@config@history@\forest@nodewalk@config@history@method @after\endcsname
5366 \edef\noexpand\forest@nodewalk@oninvalid{\forest@nodewalk@oninvalid}%
5367 }%
5368 \csname forest@nodewalk@config@everystep@\forest@nodewalk@config@everystep@method @before\endcsname{#2}%
5369 \csname forest@nodewalk@config@history@\forest@nodewalk@config@history@method @before\endcsname
5370 \edef\forest@nodewalk@oninvalid{\forest@nodewalk@config@oninvalid}%
5371 \forest@saveandrestoreifcs{forest@nodewalk@fake}{%
5372 \forest@nodewalk@fakefalse
5373 \forest@nw@marshal
5374 }%
5375 }
5376 \pgfmathdeclarefunction{valid}{1}{%
5377 \forest@forthis{%
5378 \forest@nameandgo{#1}%
5379 \edef\pgfmathresult{\ifnum\forest@cn=0 0\else 1\fi}%
5380 }%
5381 }
5382 \pgfmathdeclarefunction{invalid}{1}{%
5383 \forest@forthis{%
5384 \forest@nameandgo{#1}%
5385 \edef\pgfmathresult{\ifnum\forest@cn=0 1\else 0\fi}%
5386 }%
5387 }
5388 \newif\ifforest@nodewalk@fake
5389 \def\forest@nodewalk@oninvalid{error}
5390 \def\forest@nodewalk@makestep{%
5391 \ifnum\forest@cn=0
5392 \csname forest@nodewalk@makestep@oninvalid@\forest@nodewalk@oninvalid\endcsname
5393 \else
5394 \forest@nodewalk@makestep@
5395 \fi
5396 }
5397 \csdef{forest@nodewalk@makestep@oninvalid@error if real}{\ifforest@nodewalk@fake\expandafter\forest@nodewalk@makestep@\else\expandafter\forest@nodewalk@makestep@oninvalid@error\fi}
5398 \csdef{forest@nodewalk@makestep@oninvalid@last valid}{%
5399 \forest@nodewalk@tolastvalid
5400 \ifforestdebugnodewalks\forest@nodewalk@makestep@invalidtolastvalid@debug\fi}%
5401 \def\forest@nodewalk@makestep@oninvalid@error{\PackageError{forest}{nodewalk stepped to the invalid node\MessageBreak nodewalk stack: "\forest@nodewalk@currentstepname"}{}}%
5402 \let\forest@nodewalk@makestep@oninvalid@fake\relax
5403 \def\forest@nodewalk@makestep@oninvalid@compatfake{%
5404 \forest@deprecated{last step in stack "\forest@nodewalk@currentstepname", which stepped on an invalid node; enabled by "compat=1.0-forstep". Use "on invalid={fake}{...}" or "for Nodewalk={on invalid=fake}{...}{...}" instead.}%
5405 }%
5406 \def\forest@nodewalk@makestep@{%
5407 \ifforestdebugnodewalks\forest@nodewalk@makestep@debug\fi
5408 \ifforest@nodewalk@fake
5409 \else
5410 \edef\forest@nodewalk@n{\number\numexpr\forest@nodewalk@n+1}%
5411 \epreto\forest@nodewalk@historyback{\forest@cn,}%
5412 \def\forest@nodewalk@historyforward{0,}%
5413 \forest@process@keylist@register{every step}%
5414 \fi
5415 }
5416 \def\forest@nodewalk@makestep@debug{%
5417 \edef\forest@marshal{%
5418 \noexpand\typeout{\ifforest@nodewalk@fake fake \fi "\forest@nodewalk@currentstepname" step to node id=\forest@cn, content=\forestoption{content}}%
5419 }\forest@marshal
5420 }%
5421 \def\forest@nodewalk@makestep@invalidtolastvalid@debug{%
5422 \edef\forest@marshal{%
5423 \noexpand\typeout{\ifforest@nodewalk@fake fake \fi "\forest@nodewalk@currentstepname" step to invalid node, (fake) return to last valid id=\forest@cn, content=\forestoption{content}}%
5424 }\forest@marshal
5425 }%
5426 \def\forest@handlers@savecurrentpath{%
5427 \edef\pgfkeyscurrentkey{\pgfkeyscurrentpath}%
5428 \let\forest@currentkey\pgfkeyscurrentkey
5429 \pgfkeys@split@path
5430 \edef\forest@currentpath{\pgfkeyscurrentpath}%
5431 \let\forest@currentname\pgfkeyscurrentname
5432 }
5433 \pgfkeys{/handlers/save current path/.code={\forest@handlers@savecurrentpath}}
5434 \newif\ifforest@nodewalkstephandler@style
5435 \newif\ifforest@nodewalkstephandler@autostep
5436 \newif\ifforest@nodewalkstephandler@stripfakesteps
5437 \newif\ifforest@nodewalkstephandler@muststartatvalidnode
5438 \newif\ifforest@nodewalkstephandler@makefor
5439 \let\forest@nodewalkstephandler@styletrueorfalse\forest@nodewalkstephandler@stylefalse
5440 \def\forest@nodewalk@currentstepname{}
5441 \forestset{
5442 /forest/define@step/style/.is if=forest@nodewalkstephandler@style,
5443 /forest/define@step/autostep/.is if=forest@nodewalkstephandler@autostep,
5444 % the following is useful because some macros use grouping (by \forest@forthis or similar) and therefore, after making the last step, revert \forest@cn to the original value, essentially making a fake step
5445 /forest/define@step/strip fake steps/.is if=forest@nodewalkstephandler@stripfakesteps,
5446 % this can never happen with autosteps ...
5447 /forest/define@step/autostep/.append code={%
5448 \ifforest@nodewalkstephandler@autostep
5449 \forest@nodewalkstephandler@stripfakestepsfalse
5450 \fi
5451 },
5452 /forest/define@step/must start at valid node/.is if=forest@nodewalkstephandler@muststartatvalidnode,
5453 /forest/define@step/n args/.store in=\forest@nodewalkstephandler@nargs,
5454 /forest/define@step/make for/.is if=forest@nodewalkstephandler@makefor,
5455 /forest/define@step/@bare/.style={strip fake steps=false,must start at valid node=false,make for=false},
5456 define long step/.code n args=3{%
5457 \forest@nodewalkstephandler@styletrueorfalse % true for end users; but in the package, most of steps are defined by .code
5458 \forest@nodewalkstephandler@autostepfalse
5459 \forest@nodewalkstephandler@stripfakestepstrue
5460 \forest@nodewalkstephandler@muststartatvalidnodetrue % most steps can only start at a valid node
5461 \forest@nodewalkstephandler@makefortrue % make for prefix?
5462 \def\forest@nodewalkstephandler@nargs{0}%
5463 \pgfqkeys{/forest/define@step}{#2}%
5464 \forest@temp@toks{#3}% handler code
5465 \ifforest@nodewalkstephandler@style
5466 \expandafter\forest@temp@toks\expandafter{%
5467 \expandafter\pgfkeysalso\expandafter{\the\forest@temp@toks}%
5468 }%
5469 \fi
5470 \ifforest@nodewalkstephandler@autostep
5471 \apptotoks\forest@temp@toks{\forest@nodewalk@makestep}%
5472 \fi
5473 \ifforest@nodewalkstephandler@stripfakesteps
5474 \expandafter\forest@temp@toks\expandafter{\expandafter\forest@nodewalk@stripfakesteps\expandafter{\the\forest@temp@toks}}%
5475 \fi
5476 \ifforest@nodewalkstephandler@muststartatvalidnode
5477 \edef\forest@marshal{%
5478 \noexpand\forest@temp@toks{%
5479 \unexpanded{%
5480 \ifnum\forest@cn=0
5481 \csname forest@nodewalk@start@oninvalid@\forest@nodewalk@oninvalid\endcsname{#1}%
5482 \else
5483 }%
5484 \noexpand\@escapeif{\the\forest@temp@toks}%
5485 \noexpand\fi
5486 }%
5487 }\forest@marshal
5488 \fi
5489 \pretotoks\forest@temp@toks{\appto\forest@nodewalk@currentstepname{,#1}}%
5490 \expandafter\forest@temp@toks\expandafter{\expandafter\forest@saveandrestoremacro\expandafter\forest@nodewalk@currentstepname\expandafter{\the\forest@temp@toks}}%
5491 \ifforestdebugnodewalks
5492 \epretotoks\forest@temp@toks{\noexpand\typeout{Starting step "#1" from id=\noexpand\forest@cn
5493 \ifnum\forest@nodewalkstephandler@nargs>0 \space with args \noexpand\unexpanded{####1}\fi
5494 \ifnum\forest@nodewalkstephandler@nargs>1 ,\noexpand\unexpanded{####2}\fi
5495 \ifnum\forest@nodewalkstephandler@nargs>2 ,\noexpand\unexpanded{####3}\fi
5496 \ifnum\forest@nodewalkstephandler@nargs>3 ,\noexpand\unexpanded{####4}\fi
5497 \ifnum\forest@nodewalkstephandler@nargs>4 ,\noexpand\unexpanded{####5}\fi
5498 \ifnum\forest@nodewalkstephandler@nargs>5 ,\noexpand\unexpanded{####6}\fi
5499 \ifnum\forest@nodewalkstephandler@nargs>6 ,\noexpand\unexpanded{####7}\fi
5500 \ifnum\forest@nodewalkstephandler@nargs>7 ,\noexpand\unexpanded{####8}\fi
5501 \ifnum\forest@nodewalkstephandler@nargs>8 ,\noexpand\unexpanded{####9}\fi
5502 }}%
5503 \fi
5504 \def\forest@temp{/forest/nodewalk/#1/.code}%
5505 \ifnum\forest@nodewalkstephandler@nargs<2
5506 \eappto\forest@temp{=}%
5507 \else\ifnum\forest@nodewalkstephandler@nargs=2
5508 \eappto\forest@temp{ 2 args=}%
5509 \else
5510 \eappto\forest@temp{ n args={\forest@nodewalkstephandler@nargs}}%
5511 \fi\fi
5512 \eappto\forest@temp{{\the\forest@temp@toks}}%
5513 \expandafter\pgfkeysalso\expandafter{\forest@temp}%
5514 \ifforest@nodewalkstephandler@makefor
5515 \ifnum\forest@nodewalkstephandler@nargs=0
5516 \forestset{%
5517 for #1/.code={\forest@forstepwrapper{#1}{##1}},
5518 }%
5519 \else\ifnum\forest@nodewalkstephandler@nargs=1
5520 \forestset{%
5521 for #1/.code 2 args={\forest@forstepwrapper{#1={##1}}{##2}},
5522 }%
5523 \else
5524 \forestset{%
5525 for #1/.code n args/.expanded=%
5526 {\number\numexpr\forest@nodewalkstephandler@nargs+1}%
5527 {\noexpand\forest@forstepwrapper{#1\ifnum\forest@nodewalkstephandler@nargs>0=\fi\forest@util@nargs{####}{\number\numexpr\forest@nodewalkstephandler@nargs}{0}}{####\number\numexpr\forest@nodewalkstephandler@nargs+1}},
5528 }%
5529 \fi\fi
5530 \fi
5531 },
5532 }
5533 {\csname forest@@doc@@hook@bigbadforlist\endcsname}%
5534 \pgfqkeys{/handlers}{
5535 .nodewalk style/.code={\forest@handlers@savecurrentpath\pgfkeysalso{%
5536 \forest@currentpath/nodewalk/\forest@currentname/.style={#1}%
5537 }},
5538 }
5539 % \end{macrocode}
5540 % |\forest@forstepwrapper| is defined so that it can be changed by |compat| to create unfailable spatial propagators from v1.0.
5541 % \begin{macrocode}
5542 \def\forest@forstepwrapper#1#2{\forest@forthis{\forest@nodewalk{#1}{#2}}}
5543 \def\forest@util@nargs#1#2#3{% #1 = prefix (#, ##, ...), #2 = n args, #3=start; returns {#start+1}...{#start+n}
5544 \ifnum#2>0 {#1\number\numexpr#3+1}\fi
5545 \ifnum#2>1 {#1\number\numexpr#3+2}\fi
5546 \ifnum#2>2 {#1\number\numexpr#3+3}\fi
5547 \ifnum#2>3 {#1\number\numexpr#3+4}\fi
5548 \ifnum#2>4 {#1\number\numexpr#3+5}\fi
5549 \ifnum#2>5 {#1\number\numexpr#3+6}\fi
5550 \ifnum#2>6 {#1\number\numexpr#3+7}\fi
5551 \ifnum#2>7 {#1\number\numexpr#3+8}\fi
5552 \ifnum#2>8 {#1\number\numexpr#3+9}\fi
5553 }
5554 \def\forest@nodewalk@start@oninvalid@fake#1{}
5555 \def\forest@nodewalk@start@oninvalid@compatfake#1{%
5556 \forest@deprecated{last step in stack "\forest@nodewalk@currentstepname", which started from an invalid node; enabled by "compat=1.0-forstep". Use "on invalid={fake}{...}" or "for Nodewalk={on invalid=fake}{...}{...}" instead.}%
5557 }%
5558 \let\forest@nodewalk@start@oninvalid@errorifreal\forest@nodewalk@start@oninvalid@fake % the step will be to an invalid node anyway
5559 \let\forest@nodewalk@start@oninvalid@lastvalid\forest@nodewalk@start@oninvalid@fake
5560 \def\forest@nodewalk@start@oninvalid@error#1{\PackageError{forest}{nodewalk step "#1" cannot start at the invalid node}{}}
5561 % \end{macrocode}
5562 % Define long-form single-step walks.
5563 % \begin{macrocode}
5564 \forestset{
5565 define long step={current}{autostep}{},
5566 define long step={next}{autostep}{\edef\forest@cn{\forestove{@next}}},
5567 define long step={previous}{autostep}{\edef\forest@cn{\forestove{@previous}}},
5568 define long step={parent}{autostep}{\edef\forest@cn{\forestove{@parent}}},
5569 define long step={first}{autostep}{\edef\forest@cn{\forestove{@first}}},
5570 define long step={last}{autostep}{\edef\forest@cn{\forestove{@last}}},
5571 define long step={sibling}{autostep}{%
5572 \edef\forest@cn{%
5573 \ifnum\forestove{@previous}=0
5574 \forestove{@next}%
5575 \else
5576 \forestove{@previous}%
5577 \fi
5578 }%
5579 },
5580 define long step={next node}{autostep}{\edef\forest@cn{\forest@node@linearnextid}},
5581 define long step={previous node}{autostep}{\edef\forest@cn{\forest@node@linearpreviousid}},
5582 define long step={first leaf}{autostep}{%
5583 \safeloop
5584 \edef\forest@cn{\forestove{@first}}%
5585 \unless\ifnum\forestove{@first}=0
5586 \saferepeat
5587 },
5588 define long step={first leaf'}{autostep}{%
5589 \safeloop
5590 \unless\ifnum\forestove{@first}=0
5591 \edef\forest@cn{\forestove{@first}}%
5592 \saferepeat
5593 },
5594 define long step={last leaf}{autostep}{%
5595 \safeloop
5596 \edef\forest@cn{\forestove{@last}}%
5597 \unless\ifnum\forestove{@last}=0
5598 \saferepeat
5599 },
5600 define long step={last leaf'}{autostep}{%
5601 \safeloop
5602 \unless\ifnum\forestove{@last}=0
5603 \edef\forest@cn{\forestove{@last}}%
5604 \saferepeat
5605 },
5606 define long step={next leaf}{style,strip fake steps=false}{group={do until={n_children()==0}{next node}}},
5607 define long step={previous leaf}{style,strip fake steps=false}{group={do until={n_children()==0}{previous node}}},
5608 define long step={next on tier}{autostep,n args=1}{%
5609 \def\forest@temp{#1}%
5610 \ifx\forest@temp\pgfkeysnovalue@text
5611 \forestoget{tier}\forest@nodewalk@giventier
5612 \else
5613 \def\forest@nodewalk@giventier{#1}%
5614 \fi
5615 \edef\forest@cn{\forest@node@linearnextid}%
5616 \safeloop
5617 \forest@nodewalk@gettier
5618 \ifforest@temp
5619 \edef\forest@cn{\forest@node@linearnextid}%
5620 \saferepeat
5621 },
5622 define long step={previous on tier}{autostep,n args=1}{%
5623 \def\forest@temp{#1}%
5624 \ifx\forest@temp\pgfkeysnovalue@text
5625 \forestoget{tier}\forest@nodewalk@giventier
5626 \else
5627 \def\forest@nodewalk@giventier{#1}%
5628 \fi
5629 \safeloop
5630 \edef\forest@cn{\forest@node@linearpreviousid}%
5631 \forest@nodewalk@gettier
5632 \ifforest@temp
5633 \saferepeat
5634 },
5635 TeX={%
5636 \def\forest@nodewalk@gettier{%
5637 \ifnum\forest@cn=0
5638 \forest@tempfalse
5639 \else
5640 \forestoget{tier}\forest@temp
5641 \ifx\forest@temp\forest@nodewalk@giventier
5642 \forest@tempfalse
5643 \else
5644 \forest@temptrue
5645 \fi
5646 \fi
5647 }%
5648 },
5649 %
5650 define long step={root}{autostep,must start at valid node=false}{%
5651 \edef\forest@cn{\forest@node@rootid}},
5652 define long step={root'}{autostep,must start at valid node=false}{%
5653 \forestOifdefined{\forest@root}{@parent}{\edef\forest@cn{\forest@root}}{\edef\forest@cn{0}}%
5654 },
5655 define long step={origin}{autostep,must start at valid node=false}{\edef\forest@cn{\forest@nodewalk@origin}},
5656 %
5657 define long step={n}{autostep,n args=1}{%
5658 \forestmathtruncatemacro\forest@temp@n{#1}%
5659 \edef\forest@cn{\forest@node@nthchildid{\forest@temp@n}}%
5660 },
5661 define long step={n}{autostep,make for=false,n args=1}{%
5662 % Yes, twice. ;-)
5663 % n=1 and n(ext)
5664 \def\forest@nodewalk@temp{#1}%
5665 \ifx\forest@nodewalk@temp\pgfkeysnovalue@text
5666 \edef\forest@cn{\forestove{@next}}%
5667 \else
5668 \forestmathtruncatemacro\forest@temp@n{#1}%
5669 \edef\forest@cn{\forest@node@nthchildid{\forest@temp@n}}%
5670 \fi
5671 },
5672 define long step={n'}{autostep,n args=1}{%
5673 \forestmathtruncatemacro\forest@temp@n{#1}%
5674 \edef\forest@cn{\forest@node@nbarthchildid{\forest@temp@n}}%
5675 },
5676 define long step={to tier}{autostep,n args=1}{%
5677 \def\forest@nodewalk@giventier{#1}%
5678 \safeloop
5679 \forest@nodewalk@gettier
5680 \ifforest@temp
5681 \forestoget{@parent}\forest@cn
5682 \saferepeat
5683 },
5684 %
5685 define long step={name}{autostep,n args=1,must start at valid node=false}{%
5686 \edef\forest@cn{%
5687 \forest@node@Ifnamedefined{#1}{\forest@node@Nametoid{#1}}{0}%
5688 }%
5689 },
5690 define long step={id}{autostep,n args=1,must start at valid node=false}{%
5691 \forestOifdefined{#1}{@parent}{\edef\forest@cn{#1}}{\edef\forest@cn{0}}%
5692 },
5693 define long step={Nodewalk}{n args=3,@bare}{% #1 = config, #2 = nodewalk
5694 \def\forest@nodewalk@config@everystep@method{independent}%
5695 \def\forest@nodewalk@config@history@method{shared}%
5696 \def\forest@nodewalk@config@oninvalid{inherited}%
5697 \pgfqkeys{/forest/nodewalk@config}{#1}%
5698 \forest@Nodewalk{#2}{#3}%
5699 },
5700 define long step={nodewalk}{n args=2,@bare}{% #1 = nodewalk, #2 = every step
5701 \forest@nodewalk{#1}{#2}%
5702 },
5703 define long step={nodewalk'}{n args=1,@bare}{% #1 = nodewalk
5704 \forest@configured@nodewalk{inherited}{independent}{inherited}{#1}{}%
5705 },
5706 % these "for ..." keys must be defined explicitely
5707 % (and copied into node keyspace manually),
5708 % as prefix "for" normally introduces the every-step keylist
5709 define long step={for nodewalk}{n args=2,@bare}{% #1 = nodewalk, #2 = every step
5710 \forest@forthis{\forest@nodewalk{#1}{#2}}},
5711 define long step={for nodewalk'}{n args=1,@bare}{% #1 = nodewalk
5712 \forest@forthis{%
5713 \forest@configured@nodewalk{inherited}{independent}{inherited}{#1}{}%
5714 }%
5715 },
5716 define long step={for Nodewalk}{n args=3,@bare}{% #1 = config, #2 = nodewalk, #3 = every-step
5717 \def\forest@nodewalk@config@everystep@method{independent}%
5718 \def\forest@nodewalk@config@history@method{shared}%
5719 \def\forest@nodewalk@config@oninvalid{inherited}%
5720 \pgfqkeys{/forest/nodewalk@config}{#1}%
5721 \forest@forthis{\forest@Nodewalk{#2}{#3}}%
5722 },
5723 copy command key={/forest/nodewalk/Nodewalk}{/forest/Nodewalk},
5724 copy command key={/forest/nodewalk/for nodewalk}{/forest/for nodewalk},
5725 copy command key={/forest/nodewalk/for Nodewalk}{/forest/for Nodewalk},
5726 declare keylist register=every step,
5727 every step'={},
5728 %%% begin nodewalk config
5729 nodewalk@config/.cd,
5730 every@step/.is choice,
5731 every@step/independent/.code={},
5732 every@step/inherited/.code={},
5733 every@step/shared/.code={},
5734 every step/.store in=\forest@nodewalk@config@everystep@method,
5735 every step/.prefix style={every@step=#1},
5736 @history/.is choice,
5737 @history/independent/.code={},
5738 @history/inherited/.code={},
5739 @history/shared/.code={},
5740 history/.store in=\forest@nodewalk@config@history@method,
5741 history/.prefix style={@history=#1},
5742 on@invalid/.is choice,
5743 on@invalid/error/.code={},
5744 on@invalid/fake/.code={},
5745 on@invalid/error if real/.code={},
5746 on@invalid/last valid/.code={},
5747 on@invalid/inherited/.code={},
5748 on invalid/.store in=\forest@nodewalk@config@oninvalid,
5749 on invalid/.prefix style={on@invalid=#1},
5750 %%% end nodewalk config
5751 }
5752 \newtoks\forest@nodewalk@branch@toks
5753 \forestset{
5754 declare toks register=branch@temp@toks,
5755 branch@temp@toks={},
5756 declare keylist register=branched@nodewalk,
5757 branched@nodewalk={},
5758 define long step={branch}{n args=1,@bare,make for,style}{@branch={#1}{branch@build@realstep,branch@build@fakestep}},
5759 define long step={branch'}{n args=1,@bare,make for,style}{@branch={#1}{branch@build@realstep}},
5760 @branch/.style 2 args={%
5761 save and restore register={branched@nodewalk}{
5762 branch@temp@toks={},
5763 split/.process={r}{#1}{,}{#2},
5764 also/.register=branch@temp@toks,
5765 also/.register=branched@nodewalk,
5766 }
5767 },
5768 nodewalk/branch@build@realstep/.style={% #1 = nodewalk for this branch
5769 branch@temp@toks/.expanded={for nodewalk={\unexpanded{#1}}{
5770 branched@nodewalk+/.expanded={id=\noexpand\forestoption{id}},
5771 \forestregister{branch@temp@toks}}},
5772 },
5773 nodewalk/branch@build@fakestep/.style={% #1 = nodewalk for this branch
5774 branch@temp@toks/.expanded={for nodewalk={\unexpanded{#1}}{
5775 \forestregister{branch@temp@toks}}},
5776 },
5777 define long step={group}{autostep,n args=1}{\forest@go{#1}},
5778 nodewalk/fake/.code={%
5779 \forest@saveandrestoreifcs{forest@nodewalk@fake}{%
5780 \forest@nodewalk@faketrue
5781 \pgfkeysalso{#1}%
5782 }%
5783 },
5784 nodewalk/real/.code={%
5785 \forest@saveandrestoreifcs{forest@nodewalk@fake}{%
5786 \forest@nodewalk@fakefalse
5787 \pgfkeysalso{#1}%
5788 }%
5789 },
5790 declare keylist register=filtered@nodewalk,
5791 filtered@nodewalk={},
5792 define long step={filter}{n args=2,@bare,make for,style}{% #1 = nodewalk, #2 = condition
5793 save and restore register={filtered@nodewalk}{
5794 filtered@nodewalk'={},
5795 Nodewalk=%
5796 {history=inherited}%
5797 {#1}%
5798 {if={#2}{filtered@nodewalk+/.expanded={id=\forestoption{id}}}{}},
5799 filtered@nodewalk@style/.style/.register=filtered@nodewalk,
5800 filtered@nodewalk@style
5801 },
5802 },
5803 on@invalid/.is choice,
5804 on@invalid/error/.code={},
5805 on@invalid/fake/.code={},
5806 on@invalid/error if real/.code={},
5807 on@invalid/last valid/.code={},
5808 on invalid/.code 2 args={%
5809 \pgfkeysalso{/forest/on@invalid={#1}}%
5810 \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
5811 \def\forest@nodewalk@oninvalid{#1}%
5812 \pgfkeysalso{#2}%
5813 }%
5814 },
5815 define long step={strip fake steps}{n args=1,@bare}{%
5816 \forest@nodewalk@stripfakesteps{\pgfkeysalso{#1}}},
5817 define long step={unique}{n args=1}{%
5818 \begingroup
5819 \def\forest@nodewalk@unique@temp{}%
5820 \forest@nodewalk{#1}{%
5821 TeX={%
5822 \forestoget{unique@visited}\forest@temp
5823 \ifx\forest@temp\relax
5824 \forestoset{unique@visited}{1}%
5825 \eappto\forest@nodewalk@unique@temp{,id=\forest@cn}%
5826 \fi
5827 }%
5828 }%
5829 \global\let\forest@global@temp\forest@nodewalk@unique@temp
5830 \endgroup
5831 \pgfkeysalsofrom{\forest@global@temp}%
5832 },
5833 define long step={walk back}{n args=1,@bare}{%
5834 \forestmathtruncatemacro\forest@temp@n{#1}%
5835 \forest@nodewalk@walklist{\forest@nodewalk@historyforward}{\forest@nodewalk@historyback}{\ifnum\forest@cn=0 0\else1\fi}{\forest@temp@n+\ifnum\forest@cn=0 0\else1\fi}{\let\forest@cn\forest@nodewalk@cn\forest@nodewalk@makestep}%
5836 \forest@nodewalk@back@updatehistory
5837 },
5838 nodewalk/walk back/.default=1,
5839 define long step={jump back}{n args=1,@bare}{%
5840 \forestmathtruncatemacro\forest@temp@n{(#1)+\ifnum\forest@cn=0 0\else1\fi}%
5841 \forest@nodewalk@walklist{\forest@nodewalk@historyforward}{\forest@nodewalk@historyback}{\forest@temp@n-1}{\forest@temp@n}{\let\forest@cn\forest@nodewalk@cn\forest@nodewalk@makestep}%
5842 \forest@nodewalk@back@updatehistory
5843 },
5844 nodewalk/jump back/.default=1,
5845 define long step={back}{n args=1,@bare}{%
5846 \forestmathtruncatemacro\forest@temp@n{#1}%
5847 \forest@nodewalk@walklist{\forest@nodewalk@historyforward}{\forest@nodewalk@historyback}{\ifnum\forest@cn=0 0\else1\fi}{\forest@temp@n+\ifnum\forest@cn=0 0\else1\fi}{\let\forest@cn\forest@nodewalk@cn\forest@saveandrestoreifcs{forest@nodewalk@fake}{\forest@nodewalk@faketrue\forest@nodewalk@makestep}}%
5848 \forest@nodewalk@back@updatehistory
5849 },
5850 nodewalk/back/.default=1,
5851 define long step={walk forward}{n args=1,@bare}{%
5852 \forestmathtruncatemacro\forest@temp@n{#1}%
5853 \forest@nodewalk@walklist{\forest@nodewalk@historyback}{\forest@nodewalk@historyforward}{0}{\forest@temp@n}{\let\forest@cn\forest@nodewalk@cn\forest@nodewalk@makestep}%
5854 \forest@nodewalk@forward@updatehistory
5855 },
5856 nodewalk/walk forward/.default=1,
5857 define long step={jump forward}{n args=1,@bare}{%
5858 \forestmathtruncatemacro\forest@temp@n{#1}%
5859 \forest@nodewalk@walklist{\forest@nodewalk@historyback}{\forest@nodewalk@historyforward}{\forest@temp@n-1}{\forest@temp@n}{\let\forest@cn\forest@nodewalk@cn\forest@nodewalk@makestep}%
5860 \forest@nodewalk@forward@updatehistory
5861 },
5862 nodewalk/jump forward/.default=1,
5863 define long step={forward}{n args=1,@bare}{%
5864 \forestmathtruncatemacro\forest@temp@n{#1}%
5865 \forest@nodewalk@walklist{\forest@nodewalk@historyback}{\forest@nodewalk@historyforward}{0}{\forest@temp@n}{\let\forest@cn\forest@nodewalk@cn\forest@saveandrestoreifcs{forest@nodewalk@fake}{\forest@nodewalk@faketrue\forest@nodewalk@makestep}}%
5866 \forest@nodewalk@forward@updatehistory
5867 },
5868 nodewalk/forward/.default=1,
5869 define long step={last valid'}{@bare}{%
5870 \ifnum\forest@cn=0
5871 \forest@nodewalk@tolastvalid
5872 \forest@nodewalk@makestep
5873 \fi
5874 },
5875 define long step={last valid}{@bare}{%
5876 \forest@nodewalk@tolastvalid
5877 },
5878 define long step={reverse}{n args=1,@bare,make for}{%
5879 \forest@nodewalk{#1,TeX={%
5880 \global\let\forest@global@temp\forest@nodewalk@historyback
5881 \global\let\forest@global@tempn\forest@nodewalk@n
5882 }}{}%
5883 \forest@nodewalk@walklist{}{\forest@global@temp}{0}{\forest@global@tempn}{\let\forest@cn\forest@nodewalk@cn\forest@nodewalk@makestep}%
5884 },
5885 define long step={walk and reverse}{n args=1,@bare,make for}{%
5886 \edef\forest@marshal{%
5887 \noexpand\pgfkeysalso{\unexpanded{#1}}%
5888 \noexpand\forest@nodewalk@walklist{}{\noexpand\forest@nodewalk@historyback}{0}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{\let\noexpand\forest@cn\noexpand\forest@nodewalk@cn\noexpand\forest@nodewalk@makestep}%
5889 }\forest@marshal
5890 },
5891 define long step={sort}{n args=1,@bare,make for}{%
5892 \forest@nodewalk{#1,TeX={%
5893 \global\let\forest@global@temp\forest@nodewalk@historyback
5894 \global\let\forest@global@tempn\forest@nodewalk@n
5895 }}{}%
5896 \forest@nodewalk@sortlist{\forest@global@temp}{\forest@global@tempn}\forest@sort@ascending
5897 },
5898 define long step={sort'}{n args=1,@bare,make for}{%
5899 \forest@nodewalk{#1,TeX={%
5900 \global\let\forest@global@temp\forest@nodewalk@historyback
5901 \global\let\forest@global@tempn\forest@nodewalk@n
5902 }}{}%
5903 \forest@nodewalk@sortlist{\forest@global@temp}{\forest@global@tempn}\forest@sort@descending
5904 },
5905 define long step={walk and sort}{n args=1,@bare,make for}{% walk as given, then walk sorted
5906 \edef\forest@marshal{%
5907 \noexpand\pgfkeysalso{\unexpanded{#1}}%
5908 \noexpand\forest@nodewalk@sortlist{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}\noexpand\forest@sort@ascending
5909 }\forest@marshal
5910 },
5911 define long step={walk and sort'}{n args=1,@bare,make for}{%
5912 \edef\forest@marshal{%
5913 \noexpand\pgfkeysalso{\unexpanded{#1}}%
5914 \noexpand\forest@nodewalk@sortlist{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}\noexpand\forest@sort@descending
5915 }\forest@marshal
5916 },
5917 declare keylist register=sort by,
5918 copy command key={/forest/sort by'}{/forest/sort by},
5919 sort by={},
5920 define long step={save}{n args=2,@bare,make for}{% #1 = name, #2 = nodewalk
5921 \forest@forthis{%
5922 \forest@nodewalk{#2,TeX={%
5923 \global\let\forest@global@temp\forest@nodewalk@historyback
5924 \global\let\forest@global@tempn\forest@nodewalk@n
5925 }}{}%
5926 }%
5927 \forest@nodewalk@walklist{}{\forest@global@temp}{0}{\forest@global@tempn}\relax
5928 \csedef{forest@nodewalk@saved@#1}{\forest@nodewalk@walklist@walked}%
5929 },
5930 define long step={walk and save}{n args=2,@bare,make for}{% #1 = name, #2 = nodewalk
5931 \edef\forest@marshal{%
5932 \noexpand\pgfkeysalso{\unexpanded{#2}}%
5933 \noexpand\forest@nodewalk@walklist{}{\noexpand\forest@nodewalk@historyback}{0}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}\relax
5934 }\forest@marshal
5935 \csedef{forest@nodewalk@saved@#1}{\forest@nodewalk@walklist@walked}%
5936 },
5937 define long step={save append}{style,n args=2,@bare,make for}{% #1 = nodewalk name, #2 = nodewalk
5938 save@append@prepend={#1}{#2}{save}{\cseappto}},
5939 define long step={save prepend}{style,n args=2,@bare,make for}{% #1 = nodewalk name, #2 = nodewalk
5940 save@append@prepend={#1}{#2}{save}{\csepreto}},
5941 define long step={walk and save append}{style,n args=2,@bare,make for}{% #1 = nodewalk name, #2 = nodewalk
5942 save@append@prepend={#1}{#2}{walk and save}{\cseappto}},
5943 define long step={walk and save prepend}{style,n args=2,@bare,make for}{% #1 = nodewalk name, #2 = nodewalk
5944 save@append@prepend={#1}{#2}{walk and save}{\csepreto}},
5945 nodewalk/save@append@prepend/.code n args=4{%
5946 % #1 = nodewalk name, #2 = nodewalk
5947 % #3 = "(walk and) save" #4 = \cseappto/\csepreto
5948 \pgfkeysalso{#3={@temp}{#2}}%
5949 \letcs\forest@temp{forest@nodewalk@saved@@temp}%
5950 #4{forest@nodewalk@saved@#1}{\expandonce{\forest@temp}}%
5951 },
5952 nodewalk/save history/.code 2 args={% #1 = back, forward
5953 \csedef{forest@nodewalk@saved@#1}{\forest@nodewalk@historyback}%
5954 \csedef{forest@nodewalk@saved@#2}{\forest@nodewalk@historyforward}%
5955 },
5956 define long step={load}{n args=1,@bare,make for}{%
5957 \forest@nodewalk@walklist{}{\csuse{forest@nodewalk@saved@#1}0,}{0}{-1}{\ifnum\forest@nodewalk@cn=0 \else\let\forest@cn\forest@nodewalk@cn\forest@nodewalk@makestep\fi}%
5958 },
5959 if in saved nodewalk/.code n args=4{% is node #1 in nodewalk #2; yes: #3, no: #4
5960 \forest@forthis{%
5961 \forest@go{#1}%
5962 \edef\forest@marshal{%
5963 \noexpand\pgfutil@in@{,\forest@cn,}{,\csuse{forest@nodewalk@saved@#2},}%
5964 }\forest@marshal
5965 }%
5966 \ifpgfutil@in@
5967 \@escapeif{\pgfkeysalso{#3}}%
5968 \else
5969 \@escapeif{\pgfkeysalso{#4}}%
5970 \fi
5971 },
5972 where in saved nodewalk/.style n args=4{
5973 for tree={if in saved nodewalk={#1}{#2}{#3}{#4}}
5974 },
5975 nodewalk/options/.code={\forestset{#1}},
5976 nodewalk/TeX/.code={#1},
5977 nodewalk/TeX'/.code={\appto\forest@externalize@loadimages{#1}#1},
5978 nodewalk/TeX''/.code={\appto\forest@externalize@loadimages{#1}},
5979 nodewalk/typeout/.style={TeX={\typeout{#1}}},
5980 % repeat is taken later from /forest/repeat
5981 }
5982 \def\forest@nodewalk@walklist#1#2#3#4#5{%
5983 % #1 = list of preceding, #2 = list to walk
5984 % #3 = from, #4 = to
5985 % #5 = every step code
5986 \let\forest@nodewalk@cn\forest@cn
5987 \edef\forest@marshal{%
5988 \noexpand\forest@nodewalk@walklist@{#1}{#2}{\number\numexpr#3}{\number\numexpr#4}{1}{0}{\unexpanded{#5}}%
5989 }\forest@marshal
5990 }
5991 \def\forest@nodewalk@walklist@#1#2#3#4#5#6#7{%
5992 % #1 = list of walked, #2 = list to walk
5993 % #3 = from, #4 = to
5994 % #5 = current step n, #6 = steps made
5995 % #7 = every step code
5996 \def\forest@nodewalk@walklist@walked{#1}%
5997 \def\forest@nodewalk@walklist@rest{#2}%
5998 \edef\forest@nodewalk@walklist@stepsmade{#6}%
5999 \ifnum#4<0
6000 \forest@temptrue
6001 \else
6002 \ifnum#5>#4\relax
6003 \forest@tempfalse
6004 \else
6005 \forest@temptrue
6006 \fi
6007 \fi
6008 \ifforest@temp
6009 \edef\forest@nodewalk@cn{\forest@csvlist@getfirst@{#2}}%
6010 \ifnum\forest@nodewalk@cn=0
6011 #7%
6012 \else
6013 \ifnum#5>#3\relax
6014 #7%
6015 \edef\forest@nodewalk@walklist@stepsmade{\number\numexpr#6+1}%
6016 \fi
6017 \forest@csvlist@getfirstrest@{#2}\forest@nodewalk@cn\forest@nodewalk@walklist@rest
6018 \@escapeifif{%
6019 \edef\forest@marshal{%
6020 \noexpand\forest@nodewalk@walklist@
6021 {\forest@nodewalk@cn,#1}{\forest@nodewalk@walklist@rest}{#3}{#4}{\number\numexpr#5+1}{\forest@nodewalk@walklist@stepsmade}{\unexpanded{#7}}%
6022 }\forest@marshal
6023 }%
6024 \fi
6025 \fi
6026 }
6027
6028 \def\forest@nodewalk@back@updatehistory{%
6029 \ifnum\forest@cn=0
6030 \let\forest@nodewalk@historyback\forest@nodewalk@walklist@rest
6031 \let\forest@nodewalk@historyforward\forest@nodewalk@walklist@walked
6032 \else
6033 \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalk@walklist@walked}\forest@temp\forest@nodewalk@historyforward
6034 \edef\forest@nodewalk@historyback{\forest@temp,\forest@nodewalk@walklist@rest}%
6035 \fi
6036 }
6037 \def\forest@nodewalk@forward@updatehistory{%
6038 \let\forest@nodewalk@historyforward\forest@nodewalk@walklist@rest
6039 \let\forest@nodewalk@historyback\forest@nodewalk@walklist@walked
6040 }
6041 \def\forest@go#1{%
6042 \forest@configured@nodewalk{independent}{inherited}{inherited}{#1}{}%
6043 }
6044 \def\forest@csvlist@getfirst@#1{% assuming that the list is nonempty and finishes with a comma
6045 \forest@csvlist@getfirst@@#1\forest@csvlist@getfirst@@}
6046 \def\forest@csvlist@getfirst@@#1,#2\forest@csvlist@getfirst@@{#1}
6047 \def\forest@csvlist@getrest@#1{% assuming that the list is nonempty and finishes with a comma
6048 \forest@csvlist@getrest@@#1\forest@csvlist@getrest@@}
6049 \def\forest@csvlist@getrest@@#1,#2\forest@csvlist@getrest@@{#2}
6050 \def\forest@csvlist@getfirstrest@#1#2#3{% assuming that the list is nonempty and finishes with a comma
6051 % #1 = list, #2 = cs receiving first, #3 = cs receiving rest
6052 \forest@csvlist@getfirstrest@@#1\forest@csvlist@getfirstrest@@{#2}{#3}}
6053 \def\forest@csvlist@getfirstrest@@#1,#2\forest@csvlist@getfirstrest@@#3#4{%
6054 \def#3{#1}%
6055 \def#4{#2}%
6056 }
6057 \def\forest@nodewalk@stripfakesteps#1{%
6058 % go to the last valid node if the walk contained any nodes, otherwise restore the current node
6059 \edef\forest@marshal{%
6060 \unexpanded{#1}%
6061 \noexpand\ifnum\noexpand\forest@nodewalk@n=\forest@nodewalk@n\relax
6062 \def\noexpand\forest@cn{\forest@cn}%
6063 \noexpand\else
6064 \unexpanded{%
6065 \edef\forest@cn{%
6066 \expandafter\forest@csvlist@getfirst@\expandafter{\forest@nodewalk@historyback}%
6067 }%
6068 }%
6069 \noexpand\fi
6070 }\forest@marshal
6071 }
6072 \def\forest@nodewalk@tolastvalid{%
6073 \ifnum\forest@cn=0
6074 \edef\forest@cn{\expandafter\forest@csvlist@getfirst@\expandafter{\forest@nodewalk@historyback}}%
6075 \ifnum\forest@cn=0
6076 \let\forest@cn\forest@nodewalk@origin
6077 \fi
6078 \fi
6079 }
6080 \def\forest@nodewalk@sortlist#1#2#3{%#1=list,#2=to,#3=asc/desc
6081 \edef\forest@nodewalksort@list{#1}%
6082 \expandafter\forest@nodewalk@sortlist@\expandafter{\number\numexpr#2}{#3}%
6083 }
6084 \def\forest@nodewalk@sortlist@#1#2{%#1=to,#2=asc/desc
6085 \safeloop
6086 \unless\ifnum\safeloopn>#1\relax
6087 \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalksort@list}\forest@nodewalksort@cn\forest@nodewalksort@list
6088 \csedef{forest@nodesort@\safeloopn}{\forest@nodewalksort@cn}%
6089 \saferepeat
6090 \forestrget{sort by}\forest@nodesort@sortkey
6091 \forest@sort\forest@nodesort@cmpnodes\forest@nodesort@let#2{1}{#1}%
6092 \def\forest@nodewalksort@sorted{}%
6093 \safeloop
6094 \unless\ifnum\safeloopn>#1\relax
6095 \edef\forest@cn{\csname forest@nodesort@\safeloopn\endcsname}%
6096 \forest@nodewalk@makestep
6097 \saferepeat
6098 }
6099 % \end{macrocode}
6100 %
6101 % Find minimal/maximal node in a walk.
6102 % \begin{macrocode}
6103 \forestset{
6104 define long step={min}{n args=1,@bare,make for}{% the first min in the argument nodewalk
6105 \forest@nodewalk{#1,TeX={%
6106 \global\let\forest@global@temp\forest@nodewalk@historyback
6107 }}{}%
6108 \forest@nodewalk@minmax{\forest@global@temp}{-1}{<}{\forest@nodewalk@minmax@node,}%
6109 },
6110 define long step={mins}{n args=1,@bare,make for}{% all mins in the argument nodewalk
6111 \forest@nodewalk{#1,TeX={%
6112 \global\let\forest@global@temp\forest@nodewalk@historyback
6113 }}{}%
6114 \forest@nodewalk@minmax{\forest@global@temp}{-1}{<}{\forest@nodewalk@minmax@nodes}%
6115 },
6116 define long step={walk and min}{n args=1,@bare}{%
6117 \edef\forest@marshal{%
6118 \noexpand\pgfkeysalso{\unexpanded{#1}}%
6119 \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{<}{\noexpand\forest@nodewalk@minmax@node,}%%
6120 }\forest@marshal
6121 },
6122 define long step={walk and mins}{n args=1,@bare}{%
6123 \edef\forest@marshal{%
6124 \noexpand\pgfkeysalso{\unexpanded{#1}}%
6125 \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{<}{\noexpand\forest@nodewalk@minmax@nodes}%%
6126 }\forest@marshal
6127 },
6128 define long step={min in nodewalk}{@bare}{% find the first min in the preceding nodewalk, step to it
6129 \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{<}{\forest@nodewalk@minmax@node,}%
6130 },
6131 define long step={mins in nodewalk}{@bare}{% find mins in the preceding nodewalk, step to mins
6132 \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{<}{\forest@nodewalk@minmax@nodes}%
6133 },
6134 define long step={min in nodewalk'}{@bare}{% find the first min in the preceding nodewalk, step to min in history
6135 \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{<}{}%
6136 },
6137 %
6138 define long step={max}{n args=1,@bare,make for}{% the first max in the argument nodewalk
6139 \forest@nodewalk{#1,TeX={%
6140 \global\let\forest@global@temp\forest@nodewalk@historyback
6141 }}{}%
6142 \forest@nodewalk@minmax{\forest@global@temp}{-1}{>}{\forest@nodewalk@minmax@node,}%
6143 },
6144 define long step={maxs}{n args=1,@bare,make for}{% all maxs in the argument nodewalk
6145 \forest@nodewalk{#1,TeX={%
6146 \global\let\forest@global@temp\forest@nodewalk@historyback
6147 }}{}%
6148 \forest@nodewalk@minmax{\forest@global@temp}{-1}{>}{\forest@nodewalk@minmax@nodes}%
6149 },
6150 define long step={walk and max}{n args=1,@bare}{%
6151 \edef\forest@marshal{%
6152 \noexpand\pgfkeysalso{\unexpanded{#1}}%
6153 \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{>}{\noexpand\forest@nodewalk@minmax@node,}%%
6154 }\forest@marshal
6155 },
6156 define long step={walk and maxs}{n args=1,@bare}{%
6157 \edef\forest@marshal{%
6158 \noexpand\pgfkeysalso{\unexpanded{#1}}%
6159 \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{>}{\noexpand\forest@nodewalk@minmax@nodes}%%
6160 }\forest@marshal
6161 },
6162 define long step={max in nodewalk}{@bare}{% find the first max in the preceding nodewalk, step to it
6163 \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{>}{\forest@nodewalk@minmax@node,}%
6164 },
6165 define long step={maxs in nodewalk}{@bare}{% find maxs in the preceding nodewalk, step to maxs
6166 \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{>}{\forest@nodewalk@minmax@nodes}%
6167 },
6168 define long step={max in nodewalk'}{@bare}{% find the first max in the preceding nodewalk, step to max in history
6169 \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{>}{}%
6170 },
6171 }
6172
6173 \def\forest@nodewalk@minmax#1#2#3#4{%
6174 % #1 = list of nodes
6175 % #2 = max index in list (start with 1)
6176 % #3 = min/max = ascending/descending = </>
6177 % #4 = how many results? 1 = {\forest@nodewalk@minmax@node,}, all={\forest@nodewalk@minmax@nodes}, walk in history={}
6178 \forestrget{sort by}\forest@nodesort@sortkey
6179 \edef\forest@nodewalk@minmax@N{\number\numexpr#2}%
6180 \edef\forest@nodewalk@minmax@n{}%
6181 \edef\forest@nodewalk@minmax@list{#1}%
6182 \def\forest@nodewalk@minmax@nodes{}%
6183 \def\forest@nodewalk@minmax@node{}%
6184 \ifdefempty{\forest@nodewalk@minmax@list}{%
6185 }{%
6186 \safeloop
6187 \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalk@minmax@list}\forest@nodewalk@minmax@cn\forest@nodewalk@minmax@list
6188 \ifnum\forest@nodewalk@minmax@cn=0 \else
6189 \ifdefempty{\forest@nodewalk@minmax@node}{%
6190 \edef\forest@nodewalk@minmax@node{\forest@nodewalk@minmax@cn}%
6191 \edef\forest@nodewalk@minmax@nodes{\forest@nodewalk@minmax@cn,}%
6192 \edef\forest@nodewalk@minmax@n{\safeloopn}%
6193 }{%
6194 \csedef{forest@nodesort@1}{\forest@nodewalk@minmax@node}%
6195 \csedef{forest@nodesort@2}{\forest@nodewalk@minmax@cn}%
6196 \forest@nodesort@cmpnodes{2}{1}%
6197 \if=\forest@sort@cmp@result
6198 \edef\forest@nodewalk@minmax@node{\forest@nodewalk@minmax@cn}%
6199 \epreto\forest@nodewalk@minmax@nodes{\forest@nodewalk@minmax@cn,}%
6200 \edef\forest@nodewalk@minmax@n{\safeloopn}%
6201 \else
6202 \if#3\forest@sort@cmp@result
6203 \edef\forest@nodewalk@minmax@node{\forest@nodewalk@minmax@cn}%
6204 \edef\forest@nodewalk@minmax@nodes{\forest@nodewalk@minmax@cn,}%
6205 \edef\forest@nodewalk@minmax@n{\safeloopn}%
6206 \fi
6207 \fi
6208 }%
6209 \fi
6210 \ifdefempty{\forest@nodewalk@minmax@list}{\forest@tempfalse}{\forest@temptrue}%
6211 \ifnum\safeloopn=\forest@nodewalk@minmax@N\relax\forest@temptrue\fi
6212 \ifforest@temp
6213 \saferepeat
6214 \edef\forest@nodewalk@minmax@list{#4}%
6215 \ifdefempty\forest@nodewalk@minmax@list{%
6216 \forestset{nodewalk/jump back=\forest@nodewalk@minmax@n-1}% CHECK
6217 }{%
6218 \safeloop
6219 \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalk@minmax@list}\forest@cn\forest@nodewalk@minmax@list
6220 \forest@nodewalk@makestep
6221 \ifdefempty{\forest@nodewalk@minmax@list}{\forest@tempfalse}{\forest@temptrue}%
6222 \ifforest@temp
6223 \saferepeat
6224 }%
6225 }%
6226 }
6227 % \end{macrocode}
6228 %
6229 % The short-form step mechanism. The complication is that we want to be able to collect tikz and pgf options here, and it is impossible(?) to know in advance what keys are valid there. So we rather check whether the given keyname is a sequence of short steps; if not, we pass the key on.
6230 % \begin{macrocode}
6231 \newtoks\forest@nodewalk@shortsteps@resolution
6232 \newif\ifforest@nodewalk@areshortsteps
6233 \pgfqkeys{/forest/nodewalk}{
6234 .unknown/.code={%
6235 \forest@nodewalk@areshortstepsfalse
6236 \ifx\pgfkeyscurrentvalue\pgfkeysnovalue@text % no value, so possibly short steps
6237 \forest@nodewalk@shortsteps@resolution{}%
6238 \forest@nodewalk@areshortstepstrue
6239 \expandafter\forest@nodewalk@shortsteps\pgfkeyscurrentname==========,% "=" and "," cannot be short steps, so they are good as delimiters
6240 \fi
6241 \ifforest@nodewalk@areshortsteps
6242 \@escapeif{\expandafter\pgfkeysalso\expandafter{\the\forest@nodewalk@shortsteps@resolution}}%
6243 \else
6244 \@escapeif{\pgfkeysalso{/forest/\pgfkeyscurrentname={#1}}}%
6245 \fi
6246 },
6247 }
6248 \def\forest@nodewalk@shortsteps{%
6249 \futurelet\forest@nodewalk@nexttoken\forest@nodewalk@shortsteps@
6250 }
6251 \def\forest@nodewalk@shortsteps@{%
6252 \ifx\forest@nodewalk@nexttoken=%
6253 \let\forest@nodewalk@nextop\forest@nodewalk@shortsteps@end
6254 \else
6255 \ifx\forest@nodewalk@nexttoken\bgroup
6256 \letcs\forest@nodewalk@nextop{forest@shortstep@group}%
6257 \else
6258 \let\forest@nodewalk@nextop\forest@nodewalk@shortsteps@@
6259 \fi
6260 \fi
6261 \forest@nodewalk@nextop
6262 }
6263 \def\forest@nodewalk@shortsteps@@#1{%
6264 \ifcsdef{forest@shortstep@#1}{%
6265 \csname forest@shortstep@#1\endcsname
6266 }{%
6267 \forest@nodewalk@areshortstepsfalse
6268 \forest@nodewalk@shortsteps@end
6269 }%
6270 }
6271 % in the following definitions:
6272 % #1 = short step
6273 % #2 = (long) step, or a style in /forest/nodewalk (taking n args)
6274 \csdef{forest@nodewalk@defshortstep@0@args}#1#2{%
6275 \csdef{forest@shortstep@#1}{%
6276 \apptotoks\forest@nodewalk@shortsteps@resolution{,#2}%
6277 \forest@nodewalk@shortsteps}}
6278 \csdef{forest@nodewalk@defshortstep@1@args}#1#2{%
6279 \csdef{forest@shortstep@#1}##1{%
6280 \edef\forest@marshal####1{#2}%
6281 \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}}%
6282 \forest@nodewalk@shortsteps}}
6283 \csdef{forest@nodewalk@defshortstep@2@args}#1#2{%
6284 \csdef{forest@shortstep@#1}##1##2{%
6285 \edef\forest@marshal####1####2{#2}%
6286 \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}}%
6287 \forest@nodewalk@shortsteps}}
6288 \csdef{forest@nodewalk@defshortstep@3@args}#1#2{%
6289 \csdef{forest@shortstep@#1}##1##2##3{%
6290 \edef\forest@marshal####1####2####3{#2}%
6291 \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}}%
6292 \forest@nodewalk@shortsteps}}
6293 \csdef{forest@nodewalk@defshortstep@4@args}#1#2{%
6294 \csdef{forest@shortstep@#1}##1##2##3##4{%
6295 \edef\forest@marshal####1####2####3####4{#2}%
6296 \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}}%
6297 \forest@nodewalk@shortsteps}}
6298 \csdef{forest@nodewalk@defshortstep@5@args}#1#2{%
6299 \csdef{forest@shortstep@#1}##1##2##3##4##5{%
6300 \edef\forest@marshal####1####2####3####4####5{#2}%
6301 \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}}%
6302 \forest@nodewalk@shortsteps}}
6303 \csdef{forest@nodewalk@defshortstep@6@args}#1#2{%
6304 \csdef{forest@shortstep@#1}##1##2##3##4##5##6{%
6305 \edef\forest@marshal####1####2####3####4####5####6{#2}%
6306 \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}}%
6307 \forest@nodewalk@shortsteps}}
6308 \csdef{forest@nodewalk@defshortstep@7@args}#1#2{%
6309 \csdef{forest@shortstep@#1}##1##2##3##4##5##6##7{%
6310 \edef\forest@marshal####1####2####3####4####5####6####7{#2}%
6311 \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}{##7}}%
6312 \forest@nodewalk@shortsteps}}
6313 \csdef{forest@nodewalk@defshortstep@8@args}#1#2{%
6314 \csdef{forest@shortstep@#1}##1##2##3##4##5##6##7##8{%
6315 \edef\forest@marshal####1####2####3####4####5####6####7####8{#2}%
6316 \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}}%
6317 \forest@nodewalk@shortsteps}}
6318 \csdef{forest@nodewalk@defshortstep@9@args}#1#2{%
6319 \csdef{forest@shortstep@#1}##1##2##3##4##5##6##7##8##9{%
6320 \edef\forest@marshal####1####2####3####4####5####6####7####8####9{#2}%
6321 \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}{##9}}%
6322 \forest@nodewalk@shortsteps}}
6323 \forestset{
6324 define short step/.code n args=3{% #1 = short step, #2 = n args, #3 = long step
6325 \csname forest@nodewalk@defshortstep@#2@args\endcsname{#1}{#3}%
6326 },
6327 }
6328 \def\forest@nodewalk@shortsteps@end#1,{}
6329 % \end{macrocode}
6330 %
6331 % Define short-form steps.
6332 % \begin{macrocode}
6333 \forestset{
6334 define short step={group}{1}{group={#1}}, % {braces} are special
6335 define short step={p}{0}{previous},
6336 define short step={n}{0}{next},
6337 define short step={u}{0}{parent},
6338 define short step={s}{0}{sibling},
6339 define short step={c}{0}{current},
6340 define short step={o}{0}{origin},
6341 define short step={r}{0}{root},
6342 define short step={R}{0}{root'},
6343 define short step={P}{0}{previous leaf},
6344 define short step={N}{0}{next leaf},
6345 define short step={F}{0}{first leaf},
6346 define short step={L}{0}{last leaf},
6347 define short step={>}{0}{next on tier},
6348 define short step={<}{0}{previous on tier},
6349 define short step={1}{0}{n=1},
6350 define short step={2}{0}{n=2},
6351 define short step={3}{0}{n=3},
6352 define short step={4}{0}{n=4},
6353 define short step={5}{0}{n=5},
6354 define short step={6}{0}{n=6},
6355 define short step={7}{0}{n=7},
6356 define short step={8}{0}{n=8},
6357 define short step={9}{0}{n=9},
6358 define short step={l}{0}{last},
6359 define short step={b}{0}{back},
6360 define short step={f}{0}{forward},
6361 define short step={v}{0}{last valid},
6362 define short step={*}{2}{repeat={#1}{#2}},
6363 for 1/.style={for nodewalk={n=1}{#1}},
6364 for 2/.style={for nodewalk={n=2}{#1}},
6365 for 3/.style={for nodewalk={n=3}{#1}},
6366 for 4/.style={for nodewalk={n=4}{#1}},
6367 for 5/.style={for nodewalk={n=5}{#1}},
6368 for 6/.style={for nodewalk={n=6}{#1}},
6369 for 7/.style={for nodewalk={n=7}{#1}},
6370 for 8/.style={for nodewalk={n=8}{#1}},
6371 for 9/.style={for nodewalk={n=9}{#1}},
6372 for -1/.style={for nodewalk={n'=1}{#1}},
6373 for -2/.style={for nodewalk={n'=2}{#1}},
6374 for -3/.style={for nodewalk={n'=3}{#1}},
6375 for -4/.style={for nodewalk={n'=4}{#1}},
6376 for -5/.style={for nodewalk={n'=5}{#1}},
6377 for -6/.style={for nodewalk={n'=6}{#1}},
6378 for -7/.style={for nodewalk={n'=7}{#1}},
6379 for -8/.style={for nodewalk={n'=8}{#1}},
6380 for -9/.style={for nodewalk={n'=9}{#1}},
6381 }
6382 % \end{macrocode}
6383 %
6384 % Define multiple-step walks.
6385 % \begin{macrocode}
6386 \forestset{
6387 define long step={tree}{}{\forest@node@foreach{\forest@nodewalk@makestep}},
6388 define long step={tree reversed}{}{\forest@node@foreach@reversed{\forest@nodewalk@makestep}},
6389 define long step={tree children-first}{}{\forest@node@foreach@childrenfirst{\forest@nodewalk@makestep}},
6390 define long step={tree children-first reversed}{}{\forest@node@foreach@childrenfirst@reversed{\forest@nodewalk@makestep}},
6391 define long step={tree breadth-first}{}{\forest@node@foreach@breadthfirst{-1}{\forest@nodewalk@makestep}},
6392 define long step={tree breadth-first reversed}{}{\forest@node@foreach@breadthfirst@reversed{-1}{\forest@nodewalk@makestep}},
6393 define long step={descendants}{}{\forest@node@foreachdescendant{\forest@nodewalk@makestep}},
6394 define long step={descendants reversed}{}{\forest@node@foreachdescendant@reversed{\forest@nodewalk@makestep}},
6395 define long step={descendants children-first}{}{\forest@node@foreachdescendant@childrenfirst{\forest@nodewalk@makestep}},
6396 define long step={descendants children-first reversed}{}{\forest@node@foreachdescendant@childrenfirst@reversed{\forest@nodewalk@makestep}},
6397 define long step={descendants breadth-first}{}{\forest@node@foreach@breadthfirst{0}{\forest@nodewalk@makestep}},
6398 define long step={descendants breadth-first reversed}{}{\forest@node@foreach@breadthfirst@reversed{0}{\forest@nodewalk@makestep}},
6399 define long step={level}{n args=1}{%
6400 \forestmathtruncatemacro\forest@temp{#1}%
6401 \edef\forest@marshal{%
6402 \noexpand\forest@node@foreach@breadthfirst
6403 {\forest@temp}%
6404 {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
6405 }\forest@marshal
6406 },
6407 define long step={level>}{n args=1}{%
6408 \forestmathtruncatemacro\forest@temp{#1}%
6409 \edef\forest@marshal{%
6410 \noexpand\forest@node@foreach@breadthfirst
6411 {-1}%
6412 {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
6413 }\forest@marshal
6414 },
6415 define long step={level<}{n args=1}{%
6416 \forestmathtruncatemacro\forest@temp{(#1)-1}%
6417 \ifnum\forest@temp=-1
6418 % special case, as \forest@node@foreach@breadthfirst uses level<0 as a signal for unlimited max level
6419 \ifnum\forestove{level}=0
6420 \forest@nodewalk@makestep
6421 \fi
6422 \else
6423 \edef\forest@marshal{%
6424 \noexpand\forest@node@foreach@breadthfirst
6425 {\forest@temp}%
6426 {\noexpand\forest@nodewalk@makestep}%
6427 }\forest@marshal
6428 \fi
6429 },
6430 define long step={level reversed}{n args=1}{%
6431 \forestmathtruncatemacro\forest@temp{#1}%
6432 \edef\forest@marshal{%
6433 \noexpand\forest@node@foreach@breadthfirst@reversed
6434 {\forest@temp}%
6435 {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
6436 }\forest@marshal
6437 },
6438 define long step={level reversed>}{n args=1}{%
6439 \forestmathtruncatemacro\forest@temp{#1}%
6440 \edef\forest@marshal{%
6441 \noexpand\forest@node@foreach@breadthfirst@reversed
6442 {-1}%
6443 {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
6444 }\forest@marshal
6445 },
6446 define long step={level reversed<}{n args=1}{%
6447 \forestmathtruncatemacro\forest@temp{(#1)-1}%
6448 \edef\forest@marshal{%
6449 \noexpand\forest@node@foreach@breadthfirst@reversed
6450 {\forest@temp}%
6451 {\noexpand\forest@nodewalk@makestep}%
6452 }\forest@marshal
6453 },
6454 %
6455 define long step={relative level}{n args=1}{%
6456 \forestmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
6457 \edef\forest@marshal{%
6458 \noexpand\forest@node@foreach@breadthfirst
6459 {\forest@temp}%
6460 {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
6461 }\forest@marshal
6462 },
6463 define long step={relative level>}{n args=1}{%
6464 \forestmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
6465 \edef\forest@marshal{%
6466 \noexpand\forest@node@foreach@breadthfirst
6467 {-1}%
6468 {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
6469 }\forest@marshal
6470 },
6471 define long step={relative level<}{n args=1}{%
6472 \forestmathtruncatemacro\forest@temp{(#1)+\forestove{level}-1}%
6473 \edef\forest@marshal{%
6474 \noexpand\forest@node@foreach@breadthfirst
6475 {\forest@temp}%
6476 {\noexpand\forest@nodewalk@makestep}%
6477 }\forest@marshal
6478 },
6479 define long step={relative level reversed}{n args=1}{%
6480 \forestmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
6481 \edef\forest@marshal{%
6482 \noexpand\forest@node@foreach@breadthfirst@reversed
6483 {\forest@temp}%
6484 {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
6485 }\forest@marshal
6486 },
6487 define long step={relative level reversed>}{n args=1}{%
6488 \forestmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
6489 \edef\forest@marshal{%
6490 \noexpand\forest@node@foreach@breadthfirst@reversed
6491 {-1}%
6492 {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
6493 }\forest@marshal
6494 },
6495 define long step={relative level reversed<}{n args=1}{%
6496 \forestmathtruncatemacro\forest@temp{(#1)+\forestove{level}-1}%
6497 \edef\forest@marshal{%
6498 \noexpand\forest@node@foreach@breadthfirst@reversed
6499 {\forest@temp}%
6500 {\noexpand\forest@nodewalk@makestep}%
6501 }\forest@marshal
6502 },
6503 define long step={leaves}{}{%
6504 \forest@node@foreach{%
6505 \ifnum\forestove{n children}=0
6506 \forest@nodewalk@makestep
6507 \fi
6508 }%
6509 },
6510 define long step={-level}{n args=1,style}{%
6511 unique={branch={leaves,{group={repeat={#1}{parent}}}}}
6512 },
6513 define long step={-level'}{n args=1,style}{%
6514 unique={on invalid={fake}{branch={leaves,{group={repeat={#1}{parent}}}}}}
6515 },
6516 define long step={children}{}{\forest@node@foreachchild{\forest@nodewalk@makestep}},
6517 define long step={children reversed}{}{\forest@node@foreachchild@reversed{\forest@nodewalk@makestep}},
6518 define long step={current and following siblings}{}{\forest@node@@forselfandfollowingsiblings{\forest@nodewalk@makestep}},
6519 define long step={following siblings}{style}{if nodewalk valid={next}{fake=next,current and following siblings}{}},
6520 define long step={current and preceding siblings}{}{\forest@node@@forselfandprecedingsiblings{\forest@nodewalk@makestep}},
6521 define long step={preceding siblings}{style}{if nodewalk valid={previous}{fake=previous,current and preceding siblings}{}},
6522 define long step={current and following siblings reversed}{}{\forest@node@@forselfandfollowingsiblings@reversed{\forest@nodewalk@makestep}},
6523 define long step={following siblings reversed}{style}{fake=next,current and following siblings reversed},
6524 define long step={current and preceding siblings reversed}{}{\forest@node@@forselfandprecedingsiblings@reversed{\forest@nodewalk@makestep}},
6525 define long step={preceding siblings reversed}{style}{fake=previous,current and preceding siblings reversed},
6526 define long step={siblings}{style}{for nodewalk'={preceding siblings},following siblings},
6527 define long step={siblings reversed}{style}{for nodewalk'={following siblings reversed},preceding siblings reversed},
6528 define long step={current and siblings}{style}{for nodewalk'={preceding siblings},current and following siblings},
6529 define long step={current and siblings reversed}{style}{for nodewalk'={current and following siblings reversed},preceding siblings reversed},
6530 define long step={ancestors}{style}{while={}{parent},last valid},
6531 define long step={current and ancestors}{style}{current,ancestors},
6532 define long step={following nodes}{style}{while={}{next node},last valid},
6533 define long step={preceding nodes}{style}{while={}{previous node},last valid},
6534 define long step={current and following nodes}{style}{current,following nodes},
6535 define long step={current and preceding nodes}{style}{current,preceding nodes},
6536 }
6537 \let\forest@nodewalkstephandler@styletrueorfalse\forest@nodewalkstephandler@styletrue
6538 % \end{macrocode}
6539 %
6540 %
6541 % \subsection{Dynamic tree}
6542 % \label{sec:impl:dynamic}
6543 %
6544 % \begin{macrocode}
6545 \def\forest@last@node{0}
6546 \csdef{forest@nodewalk@saved@dynamic nodes}{}
6547 \def\forest@nodehandleby@name@nodewalk@or@bracket#1{%
6548 \ifx\pgfkeysnovalue#1%
6549 \edef\forest@last@node{\forest@node@Nametoid{forest@last@node}}%
6550 \else
6551 \forest@nodehandleby@nnb@checkfirst#1\forest@END
6552 \fi
6553 }
6554 \def\forest@nodehandleby@nnb@checkfirst#1#2\forest@END{%
6555 \ifx[#1%]
6556 \forest@create@node{#1#2}%
6557 \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@last@node,}%
6558 \else
6559 \forest@forthis{%
6560 \forest@nameandgo{#1#2}%
6561 \ifnum\forest@cn=0
6562 \PackageError{forest}{Cannot use a dynamic key on the invalid node}{}%
6563 \fi
6564 \let\forest@last@node\forest@cn
6565 }%
6566 \fi
6567 }
6568 \def\forest@create@node#1{% #1=bracket representation
6569 \bracketParse{\forest@create@collectafterthought}%
6570 \forest@last@node=#1\forest@end@create@node
6571 }
6572 \def\forest@create@collectafterthought#1\forest@end@create@node{%
6573 \forest@node@Foreach{\forest@last@node}{%
6574 \forestoleto{delay}{given options}%
6575 \forestoset{given options}{}%
6576 }%
6577 \forestOeappto{\forest@last@node}{delay}{,\unexpanded{#1}}%
6578 \forestOset{\forest@last@node}{given options}{delay={}}%
6579 }
6580 \def\forest@create@node@and@process@given@options#1{% #1=bracket representation
6581 \bracketParse{\forest@createandprocess@collectafterthought}%
6582 \forest@last@node=#1\forest@end@create@node
6583 }
6584 \def\forest@createandprocess@collectafterthought#1\forest@end@create@node{%
6585 \forest@node@Compute@numeric@ts@info{\forest@last@node}%
6586 \forest@saveandrestoremacro\forest@root{%
6587 \let\forest@root\forest@last@node
6588 \forestset{process keylist=given options}%
6589 }%
6590 }
6591 \def\forest@saveandrestoremacro#1#2{% #1 = the (zero-arg) macro to save before and restore after processing code in #2
6592 \edef\forest@marshal{%
6593 \unexpanded{#2}%
6594 \noexpand\def\noexpand#1{\expandonce{#1}}%
6595 }\forest@marshal
6596 }
6597 \def\forest@saveandrestoreifcs#1#2{% #1 = the if cs to save before and restore after processing code in #2
6598 \edef\forest@marshal{%
6599 \unexpanded{#2}%
6600 \ifbool{#1}{\noexpand\setbool{#1}{true}}{\noexpand\setbool{#1}{false}}%
6601 }\forest@marshal
6602 }
6603 \def\forest@globalsaveandrestoreifcs#1#2{% #1 = the if cs to save before and restore after processing code in #2
6604 \edef\forest@marshal{%
6605 \unexpanded{#2}%
6606 \ifbool{#1}{\global\noexpand\setbool{#1}{true}}{\global\noexpand\setbool{#1}{false}}%
6607 }\forest@marshal
6608 }
6609 \def\forest@saveandrestoretoks#1#2{% #1 = the toks to save before and restore after processing code in #2
6610 \edef\forest@marshal{%
6611 \unexpanded{#2}%
6612 \noexpand#1{\the#1}%
6613 }\forest@marshal
6614 }
6615 \def\forest@saveandrestoreregister#1#2{% #1 = the register to save before and restore after processing code in #2
6616 \edef\forest@marshal{%
6617 \unexpanded{#2}%
6618 \noexpand\forestrset{#1}{\forestregister{#1}}%
6619 }\forest@marshal
6620 }
6621 \forestset{
6622 save and restore register/.code 2 args={%
6623 \forest@saveandrestoreregister{#1}{%
6624 \pgfkeysalso{#2}%
6625 }%
6626 },
6627 }
6628 \def\forest@remove@node#1{%
6629 \ifforestdebugdynamics\forestdebug@dynamics{before removing #1}\fi
6630 \forest@node@Remove{#1}%
6631 }
6632 \def\forest@append@node#1#2{%
6633 \ifforestdebugdynamics\forestdebug@dynamics{before appending #2 to #1}\fi
6634 \forest@dynamic@circularitytest{#2}{#1}{append}%
6635 \forest@node@Remove{#2}%
6636 \forest@node@Append{#1}{#2}%
6637 }
6638 \def\forest@prepend@node#1#2{%
6639 \ifforestdebugdynamics\forestdebug@dynamics{before prepending #2 to #1}\fi
6640 \forest@dynamic@circularitytest{#2}{#1}{prepend}%
6641 \forest@node@Remove{#2}%
6642 \forest@node@Prepend{#1}{#2}%
6643 }
6644 \def\forest@insertafter@node#1#2{%
6645 \ifforestdebugdynamics\forestdebug@dynamics{before inserting #2 after #1}\fi
6646 \forest@node@Remove{#2}%
6647 \forest@node@Insertafter{\forestOve{#1}{@parent}}{#2}{#1}%
6648 }
6649 \def\forest@insertbefore@node#1#2{%
6650 \ifforestdebugdynamics\forestdebug@dynamics{before inserting #2 before #1}\fi
6651 \forest@node@Remove{#2}%
6652 \forest@node@Insertbefore{\forestOve{#1}{@parent}}{#2}{#1}%
6653 }
6654 \def\forest@set@root#1#2{%
6655 \ifforestdebugdynamics\forestdebug@dynamics{before setting #1 as root}\fi
6656 \def\forest@root{#2}%
6657 }
6658 \def\forest@dynamic@circularitytest#1#2#3{%
6659 % #1=potenitial ancestor,#2=potential descendant, #3=message prefix
6660 \ifnum#1=#2
6661 \forest@circularityerror{#1}{#2}{#3}%
6662 \else
6663 \forest@fornode{#1}{%
6664 \forest@ifancestorof{#2}{\forest@circularityerror{#1}{#2}{#3}}{}%
6665 }%
6666 \fi
6667 }
6668 \def\forest@circularityerror#1#2#3{%
6669 \forestdebug@typeouttrees{\forest@temp}%
6670 \PackageError{forest}{#3ing node id=#1 to id=#2 would result in a circular tree\MessageBreak forest of ids: \forest@temp}{}%
6671 }%
6672 \def\forestdebug@dynamics#1{%
6673 \forestdebug@typeouttrees\forest@temp
6674 \typeout{#1: \forest@temp}%
6675 }
6676 \def\forest@appto@do@dynamics#1#2{%
6677 \forest@nodehandleby@name@nodewalk@or@bracket{#2}%
6678 \ifcase\forest@dynamics@copyhow\relax\or
6679 \forest@tree@copy{\forest@last@node}\forest@last@node
6680 \or
6681 \forest@node@copy{\forest@last@node}\forest@last@node
6682 \fi
6683 \forest@node@Ifnamedefined{forest@last@node}{%
6684 \forestOepreto{\forest@last@node}{delay}
6685 {for id={\forest@node@Nametoid{forest@last@node}}{alias=forest@last@node},}%
6686 }{}%
6687 \edef\forest@marshal{%
6688 \noexpand\apptotoks\noexpand\forest@do@dynamics{%
6689 \noexpand#1{\forest@cn}{\forest@last@node}}%
6690 }\forest@marshal
6691 }
6692 \forestset{%
6693 create/.code={%
6694 \forest@create@node{#1}%
6695 \forest@fornode{\forest@last@node}{%
6696 \forest@node@setalias{forest@last@node}%
6697 \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@last@node,}%
6698 }%
6699 },
6700 create'/.code={%
6701 \forest@create@node@and@process@given@options{#1}%
6702 \forest@fornode{\forest@last@node}{%
6703 \forest@node@setalias{forest@last@node}%
6704 \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@last@node,}%
6705 }%
6706 },
6707 append/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@append@node{#1}},
6708 prepend/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@prepend@node{#1}},
6709 insert after/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@insertafter@node{#1}},
6710 insert before/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@insertbefore@node{#1}},
6711 append'/.code={\def\forest@dynamics@copyhow{1}\forest@appto@do@dynamics\forest@append@node{#1}},
6712 prepend'/.code={\def\forest@dynamics@copyhow{1}\forest@appto@do@dynamics\forest@prepend@node{#1}},
6713 insert after'/.code={\def\forest@dynamics@copyhow{1}\forest@appto@do@dynamics\forest@insertafter@node{#1}},
6714 insert before'/.code={\def\forest@dynamics@copyhow{1}\forest@appto@do@dynamics\forest@insertbefore@node{#1}},
6715 append''/.code={\def\forest@dynamics@copyhow{2}\forest@appto@do@dynamics\forest@append@node{#1}},
6716 prepend''/.code={\def\forest@dynamics@copyhow{2}\forest@appto@do@dynamics\forest@prepend@node{#1}},
6717 insert after''/.code={\def\forest@dynamics@copyhow{2}\forest@appto@do@dynamics\forest@insertafter@node{#1}},
6718 insert before''/.code={\def\forest@dynamics@copyhow{2}\forest@appto@do@dynamics\forest@insertbefore@node{#1}},
6719 remove/.code={%
6720 \pgfkeysalso{alias=forest@last@node}%
6721 \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@cn,}%
6722 \expandafter\apptotoks\expandafter\forest@do@dynamics\expandafter{%
6723 \expandafter\forest@remove@node\expandafter{\forest@cn}}%
6724 },
6725 set root/.code={%
6726 \def\forest@dynamics@copyhow{0}%
6727 \forest@appto@do@dynamics\forest@set@root{#1}%
6728 },
6729 replace by/.code={\forest@replaceby@code{#1}{insert after}},
6730 replace by'/.code={\forest@replaceby@code{#1}{insert after'}},
6731 replace by''/.code={\forest@replaceby@code{#1}{insert after''}},
6732 sort/.code={%
6733 \eapptotoks\forest@do@dynamics{%
6734 \def\noexpand\forest@nodesort@sortkey{\forestrv{sort by}}%
6735 \noexpand\forest@nodesort\noexpand\forest@sort@ascending{\forest@cn}
6736 }%
6737 },
6738 sort'/.code={%
6739 \eapptotoks\forest@do@dynamics{%
6740 \def\noexpand\forest@nodesort@sortkey{\forestrv{sort by}}%
6741 \noexpand\forest@nodesort\noexpand\forest@sort@descending{\forest@cn}
6742 }%
6743 },
6744 }
6745 \def\forest@replaceby@code#1#2{%#1=node spec,#2=insert after['][']
6746 \ifnum\forestove{@parent}=0
6747 \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@cn,}%
6748 \pgfkeysalso{alias=forest@last@node,set root={#1}}%
6749 \else
6750 \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@cn,}%
6751 \pgfkeysalso{alias=forest@last@node,#2={#1}}%
6752 \eapptotoks\forest@do@dynamics{%
6753 \noexpand\ifnum\noexpand\forestOve{\forest@cn}{@parent}=\forestove{@parent}
6754 \noexpand\forest@remove@node{\forest@cn}%
6755 \noexpand\fi
6756 }%
6757 \fi
6758 }
6759 \def\forest@nodesort#1#2{% #1 = direction, #2 = parent node
6760 \ifforestdebugdynamics\forestdebug@dynamics{before sorting children of #2}\fi
6761 \forest@fornode{#2}{\forest@nodesort@#1}%
6762 \ifforestdebugdynamics\forestdebug@dynamics{after sorting children of #2}\fi
6763 }
6764 \def\forest@nodesort@#1{%
6765 % prepare the array of child ids
6766 \c@pgf@counta=0
6767 \forestoget{@first}\forest@nodesort@id
6768 \forest@loop
6769 \ifnum\forest@nodesort@id>0
6770 \advance\c@pgf@counta 1
6771 \csedef{forest@nodesort@\the\c@pgf@counta}{\forest@nodesort@id}%
6772 \forestOget{\forest@nodesort@id}{@next}\forest@nodesort@id
6773 \forest@repeat
6774 % sort
6775 \forestoget{n children}\forest@nodesort@n
6776 \forest@sort\forest@nodesort@cmpnodes\forest@nodesort@let#1{1}{\forest@nodesort@n}%
6777 % remove all children
6778 \forestoget{@first}\forest@nodesort@id
6779 \forest@loop
6780 \ifnum\forest@nodesort@id>0
6781 \forest@node@Remove{\forest@nodesort@id}%
6782 \forestoget{@first}\forest@nodesort@id
6783 \forest@repeat
6784 % insert the children in new order
6785 \c@pgf@counta=0
6786 \forest@loop
6787 \ifnum\c@pgf@counta<\forest@nodesort@n\relax
6788 \advance\c@pgf@counta 1
6789 \forest@node@append{\csname forest@nodesort@\the\c@pgf@counta\endcsname}%
6790 \forest@repeat
6791 }
6792 \def\forest@nodesort@cmpnodes#1#2{%
6793 \expandafter\forest@nodesort@cmpnodes@\forest@nodesort@sortkey,\forest@END{#1}{#2}%
6794 }
6795 \def\forest@nodesort@cmpnodes@#1,#2\forest@END#3#4{%
6796 % #1=process ins+arg for this dimension, #2=for next dimensions
6797 % #3, #4 = node ids
6798 {%
6799 \forest@fornode{\csname forest@nodesort@#3\endcsname}{%
6800 \forestmathsetmacro\forest@nodesort@resulta{#1}%
6801 }%
6802 \forest@fornode{\csname forest@nodesort@#4\endcsname}{%
6803 \forestmathsetmacro\forest@nodesort@resultb{#1}%
6804 }%
6805 \ifx\forestmathresulttype\forestmathtype@generic
6806 \forest@cmp@error{\forest@nodesort@resulta}{\forest@nodesort@resultb}%
6807 \fi
6808 \edef\forest@temp{%
6809 \noexpand\forest@nodesort@cmp
6810 {\expandonce{\forest@nodesort@resulta}}%
6811 {\expandonce{\forest@nodesort@resultb}}%
6812 }%
6813 \xdef\forest@global@temp{\forest@temp}%
6814 }%
6815 \if=\forest@global@temp
6816 \let\forest@next\forest@nodesort@cmpnodes@
6817 \else
6818 \let\forest@next\forest@nodesort@cmpnodes@finish
6819 \fi
6820 \ifstrempty{#2}{\let\forest@next\forest@nodesort@cmpnodes@finish}{}%
6821 \forest@next#2\forest@END{#3}{#4}%
6822 }
6823 \def\forest@nodesort@cmpnodes@finish#1\forest@END#2#3{%
6824 \let\forest@sort@cmp@result\forest@global@temp
6825 }
6826 % \end{macrocode}
6827 % Usage: |\forest@nodesort@cmp|\meta{first}\meta{second}. Fully expandable. Return |<|, |=| or |>|, as required by |\forest@sort|.
6828 % \begin{macrocode}
6829 \def\forest@nodesort@cmp{\csname fRsT@nsc@\forestmathresulttype\endcsname}
6830 \def\fRsT@nsc@#1{\csname fRsT@nsc@#1\endcsname}
6831 \def\fRsT@nsc@n#1#2{\ifnum#1<#2 <\else\ifnum#1=#2 =\else>\fi\fi}
6832 \def\fRsT@nsc@d#1#2{\ifdim#1<#2 <\else\ifdim#1=#2 =\else>\fi\fi}
6833 \def\fRsT@nsc@P#1#2{\ifdim#1pt<#2pt <\else\ifdim#1pt=#2pt =\else>\fi\fi}
6834 \def\fRsT@nsc@t#1#2{\csname fRsT@nsc@\pdfstrcmp{#1}{#2}\endcsname}
6835 \def\fRsT@nsc@T#1#2{\csname fRsT@nsc@\pdfstrcmp{#2}{#1}\endcsname}
6836 \csdef{fRsT@nsc@-1}{<}
6837 \csdef{fRsT@nsc@0}{=}
6838 \csdef{fRsT@nsc@1}{>}
6839 \def\forest@nodesort@let#1#2{%
6840 \csletcs{forest@nodesort@#1}{forest@nodesort@#2}%
6841 }
6842 \forestset{
6843 define long step={last dynamic node}{style,must start at valid node=false}{%
6844 name=forest@last@node
6845 }
6846 }
6847 % \end{macrocode}
6848 %
6849 % \section{Stages}
6850 %
6851 % \begin{macrocode}
6852 \def\forest@root{0}
6853 %%% begin listing region: stages
6854 \forestset{
6855 stages/.style={
6856 for root'={
6857 process keylist register=default preamble,
6858 process keylist register=preamble
6859 },
6860 process keylist=given options,
6861 process keylist=before typesetting nodes,
6862 typeset nodes stage,
6863 process keylist=before packing,
6864 pack stage,
6865 process keylist=before computing xy,
6866 compute xy stage,
6867 process keylist=before drawing tree,
6868 draw tree stage
6869 },
6870 typeset nodes stage/.style={for root'=typeset nodes},
6871 pack stage/.style={for root'=pack},
6872 compute xy stage/.style={for root'=compute xy},
6873 draw tree stage/.style={for root'=draw tree},
6874 }
6875 %%% end listing region: stages
6876 \forestset{
6877 process keylist/.code={%
6878 \forest@process@hook@keylist{#1}{#1 processing order/.try,processing order/.lastretry}},
6879 process keylist'/.code 2 args={\forest@process@hook@keylist@nodynamics{#1}{#2}},
6880 process keylist''/.code 2 args={\forest@process@hook@keylist@{#1}{#2}},
6881 process keylist register/.code={\forest@process@keylist@register{#1}},
6882 process delayed/.code={%
6883 \forest@havedelayedoptions{@delay}{#1}%
6884 \ifforest@havedelayedoptions
6885 \forest@process@hook@keylist@nodynamics{@delay}{#1}%
6886 \fi
6887 },
6888 do dynamics/.code={%
6889 \the\forest@do@dynamics
6890 \forest@do@dynamics{}%
6891 \forest@node@Compute@numeric@ts@info{\forest@root}%
6892 },
6893 declare keylist={given options}{},
6894 declare keylist={before typesetting nodes}{},
6895 declare keylist={before packing}{},
6896 declare keylist={before packing node}{},
6897 declare keylist={after packing node}{},
6898 declare keylist={before computing xy}{},
6899 declare keylist={before drawing tree}{},
6900 declare keylist={delay}{},
6901 delay n/.code 2 args={%
6902 \forestmathsetcount\forest@temp@count{#1}%
6903 \pgfkeysalso{delay n'={\forest@temp@count}{#2}}%
6904 },
6905 delay n'/.code 2 args={
6906 \ifnum#1=0
6907 \pgfkeysalso{#2}%
6908 \else
6909 \pgfkeysalso{delay={delay n'/.expand once=\expandafter{\number\numexpr#1-1\relax}{#2}}}%
6910 \fi
6911 },
6912 if have delayed/.style 2 args={if have delayed'={processing order}{#1}{#2}},
6913 if have delayed'/.code n args=3{%
6914 \forest@havedelayedoptionsfalse
6915 \forest@forthis{%
6916 \forest@nodewalk{#1}{%
6917 TeX={%
6918 \forestoget{delay}\forest@temp@delayed
6919 \ifdefempty\forest@temp@delayed{}{\forest@havedelayedoptionstrue}%
6920 }%
6921 }%
6922 }%
6923 \ifforest@havedelayedoptions\pgfkeysalso{#2}\else\pgfkeysalso{#3}\fi
6924 },
6925 typeset nodes/.code={%
6926 \forest@drawtree@preservenodeboxes@false
6927 \forest@nodewalk
6928 {typeset nodes processing order/.try,processing order/.lastretry}%
6929 {TeX={\forest@node@typeset}}%
6930 },
6931 typeset nodes'/.code={%
6932 \forest@drawtree@preservenodeboxes@true
6933 \forest@nodewalk
6934 {typeset nodes processing order/.try,processing order/.lastretry}%
6935 {TeX={\forest@node@typeset}}%
6936 },
6937 typeset node/.code={%
6938 \forest@drawtree@preservenodeboxes@false
6939 \forest@node@typeset
6940 },
6941 pack/.code={\forest@pack},
6942 pack'/.code={\forest@pack@onlythisnode},
6943 compute xy/.code={\forest@node@computeabsolutepositions},
6944 draw tree box/.store in=\forest@drawtreebox,
6945 draw tree box,
6946 draw tree/.code={%
6947 \forest@drawtree@preservenodeboxes@false
6948 \forest@node@drawtree
6949 },
6950 draw tree'/.code={%
6951 \forest@drawtree@preservenodeboxes@true
6952 \forest@node@drawtree
6953 },
6954 %%% begin listing region: draw_tree_method
6955 draw tree method/.style={
6956 for nodewalk={
6957 draw tree nodes processing order/.try,
6958 draw tree processing order/.retry,
6959 processing order/.lastretry
6960 }{draw tree node},
6961 for nodewalk={
6962 draw tree edges processing order/.try,
6963 draw tree processing order/.retry,
6964 processing order/.lastretry
6965 }{draw tree edge},
6966 for nodewalk={
6967 draw tree tikz processing order/.try,
6968 draw tree processing order/.retry,
6969 processing order/.lastretry
6970 }{draw tree tikz}
6971 },
6972 %%% end listing region: draw_tree_method
6973 draw tree node/.code={\forest@draw@node},
6974 draw tree node'/.code={\forest@draw@node@},
6975 if node drawn/.code n args={3}{%
6976 \forest@forthis{%
6977 \forest@configured@nodewalk{independent}{inherited}{fake}{#1}{}%
6978 \ifnum\forest@cn=0
6979 \forest@tempfalse
6980 \else
6981 \ifcsdef{forest@drawn@\forest@cn}{\forest@temptrue}{\forest@tempfalse}%
6982 \fi
6983 }%
6984 \ifforest@temp\pgfkeysalso{#2}\else\pgfkeysalso{#3}\fi
6985 },
6986 draw tree edge/.code={\forest@draw@edge},
6987 draw tree edge'/.code={\forest@draw@edge@},
6988 draw tree tikz/.code={\forest@draw@tikz@}, % always!
6989 draw tree tikz'/.code={\forest@draw@tikz@},
6990 processing order/.nodewalk style={tree},
6991 %given options processing order/.style={processing order},
6992 %before typesetting nodes processing order/.style={processing order},
6993 %before packing processing order/.style={processing order},
6994 %before computing xy processing order/.style={processing order},
6995 %before drawing tree processing order/.style={processing order},
6996 }
6997 \newtoks\forest@do@dynamics
6998 \newif\ifforest@havedelayedoptions
6999 \def\forest@process@hook@keylist#1#2{%,#1=keylist,#2=processing order nodewalk
7000 \safeloop
7001 \forest@fornode{\forest@root}{\forest@process@hook@keylist@{#1}{#2}}%
7002 \expandafter\ifstrempty\expandafter{\the\forest@do@dynamics}{}{%
7003 \the\forest@do@dynamics
7004 \forest@do@dynamics={}%
7005 \forest@node@Compute@numeric@ts@info{\forest@root}%
7006 }%
7007 \forest@fornode{\forest@root}{\forest@havedelayedoptions{#1}{#2}}%
7008 \ifforest@havedelayedoptions
7009 \saferepeat
7010 }
7011 \def\forest@process@hook@keylist@nodynamics#1#2{%#1=keylist,#2=processing order nodewalk
7012 % note: this macro works on (nodewalk starting at) the current node
7013 \safeloop
7014 \forest@forthis{\forest@process@hook@keylist@{#1}{#2}}%
7015 \forest@havedelayedoptions{#1}{#2}%
7016 \ifforest@havedelayedoptions
7017 \saferepeat
7018 }
7019 \def\forest@process@hook@keylist@#1#2{%#1=keylist,#2=processing order nodewalk
7020 \forest@nodewalk{#2}{%
7021 TeX={%
7022 \forestoget{#1}\forest@temp@keys
7023 \ifdefvoid\forest@temp@keys{}{%
7024 \forestoset{#1}{}%
7025 \expandafter\forestset\expandafter{\forest@temp@keys}%
7026 }%
7027 }%
7028 }%
7029 }
7030 \def\forest@process@keylist@register#1{%
7031 \edef\forest@marshal{%
7032 \noexpand\forestset{\forestregister{#1}}%
7033 }\forest@marshal
7034 }
7035 % \end{macrocode}
7036 % Clear the keylist, transfer delayed into it, and set |\ifforest@havedelayedoptions|.
7037 % \begin{macrocode}
7038 \def\forest@havedelayedoptions#1#2{%#1 = keylist, #2=nodewalk
7039 \forest@havedelayedoptionsfalse
7040 \forest@forthis{%
7041 \forest@nodewalk{#2}{%
7042 TeX={%
7043 \forestoget{delay}\forest@temp@delayed
7044 \ifdefempty\forest@temp@delayed{}{\forest@havedelayedoptionstrue}%
7045 \forestolet{#1}\forest@temp@delayed
7046 \forestoset{delay}{}%
7047 }%
7048 }%
7049 }%
7050 }
7051 % \end{macrocode}
7052 %
7053 % \subsection{Typesetting nodes}
7054 %
7055 % \begin{macrocode}
7056 \def\forest@node@typeset{%
7057 \let\forest@next\forest@node@typeset@
7058 \forestoifdefined{@box}{%
7059 \forestoget{@box}\forest@temp
7060 \ifdefempty\forest@temp{%
7061 \locbox\forest@temp@box
7062 \forestolet{@box}\forest@temp@box
7063 }{%
7064 \ifforest@drawtree@preservenodeboxes@
7065 \let\forest@next\relax
7066 \fi
7067 }%
7068 }{%
7069 \locbox\forest@temp@box
7070 \forestolet{@box}\forest@temp@box
7071 }%
7072 \def\forest@node@typeset@restore{}%
7073 \ifdefined\ifsa@tikz\forest@standalone@hack\fi
7074 \forest@next
7075 \forest@node@typeset@restore
7076 }
7077 \def\forest@standalone@hack{%
7078 \ifsa@tikz
7079 \let\forest@standalone@tikzpicture\tikzpicture
7080 \let\forest@standalone@endtikzpicture\endtikzpicture
7081 \let\tikzpicture\sa@orig@tikzpicture
7082 \let\endtikzpicture\sa@orig@endtikzpicture
7083 \def\forest@node@typeset@restore{%
7084 \let\tikzpicture\forest@standalone@tikzpicture
7085 \let\endtikzpicture\forest@standalone@endtikzpicture
7086 }%
7087 \fi
7088 }
7089 \newbox\forest@box
7090 \def\forest@pgf@notyetpositioned{not yet positionedPGFINTERNAL}
7091 \def\forest@node@typeset@{%
7092 \forestanchortotikzanchor{anchor}\forest@temp
7093 \edef\forest@marshal{%
7094 \noexpand\forestolet{anchor}\noexpand\forest@temp
7095 \noexpand\forest@node@typeset@@
7096 \noexpand\forestoset{anchor}{\forestov{anchor}}%
7097 }\forest@marshal
7098 }
7099 \def\forest@node@typeset@@{%
7100 \forestoget{name}\forest@nodename
7101 \edef\forest@temp@nodeformat{\forestove{node format}}%
7102 \gdef\forest@smuggle{}%
7103 \setbox0=\hbox{%
7104 \begin{tikzpicture}[%
7105 /forest/copy command key={/tikz/anchor}{/tikz/forest@orig@anchor},
7106 anchor/.style={%
7107 /forest/TeX={\forestanchortotikzanchor{##1}\forest@temp@anchor},
7108 forest@orig@anchor/.expand once=\forest@temp@anchor
7109 }]
7110 \pgfpositionnodelater{\forest@positionnodelater@save}%
7111 \forest@temp@nodeformat
7112 \pgfinterruptpath
7113 \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{forestcomputenodeboundary}%
7114 \endpgfinterruptpath
7115 \end{tikzpicture}%
7116 }%
7117 \setbox\forestove{@box}=\box\forest@box % smuggle the box
7118 \forestolet{@boundary}\forest@global@boundary
7119 \forest@smuggle % ... and the rest
7120 }
7121
7122
7123 \forestset{
7124 declare readonly dimen={min x}{0pt},
7125 declare readonly dimen={min y}{0pt},
7126 declare readonly dimen={max x}{0pt},
7127 declare readonly dimen={max y}{0pt},
7128 }
7129 \def\forest@patch@enormouscoordinateboxbounds@plus#1{%
7130 \expandafter\ifstrequal\expandafter{#1}{16000.0pt}{\edef#1{0.0\pgfmath@pt}}{}%
7131 }
7132 \def\forest@patch@enormouscoordinateboxbounds@minus#1{%
7133 \expandafter\ifstrequal\expandafter{#1}{-16000.0pt}{\edef#1{0.0\pgfmath@pt}}{}%
7134 }
7135 \def\forest@positionnodelater@save{%
7136 \global\setbox\forest@box=\box\pgfpositionnodelaterbox
7137 \xappto\forest@smuggle{\noexpand\forestoset{later@name}{\pgfpositionnodelatername}}%
7138 % a bug in pgf? ---well, here's a patch
7139 \forest@patch@enormouscoordinateboxbounds@plus\pgfpositionnodelaterminx
7140 \forest@patch@enormouscoordinateboxbounds@plus\pgfpositionnodelaterminy
7141 \forest@patch@enormouscoordinateboxbounds@minus\pgfpositionnodelatermaxx
7142 \forest@patch@enormouscoordinateboxbounds@minus\pgfpositionnodelatermaxy
7143 % end of patch
7144 % when shape=coordinate, pgf returns \pgfpositionnodelater... with wrong catcode of pt
7145 \forest@pnn@addtosmuggle{min x}\pgfpositionnodelaterminx
7146 \forest@pnn@addtosmuggle{max x}\pgfpositionnodelatermaxx
7147 \forest@pnn@addtosmuggle{min y}\pgfpositionnodelaterminy
7148 \forest@pnn@addtosmuggle{max y}\pgfpositionnodelatermaxy
7149 }
7150 \def\forest@pnn@addtosmuggle#1#2{%
7151 {%
7152 \pgfutil@tempdima=#2\relax
7153 \xappto\forest@smuggle{\noexpand\forestoset{#1}{\the\pgfutil@tempdima}}%
7154 }%
7155 }
7156 \def\forest@node@forest@positionnodelater@restore{%
7157 \ifforest@drawtree@preservenodeboxes@
7158 \let\forest@boxorcopy\copy
7159 \else
7160 \let\forest@boxorcopy\box
7161 \fi
7162 \forestoget{@box}\forest@temp
7163 \setbox\pgfpositionnodelaterbox=\forest@boxorcopy\forest@temp
7164 \edef\pgfpositionnodelatername{\forestove{later@name}}%
7165 \edef\pgfpositionnodelaterminx{\forestove{min x}}%
7166 \edef\pgfpositionnodelaterminy{\forestove{min y}}%
7167 \edef\pgfpositionnodelatermaxx{\forestove{max x}}%
7168 \edef\pgfpositionnodelatermaxy{\forestove{max y}}%
7169 \ifforest@drawtree@preservenodeboxes@
7170 \else
7171 \forestoset{@box}{}%
7172 \fi
7173 }
7174 % \end{macrocode}
7175 %
7176 % \subsection{Packing}
7177 % \label{imp:packing}
7178 %
7179 % Method |pack| should be called to calculate the positions of
7180 % descendant nodes; the positions are stored in attributes |l| and |s|
7181 % of these nodes, in a level/sibling coordinate system with origin at
7182 % the parent's anchor.
7183 % \begin{macrocode}
7184 \def\forest@pack{%
7185 \pgfsyssoftpath@getcurrentpath\forest@pack@original@path
7186 \forest@pack@computetiers
7187 \forest@pack@computegrowthuniformity
7188 \forest@@pack
7189 \pgfsyssoftpath@setcurrentpath\forest@pack@original@path
7190 }
7191 \def\forest@@pack{%
7192 \ifnum\forestove{uniform growth}>0
7193 \ifnum\forestove{n children}>0
7194 \forest@pack@level@uniform
7195 \forest@pack@aligntiers@ofsubtree
7196 \forest@pack@sibling@uniform@recursive
7197 \fi
7198 \else
7199 \forest@node@foreachchild{\forest@@pack}%
7200 \forest@process@hook@keylist@nodynamics{before packing node}{current}%
7201 \ifnum\forestove{n children}>0
7202 \forest@pack@level@nonuniform
7203 \forest@pack@aligntiers
7204 \forest@pack@sibling@uniform@applyreversed
7205 \fi
7206 \forestoget{after packing node}\forest@temp@keys
7207 \forest@process@hook@keylist@nodynamics{after packing node}{current}%
7208 \fi
7209 }
7210 % \forestset{recalculate tree boundary/.code={\forest@node@recalculate@edges}}
7211 % \def\forest@node@recalculate@edges{%
7212 % \edef\forest@marshal{%
7213 % \noexpand\forest@forthis{\noexpand\forest@node@getedges{\forestove{grow}}}%
7214 % }\forest@marshal
7215 % }
7216 \def\forest@pack@onlythisnode{%
7217 \ifnum\forestove{n children}>0
7218 \forest@pack@computetiers
7219 \forest@pack@level@nonuniform
7220 \forest@pack@aligntiers
7221 \forest@node@foreachchild{\forestoset{s}{0\pgfmath@pt}}%
7222 \forest@pack@sibling@uniform@applyreversed
7223 \fi
7224 }
7225 % \end{macrocode}
7226 %
7227 % Compute growth uniformity for the subtree. A tree grows uniformly is all its branching nodes have
7228 % the same |grow|.
7229 % \begin{macrocode}
7230 \def\forest@pack@computegrowthuniformity{%
7231 \forest@node@foreachchild{\forest@pack@computegrowthuniformity}%
7232 \edef\forest@pack@cgu@uniformity{%
7233 \ifnum\forestove{n children}=0
7234 2\else 1\fi
7235 }%
7236 \forestoget{grow}\forest@pack@cgu@parentgrow
7237 \forest@node@foreachchild{%
7238 \ifnum\forestove{uniform growth}=0
7239 \def\forest@pack@cgu@uniformity{0}%
7240 \else
7241 \ifnum\forestove{uniform growth}=1
7242 \ifnum\forestove{grow}=\forest@pack@cgu@parentgrow\relax\else
7243 \def\forest@pack@cgu@uniformity{0}%
7244 \fi
7245 \fi
7246 \fi
7247 }%
7248 \forestoget{before packing node}\forest@temp@a
7249 \forestoget{after packing node}\forest@temp@b
7250 \expandafter\expandafter\expandafter\ifstrempty\expandafter\expandafter\expandafter{\expandafter\forest@temp@a\forest@temp@b}{%
7251 \forestolet{uniform growth}\forest@pack@cgu@uniformity
7252 }{%
7253 \forestoset{uniform growth}{0}%
7254 }%
7255 }
7256 % \end{macrocode}
7257 %
7258 % Pack children in the level dimension in a uniform tree.
7259 % \begin{macrocode}
7260 \def\forest@pack@level@uniform{%
7261 \let\forest@plu@minchildl\relax
7262 \forestoget{grow}\forest@plu@grow
7263 \forest@node@foreachchild{%
7264 \forest@node@getboundingrectangle@ls{\forest@plu@grow}%
7265 \advance\pgf@xa\forestove{l}\relax
7266 \ifx\forest@plu@minchildl\relax
7267 \edef\forest@plu@minchildl{\the\pgf@xa}%
7268 \else
7269 \ifdim\pgf@xa<\forest@plu@minchildl\relax
7270 \edef\forest@plu@minchildl{\the\pgf@xa}%
7271 \fi
7272 \fi
7273 }%
7274 \forest@node@getboundingrectangle@ls{\forest@plu@grow}%
7275 \pgfutil@tempdima=\pgf@xb\relax
7276 \advance\pgfutil@tempdima -\forest@plu@minchildl\relax
7277 \advance\pgfutil@tempdima \forestove{l sep}\relax
7278 \ifdim\pgfutil@tempdima>0pt
7279 \forest@node@foreachchild{%
7280 \forestoeset{l}{\the\dimexpr\forestove{l}+\the\pgfutil@tempdima}%
7281 }%
7282 \fi
7283 \forest@node@foreachchild{%
7284 \ifnum\forestove{n children}>0
7285 \forest@pack@level@uniform
7286 \fi
7287 }%
7288 }
7289 % \end{macrocode}
7290 %
7291 % Pack children in the level dimension in a non-uniform tree. (Expects
7292 % the children to be fully packed.)
7293 % \begin{macrocode}
7294 \def\forest@pack@level@nonuniform{%
7295 \let\forest@plu@minchildl\relax
7296 \forestoget{grow}\forest@plu@grow
7297 \forest@node@foreachchild{%
7298 \forest@node@getedge{negative}{\forest@plu@grow}{\forest@plnu@negativechildedge}%
7299 \forest@node@getedge{positive}{\forest@plu@grow}{\forest@plnu@positivechildedge}%
7300 \def\forest@plnu@childedge{\forest@plnu@negativechildedge\forest@plnu@positivechildedge}%
7301 \forest@path@getboundingrectangle@ls\forest@plnu@childedge{\forest@plu@grow}%
7302 \advance\pgf@xa\forestove{l}\relax
7303 \ifx\forest@plu@minchildl\relax
7304 \edef\forest@plu@minchildl{\the\pgf@xa}%
7305 \else
7306 \ifdim\pgf@xa<\forest@plu@minchildl\relax
7307 \edef\forest@plu@minchildl{\the\pgf@xa}%
7308 \fi
7309 \fi
7310 }%
7311 \forest@node@getboundingrectangle@ls{\forest@plu@grow}%
7312 \pgfutil@tempdima=\pgf@xb\relax
7313 \advance\pgfutil@tempdima -\forest@plu@minchildl\relax
7314 \advance\pgfutil@tempdima \forestove{l sep}\relax
7315 \ifdim\pgfutil@tempdima>0pt
7316 \forest@node@foreachchild{%
7317 \forestoeset{l}{\the\dimexpr\the\pgfutil@tempdima+\forestove{l}}%
7318 }%
7319 \fi
7320 }
7321 % \end{macrocode}
7322 %
7323 % Align tiers.
7324 % \begin{macrocode}
7325 \def\forest@pack@aligntiers{%
7326 \forestoget{grow}\forest@temp@parentgrow
7327 \forestoget{@tiers}\forest@temp@tiers
7328 \forlistloop\forest@pack@aligntier@\forest@temp@tiers
7329 }
7330 \def\forest@pack@aligntiers@ofsubtree{%
7331 \forest@node@foreach{\forest@pack@aligntiers}%
7332 }
7333 \def\forest@pack@aligntiers@computeabsl{%
7334 \forestoleto{abs@l}{l}%
7335 \forest@node@foreachdescendant{\forest@pack@aligntiers@computeabsl@}%
7336 }
7337 \def\forest@pack@aligntiers@computeabsl@{%
7338 \forestoeset{abs@l}{\the\dimexpr\forestove{l}+\forestOve{\forestove{@parent}}{abs@l}}%
7339 }
7340 \def\forest@pack@aligntier@#1{%
7341 \forest@pack@aligntiers@computeabsl
7342 \pgfutil@tempdima=-\maxdimen\relax
7343 \def\forest@temp@currenttier{#1}%
7344 \forest@node@foreach{%
7345 \forestoget{tier}\forest@temp@tier
7346 \ifx\forest@temp@currenttier\forest@temp@tier
7347 \ifdim\pgfutil@tempdima<\forestove{abs@l}\relax
7348 \pgfutil@tempdima=\forestove{abs@l}\relax
7349 \fi
7350 \fi
7351 }%
7352 \ifdim\pgfutil@tempdima=-\maxdimen\relax\else
7353 \forest@node@foreach{%
7354 \forestoget{tier}\forest@temp@tier
7355 \ifx\forest@temp@currenttier\forest@temp@tier
7356 \forestoeset{l}{\the\dimexpr\pgfutil@tempdima-\forestove{abs@l}+\forestove{l}}%
7357 \fi
7358 }%
7359 \fi
7360 }
7361 % \end{macrocode}
7362 % Pack children in the sibling dimension in a uniform tree:
7363 % recursion.
7364 % \begin{macrocode}
7365 \def\forest@pack@sibling@uniform@recursive{%
7366 \forest@node@foreachchild{\forest@pack@sibling@uniform@recursive}%
7367 \forest@pack@sibling@uniform@applyreversed
7368 }
7369 % \end{macrocode}
7370 % Pack children in the sibling dimension in a uniform tree: applyreversed.
7371 % \begin{macrocode}
7372 \def\forest@pack@sibling@uniform@applyreversed{%
7373 \ifnum\forestove{n children}>1
7374 \ifnum\forestove{reversed}=0
7375 \forest@pack@sibling@uniform@main{first}{last}{next}{previous}%
7376 \else
7377 \forest@pack@sibling@uniform@main{last}{first}{previous}{next}%
7378 \fi
7379 \else
7380 \ifnum\forestove{n children}=1
7381 % \end{macrocode}
7382 % No need to run packing, but we still need to align the children.
7383 % \begin{macrocode}
7384 \csname forest@calign@\forestove{calign}\endcsname
7385 \fi
7386 \fi
7387 }
7388 % \end{macrocode}
7389 % Pack children in the sibling dimension in a uniform tree: the main
7390 % routine.
7391 % \begin{macrocode}
7392 \def\forest@pack@sibling@uniform@main#1#2#3#4{%
7393 % \end{macrocode}
7394 % Loop through the children. At each iteration, we compute the
7395 % distance between the negative edge of the current child and the
7396 % positive edge of the block of the previous children, and then set
7397 % the |s| attribute of the current child accordingly.
7398 %
7399 % We start the loop with the second (to last) child, having
7400 % initialized the positive edge of the previous children to the
7401 % positive edge of the first child.
7402 % \begin{macrocode}
7403 \forestoget{@#1}\forest@child
7404 \edef\forest@marshal{%
7405 \noexpand\forest@fornode{\forestove{@#1}}{%
7406 \noexpand\forest@node@getedge
7407 {positive}%
7408 {\forestove{grow}}%
7409 \noexpand\forest@temp@edge
7410 }%
7411 }\forest@marshal
7412 \forest@pack@pgfpoint@childsposition\forest@child
7413 \let\forest@previous@positive@edge\pgfutil@empty
7414 \forest@extendpath\forest@previous@positive@edge\forest@temp@edge{}%
7415 \forestOget{\forest@child}{@#3}\forest@child
7416 % \end{macrocode}
7417 % Loop until the current child is the null node.
7418 % \begin{macrocode}
7419 \edef\forest@previous@child@s{0\pgfmath@pt}%
7420 \safeloop
7421 \unless\ifnum\forest@child=0
7422 % \end{macrocode}
7423 % Get the negative edge of the child.
7424 % \begin{macrocode}
7425 \edef\forest@temp{%
7426 \noexpand\forest@fornode{\forest@child}{%
7427 \noexpand\forest@node@getedge
7428 {negative}%
7429 {\forestove{grow}}%
7430 \noexpand\forest@temp@edge
7431 }%
7432 }\forest@temp
7433 % \end{macrocode}
7434 % Set |\pgf@x| and |\pgf@y| to the position of the child (in the
7435 % coordinate system of this node).
7436 % \begin{macrocode}
7437 \forest@pack@pgfpoint@childsposition\forest@child
7438 % \end{macrocode}
7439 % Translate the edge of the child by the child's position.
7440 % \begin{macrocode}
7441 \let\forest@child@negative@edge\pgfutil@empty
7442 \forest@extendpath\forest@child@negative@edge\forest@temp@edge{}%
7443 % \end{macrocode}
7444 % Setup the grow line: the angle is given by this node's |grow|
7445 % attribute.
7446 % \begin{macrocode}
7447 \forest@setupgrowline{\forestove{grow}}%
7448 % \end{macrocode}
7449 % Get the distance (wrt the grow line) between the positive edge of
7450 % the previous children and the negative edge of the current
7451 % child. (The distance can be negative!)
7452 % \begin{macrocode}
7453 \forest@distance@between@edge@paths\forest@previous@positive@edge\forest@child@negative@edge\forest@csdistance
7454 % \end{macrocode}
7455 % If the distance is |\relax|, the projections of the edges onto the
7456 % grow line don't overlap: do nothing. Otherwise, shift the current child so that its distance to the block
7457 % of previous children is |s_sep|.
7458 % \begin{macrocode}
7459 \ifx\forest@csdistance\relax
7460 %\forestOeset{\forest@child}{s}{\forest@previous@child@s}%
7461 \else
7462 \advance\pgfutil@tempdimb-\forest@csdistance\relax
7463 \advance\pgfutil@tempdimb\forestove{s sep}\relax
7464 \forestOeset{\forest@child}{s}{\the\dimexpr\forestOve{\forest@child}{s}-\forest@csdistance+\forestove{s sep}}%
7465 \fi
7466 % \end{macrocode}
7467 % Retain monotonicity (is this ok?). (This problem arises when the adjacent children's |l| are too
7468 % far apart.)
7469 % \begin{macrocode}
7470 \ifdim\forestOve{\forest@child}{s}<\forest@previous@child@s\relax
7471 \forestOeset{\forest@child}{s}{\forest@previous@child@s}%
7472 \fi
7473 % \end{macrocode}
7474 % Prepare for the next iteration: add the current child's positive
7475 % edge to the positive edge of the previous children, and set up the
7476 % next current child.
7477 % \begin{macrocode}
7478 \forestOget{\forest@child}{s}\forest@child@s
7479 \edef\forest@previous@child@s{\forest@child@s}%
7480 \edef\forest@temp{%
7481 \noexpand\forest@fornode{\forest@child}{%
7482 \noexpand\forest@node@getedge
7483 {positive}%
7484 {\forestove{grow}}%
7485 \noexpand\forest@temp@edge
7486 }%
7487 }\forest@temp
7488 \forest@pack@pgfpoint@childsposition\forest@child
7489 \forest@extendpath\forest@previous@positive@edge\forest@temp@edge{}%
7490 \forest@getpositivetightedgeofpath\forest@previous@positive@edge\forest@previous@positive@edge
7491 \forestOget{\forest@child}{@#3}\forest@child
7492 \saferepeat
7493 % \end{macrocode}
7494 % Shift the position of all children to achieve the desired alignment
7495 % of the parent and its children.
7496 % \begin{macrocode}
7497 \csname forest@calign@\forestove{calign}\endcsname
7498 }
7499 % \end{macrocode}
7500 % Get the position of child |#1| in the current node, in node's l-s
7501 % coordinate system.
7502 % \begin{macrocode}
7503 \def\forest@pack@pgfpoint@childsposition#1{%
7504 {%
7505 \pgftransformreset
7506 \forest@pgfqtransformrotate{\forestove{grow}}%
7507 \forest@fornode{#1}{%
7508 \pgfpointtransformed{\pgfqpoint{\forestove{l}}{\forestove{s}}}%
7509 }%
7510 }%
7511 }
7512 % \end{macrocode}
7513 % Get the position of the node in the grow (|#1|)-rotated coordinate
7514 % system.
7515 % \begin{macrocode}
7516 \def\forest@pack@pgfpoint@positioningrow#1{%
7517 {%
7518 \pgftransformreset
7519 \forest@pgfqtransformrotate{#1}%
7520 \pgfpointtransformed{\pgfqpoint{\forestove{l}}{\forestove{s}}}%
7521 }%
7522 }
7523 % \end{macrocode}
7524 %
7525 % Child alignment.
7526 % \begin{macrocode}
7527 \def\forest@calign@s@shift#1{%
7528 \pgfutil@tempdima=#1\relax
7529 \forest@node@foreachchild{%
7530 \forestoeset{s}{\the\dimexpr\forestove{s}+\pgfutil@tempdima}%
7531 }%
7532 }
7533 \def\forest@calign@child{%
7534 \forest@calign@s@shift{-\forestOve{\forest@node@nornbarthchildid{\forestove{calign primary child}}}{s}}%
7535 }
7536 \csdef{forest@calign@child edge}{%
7537 {%
7538 \edef\forest@temp@child{\forest@node@nornbarthchildid{\forestove{calign primary child}}}%
7539 \pgftransformreset
7540 \forest@pgfqtransformrotate{\forestove{grow}}%
7541 \pgfpointtransformed{\pgfqpoint{\forestOve{\forest@temp@child}{l}}{\forestOve{\forest@temp@child}{s}}}%
7542 \pgf@xa=\pgf@x\relax\pgf@ya=\pgf@y\relax
7543 \forest@Pointanchor{\forest@temp@child}{child anchor}%
7544 \advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
7545 \forest@pointanchor{parent anchor}%
7546 \advance\pgf@xa-\pgf@x\relax\advance\pgf@ya-\pgf@y\relax
7547 \edef\forest@marshal{%
7548 \noexpand\pgftransformreset
7549 \noexpand\forest@pgfqtransformrotate{-\forestove{grow}}%
7550 \noexpand\pgfpointtransformed{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
7551 }\forest@marshal
7552 }%
7553 \forest@calign@s@shift{\the\dimexpr-\the\pgf@y}%
7554 }
7555 \csdef{forest@calign@midpoint}{%
7556 \forest@calign@s@shift{\the\dimexpr 0pt -%
7557 (\forestOve{\forest@node@nornbarthchildid{\forestove{calign primary child}}}{s}%
7558 +\forestOve{\forest@node@nornbarthchildid{\forestove{calign secondary child}}}{s}%
7559 )/2\relax
7560 }%
7561 }
7562 \csdef{forest@calign@edge midpoint}{%
7563 {%
7564 \edef\forest@temp@firstchild{\forest@node@nornbarthchildid{\forestove{calign primary child}}}%
7565 \edef\forest@temp@secondchild{\forest@node@nornbarthchildid{\forestove{calign secondary child}}}%
7566 \pgftransformreset
7567 \forest@pgfqtransformrotate{\forestove{grow}}%
7568 \pgfpointtransformed{\pgfqpoint{\forestOve{\forest@temp@firstchild}{l}}{\forestOve{\forest@temp@firstchild}{s}}}%
7569 \pgf@xa=\pgf@x\relax\pgf@ya=\pgf@y\relax
7570 \forest@Pointanchor{\forest@temp@firstchild}{child anchor}%
7571 \advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
7572 \edef\forest@marshal{%
7573 \noexpand\pgfpointtransformed{\noexpand\pgfqpoint{\forestOve{\forest@temp@secondchild}{l}}{\forestOve{\forest@temp@secondchild}{s}}}%
7574 }\forest@marshal
7575 \advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
7576 \forest@Pointanchor{\forest@temp@secondchild}{child anchor}%
7577 \advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
7578 \divide\pgf@xa2 \divide\pgf@ya2
7579 \forest@pointanchor{parent anchor}%
7580 \advance\pgf@xa-\pgf@x\relax\advance\pgf@ya-\pgf@y\relax
7581 \edef\forest@marshal{%
7582 \noexpand\pgftransformreset
7583 \noexpand\forest@pgfqtransformrotate{-\forestove{grow}}%
7584 \noexpand\pgfpointtransformed{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
7585 }\forest@marshal
7586 }%
7587 \forest@calign@s@shift{\the\dimexpr-\the\pgf@y}%
7588 }
7589 % \end{macrocode}
7590 % Aligns the children to the center of the angles given by the options
7591 % |calign_first_angle| and |calign_second_angle| and spreads them additionally if needed to fill the
7592 % whole
7593 % space determined by the option. The version |fixed_angles| calculates the
7594 % angles between node anchors; the version |fixes_edge_angles| calculates the angles between the
7595 % node edges.
7596 % \begin{macrocode}
7597 \def\forest@edef@strippt#1#2{%
7598 \edef#1{#2}%
7599 \edef#1{\expandafter\Pgf@geT#1}%
7600 }
7601 \csdef{forest@calign@fixed angles}{%
7602 \ifnum\forestove{n children}>1
7603 \edef\forest@ca@first@child{\forest@node@nornbarthchildid{\forestove{calign primary child}}}%
7604 \edef\forest@ca@second@child{\forest@node@nornbarthchildid{\forestove{calign secondary child}}}%
7605 \ifnum\forestove{reversed}=1
7606 \let\forest@temp\forest@ca@first@child
7607 \let\forest@ca@first@child\forest@ca@second@child
7608 \let\forest@ca@second@child\forest@temp
7609 \fi
7610 \forestOget{\forest@ca@first@child}{l}\forest@ca@first@l
7611 \edef\forest@ca@first@l{\expandafter\Pgf@geT\forest@ca@first@l}%
7612 \forestOget{\forest@ca@second@child}{l}\forest@ca@second@l
7613 \edef\forest@ca@second@l{\expandafter\Pgf@geT\forest@ca@second@l}%
7614 \pgfmathtan@{\forestove{calign secondary angle}}%
7615 \pgfmathmultiply@{\pgfmathresult}{\forest@ca@second@l}%
7616 \let\forest@calign@temp\pgfmathresult
7617 \pgfmathtan@{\forestove{calign primary angle}}%
7618 \pgfmathmultiply@{\pgfmathresult}{\forest@ca@first@l}%
7619 \edef\forest@ca@desired@s@distance{\the\dimexpr
7620 \forest@calign@temp pt-\pgfmathresult pt}%
7621 % \pgfmathsetlengthmacro\forest@ca@desired@s@distance{%
7622 % tan(\forestove{calign secondary angle})*\forest@ca@second@l
7623 % -tan(\forestove{calign primary angle})*\forest@ca@first@l
7624 % }%
7625 \forestOget{\forest@ca@first@child}{s}\forest@ca@first@s
7626 \forestOget{\forest@ca@second@child}{s}\forest@ca@second@s
7627 \edef\forest@ca@actual@s@distance{\the\dimexpr
7628 \forest@ca@second@s-\forest@ca@first@s}%
7629 %\pgfmathsetlengthmacro\forest@ca@actual@s@distance{%
7630 % \forest@ca@second@s-\forest@ca@first@s}%
7631 \ifdim\forest@ca@desired@s@distance>\forest@ca@actual@s@distance\relax
7632 \ifdim\forest@ca@actual@s@distance=0pt
7633 \pgfmathtan@{\forestove{calign primary angle}}%
7634 \pgfmathmultiply@{\pgfmathresult}{\forest@ca@second@l}%
7635 \pgfutil@tempdima=\pgfmathresult pt
7636 % \pgfmathsetlength\pgfutil@tempdima{tan(\forestove{calign primary angle})*\forest@ca@second@l}%
7637 \pgfutil@tempdimb=\dimexpr
7638 \forest@ca@desired@s@distance/(\forestove{n children}-1)\relax%
7639 %\pgfmathsetlength\pgfutil@tempdimb{\forest@ca@desired@s@distance/(\forestove{n children}-1)}%
7640 \forest@node@foreachchild{%
7641 \forestoeset{s}{\the\pgfutil@tempdima}%
7642 \advance\pgfutil@tempdima\pgfutil@tempdimb
7643 }%
7644 \def\forest@calign@anchor{0pt}%
7645 \else
7646 \edef\forest@marshal{\noexpand\pgfmathdivide@
7647 {\expandafter\Pgf@geT\forest@ca@desired@s@distance}%
7648 {\expandafter\Pgf@geT\forest@ca@actual@s@distance}%
7649 }\forest@marshal
7650 \let\forest@ca@ratio\pgfmathresult
7651 %\pgfmathsetmacro\forest@ca@ratio{%
7652 % \forest@ca@desired@s@distance/\forest@ca@actual@s@distance}%
7653 \forest@node@foreachchild{%
7654 \forest@edef@strippt\forest@temp{\forestove{s}}%
7655 \pgfmathmultiply@{\forest@ca@ratio}{\forest@temp}%
7656 \forestoeset{s}{\the\dimexpr\pgfmathresult pt}%
7657 %\pgfmathsetlengthmacro\forest@temp{\forest@ca@ratio*\forestove{s}}%
7658 %\forestolet{s}\forest@temp
7659 }%
7660 \pgfmathtan@{\forestove{calign primary angle}}%
7661 \pgfmathmultiply@{\pgfmathresult}{\forest@ca@first@l}%
7662 \edef\forest@calign@anchor{\the\dimexpr-\pgfmathresult pt}%
7663 %\pgfmathsetlengthmacro\forest@calign@anchor{%
7664 % -tan(\forestove{calign primary angle})*\forest@ca@first@l}%
7665 \fi
7666 \else
7667 \ifdim\forest@ca@desired@s@distance<\forest@ca@actual@s@distance\relax
7668 \edef\forest@marshal{\noexpand\pgfmathdivide@
7669 {\expandafter\Pgf@geT\forest@ca@actual@s@distance}%
7670 {\expandafter\Pgf@geT\forest@ca@desired@s@distance}%
7671 }\forest@marshal
7672 \let\forest@ca@ratio\pgfmathresult
7673 %\pgfmathsetlengthmacro\forest@ca@ratio{%
7674 % \forest@ca@actual@s@distance/\forest@ca@desired@s@distance}%
7675 \forest@node@foreachchild{%
7676 \forest@edef@strippt\forest@temp{\forestove{l}}%
7677 \pgfmathmultiply@{\forest@ca@ratio}{\forest@temp}%
7678 \forestoeset{l}{\the\dimexpr\pgfmathresult pt}%
7679 %\pgfmathsetlengthmacro\forest@temp{\forest@ca@ratio*\forestove{l}}%
7680 %\forestolet{l}\forest@temp
7681 }%
7682 \forestOget{\forest@ca@first@child}{l}\forest@ca@first@l
7683 \edef\forest@ca@first@l{\expandafter\Pgf@geT\forest@ca@first@l}%
7684 \pgfmathtan@{\forestove{calign primary angle}}%
7685 \pgfmathmultiply@{\pgfmathresult}{\forest@ca@first@l}%
7686 \edef\forest@calign@anchor{\the\dimexpr-\pgfmathresult pt}%
7687 %\pgfmathsetlengthmacro\forest@calign@anchor{%
7688 % -tan(\forestove{calign primary angle})*\forest@ca@first@l}%
7689 \fi
7690 \fi
7691 \forest@calign@s@shift{-\forest@calign@anchor}%
7692 \fi
7693 }
7694 \csdef{forest@calign@fixed edge angles}{%
7695 \ifnum\forestove{n children}>1
7696 \edef\forest@ca@first@child{\forest@node@nornbarthchildid{\forestove{calign primary child}}}%
7697 \edef\forest@ca@second@child{\forest@node@nornbarthchildid{\forestove{calign secondary child}}}%
7698 \ifnum\forestove{reversed}=1
7699 \let\forest@temp\forest@ca@first@child
7700 \let\forest@ca@first@child\forest@ca@second@child
7701 \let\forest@ca@second@child\forest@temp
7702 \fi
7703 \forestOget{\forest@ca@first@child}{l}\forest@ca@first@l
7704 \forestOget{\forest@ca@second@child}{l}\forest@ca@second@l
7705 \forest@pointanchor{parent anchor}%
7706 \edef\forest@ca@parent@anchor@s{\the\pgf@x}%
7707 \edef\forest@ca@parent@anchor@l{\the\pgf@y}%
7708 \forest@Pointanchor{\forest@ca@first@child}{child anchor}%
7709 \edef\forest@ca@first@child@anchor@s{\the\pgf@x}%
7710 \edef\forest@ca@first@child@anchor@l{\the\pgf@y}%
7711 \forest@Pointanchor{\forest@ca@second@child}{child anchor}%
7712 \edef\forest@ca@second@child@anchor@s{\the\pgf@x}%
7713 \edef\forest@ca@second@child@anchor@l{\the\pgf@y}%
7714 \pgfmathtan@{\forestove{calign secondary angle}}%
7715 \edef\forest@temp{\the\dimexpr
7716 \forest@ca@second@l-\forest@ca@second@child@anchor@l+\forest@ca@parent@anchor@l}%
7717 \pgfmathmultiply@{\pgfmathresult}{\expandafter\Pgf@geT\forest@temp}%
7718 \edef\forest@ca@desired@second@edge@s{\the\dimexpr\pgfmathresult pt}%
7719 %\pgfmathsetlengthmacro\forest@ca@desired@second@edge@s{%
7720 % tan(\forestove{calign secondary angle})*%
7721 % (\forest@ca@second@l-\forest@ca@second@child@anchor@l+\forest@ca@parent@anchor@l)}%
7722 \pgfmathtan@{\forestove{calign primary angle}}%
7723 \edef\forest@temp{\the\dimexpr
7724 \forest@ca@first@l-\forest@ca@first@child@anchor@l+\forest@ca@parent@anchor@l}%
7725 \pgfmathmultiply@{\pgfmathresult}{\expandafter\Pgf@geT\forest@temp}%
7726 \edef\forest@ca@desired@first@edge@s{\the\dimexpr\pgfmathresult pt}%
7727 %\pgfmathsetlengthmacro\forest@ca@desired@first@edge@s{%
7728 % tan(\forestove{calign primary angle})*%
7729 % (\forest@ca@first@l-\forest@ca@first@child@anchor@l+\forest@ca@parent@anchor@l)}%
7730 \edef\forest@ca@desired@s@distance{\the\dimexpr
7731 \forest@ca@desired@second@edge@s-\forest@ca@desired@first@edge@s}%
7732 %\pgfmathsetlengthmacro\forest@ca@desired@s@distance{\forest@ca@desired@second@edge@s-\forest@ca@desired@first@edge@s}%
7733 \forestOget{\forest@ca@first@child}{s}\forest@ca@first@s
7734 \forestOget{\forest@ca@second@child}{s}\forest@ca@second@s
7735 \edef\forest@ca@actual@s@distance{\the\dimexpr
7736 \forest@ca@second@s+\forest@ca@second@child@anchor@s
7737 -\forest@ca@first@s-\forest@ca@first@child@anchor@s}%
7738 %\pgfmathsetlengthmacro\forest@ca@actual@s@distance{%
7739 % \forest@ca@second@s+\forest@ca@second@child@anchor@s
7740 % -\forest@ca@first@s-\forest@ca@first@child@anchor@s}%
7741 \ifdim\forest@ca@desired@s@distance>\forest@ca@actual@s@distance\relax
7742 \ifdim\forest@ca@actual@s@distance=0pt
7743 \forestoget{n children}\forest@temp@n@children
7744 \forest@node@foreachchild{%
7745 \forest@pointanchor{child anchor}%
7746 \edef\forest@temp@child@anchor@s{\the\pgf@x}%
7747 \forestoeset{s}{\the\dimexpr
7748 \forest@ca@desired@first@edge@s+\forest@ca@desired@s@distance*(\forestove{n}-1)/(\forest@temp@n@children-1)+\forest@ca@first@child@anchor@s-\forest@temp@child@anchor@s}%
7749 %\pgfmathsetlengthmacro\forest@temp{%
7750 % \forest@ca@desired@first@edge@s+(\forestove{n}-1)*\forest@ca@desired@s@distance/(\forest@temp@n@children-1)+\forest@ca@first@child@anchor@s-\forest@temp@child@anchor@s}%
7751 %\forestolet{s}\forest@temp
7752 }%
7753 \def\forest@calign@anchor{0pt}%
7754 \else
7755 \edef\forest@marshal{\noexpand\pgfmathdivide@
7756 {\expandafter\Pgf@geT\forest@ca@desired@s@distance}%
7757 {\expandafter\Pgf@geT\forest@ca@actual@s@distance}%
7758 }\forest@marshal
7759 \let\forest@ca@ratio\pgfmathresult
7760 %\pgfmathsetmacro\forest@ca@ratio{%
7761 % \forest@ca@desired@s@distance/\forest@ca@actual@s@distance}%
7762 \forest@node@foreachchild{%
7763 \forest@pointanchor{child anchor}%
7764 \edef\forest@temp@child@anchor@s{\the\pgf@x}%
7765 \edef\forest@marshal{\noexpand\pgfmathmultiply@
7766 {\forest@ca@ratio}%
7767 {\expandafter\Pgf@geT\the\dimexpr
7768 \forestove{s}-\forest@ca@first@s+%
7769 \forest@temp@child@anchor@s-\forest@ca@first@child@anchor@s}%
7770 }\forest@marshal
7771 \forestoeset{s}{\the\dimexpr\pgfmathresult pt+\forest@ca@first@s
7772 +\forest@ca@first@child@anchor@s-\forest@temp@child@anchor@s}%
7773 % \pgfmathsetlengthmacro\forest@temp{%
7774 % \forest@ca@ratio*(%
7775 % \forestove{s}-\forest@ca@first@s
7776 % +\forest@temp@child@anchor@s-\forest@ca@first@child@anchor@s)%
7777 % +\forest@ca@first@s
7778 % +\forest@ca@first@child@anchor@s-\forest@temp@child@anchor@s}%
7779 % \forestolet{s}\forest@temp
7780 }%
7781 \pgfmathtan@{\forestove{calign primary angle}}%
7782 \edef\forest@marshal{\noexpand\pgfmathmultiply@
7783 {\pgfmathresult}%
7784 {\expandafter\Pgf@geT\the\dimexpr
7785 \forest@ca@first@l-\forest@ca@first@child@anchor@l+\forest@ca@parent@anchor@l}%
7786 }\forest@marshal
7787 \edef\forest@calign@anchor{\the\dimexpr
7788 -\pgfmathresult pt+\forest@ca@first@child@anchor@s-\forest@ca@parent@anchor@s}%
7789 % \pgfmathsetlengthmacro\forest@calign@anchor{%
7790 % -tan(\forestove{calign primary angle})*(\forest@ca@first@l-\forest@ca@first@child@anchor@l+\forest@ca@parent@anchor@l)%
7791 % +\forest@ca@first@child@anchor@s-\forest@ca@parent@anchor@s
7792 % }%
7793 \fi
7794 \else
7795 \ifdim\forest@ca@desired@s@distance<\forest@ca@actual@s@distance\relax
7796 \edef\forest@marshal{\noexpand\pgfmathdivide@
7797 {\expandafter\Pgf@geT\forest@ca@actual@s@distance}%
7798 {\expandafter\Pgf@geT\forest@ca@desired@s@distance}%
7799 }\forest@marshal
7800 \let\forest@ca@ratio\pgfmathresult
7801 %\pgfmathsetlengthmacro\forest@ca@ratio{%
7802 % \forest@ca@actual@s@distance/\forest@ca@desired@s@distance}%
7803 \forest@node@foreachchild{%
7804 \forest@pointanchor{child anchor}%
7805 \edef\forest@temp@child@anchor@l{\the\pgf@y}%
7806 \edef\forest@marshal{\noexpand\pgfmathmultiply@
7807 {\forest@ca@ratio}%
7808 {\expandafter\Pgf@geT\the\dimexpr\forestove{l}+\forest@ca@parent@anchor@l-\forest@temp@child@anchor@l}%
7809 }\forest@marshal
7810 \forestoeset{l}{\the\dimexpr
7811 \pgfmathresult pt-\forest@ca@parent@anchor@l+\forest@temp@child@anchor@l}%
7812 % \pgfmathsetlengthmacro\forest@temp{%
7813 % \forest@ca@ratio*(%
7814 % \forestove{l}+\forest@ca@parent@anchor@l-\forest@temp@child@anchor@l)
7815 % -\forest@ca@parent@anchor@l+\forest@temp@child@anchor@l}%
7816 % \forestolet{l}\forest@temp
7817 }%
7818 \forestOget{\forest@ca@first@child}{l}\forest@ca@first@l
7819 \pgfmathtan@{\forestove{calign primary angle}}%
7820 \edef\forest@marshal{\noexpand\pgfmathmultiply@
7821 {\pgfmathresult}%
7822 {\expandafter\Pgf@geT\the\dimexpr
7823 \forest@ca@first@l+\forest@ca@parent@anchor@l-\forest@temp@child@anchor@l}%
7824 }\forest@marshal
7825 \edef\forest@calign@anchor{\the\dimexpr
7826 -\pgfmathresult pt+\forest@ca@first@child@anchor@s-\forest@ca@parent@anchor@s}%
7827 % \pgfmathsetlengthmacro\forest@calign@anchor{%
7828 % -tan(\forestove{calign primary angle})*(\forest@ca@first@l+\forest@ca@parent@anchor@l-\forest@temp@child@anchor@l)%
7829 % +\forest@ca@first@child@anchor@s-\forest@ca@parent@anchor@s
7830 % }%
7831 \fi
7832 \fi
7833 \forest@calign@s@shift{-\forest@calign@anchor}%
7834 \fi
7835 }
7836 % \end{macrocode}
7837 %
7838 % Get edge: |#1| = |positive|/|negative|, |#2| = grow (in degrees), |#3| = the control
7839 % sequence receiving the resulting path. The edge is taken from the
7840 % cache (attribute |#1@edge@#2|) if possible; otherwise, both
7841 % positive and negative edge are computed and stored in the cache.
7842 % \begin{macrocode}
7843 \def\forest@node@getedge#1#2#3{%
7844 \forestoget{#1@edge@#2}#3%
7845 \ifx#3\relax
7846 \forest@node@foreachchild{%
7847 \forest@node@getedge{#1}{#2}{\forest@temp@edge}%
7848 }%
7849 \forest@forthis{\forest@node@getedges{#2}}%
7850 \forestoget{#1@edge@#2}#3%
7851 \fi
7852 }
7853 % \end{macrocode}
7854 % Get edges. |#1| = grow (in degrees). The result is stored in
7855 % attributes |negative@edge@#1| and |positive@edge@#1|. This method
7856 % expects that the children's edges are already cached.
7857 % \begin{macrocode}
7858 \def\forest@node@getedges#1{%
7859 % \end{macrocode}
7860 % Run the computation in a \TeX\ group.
7861 % \begin{macrocode}
7862 %{%
7863 % \end{macrocode}
7864 % Setup the grow line.
7865 % \begin{macrocode}
7866 \forest@setupgrowline{#1}%
7867 % \end{macrocode}
7868 % Get the edge of the node itself.
7869 % \begin{macrocode}
7870 \ifnum\forestove{ignore}=0
7871 \forestoget{@boundary}\forest@node@boundary
7872 \else
7873 \def\forest@node@boundary{}%
7874 \fi
7875 \csname forest@getboth\forestove{fit}edgesofpath\endcsname
7876 \forest@node@boundary\forest@negative@node@edge\forest@positive@node@edge
7877 \forestolet{negative@edge@#1}\forest@negative@node@edge
7878 \forestolet{positive@edge@#1}\forest@positive@node@edge
7879 % \end{macrocode}
7880 % Add the edges of the children.
7881 % \begin{macrocode}
7882 \forest@get@edges@merge{negative}{#1}%
7883 \forest@get@edges@merge{positive}{#1}%
7884 %}%
7885 }
7886 % \end{macrocode}
7887 % Merge the |#1| (=|negative| or |positive|) edge of the node with
7888 % |#1| edges of the children. |#2| = grow angle.
7889 % \begin{macrocode}
7890 \def\forest@get@edges@merge#1#2{%
7891 \ifnum\forestove{n children}>0
7892 \forestoget{#1@edge@#2}\forest@node@edge
7893 % \end{macrocode}
7894 % Remember the node's |parent anchor| and add it to the path (for breaking).
7895 % \begin{macrocode}
7896 \forest@pointanchor{parent anchor}%
7897 \edef\forest@getedge@pa@l{\the\pgf@x}%
7898 \edef\forest@getedge@pa@s{\the\pgf@y}%
7899 \eappto\forest@node@edge{\noexpand\pgfsyssoftpath@movetotoken{\forest@getedge@pa@l}{\forest@getedge@pa@s}}%
7900 % \end{macrocode}
7901 % Switch to this node's |(l,s)| coordinate system (origin at the
7902 % node's anchor).
7903 % \begin{macrocode}
7904 \pgfgettransform\forest@temp@transform
7905 \pgftransformreset
7906 \forest@pgfqtransformrotate{\forestove{grow}}%
7907 % \end{macrocode}
7908 % Get the child's (cached) edge, translate it by the child's position,
7909 % and add it to the path holding all edges. Also add the edge from parent to the child to the path.
7910 % This gets complicated when the child and/or parent anchor is empty, i.e.\ automatic border: we can
7911 % get self-intersecting paths. So we store all the parent--child edges to a safe place first,
7912 % compute all the possible breaking points (i.e.\ all the points in node@edge path), and break the
7913 % parent--child edges on these points.
7914 % \begin{macrocode}
7915 \def\forest@all@edges{}%
7916 \forest@node@foreachchild{%
7917 \forestoget{#1@edge@#2}\forest@temp@edge
7918 \pgfpointtransformed{\pgfqpoint{\forestove{l}}{\forestove{s}}}%
7919 \forest@extendpath\forest@node@edge\forest@temp@edge{}%
7920 \ifnum\forestove{ignore edge}=0
7921 \pgfpointadd
7922 {\pgfpointtransformed{\pgfqpoint{\forestove{l}}{\forestove{s}}}}%
7923 {\forest@pointanchor{child anchor}}%
7924 \pgfgetlastxy{\forest@getedge@ca@l}{\forest@getedge@ca@s}%
7925 \eappto\forest@all@edges{%
7926 \noexpand\pgfsyssoftpath@movetotoken{\forest@getedge@pa@l}{\forest@getedge@pa@s}%
7927 \noexpand\pgfsyssoftpath@linetotoken{\forest@getedge@ca@l}{\forest@getedge@ca@s}%
7928 }%
7929 % this deals with potential overlap of the edges:
7930 \eappto\forest@node@edge{\noexpand\pgfsyssoftpath@movetotoken{\forest@getedge@ca@l}{\forest@getedge@ca@s}}%
7931 \fi
7932 }%
7933 \ifdefempty{\forest@all@edges}{}{%
7934 \pgfintersectionofpaths{\pgfsetpath\forest@all@edges}{\pgfsetpath\forest@node@edge}%
7935 \def\forest@edgenode@intersections{}%
7936 \forest@merge@intersectionloop
7937 \eappto\forest@node@edge{\expandonce{\forest@all@edges}\expandonce{\forest@edgenode@intersections}}%
7938 }%
7939 \pgfsettransform\forest@temp@transform
7940 % \end{macrocode}
7941 % Process the path into an edge and store the edge.
7942 % \begin{macrocode}
7943 \csname forest@get#1\forestove{fit}edgeofpath\endcsname\forest@node@edge\forest@node@edge
7944 \forestolet{#1@edge@#2}\forest@node@edge
7945 \fi
7946 }
7947 %\newloop\forest@merge@loop
7948 \def\forest@merge@intersectionloop{%
7949 \c@pgf@counta=0
7950 \forest@loop
7951 \ifnum\c@pgf@counta<\pgfintersectionsolutions\relax
7952 \advance\c@pgf@counta1
7953 \pgfpointintersectionsolution{\the\c@pgf@counta}%
7954 \eappto\forest@edgenode@intersections{\noexpand\pgfsyssoftpath@movetotoken
7955 {\the\pgf@x}{\the\pgf@y}}%
7956 \forest@repeat
7957 }
7958 % \end{macrocode}
7959 %
7960 % Get the bounding rectangle of the node (without descendants). |#1| =
7961 % grow.
7962 % \begin{macrocode}
7963 \def\forest@node@getboundingrectangle@ls#1{%
7964 \forestoget{@boundary}\forest@node@boundary
7965 \forest@path@getboundingrectangle@ls\forest@node@boundary{#1}%
7966 }
7967 % \end{macrocode}
7968 %
7969 % Applies the current coordinate transformation to the points in the
7970 % path |#1|. Returns via the current path (so that the coordinate
7971 % transformation can be set up as local).
7972 % \begin{macrocode}
7973 \def\forest@pgfpathtransformed#1{%
7974 \forest@save@pgfsyssoftpath@tokendefs
7975 \let\pgfsyssoftpath@movetotoken\forest@pgfpathtransformed@moveto
7976 \let\pgfsyssoftpath@linetotoken\forest@pgfpathtransformed@lineto
7977 \pgfsyssoftpath@setcurrentpath\pgfutil@empty
7978 #1%
7979 \forest@restore@pgfsyssoftpath@tokendefs
7980 }
7981 \def\forest@pgfpathtransformed@moveto#1#2{%
7982 \forest@pgfpathtransformed@op\pgfsyssoftpath@moveto{#1}{#2}%
7983 }
7984 \def\forest@pgfpathtransformed@lineto#1#2{%
7985 \forest@pgfpathtransformed@op\pgfsyssoftpath@lineto{#1}{#2}%
7986 }
7987 \def\forest@pgfpathtransformed@op#1#2#3{%
7988 \pgfpointtransformed{\pgfqpoint{#2}{#3}}%
7989 \edef\forest@temp{%
7990 \noexpand#1{\the\pgf@x}{\the\pgf@y}%
7991 }%
7992 \forest@temp
7993 }
7994 % \end{macrocode}
7995 %
7996 % \subsubsection{Tiers}
7997 %
7998 % Compute tiers to be aligned at a node. The result in saved in
7999 % attribute |@tiers|.
8000 % \begin{macrocode}
8001 \def\forest@pack@computetiers{%
8002 {%
8003 \forest@pack@tiers@getalltiersinsubtree
8004 \forest@pack@tiers@computetierhierarchy
8005 \forest@pack@tiers@findcontainers
8006 \forest@pack@tiers@raisecontainers
8007 \forest@pack@tiers@computeprocessingorder
8008 \gdef\forest@smuggle{}%
8009 \forest@pack@tiers@write
8010 }%
8011 \forest@node@foreach{\forestoset{@tiers}{}}%
8012 \forest@smuggle
8013 }
8014 % \end{macrocode}
8015 % Puts all tiers contained in the subtree into attribute
8016 % |tiers|.
8017 % \begin{macrocode}
8018 \def\forest@pack@tiers@getalltiersinsubtree{%
8019 \ifnum\forestove{n children}>0
8020 \forest@node@foreachchild{\forest@pack@tiers@getalltiersinsubtree}%
8021 \fi
8022 \forestoget{tier}\forest@temp@mytier
8023 \def\forest@temp@mytiers{}%
8024 \ifdefempty\forest@temp@mytier{}{%
8025 \listeadd\forest@temp@mytiers\forest@temp@mytier
8026 }%
8027 \ifnum\forestove{n children}>0
8028 \forest@node@foreachchild{%
8029 \forestoget{tiers}\forest@temp@tiers
8030 \forlistloop\forest@pack@tiers@forhandlerA\forest@temp@tiers
8031 }%
8032 \fi
8033 \forestolet{tiers}\forest@temp@mytiers
8034 }
8035 \def\forest@pack@tiers@forhandlerA#1{%
8036 \ifinlist{#1}\forest@temp@mytiers{}{%
8037 \listeadd\forest@temp@mytiers{#1}%
8038 }%
8039 }
8040 % \end{macrocode}
8041 % Compute a set of higher and lower tiers for each tier. Tier A is
8042 % higher than tier B iff a node on tier A is an ancestor of a
8043 % node on tier B.
8044 % \begin{macrocode}
8045 \def\forest@pack@tiers@computetierhierarchy{%
8046 \def\forest@tiers@ancestors{}%
8047 \forestoget{tiers}\forest@temp@mytiers
8048 \forlistloop\forest@pack@tiers@cth@init\forest@temp@mytiers
8049 \forest@pack@tiers@computetierhierarchy@
8050 }
8051 \def\forest@pack@tiers@cth@init#1{%
8052 \csdef{forest@tiers@higher@#1}{}%
8053 \csdef{forest@tiers@lower@#1}{}%
8054 }
8055 \def\forest@pack@tiers@computetierhierarchy@{%
8056 \forestoget{tier}\forest@temp@mytier
8057 \ifdefempty\forest@temp@mytier{}{%
8058 \forlistloop\forest@pack@tiers@forhandlerB\forest@tiers@ancestors
8059 \listeadd\forest@tiers@ancestors\forest@temp@mytier
8060 }%
8061 \forest@node@foreachchild{%
8062 \forest@pack@tiers@computetierhierarchy@
8063 }%
8064 \forestoget{tier}\forest@temp@mytier
8065 \ifdefempty\forest@temp@mytier{}{%
8066 \forest@listedel\forest@tiers@ancestors\forest@temp@mytier
8067 }%
8068 }
8069 \def\forest@pack@tiers@forhandlerB#1{%
8070 \def\forest@temp@tier{#1}%
8071 \ifx\forest@temp@tier\forest@temp@mytier
8072 \PackageError{forest}{Circular tier hierarchy (tier \forest@temp@mytier)}{}%
8073 \fi
8074 \ifinlistcs{#1}{forest@tiers@higher@\forest@temp@mytier}{}{%
8075 \listcsadd{forest@tiers@higher@\forest@temp@mytier}{#1}}%
8076 \xifinlistcs\forest@temp@mytier{forest@tiers@lower@#1}{}{%
8077 \listcseadd{forest@tiers@lower@#1}{\forest@temp@mytier}}%
8078 }
8079 \def\forest@pack@tiers@findcontainers{%
8080 \forestoget{tiers}\forest@temp@tiers
8081 \forlistloop\forest@pack@tiers@findcontainer\forest@temp@tiers
8082 }
8083 \def\forest@pack@tiers@findcontainer#1{%
8084 \def\forest@temp@tier{#1}%
8085 \forestoget{tier}\forest@temp@mytier
8086 \ifx\forest@temp@tier\forest@temp@mytier
8087 \csedef{forest@tiers@container@#1}{\forest@cn}%
8088 \else\@escapeif{%
8089 \forest@pack@tiers@findcontainerA{#1}%
8090 }\fi%
8091 }
8092 \def\forest@pack@tiers@findcontainerA#1{%
8093 \c@pgf@counta=0
8094 \forest@node@foreachchild{%
8095 \forestoget{tiers}\forest@temp@tiers
8096 \ifinlist{#1}\forest@temp@tiers{%
8097 \advance\c@pgf@counta 1
8098 \let\forest@temp@child\forest@cn
8099 }{}%
8100 }%
8101 \ifnum\c@pgf@counta>1
8102 \csedef{forest@tiers@container@#1}{\forest@cn}%
8103 \else\@escapeif{% surely =1
8104 \forest@fornode{\forest@temp@child}{%
8105 \forest@pack@tiers@findcontainer{#1}%
8106 }%
8107 }\fi
8108 }
8109 \def\forest@pack@tiers@raisecontainers{%
8110 \forestoget{tiers}\forest@temp@mytiers
8111 \forlistloop\forest@pack@tiers@rc@forhandlerA\forest@temp@mytiers
8112 }
8113 \def\forest@pack@tiers@rc@forhandlerA#1{%
8114 \edef\forest@tiers@temptier{#1}%
8115 \letcs\forest@tiers@containernodeoftier{forest@tiers@container@#1}%
8116 \letcs\forest@temp@lowertiers{forest@tiers@lower@#1}%
8117 \forlistloop\forest@pack@tiers@rc@forhandlerB\forest@temp@lowertiers
8118 }
8119 \def\forest@pack@tiers@rc@forhandlerB#1{%
8120 \letcs\forest@tiers@containernodeoflowertier{forest@tiers@container@#1}%
8121 \forestOget{\forest@tiers@containernodeoflowertier}{content}\lowercontent
8122 \forestOget{\forest@tiers@containernodeoftier}{content}\uppercontent
8123 \forest@fornode{\forest@tiers@containernodeoflowertier}{%
8124 \forest@ifancestorof
8125 {\forest@tiers@containernodeoftier}
8126 {\csletcs{forest@tiers@container@\forest@tiers@temptier}{forest@tiers@container@#1}}%
8127 {}%
8128 }%
8129 }
8130 \def\forest@pack@tiers@computeprocessingorder{%
8131 \def\forest@tiers@processingorder{}%
8132 \forestoget{tiers}\forest@tiers@cpo@tierstodo
8133 \safeloop
8134 \ifdefempty\forest@tiers@cpo@tierstodo{\forest@tempfalse}{\forest@temptrue}%
8135 \ifforest@temp
8136 \def\forest@tiers@cpo@tiersremaining{}%
8137 \def\forest@tiers@cpo@tiersindependent{}%
8138 \forlistloop\forest@pack@tiers@cpo@forhandlerA\forest@tiers@cpo@tierstodo
8139 \ifdefempty\forest@tiers@cpo@tiersindependent{%
8140 \PackageError{forest}{Circular tiers!}{}}{}%
8141 \forlistloop\forest@pack@tiers@cpo@forhandlerB\forest@tiers@cpo@tiersremaining
8142 \let\forest@tiers@cpo@tierstodo\forest@tiers@cpo@tiersremaining
8143 \saferepeat
8144 }
8145 \def\forest@pack@tiers@cpo@forhandlerA#1{%
8146 \ifcsempty{forest@tiers@higher@#1}{%
8147 \listadd\forest@tiers@cpo@tiersindependent{#1}%
8148 \listadd\forest@tiers@processingorder{#1}%
8149 }{%
8150 \listadd\forest@tiers@cpo@tiersremaining{#1}%
8151 }%
8152 }
8153 \def\forest@pack@tiers@cpo@forhandlerB#1{%
8154 \def\forest@pack@tiers@cpo@aremainingtier{#1}%
8155 \forlistloop\forest@pack@tiers@cpo@forhandlerC\forest@tiers@cpo@tiersindependent
8156 }
8157 \def\forest@pack@tiers@cpo@forhandlerC#1{%
8158 \ifinlistcs{#1}{forest@tiers@higher@\forest@pack@tiers@cpo@aremainingtier}{%
8159 \forest@listcsdel{forest@tiers@higher@\forest@pack@tiers@cpo@aremainingtier}{#1}%
8160 }{}%
8161 }
8162 \def\forest@pack@tiers@write{%
8163 \forlistloop\forest@pack@tiers@write@forhandler\forest@tiers@processingorder
8164 }
8165 \def\forest@pack@tiers@write@forhandler#1{%
8166 \forest@fornode{\csname forest@tiers@container@#1\endcsname}{%
8167 \forest@pack@tiers@check{#1}%
8168 }%
8169 \xappto\forest@smuggle{%
8170 \noexpand\listadd
8171 \forestOm{\csname forest@tiers@container@#1\endcsname}{@tiers}%
8172 {#1}%
8173 }%
8174 }
8175 % checks if the tier is compatible with growth changes and calign=node/edge angle
8176 \def\forest@pack@tiers@check#1{%
8177 \def\forest@temp@currenttier{#1}%
8178 \forest@node@foreachdescendant{%
8179 \ifnum\forestove{grow}=\forestOve{\forestove{@parent}}{grow}
8180 \else
8181 \forest@pack@tiers@check@grow
8182 \fi
8183 \ifnum\forestove{n children}>1
8184 \forestoget{calign}\forest@temp
8185 \ifx\forest@temp\forest@pack@tiers@check@nodeangle
8186 \forest@pack@tiers@check@calign
8187 \fi
8188 \ifx\forest@temp\forest@pack@tiers@check@edgeangle
8189 \forest@pack@tiers@check@calign
8190 \fi
8191 \fi
8192 }%
8193 }
8194 \def\forest@pack@tiers@check@nodeangle{node angle}%
8195 \def\forest@pack@tiers@check@edgeangle{edge angle}%
8196 \def\forest@pack@tiers@check@grow{%
8197 \forestoget{content}\forest@temp@content
8198 \let\forest@temp@currentnode\forest@cn
8199 \forest@node@foreachdescendant{%
8200 \forestoget{tier}\forest@temp
8201 \ifx\forest@temp@currenttier\forest@temp
8202 \forest@pack@tiers@check@grow@error
8203 \fi
8204 }%
8205 }
8206 \def\forest@pack@tiers@check@grow@error{%
8207 \PackageError{forest}{Tree growth direction changes in node \forest@temp@currentnode\space
8208 (content: \forest@temp@content), while tier '\forest@temp' is specified for nodes both
8209 out- and inside the subtree rooted in node \forest@temp@currentnode. This will not work.}{}%
8210 }
8211 \def\forest@pack@tiers@check@calign{%
8212 \forest@node@foreachchild{%
8213 \forestoget{tier}\forest@temp
8214 \ifx\forest@temp@currenttier\forest@temp
8215 \forest@pack@tiers@check@calign@warning
8216 \fi
8217 }%
8218 }
8219 \def\forest@pack@tiers@check@calign@warning{%
8220 \PackageWarning{forest}{Potential option conflict: node \forestove{@parent} (content:
8221 '\forestOve{\forestove{@parent}}{content}') was given 'calign=\forestove{calign}', while its
8222 child \forest@cn\space (content: '\forestove{content}') was given 'tier=\forestove{tier}'.
8223 The parent's 'calign' will only work if the child was the lowest node on its tier before the
8224 alignment.}%
8225 }
8226 % \end{macrocode}
8227 %
8228 %
8229 % \subsubsection{Node boundary}
8230 %
8231 % Compute the node boundary: it will be put in the pgf's current path. The computation is done
8232 % within a generic anchor so that the shape's saved anchors and macros are available.
8233 % \begin{macrocode}
8234 \pgfdeclaregenericanchor{forestcomputenodeboundary}{%
8235 \letcs\forest@temp@boundary@macro{forest@compute@node@boundary@#1}%
8236 \ifcsname forest@compute@node@boundary@#1\endcsname
8237 \csname forest@compute@node@boundary@#1\endcsname
8238 \else
8239 \forest@compute@node@boundary@rectangle
8240 \fi
8241 \pgfsyssoftpath@getcurrentpath\forest@temp
8242 \global\let\forest@global@boundary\forest@temp
8243 }
8244 \def\forest@mt#1{%
8245 \expandafter\pgfpointanchor\expandafter{\pgfreferencednodename}{#1}%
8246 \pgfsyssoftpath@moveto{\the\pgf@x}{\the\pgf@y}%
8247 }%
8248 \def\forest@lt#1{%
8249 \expandafter\pgfpointanchor\expandafter{\pgfreferencednodename}{#1}%
8250 \pgfsyssoftpath@lineto{\the\pgf@x}{\the\pgf@y}%
8251 }%
8252 \def\forest@compute@node@boundary@coordinate{%
8253 \forest@mt{center}%
8254 }
8255 \def\forest@compute@node@boundary@circle{%
8256 \forest@mt{east}%
8257 \forest@lt{north east}%
8258 \forest@lt{north}%
8259 \forest@lt{north west}%
8260 \forest@lt{west}%
8261 \forest@lt{south west}%
8262 \forest@lt{south}%
8263 \forest@lt{south east}%
8264 \forest@lt{east}%
8265 }
8266 \def\forest@compute@node@boundary@rectangle{%
8267 \forest@mt{south west}%
8268 \forest@lt{south east}%
8269 \forest@lt{north east}%
8270 \forest@lt{north west}%
8271 \forest@lt{south west}%
8272 }
8273 \def\forest@compute@node@boundary@diamond{%
8274 \forest@mt{east}%
8275 \forest@lt{north}%
8276 \forest@lt{west}%
8277 \forest@lt{south}%
8278 \forest@lt{east}%
8279 }
8280 \let\forest@compute@node@boundary@ellipse\forest@compute@node@boundary@circle
8281 \def\forest@compute@node@boundary@trapezium{%
8282 \forest@mt{top right corner}%
8283 \forest@lt{top left corner}%
8284 \forest@lt{bottom left corner}%
8285 \forest@lt{bottom right corner}%
8286 \forest@lt{top right corner}%
8287 }
8288 \def\forest@compute@node@boundary@semicircle{%
8289 \forest@mt{arc start}%
8290 \forest@lt{north}%
8291 \forest@lt{east}%
8292 \forest@lt{north east}%
8293 \forest@lt{apex}%
8294 \forest@lt{north west}%
8295 \forest@lt{west}%
8296 \forest@lt{arc end}%
8297 \forest@lt{arc start}%
8298 }
8299 %\newloop\forest@computenodeboundary@loop
8300 \csdef{forest@compute@node@boundary@regular polygon}{%
8301 \forest@mt{corner 1}%
8302 \c@pgf@counta=\sides\relax
8303 \forest@loop
8304 \ifnum\c@pgf@counta>0
8305 \forest@lt{corner \the\c@pgf@counta}%
8306 \advance\c@pgf@counta-1
8307 \forest@repeat
8308 }%
8309 \def\forest@compute@node@boundary@star{%
8310 \forest@mt{outer point 1}%
8311 \c@pgf@counta=\totalstarpoints\relax
8312 \divide\c@pgf@counta2
8313 \forest@loop
8314 \ifnum\c@pgf@counta>0
8315 \forest@lt{inner point \the\c@pgf@counta}%
8316 \forest@lt{outer point \the\c@pgf@counta}%
8317 \advance\c@pgf@counta-1
8318 \forest@repeat
8319 }%
8320 \csdef{forest@compute@node@boundary@isosceles triangle}{%
8321 \forest@mt{apex}%
8322 \forest@lt{left corner}%
8323 \forest@lt{right corner}%
8324 \forest@lt{apex}%
8325 }
8326 \def\forest@compute@node@boundary@kite{%
8327 \forest@mt{upper vertex}%
8328 \forest@lt{left vertex}%
8329 \forest@lt{lower vertex}%
8330 \forest@lt{right vertex}%
8331 \forest@lt{upper vertex}%
8332 }
8333 \def\forest@compute@node@boundary@dart{%
8334 \forest@mt{tip}%
8335 \forest@lt{left tail}%
8336 \forest@lt{tail center}%
8337 \forest@lt{right tail}%
8338 \forest@lt{tip}%
8339 }
8340 \csdef{forest@compute@node@boundary@circular sector}{%
8341 \forest@mt{sector center}%
8342 \forest@lt{arc start}%
8343 \forest@lt{arc center}%
8344 \forest@lt{arc end}%
8345 \forest@lt{sector center}%
8346 }
8347 \def\forest@compute@node@boundary@cylinder{%
8348 \forest@mt{top}%
8349 \forest@lt{after top}%
8350 \forest@lt{before bottom}%
8351 \forest@lt{bottom}%
8352 \forest@lt{after bottom}%
8353 \forest@lt{before top}%
8354 \forest@lt{top}%
8355 }
8356 \cslet{forest@compute@node@boundary@forbidden sign}\forest@compute@node@boundary@circle
8357 \cslet{forest@compute@node@boundary@magnifying glass}\forest@compute@node@boundary@circle
8358 \def\forest@compute@node@boundary@cloud{%
8359 \getradii
8360 \forest@mt{puff 1}%
8361 \c@pgf@counta=\puffs\relax
8362 \forest@loop
8363 \ifnum\c@pgf@counta>0
8364 \forest@lt{puff \the\c@pgf@counta}%
8365 \advance\c@pgf@counta-1
8366 \forest@repeat
8367 }
8368 \def\forest@compute@node@boundary@starburst{
8369 \calculatestarburstpoints
8370 \forest@mt{outer point 1}%
8371 \c@pgf@counta=\totalpoints\relax
8372 \divide\c@pgf@counta2
8373 \forest@loop
8374 \ifnum\c@pgf@counta>0
8375 \forest@lt{inner point \the\c@pgf@counta}%
8376 \forest@lt{outer point \the\c@pgf@counta}%
8377 \advance\c@pgf@counta-1
8378 \forest@repeat
8379 }%
8380 \def\forest@compute@node@boundary@signal{%
8381 \forest@mt{east}%
8382 \forest@lt{south east}%
8383 \forest@lt{south west}%
8384 \forest@lt{west}%
8385 \forest@lt{north west}%
8386 \forest@lt{north east}%
8387 \forest@lt{east}%
8388 }
8389 \def\forest@compute@node@boundary@tape{%
8390 \forest@mt{north east}%
8391 \forest@lt{60}%
8392 \forest@lt{north}%
8393 \forest@lt{120}%
8394 \forest@lt{north west}%
8395 \forest@lt{south west}%
8396 \forest@lt{240}%
8397 \forest@lt{south}%
8398 \forest@lt{310}%
8399 \forest@lt{south east}%
8400 \forest@lt{north east}%
8401 }
8402 \csdef{forest@compute@node@boundary@single arrow}{%
8403 \forest@mt{tip}%
8404 \forest@lt{after tip}%
8405 \forest@lt{after head}%
8406 \forest@lt{before tail}%
8407 \forest@lt{after tail}%
8408 \forest@lt{before head}%
8409 \forest@lt{before tip}%
8410 \forest@lt{tip}%
8411 }
8412 \csdef{forest@compute@node@boundary@double arrow}{%
8413 \forest@mt{tip 1}%
8414 \forest@lt{after tip 1}%
8415 \forest@lt{after head 1}%
8416 \forest@lt{before head 2}%
8417 \forest@lt{before tip 2}%
8418 \forest@mt{tip 2}%
8419 \forest@lt{after tip 2}%
8420 \forest@lt{after head 2}%
8421 \forest@lt{before head 1}%
8422 \forest@lt{before tip 1}%
8423 \forest@lt{tip 1}%
8424 }
8425 \csdef{forest@compute@node@boundary@arrow box}{%
8426 \forest@mt{before north arrow}%
8427 \forest@lt{before north arrow head}%
8428 \forest@lt{before north arrow tip}%
8429 \forest@lt{north arrow tip}%
8430 \forest@lt{after north arrow tip}%
8431 \forest@lt{after north arrow head}%
8432 \forest@lt{after north arrow}%
8433 \forest@lt{north east}%
8434 \forest@lt{before east arrow}%
8435 \forest@lt{before east arrow head}%
8436 \forest@lt{before east arrow tip}%
8437 \forest@lt{east arrow tip}%
8438 \forest@lt{after east arrow tip}%
8439 \forest@lt{after east arrow head}%
8440 \forest@lt{after east arrow}%
8441 \forest@lt{south east}%
8442 \forest@lt{before south arrow}%
8443 \forest@lt{before south arrow head}%
8444 \forest@lt{before south arrow tip}%
8445 \forest@lt{south arrow tip}%
8446 \forest@lt{after south arrow tip}%
8447 \forest@lt{after south arrow head}%
8448 \forest@lt{after south arrow}%
8449 \forest@lt{south west}%
8450 \forest@lt{before west arrow}%
8451 \forest@lt{before west arrow head}%
8452 \forest@lt{before west arrow tip}%
8453 \forest@lt{west arrow tip}%
8454 \forest@lt{after west arrow tip}%
8455 \forest@lt{after west arrow head}%
8456 \forest@lt{after west arrow}%
8457 \forest@lt{north west}%
8458 \forest@lt{before north arrow}%
8459 }
8460 \cslet{forest@compute@node@boundary@circle split}\forest@compute@node@boundary@circle
8461 \cslet{forest@compute@node@boundary@circle solidus}\forest@compute@node@boundary@circle
8462 \cslet{forest@compute@node@boundary@ellipse split}\forest@compute@node@boundary@ellipse
8463 \cslet{forest@compute@node@boundary@rectangle split}\forest@compute@node@boundary@rectangle
8464 \def\forest@compute@node@boundary@@callout{%
8465 \beforecalloutpointer
8466 \pgfsyssoftpath@moveto{\the\pgf@x}{\the\pgf@y}%
8467 \calloutpointeranchor
8468 \pgfsyssoftpath@lineto{\the\pgf@x}{\the\pgf@y}%
8469 \aftercalloutpointer
8470 \pgfsyssoftpath@lineto{\the\pgf@x}{\the\pgf@y}%
8471 }
8472 \csdef{forest@compute@node@boundary@rectangle callout}{%
8473 \forest@compute@node@boundary@rectangle
8474 \rectanglecalloutpoints
8475 \forest@compute@node@boundary@@callout
8476 }
8477 \csdef{forest@compute@node@boundary@ellipse callout}{%
8478 \forest@compute@node@boundary@ellipse
8479 \ellipsecalloutpoints
8480 \forest@compute@node@boundary@@callout
8481 }
8482 \csdef{forest@compute@node@boundary@cloud callout}{%
8483 \forest@compute@node@boundary@cloud
8484 % at least a first approx...
8485 \forest@mt{center}%
8486 \forest@lt{pointer}%
8487 }%
8488 \csdef{forest@compute@node@boundary@cross out}{%
8489 \forest@mt{south east}%
8490 \forest@lt{north west}%
8491 \forest@mt{south west}%
8492 \forest@lt{north east}%
8493 }%
8494 \csdef{forest@compute@node@boundary@strike out}{%
8495 \forest@mt{north east}%
8496 \forest@lt{south west}%
8497 }%
8498 \csdef{forest@compute@node@boundary@rounded rectangle}{%
8499 \forest@mt{east}%
8500 \forest@lt{north east}%
8501 \forest@lt{north}%
8502 \forest@lt{north west}%
8503 \forest@lt{west}%
8504 \forest@lt{south west}%
8505 \forest@lt{south}%
8506 \forest@lt{south east}%
8507 \forest@lt{east}%
8508 }%
8509 \csdef{forest@compute@node@boundary@chamfered rectangle}{%
8510 \forest@mt{before south west}%
8511 \forest@mt{after south west}%
8512 \forest@lt{before south east}%
8513 \forest@lt{after south east}%
8514 \forest@lt{before north east}%
8515 \forest@lt{after north east}%
8516 \forest@lt{before north west}%
8517 \forest@lt{after north west}%
8518 \forest@lt{before south west}%
8519 }%
8520 % \end{macrocode}
8521 %
8522 %
8523 %
8524 %
8525 % \subsection{Compute absolute positions}
8526 %
8527 % Computes absolute positions of descendants relative to this node.
8528 % Stores the results in attributes |x| and |y|.
8529 % \begin{macrocode}
8530 \def\forest@node@computeabsolutepositions{%
8531 \edef\forest@marshal{%
8532 \noexpand\forest@node@foreachchild{%
8533 \noexpand\forest@node@computeabsolutepositions@{\forestove{x}}{\forestove{y}}{\forestove{grow}}%
8534 }%
8535 }\forest@marshal
8536 }
8537 \def\forest@node@computeabsolutepositions@#1#2#3{%
8538 \pgfpointadd
8539 {\pgfqpoint{#1}{#2}}%
8540 {\pgfpointadd
8541 {\pgfqpointpolar{#3}{\forestove{l}}}%
8542 {\pgfqpointpolar{\numexpr 90+#3\relax}{\forestove{s}}}%
8543 }%
8544 \pgfgetlastxy\forest@temp@x\forest@temp@y
8545 \forestolet{x}\forest@temp@x
8546 \forestolet{y}\forest@temp@y
8547 \edef\forest@marshal{%
8548 \noexpand\forest@node@foreachchild{%
8549 \noexpand\forest@node@computeabsolutepositions@{\forest@temp@x}{\forest@temp@y}{\forestove{grow}}%
8550 }%
8551 }\forest@marshal
8552 }
8553 % \end{macrocode}
8554 %
8555 %
8556 % \subsection{Drawing the tree}
8557 % \label{imp:drawing-the-tree}
8558 % \begin{macrocode}
8559 \newif\ifforest@drawtree@preservenodeboxes@
8560 \def\forest@node@drawtree{%
8561 \expandafter\ifstrequal\expandafter{\forest@drawtreebox}{\pgfkeysnovalue}{%
8562 \let\forest@drawtree@beginbox\relax
8563 \let\forest@drawtree@endbox\relax
8564 }{%
8565 \edef\forest@drawtree@beginbox{\global\setbox\forest@drawtreebox=\hbox\bgroup}%
8566 \let\forest@drawtree@endbox\egroup
8567 }%
8568 \ifforest@external@
8569 \ifforest@externalize@tree@
8570 \forest@temptrue
8571 \else
8572 \tikzifexternalizing{%
8573 \ifforest@was@tikzexternalwasenable
8574 \forest@temptrue
8575 \pgfkeys{/tikz/external/optimize=false}%
8576 \let\forest@drawtree@beginbox\relax
8577 \let\forest@drawtree@endbox\relax
8578 \else
8579 \forest@tempfalse
8580 \fi
8581 }{%
8582 \forest@tempfalse
8583 }%
8584 \fi
8585 \ifforest@temp
8586 \advance\forest@externalize@inner@n 1
8587 \edef\forest@externalize@filename{%
8588 \tikzexternalrealjob-forest-\forest@externalize@outer@n
8589 \ifnum\forest@externalize@inner@n=0 \else.\the\forest@externalize@inner@n\fi}%
8590 \expandafter\tikzsetnextfilename\expandafter{\forest@externalize@filename}%
8591 \tikzexternalenable
8592 \pgfkeysalso{/tikz/external/remake next,/tikz/external/export next}%
8593 \fi
8594 \ifforest@externalize@tree@
8595 \typeout{forest: Invoking a recursive call to generate the external picture
8596 '\forest@externalize@filename' for the following context+code:
8597 '\expandafter\detokenize\expandafter{\forest@externalize@id}'}%
8598 \fi
8599 \fi
8600 %
8601 \ifforesttikzcshack
8602 \let\forest@original@tikz@parse@node\tikz@parse@node
8603 \let\tikz@parse@node\forest@tikz@parse@node
8604 \fi
8605 \pgfkeysgetvalue{/forest/begin draw/.@cmd}\forest@temp@begindraw
8606 \pgfkeysgetvalue{/forest/end draw/.@cmd}\forest@temp@enddraw
8607 \edef\forest@marshal{%
8608 \noexpand\forest@drawtree@beginbox
8609 \expandonce{\forest@temp@begindraw\pgfkeysnovalue\pgfeov}%
8610 \noexpand\forest@node@drawtree@
8611 \expandonce{\forest@temp@enddraw\pgfkeysnovalue\pgfeov}%
8612 \noexpand\forest@drawtree@endbox
8613 }\forest@marshal
8614 \ifforesttikzcshack
8615 \let\tikz@parse@node\forest@original@tikz@parse@node
8616 \fi
8617 %
8618 \ifforest@external@
8619 \ifforest@externalize@tree@
8620 \tikzexternaldisable
8621 \eappto\forest@externalize@checkimages{%
8622 \noexpand\forest@includeexternal@check{\forest@externalize@filename}%
8623 }%
8624 \expandafter\ifstrequal\expandafter{\forest@drawtreebox}{\pgfkeysnovalue}{%
8625 \eappto\forest@externalize@loadimages{%
8626 \noexpand\forest@includeexternal{\forest@externalize@filename}%
8627 }%
8628 }{%
8629 \eappto\forest@externalize@loadimages{%
8630 \noexpand\forest@includeexternal@box\forest@drawtreebox{\forest@externalize@filename}%
8631 }%
8632 }%
8633 \fi
8634 \fi
8635 }
8636 \def\forest@drawtree@root{0}
8637 \def\forest@node@drawtree@{%
8638 \def\forest@clear@drawn{}%
8639 \forest@forthis{%
8640 \forest@saveandrestoremacro\forest@drawtree@root{%
8641 \edef\forest@drawtree@root{\forest@cn}%
8642 \forestset{draw tree method}%
8643 }%
8644 }%
8645 \forest@node@Ifnamedefined{forest@baseline@node}{%
8646 \edef\forest@baseline@id{\forest@node@Nametoid{forest@baseline@node}}%
8647 \ifnum\forest@baseline@id=0
8648 \else
8649 \ifcsdef{forest@drawn@\forest@baseline@id}{%
8650 \edef\forest@marshal{%
8651 \noexpand\pgfsetbaselinepointlater{%
8652 \noexpand\pgfpointanchor
8653 {\forestOve{\forest@baseline@id}{name}}%
8654 {\forestOve{\forest@baseline@id}{anchor}}%
8655 }%
8656 }\forest@marshal
8657 }{%
8658 \PackageWarning{forest}{Baseline node (id=\forest@cn) was not drawn (most likely it's a phantom node)}%
8659 }%
8660 \fi
8661 }%
8662 \forest@clear@drawn
8663 }
8664 \def\forest@draw@node{%
8665 \ifnum\forestove{phantom}=0
8666 \forest@draw@node@
8667 \fi
8668 }
8669 \def\forest@draw@node@{%
8670 \forest@node@forest@positionnodelater@restore
8671 \ifforest@drawtree@preservenodeboxes@
8672 \pgfnodealias{forest@temp}{\forestove{later@name}}%
8673 \fi
8674 \pgfpositionnodenow{\pgfqpoint{\forestove{x}}{\forestove{y}}}%
8675 \ifforest@drawtree@preservenodeboxes@
8676 \pgfnodealias{\forestove{later@name}}{forest@temp}%
8677 \fi
8678 \csdef{forest@drawn@\forest@cn}{}%
8679 \eappto\forest@clear@drawn{\noexpand\csundef{forest@drawn@\forest@cn}}%
8680 }
8681 \def\forest@draw@edge{%
8682 \ifcsdef{forest@drawn@\forest@cn}{% was the current node drawn?
8683 \ifnum\forestove{@parent}=0 % do we have a parent?
8684 \else
8685 \ifcsdef{forest@drawn@\forestove{@parent}}{% was the parent drawn?
8686 \forest@draw@edge@
8687 }{}%
8688 \fi
8689 }{}%
8690 }
8691 \def\forest@draw@edge@{%
8692 \edef\forest@temp{\forestove{edge path}}\forest@temp
8693 }
8694 \def\forest@draw@tikz{%
8695 \ifnum\forestove{phantom}=0
8696 \forest@draw@tikz@
8697 \fi
8698 }
8699 \def\forest@draw@tikz@{%
8700 \forestove{tikz}%
8701 }
8702 % \end{macrocode}
8703 %
8704 % \section{Geometry}
8705 % \label{imp:geometry}
8706 %
8707 % A \emph{$\alpha$ grow line} is a line through the origin at angle
8708 % $\alpha$. The following macro sets up the grow line, which can then
8709 % be used by other code (the change is local to the \TeX\ group). More
8710 % precisely, two normalized vectors are set up: one $(x_g,y_g)$ on the
8711 % grow line, and one $(x_s,y_s)$ orthogonal to it---to get
8712 % $(x_s,y_s$), rotate $(x_g,y_g)$ 90$^\circ$ counter-clockwise.
8713 % \begin{macrocode}
8714 \newdimen\forest@xg
8715 \newdimen\forest@yg
8716 \newdimen\forest@xs
8717 \newdimen\forest@ys
8718 \def\forest@setupgrowline#1{%
8719 \edef\forest@grow{#1}%
8720 \pgfqpointpolar{\forest@grow}{1pt}%
8721 \forest@xg=\pgf@x
8722 \forest@yg=\pgf@y
8723 \forest@xs=-\pgf@y
8724 \forest@ys=\pgf@x
8725 }
8726 % \end{macrocode}
8727 %
8728 % \subsection{Projections}
8729 % \label{imp:projections}
8730 %
8731 % The following macro belongs to the |\pgfpoint...| family: it
8732 % projects point |#1| on the grow line. (The result is returned via
8733 % |\pgf@x| and |\pgf@y|.) The implementation is based on code from
8734 % |tikzlibrarycalc|, but optimized for projecting on grow lines, and
8735 % split to optimize serial usage in |\forest@projectpath|.
8736 % \begin{macrocode}
8737 \def\forest@pgfpointprojectiontogrowline#1{{%
8738 \pgf@process{#1}%
8739 % \end{macrocode}
8740 % Calculate the scalar product of $(x,y)$ and $(x_g,y_g)$: that's the
8741 % distance of $(x,y)$ to the grow line.
8742 % \begin{macrocode}
8743 \pgfutil@tempdima=\pgf@sys@tonumber{\pgf@x}\forest@xg%
8744 \advance\pgfutil@tempdima by\pgf@sys@tonumber{\pgf@y}\forest@yg%
8745 % \end{macrocode}
8746 % The projection is $(x_g,y_g)$ scaled by the distance.
8747 % \begin{macrocode}
8748 \global\pgf@x=\pgf@sys@tonumber{\pgfutil@tempdima}\forest@xg%
8749 \global\pgf@y=\pgf@sys@tonumber{\pgfutil@tempdima}\forest@yg%
8750 }}
8751 % \end{macrocode}
8752 %
8753 % The following macro calculates the distance of point |#2| to the
8754 % grow line and stores the result in \TeX-dimension |#1|. The distance
8755 % is the scalar product of the point vector and the normalized vector
8756 % orthogonal to the grow line.
8757 % \begin{macrocode}
8758 \def\forest@distancetogrowline#1#2{%
8759 \pgf@process{#2}%
8760 #1=\pgf@sys@tonumber{\pgf@x}\forest@xs\relax
8761 \advance#1 by\pgf@sys@tonumber{\pgf@y}\forest@ys\relax
8762 }
8763 % \end{macrocode}
8764 % Note that the distance to the grow line is positive for points on
8765 % one of its sides and negative for points on the other side. (It is
8766 % positive on the side which $(x_s,y_s)$ points to.) We thus say that
8767 % the grow line partitions the plane into a \emph{positive} and a
8768 % \emph{negative} side.
8769 %
8770 % The following macro projects all segment edges (``points'') of a
8771 % simple\footnote{A path is \emph{simple} if it consists of only
8772 % move-to and line-to operations.} path |#1| onto the grow line.
8773 % The result is an array of tuples (|xo|, |yo|, |xp|, |yp|), where
8774 % |xo| and |yo| stand for the \emph{o}riginal point, and |xp| and |yp|
8775 % stand for its \emph{p}rojection. The prefix of the array is given by
8776 % |#2|. If the array already exists, the new items are appended to
8777 % it. The array is not sorted: the order of original points in the
8778 % array is their order in the path. The computation does not destroy
8779 % the current path. All result-macros have local scope.
8780 %
8781 % The macro is just a wrapper for |\forest@projectpath@process|.
8782 % \begin{macrocode}
8783 \let\forest@pp@n\relax
8784 \def\forest@projectpathtogrowline#1#2{%
8785 \edef\forest@pp@prefix{#2}%
8786 \forest@save@pgfsyssoftpath@tokendefs
8787 \let\pgfsyssoftpath@movetotoken\forest@projectpath@processpoint
8788 \let\pgfsyssoftpath@linetotoken\forest@projectpath@processpoint
8789 \c@pgf@counta=0
8790 #1%
8791 \csedef{#2n}{\the\c@pgf@counta}%
8792 \forest@restore@pgfsyssoftpath@tokendefs
8793 }
8794 % \end{macrocode}
8795 % For each point, remember the point and its projection to grow line.
8796 % \begin{macrocode}
8797 \def\forest@projectpath@processpoint#1#2{%
8798 \pgfqpoint{#1}{#2}%
8799 \expandafter\edef\csname\forest@pp@prefix\the\c@pgf@counta xo\endcsname{\the\pgf@x}%
8800 \expandafter\edef\csname\forest@pp@prefix\the\c@pgf@counta yo\endcsname{\the\pgf@y}%
8801 \forest@pgfpointprojectiontogrowline{}%
8802 \expandafter\edef\csname\forest@pp@prefix\the\c@pgf@counta xp\endcsname{\the\pgf@x}%
8803 \expandafter\edef\csname\forest@pp@prefix\the\c@pgf@counta yp\endcsname{\the\pgf@y}%
8804 \advance\c@pgf@counta 1\relax
8805 }
8806 % \end{macrocode}
8807 % Sort the array (prefix |#1|) produced by
8808 % |\forest@projectpathtogrowline| by |(xp,yp)|, in the ascending order.
8809 % \begin{macrocode}
8810 \def\forest@sortprojections#1{%
8811 % todo: optimize in cases when we know that the array is actually a
8812 % merger of sorted arrays; when does this happen? in
8813 % distance_between_paths, and when merging the edges of the parent
8814 % and its children in a uniform growth tree
8815 \edef\forest@ppi@inputprefix{#1}%
8816 \c@pgf@counta=\csname#1n\endcsname\relax
8817 \advance\c@pgf@counta -1
8818 \forest@sort\forest@ppiraw@cmp\forest@ppiraw@let\forest@sort@ascending{0}{\the\c@pgf@counta}%
8819 }
8820 % \end{macrocode}
8821 %
8822 % The following macro processes the data gathered by (possibly more
8823 % than one invocation of) |\forest@projectpathtogrowline| into array
8824 % with prefix |#1|. The resulting data is the following.
8825 % \begin{itemize}
8826 % \item Array of projections (prefix |#2|)
8827 % \begin{itemize}
8828 % \item its items are tuples |(x,y)| (the array is sorted by |x|
8829 % and |y|), and
8830 % \item an inner array of original points (prefix |#2N@|, where $N$
8831 % is the index of the item in array |#2|. The items of |#2N@|
8832 % are |x|, |y| and |d|: |x| and |y| are the coordinates of the
8833 % original point; |d| is its distance to the grow line. The inner
8834 % array is not sorted.
8835 % \end{itemize}
8836 % \item A ``dictionary'' |#3|: keys are the coordinates |(x,y)| of
8837 % the original points; a value is the index of the original point's
8838 % projection in array |#2|.\footnote{At first sight, this
8839 % information could be cached ``at the source'': by
8840 % forest@pgfpointprojectiontogrowline. However, due to imprecise
8841 % intersecting (in breakpath), we cheat and merge very adjacent
8842 % projection points, expecting that the points to project to the
8843 % merged projection point. All this depends on the given path, so a
8844 % generic cache is not feasible.} In v2.1.4, the ``dictionary'' was
8845 % reimplemented using a toks register, to prevent using up the string
8846 % pool; that's when |#3| was introduced.
8847 % \end{itemize}
8848 % \begin{macrocode}
8849 \def\forest@processprojectioninfo#1#2#3{%
8850 \edef\forest@ppi@inputprefix{#1}%
8851 % \end{macrocode}
8852 % Loop (counter |\c@pgf@counta|) through the sorted array of raw data.
8853 % \begin{macrocode}
8854 \c@pgf@counta=0
8855 \c@pgf@countb=-1
8856 \safeloop
8857 \ifnum\c@pgf@counta<\csname#1n\endcsname\relax
8858 % \end{macrocode}
8859 % Check if the projection tuple in the current raw item equals the
8860 % current projection.
8861 % \begin{macrocode}
8862 \letcs\forest@xo{#1\the\c@pgf@counta xo}%
8863 \letcs\forest@yo{#1\the\c@pgf@counta yo}%
8864 \letcs\forest@xp{#1\the\c@pgf@counta xp}%
8865 \letcs\forest@yp{#1\the\c@pgf@counta yp}%
8866 \ifnum\c@pgf@countb<0
8867 \forest@equaltotolerancefalse
8868 \else
8869 \forest@equaltotolerance
8870 {\pgfqpoint\forest@xp\forest@yp}%
8871 {\pgfqpoint
8872 {\csname#2\the\c@pgf@countb x\endcsname}%
8873 {\csname#2\the\c@pgf@countb y\endcsname}%
8874 }%
8875 \fi
8876 \ifforest@equaltotolerance\else
8877 % \end{macrocode}
8878 % It not, we will append a new item to the outer result array.
8879 % \begin{macrocode}
8880 \advance\c@pgf@countb 1
8881 \cslet{#2\the\c@pgf@countb x}\forest@xp
8882 \cslet{#2\the\c@pgf@countb y}\forest@yp
8883 \csdef{#2\the\c@pgf@countb @n}{0}%
8884 \fi
8885 % \end{macrocode}
8886 % If the projection is actually a projection of one point in our path (it will not be when this macro is called from |\forest@distance@between@edge@paths|):
8887 % \begin{macrocode}
8888 % todo: this is ugly!
8889 \ifdefined\forest@xo\ifx\forest@xo\relax\else
8890 \ifdefined\forest@yo\ifx\forest@yo\relax\else
8891 % \end{macrocode}
8892 % Append the point of the current raw item to the inner array of
8893 % points projecting to the current projection.
8894 % \begin{macrocode}
8895 \forest@append@point@to@inner@array
8896 \forest@xo\forest@yo
8897 {#2\the\c@pgf@countb @}%
8898 % \end{macrocode}
8899 % Put a new item in the dictionary: key = the original point, value =
8900 % the projection index.
8901 % \begin{macrocode}
8902 \eapptotoks#3{(\forest@xo,\forest@yo){\the\c@pgf@countb}}%
8903 \fi\fi
8904 \fi\fi
8905 % \end{macrocode}
8906 % Clean-up the raw array item.
8907 % \begin{macrocode}
8908 % todo: is this really necessary? (yes: see the "ugly" thing above)
8909 \cslet{#1\the\c@pgf@counta xo}\relax
8910 \cslet{#1\the\c@pgf@counta yo}\relax
8911 \cslet{#1\the\c@pgf@counta xp}\relax
8912 \cslet{#1\the\c@pgf@counta yp}\relax
8913 \advance\c@pgf@counta 1
8914 \saferepeat
8915 % \end{macrocode}
8916 % Clean up the raw array length.
8917 % \begin{macrocode}
8918 % todo: is this really necessary?
8919 \cslet{#1n}\relax
8920 % \end{macrocode}
8921 % Store the length of the outer result array.
8922 % \begin{macrocode}
8923 \advance\c@pgf@countb 1
8924 \csedef{#2n}{\the\c@pgf@countb}%
8925 }
8926 % \end{macrocode}
8927 %
8928 % Item-exchange macro for sorting the raw projection data. (|#1|
8929 % is copied into |#2|.)
8930 % \begin{macrocode}
8931 \def\forest@ppiraw@let#1#2{%
8932 \csletcs{\forest@ppi@inputprefix#1xo}{\forest@ppi@inputprefix#2xo}%
8933 \csletcs{\forest@ppi@inputprefix#1yo}{\forest@ppi@inputprefix#2yo}%
8934 \csletcs{\forest@ppi@inputprefix#1xp}{\forest@ppi@inputprefix#2xp}%
8935 \csletcs{\forest@ppi@inputprefix#1yp}{\forest@ppi@inputprefix#2yp}%
8936 }
8937 % \end{macrocode}
8938 % Item comparision macro for sorting the raw projection data.
8939 % \begin{macrocode}
8940 \def\forest@ppiraw@cmp#1#2{%
8941 \forest@sort@cmptwodimcs
8942 {\forest@ppi@inputprefix#1xp}{\forest@ppi@inputprefix#1yp}%
8943 {\forest@ppi@inputprefix#2xp}{\forest@ppi@inputprefix#2yp}%
8944 }
8945 % \end{macrocode}
8946 %
8947 % Append the point |(#1,#2)| to the (inner) array of points
8948 % (prefix |#3|).
8949 % \begin{macrocode}
8950 \def\forest@append@point@to@inner@array#1#2#3{%
8951 \c@pgf@countc=\csname#3n\endcsname\relax
8952 \csedef{#3\the\c@pgf@countc x}{#1}%
8953 \csedef{#3\the\c@pgf@countc y}{#2}%
8954 \forest@distancetogrowline\pgfutil@tempdima{\pgfqpoint#1#2}%
8955 \csedef{#3\the\c@pgf@countc d}{\the\pgfutil@tempdima}%
8956 \advance\c@pgf@countc 1
8957 \csedef{#3n}{\the\c@pgf@countc}%
8958 }
8959 % \end{macrocode}
8960 %
8961 % \subsection{Break path}
8962 %
8963 % The following macro computes from the given path (|#1|) a ``broken''
8964 % path (|#4|) that contains the same points of the plane, but has
8965 % potentially more segments, so that, for every point from a given set
8966 % of points on the grow line, a line through this point perpendicular
8967 % to the grow line intersects the broken path only at its edge
8968 % segments (i.e.\ not between them).
8969 %
8970 % The macro works only for \emph{simple} paths, i.e.\ paths built
8971 % using only move-to and line-to operations. Furthermore,
8972 % |\forest@processprojectioninfo| must be called before calling
8973 % |\forest@breakpath|: we expect information in an array with prefix
8974 % |#2| (projections and (an inner array of) their original points)
8975 % and toks register |#3| (a ``dictionary'': for each original points,
8976 % the index of its projection in |#2|). The macro updates array |#2|.
8977 % (No need to update |#3|, as it is not used anymore.)
8978 % \begin{macrocode}
8979 \def\forest@breakpath#1#2#3#4{%
8980 % \end{macrocode}
8981 % Store the current path in a macro and empty it, then process the
8982 % stored path. The processing creates a new current path.
8983 % \begin{macrocode}
8984 \edef\forest@bp@prefix{#2}%
8985 \let\forest@breakpath@toks#3%
8986 \forest@save@pgfsyssoftpath@tokendefs
8987 \let\pgfsyssoftpath@movetotoken\forest@breakpath@processfirstpoint
8988 \let\pgfsyssoftpath@linetotoken\forest@breakpath@processfirstpoint
8989 %\pgfusepath{}% empty the current path. ok?
8990 #1%
8991 \forest@restore@pgfsyssoftpath@tokendefs
8992 \pgfsyssoftpath@getcurrentpath#4%
8993 }
8994 % \end{macrocode}
8995 % The original and the broken path start in the same way. (This code
8996 % implicitely ``repairs'' a path that starts illegally, with a line-to
8997 % operation.)
8998 % \begin{macrocode}
8999 \def\forest@breakpath@processfirstpoint#1#2{%
9000 \forest@breakpath@processmoveto{#1}{#2}%
9001 \let\pgfsyssoftpath@movetotoken\forest@breakpath@processmoveto
9002 \let\pgfsyssoftpath@linetotoken\forest@breakpath@processlineto
9003 }
9004 % \end{macrocode}
9005 % When a move-to operation is encountered, it is simply copied to the
9006 % broken path, starting a new subpath. Then we remember the last
9007 % point, its projection's index (the point dictionary is used here)
9008 % and the actual projection point.
9009 % \begin{macrocode}
9010 \def\forest@breakpath@processmoveto#1#2{%
9011 \pgfsyssoftpath@moveto{#1}{#2}%
9012 \def\forest@previous@x{#1}%
9013 \def\forest@previous@y{#2}%
9014 \forest@breakpath@getfromtoks\forest@breakpath@toks\forest@previous@i{#1}{#2}%
9015 \expandafter\let\expandafter\forest@previous@px
9016 \csname\forest@bp@prefix\forest@previous@i x\endcsname
9017 \expandafter\let\expandafter\forest@previous@py
9018 \csname\forest@bp@prefix\forest@previous@i y\endcsname
9019 }
9020 \def\forest@breakpath@getfromtoks#1#2#3#4{%
9021 % #1=cache toks register, #2=receiving cs, (#3,#4)=point;
9022 % we rely on the fact that the point we're looking up should always be present
9023 \def\forest@breakpath@getfromtoks@##1(#3,#4)##2##3\forest@END{##2}%
9024 \edef#2{\expandafter\forest@breakpath@getfromtoks@\the#1\forest@END}%
9025 }
9026 % \end{macrocode}
9027 %
9028 % This is the heart of the path-breaking procedure.
9029 % \begin{macrocode}
9030 \def\forest@breakpath@processlineto#1#2{%
9031 % \end{macrocode}
9032 % Usually, the broken path will continue with a line-to operation (to
9033 % the current point |(#1,#2)|).
9034 % \begin{macrocode}
9035 \let\forest@breakpath@op\pgfsyssoftpath@lineto
9036 % \end{macrocode}
9037 % Get the index of the current point's projection and the projection
9038 % itself. (The point dictionary is used here.)
9039 % \begin{macrocode}
9040 \forest@breakpath@getfromtoks\forest@breakpath@toks\forest@i{#1}{#2}%
9041 \expandafter\let\expandafter\forest@px
9042 \csname\forest@bp@prefix\forest@i x\endcsname
9043 \expandafter\let\expandafter\forest@py
9044 \csname\forest@bp@prefix\forest@i y\endcsname
9045 % \end{macrocode}
9046 % Test whether the projections of the previous and the current point
9047 % are the same.
9048 % \begin{macrocode}
9049 \forest@equaltotolerance
9050 {\pgfqpoint{\forest@previous@px}{\forest@previous@py}}%
9051 {\pgfqpoint{\forest@px}{\forest@py}}%
9052 \ifforest@equaltotolerance
9053 % \end{macrocode}
9054 % If so, we are dealing with a segment, perpendicular to the grow
9055 % line. This segment must be removed, so we change the operation to
9056 % move-to.
9057 % \begin{macrocode}
9058 \let\forest@breakpath@op\pgfsyssoftpath@moveto
9059 \else
9060 % \end{macrocode}
9061 % Figure out the ``direction'' of the segment: in the order of the
9062 % array of projections, or in the reversed order? Setup the loop step
9063 % and the test condition.
9064 % \begin{macrocode}
9065 \forest@temp@count=\forest@previous@i\relax
9066 \ifnum\forest@previous@i<\forest@i\relax
9067 \def\forest@breakpath@step{1}%
9068 \def\forest@breakpath@test{\forest@temp@count<\forest@i\relax}%
9069 \else
9070 \def\forest@breakpath@step{-1}%
9071 \def\forest@breakpath@test{\forest@temp@count>\forest@i\relax}%
9072 \fi
9073 % \end{macrocode}
9074 % Loop through all the projections between (in the (possibly reversed)
9075 % array order) the projections of the previous and the current point
9076 % (both exclusive).
9077 % \begin{macrocode}
9078 \safeloop
9079 \advance\forest@temp@count\forest@breakpath@step\relax
9080 \expandafter\ifnum\forest@breakpath@test
9081 % \end{macrocode}
9082 % Intersect the current segment with the line through the current (in
9083 % the loop!) projection perpendicular to the grow line. (There
9084 % \emph{will} be an intersection.)
9085 % \begin{macrocode}
9086 \pgfpointintersectionoflines
9087 {\pgfqpoint
9088 {\csname\forest@bp@prefix\the\forest@temp@count x\endcsname}%
9089 {\csname\forest@bp@prefix\the\forest@temp@count y\endcsname}%
9090 }%
9091 {\pgfpointadd
9092 {\pgfqpoint
9093 {\csname\forest@bp@prefix\the\forest@temp@count x\endcsname}%
9094 {\csname\forest@bp@prefix\the\forest@temp@count y\endcsname}%
9095 }%
9096 {\pgfqpoint{\forest@xs}{\forest@ys}}%
9097 }%
9098 {\pgfqpoint{\forest@previous@x}{\forest@previous@y}}%
9099 {\pgfqpoint{#1}{#2}}%
9100 % \end{macrocode}
9101 % Break the segment at the intersection.
9102 % \begin{macrocode}
9103 \pgfgetlastxy\forest@last@x\forest@last@y
9104 \pgfsyssoftpath@lineto\forest@last@x\forest@last@y
9105 % \end{macrocode}
9106 % Append the breaking point to the inner array for the projection.
9107 % \begin{macrocode}
9108 \forest@append@point@to@inner@array
9109 \forest@last@x\forest@last@y
9110 {\forest@bp@prefix\the\forest@temp@count @}%
9111 \saferepeat
9112 \fi
9113 % \end{macrocode}
9114 % Add the current point.
9115 % \begin{macrocode}
9116 \forest@breakpath@op{#1}{#2}%
9117 % \end{macrocode}
9118 % Setup new ``previous'' info: the segment edge, its projection's
9119 % index, and the projection.
9120 % \begin{macrocode}
9121 \def\forest@previous@x{#1}%
9122 \def\forest@previous@y{#2}%
9123 \let\forest@previous@i\forest@i
9124 \let\forest@previous@px\forest@px
9125 \let\forest@previous@py\forest@py
9126 }
9127 % \end{macrocode}
9128 % Patch for speed: no need to call |\pgfmathparse| here.
9129 % \begin{macrocode}
9130 \patchcmd{\pgfpointintersectionoflines}{\pgfpoint}{\pgfqpoint}{}{}
9131 % \end{macrocode}
9132 %
9133 % \subsection{Get tight edge of path}
9134 %
9135 % This is one of the central algorithms of the package. Given a simple
9136 % path and a grow line, this method computes its (negative and
9137 % positive) ``tight edge'', which we (informally) define as follows.
9138 %
9139 % Imagine an infinitely long light source parallel to the grow line,
9140 % on the grow line's negative/positive side.\footnote{For the
9141 % definition of negative/positive side, see {\tt\string\forest@distancetogrowline}
9142 % in \S\ref{imp:projections}} Furthermore imagine that the path is
9143 % opaque. Then the negative/positive tight edge of the path is the
9144 % part of the path that is illuminated.
9145 %
9146 % This macro takes three arguments: |#1| is the path; |#2| and |#3|
9147 % are macros which will receive the negative and the positive edge,
9148 % respectively. The edges are returned in the softpath format. Grow
9149 % line should be set before calling this macro.
9150 %
9151 % Enclose the computation in a \TeX\ group. This is actually quite
9152 % crucial: if there was no enclosure, the temporary data (the segment
9153 % dictionary, to be precise) computed by the prior invocations of the
9154 % macro could corrupt the computation in the current invocation.
9155 % \begin{macrocode}
9156 \def\forest@getnegativetightedgeofpath#1#2{%
9157 \forest@get@onetightedgeofpath#1\forest@sort@ascending#2}
9158 \def\forest@getpositivetightedgeofpath#1#2{%
9159 \forest@get@onetightedgeofpath#1\forest@sort@descending#2}
9160 \def\forest@get@onetightedgeofpath#1#2#3{%
9161 {%
9162 \forest@get@one@tightedgeofpath#1#2\forest@gep@edge
9163 \global\let\forest@gep@global@edge\forest@gep@edge
9164 }%
9165 \let#3\forest@gep@global@edge
9166 }
9167 \newtoks\forest@pi@toks
9168 \newtoks\forest@segment@toks
9169 \def\forest@get@one@tightedgeofpath#1#2#3{%
9170 % \end{macrocode}
9171 % Project the path to the grow line and compile some useful information.
9172 % \begin{macrocode}
9173 \forest@projectpathtogrowline#1{forest@pp@}%
9174 \forest@sortprojections{forest@pp@}%
9175 \forest@processprojectioninfo{forest@pp@}{forest@pi@}\forest@pi@toks
9176 % \end{macrocode}
9177 % Break the path.
9178 % \begin{macrocode}
9179 \forest@breakpath#1{forest@pi@}\forest@pi@toks\forest@brokenpath
9180 % \end{macrocode}
9181 % Compile some more useful information.
9182 % \begin{macrocode}
9183 \forest@sort@inner@arrays{forest@pi@}#2%
9184 \forest@pathtodict\forest@brokenpath\forest@segment@toks
9185 % \end{macrocode}
9186 % The auxiliary data is set up: do the work!
9187 % \begin{macrocode}
9188 \forest@gettightedgeofpath@getedge\forest@edge
9189 % \end{macrocode}
9190 % Where possible, merge line segments of the path into a single line
9191 % segment. This is an important optimization, since the edges of the
9192 % subtrees are computed recursively. Not simplifying the edge could
9193 % result in a wild growth of the length of the edge (in the sense of
9194 % the number of segments).
9195 % \begin{macrocode}
9196 \forest@simplifypath\forest@edge#3%
9197 }
9198 % \end{macrocode}
9199 % Get both negative (stored in |#2|) and positive (stored in |#3|)
9200 % edge of the path |#1|.
9201 % \begin{macrocode}
9202 \def\forest@getbothtightedgesofpath#1#2#3{%
9203 {%
9204 \forest@get@one@tightedgeofpath#1\forest@sort@ascending\forest@gep@firstedge
9205 % \end{macrocode}
9206 % Reverse the order of items in the inner arrays.
9207 % \begin{macrocode}
9208 \c@pgf@counta=0
9209 \forest@loop
9210 \ifnum\c@pgf@counta<\forest@pi@n\relax
9211 \forest@ppi@deflet{forest@pi@\the\c@pgf@counta @}%
9212 \forest@reversearray\forest@ppi@let
9213 {0}%
9214 {\csname forest@pi@\the\c@pgf@counta @n\endcsname}%
9215 \advance\c@pgf@counta 1
9216 \forest@repeat
9217 % \end{macrocode}
9218 % Calling |\forest@gettightedgeofpath@getedge| now will result in the
9219 % positive edge.
9220 % \begin{macrocode}
9221 \forest@gettightedgeofpath@getedge\forest@edge
9222 \forest@simplifypath\forest@edge\forest@gep@secondedge
9223 % \end{macrocode}
9224 % Smuggle the results out of the enclosing \TeX\ group.
9225 % \begin{macrocode}
9226 \global\let\forest@gep@global@firstedge\forest@gep@firstedge
9227 \global\let\forest@gep@global@secondedge\forest@gep@secondedge
9228 }%
9229 \let#2\forest@gep@global@firstedge
9230 \let#3\forest@gep@global@secondedge
9231 }
9232 % \end{macrocode}
9233 %
9234 % Sort the inner arrays of original points wrt the distance to the
9235 % grow line. |#2| =
9236 % |\forest@sort@ascending|/|\forest@sort@descending|.
9237 % \begin{macrocode}
9238 \def\forest@sort@inner@arrays#1#2{%
9239 \c@pgf@counta=0
9240 \safeloop
9241 \ifnum\c@pgf@counta<\csname#1n\endcsname
9242 \c@pgf@countb=\csname#1\the\c@pgf@counta @n\endcsname\relax
9243 \ifnum\c@pgf@countb>1
9244 \advance\c@pgf@countb -1
9245 \forest@ppi@deflet{#1\the\c@pgf@counta @}%
9246 \forest@ppi@defcmp{#1\the\c@pgf@counta @}%
9247 \forest@sort\forest@ppi@cmp\forest@ppi@let#2{0}{\the\c@pgf@countb}%
9248 \fi
9249 \advance\c@pgf@counta 1
9250 \saferepeat
9251 }
9252 % \end{macrocode}
9253 %
9254 % A macro that will define the item exchange macro for quicksorting
9255 % the inner arrays of original points. It takes one argument: the
9256 % prefix of the inner array.
9257 % \begin{macrocode}
9258 \def\forest@ppi@deflet#1{%
9259 \edef\forest@ppi@let##1##2{%
9260 \noexpand\csletcs{#1##1x}{#1##2x}%
9261 \noexpand\csletcs{#1##1y}{#1##2y}%
9262 \noexpand\csletcs{#1##1d}{#1##2d}%
9263 }%
9264 }
9265 % \end{macrocode}
9266 % A macro that will define the item-compare macro for quicksorting the
9267 % embedded arrays of original points. It takes one argument: the
9268 % prefix of the inner array.
9269 % \begin{macrocode}
9270 \def\forest@ppi@defcmp#1{%
9271 \edef\forest@ppi@cmp##1##2{%
9272 \noexpand\forest@sort@cmpdimcs{#1##1d}{#1##2d}%
9273 }%
9274 }
9275 % \end{macrocode}
9276 %
9277 % Put path segments into a ``segment dictionary'': for each segment of
9278 % the pgf path (given in |#1|) from $(x_1,y_1)$ to $(x_2,y_2)$ we put
9279 % |(x1,y1)--(x2,y2)| into toks |#2|. (The ``dictionary'' was
9280 % reimplemented in v2.1.4. It's based on a toks register now, we search using
9281 % |\pgfutil@in@|.)
9282 % \begin{macrocode}
9283 \def\forest@pathtodict#1#2{%
9284 \let\forest@pathtodict@toks#2%
9285 \forest@save@pgfsyssoftpath@tokendefs
9286 \let\pgfsyssoftpath@movetotoken\forest@pathtodict@movetoop
9287 \let\pgfsyssoftpath@linetotoken\forest@pathtodict@linetoop
9288 \def\forest@pathtodict@subpathstart{}%
9289 #1%
9290 \forest@restore@pgfsyssoftpath@tokendefs
9291 }
9292 % \end{macrocode}
9293 % When a move-to operation is encountered:
9294 % \begin{macrocode}
9295 \def\forest@pathtodict@movetoop#1#2{%
9296 \apptotoks\forest@pathtodict@toks{(#1,#2)}%
9297 }
9298 % \end{macrocode}
9299 % When a line-to operation is encountered:
9300 % \begin{macrocode}
9301 \def\forest@pathtodict@linetoop#1#2{%
9302 \apptotoks\forest@pathtodict@toks{--(#1,#2)}%
9303 }
9304 % \end{macrocode}
9305 %
9306 % In this macro, the edge is actually computed.
9307 % \begin{macrocode}
9308 \def\forest@gettightedgeofpath@getedge#1{% cs to store the edge into
9309 % \end{macrocode}
9310 % Clear the path and the last projection.
9311 % \begin{macrocode}
9312 \pgfsyssoftpath@setcurrentpath\pgfutil@empty
9313 \let\forest@last@x\relax
9314 \let\forest@last@y\relax
9315 % \end{macrocode}
9316 % Loop through the (ordered) array of projections. (Since we will be
9317 % dealing with the current and the next projection in each iteration
9318 % of the loop, we loop the counter from the first to the
9319 % second-to-last projection.)
9320 % \begin{macrocode}
9321 \c@pgf@counta=0
9322 \forest@temp@count=\forest@pi@n\relax
9323 \advance\forest@temp@count -1
9324 \edef\forest@nminusone{\the\forest@temp@count}%
9325 \safeloop
9326 \ifnum\c@pgf@counta<\forest@nminusone\relax
9327 \forest@gettightedgeofpath@getedge@loopa
9328 \saferepeat
9329 % \end{macrocode}
9330 % A special case: the edge ends with a degenerate subpath (a
9331 % point).
9332 % \begin{macrocode}
9333 \ifnum\forest@nminusone<\forest@n\relax\else
9334 \ifnum\csname forest@pi@\forest@nminusone @n\endcsname>0
9335 \forest@gettightedgeofpath@maybemoveto{\forest@nminusone}{0}%
9336 \fi
9337 \fi
9338 \pgfsyssoftpath@getcurrentpath#1%
9339 \pgfsyssoftpath@setcurrentpath\pgfutil@empty
9340 }
9341 % \end{macrocode}
9342 % The body of a loop containing an embedded loop must be put in a
9343 % separate macro because it contains the |\if...| of the embedded
9344 % |\forest@loop...| without the matching |\fi|: |\fi| is ``hiding'' in the
9345 % embedded |\forest@loop|, which has not been expanded yet.
9346 % \begin{macrocode}
9347 \def\forest@gettightedgeofpath@getedge@loopa{%
9348 \ifnum\csname forest@pi@\the\c@pgf@counta @n\endcsname>0
9349 % \end{macrocode}
9350 % Degenerate case: a subpath of the edge is a point.
9351 % \begin{macrocode}
9352 \forest@gettightedgeofpath@maybemoveto{\the\c@pgf@counta}{0}%
9353 % \end{macrocode}
9354 % Loop through points projecting to the current projection. The
9355 % preparations above guarantee that the points are ordered (either in
9356 % the ascending or the descending order) with respect to their
9357 % distance to the grow line.
9358 % \begin{macrocode}
9359 \c@pgf@countb=0
9360 \safeloop
9361 \ifnum\c@pgf@countb<\csname forest@pi@\the\c@pgf@counta @n\endcsname\relax
9362 \forest@gettightedgeofpath@getedge@loopb
9363 \saferepeat
9364 \fi
9365 \advance\c@pgf@counta 1
9366 }
9367 % \end{macrocode}
9368 % Loop through points projecting to the next projection. Again, the
9369 % points are ordered.
9370 % \begin{macrocode}
9371 \def\forest@gettightedgeofpath@getedge@loopb{%
9372 \c@pgf@countc=0
9373 \advance\c@pgf@counta 1
9374 \edef\forest@aplusone{\the\c@pgf@counta}%
9375 \advance\c@pgf@counta -1
9376 \safeloop
9377 \ifnum\c@pgf@countc<\csname forest@pi@\forest@aplusone @n\endcsname\relax
9378 % \end{macrocode}
9379 % Test whether [the current point]--[the next point] or [the next
9380 % point]--[the current point] is a segment in the (broken) path. The
9381 % first segment found is the one with the minimal/maximal distance
9382 % (depending on the sort order of arrays of points projecting to the
9383 % same projection) to the grow line.
9384 %
9385 % Note that for this to work in all cases, the original path should
9386 % have been broken on its self-intersections. However, a careful
9387 % reader will probably remember that |\forest@breakpath| does
9388 % \emph{not} break the path at its self-intersections. This is
9389 % omitted for performance reasons. Given the intended use of the
9390 % algorithm (calculating edges of subtrees), self-intersecting paths
9391 % cannot arise anyway, if only the node boundaries are
9392 % non-self-intersecting. So, a warning: if you develop a new shape and
9393 % write a macro computing its boundary, make sure that the computed
9394 % boundary path is non-self-intersecting!
9395 % \begin{macrocode}
9396 \edef\forest@temp{%
9397 (\csname forest@pi@\the\c@pgf@counta @\the\c@pgf@countb x\endcsname,%
9398 \csname forest@pi@\the\c@pgf@counta @\the\c@pgf@countb y\endcsname)--(%
9399 \csname forest@pi@\forest@aplusone @\the\c@pgf@countc x\endcsname,%
9400 \csname forest@pi@\forest@aplusone @\the\c@pgf@countc y\endcsname)%
9401 }%
9402 \expandafter\expandafter\expandafter\pgfutil@in@\expandafter\expandafter\expandafter
9403 {\expandafter\forest@temp\expandafter}\expandafter
9404 {\the\forest@segment@toks}%
9405 \ifpgfutil@in@
9406 \else
9407 \edef\forest@temp{%
9408 (\csname forest@pi@\forest@aplusone @\the\c@pgf@countc x\endcsname,%
9409 \csname forest@pi@\forest@aplusone @\the\c@pgf@countc y\endcsname)--(%
9410 \csname forest@pi@\the\c@pgf@counta @\the\c@pgf@countb x\endcsname,%
9411 \csname forest@pi@\the\c@pgf@counta @\the\c@pgf@countb y\endcsname)%
9412 }%
9413 \expandafter\expandafter\expandafter\pgfutil@in@\expandafter\expandafter\expandafter
9414 {\expandafter\forest@temp\expandafter}\expandafter
9415 {\the\forest@segment@toks}%
9416 \fi
9417 \ifpgfutil@in@
9418 % \end{macrocode}
9419 % We have found the segment with the minimal/maximal distance to the
9420 % grow line. So let's add it to the edge path.
9421 %
9422 % First, deal with the
9423 % start point of the edge: check if the current point is the last
9424 % point. If that is the case (this happens if the current point was
9425 % the end point of the last segment added to the edge), nothing needs
9426 % to be done; otherwise (this happens if the current point will start
9427 % a new subpath of the edge), move to the current point, and update
9428 % the last-point macros.
9429 % \begin{macrocode}
9430 \forest@gettightedgeofpath@maybemoveto{\the\c@pgf@counta}{\the\c@pgf@countb}%
9431 % \end{macrocode}
9432 % Second, create a line to the end point.
9433 % \begin{macrocode}
9434 \edef\forest@last@x{%
9435 \csname forest@pi@\forest@aplusone @\the\c@pgf@countc x\endcsname}%
9436 \edef\forest@last@y{%
9437 \csname forest@pi@\forest@aplusone @\the\c@pgf@countc y\endcsname}%
9438 \pgfsyssoftpath@lineto\forest@last@x\forest@last@y
9439 % \end{macrocode}
9440 % Finally, ``break'' out of the innermost two loops.
9441 % \begin{macrocode}
9442 \c@pgf@countc=\csname forest@pi@\forest@aplusone @n\endcsname
9443 \c@pgf@countb=\csname forest@pi@\the\c@pgf@counta @n\endcsname
9444 \fi
9445 \advance\c@pgf@countc 1
9446 \saferepeat
9447 \advance\c@pgf@countb 1
9448 }
9449 % \end{macrocode}
9450 % |\forest@#1@| is an (ordered) array of points projecting to
9451 % projection with index |#1|. Check if |#2|th point of that array
9452 % equals the last point added to the edge: if not, add it.
9453 % \begin{macrocode}
9454 \def\forest@gettightedgeofpath@maybemoveto#1#2{%
9455 \forest@temptrue
9456 \ifx\forest@last@x\relax\else
9457 \ifdim\forest@last@x=\csname forest@pi@#1@#2x\endcsname\relax
9458 \ifdim\forest@last@y=\csname forest@pi@#1@#2y\endcsname\relax
9459 \forest@tempfalse
9460 \fi
9461 \fi
9462 \fi
9463 \ifforest@temp
9464 \edef\forest@last@x{\csname forest@pi@#1@#2x\endcsname}%
9465 \edef\forest@last@y{\csname forest@pi@#1@#2y\endcsname}%
9466 \pgfsyssoftpath@moveto\forest@last@x\forest@last@y
9467 \fi
9468 }
9469 % \end{macrocode}
9470 %
9471 % Simplify the resulting path by ``unbreaking'' segments where
9472 % possible. (The macro itself is just a wrapper for path processing
9473 % macros below.)
9474 % \begin{macrocode}
9475 \def\forest@simplifypath#1#2{%
9476 \pgfsyssoftpath@setcurrentpath\pgfutil@empty
9477 \forest@save@pgfsyssoftpath@tokendefs
9478 \let\pgfsyssoftpath@movetotoken\forest@simplifypath@moveto
9479 \let\pgfsyssoftpath@linetotoken\forest@simplifypath@lineto
9480 \let\forest@last@x\relax
9481 \let\forest@last@y\relax
9482 \let\forest@last@atan\relax
9483 #1%
9484 \ifx\forest@last@x\relax\else
9485 \ifx\forest@last@atan\relax\else
9486 \pgfsyssoftpath@lineto\forest@last@x\forest@last@y
9487 \fi
9488 \fi
9489 \forest@restore@pgfsyssoftpath@tokendefs
9490 \pgfsyssoftpath@getcurrentpath#2%
9491 \pgfsyssoftpath@setcurrentpath\pgfutil@empty
9492 }
9493 % \end{macrocode}
9494 % When a move-to is encountered, we flush whatever segment we were
9495 % building, make the move, remember the last position, and set the
9496 % slope to unknown.
9497 % \begin{macrocode}
9498 \def\forest@simplifypath@moveto#1#2{%
9499 \ifx\forest@last@x\relax\else
9500 \pgfsyssoftpath@lineto\forest@last@x\forest@last@y
9501 \fi
9502 \pgfsyssoftpath@moveto{#1}{#2}%
9503 \def\forest@last@x{#1}%
9504 \def\forest@last@y{#2}%
9505 \let\forest@last@atan\relax
9506 }
9507 % \end{macrocode}
9508 % How much may the segment slopes differ that we can still merge them?
9509 % (Ignore |pt|, these are degrees.) Also, how good is this number?
9510 % \begin{macrocode}
9511 \def\forest@getedgeofpath@precision{1pt}
9512 % \end{macrocode}
9513 % When a line-to is encountered\dots
9514 % \begin{macrocode}
9515 \def\forest@simplifypath@lineto#1#2{%
9516 \ifx\forest@last@x\relax
9517 % \end{macrocode}
9518 % If we're not in the middle of a merger, we need to nothing but start
9519 % it.
9520 % \begin{macrocode}
9521 \def\forest@last@x{#1}%
9522 \def\forest@last@y{#2}%
9523 \let\forest@last@atan\relax
9524 \else
9525 % \end{macrocode}
9526 % Otherwise, we calculate the slope of the current segment (i.e.\ the
9527 % segment between the last and the current point), \dots
9528 % \begin{macrocode}
9529 \pgfpointdiff{\pgfqpoint{#1}{#2}}{\pgfqpoint{\forest@last@x}{\forest@last@y}}%
9530 \ifdim\pgf@x<\pgfintersectiontolerance
9531 \ifdim-\pgf@x<\pgfintersectiontolerance
9532 \pgf@x=0pt
9533 \fi
9534 \fi
9535 \edef\forest@marshal{%
9536 \noexpand\pgfmathatantwo@
9537 {\expandafter\Pgf@geT\the\pgf@x}%
9538 {\expandafter\Pgf@geT\the\pgf@y}%
9539 }\forest@marshal
9540 \let\forest@current@atan\pgfmathresult
9541 \ifx\forest@last@atan\relax
9542 % \end{macrocode}
9543 % If this is the first segment in the current merger, simply remember
9544 % the slope and the last point.
9545 % \begin{macrocode}
9546 \def\forest@last@x{#1}%
9547 \def\forest@last@y{#2}%
9548 \let\forest@last@atan\forest@current@atan
9549 \else
9550 % \end{macrocode}
9551 % Otherwise, compare the first and the current slope.
9552 % \begin{macrocode}
9553 \pgfutil@tempdima=\forest@current@atan pt
9554 \advance\pgfutil@tempdima -\forest@last@atan pt
9555 \ifdim\pgfutil@tempdima<0pt\relax
9556 \multiply\pgfutil@tempdima -1
9557 \fi
9558 \ifdim\pgfutil@tempdima<\forest@getedgeofpath@precision\relax
9559 \else
9560 % \end{macrocode}
9561 % If the slopes differ too much, flush the path up to the previous
9562 % segment, and set up a new first slope.
9563 % \begin{macrocode}
9564 \pgfsyssoftpath@lineto\forest@last@x\forest@last@y
9565 \let\forest@last@atan\forest@current@atan
9566 \fi
9567 % \end{macrocode}
9568 % In any event, update the last point.
9569 % \begin{macrocode}
9570 \def\forest@last@x{#1}%
9571 \def\forest@last@y{#2}%
9572 \fi
9573 \fi
9574 }
9575 % \end{macrocode}
9576 %
9577 %
9578 % \subsection{Get rectangle/band edge}
9579 %
9580 % \begin{macrocode}
9581 \def\forest@getnegativerectangleedgeofpath#1#2{%
9582 \forest@getnegativerectangleorbandedgeofpath{#1}{#2}{\the\pgf@xb}}
9583 \def\forest@getpositiverectangleedgeofpath#1#2{%
9584 \forest@getpositiverectangleorbandedgeofpath{#1}{#2}{\the\pgf@xb}}
9585 \def\forest@getbothrectangleedgesofpath#1#2#3{%
9586 \forest@getbothrectangleorbandedgesofpath{#1}{#2}{#3}{\the\pgf@xb}}
9587 \def\forest@bandlength{5000pt} % something large (ca. 180cm), but still manageable for TeX without producing `too large' errors
9588 \def\forest@getnegativebandedgeofpath#1#2{%
9589 \forest@getnegativerectangleorbandedgeofpath{#1}{#2}{\forest@bandlength}}
9590 \def\forest@getpositivebandedgeofpath#1#2{%
9591 \forest@getpositiverectangleorbandedgeofpath{#1}{#2}{\forest@bandlength}}
9592 \def\forest@getbothbandedgesofpath#1#2#3{%
9593 \forest@getbothrectangleorbandedgesofpath{#1}{#2}{#3}{\forest@bandlength}}
9594 \def\forest@getnegativerectangleorbandedgeofpath#1#2#3{%
9595 \forest@path@getboundingrectangle@ls#1{\forest@grow}%
9596 \edef\forest@gre@path{%
9597 \noexpand\pgfsyssoftpath@movetotoken{\the\pgf@xa}{\the\pgf@ya}%
9598 \noexpand\pgfsyssoftpath@linetotoken{#3}{\the\pgf@ya}%
9599 }%
9600 {%
9601 \pgftransformreset
9602 \forest@pgfqtransformrotate{\forest@grow}%
9603 \forest@pgfpathtransformed\forest@gre@path
9604 }%
9605 \pgfsyssoftpath@getcurrentpath#2%
9606 }
9607 \def\forest@getpositiverectangleorbandedgeofpath#1#2#3{%
9608 \forest@path@getboundingrectangle@ls#1{\forest@grow}%
9609 \edef\forest@gre@path{%
9610 \noexpand\pgfsyssoftpath@movetotoken{\the\pgf@xa}{\the\pgf@yb}%
9611 \noexpand\pgfsyssoftpath@linetotoken{#3}{\the\pgf@yb}%
9612 }%
9613 {%
9614 \pgftransformreset
9615 \forest@pgfqtransformrotate{\forest@grow}%
9616 \forest@pgfpathtransformed\forest@gre@path
9617 }%
9618 \pgfsyssoftpath@getcurrentpath#2%
9619 }
9620 \def\forest@getbothrectangleorbandedgesofpath#1#2#3#4{%
9621 \forest@path@getboundingrectangle@ls#1{\forest@grow}%
9622 \edef\forest@gre@negpath{%
9623 \noexpand\pgfsyssoftpath@movetotoken{\the\pgf@xa}{\the\pgf@ya}%
9624 \noexpand\pgfsyssoftpath@linetotoken{#4}{\the\pgf@ya}%
9625 }%
9626 \edef\forest@gre@pospath{%
9627 \noexpand\pgfsyssoftpath@movetotoken{\the\pgf@xa}{\the\pgf@yb}%
9628 \noexpand\pgfsyssoftpath@linetotoken{#4}{\the\pgf@yb}%
9629 }%
9630 {%
9631 \pgftransformreset
9632 \forest@pgfqtransformrotate{\forest@grow}%
9633 \forest@pgfpathtransformed\forest@gre@negpath
9634 }%
9635 \pgfsyssoftpath@getcurrentpath#2%
9636 {%
9637 \pgftransformreset
9638 \forest@pgfqtransformrotate{\forest@grow}%
9639 \forest@pgfpathtransformed\forest@gre@pospath
9640 }%
9641 \pgfsyssoftpath@getcurrentpath#3%
9642 }
9643 % \end{macrocode}
9644 %
9645 % \subsection{Distance between paths}
9646 % \label{imp:distance}
9647 %
9648 % Another crucial part of the package.
9649 %
9650 % \begin{macrocode}
9651 \newtoks\forest@PIi@toks
9652 \newtoks\forest@PIii@toks
9653 \def\forest@distance@between@edge@paths#1#2#3{%
9654 \begingroup
9655 % #1, #2 = (edge) paths
9656 %
9657 % project paths
9658 \forest@projectpathtogrowline#1{forest@p1@}%
9659 \forest@projectpathtogrowline#2{forest@p2@}%
9660 % merge projections (the lists are sorted already, because edge
9661 % paths are |sorted|)
9662 \forest@dbep@mergeprojections
9663 {forest@p1@}{forest@p2@}%
9664 {forest@P1@}{forest@P2@}%
9665 % process projections
9666 \forest@processprojectioninfo{forest@P1@}{forest@PI1@}\forest@PIi@toks
9667 \forest@processprojectioninfo{forest@P2@}{forest@PI2@}\forest@PIii@toks
9668 % break paths
9669 \forest@breakpath#1{forest@PI1@}\forest@PIi@toks\forest@broken@one
9670 \forest@breakpath#2{forest@PI2@}\forest@PIii@toks\forest@broken@two
9671 % sort inner arrays ---optimize: it's enough to find max and min
9672 \forest@sort@inner@arrays{forest@PI1@}\forest@sort@descending
9673 \forest@sort@inner@arrays{forest@PI2@}\forest@sort@ascending
9674 % compute the distance
9675 \let\forest@distance\relax
9676 \c@pgf@countc=0
9677 \forest@loop
9678 \ifnum\c@pgf@countc<\csname forest@PI1@n\endcsname\relax
9679 \ifnum\csname forest@PI1@\the\c@pgf@countc @n\endcsname=0 \else
9680 \ifnum\csname forest@PI2@\the\c@pgf@countc @n\endcsname=0 \else
9681 \pgfutil@tempdima=\csname forest@PI2@\the\c@pgf@countc @0d\endcsname\relax
9682 \advance\pgfutil@tempdima -\csname forest@PI1@\the\c@pgf@countc @0d\endcsname\relax
9683 \ifx\forest@distance\relax
9684 \edef\forest@distance{\the\pgfutil@tempdima}%
9685 \else
9686 \ifdim\pgfutil@tempdima<\forest@distance\relax
9687 \edef\forest@distance{\the\pgfutil@tempdima}%
9688 \fi
9689 \fi
9690 \fi
9691 \fi
9692 \advance\c@pgf@countc 1
9693 \forest@repeat
9694 \global\let\forest@global@temp\forest@distance
9695 \endgroup
9696 \let#3\forest@global@temp
9697 }
9698 % merge projections: we need two projection arrays, both containing
9699 % projection points from both paths, but each with the original
9700 % points from only one path
9701 \def\forest@dbep@mergeprojections#1#2#3#4{%
9702 % TODO: optimize: v bistvu ni treba sortirat, ker je edge path že sortiran
9703 \forest@sortprojections{#1}%
9704 \forest@sortprojections{#2}%
9705 \c@pgf@counta=0
9706 \c@pgf@countb=0
9707 \c@pgf@countc=0
9708 \edef\forest@input@prefix@one{#1}%
9709 \edef\forest@input@prefix@two{#2}%
9710 \edef\forest@output@prefix@one{#3}%
9711 \edef\forest@output@prefix@two{#4}%
9712 \forest@dbep@mp@iterate
9713 \csedef{#3n}{\the\c@pgf@countc}%
9714 \csedef{#4n}{\the\c@pgf@countc}%
9715 }
9716 \def\forest@dbep@mp@iterate{%
9717 \let\forest@dbep@mp@next\forest@dbep@mp@iterate
9718 \ifnum\c@pgf@counta<\csname\forest@input@prefix@one n\endcsname\relax
9719 \ifnum\c@pgf@countb<\csname\forest@input@prefix@two n\endcsname\relax
9720 \let\forest@dbep@mp@next\forest@dbep@mp@do
9721 \else
9722 \let\forest@dbep@mp@next\forest@dbep@mp@iteratefirst
9723 \fi
9724 \else
9725 \ifnum\c@pgf@countb<\csname\forest@input@prefix@two n\endcsname\relax
9726 \let\forest@dbep@mp@next\forest@dbep@mp@iteratesecond
9727 \else
9728 \let\forest@dbep@mp@next\relax
9729 \fi
9730 \fi
9731 \forest@dbep@mp@next
9732 }
9733 \def\forest@dbep@mp@do{%
9734 \forest@sort@cmptwodimcs%
9735 {\forest@input@prefix@one\the\c@pgf@counta xp}%
9736 {\forest@input@prefix@one\the\c@pgf@counta yp}%
9737 {\forest@input@prefix@two\the\c@pgf@countb xp}%
9738 {\forest@input@prefix@two\the\c@pgf@countb yp}%
9739 \if\forest@sort@cmp@result=%
9740 \forest@dbep@mp@@store@p\forest@input@prefix@one\c@pgf@counta
9741 \forest@dbep@mp@@store@o\forest@input@prefix@one
9742 \c@pgf@counta\forest@output@prefix@one
9743 \forest@dbep@mp@@store@o\forest@input@prefix@two
9744 \c@pgf@countb\forest@output@prefix@two
9745 \advance\c@pgf@counta 1
9746 \advance\c@pgf@countb 1
9747 \else
9748 \if\forest@sort@cmp@result>%
9749 \forest@dbep@mp@@store@p\forest@input@prefix@two\c@pgf@countb
9750 \forest@dbep@mp@@store@o\forest@input@prefix@two
9751 \c@pgf@countb\forest@output@prefix@two
9752 \advance\c@pgf@countb 1
9753 \else%<
9754 \forest@dbep@mp@@store@p\forest@input@prefix@one\c@pgf@counta
9755 \forest@dbep@mp@@store@o\forest@input@prefix@one
9756 \c@pgf@counta\forest@output@prefix@one
9757 \advance\c@pgf@counta 1
9758 \fi
9759 \fi
9760 \advance\c@pgf@countc 1
9761 \forest@dbep@mp@iterate
9762 }
9763 \def\forest@dbep@mp@@store@p#1#2{%
9764 \csletcs
9765 {\forest@output@prefix@one\the\c@pgf@countc xp}%
9766 {#1\the#2xp}%
9767 \csletcs
9768 {\forest@output@prefix@one\the\c@pgf@countc yp}%
9769 {#1\the#2yp}%
9770 \csletcs
9771 {\forest@output@prefix@two\the\c@pgf@countc xp}%
9772 {#1\the#2xp}%
9773 \csletcs
9774 {\forest@output@prefix@two\the\c@pgf@countc yp}%
9775 {#1\the#2yp}%
9776 }
9777 \def\forest@dbep@mp@@store@o#1#2#3{%
9778 \csletcs{#3\the\c@pgf@countc xo}{#1\the#2xo}%
9779 \csletcs{#3\the\c@pgf@countc yo}{#1\the#2yo}%
9780 }
9781 \def\forest@dbep@mp@iteratefirst{%
9782 \forest@dbep@mp@iterateone\forest@input@prefix@one\c@pgf@counta\forest@output@prefix@one
9783 }
9784 \def\forest@dbep@mp@iteratesecond{%
9785 \forest@dbep@mp@iterateone\forest@input@prefix@two\c@pgf@countb\forest@output@prefix@two
9786 }
9787 \def\forest@dbep@mp@iterateone#1#2#3{%
9788 \forest@loop
9789 \ifnum#2<\csname#1n\endcsname\relax
9790 \forest@dbep@mp@@store@p#1#2%
9791 \forest@dbep@mp@@store@o#1#2#3%
9792 \advance\c@pgf@countc 1
9793 \advance#21
9794 \forest@repeat
9795 }
9796 % \end{macrocode}
9797 %
9798 % \subsection{Utilities}
9799 %
9800 % Equality test: points are considered equal if they differ less than
9801 % |\pgfintersectiontolerance| in each coordinate.
9802 % \begin{macrocode}
9803 \newif\ifforest@equaltotolerance
9804 \def\forest@equaltotolerance#1#2{{%
9805 \pgfpointdiff{#1}{#2}%
9806 \ifdim\pgf@x<0pt \multiply\pgf@x -1 \fi
9807 \ifdim\pgf@y<0pt \multiply\pgf@y -1 \fi
9808 \global\forest@equaltotolerancefalse
9809 \ifdim\pgf@x<\pgfintersectiontolerance\relax
9810 \ifdim\pgf@y<\pgfintersectiontolerance\relax
9811 \global\forest@equaltotolerancetrue
9812 \fi
9813 \fi
9814 }}
9815 % \end{macrocode}
9816 %
9817 % Save/restore |pgf|s |\[email protected]| definitions.
9818 % \begin{macrocode}
9819 \def\forest@save@pgfsyssoftpath@tokendefs{%
9820 \let\forest@origmovetotoken\pgfsyssoftpath@movetotoken
9821 \let\forest@origlinetotoken\pgfsyssoftpath@linetotoken
9822 \let\forest@origcurvetosupportatoken\pgfsyssoftpath@curvetosupportatoken
9823 \let\forest@origcurvetosupportbtoken\pgfsyssoftpath@curvetosupportbtoken
9824 \let\forest@origcurvetotoken\pgfsyssoftpath@curvetototoken
9825 \let\forest@origrectcornertoken\pgfsyssoftpath@rectcornertoken
9826 \let\forest@origrectsizetoken\pgfsyssoftpath@rectsizetoken
9827 \let\forest@origclosepathtoken\pgfsyssoftpath@closepathtoken
9828 \let\pgfsyssoftpath@movetotoken\forest@badtoken
9829 \let\pgfsyssoftpath@linetotoken\forest@badtoken
9830 \let\pgfsyssoftpath@curvetosupportatoken\forest@badtoken
9831 \let\pgfsyssoftpath@curvetosupportbtoken\forest@badtoken
9832 \let\pgfsyssoftpath@curvetototoken\forest@badtoken
9833 \let\pgfsyssoftpath@rectcornertoken\forest@badtoken
9834 \let\pgfsyssoftpath@rectsizetoken\forest@badtoken
9835 \let\pgfsyssoftpath@closepathtoken\forest@badtoken
9836 }
9837 \def\forest@badtoken{%
9838 \PackageError{forest}{This token should not be in this path}{}%
9839 }
9840 \def\forest@restore@pgfsyssoftpath@tokendefs{%
9841 \let\pgfsyssoftpath@movetotoken\forest@origmovetotoken
9842 \let\pgfsyssoftpath@linetotoken\forest@origlinetotoken
9843 \let\pgfsyssoftpath@curvetosupportatoken\forest@origcurvetosupportatoken
9844 \let\pgfsyssoftpath@curvetosupportbtoken\forest@origcurvetosupportbtoken
9845 \let\pgfsyssoftpath@curvetototoken\forest@origcurvetotoken
9846 \let\pgfsyssoftpath@rectcornertoken\forest@origrectcornertoken
9847 \let\pgfsyssoftpath@rectsizetoken\forest@origrectsizetoken
9848 \let\pgfsyssoftpath@closepathtoken\forest@origclosepathtoken
9849 }
9850 % \end{macrocode}
9851 %
9852 % Extend path |#1| with path |#2| translated by point |#3|.
9853 % \begin{macrocode}
9854 \def\forest@extendpath#1#2#3{%
9855 \pgf@process{#3}%
9856 \pgfsyssoftpath@setcurrentpath#1%
9857 \forest@save@pgfsyssoftpath@tokendefs
9858 \let\pgfsyssoftpath@movetotoken\forest@extendpath@moveto
9859 \let\pgfsyssoftpath@linetotoken\forest@extendpath@lineto
9860 #2%
9861 \forest@restore@pgfsyssoftpath@tokendefs
9862 \pgfsyssoftpath@getcurrentpath#1%
9863 }
9864 \def\forest@extendpath@moveto#1#2{%
9865 \forest@extendpath@do{#1}{#2}\pgfsyssoftpath@moveto
9866 }
9867 \def\forest@extendpath@lineto#1#2{%
9868 \forest@extendpath@do{#1}{#2}\pgfsyssoftpath@lineto
9869 }
9870 \def\forest@extendpath@do#1#2#3{%
9871 {%
9872 \advance\pgf@x #1
9873 \advance\pgf@y #2
9874 #3{\the\pgf@x}{\the\pgf@y}%
9875 }%
9876 }
9877 % \end{macrocode}
9878 %
9879 % Get bounding rectangle of the path. |#1| = the path, |#2| = grow.
9880 % Returns (|\pgf@xa|=min x/l, |\pgf@ya|=max y/s, |\pgf@xb|=min x/l, |\pgf@yb|=max y/s). (If path |#1|
9881 % is empty, the result is undefined.)
9882 % \begin{macrocode}
9883 \def\forest@path@getboundingrectangle@ls#1#2{%
9884 {%
9885 \pgftransformreset
9886 \forest@pgfqtransformrotate{-#2}%
9887 \forest@pgfpathtransformed#1%
9888 }%
9889 \pgfsyssoftpath@getcurrentpath\forest@gbr@rotatedpath
9890 \forest@path@getboundingrectangle@xy\forest@gbr@rotatedpath
9891 }
9892 \def\forest@path@getboundingrectangle@xy#1{%
9893 \forest@save@pgfsyssoftpath@tokendefs
9894 \let\pgfsyssoftpath@movetotoken\forest@gbr@firstpoint
9895 \let\pgfsyssoftpath@linetotoken\forest@gbr@firstpoint
9896 #1%
9897 \forest@restore@pgfsyssoftpath@tokendefs
9898 }
9899 \def\forest@gbr@firstpoint#1#2{%
9900 \pgf@xa=#1 \pgf@xb=#1 \pgf@ya=#2 \pgf@yb=#2
9901 \let\pgfsyssoftpath@movetotoken\forest@gbr@point
9902 \let\pgfsyssoftpath@linetotoken\forest@gbr@point
9903 }
9904 \def\forest@gbr@point#1#2{%
9905 \ifdim#1<\pgf@xa\relax\pgf@xa=#1 \fi
9906 \ifdim#1>\pgf@xb\relax\pgf@xb=#1 \fi
9907 \ifdim#2<\pgf@ya\relax\pgf@ya=#2 \fi
9908 \ifdim#2>\pgf@yb\relax\pgf@yb=#2 \fi
9909 }
9910 % \end{macrocode}
9911 % Hack: create our own version of |pgf|'s |\pgftransformrotate| which does not call |\pgfmathparse|. Nothing really bad happens if patch fails. We're just a bit slower.
9912 % \begin{macrocode}
9913 \let\forest@pgfqtransformrotate\pgftransformrotate
9914 \let\forest@pgftransformcm\pgftransformcm
9915 \let\forest@pgf@transformcm\pgf@transformcm
9916 \patchcmd{\forest@pgfqtransformrotate}{\pgfmathparse{#1}}{\edef\pgfmathresult{\number\numexpr#1}}{}{}
9917 \patchcmd{\forest@pgfqtransformrotate}{\pgftransformcm}{\forest@pgftransformcm}{}{}
9918 \patchcmd{\forest@pgftransformcm}{\pgf@transformcm}{\forest@pgf@transformcm}{}{}
9919 \patchcmd{\forest@pgf@transformcm}{\pgfmathsetlength}{\forest@pgf@transformcm@setlength}{}{} % 4x
9920 \patchcmd{\forest@pgf@transformcm}{\pgfmathsetlength}{\forest@pgf@transformcm@setlength}{}{} % 4x
9921 \patchcmd{\forest@pgf@transformcm}{\pgfmathsetlength}{\forest@pgf@transformcm@setlength}{}{} % 4x
9922 \patchcmd{\forest@pgf@transformcm}{\pgfmathsetlength}{\forest@pgf@transformcm@setlength}{}{} % 4x
9923 \def\forest@pgf@transformcm@setlength#1#2{#1=#2pt}
9924 % \end{macrocode}
9925 %
9926 % \section{The outer UI}
9927 %
9928 %
9929 % \subsection{Externalization}
9930 % \begin{macrocode}
9931 \pgfkeys{/forest/external/.cd,
9932 %copy command/.initial={cp "\source" "\target"},
9933 copy command/.initial={},
9934 optimize/.is if=forest@external@optimize@,
9935 context/.initial={%
9936 \forestOve{\csname forest@id@of@standard node\endcsname}{environment@formula}},
9937 depends on macro/.style={context/.append/.expanded={%
9938 \expandafter\detokenize\expandafter{#1}}},
9939 }
9940 \def\forest@file@copy#1#2{%
9941 \IfFileExists{#1}{%
9942 \pgfkeysgetvalue{/forest/external/copy command}\forest@copy@command
9943 \ifdefempty\forest@copy@command{%
9944 \forest@file@copy@{#1}{#2}%
9945 }{ % copy by external command
9946 \def\source{#1}%
9947 \def\target{#2}%
9948 \immediate\write18{\forest@copy@command}%
9949 }%
9950 }{}%
9951 }
9952 \newread\forest@copy@in
9953 \newwrite\forest@copy@out
9954 \def\forest@file@copy@#1#2{%
9955 \begingroup
9956 \openin\forest@copy@in=#1
9957 \immediate\openout\forest@copy@out#2
9958 \endlinechar-1
9959 \loop
9960 \unless\ifeof\forest@copy@in
9961 \readline\forest@copy@in to\forest@temp
9962 \immediate\write\forest@copy@out{\forest@temp}%
9963 \repeat
9964 \immediate\closeout\forest@copy@out
9965 \closein\forest@copy@in
9966 \endgroup
9967 }
9968 \newif\ifforest@external@optimize@
9969 \forest@external@optimize@true
9970 \ifforest@install@keys@to@tikz@path@
9971 \tikzset{
9972 fit to/.style={
9973 /forest/for nodewalk=%
9974 {TeX={\def\forest@fitto{}},#1}%
9975 {TeX={\eappto\forest@fitto{(\forestove{name})}}},
9976 fit/.expanded={\forest@fitto}
9977 },
9978 }
9979 \fi
9980 \ifforest@external@
9981 \ifdefined\tikzexternal@tikz@replacement\else
9982 \usetikzlibrary{external}%
9983 \fi
9984 \pgfkeys{%
9985 /tikz/external/failed ref warnings for={},
9986 /pgf/images/aux in dpth=false,
9987 }%
9988 \tikzifexternalizing{}{%
9989 \forest@file@copy{\jobname.aux}{\jobname.aux.copy}%
9990 }%
9991 \AtBeginDocument{%
9992 \tikzifexternalizing{%
9993 \IfFileExists{\tikzexternalrealjob.aux.copy}{%
9994 \makeatletter
9995 \input\tikzexternalrealjob.aux.copy\relax
9996 \makeatother
9997 }{}%
9998 }{%
9999 \newwrite\forest@auxout
10000 \immediate\openout\forest@auxout=\tikzexternalrealjob.for.tmp
10001 }%
10002 \IfFileExists{\tikzexternalrealjob.for}{%
10003 {%
10004 \makehashother\makeatletter
10005 \input\tikzexternalrealjob.for\relax
10006 }%
10007 }{}%
10008 }%
10009 \AtEndDocument{%
10010 \tikzifexternalizing{}{%
10011 \immediate\closeout\forest@auxout
10012 \forest@file@copy{\jobname.for.tmp}{\jobname.for}%
10013 }%
10014 }%
10015 \fi
10016 % \end{macrocode}
10017 %
10018 % \subsection{The \texttt{forest} environment}
10019 % \label{imp:forest-environment}
10020 %
10021 % There are three ways to invoke \foRest;: the environment and the starless and the starred version
10022 % of the macro. The latter creates no group.
10023 %
10024 % Most of the code in this section deals with externalization.
10025 %
10026 % \begin{macrocode}
10027 \NewDocumentEnvironment{forest}{D(){}}{%
10028 \forest@config{#1}%
10029 \Collect@Body
10030 \forest@env
10031 }{}
10032 \NewDocumentCommand{\Forest}{s D(){} m}{%
10033 \forest@config{#2}%
10034 \IfBooleanTF{#1}{\let\forest@next\forest@env}{\let\forest@next\forest@group@env}%
10035 \forest@next{#3}%
10036 }
10037 \def\forest@config#1{%
10038 \forest@defstages{stages}%
10039 \forestset{@config/.cd,#1}%
10040 }
10041 \def\forest@defstages#1{%
10042 \def\forest@stages{#1}%
10043 }
10044 \forestset{@config/.cd,
10045 %stages/.store in=\forest@stages,
10046 stages/.code={\forest@defstages{#1}},
10047 .unknown/.code={\PackageError{forest}{Unknown config option for forest environment/command.}{In Forest v2.0.0 and v2.0.1, this (parenthesized) argument accepted the definition of style stages for the current forest environment/macro. Since v2.0.2, you should write "\string\begin{forest}(stages={...})...\string\end{forest}", or "\string\Forest(stages={...}){...}" instead.}}
10048 }
10049 \def\forest@group@env#1{{\forest@env{#1}}}
10050 \newif\ifforest@externalize@tree@
10051 \newif\ifforest@was@tikzexternalwasenable
10052 \newcommand\forest@env[1]{%
10053 \let\forest@external@next\forest@begin
10054 \forest@was@tikzexternalwasenablefalse
10055 \ifdefined\tikzexternal@tikz@replacement
10056 \ifx\tikz\tikzexternal@tikz@replacement
10057 \forest@was@tikzexternalwasenabletrue
10058 \tikzexternaldisable
10059 \fi
10060 \fi
10061 \forest@externalize@tree@false
10062 \ifforest@external@
10063 \ifforest@was@tikzexternalwasenable
10064 \forest@env@
10065 \fi
10066 \fi
10067 \forest@standardnode@calibrate
10068 \forest@external@next{#1}%
10069 }
10070 \def\forest@env@{%
10071 \iftikzexternalexportnext
10072 \tikzifexternalizing{%
10073 \let\forest@external@next\forest@begin@externalizing
10074 }{%
10075 \let\forest@external@next\forest@begin@externalize
10076 }%
10077 \else
10078 \tikzexternalexportnexttrue
10079 \fi
10080 }
10081 % \end{macrocode}
10082 % We're externalizing, i.e.\ this code gets executed in the embedded call.
10083 % \begin{macrocode}
10084 \long\def\forest@begin@externalizing#1{%
10085 \forest@external@setup{#1}%
10086 \let\forest@external@next\forest@begin
10087 \forest@externalize@inner@n=-1
10088 \ifforest@external@optimize@\forest@externalizing@maybeoptimize\fi
10089 \forest@external@next{#1}%
10090 \tikzexternalenable
10091 }
10092 \def\forest@externalizing@maybeoptimize{%
10093 \edef\forest@temp{\tikzexternalrealjob-forest-\forest@externalize@outer@n}%
10094 \edef\forest@marshal{%
10095 \noexpand\pgfutil@in@
10096 {\expandafter\detokenize\expandafter{\forest@temp}.}
10097 {\expandafter\detokenize\expandafter{\pgfactualjobname}.}%
10098 }\forest@marshal
10099 \ifpgfutil@in@
10100 \else
10101 \let\forest@external@next\@gobble
10102 \fi
10103 }
10104 % \end{macrocode}
10105 % Externalization is enabled, we're in the outer process, deciding if the picture is up-to-date.
10106 % \begin{macrocode}
10107 \long\def\forest@begin@externalize#1{%
10108 \forest@external@setup{#1}%
10109 \iftikzexternal@file@isuptodate
10110 \setbox0=\hbox{%
10111 \csname forest@externalcheck@\forest@externalize@outer@n\endcsname
10112 }%
10113 \fi
10114 \iftikzexternal@file@isuptodate
10115 \csname forest@externalload@\forest@externalize@outer@n\endcsname
10116 \else
10117 \forest@externalize@tree@true
10118 \forest@externalize@inner@n=-1
10119 \forest@begin{#1}%
10120 \ifcsdef{forest@externalize@@\forest@externalize@id}{}{%
10121 \immediate\write\forest@auxout{%
10122 \noexpand\forest@external
10123 {\forest@externalize@outer@n}%
10124 {\expandafter\detokenize\expandafter{\forest@externalize@id}}%
10125 {\expandonce\forest@externalize@checkimages}%
10126 {\expandonce\forest@externalize@loadimages}%
10127 }%
10128 }%
10129 \fi
10130 \tikzexternalenable
10131 }
10132 \def\forest@includeexternal@check#1{%
10133 \tikzsetnextfilename{#1}%
10134 \IfFileExists{\tikzexternal@filenameprefix/#1}{\tikzexternal@file@isuptodatetrue}{\tikzexternal@file@isuptodatefalse}%
10135 }
10136 \def\makehashother{\catcode`\#=12}%
10137 \long\def\forest@external@setup#1{%
10138 % set up \forest@externalize@id and \forest@externalize@outer@n
10139 % we need to deal with #s correctly (\write doubles them)
10140 \setbox0=\hbox{\makehashother\makeatletter
10141 \scantokens{\forest@temp@toks{#1}}\expandafter
10142 }%
10143 \expandafter\forest@temp@toks\expandafter{\the\forest@temp@toks}%
10144 \edef\forest@temp{\pgfkeysvalueof{/forest/external/context}}%
10145 \edef\forest@externalize@id{%
10146 \expandafter\detokenize\expandafter{\forest@temp}%
10147 @@%
10148 \expandafter\detokenize\expandafter{\the\forest@temp@toks}%
10149 }%
10150 \letcs\forest@externalize@outer@n{forest@externalize@@\forest@externalize@id}%
10151 \ifdefined\forest@externalize@outer@n
10152 \global\tikzexternal@file@isuptodatetrue
10153 \else
10154 \global\advance\forest@externalize@max@outer@n 1
10155 \edef\forest@externalize@outer@n{\the\forest@externalize@max@outer@n}%
10156 \global\tikzexternal@file@isuptodatefalse
10157 \fi
10158 \def\forest@externalize@loadimages{}%
10159 \def\forest@externalize@checkimages{}%
10160 }
10161 \newcount\forest@externalize@max@outer@n
10162 \global\forest@externalize@max@outer@n=0
10163 \newcount\forest@externalize@inner@n
10164 % \end{macrocode}
10165 % The \texttt{.for} file is a string of calls of this macro.
10166 % \begin{macrocode}
10167 \long\def\forest@external#1#2#3#4{% #1=n,#2=context+source code,#3=update check code, #4=load code
10168 \ifnum\forest@externalize@max@outer@n<#1
10169 \global\forest@externalize@max@outer@n=#1
10170 \fi
10171 \global\csdef{forest@externalize@@\detokenize{#2}}{#1}%
10172 \global\csdef{forest@externalcheck@#1}{#3}%
10173 \global\csdef{forest@externalload@#1}{#4}%
10174 \tikzifexternalizing{}{%
10175 \immediate\write\forest@auxout{%
10176 \noexpand\forest@external{#1}%
10177 {\expandafter\detokenize\expandafter{#2}}%
10178 {\unexpanded{#3}}%
10179 {\unexpanded{#4}}%
10180 }%
10181 }%
10182 }
10183 % \end{macrocode}
10184 % These two macros include the external picture.
10185 % \begin{macrocode}
10186 \def\forest@includeexternal#1{%
10187 \edef\forest@temp{\pgfkeysvalueof{/forest/external/context}}%
10188 %\typeout{forest: Including external picture '#1' for forest context+code: '\expandafter\detokenize\expandafter{\forest@externalize@id}'}%
10189 {%
10190 %\def\pgf@declaredraftimage##1##2{\def\pgf@image{\hbox{}}}%
10191 \tikzsetnextfilename{#1}%
10192 \tikzexternalenable
10193 \tikz{}%
10194 }%
10195 }
10196 \def\forest@includeexternal@box#1#2{%
10197 \global\setbox#1=\hbox{\forest@includeexternal{#2}}%
10198 }
10199 % \end{macrocode}
10200 % This code runs the bracket parser and stage processing.
10201 % \begin{macrocode}
10202 \long\def\forest@begin#1{%
10203 \iffalse{\fi\forest@parsebracket#1}%
10204 }
10205 \def\forest@parsebracket{%
10206 \bracketParse{\forest@get@root@afterthought}\forest@root=%
10207 }
10208 \def\forest@get@root@afterthought{%
10209 \expandafter\forest@get@root@afterthought@\expandafter{\iffalse}\fi
10210 }
10211 \long\def\forest@get@root@afterthought@#1{%
10212 \ifblank{#1}{}{%
10213 \forestOeappto{\forest@root}{given options}{,afterthought={\unexpanded{#1}}}%
10214 }%
10215 \forest@do
10216 }
10217 \def\forest@do{%
10218 \forest@node@Compute@numeric@ts@info{\forest@root}%
10219 \expandafter\forestset\expandafter{\forest@stages}%
10220 \ifforest@was@tikzexternalwasenable
10221 \tikzexternalenable
10222 \fi
10223 }
10224 % \end{macrocode}
10225 %
10226 % \subsection{Standard node}
10227 % \label{impl:standard-node}
10228 %
10229 % The standard node should be calibrated when entering the forest env: ^^AAAAAAAAAAAAAAAAAAAAAAAA
10230 % ^^A|\forestNodeHandle{standard node}.calibrate()|. What the calibration does is defined in a call to
10231 % ^^A|\forestStandardNode|.
10232 % The standard node init does \emph{not} initialize options from a(nother) standard node!
10233 % \begin{macrocode}
10234 \def\forest@standardnode@new{%
10235 \advance\forest@node@maxid1
10236 \forest@fornode{\the\forest@node@maxid}{%
10237 \forest@node@init
10238 \forestoeset{id}{\forest@cn}%
10239 \forest@node@setname@silent{standard node}%
10240 }%
10241 }
10242 \def\forest@standardnode@calibrate{%
10243 \forest@fornode{\forest@node@Nametoid{standard node}}{%
10244 \edef\forest@environment{\forestove{environment@formula}}%
10245 \forestoget{previous@environment}\forest@previous@environment
10246 \ifx\forest@environment\forest@previous@environment\else
10247 \forestolet{previous@environment}\forest@environment
10248 \forest@node@typeset
10249 \forestoget{calibration@procedure}\forest@temp
10250 \expandafter\forestset\expandafter{\forest@temp}%
10251 \fi
10252 }%
10253 }
10254 % \end{macrocode}
10255 % Usage: |\forestStandardNode[#1]{#2}{#3}{#4}|. |#1| = standard node specification --- specify it
10256 % as any other node content (but without children, of course). |#2| = the environment fingerprint:
10257 % list the values of parameters that influence the standard node's height and depth; the standard
10258 % will be adjusted whenever any of these parameters changes. |#3| = the calibration procedure: a
10259 % list of usual forest options which should calculating the values of exported options. |#4| = a
10260 % comma-separated list of exported options: every newly created node receives the initial values of
10261 % exported options from the standard node. (The standard node definition is local to the \TeX\
10262 % group.)
10263 % \begin{macrocode}
10264 \def\forestStandardNode[#1]#2#3#4{%
10265 \let\forest@standardnode@restoretikzexternal\relax
10266 \ifdefined\tikzexternaldisable
10267 \ifx\tikz\tikzexternal@tikz@replacement
10268 \tikzexternaldisable
10269 \let\forest@standardnode@restoretikzexternal\tikzexternalenable
10270 \fi
10271 \fi
10272 \forest@standardnode@new
10273 \forest@fornode{\forest@node@Nametoid{standard node}}{%
10274 \forestset{content=#1}%
10275 \forestoset{environment@formula}{#2}%
10276 \edef\forest@temp{\unexpanded{#3}}%
10277 \forestolet{calibration@procedure}\forest@temp
10278 \def\forest@calibration@initializing@code{}%
10279 \pgfqkeys{/forest/initializing@code}{#4}%
10280 \forestolet{initializing@code}\forest@calibration@initializing@code
10281 \forest@standardnode@restoretikzexternal
10282 }
10283 }
10284 \forestset{initializing@code/.unknown/.code={%
10285 \eappto\forest@calibration@initializing@code{%
10286 \noexpand\forestOget{\forest@node@Nametoid{standard node}}{\pgfkeyscurrentname}\noexpand\forest@temp
10287 \noexpand\forestolet{\pgfkeyscurrentname}\noexpand\forest@temp
10288 }%
10289 }
10290 }
10291 % \end{macrocode}
10292 % This macro is called from a new (non-standard) node's init.
10293 % \begin{macrocode}
10294 \def\forest@initializefromstandardnode{%
10295 \forestOve{\forest@node@Nametoid{standard node}}{initializing@code}%
10296 }
10297 % \end{macrocode}
10298 % Define the default standard node. Standard content: dj --- in Computer Modern font, d is the
10299 % highest and j the deepest letter (not character!). Environment fingerprint: the height of the
10300 % strut and the values of inner and outer seps. Calibration procedure: (i) \keyname{l sep}
10301 % equals the height of the strut plus the value of \keyname{inner ysep}, implementing both font-size and
10302 % inner sep dependency; (ii) The effect of \keyname{l} on the standard node should be the same as the
10303 % effect of \keyname{l sep}, thus, we derive \keyname{l} from \keyname{l sep} by adding
10304 % to the latter the total height of the standard node (plus the double outer sep, one for the parent
10305 % and one for the child). (iii) s sep is straightforward: a double inner xsep. Exported options:
10306 % options, calculated in the calibration. (Tricks: to change the default anchor, set it in |#1| and
10307 % export it; to set a non-forest node option (such as \keyname{draw} or \keyname{blue}) as default, set it
10308 % in |#1| and export the (internal) option \keyname{node options}.)
10309 % \begin{macrocode}
10310 \forestStandardNode[dj]
10311 {%
10312 \forestOve{\forest@node@Nametoid{standard node}}{content},%
10313 \the\ht\strutbox,\the\pgflinewidth,%
10314 \pgfkeysvalueof{/pgf/inner ysep},\pgfkeysvalueof{/pgf/outer ysep},%
10315 \pgfkeysvalueof{/pgf/inner xsep},\pgfkeysvalueof{/pgf/outer xsep}%
10316 }
10317 {
10318 l sep'/.expanded={\the\dimexpr\the\ht\strutbox+\pgfkeysvalueof{/pgf/inner ysep}},
10319 l={l_sep()+abs(max_y()-min_y())+2*\pgfkeysvalueof{/pgf/outer ysep}},
10320 s sep'/.expanded={\the\dimexpr \pgfkeysvalueof{/pgf/inner xsep}*2}
10321 }
10322 {l sep,l,s sep}
10323 % \end{macrocode}
10324 %
10325 %
10326 % \subsection{\texttt{ls} coordinate system}
10327 % \label{imp:ls-coordinates}
10328 %
10329 % \begin{macrocode}
10330 \pgfqkeys{/forest/@cs}{%
10331 name/.code={%
10332 \edef\forest@cn{\forest@node@Nametoid{#1}}%
10333 \forest@forestcs@resetxy},
10334 id/.code={%
10335 \edef\forest@cn{#1}%
10336 \forest@forestcs@resetxy},
10337 go/.code={%
10338 \forest@go{#1}%
10339 \forest@forestcs@resetxy},
10340 anchor/.code={\forest@forestcs@anchor{#1}},
10341 l/.code={%
10342 \forestmathsetlengthmacro\forest@forestcs@l{#1}%
10343 \forest@forestcs@ls
10344 },
10345 s/.code={%
10346 \forestmathsetlengthmacro\forest@forestcs@s{#1}%
10347 \forest@forestcs@ls
10348 },
10349 .unknown/.code={%
10350 \expandafter\pgfutil@in@\expandafter.\expandafter{\pgfkeyscurrentname}%
10351 \ifpgfutil@in@
10352 \expandafter\forest@forestcs@namegoanchor\pgfkeyscurrentname\forest@end
10353 \else
10354 \expandafter\forest@nameandgo\expandafter{\pgfkeyscurrentname}%
10355 \forest@forestcs@resetxy
10356 \fi
10357 }
10358 }
10359 \def\forest@forestcs@resetxy{%
10360 \ifnum\forest@cn=0 \forest@cs@invalidnodeerror\fi
10361 \global\pgf@x\forestove{x}\relax
10362 \global\pgf@y\forestove{y}\relax
10363 }
10364 \def\forest@forestcs@ls{%
10365 \ifdefined\forest@forestcs@l
10366 \ifdefined\forest@forestcs@s
10367 {%
10368 \pgftransformreset
10369 \forest@pgfqtransformrotate{\forestove{grow}}%
10370 \pgfpointtransformed{\pgfqpoint{\forest@forestcs@l}{\forest@forestcs@s}}%
10371 }%
10372 \global\advance\pgf@x\forestove{x}%
10373 \global\advance\pgf@y\forestove{y}%
10374 \fi
10375 \fi
10376 }
10377 \def\forest@forestcs@anchor#1{%
10378 \edef\forest@marshal{%
10379 \noexpand\forest@original@tikz@parse@node\relax
10380 (\forestove{name}\ifx\relax#1\relax\else.\fi#1)%
10381 }\forest@marshal
10382 }
10383 \def\forest@forestcs@namegoanchor#1.#2\forest@end{%
10384 \forest@nameandgo{#1}%
10385 \ifnum\forest@cn=0 \forest@cs@invalidnodeerror\fi
10386 \forest@forestcs@anchor{#2}%
10387 }
10388 \def\forest@cs@invalidnodeerror{%
10389 \PackageError{forest}{Attempt to refer to the invalid node by "forest cs"}{}%
10390 }
10391 \tikzdeclarecoordinatesystem{forest}{%
10392 \forest@forthis{%
10393 \forest@forestcs@resetxy
10394 \ifdefined\forest@forestcs@l\undef\forest@forestcs@l\fi
10395 \ifdefined\forest@forestcs@s\undef\forest@forestcs@s\fi
10396 \pgfqkeys{/forest/@cs}{#1}%
10397 }%
10398 }
10399 % \end{macrocode}
10400 %
10401 % \subsection{Relative node names in \TikZ;}
10402 % \label{sec:relative-node-names}
10403 %
10404 % A hack into \TikZ;'s coordinate parser: implements relative node names!
10405 % \begin{macrocode}
10406 \def\forest@tikz@parse@node#1(#2){%
10407 \pgfutil@in@.{#2}%
10408 \ifpgfutil@in@
10409 \expandafter\forest@tikz@parse@node@checkiftikzname@withdot
10410 \else%
10411 \expandafter\forest@tikz@parse@node@checkiftikzname@withoutdot
10412 \fi%
10413 #1(#2)\forest@end
10414 }
10415 \def\forest@tikz@parse@node@checkiftikzname@withdot#1(#2.#3)\forest@end{%
10416 \forest@tikz@parse@node@checkiftikzname#1{#2}{.#3}}
10417 \def\forest@tikz@parse@node@checkiftikzname@withoutdot#1(#2)\forest@end{%
10418 \forest@tikz@parse@node@checkiftikzname#1{#2}{}}
10419 \def\forest@tikz@parse@node@checkiftikzname#1#2#3{%
10420 \expandafter\ifx\csname pgf@sh@ns@#2\endcsname\relax
10421 \forest@forthis{%
10422 \forest@nameandgo{#2}%
10423 \ifnum\forest@cn=0 \forest@cs@invalidnodeerror\fi
10424 \edef\forest@temp@relativenodename{\forestove{name}}%
10425 }%
10426 \else
10427 \def\forest@temp@relativenodename{#2}%
10428 \fi
10429 \expandafter\forest@original@tikz@parse@node\expandafter#1\expandafter(\forest@temp@relativenodename#3)%
10430 }
10431 \def\forest@nameandgo#1{%
10432 \pgfutil@in@!{#1}%
10433 \ifpgfutil@in@
10434 \forest@nameandgo@(#1)%
10435 \else
10436 \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
10437 \fi
10438 }
10439 \def\forest@nameandgo@(#1!#2){%
10440 \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
10441 \forest@go{#2}%
10442 }
10443 % \end{macrocode}
10444 %
10445 % \subsection{Anchors}
10446 % \label{sec:anchors}
10447 %
10448 % \FoRest; anchors are |(child/parent)_anchor| and growth anchors |parent/children_first/last|. The following code resolves them into \TikZ; anchors, based on the value of option |(child/parent)_anchor| and values of |grow| and |reversed|.
10449 %
10450 % We need to access |rotate| for the anchors below to work in general.
10451 % \begin{macrocode}
10452 \forestset{
10453 declare count={rotate}{0},
10454 autoforward'={rotate}{node options},
10455 }
10456 % \end{macrocode}
10457 % Variants of |parent/children_first/last| without |'| snap border anchors to the closest compass direction.
10458 % \begin{macrocode}
10459 \newif\ifforest@anchor@snapbordertocompass
10460 % \end{macrocode}
10461 % The code is used both in generic anchors (then, the result should be forwarded to \TikZ; for evaluation into coordinates) and in the UI macro |\forestanchortotikzanchor|.
10462 % \begin{macrocode}
10463 \newif\ifforest@anchor@forwardtotikz
10464 % \end{macrocode}
10465 % Growth-based anchors set this to true to signal that the result is a border anchor.
10466 % \begin{macrocode}
10467 \newif\ifforest@anchor@isborder
10468 % \end{macrocode}
10469 % The UI macro.
10470 % \begin{macrocode}
10471 \def\forestanchortotikzanchor#1#2{% #1 = forest anchor, #2 = macro to receive the tikz anchor
10472 \forest@anchor@forwardtotikzfalse
10473 \forest@anchor@do{}{#1}{\forest@cn}%
10474 \let#2\forest@temp@anchor
10475 }
10476 % \end{macrocode}
10477 % Generic anchors.
10478 % \begin{macrocode}
10479 \pgfdeclaregenericanchor{child anchor}{%
10480 \forest@anchor@forwardtotikztrue
10481 \forest@anchor@do{#1}{child anchor}{\forest@referencednodeid}%
10482 }
10483 \pgfdeclaregenericanchor{parent anchor}{%
10484 \forest@anchor@forwardtotikztrue
10485 \forest@anchor@do{#1}{parent anchor}{\forest@referencednodeid}%
10486 }
10487 \pgfdeclaregenericanchor{anchor}{%
10488 \forest@anchor@forwardtotikztrue
10489 \forest@anchor@do{#1}{anchor}{\forest@referencednodeid}%
10490 }
10491 \pgfdeclaregenericanchor{children}{%
10492 \forest@anchor@forwardtotikztrue
10493 \forest@anchor@do{#1}{children}{\forest@referencednodeid}%
10494 }
10495 \pgfdeclaregenericanchor{-children}{%
10496 \forest@anchor@forwardtotikztrue
10497 \forest@anchor@do{#1}{-children}{\forest@referencednodeid}%
10498 }
10499 \pgfdeclaregenericanchor{children first}{%
10500 \forest@anchor@forwardtotikztrue
10501 \forest@anchor@do{#1}{children first}{\forest@referencednodeid}%
10502 }
10503 \pgfdeclaregenericanchor{-children first}{%
10504 \forest@anchor@forwardtotikztrue
10505 \forest@anchor@do{#1}{-children first}{\forest@referencednodeid}%
10506 }
10507 \pgfdeclaregenericanchor{first}{%
10508 \forest@anchor@forwardtotikztrue
10509 \forest@anchor@do{#1}{first}{\forest@referencednodeid}%
10510 }
10511 \pgfdeclaregenericanchor{parent first}{%
10512 \forest@anchor@forwardtotikztrue
10513 \forest@anchor@do{#1}{parent first}{\forest@referencednodeid}%
10514 }
10515 \pgfdeclaregenericanchor{-parent first}{%
10516 \forest@anchor@forwardtotikztrue
10517 \forest@anchor@do{#1}{-parent first}{\forest@referencednodeid}%
10518 }
10519 \pgfdeclaregenericanchor{parent}{%
10520 \forest@anchor@forwardtotikztrue
10521 \forest@anchor@do{#1}{parent}{\forest@referencednodeid}%
10522 }
10523 \pgfdeclaregenericanchor{-parent}{%
10524 \forest@anchor@forwardtotikztrue
10525 \forest@anchor@do{#1}{-parent}{\forest@referencednodeid}%
10526 }
10527 \pgfdeclaregenericanchor{parent last}{%
10528 \forest@anchor@forwardtotikztrue
10529 \forest@anchor@do{#1}{parent last}{\forest@referencednodeid}%
10530 }
10531 \pgfdeclaregenericanchor{-parent last}{%
10532 \forest@anchor@forwardtotikztrue
10533 \forest@anchor@do{#1}{-parent last}{\forest@referencednodeid}%
10534 }
10535 \pgfdeclaregenericanchor{last}{%
10536 \forest@anchor@forwardtotikztrue
10537 \forest@anchor@do{#1}{last}{\forest@referencednodeid}%
10538 }
10539 \pgfdeclaregenericanchor{children last}{%
10540 \forest@anchor@forwardtotikztrue
10541 \forest@anchor@do{#1}{children last}{\forest@referencednodeid}%
10542 }
10543 \pgfdeclaregenericanchor{-children last}{%
10544 \forest@anchor@forwardtotikztrue
10545 \forest@anchor@do{#1}{-children last}{\forest@referencednodeid}%
10546 }
10547 \pgfdeclaregenericanchor{children'}{%
10548 \forest@anchor@forwardtotikztrue
10549 \forest@anchor@do{#1}{children'}{\forest@referencednodeid}%
10550 }
10551 \pgfdeclaregenericanchor{-children'}{%
10552 \forest@anchor@forwardtotikztrue
10553 \forest@anchor@do{#1}{-children'}{\forest@referencednodeid}%
10554 }
10555 \pgfdeclaregenericanchor{children first'}{%
10556 \forest@anchor@forwardtotikztrue
10557 \forest@anchor@do{#1}{children first'}{\forest@referencednodeid}%
10558 }
10559 \pgfdeclaregenericanchor{-children first'}{%
10560 \forest@anchor@forwardtotikztrue
10561 \forest@anchor@do{#1}{-children first'}{\forest@referencednodeid}%
10562 }
10563 \pgfdeclaregenericanchor{first'}{%
10564 \forest@anchor@forwardtotikztrue
10565 \forest@anchor@do{#1}{first'}{\forest@referencednodeid}%
10566 }
10567 \pgfdeclaregenericanchor{parent first'}{%
10568 \forest@anchor@forwardtotikztrue
10569 \forest@anchor@do{#1}{parent first'}{\forest@referencednodeid}%
10570 }
10571 \pgfdeclaregenericanchor{-parent first'}{%
10572 \forest@anchor@forwardtotikztrue
10573 \forest@anchor@do{#1}{-parent first'}{\forest@referencednodeid}%
10574 }
10575 \pgfdeclaregenericanchor{parent'}{%
10576 \forest@anchor@forwardtotikztrue
10577 \forest@anchor@do{#1}{parent'}{\forest@referencednodeid}%
10578 }
10579 \pgfdeclaregenericanchor{-parent'}{%
10580 \forest@anchor@forwardtotikztrue
10581 \forest@anchor@do{#1}{-parent'}{\forest@referencednodeid}%
10582 }
10583 \pgfdeclaregenericanchor{parent last'}{%
10584 \forest@anchor@forwardtotikztrue
10585 \forest@anchor@do{#1}{parent last'}{\forest@referencednodeid}%
10586 }
10587 \pgfdeclaregenericanchor{-parent last'}{%
10588 \forest@anchor@forwardtotikztrue
10589 \forest@anchor@do{#1}{-parent last'}{\forest@referencednodeid}%
10590 }
10591 \pgfdeclaregenericanchor{last'}{%
10592 \forest@anchor@forwardtotikztrue
10593 \forest@anchor@do{#1}{last'}{\forest@referencednodeid}%
10594 }
10595 \pgfdeclaregenericanchor{children last'}{%
10596 \forest@anchor@forwardtotikztrue
10597 \forest@anchor@do{#1}{children last'}{\forest@referencednodeid}%
10598 }
10599 \pgfdeclaregenericanchor{-children last'}{%
10600 \forest@anchor@forwardtotikztrue
10601 \forest@anchor@do{#1}{-children last'}{\forest@referencednodeid}%
10602 }
10603 % \end{macrocode}
10604 % The driver. The result is being passed around in |\forest@temp@anchor|.
10605 % \begin{macrocode}
10606 \def\forest@anchor@do#1#2#3{% #1 = shape name, #2 = (potentially) forest anchor, #3 = node id
10607 \forest@fornode{#3}{%
10608 \def\forest@temp@anchor{#2}%
10609 \forest@anchor@snapbordertocompassfalse
10610 \forest@anchor@isborderfalse
10611 \forest@anchor@to@tikz@anchor
10612 \forest@anchor@border@to@compass
10613 \ifforest@anchor@forwardtotikz
10614 \forest@anchor@forward{#1}%
10615 \else
10616 \fi
10617 }%
10618 }
10619 % \end{macrocode}
10620 % This macro will loop (resolving the anchor) until the result is not a \FoRest; macro.
10621 % \begin{macrocode}
10622 \def\forest@anchor@to@tikz@anchor{%
10623 \ifcsdef{forest@anchor@@\forest@temp@anchor}{%
10624 \csuse{forest@anchor@@\forest@temp@anchor}%
10625 \forest@anchor@to@tikz@anchor
10626 }{}%
10627 }
10628 % \end{macrocode}
10629 % Actual computation.
10630 % \begin{macrocode}
10631 \csdef{forest@anchor@@parent anchor}{%
10632 \forestoget{parent anchor}\forest@temp@anchor}
10633 \csdef{forest@anchor@@child anchor}{%
10634 \forestoget{child anchor}\forest@temp@anchor}
10635 \csdef{forest@anchor@@anchor}{%
10636 \forestoget{anchor}\forest@temp@anchor}
10637 \csdef{forest@anchor@@children'}{%
10638 \forest@anchor@isbordertrue
10639 \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}}%
10640 }
10641 \csdef{forest@anchor@@-children'}{%
10642 \forest@anchor@isbordertrue
10643 \edef\forest@temp@anchor{\number\numexpr 180+\forestove{grow}-\forestove{rotate}}%
10644 }
10645 \csdef{forest@anchor@@parent'}{%
10646 \forest@anchor@isbordertrue
10647 \edef\forest@temp@grow{\ifnum\forestove{@parent}=0 \forestove{grow}\else\forestOve{\forestove{@parent}}{grow}\fi}%
10648 \edef\forest@temp@anchor{\number\numexpr\forest@temp@grow-\forestove{rotate}+180}%
10649 }
10650 \csdef{forest@anchor@@-parent'}{%
10651 \forest@anchor@isbordertrue
10652 \edef\forest@temp@grow{\ifnum\forestove{@parent}=0 \forestove{grow}\else\forestOve{\forestove{@parent}}{grow}\fi}%
10653 \edef\forest@temp@anchor{\number\numexpr\forest@temp@grow-\forestove{rotate}}%
10654 }
10655 \csdef{forest@anchor@@first'}{%
10656 \forest@anchor@isbordertrue
10657 \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 -\else+\fi90}%
10658 }
10659 \csdef{forest@anchor@@last'}{%
10660 \forest@anchor@isbordertrue
10661 \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 +\else-\fi90}%
10662 }
10663 \csdef{forest@anchor@@parent first'}{%
10664 \forest@anchor@isbordertrue
10665 \edef\forest@temp@grow{\ifnum\forestove{@parent}=0 \forestove{grow}\else\forestOve{\forestove{@parent}}{grow}\fi}%
10666 \edef\forest@temp@reversed{\ifnum\forestove{@parent}=0 \forestove{reversed}\else\forestOve{\forestove{@parent}}{reversed}\fi}%
10667 \edef\forest@temp@anchor@parent{\number\numexpr\forest@temp@grow-\forestove{rotate}+180}%
10668 \edef\forest@temp@anchor@first{\number\numexpr\forest@temp@grow-\forestove{rotate}\ifnum\forest@temp@reversed=0 -\else+\fi90}%
10669 \forest@getaverageangle{\forest@temp@anchor@parent}{\forest@temp@anchor@first}\forest@temp@anchor
10670 }
10671 \csdef{forest@anchor@@-parent first'}{%
10672 \forest@anchor@isbordertrue
10673 \edef\forest@temp@grow{\ifnum\forestove{@parent}=0 \forestove{grow}\else\forestOve{\forestove{@parent}}{grow}\fi}%
10674 \edef\forest@temp@reversed{\ifnum\forestove{@parent}=0 \forestove{reversed}\else\forestOve{\forestove{@parent}}{reversed}\fi}%
10675 \edef\forest@temp@anchor@parent{\number\numexpr\forest@temp@grow-\forestove{rotate}}%
10676 \edef\forest@temp@anchor@first{\number\numexpr\forest@temp@grow-\forestove{rotate}\ifnum\forest@temp@reversed=0 -\else+\fi90}%
10677 \forest@getaverageangle{\forest@temp@anchor@parent}{\forest@temp@anchor@first}\forest@temp@anchor
10678 }
10679 \csdef{forest@anchor@@parent last'}{%
10680 \forest@anchor@isbordertrue
10681 \edef\forest@temp@grow{\ifnum\forestove{@parent}=0 \forestove{grow}\else\forestOve{\forestove{@parent}}{grow}\fi}%
10682 \edef\forest@temp@reversed{\ifnum\forestove{@parent}=0 \forestove{reversed}\else\forestOve{\forestove{@parent}}{reversed}\fi}%
10683 \edef\forest@temp@anchor@parent{\number\numexpr\forest@temp@grow-\forestove{rotate}+180}%
10684 \edef\forest@temp@anchor@last{\number\numexpr\forest@temp@grow-\forestove{rotate}\ifnum\forest@temp@reversed=0 +\else-\fi90}%
10685 \forest@getaverageangle{\forest@temp@anchor@parent}{\forest@temp@anchor@last}\forest@temp@anchor
10686 }
10687 \csdef{forest@anchor@@-parent last'}{%
10688 \forest@anchor@isbordertrue
10689 \edef\forest@temp@grow{\ifnum\forestove{@parent}=0 \forestove{grow}\else\forestOve{\forestove{@parent}}{grow}\fi}%
10690 \edef\forest@temp@reversed{\ifnum\forestove{@parent}=0 \forestove{reversed}\else\forestOve{\forestove{@parent}}{reversed}\fi}%
10691 \edef\forest@temp@anchor@parent{\number\numexpr\forest@temp@grow-\forestove{rotate}}%
10692 \edef\forest@temp@anchor@last{\number\numexpr\forest@temp@grow-\forestove{rotate}\ifnum\forest@temp@reversed=0 +\else-\fi90}%
10693 \forest@getaverageangle{\forest@temp@anchor@parent}{\forest@temp@anchor@last}\forest@temp@anchor
10694 }
10695 \csdef{forest@anchor@@children first'}{%
10696 \forest@anchor@isbordertrue
10697 \edef\forest@temp@anchor@first{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 -\else+\fi90}%
10698 \forest@getaverageangle{\forestove{grow}-\forestove{rotate}}{\forest@temp@anchor@first}\forest@temp@anchor
10699 }
10700 \csdef{forest@anchor@@-children first'}{%
10701 \forest@anchor@isbordertrue
10702 \edef\forest@temp@anchor@first{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 -\else+\fi90}%
10703 \forest@getaverageangle{180+\forestove{grow}-\forestove{rotate}}{\forest@temp@anchor@first}\forest@temp@anchor
10704 }
10705 \csdef{forest@anchor@@children last'}{%
10706 \forest@anchor@isbordertrue
10707 \edef\forest@temp@anchor@last{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 +\else-\fi90}%
10708 \forest@getaverageangle{\forestove{grow}-\forestove{rotate}}{\forest@temp@anchor@last}\forest@temp@anchor
10709 }
10710 \csdef{forest@anchor@@-children last'}{%
10711 \forest@anchor@isbordertrue
10712 \edef\forest@temp@anchor@last{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 +\else-\fi90}%
10713 \forest@getaverageangle{180+\forestove{grow}-\forestove{rotate}}{\forest@temp@anchor@last}\forest@temp@anchor
10714 }
10715 \csdef{forest@anchor@@children}{%
10716 \forest@anchor@snapbordertocompasstrue
10717 \csuse{forest@anchor@@children'}%
10718 }
10719 \csdef{forest@anchor@@-children}{%
10720 \forest@anchor@snapbordertocompasstrue
10721 \csuse{forest@anchor@@-children'}%
10722 }
10723 \csdef{forest@anchor@@parent}{%
10724 \forest@anchor@snapbordertocompasstrue
10725 \csuse{forest@anchor@@parent'}%
10726 }
10727 \csdef{forest@anchor@@-parent}{%
10728 \forest@anchor@snapbordertocompasstrue
10729 \csuse{forest@anchor@@-parent'}%
10730 }
10731 \csdef{forest@anchor@@first}{%
10732 \forest@anchor@snapbordertocompasstrue
10733 \csuse{forest@anchor@@first'}%
10734 }
10735 \csdef{forest@anchor@@last}{%
10736 \forest@anchor@snapbordertocompasstrue
10737 \csuse{forest@anchor@@last'}%
10738 }
10739 \csdef{forest@anchor@@parent first}{%
10740 \forest@anchor@snapbordertocompasstrue
10741 \csuse{forest@anchor@@parent first'}%
10742 }
10743 \csdef{forest@anchor@@-parent first}{%
10744 \forest@anchor@snapbordertocompasstrue
10745 \csuse{forest@anchor@@-parent first'}%
10746 }
10747 \csdef{forest@anchor@@parent last}{%
10748 \forest@anchor@snapbordertocompasstrue
10749 \csuse{forest@anchor@@parent last'}%
10750 }
10751 \csdef{forest@anchor@@-parent last}{%
10752 \forest@anchor@snapbordertocompasstrue
10753 \csuse{forest@anchor@@-parent last'}%
10754 }
10755 \csdef{forest@anchor@@children first}{%
10756 \forest@anchor@snapbordertocompasstrue
10757 \csuse{forest@anchor@@children first'}%
10758 }
10759 \csdef{forest@anchor@@-children first}{%
10760 \forest@anchor@snapbordertocompasstrue
10761 \csuse{forest@anchor@@-children first'}%
10762 }
10763 \csdef{forest@anchor@@children last}{%
10764 \forest@anchor@snapbordertocompasstrue
10765 \csuse{forest@anchor@@children last'}%
10766 }
10767 \csdef{forest@anchor@@-children last}{%
10768 \forest@anchor@snapbordertocompasstrue
10769 \csuse{forest@anchor@@-children last'}%
10770 }
10771 % \end{macrocode}
10772 % This macro computes the "average" angle of |#1| and |#2| and stores in into |#3|.
10773 % The angle computed is the geometrically "closer" one. The formula is
10774 % adapted from \url{http://stackoverflow.com/a/1159336/624872}.
10775 % \begin{macrocode}
10776 \def\forest@getaverageangle#1#2#3{%
10777 \edef\forest@temp{\number\numexpr #1-#2+540}%
10778 \expandafter\pgfmathMod@\expandafter{\forest@temp}{360}%
10779 \forest@truncatepgfmathresult
10780 \edef\forest@temp{\number\numexpr 360+#2+((\pgfmathresult-180)/2)}%
10781 \expandafter\pgfmathMod@\expandafter{\forest@temp}{360}%
10782 \forest@truncatepgfmathresult
10783 \let#3\pgfmathresult
10784 }
10785 \def\forest@truncatepgfmathresult{%
10786 \afterassignment\forest@gobbletoEND
10787 \forest@temp@count=\pgfmathresult\forest@END
10788 \def\pgfmathresult{\the\forest@temp@count}%
10789 }
10790 \def\forest@gobbletoEND#1\forest@END{}
10791 % \end{macrocode}
10792 % The first macro changes border anchor to compass anchor. The second one does this only if the node shape allows it.
10793 % \begin{macrocode}
10794 \def\forest@anchor@border@to@compass{%
10795 \ifforest@anchor@isborder % snap to 45 deg, to range 0-360
10796 \ifforest@anchor@snapbordertocompass
10797 \forest@anchor@snap@border@to@compass
10798 \else % to range 0-360
10799 \pgfmathMod@{\forest@temp@anchor}{360}%
10800 \forest@truncatepgfmathresult
10801 \let\forest@temp@anchor\pgfmathresult
10802 \fi
10803 \ifforest@anchor@snapbordertocompass
10804 \ifforest@anchor@forwardtotikz
10805 \ifcsname pgf@anchor%
10806 @\csname pgf@sh@ns@\pgfreferencednodename\endcsname
10807 @\csname forest@compass@\forest@temp@anchor\endcsname
10808 \endcsname
10809 \letcs\forest@temp@anchor{forest@compass@\forest@temp@anchor}%
10810 \fi
10811 \else
10812 \letcs\forest@temp@anchor{forest@compass@\forest@temp@anchor}%
10813 \fi
10814 \fi
10815 \fi
10816 }
10817 \csdef{forest@compass@0}{east}
10818 \csdef{forest@compass@45}{north east}
10819 \csdef{forest@compass@90}{north}
10820 \csdef{forest@compass@135}{north west}
10821 \csdef{forest@compass@180}{west}
10822 \csdef{forest@compass@225}{south west}
10823 \csdef{forest@compass@270}{south}
10824 \csdef{forest@compass@315}{south east}
10825 \csdef{forest@compass@360}{east}
10826 % \end{macrocode}
10827 % This macro approximates an angle (stored in |\forest@temp@anchor|) with a compass direction (stores it in the same macro).
10828 % \begin{macrocode}
10829 \def\forest@anchor@snap@border@to@compass{%
10830 \pgfmathMod@{\forest@temp@anchor}{360}%
10831 \pgfmathdivide@{\pgfmathresult}{45}%
10832 \pgfmathround@{\pgfmathresult}%
10833 \pgfmathmultiply@{\pgfmathresult}{45}%
10834 \forest@truncatepgfmathresult
10835 \let\forest@temp@anchor\pgfmathresult
10836 }
10837 % \end{macrocode}
10838 % This macro forwards the resulting anchor to \TikZ;.
10839 % \begin{macrocode}
10840 \def\forest@anchor@forward#1{% #1 = shape name
10841 \ifdefempty\forest@temp@anchor{%
10842 \pgf@sh@reanchor{#1}{center}%
10843 \xdef\forest@hack@tikzshapeborder{%
10844 \noexpand\tikz@shapebordertrue
10845 \def\noexpand\tikz@shapeborder@name{\pgfreferencednodename}%
10846 }\aftergroup\forest@hack@tikzshapeborder
10847 }{%
10848 \pgf@sh@reanchor{#1}{\forest@temp@anchor}%
10849 }%
10850 }
10851 % \end{macrocode}
10852 %
10853 % Expandably strip "not yet positionedPGFINTERNAL" from |\pgfreferencednodename| if it is there.
10854 % \begin{macrocode}
10855 \def\forest@referencednodeid{\forest@node@Nametoid{\forest@referencednodename}}%
10856 \def\forest@referencednodename{%
10857 \expandafter\expandafter\expandafter\forest@referencednodename@\expandafter\pgfreferencednodename\forest@pgf@notyetpositioned\relax
10858 }
10859 \expandafter\def\expandafter\forest@referencednodename@\expandafter#\expandafter1\forest@pgf@notyetpositioned#2\relax{%
10860 \if\relax#1\relax\forest@referencednodename@stripafter#2\relax\fi
10861 \if\relax#2\relax#1\fi
10862 }
10863 \expandafter\def\expandafter\forest@referencednodename@stripafter\expandafter#\expandafter1\forest@pgf@notyetpositioned\relax{#1}
10864 % \end{macrocode}
10865 %
10866 % This macro sets up |\pgf@x| and |\pgf@y| to the given anchor's coordinates, within the node's coordinate system. It works even before the node was positioned. If the anchor is empty, i.e.\ if is the implicit border anchor, we return the coordinates for the center.
10867 % \begin{macrocode}
10868 \def\forest@pointanchor#1{% #1 = anchor
10869 \forest@Pointanchor{\forest@cn}{#1}%
10870 }
10871 \def\forest@Pointanchor#1#2{% #1 = node id, #2 = anchor
10872 \def\forest@pa@temp@name{name}%
10873 \forestOifdefined{#1}{@box}{%
10874 \forestOget{#1}{@box}\forest@temp
10875 \ifdefempty\forest@temp{}{%
10876 \def\forest@pa@temp@name{later@name}%
10877 }%
10878 }{}%
10879 \setbox0\hbox{%
10880 \begin{pgfpicture}%
10881 \if\relax\forestOve{#1}{#2}\relax
10882 \pgfpointanchor{\forestOve{#1}{\forest@pa@temp@name}}{center}%
10883 \else
10884 \pgfpointanchor{\forestOve{#1}{\forest@pa@temp@name}}{\forestOve{#1}{#2}}%
10885 \fi
10886 \xdef\forest@global@marshal{%
10887 \noexpand\global\noexpand\pgf@x=\the\pgf@x\relax
10888 \noexpand\global\noexpand\pgf@y=\the\pgf@y\relax\relax
10889 }%
10890 \end{pgfpicture}%
10891 }%
10892 \forest@global@marshal
10893 }
10894 % \end{macrocode}
10895 % Fill in the values of the invalid node. (It's now easy to test for |id=0|.)
10896 % \begin{macrocode}
10897 \forest@node@init
10898 % \end{macrocode}
10899 % \section{Compatibility with previous versions}
10900 % \begin{macrocode}
10901 \ifdefempty{\forest@compat}{}{%
10902 \RequirePackage{forest-compat}
10903 }
10904 % \end{macrocode}
10905 %
10906 % \endinput
10907 %
10908 % Local Variables:
10909 % mode: doctex
10910 % fill-column: 100
10911 % TeX-command-default: "sty"
10912 % TeX-master: t
10913 % End: