summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/latex/forest/LICENCE416
-rw-r--r--Master/texmf-dist/doc/latex/forest/README7
-rw-r--r--Master/texmf-dist/doc/latex/forest/forest-doc.pdfbin0 -> 1113831 bytes
-rw-r--r--Master/texmf-dist/doc/latex/forest/forest-doc.tex5324
-rw-r--r--Master/texmf-dist/doc/latex/forest/forest.pdfbin888811 -> 430112 bytes
-rw-r--r--Master/texmf-dist/doc/latex/forest/tex.bib20
-rw-r--r--Master/texmf-dist/makeindex/forest/forest-doc.ist25
-rw-r--r--Master/texmf-dist/source/latex/forest/forest-doc.ins26
-rw-r--r--Master/texmf-dist/source/latex/forest/forest-index.dtx788
-rw-r--r--Master/texmf-dist/source/latex/forest/forest-libs.dtx516
-rw-r--r--Master/texmf-dist/source/latex/forest/forest.dtx8358
-rw-r--r--Master/texmf-dist/source/latex/forest/forest.ins11
-rw-r--r--Master/texmf-dist/tex/latex/forest/forest-compat.sty170
-rw-r--r--Master/texmf-dist/tex/latex/forest/forest-doc.sty240
-rw-r--r--Master/texmf-dist/tex/latex/forest/forest-index.sty383
-rw-r--r--Master/texmf-dist/tex/latex/forest/forest-lib-edges.sty74
-rw-r--r--Master/texmf-dist/tex/latex/forest/forest-lib-linguistics.sty133
-rw-r--r--Master/texmf-dist/tex/latex/forest/forest.sty4112
18 files changed, 14885 insertions, 5718 deletions
diff --git a/Master/texmf-dist/doc/latex/forest/LICENCE b/Master/texmf-dist/doc/latex/forest/LICENCE
new file mode 100644
index 00000000000..22443139013
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/forest/LICENCE
@@ -0,0 +1,416 @@
+The LaTeX Project Public License
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
+LPPL Version 1.3c 2008-05-04
+
+Copyright 1999 2002-2008 LaTeX3 Project
+ Everyone is allowed to distribute verbatim copies of this
+ license document, but modification of it is not allowed.
+
+
+PREAMBLE
+========
+
+The LaTeX Project Public License (LPPL) is the primary license under
+which the LaTeX kernel and the base LaTeX packages are distributed.
+
+You may use this license for any work of which you hold the copyright
+and which you wish to distribute. This license may be particularly
+suitable if your work is TeX-related (such as a LaTeX package), but
+it is written in such a way that you can use it even if your work is
+unrelated to TeX.
+
+The section `WHETHER AND HOW TO DISTRIBUTE WORKS UNDER THIS LICENSE',
+below, gives instructions, examples, and recommendations for authors
+who are considering distributing their works under this license.
+
+This license gives conditions under which a work may be distributed
+and modified, as well as conditions under which modified versions of
+that work may be distributed.
+
+We, the LaTeX3 Project, believe that the conditions below give you
+the freedom to make and distribute modified versions of your work
+that conform with whatever technical specifications you wish while
+maintaining the availability, integrity, and reliability of
+that work. If you do not see how to achieve your goal while
+meeting these conditions, then read the document `cfgguide.tex'
+and `modguide.tex' in the base LaTeX distribution for suggestions.
+
+
+DEFINITIONS
+===========
+
+In this license document the following terms are used:
+
+ `Work'
+ Any work being distributed under this License.
+
+ `Derived Work'
+ Any work that under any applicable law is derived from the Work.
+
+ `Modification'
+ Any procedure that produces a Derived Work under any applicable
+ law -- for example, the production of a file containing an
+ original file associated with the Work or a significant portion of
+ such a file, either verbatim or with modifications and/or
+ translated into another language.
+
+ `Modify'
+ To apply any procedure that produces a Derived Work under any
+ applicable law.
+
+ `Distribution'
+ Making copies of the Work available from one person to another, in
+ whole or in part. Distribution includes (but is not limited to)
+ making any electronic components of the Work accessible by
+ file transfer protocols such as FTP or HTTP or by shared file
+ systems such as Sun's Network File System (NFS).
+
+ `Compiled Work'
+ A version of the Work that has been processed into a form where it
+ is directly usable on a computer system. This processing may
+ include using installation facilities provided by the Work,
+ transformations of the Work, copying of components of the Work, or
+ other activities. Note that modification of any installation
+ facilities provided by the Work constitutes modification of the Work.
+
+ `Current Maintainer'
+ A person or persons nominated as such within the Work. If there is
+ no such explicit nomination then it is the `Copyright Holder' under
+ any applicable law.
+
+ `Base Interpreter'
+ A program or process that is normally needed for running or
+ interpreting a part or the whole of the Work.
+
+ A Base Interpreter may depend on external components but these
+ are not considered part of the Base Interpreter provided that each
+ external component clearly identifies itself whenever it is used
+ interactively. Unless explicitly specified when applying the
+ license to the Work, the only applicable Base Interpreter is a
+ `LaTeX-Format' or in the case of files belonging to the
+ `LaTeX-format' a program implementing the `TeX language'.
+
+
+
+CONDITIONS ON DISTRIBUTION AND MODIFICATION
+===========================================
+
+1. Activities other than distribution and/or modification of the Work
+are not covered by this license; they are outside its scope. In
+particular, the act of running the Work is not restricted and no
+requirements are made concerning any offers of support for the Work.
+
+2. You may distribute a complete, unmodified copy of the Work as you
+received it. Distribution of only part of the Work is considered
+modification of the Work, and no right to distribute such a Derived
+Work may be assumed under the terms of this clause.
+
+3. You may distribute a Compiled Work that has been generated from a
+complete, unmodified copy of the Work as distributed under Clause 2
+above, as long as that Compiled Work is distributed in such a way that
+the recipients may install the Compiled Work on their system exactly
+as it would have been installed if they generated a Compiled Work
+directly from the Work.
+
+4. If you are the Current Maintainer of the Work, you may, without
+restriction, modify the Work, thus creating a Derived Work. You may
+also distribute the Derived Work without restriction, including
+Compiled Works generated from the Derived Work. Derived Works
+distributed in this manner by the Current Maintainer are considered to
+be updated versions of the Work.
+
+5. If you are not the Current Maintainer of the Work, you may modify
+your copy of the Work, thus creating a Derived Work based on the Work,
+and compile this Derived Work, thus creating a Compiled Work based on
+the Derived Work.
+
+6. If you are not the Current Maintainer of the Work, you may
+distribute a Derived Work provided the following conditions are met
+for every component of the Work unless that component clearly states
+in the copyright notice that it is exempt from that condition. Only
+the Current Maintainer is allowed to add such statements of exemption
+to a component of the Work.
+
+ a. If a component of this Derived Work can be a direct replacement
+ for a component of the Work when that component is used with the
+ Base Interpreter, then, wherever this component of the Work
+ identifies itself to the user when used interactively with that
+ Base Interpreter, the replacement component of this Derived Work
+ clearly and unambiguously identifies itself as a modified version
+ of this component to the user when used interactively with that
+ Base Interpreter.
+
+ b. Every component of the Derived Work contains prominent notices
+ detailing the nature of the changes to that component, or a
+ prominent reference to another file that is distributed as part
+ of the Derived Work and that contains a complete and accurate log
+ of the changes.
+
+ c. No information in the Derived Work implies that any persons,
+ including (but not limited to) the authors of the original version
+ of the Work, provide any support, including (but not limited to)
+ the reporting and handling of errors, to recipients of the
+ Derived Work unless those persons have stated explicitly that
+ they do provide such support for the Derived Work.
+
+ d. You distribute at least one of the following with the Derived Work:
+
+ 1. A complete, unmodified copy of the Work;
+ if your distribution of a modified component is made by
+ offering access to copy the modified component from a
+ designated place, then offering equivalent access to copy
+ the Work from the same or some similar place meets this
+ condition, even though third parties are not compelled to
+ copy the Work along with the modified component;
+
+ 2. Information that is sufficient to obtain a complete,
+ unmodified copy of the Work.
+
+7. If you are not the Current Maintainer of the Work, you may
+distribute a Compiled Work generated from a Derived Work, as long as
+the Derived Work is distributed to all recipients of the Compiled
+Work, and as long as the conditions of Clause 6, above, are met with
+regard to the Derived Work.
+
+8. The conditions above are not intended to prohibit, and hence do not
+apply to, the modification, by any method, of any component so that it
+becomes identical to an updated version of that component of the Work as
+it is distributed by the Current Maintainer under Clause 4, above.
+
+9. Distribution of the Work or any Derived Work in an alternative
+format, where the Work or that Derived Work (in whole or in part) is
+then produced by applying some process to that format, does not relax or
+nullify any sections of this license as they pertain to the results of
+applying that process.
+
+10. a. A Derived Work may be distributed under a different license
+ provided that license itself honors the conditions listed in
+ Clause 6 above, in regard to the Work, though it does not have
+ to honor the rest of the conditions in this license.
+
+ b. If a Derived Work is distributed under a different license, that
+ Derived Work must provide sufficient documentation as part of
+ itself to allow each recipient of that Derived Work to honor the
+ restrictions in Clause 6 above, concerning changes from the Work.
+
+11. This license places no restrictions on works that are unrelated to
+the Work, nor does this license place any restrictions on aggregating
+such works with the Work by any means.
+
+12. Nothing in this license is intended to, or may be used to, prevent
+complete compliance by all parties with all applicable laws.
+
+
+NO WARRANTY
+===========
+
+There is no warranty for the Work. Except when otherwise stated in
+writing, the Copyright Holder provides the Work `as is', without
+warranty of any kind, either expressed or implied, including, but not
+limited to, the implied warranties of merchantability and fitness for a
+particular purpose. The entire risk as to the quality and performance
+of the Work is with you. Should the Work prove defective, you assume
+the cost of all necessary servicing, repair, or correction.
+
+In no event unless required by applicable law or agreed to in writing
+will The Copyright Holder, or any author named in the components of the
+Work, or any other party who may distribute and/or modify the Work as
+permitted above, be liable to you for damages, including any general,
+special, incidental or consequential damages arising out of any use of
+the Work or out of inability to use the Work (including, but not limited
+to, loss of data, data being rendered inaccurate, or losses sustained by
+anyone as a result of any failure of the Work to operate with any other
+programs), even if the Copyright Holder or said author or said other
+party has been advised of the possibility of such damages.
+
+
+MAINTENANCE OF THE WORK
+=======================
+
+The Work has the status `author-maintained' if the Copyright Holder
+explicitly and prominently states near the primary copyright notice in
+the Work that the Work can only be maintained by the Copyright Holder
+or simply that it is `author-maintained'.
+
+The Work has the status `maintained' if there is a Current Maintainer
+who has indicated in the Work that they are willing to receive error
+reports for the Work (for example, by supplying a valid e-mail
+address). It is not required for the Current Maintainer to acknowledge
+or act upon these error reports.
+
+The Work changes from status `maintained' to `unmaintained' if there
+is no Current Maintainer, or the person stated to be Current
+Maintainer of the work cannot be reached through the indicated means
+of communication for a period of six months, and there are no other
+significant signs of active maintenance.
+
+You can become the Current Maintainer of the Work by agreement with
+any existing Current Maintainer to take over this role.
+
+If the Work is unmaintained, you can become the Current Maintainer of
+the Work through the following steps:
+
+ 1. Make a reasonable attempt to trace the Current Maintainer (and
+ the Copyright Holder, if the two differ) through the means of
+ an Internet or similar search.
+
+ 2. If this search is successful, then enquire whether the Work
+ is still maintained.
+
+ a. If it is being maintained, then ask the Current Maintainer
+ to update their communication data within one month.
+
+ b. If the search is unsuccessful or no action to resume active
+ maintenance is taken by the Current Maintainer, then announce
+ within the pertinent community your intention to take over
+ maintenance. (If the Work is a LaTeX work, this could be
+ done, for example, by posting to comp.text.tex.)
+
+ 3a. If the Current Maintainer is reachable and agrees to pass
+ maintenance of the Work to you, then this takes effect
+ immediately upon announcement.
+
+ b. If the Current Maintainer is not reachable and the Copyright
+ Holder agrees that maintenance of the Work be passed to you,
+ then this takes effect immediately upon announcement.
+
+ 4. If you make an `intention announcement' as described in 2b. above
+ and after three months your intention is challenged neither by
+ the Current Maintainer nor by the Copyright Holder nor by other
+ people, then you may arrange for the Work to be changed so as
+ to name you as the (new) Current Maintainer.
+
+ 5. If the previously unreachable Current Maintainer becomes
+ reachable once more within three months of a change completed
+ under the terms of 3b) or 4), then that Current Maintainer must
+ become or remain the Current Maintainer upon request provided
+ they then update their communication data within one month.
+
+A change in the Current Maintainer does not, of itself, alter the fact
+that the Work is distributed under the LPPL license.
+
+If you become the Current Maintainer of the Work, you should
+immediately provide, within the Work, a prominent and unambiguous
+statement of your status as Current Maintainer. You should also
+announce your new status to the same pertinent community as
+in 2b) above.
+
+
+WHETHER AND HOW TO DISTRIBUTE WORKS UNDER THIS LICENSE
+======================================================
+
+This section contains important instructions, examples, and
+recommendations for authors who are considering distributing their
+works under this license. These authors are addressed as `you' in
+this section.
+
+Choosing This License or Another License
+----------------------------------------
+
+If for any part of your work you want or need to use *distribution*
+conditions that differ significantly from those in this license, then
+do not refer to this license anywhere in your work but, instead,
+distribute your work under a different license. You may use the text
+of this license as a model for your own license, but your license
+should not refer to the LPPL or otherwise give the impression that
+your work is distributed under the LPPL.
+
+The document `modguide.tex' in the base LaTeX distribution explains
+the motivation behind the conditions of this license. It explains,
+for example, why distributing LaTeX under the GNU General Public
+License (GPL) was considered inappropriate. Even if your work is
+unrelated to LaTeX, the discussion in `modguide.tex' may still be
+relevant, and authors intending to distribute their works under any
+license are encouraged to read it.
+
+A Recommendation on Modification Without Distribution
+-----------------------------------------------------
+
+It is wise never to modify a component of the Work, even for your own
+personal use, without also meeting the above conditions for
+distributing the modified component. While you might intend that such
+modifications will never be distributed, often this will happen by
+accident -- you may forget that you have modified that component; or
+it may not occur to you when allowing others to access the modified
+version that you are thus distributing it and violating the conditions
+of this license in ways that could have legal implications and, worse,
+cause problems for the community. It is therefore usually in your
+best interest to keep your copy of the Work identical with the public
+one. Many works provide ways to control the behavior of that work
+without altering any of its licensed components.
+
+How to Use This License
+-----------------------
+
+To use this license, place in each of the components of your work both
+an explicit copyright notice including your name and the year the work
+was authored and/or last substantially modified. Include also a
+statement that the distribution and/or modification of that
+component is constrained by the conditions in this license.
+
+Here is an example of such a notice and statement:
+
+ %% pig.dtx
+ %% Copyright 2005 M. Y. Name
+ %
+ % This work may be distributed and/or modified under the
+ % conditions of the LaTeX Project Public License, either version 1.3
+ % of this license or (at your option) any later version.
+ % The latest version of this license is in
+ % http://www.latex-project.org/lppl.txt
+ % and version 1.3 or later is part of all distributions of LaTeX
+ % version 2005/12/01 or later.
+ %
+ % This work has the LPPL maintenance status `maintained'.
+ %
+ % The Current Maintainer of this work is M. Y. Name.
+ %
+ % This work consists of the files pig.dtx and pig.ins
+ % and the derived file pig.sty.
+
+Given such a notice and statement in a file, the conditions
+given in this license document would apply, with the `Work' referring
+to the three files `pig.dtx', `pig.ins', and `pig.sty' (the last being
+generated from `pig.dtx' using `pig.ins'), the `Base Interpreter'
+referring to any `LaTeX-Format', and both `Copyright Holder' and
+`Current Maintainer' referring to the person `M. Y. Name'.
+
+If you do not want the Maintenance section of LPPL to apply to your
+Work, change `maintained' above into `author-maintained'.
+However, we recommend that you use `maintained', as the Maintenance
+section was added in order to ensure that your Work remains useful to
+the community even when you can no longer maintain and support it
+yourself.
+
+Derived Works That Are Not Replacements
+---------------------------------------
+
+Several clauses of the LPPL specify means to provide reliability and
+stability for the user community. They therefore concern themselves
+with the case that a Derived Work is intended to be used as a
+(compatible or incompatible) replacement of the original Work. If
+this is not the case (e.g., if a few lines of code are reused for a
+completely different task), then clauses 6b and 6d shall not apply.
+
+
+Important Recommendations
+-------------------------
+
+ Defining What Constitutes the Work
+
+ The LPPL requires that distributions of the Work contain all the
+ files of the Work. It is therefore important that you provide a
+ way for the licensee to determine which files constitute the Work.
+ This could, for example, be achieved by explicitly listing all the
+ files of the Work near the copyright notice of each file or by
+ using a line such as:
+
+ % This work consists of all files listed in manifest.txt.
+
+ in that place. In the absence of an unequivocal list it might be
+ impossible for the licensee to determine what is considered by you
+ to comprise the Work and, in such a case, the licensee would be
+ entitled to make reasonable conjectures as to which files comprise
+ the Work.
+
diff --git a/Master/texmf-dist/doc/latex/forest/README b/Master/texmf-dist/doc/latex/forest/README
index f29698ecd39..3d81bcf1744 100644
--- a/Master/texmf-dist/doc/latex/forest/README
+++ b/Master/texmf-dist/doc/latex/forest/README
@@ -1,4 +1,4 @@
-LaTeX package: forest [2015/07/15 v1.0.10 Drawing (linguistic) trees]
+LaTeX package: forest [2015/01/30 v2.0.0 Drawing (linguistic) trees]
Copyright (c) 2015 Saso Zivanovic
(Sa\v{s}o \v{Z}ivanovi\'{c})
@@ -14,6 +14,7 @@ kinds of) trees. Its main features are:
encoding of trees plus the key--value interface to option-setting;
- many tree-formatting options, with control over option values of
individual nodes and mechanisms for their manipulation;
+- a powerful mechanism for travesing the tree;
- the possibility to decorate the tree using the full power of pgf/tikz;
- an externalization mechanism sensitive to code-changes.
@@ -30,3 +31,7 @@ http://www.latex-project.org/lppl.txt
and version 1.3 or later is part of all distributions of LaTeX
version 2005/12/01 or later.
+
+For the list of files constituting the work see the main source file
+of the package, `forest.dtx', or the derived `forest.sty'.
+
diff --git a/Master/texmf-dist/doc/latex/forest/forest-doc.pdf b/Master/texmf-dist/doc/latex/forest/forest-doc.pdf
new file mode 100644
index 00000000000..42460ca6424
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/forest/forest-doc.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/forest/forest-doc.tex b/Master/texmf-dist/doc/latex/forest/forest-doc.tex
new file mode 100644
index 00000000000..e18bd1fc79b
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/forest/forest-doc.tex
@@ -0,0 +1,5324 @@
+%% forest-doc.tex
+%% `forest-doc.tex` is a main documentation source of package `forest`.
+%%
+%% Copyright (c) 2015 Saso Zivanovic
+%% (Sa\v{s}o \v{Z}ivanovi\'{c})
+%% saso.zivanovic@guest.arnes.si
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% of this license or (at your option) any later version.
+%% The latest version of this license is in
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `author-maintained'.
+%%
+%% This file is a part of package `forest'. For the list of files
+%% constituting the package see main source file of the package,
+%% `forest.dtx', or the derived `forest.sty'.
+%%
+\documentclass{ltxdoc}
+\usepackage[a4paper,
+ top=2cm,bottom=2.5cm,
+ reversemarginpar,marginparwidth=2cm,
+ right=1.5cm,
+ nohead
+]{geometry}
+
+%\immediate\write18{makeindex -s forest-doc.ist forest-doc}
+\def\indexlettertotoc#1\relax{%
+ \phantomsection\addcontentsline{toc}{subsection}{#1}%
+ #1%
+}
+\makeatletter
+\c@IndexColumns=2 \makeatother
+\IndexPrologue{Color legend: \textcolor{red}{definition}, \textcolor{darkgreen}{example}, \textcolor{blue}{other}. If an entry belongs to a library, the library name is given in parenthesis. All page numbers are hyperlinks, and definitions in text are hyperlinked to this index.}
+\makeindex
+
+\usepackage[external]{forest}
+\useforestlibrary{edges}
+\useforestlibrary{linguistics}
+% \tikzexternalize
+% forest-tikzexternalize either contains \tikzexternalize or not ... make adjusts this
+\IfFileExists{forest-doc.tex-externalize.tex}{%
+ \input forest-doc.tex-externalize
+}{}
+\tikzset{
+ external/prefix={forest.for.dir/},
+ external/system call={
+ pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=nonstopmode
+ -jobname "\image" "\texsource"},
+ external/up to date check=simple,
+}
+
+\usepackage{forest-doc}
+
+\usepackage{hyperref}
+\hypersetup{unicode=true,colorlinks=true,linkcolor=blue,citecolor=blue,hyperindex=false}
+\usepackage{url}
+\usepackage[numbers]{natbib}
+\usepackage[multiple]{footmisc}
+\usepackage{tipa}
+\usepackage[inline,shortlabels]{enumitem}
+\newlist{compactitem}{itemize}{2}
+\setlist[compactitem]{nosep,label=\textbullet}
+\newlist{arguments}{enumerate}{1}
+\setlist[arguments]{nosep,label=\textbf{\#\arabic*}}
+\renewcommand\DescribeMacro[1]{\texttt{\detokenize{#1}}\marginpar{\hfill\small\strut\texttt{\detokenize{#1}}}}
+\usepackage{printlen}
+\usepackage{tabularx}
+\DeleteShortVerb\|
+\newcommand\OR{\ensuremath{\,|\,}}%
+\usepackage{multicol}
+
+%\usepackage[silent]{trace-pgfkeys} % silent, stack, trace, verbose
+%\pgfkeystracelevel{trace}
+
+ %%% begin listing region: index_macro_style
+\forestset{
+ detokenize/.style={result=\protect\detokenize{##1}},
+ tt/.style={result=\protect\texttt{##1}},
+ macro/.style={detokenize, +result={\char\escapechar}, tt, print in color, hyper},
+}
+ %%% end listing region: index_macro_style
+\forestset{
+ pgfkey/.style={tt,print in color,hyper},
+ path/.style={+result={/},pgfkey},
+ handler/.style={+result={.},pgfkey},
+ option value/.style={
+ format={tt,result+={ value}},
+ for first={format=pgfkey},
+ },
+ environment/.style={
+ detokenize,
+ tt,
+ print in color,
+ if stage={index}{}{
+ if index entry type={definition}{
+ temptoksa/.register=result,
+ hyper,
+ result/.wrap 2 pgfmath args={%
+ \texttt{\string\begin\char`\{##1\char`\}}%
+ \forestoption{argument}%
+ \texttt{\string\end\char`\{##2\char`\}}%
+ }{result}{temptoksa},
+ }{
+ hyper
+ }
+ }
+ },
+ empty/.style={result={{}}},
+ meta/.style={result=\protect\meta{##1},print in color,hyper},
+ index library/.style={
+ if index entry type={definition}{
+ for first leaf'={
+ index format+={
+ result+'={\space
+ {\protect\scriptsize
+ (\protect\texttt{\protect\hyperrefnocolor[sec:library-#1]{#1}})%
+ }%
+ }
+ }
+ },
+ }{}
+ },
+ margin/.style={print format={result=\marginpar{\strut##1}}},
+ also margin/.style={print format={result=##1\marginpar{\strut##1}}},
+}
+
+\let\origmeta\meta
+\renewcommand\meta[1]{\origmeta{\rm\ignorespaces#1}}
+\renewcommand\rstyle{\color{red}}
+\newcommand\hyperrefnocolor[2][]{{\hypersetup{linkcolor=black}\hyperref[#1]{#2}}}
+\newcommand\librarysection[1]{%
+ \subsection{\protect\texttt{#1}}%
+ \label{sec:library-#1}%
+ \forestset{every index end/.style={set={index library={#1}}}}%
+}
+\newcommand\reflibrary[1]{\hyperref[sec:library-#1]{\texttt{#1}}}
+
+\index[not print,not index,set={
+ index key=unknown,
+ form={\textbf{unknown!!}},
+ for first={format={
+ result/.expanded=\noexpand\textbf{\forestregister{result}??},
+ print in color}}}
+ ]>{@unknown}
+
+\indexset
+ [print form={},for first={format=pgfkey}]
+ >{node key}
+
+\indexset
+ [for first={format={+result={/tikz/},pgfkey}}]
+ >{tikz key}
+
+\indexset
+ [for first={format=pgfkey}]
+ >{option,readonly option,bracket key,nodewalk key,register,propagator,style,nodewalk style,stage,dynamic tree,step,loop,conditional,anchor,package option}
+
+ %%% begin listing region: index_macro_category
+\indexset
+ [for first={format=macro}]
+ >{macro}
+ %%% end listing region: index_macro_category
+
+\indexset
+ [for first={format=environment}]
+ >{environment}
+
+\indexset
+ [format=empty]>{empty}
+
+\indexset
+ [index form={type (of options and registers)},for first={format=meta}]
+ >{type}
+
+\indexset
+ [for first={format=handler}]
+ >{handler}
+
+\indexset
+ [format={aggregate function},for first={format=handler}]
+ >{aggregate}
+
+\indexset
+ [form={\texttt{pgfmath} function},for first={format={pgfkey}}]
+ >{pgfmath}
+
+\indexset
+ [for first={format=path}]
+ >{path}
+
+\indexset[
+ form={},
+ for first={
+ for first={
+ key+/.pgfmath=argument("!parent"),
+ index format={
+ result+/.wrap pgfmath arg={\protect\meta{##1 option}}{argument("!parent")}
+ },
+ print format={
+ if argument={}{}{
+ result+/.option=argument
+ },
+ },
+ format={
+ pgfkey
+ },
+ }
+ }
+ ]>{prefix}
+
+\indexset[
+ form={},
+ for first={
+ for first={
+ +key/.pgfmath=argument("!parent"),
+ index format={
+ +result/.wrap pgfmath arg={\protect\meta{##1 option}}{argument("!parent")}
+ },
+ print format={
+ if argument={}{}{
+ +result/.option=argument
+ },
+ },
+ format={
+ pgfkey
+ },
+ }
+ }
+ ]>{suffix}
+
+\indexset[
+ form={},
+ for first={
+ for first={
+ key/.wrap 2 pgfmath args={##1 ##2}{key}{argument("!parent,parent")},
+ index format={
+ result+={\space},
+ result+/.wrap pgfmath arg={\protect\meta{##1}}{argument("!parent,parent")}
+ },
+ print format={
+ if argument={}{}{
+ result+={\space},
+ result+/.option=argument
+ }
+ },
+ format={
+ pgfkey
+ },
+ }
+ }
+ ]>{word prefix}
+
+\indexset[
+ form={},
+ for first={
+ for first={
+ key/.wrap 2 pgfmath args={##2 ##1}{key}{argument("!parent,parent")},
+ index format={
+ +result={\space},
+ +result/.wrap pgfmath arg={\protect\meta{##1}}{argument("!parent,parent")}
+ },
+ print format={
+ if argument={}{}{
+ +result={\space},
+ +result/.option=argument
+ }
+ },
+ format={
+ pgfkey
+ },
+ }
+ }
+ ]>{word suffix}
+
+\indexset[%option values
+ index key format={result/.expanded=\forestoption{argument} value},
+ format={result/.expanded=\noexpand\texttt{\forestoption{argument}} value},
+ for first={format=pgfkey}
+ ]>{value}
+
+\indexset[
+ index key format={result/.expanded=\forestoption{argument} option},
+ format={result/.expanded=\noexpand\texttt{\forestoption{argument}} option},
+ for first={format=pgfkey}
+ ]>{option of}
+
+\indexset
+ [form={},for first={format=meta}]
+ >{meta}
+
+\indexset[
+ for first={+key={{cs }},format={pgfkey}}
+ ]>{forest cs}
+
+\indexset[
+ for first={+key={{ss }},format={pgfkey}}
+ ]>{short step}
+
+
+
+{\makeatletter % an dirty patch: \lst@nolig can sneak in the name...
+\gdef\myexampleindex#1{{\def\lst@nolig{}\lstaspectindex{#1}{}}}
+}
+\lstset{indexstyle={[1]\myexampleindex}}
+%%% end lst-related stuff
+
+\EnableCrossrefs
+\setlength\hfuzz{15pt} % dont make so many
+\hbadness=7000 % over and under full box warnings
+
+\usetikzlibrary{intersections}
+\tikzset{>=latex}
+\forestset{
+ background tree/.style={
+ for tree={text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
+}
+
+\title{\FoRest;: a \PGF;/\TikZ;-based package for drawing linguistic trees\\\normalsize\forestversion}
+\author{Sa\v so \v Zivanovi\'c\footnote{e-mail:
+ \href{mailto:saso.zivanovic@guest.arnes.si}{saso.zivanovic@guest.arnes.si};
+ web:
+ \href{http://spj.ff.uni-lj.si/zivanovic/}{http://spj.ff.uni-lj.si/zivanovic/}}}
+
+%\usepackage[trace]{trace-pgfkeys} % silent, stack, trace, verbose
+%\pgfkeystracelevel{trace}
+
+\begin{document}
+
+\typeout{)}% hacking auctex's error finding routing
+
+% short verbatim: | (changes spaces into _)
+\DeleteShortVerb\|
+{\catcode`\_=12 \def\marshal{%
+\lstMakeShortInline[basicstyle=\ttfamily,literate={_}{ }1 {__}{_}1]}%
+\expandafter}\marshal |
+
+\IfFileExists{forest-doc-test.tex}{%
+ \input{forest-doc-test}
+}{}
+
+\newbox\treebox
+\newbox\codebox
+
+{\settodayfromforestdate\maketitle}
+
+\begin{abstract}
+\FoRest; is a \PGF;/\TikZ;-based package for drawing linguistic (and
+other kinds of) trees. Its main features are
+\begin{enumerate*}[(i)]
+\item a packing algorithm which can produce very compact trees;
+\item a user-friendly interface consisting of the familiar bracket encoding of trees plus the
+ key--value interface to option-setting;
+\item many tree-formatting options, with control over option values of individual nodes and
+ mechanisms for their manipulation;
+\item a powerful mechanism for travesing the tree;
+\item the possibility to decorate the tree using the full power of \PGF;/\TikZ;;
+\item an externalization mechanism sensitive to code-changes.
+\end{enumerate*}
+\end{abstract}
+
+\vspace{1cm}
+
+\begin{forestexample}[basicstyle=\ttfamily\scriptsize,layout=tree on top,no label,v sep=1cm,index={content,pgfmath,propagator>if,repeat,append,before drawing tree,y,alias,for step,step>children,edge,before typesetting nodes,tree,s sep,dimen+,l,current and ancestors,typeset node}]
+ \pgfmathsetseed{14285}
+ \begin{forest}
+ random tree/.style n args={3}{% #1 = max levels, #2 = max children, #3 = max content
+ content/.pgfmath={random(0,#3)},
+ if={#1>0}{repeat={random(0,#2)}{append={[,random tree={#1-1}{#2}{#3}]}}}{}},
+ before typesetting nodes={for tree={draw,s sep=2pt,rotate={int(30*rand)},l+={5*rand},
+ if={isodd(level())}{fill=green}{fill=yellow}}},
+ important/.style={draw=red,line width=1.5pt,edge={red,line width=1.5pt}},
+ before drawing tree={sort by=y, for nodewalk={min=tree,ancestors}{important,typeset node}}
+ [,random tree={9}{3}{100}]
+ \end{forest}
+ \end{forestexample}%
+ \begin{center}\mbox{}\box\treebox\\\box\codebox\end{center}
+
+\newpage
+{%
+ \parskip 0pt
+ \begin{multicols}{2}
+ \tableofcontents
+ \end{multicols}
+}
+
+\newpage
+
+\section{Introduction}
+
+Over several years, I had been a grateful user of various packages
+for typesetting linguistic trees. My main experience was with
+|qtree| and |synttree|, but as far as I can tell, all of the tools
+on the market had the same problem: sometimes, the trees were just
+too wide. They looked something like the tree on the left,
+while I wanted something like the tree on the right.
+\begin{center}
+ \begin{forest}
+ baseline,
+ for tree={parent anchor=south,child anchor=north,l=7ex,s sep=10pt},
+ for children={fit=rectangle}
+ [CP
+ [DP
+ [D][NP[N][CP[C][TP[T][vP[v][VP[DP][V'[V][DP]]]]]]]]
+ [TP
+ [T][vP[v][VP[DP][V'[V][DP]]]]]
+ ]
+ \end{forest}
+ \hfill
+ \begin{forest}
+ baseline,
+ for tree={parent anchor=south,child anchor=north,l=7ex,s sep=10pt},
+ [CP
+ [DP
+ [D][NP[N][CP[C][TP[T][vP[v][VP[DP][V'[V][DP]]]]]]]]
+ [TP
+ [T][vP[v][VP[DP][V'[V][DP]]]]]
+ ]
+ \end{forest}
+\end{center}
+
+Luckily, it was possible to tweak some parameters by hand to get a
+narrower tree, but as I quite dislike constant manual adjustments, I
+eventually started to develop \foRest;. It started out as
+|xyforest|, but lost the |xy| prefix as I became increasingly fond
+of \PGF;/\TikZ;, which offered not only a drawing package but also a
+`programming paradigm.' It is due to the awesome power of the
+supplementary facilities of \PGF;/\TikZ; that \foRest; is now, I
+believe, the most flexible tree typesetting package for \LaTeX\ you can get.
+
+The latest stable version of \FoRest; is \href{http://www.ctan.org/pkg/forest}{available at CTAN}.
+Development version(s) can be found \href{https://github.com/sasozivanovic/forest}{at GitHub}.
+Comments, criticism, suggestions and code are all very welcome! If you find the package useful, you
+can show your appreciation by making a PayPal donation to \url{saso.zivanovic@guest.arnes.si}.
+
+
+\section{Tutorial}
+\label{sec:tutorial}
+
+This short tutorial progresses from basic through useful to
+obscure \dots
+
+\subsection{Basic usage}
+\label{tut:basic-usage}
+
+A tree is input by enclosing its specification in a \index{forest}
+environment. The tree is encoded by \emph{the bracket syntax}:
+every node is enclosed in square brackets; the children of a
+node are given within its brackets, after its content.
+{\lstdefinelanguage[my]{TeX}[LaTeX]{TeX}{keywords=forest,
+ otherkeywords={[,]},keywordstyle=\pstyle,texcsstyle={}}%
+\lstset{language={[my]TeX}}%
+\begin{forestexample}
+ \begin{forest}
+ [VP
+ [DP]
+ [V'
+ [V]
+ [DP]
+ ]
+ ]
+ \end{forest}
+\end{forestexample}}
+Binary trees are nice, but not the only thing this package can draw.
+Note that by default, the children are vertically centered with
+respect to their parent, i.e.\ the parent is vertically aligned with the midpoint between the
+first and the last child.
+\begin{forestexample}
+ \begin{forest}
+ [VP
+ [DP[John]]
+ [V'
+ [V[sent]]
+ [DP[Mary]]
+ [DP[D[a]][NP[letter]]]
+ ]
+ ]
+ \end{forest}
+\end{forestexample}
+Spaces around brackets are ignored --- format your code as you
+desire!
+\begin{forestexample}
+ \begin{forest}
+ [VP[DP][V'[V][DP]]]
+ \end{forest}
+ \quad
+ \begin{forest}[VP
+ [DP ] [ V'[V][ DP]]
+ ]\end{forest}
+\end{forestexample}
+If you need a square bracket as part of a node's content, use
+braces. The same is true for the other characters which have a
+special meaning in the \foRest; package, like comma
+|,| and equality sign |=|.
+\begin{forestexample}
+ \begin{forest}
+ [V{P,}
+ [{[DP]}]
+ [V'
+ [V]
+ [{===DP===}]]]
+ \end{forest}
+\end{forestexample}
+Macros in a node specification will be expanded when the node is
+drawn --- you can freely use formatting commands inside nodes!
+\begin{forestexample}
+ \begin{forest}
+ [VP
+ [{~\textbf~{DP}}]
+ [V'
+ [V]
+ [DP]]]
+ \end{forest}
+\end{forestexample}
+
+All the examples given above produced top-down trees with centered children. The other sections
+of this manual explain how various properties of a tree can be changed, making it possible to
+typeset radically different-looking trees. However, you don't have to learn everything about this
+package to profit from its power. Using styles, you can draw predefined types of trees with ease.
+For example, a phonologist can use the \index{GP1} style from library \reflibrary{linguistics} to easily
+typeset (Government Phonology) phonological representations. The style is applied simply by
+writing its name before the first (opening) bracket of the tree.
+\begin{forestexample}[label=ex:gp1-frost,code prefix={\def\usepackage[##1]##2{}}]
+ \usepackage[~linguistics~]{forest}
+ \begin{forest} ~GP1~ [
+ [O[x[f]][x[r]]]
+ [R[N[x[o]]][x[s]]]
+ [O[x[t]]]
+ [R[N[x]]]
+ ]\end{forest}
+\end{forestexample}
+Of course, someone needs to develop the style --- you, me, your local \TeX nician \dots\@
+Fortunately, designing styles is not very difficult once you get the hang of \foRest;, if you
+write one, please contribute! Some macros relating to various fields are collected in
+\emph{libraries} that are distributed alongside the main package. This is the case for the
+\index{GP1} style used above, which is defined in the |linguistics| library. The simplest way to
+load a library is as shown in the example, by loading the package with an optional argument. For
+more information on loading libraries, see \S\ref{ref:package-options}.
+
+
+(Style \index{GP1} used above is defined in the \keyname{linguistics}
+library of the \foRest; package.)
+
+\subsection{Options}
+\label{tut:options}
+
+A node can be given various options, which control various
+properties of the node and the tree. For example, at the end of
+section~\ref{tut:basic-usage}, we have seen that the \index{GP1} style
+vertically aligns the parent with the first
+child. This is achieved by setting option \index{calign} (for
+\emph{c}hild-\emph{align}ment) to \index{value=calign>first} (child).
+
+Let's try. Options are given inside the brackets, following the
+content, but separated from it by a comma. (If multiple options are
+given, they are also separated by commas.) A single option
+assignment takes the form \meta{option name}|=|\meta{option value}. (There are
+also options which do not require a value or have a default value:
+these are given simply as \meta{option name}.)
+\begin{forestexample}[label=ex:numerals-simple,index={calign,value=calign>first}]
+ \begin{forest}
+ [\LaTeX\ numerals, ~calign=first~
+ [arabic[1][2][3][4]]
+ [roman[i][ii][iii][iv]]
+ [alph[a][b][c][d]]
+ ]
+ \end{forest}
+\end{forestexample}
+
+The experiment has succeeded only partially. The root node's
+children are aligned as desired (so \index{calign}|=|\index{value=calign>first} applied to the
+root node), but the value of the \index{calign} option didn't get
+automatically assigned to the root's children! \emph{An option given
+at some node applies only to that node.} In \foRest;, the options
+are passed to the node's relatives via special options, called
+\emph{propagators}. (We'll
+call the options that actually change some property of the node
+\emph{node options}.) What we need above is the \index{for step=\index{tree}}
+propagator. Observe:
+
+\begin{forestexample}[label=ex:numerals-manual]
+ \begin{forest}
+ [\LaTeX\ numerals,
+ ~for tree~={calign=first}
+ [arabic[1][2][3][4]]
+ [roman[i][ii][iii][iv]]
+ [alph[a][b][c][d]]
+ ]
+ \end{forest}
+\end{forestexample}
+The value of propagator \index{for step=\index{tree}} is the option string that we
+want to process. This option string is propagated to all the nodes in
+the subtree\footnote{It might be more precise to call this option
+\texttt{for subtree} \dots\@ but this name at least saves some typing.}
+rooted in the current node (i.e.\ the node where \index{for step=\index{tree}} was
+given), including the node itself. (Propagator \index{for step=\index{descendants}} is
+just like \index{for step=\index{tree}}, only that it excludes the node itself. There
+are many other \index{for step=\meta{step}} propagators; for the complete list, see
+sections~\ref{ref:spatial-propagators} and \ref{ref:nodewalks}.)
+
+Some other useful options are \index{option>parent anchor}, \index{option>child anchor} and
+\index{tier}. The \index{option>parent anchor} and \index{option>child anchor} options tell
+where the parent's and child's endpoint of the edge between them should be, respectively: usually,
+the value is either empty (meaning a smartly determined border point
+\citep[see][\S16.11]{tikzpgf2.10}; this is the default) or a compass direction
+\citep[see][\S16.5.1]{tikzpgf2.10}. (Note: the \index{option>parent anchor} determines where the edge
+from the child will arrive to this node, not where the node's edge to its parent will start!)
+
+Option \index{tier} is what makes the
+skeletal points $\times$ in example (\ref{ex:gp1-frost}) align horizontally although they
+occur at different levels in the logical structure of the tree.
+Using option \index{tier} is very simple: just set |tier=tier_name| at
+all the nodes that you want to align horizontally. Any tier name
+will do, as long as the tier names of different tiers are
+different \dots\@ (Yes, you can have multiple tiers!)
+\begin{forestexample}[point={tier},index={option>parent anchor,option>child anchor,tier},label=ex:tier-manual]
+ \begin{forest}
+ [VP, for tree={~parent anchor~=south, ~child anchor~=north}
+ [DP[John,tier=word]]
+ [V'
+ [V[sent,tier=word]]
+ [DP[Mary,tier=word]]
+ [DP[D[a,tier=word]][NP[letter,tier=word]]]
+ ]
+ ]
+ \end{forest}
+\end{forestexample}
+Before discussing the variety of \foRest;'s options, it is worth
+mentioning that \foRest;'s node accepts all options \citep[see
+\S16]{tikzpgf2.10} that \TikZ;'s node does --- mostly, it just passes
+them on to \TikZ;. For example, you can easily encircle a node like
+this:\footnote{If option \texttt{draw} was not given, the shape of the node
+would still be circular, but the edge would not be drawn. For
+details, see \cite[\S16]{tikzpgf2.10}.}
+\begin{forestexample}
+ \begin{forest}
+ [VP,~circle~,~draw~
+ [DP][V'[V][DP]]
+ ]
+ \end{forest}
+\end{forestexample}
+
+Let's have another look at example (\ref{ex:gp1-frost}). You will note that the skeletal
+positions were input by typing |x|s, while the result looks like
+this: $\times$ (input as |\times| in math mode). Obviously, the
+content of the node can be changed. Even more, it can be
+manipulated: added to, doubled, boldened, emphasized, etc. We will
+demonstrate this by making example (\ref{ex:numerals-manual}) a bit
+fancier: we'll write the input in the arabic numbers and have
+\LaTeX\ convert it to the other formats. We'll start with the
+easiest case of roman numerals: to get them, we can use the (plain)
+\TeX\ command |\romannumeral|. To change the content of the node,
+we use option \index{content}. When specifying its new value, we can use
+|#1| to insert the current content.\footnote{This mechanism is called
+\emph{wrapping}. \index{content} is the only option where wrapping works implicitely (simply
+because I assume that wrapping will be almost exclusively used with this option). To wrap values
+of other options, use handler \index{wrap value}; see~\S\ref{ref:handlers}.}
+\begin{forestexample}[point={content,delay},index={for step,step>children,content,delay},label=ex:romannumeral]
+ \begin{forest}
+ [roman, delay={for children={content=\romannumeral#1}}
+ [1][2][3][4]
+ ]
+ \end{forest}
+\end{forestexample}
+This example introduces another option: \index{delay}. Without it, the example wouldn't work: we
+would get arabic numerals. This is so because of the order in which the options are processed.
+First, the processing proceeds through the tree in a depth-first, parent-first fashion (first the
+parent is processed, and then its children, recursively; but see \index{processing order}). Next,
+the option string of a node is processed linearly, in the order they were given. (Option
+\keyname{content} is specified implicitely and is always the first.) If a propagator is encountered,
+the options given as its value are propagated \emph{immediately}. The net effect is that if the
+above example contained simply |roman,for_children={content=...}|, the \keyname{content} option
+given there would be processed \emph{before} the implicit content options given to the children
+(i.e.\ numbers |1|, |2|, |3| and |4|). Thus, there would be nothing for the |\romannumeral| to
+change --- it would actually crash; more generally, the content assigned in such a way would get
+overridden by the implicit content. Option \index{delay} is true to its name. It delays the
+processing of its option string argument until the whole tree was processed. In other words, it
+introduces cyclical option processing. Whatever is delayed in one cycle, gets processed in the next
+one. The number of cycles is not limited --- you can nest \index{delay}s as deep as you need.
+
+Unlike \index{for step=\meta{step}} options we have met before, option \index{delay} is not a
+spatial, but a temporal propagator. Several other temporal propagators options exist, see
+\S\ref{ref:stages}.
+
+We are now ready to learn about simple conditionals. Every node option has the corresponding
+\index{if option=\meta{option}} and \index{where option=\meta{option}} keys.
+\index{if option=\meta{option}}|=|\meta{value}\meta{true options}\meta{false options} checks whether
+the value of \meta{option} equals \meta{value}. If so, \meta{true options} are
+processed, otherwise \meta{false options}. The \index{where option=\meta{option}} keys are
+the same, but do this for the every node in the subtree; informally
+speaking, |where| = |for_tree| + |if|. To see this in action,
+consider the rewrite of the \index{tier} example (\ref{ex:tier-manual}) from above. We don't set
+the tiers manually, but rather put the terminal nodes (option
+\index{n children} is a read-only option containing the number
+of children) on tier \keyname{word}.\footnote{We could omit the braces around \texttt{0} because
+it is a single character. If we were hunting for nodes with 42 children, we'd have to write
+\texttt{where n children=\{42\}...}.}
+\begin{forestexample}[index={tier,where option,n children}]
+ \begin{forest}
+ ~where n children~=0{tier=word}{}
+ [VP
+ [DP[John]]
+ [V'
+ [V[sent]]
+ [DP[Mary]]
+ [DP[D[a]][NP[letter]]]
+ ]
+ ]
+ \end{forest}
+\end{forestexample}
+
+Note that you usually don't want to embed a \index{where} conditional in a \index{for step=\index{tree}}, as this will lead to a multiple traversal of many nodes, resulting in a slower execution.
+If you're inside a \index{for step=\index{tree}}, you probably want to use \index{if}.
+
+Finally, let's talk about styles. Styles are simply collections of
+options. (They are not actually defined in the \foRest; package, but
+rather inherited from |pgfkeys|.) If you often want to have non-default
+parent/child anchors, say south/north as in example (\ref{ex:tier-manual}), you would save some
+typing by defining a style. Styles are defined using \PGF;'s handler
+|.style|, like shown below.\footnote{Style \index{sn edges} is actually already defined by library \reflibrary{linguistics}. The definition there is a bit more generic.}
+\begin{forestexample}[index={tier,option>parent anchor,option>child anchor}]
+ \begin{forest}
+ ~sn edges~/~.style~={for tree={
+ parent anchor=south, child anchor=north}},
+ ~sn edges~
+ [VP,
+ [DP[John,tier=word]]
+ [V'
+ [V[sent,tier=word]]
+ [DP[Mary,tier=word]]
+ [DP[D[a,tier=word]][NP[letter,tier=word]]]]]
+ \end{forest}
+\end{forestexample}
+If you want to use a style in more than one tree, you have to define it outside the \index{forest}
+environment. Use macro \index{forestset} to do this.
+\begin{lstlisting}
+ ~\forestset~{
+ sn edges/.style={for tree={parent anchor=south, child anchor=north}},
+ background tree/.style={for tree={
+ text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
+ }
+\end{lstlisting}
+
+You might have noticed that the last two examples contain options (actually, keys) even before the
+first opening bracket, contradicting was said at the beginning of this section. This is mainly
+just syntactic sugar (it can separate the design and the content): such \emph{preamble}
+keys behave as if they were given in the root node, the only difference (which often does not
+matter) being that they get processed before all other root node options, even the implicit
+\index{content}.
+
+If you find yourself writing the same options in the preamble of every tree in your document,
+consider redefining style \index{default preamble}, which is implicitely included at the beginning
+of every preamble.
+
+\subsection{Decorating the tree}
+\label{tut:decorating}
+
+The tree can be decorated (think movement arrows) with arbitrary
+\TikZ; code.
+\begin{forestexample}
+ \begin{forest}
+ [XP
+ [specifier]
+ [X$'$
+ [X$^0$]
+ [complement]
+ ]
+ ]
+ ~\node at (current bounding box.south)
+ [below=1ex,draw,cloud,aspect=6,cloud puffs=30]
+ {\emph{Figure 1: The X' template}};~
+ \end{forest}
+\end{forestexample}
+
+However, decorating the tree would make little sense if one could
+not refer to the nodes. The simplest way to do so is to give them a
+\TikZ; name using the \index{option>name} option, and then use this name in \TikZ;
+code as any other (\TikZ;) node name.
+\begin{forestexample}[point=name,index={option>phantom,option>name}]
+ \begin{forest}
+ [CP
+ [DP,name=spec CP]
+ [\dots
+ [,phantom]
+ [VP
+ [DP]
+ [V'
+ [V]
+ [DP,name=object]]]]]
+ \draw[->,dotted] ~(object)~ to[out=south west,in=south] ~(spec CP)~;
+ \end{forest}
+\end{forestexample}
+
+It gets better than this, however! In the previous examples, we put
+the \TikZ; code after the tree specification, i.e.\ after the closing
+bracket of the root node. In fact, you can put \TikZ; code after
+\emph{any} closing bracket, and \foRest; will know what the current
+node is. (Putting the code after a node's bracket is actually just a
+special way to provide a value for option \index{tikz} of that node.) To
+refer to the current node, simply use an empty node name. This works both with and without
+anchors \citep[see][\S16.11]{tikzpgf2.10}: below, |(.south east)| and |()|.
+\begin{forestexample}[index={option>phantom,option>name}]
+ \begin{forest}
+ [CP
+ [DP,name=spec CP]
+ [\dots
+ [,phantom]
+ [VP
+ [DP]
+ [V'
+ [V]
+ [DP,draw] ~{~
+ \draw[->,dotted] ~()~ to[out=south west,in=south] (spec CP);
+ \draw[<-,red] ~(.south east)~--++(0em,-4ex)--++(-2em,0pt)
+ node[anchor=east,align=center]{This guy\\has moved!};
+ ~}~
+ ]]]]
+ \end{forest}
+\end{forestexample}
+
+Important: \emph{the \TikZ; code should usually be enclosed in braces} to hide
+it from the bracket parser. You don't want all the bracketed code
+(e.g.\ |[->,dotted]|) to become tree nodes, right? (Well, they
+probably wouldn't anyway, because \TeX\ would spit out a thousand
+errors.)
+
+\bigskip
+
+Finally, the most powerful tool in the node reference toolbox:
+\emph{relative nodes}. It is possible to refer to other nodes which stand
+in some (most often geometrical) relation to the current node. To
+do this, follow the node's name with a \index>{!} and a \emph{node walk}
+specification.
+
+A node walk is a concise\footnote{Actually, \foRest; distinguishes two kinds of
+steps in node walks: long and short steps. This section introduces only short steps. See
+\S\ref{ref:nodewalks}.} way of expressing node
+relations. It is simply a string of steps, which are represented by single
+characters, where: \index{ss u} stands for the parent node (up); \index{ss p} for the
+previous sibling; \index{ss n} for the next sibling; \index{ss s} for \emph{the}
+sibling (useful only in binary trees); \index{ss 1}, \index{ss 2},
+\index[not print]{ss 3,ss 4,ss 5,ss 6,ss 7,ss 8}\dots\
+\index{ss 9} for first,
+second, \dots\ ninth child; \index{ss l}, for the last child, etc. For the
+complete specification, see section~\ref{ref:nodewalks}.
+
+To see the nodewalk in action, consider the following examples.
+In the first example, the agree arrow connects the V node, specified
+simply as |()|, since the \TikZ; code follows |[V]|, and the DP node,
+which is described as ``a sister of V's parent'': |!us| = up +
+sibling.
+\begin{forestexample}[index>={!}]
+ \begin{forest}
+ [VP
+ [DP]
+ [V'
+ [V] {\draw[<->] ~()~
+ .. controls +(left:1cm) and +(south west:0.4cm) ..
+ node[very near start,below,sloped]{\tiny agree}
+ ~(!us)~;}
+ [DP]
+ ]
+ ]
+ \end{forest}
+\end{forestexample}
+
+{\footnotesize\begin{forestexample}[index={option>phantom,tikz,fit to,tree},layout=export,basicstyle=\footnotesize\ttfamily]
+ \begin{forest}
+ [CP
+ [DP$_1$]
+ [\dots
+ [,phantom]
+ [VP,tikz={\node [draw,red,inner sep=0,~fit to~=tree]{};}
+ [DP$_2$]
+ [V'
+ [V]
+ [DP$_3$]
+ ]]]]
+ \end{forest}
+\end{forestexample}}
+The second example uses \TikZ;'s fitting library to compute the
+smallest rectangle containing node VP, its first child (DP$_2$) and its last grandchild (DP$_3$).
+The example also illustrates that the \TikZ; code
+can be specified via the ``normal'' option syntax, i.e.\ as a value
+to option \index{tikz}.\footnote{\label{fn:fit-to-tree}Actually, there's a simpler way to do this: use \index{fit to}\keyname{=}\index{tree}!\forestexampleimport}
+\begin{forestexample}[point=tikz,index={option>phantom,tikz},index>={!}]
+ \begin{forest}
+ [CP
+ [DP$_1$]
+ [\dots
+ [,phantom]
+ [VP,tikz={\node [draw,red,fit=~()(!1)(!ll)~] {};}
+ [DP$_2$]
+ [V'
+ [V]
+ [DP$_3$]
+ ]]]]
+ \end{forest}
+\end{forestexample}
+
+
+\subsection{Node positioning}
+\label{tut:node-positioning}
+
+\FoRest; positions the nodes by a recursive bottom-up algorithm which, for every non-terminal node,
+computes the positions of the node's children relative to their parent. By default, all the
+children will be aligned horizontally some distance down from their parent: the ``normal'' tree
+grows down. More generally, however, the direction of growth can change from node to node; this is
+controlled by option \index{grow}=\meta{direction}.\footnote{The direction can be specified either in
+ degrees (following the standard mathematical convention that $0$ degrees is to the right, and that
+ degrees increase counter-clockwise) or by the compass directions: \texttt{east}, \texttt{north east},
+ \texttt{north}, etc.} The system thus computes and stores the positions of children using a
+coordinate system dependent on the parent, called an \emph{ls-coordinate system}: the origin is the
+parent's anchor; l-axis is in the direction of growth in the parent; s-axis is orthogonal to the
+l-axis (positive side in the counter-clockwise direction from $l$-axis); l stands for \emph{l}evel,
+s for \emph{s}ibling. The example shows the ls-coordinate system for a node with |grow=45|.
+
+\begin{forestexample}[point=grow,index=grow]
+ \begin{forest} background tree
+ [parent, grow=45
+ [child 1][child 2][child 3][child 4][child 5]
+ ]
+ \draw[,->](-135:1cm)--(45:3cm) node[below]{$l$};
+ \draw[,->](-45:1cm)--(135:3cm) node[right]{$s$};
+ \end{forest}
+\end{forestexample}
+
+\begin{forestexample}[basicstyle=\scriptsize\ttfamily,layout=export]
+ \newcommand\measurexdistance[5][####1]{\measurexorydistance{#2}{#3}{#4}{#5}{\x}{-|}{(5pt,0)}{#1}}
+ \newcommand\measureydistance[5][####1]{\measurexorydistance{#2}{#3}{#4}{#5}{\y}{|-}{(0,5pt)}{#1}}
+ \tikzset{dimension/.style={<->,>=latex,thin,every rectangle node/.style={midway,font=\scriptsize}},
+ guideline/.style=dotted}
+ \newdimen\absmd
+ \def\measurexorydistance#1#2#3#4#5#6#7#8{%
+ \path #1 #3 #6 coordinate(md1) #1; \draw[guideline] #1 -- (md1);
+ \path (md1) #6 coordinate(md2) #2; \draw[guideline] #2 -- (md2);
+ \path let \p1=($(md1)-(md2)$), \n1={abs(#51)} in \pgfextra{\xdef\md{#51}\global\absmd=\n1\relax};
+ \def\distancelabelwrapper##1{#8}%
+ \ifdim\absmd>5mm
+ \draw[dimension] (md1)--(md2) node[#4]{\distancelabelwrapper{\uselengthunit{mm}\rndprintlength\absmd}};
+ \else
+ \ifdim\md>0pt
+ \draw[dimension,<-] (md1)--+#7; \draw[dimension,<-] let \p1=($(0,0)-#7$) in (md2)--+(\p1);
+ \else
+ \draw[dimension,<-] let \p1=($(0,0)-#7$) in (md1)--+(\p1); \draw[dimension,<-] (md2)--+#7;
+ \fi
+ \draw[dimension,-] (md1)--(md2) node[#4]{\distancelabelwrapper{\uselengthunit{mm}\rndprintlength\absmd}};
+ \fi}
+\end{forestexample}
+\input{\jobname.tmp}
+
+
+The l-coordinate of children is (almost) completely under your control, i.e.\ you set what is
+often called the level distance by yourself. Simply set option \index{option>l} to change the
+distance of a node from its parent. More precisely, \index{option>l}, and the related option
+\index{option>s}, control the distance between the (node) anchors of a node and its parent. The
+anchor of a node can be changed using option \index{option>anchor}: by default, nodes are anchored at
+their base; see \cite[\S16.5.1]{tikzpgf2.10}.) In the example below, positions of the anchors are
+shown by dots: observe that anchors of nodes with the same \index{option>l} are aligned and that the
+distances between the anchors of the children and the parent are as specified in the
+code.\footnote{Here are the definitons of the macros for measuring distances. Args: the x or y
+distance between points \#2 and \#3 is measured; \#4 is where the distance line starts (given as an
+absolute coordinate or an offset to \#2); \#5 are node options; the optional arg \#1 is the format of
+label. (Lengths are printed using package \texttt{printlen}.)
+
+\box\codebox}
+\begin{forestexample}[layout=tree on top,index={for step,tree,tikz,option>l,option>anchor},index>={!}]
+ \begin{forest} background tree,
+ for tree={draw,tikz={\fill[](.anchor)circle[radius=1pt];}}
+ [parent
+ [child 1, ~l~=10mm, ~anchor~=north west]
+ [child 2, ~l~=10mm, ~anchor~=south west]
+ [child 3, ~l~=12mm, ~anchor~=south]
+ [child 4, ~l~=12mm, ~anchor~=base east]
+ ]
+ \measureydistance[\texttt{l(child)}=#1]{(!2.anchor)}{(.anchor)}{(!1.anchor)+(-5mm,0)}{left}
+ \measureydistance[\texttt{l(child)}=#1]{(!3.anchor)}{(.anchor)}{(!4.anchor)+(5mm,0)}{right}
+ \measurexdistance[\texttt{s sep(parent)}=#1]{(!1.south east)}{(!2.south west)}{+(0,-5mm)}{below}
+ \measurexdistance[\texttt{s sep(parent)}=#1]{(!2.south east)}{(!3.south west)}{+(0,-5mm)}{below}
+ \measurexdistance[\texttt{s sep(parent)}=#1]{(!3.south east)}{(!4.south west)}{+(0,-8mm)}{below}
+ \end{forest}
+\end{forestexample}
+
+Positioning the chilren in the s-dimension is the job and \emph{raison d'etre} of the package. As a
+first approximation: the children are positioned so that the distance between them is at least the
+value of option \index{s sep} (s-separation), which defaults to double \PGF;'s |inner_xsep| (and this
+is 0.3333em by default). As you can see from the example above, s-separation is the distance
+between the borders of the nodes, not their anchors!
+
+A fuller story is that \index{s sep} does not control the s-distance between two siblings, but rather
+the distance between the subtrees rooted in the siblings. When the green and the yellow child of
+the white node are s-positioned in the example below, the horizontal
+distance between the green and the yellow subtree is computed. It can be seen with the naked eye
+that the closest nodes of the subtrees are the TP and the DP with a red border. Thus, the children
+of the root CP (top green DP and top yellow TP) are positioned so that the horizontal distance
+between the red-bordered TP and DP equals \index{s sep}.
+\begin{forestexample}[index={for step,tree,s sep}]
+ \begin{forest}
+ important/.style={name=#1,draw={red,thick}}
+ [CP, ~s sep~=3mm, for tree=draw
+ [DP, for tree={fill=green}
+ [D][NP[N][CP[C][TP,important=left
+ [T][vP[v][VP[DP][V'[V][DP]]]]]]]]
+ [TP,for tree={fill=yellow}
+ [T][vP[v][VP[DP,important=right][V'[V][DP]]]]]
+ ]
+ \measurexdistance[\texttt{s sep(root)}=#1]
+ {(left.north east)}{(right.north west)}{(.north)+(0,3mm)}{above}
+ \end{forest}
+\end{forestexample}
+
+Note that \foRest; computes the same distances between nodes
+regardless of whether the nodes are filled or not, or whether their
+border is drawn or not. Filling the node or drawing its border does
+not change its size. You can change the size by adjusting \TikZ;'s
+|inner_sep| and |outer_sep| \citep[\S16.2.2]{tikzpgf2.10}, as shown
+below:
+\begin{forestexample}[index={for step,tree,s sep}]
+ \begin{forest}
+ important/.style={name=#1,draw={red,thick}}
+ [CP, s sep=3mm, for tree=draw
+ [DP, for tree={fill=green,~inner sep~=0}
+ [D][NP,important=left[N][CP[C][TP[T][vP[v]
+ [VP[DP][V'[V][DP]]]]]]]]
+ [TP,for tree={fill=yellow,~outer sep~=2pt}
+ [T,important=right][vP[v][VP[DP][V'[V][DP]]]]]
+ ]
+ \measurexdistance[\texttt{s sep(root)}=#1]
+ {(left.north east)}{(right.north west)}{(.north)+(0,3mm)}{above}
+ \end{forest}
+\end{forestexample}
+(This looks ugly!) Observe that having increased |outer sep| makes the edges stop touching
+borders of the nodes. By (\PGF;'s) default, the |outer sep| is exactly half of the border
+line width, so that the edges start and finish precisely at the border.
+
+Let's play a bit and change the \index{option>l} of the root of the yellow subtree. Below, we set the
+vertical
+distance of the yellow TP to its parent to 3\,cm: and the yellow submarine sinks diagonally \dots\@
+Now, the closest nodes are the higher yellow DP and the green VP.
+\begin{forestexample}[index={option>l,s sep,for step,tree}]
+ \begin{forest}
+ important/.style={name=#1,draw={red,thick}}
+ [CP, s sep=3mm, for tree=draw
+ [DP, for tree={fill=green}
+ [D][NP[N][CP[C][TP
+ [T][vP[v][VP,important=left[DP][V'[V][DP]]]]]]]]
+ [TP,for tree={fill=yellow}, l=3cm
+ [T][vP[v][VP[DP,important=right][V'[V][DP]]]]]
+ ]
+ \measurexdistance[\texttt{s sep(root)}=#1]
+ {(left.north east)}{(right.north west)}{(.north)+(0,3mm)}{above}
+ \end{forest}
+\end{forestexample}
+
+Note that the yellow and green nodes are not vertically aligned anymore. The positioning algorithm
+has no problem with that. But you, as a user, might have, so here's a neat trick. (This only works
+in the ``normal'' circumstances, which are easier to see than describe.)
+\begin{forestexample}[label=ex:l*,index={dimen*=l,option>phantom,for step,tree}]
+ \begin{forest}
+ [CP, for tree=draw
+ [DP, for tree={fill=green},~l*~=3
+ [D][NP]]
+ [TP,for tree={fill=yellow}
+ [T][VP[DP][V'[V][DP]]]]
+ ]
+ \end{forest}
+\end{forestexample}
+We have changed DP's \index{option>l}'s value via ``augmented assignment'' known from
+many programming languages: above, we have used |l*=3| to triple
+\index{option>l}'s value; we could have also said |l+=5mm| or |l-=5mm| to
+increase or decrease its value by 5\,mm, respectively. This
+mechanism works for every numeric and dimensional option in \foRest;.
+
+Let's now play with option \index{s sep}.
+\begin{forestexample}[index={s sep,option>l,dimen*=l,for step,tree}]
+ \begin{forest}
+ [CP, for tree=draw, ~s sep~=0
+ [DP, for tree={fill=green},l*=3
+ [D][NP]]
+ [TP,for tree={fill=yellow}
+ [T][VP[DP][V'[V][DP]]]]
+ ]
+ \end{forest}
+\end{forestexample}
+Surprised? You shouldn't be. The value of \index{s sep} at a given node controls the s-distance
+\emph{between the subtrees rooted in the children of that node}! It has no influence over the
+internal geometry of these subtrees. In the above example, we have set |s_sep=0| only for the root
+node, so the green and the yellow subtree are touching, although internally, their nodes are not.
+Let's play a bit more. In the following example, we set the \index{s sep} to: $0$ at the last
+branching level (level 3; the root is level 0), to 2\,mm at level 2, to 4\,mm at level 1 and to
+6\,mm at level 0.
+
+\begin{forestexample}[label=ex:spread-s,point={level},index={option>level,for step,tree,s sep},index>={!}]
+ \begin{forest}
+ for tree={~s sep~=(3-level)*2mm}
+ [CP, for tree=draw
+ [DP, for tree={fill=green},l*=3
+ [D][NP]]
+ [TP,for tree={fill=yellow}
+ [T][VP[DP][V'[V][DP]]]]
+ ]
+ \measurexdistance{(!11.south east)}{(!12.south west)}{+(0,-5mm)}{below}
+ \path(md2)-|coordinate(md)(!221.south east);
+ \measurexdistance{(!221.south east)}{(!222.south west)}{(md)}{below}
+ \measurexdistance{(!21.north east)}{(!22.north west)}{+(0,2cm)}{above}
+ \measurexdistance{(!1.north east)}{(!221.north west)}{+(0,-2.4cm)}{below}
+ \end{forest}
+\end{forestexample}
+As we go up the tree, the nodes ``spread.'' At the lowest level, V and DP are touching. In the
+third level, the \index{s sep} of level 2 applies, so DP and V' are 2\,mm apart. At the second
+level we
+have two pairs of nodes, D and NP, and T and TP: they are 4\,mm apart. Finally, at level 1, the
+\index{s sep} of level 0 applies, so the green and yellow DP are 6\,mm apart. (Note that D and NP are
+at level 2, not 4! Level is a matter of structure, not geometry.)
+
+As you have probably noticed, this example also demostrated that we can compute the value of an
+option using an (arbitrarily complex) formula. This is thanks to \PGF;'s module |pgfmath|.
+\FoRest; provides an interface to |pgfmath| by defining |pgfmath| functions for every node option,
+and some other information, like the \index{option>level} we have used above, the number of children
+\index{n children}, the sequential number of the child \index{option>n}, etc. For details, see
+\S\ref{ref:pgfmath}.
+
+The final separation parameter is \index{l sep}. It determines the minimal
+separation of a
+node from its descendants. It the value of \index{option>l} is too small, then \emph{all} the
+children (and thus their subtrees)
+are pushed
+away from the parent (by increasing their \index{option>l}s), so that the distance between the node's
+and each child's subtree
+boundary is at least \index{l sep}. The initial \index{option>l} can be too small for
+two reasons: either
+some child is too high, or the parent is too deep. The first problem is easier to see: we force the
+situation using a bottom-aligned multiline node. (Multiline nodes can be easily created using |\\|
+as a line-separator. However, you must first specify the horizontal alignment using option
+\index{align} (see \S\ref{ref:node-appearance}).
+Bottom vertical alignment is achieved by setting \index{base}|=|\index{value=base>bottom};
+the default, unlike in \TikZ;, is \index{base}|=|\index{value=base>top}).
+\begin{forestexample}[point={align,base},index={align,base}]
+ \begin{forest}
+ [parent
+ [child]
+ [child]
+ [a very\\tall\\child, align=center, base=bottom]
+ ]
+ \end{forest}
+\end{forestexample}
+
+The defaults for \index{option>l} and \index{l sep} are set so that they ``cooperate.''
+What this
+means and why it is necessary is a complex issue explained in \S\ref{tut:defaults}, which you will
+hopefully never have to read \dots\@ You might be out of luck, however. What if you
+needed to decrease the level distance? And nothing happened, like below on the left? Or, what if
+you used lots of parenthesis in your nodes? And got a strange vertical misalignment, like below
+on the right? Then rest assured that these (at least) are features not bugs and read
+\S\ref{tut:defaults}.
+\begin{forestexample}[layout=tree on top,v sep=-55ex,code left skip=-3cm,label=ex:misalignments,index={option>phantom,for step,step>children,fit,propagator>for,baseline,edge,descendants,content,pgfmath,ss 1}]
+ \begin{forest}
+ [,phantom,for children={l sep=1ex,fit=band,
+ for 1={edge'=,l=0},baseline}
+ [{l+=5mm},for descendants/.pgfmath=content
+ [AdjP[AdvP][Adj'[Adj][PP]]]]
+ [default
+ [AdjP[AdvP][Adj'[Adj][PP]]]]
+ [{l-=5mm},for descendants/.pgfmath=content
+ [AdjP[AdvP][Adj'[Adj][PP]]]]
+ ]
+ \path (current bounding box.west)|-coordinate(l1)(!212.base);
+ \path (current bounding box.west)|-coordinate(l2)(!2121.base);
+ \path (current bounding box.east)|-coordinate(r1)(!212.base);
+ \path (current bounding box.east)|-coordinate(r2)(!2121.base);
+ \draw[dotted] (l1)--(r1) (l2)--(r2);
+ \end{forest}
+ \hspace{5cm}
+ \begin{forest}
+ [x forest, baseline
+ [x[x[x[x[x[x[x[x[x[x[x[x[x]]]]]]]]]]]]]
+ [(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)]]]]]]]]]]]]]
+ ]
+ \end{forest}
+\end{forestexample}
+
+\subsubsection{The defaults, or the hairy details of vertical alignment}
+\label{tut:defaults}
+
+In this section we discuss the default values of options controlling the l-alignment of the nodes.
+The defaults are set with top-down trees in mind, so l-alignment is actually vertical alignment.
+There are two desired effects of the defaults. First, the spacing between the nodes of a tree
+should adjust to the current font size. Second, the nodes of a given level should be vertically
+aligned (at the base), if possible.
+
+Let us start with the base alignment: \TikZ;'s default is to anchor the nodes at their center,
+while \foRest;, given the usual content of nodes in linguistic representations, rather anchors them
+at the base \cite[\S16.5.1]{tikzpgf2.10}. The difference is particularly clear for a ``phonological''
+representation:
+\begin{forestexample}[index={for step,tree,option>anchor}]
+ \begin{forest} for tree={anchor=center}
+ [maybe[m][a][y][b][e]]
+ \end{forest}\quad
+ \begin{forest}
+ [maybe[m][a][y][b][e]]
+ \end{forest}
+\end{forestexample}
+The following example shows that the vertical distance between nodes depends on the current font size.
+\begin{forestexample}
+ \hbox{\small A small tree
+ \begin{forest} baseline
+ [VP[DP][V'[V][DP]]]
+ \end{forest}
+ \normalsize and
+ \large
+ a large tree
+ \begin{forest} baseline
+ [VP[DP][V'[V][DP]]]
+ \end{forest}}
+\end{forestexample}
+Furthermore, the distance between nodes also depends on the value of \PGF;'s |inner_sep| (which
+also depends on the font size by default: it equals 0.3333\,em).
+\[\index{l sep}=\mbox{height}(\mbox{strut})+\mbox{\texttt{inner ysep}}\]
+The default value of \index{s sep} depends on |inner_xsep|: more precisely, it equals double
+|inner_xsep|).
+\begin{forestexample}[index={baseline,for step,tree}]
+ \begin{forest} baseline,for tree=draw
+ [VP[DP][V'[V][DP]]]
+ \end{forest}
+ \pgfkeys{/pgf/inner sep=0.6666em}
+ \begin{forest} baseline,for tree=draw
+ [VP[DP][V'[V][DP]]]
+ \end{forest}
+\end{forestexample}
+Now a hairy detail: the formula for the default \index{option>l}.
+\[\index{option>l}=\index{l sep}+2\cdot\mbox{\texttt{outer ysep}}+\mbox{total
+height}(\mbox{`dj'})\]
+
+To understand what this is all about we must first explain why it is necessary to set the default
+\index{option>l} at all? Wouldn't it be enough to simply set \index{l sep} (leaving
+\index{option>l} at 0)?
+The problem is that not all letters have the same height and depth. A tree where the vertical
+position of the nodes would be controlled solely by (a constant) \index{l sep} could
+result in a ragged tree (although the height of the child--parent edges would be constant).
+\begin{forestexample}[index={baseline,for step,step>children,no edge,option>name,descendants,option>l}]
+ \begin{forest}
+ [default,baseline,for children={no edge}
+ [DP
+ [AdjP[Adj]]
+ [D'[D][NP,name=np]]]]
+ \path (current bounding box.west)|-coordinate(l)(np.base);
+ \path (current bounding box.east)|-coordinate(r)(np.base);
+ \draw[dotted] (l)--(r);
+ \end{forest}
+ \begin{forest}
+ [{l=0},baseline,for children={no edge}
+ [DP,for descendants={l=0}
+ [AdjP[Adj]]
+ [D'[D][NP,name=np]]]]
+ \path (current bounding box.west)|-coordinate(l)(np.base);
+ \path (current bounding box.east)|-coordinate(r)(np.base);
+ \draw[dotted] (l)--(r);
+ \end{forest}
+\end{forestexample}
+The vertical misalignment of Adj in the right tree is a consequence of the fact that letter j is the
+only letter with non-zero depth in the tree. Since only \index{l sep} (which is constant
+throughout the tree) controls the vertical positioning, Adj, child of Ad\emph{j}P, is pushed lower
+than the other nodes on level 2. If the content of the nodes is variable enough (various heights
+and depths), the cumulative effect can be quite strong, see the right tree of example
+(\ref{ex:misalignments}).
+
+Setting only a default \index{l sep} thus does not work well enough in general. The same
+is true for the reverse possibility, setting a default \index{option>l} (and leaving \index{l sep} at 0). In the example below, the depth of the multiline node (anchored at the top
+line) is such that the child--parent edges are just too short if the level distance is kept constant.
+Sometimes, misalignment is much preferred \dots
+\begin{forestexample}[index={align,{value=align>center},for step,tree,l sep}]
+ \mbox{}\begin{forest}
+ [default
+ [first child[a][b][c]]
+ [second child\\[-1ex]\scriptsize(a copy),
+ align=center[a][b][c]]
+ ]
+ \end{forest}\\
+ \begin{forest} for tree={l sep=0}
+ [{\texttt{l sep}=0}
+ [first child[a][b][c]]
+ [second child\\[-1ex]\scriptsize(a copy),
+ align=center[a][b][c]]
+ ]
+ \end{forest}
+\end{forestexample}
+
+Thus, the idea is to make \index{option>l} and \index{l sep} work as a team:
+\index{option>l} prevents
+misalignments, if possible, while \index{l sep} determines the minimal vertical distance
+between levels. Each of the two options deals with a certain kind of a ``deviant'' node, i.e.\ a
+node which is too high or too deep, or a node which is not high or deep enough, so we need to
+postulate what a \emph{standard} node is, and synchronize them so that their effect on standard
+nodes is the same.
+
+By default, \foRest; sets the standard node to be a node containing letters d and j. Linguistic
+representations consist mainly of letters, and in the \TeX's default Computer Modern font, d is the
+highest letter (not character!), and j the deepest, so this decision guarantees that trees
+containing only letters will look nice. If the tree contains many parentheses, like the right
+tree of example (\ref{ex:misalignments}), the default will of course fail
+and the standard node needs to be modified. But for many applications, including nodes with
+indices, the default works.
+
+The standard node can be changed using macro \index{forestStandardNode};
+see \ref{ref:standard-node}.
+
+\subsection{Advanced option setting}
+\label{tut:advanced-option-setting}
+
+We have already seen that the value of options can be manipulated: in (\ref{ex:romannumeral}) we have
+converted numeric content from arabic into roman numerals using the \emph{wrapping} mechanism
+|content=\romannumeral#1|; in (\ref{ex:l*}), we have tripled the value of |l|
+by saying |l*=3|. In this section, we will learn about the mechanisms for setting and
+referring to option values offered by \foRest;.
+
+One other way to access an option value is using macro \index{forestoption}. The macro takes a
+single argument: an option name. (For details, see \S\ref{sec:option-reading}.) In the
+following example, the node's child sequence number is appended to the existing content. (This is
+therefore also an example of wrapping.)
+\begin{forestexample}[label=ex:forestoption,index={option>phantom,delay,for step,descendants,content,option>n,forestoption}]
+ \begin{forest}
+ [,phantom,delay={for descendants={
+ content=#1$_{~\forestoption~{n}}$}}
+ [c][o][u][n][t]]
+ \end{forest}
+\end{forestexample}
+
+However, only options of the current node can be accessed using \index{forestoption}. To
+access option values of other nodes, \foRest;'s extensions to the \PGF;'s mathematical library
+|pgfmath|, documented in \citep[part VI]{tikzpgf2.10}, must be used. To see |pgfmath| in action,
+first take a look at the crazy tree on the title page, and observe how the nodes are
+rotated: the value given to (\TikZ;) option \texttt{rotate} is a full-fledged |pgfmath| expression
+yielding an integer
+in the range from $-30$ to $30$. Similiarly, \index{dimen+=l} adds a random float
+in the $[-5,5]$ range to the current value of \index{option>l}.
+
+Example (\ref{ex:spread-s}) demonstrated that information about
+the node, like the node's level, can be accessed within |pgfmath| expressions. All
+options are accessible in this way, i.e.\ every option has a corresponding |pgfmath| function.
+For example, we could rotate the node based on its content:
+\begin{forestexample}[index={delay,for step,tree,content}]
+ \begin{forest}
+ delay={for tree={~rotate=content~}}
+ [30[-10[5][0]][-90[180]][90[-60][90]]]
+ \end{forest}
+\end{forestexample}
+
+All numeric, dimensional and boolean options of \foRest; automatically pass the given value
+through |pgfmath|. If you need pass the value through |pgfmath|
+for a string option, use the \index{pgfmath} handler. The following example sets the node's
+content to its child sequence number (the root has child sequence number 0).
+\begin{forestexample}[index={delay,for step,tree,content,option>n,pgfmath}]
+ \begin{forest}
+ delay={for tree={content/~.pgfmath~=int(n)}}
+ [[[][][]][[][]]]
+ \end{forest}
+\end{forestexample}
+
+As mentioned above, using |pgfmath| it is possible to access options of non-current nodes. This
+is achieved by providing the option function with a \index{relative node name}
+(see~\S\ref{ref:relative-node-names}) argument.\footnote{The form without
+parentheses \texttt{option\string_name} that we have been using until now to refer to an option of
+the
+current node is just a short-hand notation for \texttt{option\string_name()} --- note that in some
+contexts, like preceding \texttt{+} or \texttt{-}, the short form does not work! (The same
+seems to be true for all pgfmath functions with ``optional'' arguments.)} In the next example, we
+rotate the node based on the content of its parent.
+\begin{forestexample}[index={delay,for step,descendants,content,ss u},index>={!}]
+ \begin{forest}
+ delay={for descendants={rotate=content~("!u")~}}
+ [30[-10[5][0]][-90[180]][90[-60][90]]]
+ \end{forest}
+\end{forestexample}
+Note that the argument of the option function is surrounded by double quotation marks: this is
+to prevent evaluation of the relative node name as a |pgfmath| function --- which it is not.
+
+Handlers \index{wrap pgfmath arg} and \index{wrap $n$ pgfmath args}
+(for $n=2,\dots,8$) combine the wrapping mechanism with the |pgfmath| evaluation. The
+idea is to compute (most often, just access option values) arguments using |pgfmath| and then
+wrap them with the given macro. Below, this is used to include the number of parent's children in
+the index.
+\begin{forestexample}[index={option>phantom,delay,for step,descendants,content,option>n,n children,wrap $n$ pgfmath args},index>={!}]
+ \begin{forest} [,phantom,delay={for descendants={
+ ~content/.wrap 3 pgfmath args=
+ {#1$_{#2/#3}$}{content}{n}{n_children("!u")}~}}
+ [c][o][u][n][t]]
+ \end{forest}
+\end{forestexample}
+Note the underscore |__| character in |n__children|: in |pgfmath| function names, spaces,
+apostrophes and other non-alphanumeric characters from option names are all replaced by
+underscores.
+
+As another example, let's make the numerals example (\ref{ex:numerals-simple}) a bit fancier.
+The numeral type is read off the parent's content and used to construct the appropriate control
+sequence (|\@arabic|, |\@roman| and |\@alph|). (Also, the numbers are not specified in content
+anymore: we simply read the sequence number \index{option>n}. And, to save some horizontal space for the
+code, each child of the root is pushed further down.)
+\begin{forestexample}[index={delay,where option,option>level,content,option>n,for step,step>children,option>l,wrap $n$ pgfmath args},index>={!}]
+ \begin{forest}
+ delay={where level={2}{~content/.wrap 2 pgfmath args=
+ {\csname @#1\endcsname{#2}}{content("!u")}{n}~}{}},
+ for children={l*=n},
+ [\LaTeX numerals,
+ [arabic[][][][]]
+ [roman[][][][]]
+ [alph[][][][]]
+ ]
+ \end{forest}
+\end{forestexample}
+
+The final way to use |pgfmath| expressions in \foRest;: |if| clauses. In
+section~\ref{tut:options}, we have seen that every option has a corresponding \index{if option=\meta{option}}
+(and \index{where option=\meta{option}} key. However, these are just a matter of convenience. The full
+power resides
+in the general \index{conditional>if} conditional, which takes three arguments:
+|if=|\meta{condition}\meta{true options}\meta{false options}, where \meta{condition} can be any
+|pgfmath| expression
+(non-zero means true, zero means false). (Once again, propagator \index{propagator>where} is an abbreviation
+for \index{for step=\index{tree}}|={|\index{conditional>if}|=...}|.) In the following example, \index{conditional>if} option
+is used to orient the
+arrows from the smaller number to the greater, and to color the odd and even numbers differently.
+
+\forestset{random tree/.style n args={3}{% #1=max levels, #2=max children, #3=max content
+ content/.pgfmath={random(0,#3)},
+ if={#1>0}{repeat={random(0,#2)}{append={[,random tree={#1-1}{#2}{#3}]}}}{}}}
+\begin{forestexample}[index={before typesetting nodes,for step,descendants,conditional>if,content,edge,edge label,tree},index>={!},point=if]
+ \pgfmathsetseed{314159}
+ \begin{forest}
+ before typesetting nodes={
+ for descendants={
+ if={content()>content("!u")}{edge=->}{
+ if={content()<content("!u")}{edge=<-}{}},
+ edge label/.wrap pgfmath arg=
+ {node[midway,above,sloped,font=\scriptsize]{+#1}}
+ {int(abs(content()-content("!u")))}
+ },
+ for tree={circle,if={mod(content(),2)==0}
+ {fill=yellow}{fill=green}}
+ }
+ [,random tree={3}{3}{100}]
+ \end{forest}
+\end{forestexample}
+
+This exhausts the ways of using |pgfmath| in forest. We continue by introducing \emph{relative
+node setting}: write \index{relative node name}|.|\meta{option}|=|\meta{value} to set the
+value of \meta{option} of the specified relative node. Important: computation (pgfmath or wrap) of
+the value is
+done in the context of the original node. The following example defines style \keyname{move} which
+not only draws an arrow from the source to the target, but also moves the content of the source
+to the target (leaving a trace). Note the difference between |#1| and |##1|: |#1| is the argument
+of the style \keyname{move}, i.e.\ the given node walk, while |##1| is the original option value
+(in this case, content).
+\begin{forestexample}[index={for step,tree,calign,tikz,delay,content},index>={!}]
+ \begin{forest}
+ for tree={calign=fixed edge angles},
+ move/.style={
+ tikz={\draw[->] () to[out=south west,in=south] (#1);},
+ delay={~#1.content~={##1},content=$t$}},
+ [CP[][C'[C][\dots[,phantom][VP[DP][V'[V][DP,move=!r1]]]]]]
+ \end{forest}
+\end{forestexample}
+
+In the following example, the content of the branching nodes is computed by \foRest;: a branching
+node is a sum of its
+children. Besides the use of the relative node setting, this example notably uses a recursive
+style: for each child of the node, style \keyname{calc} first applies itself to the child and then
+adds the result to the node; obviously, recursion is made to stop at terminal nodes.
+\begin{forestexample}[index={if option,n children,content,for step,step>children,delay,pgfmath},index>={!}]
+ \begin{forest}
+ calc/.style={if n children={0}{}{content=0,for children={
+ calc,~!u.content~/.pgfmath=int(content("!u")+content())}}},
+ delay=calc,
+ [[[3][4][5]][[3][9]][8][[[1][2][3]]]]
+ \end{forest}
+\end{forestexample}
+
+
+\subsection{Externalization}
+\label{tut:externalization}
+
+\FoRest; can be quite slow, due to the slowness of both \PGF;/\TikZ; and its own computations.
+However, using \emph{externalization}, the amount of time spent in \foRest; in everyday life can
+be reduced dramatically. The idea is to typeset the trees only once, saving them in separate
+PDFs, and then, on the subsequent compilations of the document, simply include these PDFs instead
+of doing the lenghty tree-typesetting all over again.
+
+\FoRest;'s externalization mechanism is built on top of \TikZ;'s |external| library. It
+enhances it by automatically detecting the code and context changes: the tree is recompiled if and
+only if either the code in the \index{forest} environment or the context (arbitrary parameters; by
+default, the parameters of the standard node) changes.
+
+To use \foRest;'s externalization facilities, say:\footnote{When you switch on
+the externalization for a document containing many \keyname{forest} environments, the first
+compilation can take quite a while, much more than the compilation without externalization. (For
+example, more than ten minutes for the document you are reading!) Subsequent compilations,
+however, will be very fast.}\index[not print]{external}
+\begin{lstlisting}[point=external]
+ \usepackage[external]{forest}
+ ~\tikzexternalize~
+\end{lstlisting}
+
+If your \index{forest} environment contains some macro, you will probably want the externalized
+tree to be recompiled when the definition of the macro changes. To achieve this, use
+\index{forestset}|{|\index{external/depends on macro}|=|\cmdname{macro}|}|. The effect is
+local to the \TeX\ group.
+
+\TikZ;'s externalization library promises a |\label| inside the externalized graphics to work
+out-of-box, while |\ref| inside the externalized graphics should work only if the externalization
+is run manually or by |make| \citep[\S32.4.1]{tikzpgf2.10}. A bit surprisingly perhaps, the
+situation is roughly reversed in \foRest;. |\ref| inside the externalized graphics will work
+out-of-box. |\label| inside the externalized graphics will not work at all. Sorry. (The reason
+is that \foRest; prepares the node content in advance, before merging it in the whole tree, which
+is when \TikZ;'s externalization is used.)
+
+\subsection{Expansion control in the bracket parser}
+\label{tut:bracket}
+
+By default, macros in the bracket encoding of a tree are not
+expanded until nodes are being drawn --- this way, node
+specification can contain formatting instructions, as illustrated in
+section~\ref{tut:basic-usage}. However, sometimes it is useful to
+expand macros while parsing the bracket representation, for example to
+define tree templates such as the X-bar template, familiar
+to generative grammarians:\footnote{Honestly, dynamic node creation might be a better way to do
+this; see~\S\ref{ref:dynamic}.}
+\begin{forestexample}[index={bracketset,action character}]
+ ~\bracketset{action character=@}~
+ \def\XP#1#2#3{#1P[#2][#1'[#1][#3]]}
+ \begin{forest}
+ [~@~\XP T{DP}{~@~\XP V{DP}{DP}}]
+ \end{forest}
+\end{forestexample}
+In the above example, the |\XP| macro is preceded by the \emph{action character} |@|: as
+the result, the token following the action character was expanded before the parsing proceeded.
+
+The action character is not hard coded into \foRest;. Actually, there is no action character by
+default. (There's enough special characters in \foRest; already, anyway, and the situations where
+controlling the expansion is preferable to using the pgfkeys interface are not numerous.) It is
+defined at the top of the example by processing key \index{action character} in the
+|/bracket| path; the definition is local to the \TeX\ group.
+
+Let us continue with the description of the expansion control facilities of the bracket parser.
+The expandable token following the
+action character is expanded only once. Thus, if one defined macro
+|\VP| in terms of the general |\XP| and tried to use it in the same
+fashion as |\XP| above, he would fail. The correct way is to follow
+the action character by a braced expression: the braced expression
+is fully expanded before bracket-parsing is resumed.
+\begin{forestexample}[index={bracketset,action character}]
+ \bracketset{action character=@}
+ \def\XP#1#2#3{#1P[#2][#1'[#1][#3]]}
+ \def\VP#1#2{\XP V{#1}{#2}}
+ \begin{forest}
+ [@\XP T{DP}{~@{~\VP{DP}{DP}~}~}]
+ \end{forest}
+\end{forestexample}
+
+In some applications, the need for macro expansion might be much
+more common than the need to embed formatting instructions.
+Therefore, the bracket parser provides commands |@+| and |@-|: |@+|
+switches to full expansion mode --- all tokens are fully expanded
+before parsing them; |@-| switches back to the default mode, where
+nothing is automatically expanded.
+\begin{forestexample}[index={bracketset,action character}]
+ \bracketset{action character=@}
+ \def\XP#1#2#3{#1P[#2][#1'[#1][#3]]}
+ \def\VP#1#2{\XP V{#1}{#2}}
+ \begin{forest} ~@+~
+ [\XP T{DP}{\VP{DP}{DP}}]
+ \end{forest}
+\end{forestexample}
+
+All the action commands discussed above were dealing only with
+\TeX's macro expansion. There is one final action command, |@@|,
+which yields control to the user code and expects it to call
+|\bracketResume| to resume parsing. This is useful to e.g.\
+implement automatic node enumeration:
+\begin{forestexample}[index={bracketset,action character,option>phantom,delay,where option,option>level,content}]
+ \bracketset{action character=@}
+ \newcount\xcount
+ \def\x#1{~@@~\advance\xcount1
+ \edef\xtemp{[$\noexpand\times_{\the\xcount}$[#1]]}%
+ \expandafter\bracketResume\xtemp
+ }
+ \begin{forest}
+ phantom,
+ delay={where level=1{content={\strut #1}}{}}
+ ~@+~
+ [\x{f}\x{o}\x{r}\x{e}\x{s}\x{t}]
+ \end{forest}
+\end{forestexample}
+This example is fairly complex, so let's discuss how it works. |@+| switches to the full
+expansion mode, so that macro |\x| can be easily run. The real magic hides in this macro. In
+order to be able to advance the node counter |\xcount|, the macro takes control from \foRest; by
+the |@@| command. Since we're already in control, we can use |\edef| to define the node content.
+Finally, the |\xtemp| macro containing the node specification is expanded with the resume command
+sticked in front of the expansion.
+
+
+
+\section{Reference}
+\label{sec:reference}
+
+
+
+\subsection{Package loading and options}
+\label{ref:package-options}
+
+Load the package by writing |\usepackage{forest}| in the document preamble.
+
+Field-specific definitions and defaults are stored in separate libraries. Use
+|\usepackage[|\meta{library name}|]{forest}| to load library \meta{library name} and its defaults
+alongside the main package. Loading several libraries in this way is allowed: however, if you need
+more control over loading the defaults, use the following macros.
+
+\begin{syntax}
+\indexitem{macro>useforestlibrary}|{|\meta{library}|,...}|
+Loads the \meta{library} (without loading the its defaults).
+
+Multiple library names can be given, separated by commas. This macro can only be used in the
+preamble.
+
+\indexitem{macro>forestapplylibrarydefaults}|{|\meta{library name},...|}|
+Loads the default settings of \meta{library}.
+
+Multiple library names can be given, separated by commas. This macro can be used either in the
+preamble or in the document body. Its effect is local to the current \TeX\ scope.
+\end{syntax}
+
+For example, the |linguistics| library defines c-command related nodewalks, changes the default
+parent--child edges to south--north (the main package default is border--border) and sets the
+baseline to the root node. Thus, if you write |\usepackage[linguistics]{forest}| in your preamble,
+or use macro \cmdname{forestapplylibrarydefaults} like below, you get the following:
+
+\begin{forestexample}[tree bin=minipage,index={for step,c-commanded}]
+ package defaults:
+ \begin{forest}
+ [VP % cannot use "for c-commanded" below!
+ [DP, for sibling={for tree=red}]
+ [V'[V][DP]]
+ ]
+ \end{forest}\\[1ex]
+ |linguistics| library defaults:
+ ~\forestapplylibrarydefaults{linguistics}~
+ \begin{forest}
+ [VP
+ [DP, ~for c-commanded~={red}]
+ [V'[V][DP]]
+ ]
+ \end{forest}
+\end{forestexample}
+
+\begin{syntax}
+\indexitem(false){package option>external}|=|\alternative{true,false}
+
+ Enable/disable externalization, see \S\ref{ref:externalization}.
+
+\indexitem(most){package option>compat}|=|\meta{keylist}
+
+Enters compatibility mode with previous versions of the \foRest; package. If at all possible, each
+backwards incompatible change is given a key in the |compat| path, e.g.\
+|compat=|\index{1.0-forstep} reverts to the old behaviour of spatial propagators \index{for
+ step=\meta{step}}, where a propagator could not fail. To load all compatibility features, write
+|compat=|\indexdef{option of=compat>all}. To load those most likely to be useful, write
+|compat=|\indexdef{option of=compat>most} or simply |compat|; these keys are also guaranteed to not
+disrupt any new functionality of the package. To load all/most compatibility features since version
+|x.y|, write |x.y-all| or |x.y-most|.
+
+Specifying this option also defines macro \indexdef{macro>forestcompat} (taking the same arguments
+as the package option) which can be used to enable compatibility features locally, within the
+document body.
+
+For a list of compatibility features, see \S\ref{sec:changelog}.
+
+By default, the package warns when a compatibility feature is used. Disable this behaviour by
+|compat=|\indexdef{option of=compat>silent}.
+
+\indexitem(true){package option>tikzcshack}|=|\alternative{true,false}
+
+ Enable/disable the hack into \TikZ;'s implicit coordinate syntax, see
+ \S\ref{ref:relative-node-names}.
+
+\indexitem(true){package option>tikzinstallkeys}|=|\alternative{true,false}
+
+ Install certain keys into the \keyname{/tikz} path. Currently: \index{fit to}.
+
+\indexitem(true){package option>debug}|=|\alternative{true,false}
+
+ Prints out some debugging info to the log file.
+
+ \begin{advise}
+ \item Use simply as |debug| (without |=true|), as it is anticipated that a future version might
+ introduce categories of debugging information. For now we can debug only nodewalks.
+ \end{advise}
+\end{syntax}
+
+\subsection{Invocation}
+\label{sec:invocation}
+
+\begin{syntax}
+ %%% begin listing region: forest_environment_doc
+\indexitem{environment>forest={[\texttt{(}\meta{stages}\texttt{)}]\meta{tree}}}
+ %%% end listing region: forest_environment_doc
+\indexitem{macro>Forest}[*][|(|\meta{stages}|)|]\marg{tree}
+
+ The environment and the starless version of the macro introduce a group; the starred macro does
+ not, so the created nodes can be used afterwards, like in the example below. (Note that this will
+ leave a lot of temporary macros lying around. This shouldn't be a problem, however, since all of
+ them reside in the |\forest| ``namespace''.)
+
+ \meta{stages}, if given, overrides the contents of style \index{stages} for the current
+ environment/macro.
+
+{\tikzexternaldisable
+\begin{forestexample}
+ We create a
+ ~\Forest*~{
+ [DP,name=DP,baseline
+ [D]
+ [NP]
+ ]
+ }
+ and merge it into a
+ ~\Forest*~{
+ [VP,baseline
+ [V]
+ [,replace by=DP
+ ]
+ ]
+ }
+\end{forestexample}}
+
+\indexitem{macro>forestset}\marg{keylist}
+
+ Execute \meta{keylist} (of node keys) with the default path set to \keyname{/forest}.
+ \begin{advise}
+ \item This macro is usually used to define \foRest; styles.
+ \item Usually, no current node is set when this macro is called. Thus, executing most node keys
+ in this place will fail. However, if you have some nodes lying around, you can use
+ propagator \index{for step=\index{option>name}}|=|\meta{node name} to set the node with the given name as
+ current.
+ \end{advise}
+\end{syntax}
+
+
+\subsection{The bracket representation}
+\label{ref:bracket}
+
+A bracket representation of a tree is a token list with the following syntax:
+\begin{eqnarray*}
+ \meta{tree}&=&\left[\meta{preamble}\right]\meta{node}\\
+ \meta{node}&=&\texttt{[}\left[\meta{content}\right]\left[\texttt{,}\meta{keylist}\right]
+ \left[\meta{children}\right]\texttt{]}\meta{afterthought}\\
+ \meta{preamble}&=&\meta{keylist}\\
+ \meta{keylist}&=&\meta{key--value}\left[,\meta{keylist}\right]\\
+ \meta{key--value}&=&\meta{key}\OR\meta{key}\texttt{=}\meta{value}\\
+ \meta{children}&=&\meta{node}\left[\meta{children}\right]
+\end{eqnarray*}
+
+The \meta{preamble} keylist is stored into keylist register \index{preamble}. The \meta{keylist} of
+a \meta{node} is stored into keylist option \index{given options}. \meta{content} and
+\meta{afterthought} are normally stored by prepending and appending
+\index{content}|'=|\meta{content} and \index{afterthought}|=|\meta{afterthought} to \index{given
+ options}, respectively; this is customizable via \index{content to} and redefining style
+\index{afterthought}.
+
+Normally, the tokens in the bracket representation are not expanded while the input is parsed.
+However, it is possible to control expansion. Expansion control sequences of \foRest;'s bracket
+parser are shown below. Note that by default, there is no \index{action character}.
+\begin{center}
+ \begin{tabular}{ll}
+ \rstyle\meta{action character}\texttt{-}&no-expansion mode (default): nothing is expanded\\
+ \rstyle\meta{action character}\texttt{+}&expansion mode: everything is fully expanded\\
+ \rstyle\meta{action character}\texttt{}\meta{token}&expand \meta{token}\\
+ \rstyle\meta{action character}\texttt{}\meta{\TeX-group}&fully expand \meta{\TeX-group}\\
+ \rstyle\meta{action character}\meta{action character}&yield control;\\&upon finishing its job,
+ user's code should call \indexdef{macro>bracketResume}
+ \end{tabular}
+\end{center}
+
+To customize the bracket parser, call
+\indexdef{macro>bracketset}\meta{keylist}, where the keys can be the following.
+\begin{syntax}
+\indexitem({{[%]
+ }}){bracket key>opening bracket}|=|\meta{character}
+\indexitem({{{{%[
+ ]}}}}){bracket key>closing bracket}|=|\meta{character}
+\indexitem(none){bracket key>action character}|=|\meta{character}
+\end{syntax}
+
+By redefining the following two keys, the bracket parser can be used outside \foRest;.
+\begin{syntax}
+\indexitem{bracket key>new node}|=|\meta{preamble}\meta{node specification}\meta{csname}.
+ Required semantics: create a new node given the preamble (in the case of a new
+ root node) and the node specification and store the new node's id into \meta{csname}.
+\indexitem{bracket key>set afterthought}|=|\meta{afterthought}\meta{node id}.
+ Required semantics: store the afterthought in the node with given id.
+\end{syntax}
+
+\subsection{The workflow}
+\label{sec:workflow}
+
+\subsubsection{Stages}
+\label{ref:stages}
+
+\FoRest; does its job in several stages. The default course of events is the following:
+\begin{enumerate}
+\item\label{step:parsing-bracket} The bracket representation of the tree (\S\ref{ref:bracket}) is
+ parsed and stored in a data structure.
+\item\label{step:given-options} The keys given in the bracket representation are processed. In
+ detail, \index{default preamble} is processed first, then the given \index{preamble} (both in the
+ context of the (formal) root node) and finally the keylists given to individual nodes. The latter
+ are processed recursively, in a depth-first, parent-first fashion.
+\item\label{step:typeset-nodes} Each node is typeset in its own |tikzpicture| environment, saved
+ in a box and its measures are taken.
+\item\label{step:pack} The nodes of the tree are \emph{packed}, i.e.\ the relative positions of the nodes are
+ computed so that the nodes don't overlap. That's difficult. The result: option \index{option>s} is
+ set for all nodes. (Sometimes, the value of \index{option>l} is adjusted as well.)
+\item\label{step:compute-xy} Absolute positions, or rather, positions of the nodes relative to the
+ root node are computed. That's easy. The result: options \index{x} and \index{y} are
+ set.
+\item\label{step:draw-tree} The \TikZ; code that will draw the tree is produced and executed. (The nodes are
+ drawn by using the boxes typeset in step~\ref{step:typeset-nodes}.)
+\end{enumerate}
+
+Stage~\ref{step:parsing-bracket} collects user input and is thus ``fixed''. However, the other
+stages, which do the actual work, are under user's control.
+
+First, hooks exist between the individual stages which make it possible (and easy) to change the
+properties of the tree between the processing stages. For a simple example, see
+example~(\ref{ex:adjustxy}): the manual adjustment of \index{y} can only be done after the absolute
+positions have been computed, so the processing of this option is deferred by \index{before drawing
+ tree}. For a more realistic example, see the definition of style \index{GP1}: before packing,
+\texttt{outer xsep} is set to a high (user determined) value to keep the $\times$s uniformly spaced;
+before drawing the tree, the \texttt{outer xsep} is set to \texttt{0pt} to make the arrows look
+better.
+
+Second, the execution of the processing stages \ref{step:given-options}--\ref{step:draw-tree} is
+\emph{completely} under user's control. To facilitate adjusting the processing flow, the approach
+is twofold. The outer level: \foRest; initiates the processing by executing style \keyname{stages},
+which by default executes the processing stages \ref{step:given-options}--\ref{step:draw-tree},
+preceding the execution of each but the first stage by processing the keys embedded in temporal
+propagators \keyname{before ...} (see \S\ref{ref:temporal-propagators}). The inner level: each
+processing step is the sole resident of a stage-style, which makes it easy to adjust the workings of
+a single step. What follows is the default content of style \keyname{stages}, including the default
+content of the individual stage-styles. Both nicely readable and ready to copy-paste versions are given.
+\begin{syntax}
+ \indexitem{style>stages}
+ \begin{syntax}
+ \item \index{for step=\index{root'}}|={|
+ \item | |\index{process keylist register}|=|\index{default preamble}|,|
+ \item | |\index{process keylist register}|=|\index{preamble}
+ \item |}|
+ \item \index{process keylist}|=|\index{given options}
+ \item \index{process keylist}|=|\index{before typesetting nodes}
+ \indexitem{style>typeset nodes stage}\hfill
+ |{|\index{for step=\index{root'}}|=|\index{typeset nodes}|}|
+ \item \index{process keylist}|=|\index{before packing}
+ \indexitem{style>pack stage}\hfill
+ |{|\index{for step=\index{root'}}|=|\index{pack}|}|
+ \item \index{process keylist}|=|\index{before computing xy}
+ \indexitem{style>compute xy stage}\hfill
+ |{|\index{for step=\index{root'}}|=|\index{compute xy}|}|
+ \item \index{process keylist}|=|\index{before drawing tree}
+ \indexitem{style>draw tree stage}\hfill
+ |{|\index{for step=\index{root'}}|=|\index{draw tree}|}|
+ \end{syntax}
+\end{syntax}
+\lstinputregion{forest.dtx}{stages}
+
+Both style \keyname{stages} and the individual stage-styles may be freely modified by the user.
+Obviously, as a style must be redefined before it is processed, |stages| should be redefined (using
+macro \index{forestset}) outside the \index{forest} environment; alternatively, stages can be given
+as the (parenthesized) optional argument of the environment (see~\S\ref{sec:invocation}). A stage
+style can also be redefined in the preamble or in any of the keylists processed prior to entering
+that stage.
+
+Here's the list of keys used either in the default processing or useful in an alternative
+processing flow.
+\begin{syntax}
+ \indexitem{stage>typeset nodes}
+ \itemnosep
+ \indexitem{stage>typeset nodes'}
+
+ Typesets each node of the current node's subtree in its own |tikzpicture| environment. The result
+ is saved in a box (which is used later, in the \index{draw tree stage}) and its measures are
+ taken.
+
+ In the |typeset_nodes'| variant, the node box's content is not overwritten if the box already
+ exists.
+
+ The order in which the nodes are typeset is controlled by nodewalk style \indexdef{nodewalk
+ style>typeset nodes processing order} or, if this style is not defined, by \index{processing
+ order}.
+
+\indexitem{node key>typeset node} Typesets the \emph{current} node, saving the result in the node box.
+
+ This key can be useful also in the default \index{stages}. If, for example, the node's content
+ is changed and the node retypeset just before drawing the tree, the node will be positioned as if
+ it contained the ``old'' content, but have the new content: this is how the constant distance
+ between $\times$s is implemented in the \index{GP1} style.
+
+\indexitem{stage>pack} The nodes of the tree are \emph{packed}, i.e.\ the relative positions of
+ the nodes are computed so that the nodes don't overlap. The result: option \index{option>s} is set
+ for all nodes; sometimes (in tier alignment and for some values of \index{calign}), the value
+ of some nodes' \index{option>l} is adjusted as well.
+
+\indexitem{node key>pack'} ``Non-recursive'' packing: packs the children of the current node only.
+ (Experimental, use with care, especially when combining with tier alignment.)
+
+\indexitem{stage>compute xy} Computes the positions of the nodes in the subtree relative to the
+ current node. The results are stored into options \index{x} and \index{y}. The current node's
+ \index{x} and \index{y} remain unchanged.
+
+\indexitem{stage>draw tree}
+\itemnosep
+\indexitem{stage>draw tree'}
+ Produces the \TikZ; code that will draw the tree.
+
+ The procedure uses the node boxes typeset by \index{typeset nodes} or friends. The |'| variant
+ includes the node boxes in the picture using \cmdname{copy}, not \cmdname{box}, thereby preserving
+ them.
+
+ By default, the nodes are drawn first, followed by edges and finally the custom code given by
+ \index{tikz}. Within each task, the order in which the nodes are visited is determined by
+ nodewalk styles \indexdef{nodewalk style>draw tree nodes processing order}, \indexdef{nodewalk
+ style>draw tree edges processing order} and \indexdef{nodewalk style>draw tree tikz processing
+ order}, respectively, with \index{processing order} as the fallback in case any of these styles
+ does not exist (the default).
+
+ However, the whole procedure is fully customizable via style \indexdef{style>draw
+ tree method}, originally defined like shown below. To draw an individual node, edge (to parent)
+ or custom (\index{tikz}) code, \indexdef{node key>draw tree node}, \indexdef{node key>draw tree
+ edge} and \indexdef{node key>draw tree tikz} are used, respectively.
+
+ \lstinputregion{forest.dtx}{draw_tree_method}
+
+\indexitem{node key>draw tree box}|=|[\meta{\TeX\ box}] The picture drawn by the subsequent
+ invocations of \index{draw tree} and \index{draw tree'} is put into \meta{\TeX\ box}. If
+ the argument is omitted, the subsequent pictures are typeset normally (the default).
+
+ \indexitem{node key>process keylist}|=|\meta{keylist option}
+ For each node in the entire tree, the keylist saved in \meta{keylist option} of the node is
+ processed (in the context of that node).
+
+ Note that this key is not sensitive to the current node: it processes the keylists for the whole
+ tree. Actually, it is possible to control which nodes are visited: \index{keylist option
+ processing order=\meta{keylist option}} is walked if it is defined, otherwise \index{processing
+ order}. In both cases, the processing nodewalk starts at the formal root of the tree (see
+ \index{root'} and \index{set root}), which is reevaluated at the beginning of each internal cycle
+ (see below). By default, \index{keylist option processing order=\meta{keylist option}} is indeed
+ undefined, while the \index{processing order} defauls to \index{tree}, which means that \emph{all
+ the nodes in the entire tree} are processed.
+
+ Keylist-processing proceeds in cycles. In a given cycle, the value of option \meta{keylist option
+ name} is processed for every node visited by the processing nodewalk. During a cycle, keys may
+ be \emph{delayed} using key \index{delay}. Keys delayed in a cycle are processed in the next
+ cycle. The number of cycles in unlimited.
+
+ Dynamic creation of nodes happens between the cycles. The options given to the dynamically
+ created nodes are implicitely delayed and thus processed at the end of the next cycle.
+
+ The calls of this key should \emph{not} be nested, and it should not be embedded under
+ \index{process keylist'} or \index{process keylist register}.
+
+ When changing the processing nodewalk, note that delayed keys will be executed only for nodes
+ visited by the processing nodewalk. Delayed spatially propagated keys will be remembered,
+ though, and executed when the given keylist is processed for the target node. Using spatial
+ propagators without delaying cannot result in a non-processed key.
+
+\indexitem{node key>process keylist'}|=|\meta{keylist option}\meta{nodewalk}
+
+ This key is a variant of \index{process keylist}. The differences are as follows.
+
+ The processing nodewalk is given explicitely (by \meta{nodewalk}) and starts at the current node
+ (in each internal cycle).
+
+ There is no dynamic creation of nodes between the delay cycles. Any dynamic node
+ instructions will be remembered and executed after the next cycle of \index{process keylist}, or
+ an explicit call to \index{do dynamics}.
+
+ It is safe to embed this key within \index{process keylist} and (all) friends.
+
+\indexitem{node key>process keylist''}|=|\meta{keylist option}\meta{nodewalk}
+
+This key is a variant of \index{process keylist} which executes neither dynamic node operations nor
+delayed keys (there are thus no internal cycles). Any delayed keys will not be processed
+during the execution of this key. They will be remembered and executed at the end of the next cycle
+of \index{process keylist} or \index{process keylist'}.
+
+As for \index{process keylist'}, the processing nodewalk is given explicitely (by \meta{nodewalk})
+and starts at the current node.
+
+It is safe to embed this key within \index{process keylist} and (all) friends.
+
+\indexitem{node key>process keylist register}|=|\meta{register}
+
+ Process the keylist saved in \meta{register} in the context of the current node.
+
+ Any delayed keys will not be processed during the execution of this key. They will be
+ remembered and executed at the end of the next cycle of \index{process keylist} or
+ \index{process keylist'}.
+
+ It is safe to embed this key within \index{process keylist} or \index{process keylist'}.
+
+\indexitem{node key>process delayed}|=|\meta{nodewalk} Process delayed keys.
+
+ Keylist \index{delay} cannot be processed using \index{process keylist} or \index{process
+ keylist'}. Thus this key.
+
+ Like \index{process keylist} or \index{process keylist'}, this key uses internal cycles. Thus,
+ any embedded \index{delay}s will be processed.
+
+ There is no dynamic creation of nodes between the delay cycles. Any dynamic node instructions will
+ be remembered and executed after the next cycle of \index{process keylist} or \index{process
+ keylist'}, or an explicit call to \index{do dynamics}.
+
+ This key is safe to use within \index{process keylist}, \index{process keylist'} and
+ \index{process keylist register}.
+
+\indexitem(tree){nodewalk style>processing order}|=|\meta{nodewalk}
+
+Redefine this style to change the default order in which \index{process keylist} processes a keylist
+option. For example, to process the nodes in a child-first fashion, write
+\begin{lstlisting}
+ for nodewalk={processing order/.style={tree children first}}
+\end{lstlisting}
+Note that this is a \emph{nodewalk} style, so it must be defined during a nodewalk.
+
+\indexitem(processing order)[form={processing order}]{word suffix=keylist option>nodewalk style>processing order=\meta{keylist option}}|=|\meta{nodewalk}
+
+Redefine this style to change the \index{process keylist} processing order for a specific
+\meta{keylist option}. For example, to process \index{before drawing tree} options in the
+child-first fashion, leaving the processing of other |before ...| keylists untouched, write
+\begin{lstlisting}
+ for nodewalk={before drawing tree processing order/.style={tree children first}}
+\end{lstlisting}
+
+\indexitem{node key>do dynamics} Experimental. Perform pending dynamic tree operations.
+
+ Do not use this key within \index{process keylist} or \index{process keylist'}.
+
+\end{syntax}
+
+\subsubsection{Temporal propagators}
+\label{ref:temporal-propagators}
+
+Temporal propagators delay processing of given keys until some other point in the processing of the
+tree. There are three kinds of temporal propagators. Most of the |before_...| and |after_...|
+propagators defer the processing of the given keys to a hook just before some stage in the workflow
+(\S\ref{ref:stages}). \index{before packing node} and \index{after packing node} are special as
+they fire \emph{during} the packing stage. The \keyname{delay} propagator is ``internal'' to the
+current hook: the keys in the hook are processed cyclically, and \keyname{delay} delays the
+processing of the given keys until the next cycle.
+
+Formally, temporal propagators are keylist options (except \index{delay n}, which is a style), so
+augmented assignments are possible (\S\ref{sec:option-setting}).
+
+All temporal propagators can be nested without limit.
+
+\begin{syntax}
+\indexitem{propagator>delay}|=|\meta{keylist} Defers the processing of the \meta{keylist} until the next
+ cycle.
+
+ Internally, |delay| is a keylist option, so augmented operators of the \index{keylist} type can be
+ used.
+
+ To check whether any keys were delayed, use conditional \index{if have delayed}.
+\indexitem{propagator>delay n}|=|\meta{integer}\meta{keylist} Defers the processing of the
+ \meta{keylist} for $n$ cycles. $n$ may be $0$, and it may be given as a |pgfmath| expression.
+
+\indexitem{propagator>given options}
+
+ When \index{stages} processing starts, this list holds the keys given by the user in the
+ bracket representation.
+
+\indexitem{propagator>before typesetting nodes}|=|\meta{keylist} Defers the processing of the
+ \meta{keylist} to until just before the nodes are typeset.
+
+\indexitem{propagator>before packing}|=|\meta{keylist}
+
+\indexitem{propagator>before packing node}|=|\meta{keylist}
+
+ Defers the processing of the \meta{keylist} given to the node to until just before/after the
+ subtree of \emph{this specific node} is packed. Even before packing node, the (subtrees of the)
+ children of the node have already been packed.\footnote{\FoRest; employs two variants of the
+ packing algorithm: the faster one is used for (parts of) trees with uniform growth, i.e.\
+ subtrees where \index{grow} does not change; the slower, generic variant is used in where this
+ is not the case. Now, the fast method works by dealing with l and s dimension separately, and
+ it is able to do this for the entire (sub)tree, without needing to invoke the packing method for
+ its constituents. The consequence is that there is no place where \index{before packing node}
+ could be called meaningfully, as the node's constituents are not packed individually, ``just
+ before packing the current node'' is the same as ``just before packing the tree'', and for many
+ nodes packing is not called anyway in the fast method. As the rationale behind \index{before
+ packing node} is to be able to adjust the options of the subtree based on the information
+ gained by packing its constituents, specifying \index{before packing node} automatically
+ switches to the generic method.} \indexitem{propagator>after packing node}|=|\meta{keylist} Defers
+ the processing of the \meta{keylist} given to the node to until just after \emph{this specific
+ node} is packed.
+
+\begin{forestexample}[index={after packing node,no edge,calign,value=calign>first,option>l,l sep,content format,content,if option,n children,pgfmath,option>s,max x,min x,for step,step>children,wrap pgfmath arg,typeset node,dimen+=s}]
+ \forestset{box/.style={
+ draw, no edge, l=0, l sep=1.5ex,
+ calign=first, anchor=base west,
+ content format={\strut\forestoption{content}},
+ if n children=0{}{
+ ~after packing node~={
+ minimum width/.pgfmath=
+ {s("!l")+max_x("!l")-s("!1")-min_x("!1")},
+ for children/.wrap pgfmath arg={s+={##1}}{0},
+ typeset node}}}}
+ \begin{forest} for tree={box} [/
+ [home[saso[Download][TeX]][alja][joe]]
+ [usr[bin][share]]]
+ \end{forest}
+\end{forestexample}
+
+ \begin{advise}
+ \item Remember to typeset or pack the node using \index{pack'} if you have changed options
+ influencing the typesetting or packing process.
+ \end{advise}
+
+\indexitem{propagator>before computing xy}|=|\meta{keylist} Defers the processing of the
+ \meta{keylist} to until just before the absolute positions of the nodes are computed.
+\indexitem{propagator>before drawing tree}|=|\meta{keylist} Defers the processing of the
+ \meta{keylist} to until just before the tree is drawn.
+\end{syntax}
+
+\subsubsection{Spatial propagators}
+\label{ref:spatial-propagators}
+
+Spatial propagators pass the given \meta{keylist} to other node(s) in the tree.
+
+\FoRest; provides many spatial propagators. Almost all of them are built from long-form nodewalk
+steps using prefix \index{for step}. This is why the list below is so short: it only documents
+this prefix and the exceptions. For the list of nodewalk steps, see \S\ref{ref:nodewalks}.
+
+Spatial propagation does not change the current node: after visiting the nodes the keys are
+propagated to, a spatial propagator (silently) returns to the origin of the embedded nodewalk.
+
+\begin{syntax}
+\indexitem{word prefix=step>propagator>for=\meta{step}}|=|\meta{arg$_1$}|...|\meta{arg$_n$}\meta{keylist}
+
+ Walks the (single- or multi-step) \meta{step} from the current node and executes the given
+ \meta{keylist} at every visited node. The current node remains unchanged.
+
+ \meta{step} must be a long-form nodewalk step. If it has any arguments, they should be given
+ before the keylist, with one exception: \meta{keylist: every-step} arguments of embedded nodewalks
+ should be omitted, as it makes no sense to provide the every-step keylist twice.
+
+ For details on nodewalk steps, see \S\ref{ref:nodewalks}.
+
+ Examples:
+ \begin{itemize}
+ \item |for_parent={l_sep+=3mm}|
+ \item |for_n=2{circle,draw}|
+ \item |for_nodewalk={uu2}{blue}|
+ \item |for_tree={s_sep+=1em}|
+ \end{itemize}
+
+\indexitem{propagator>for tree'}|=|\meta{keylist 1}\meta{keylist 2} A ``combination'' of
+ \index{for step=\index{tree children-first}} and \index{for step=\index{tree}}.
+
+ Passes the keylists to the current node and its the descendants. At each node, the \meta{keylist
+ 1} is processed first; then, children are processed recursively; finally, \meta{keylist 2}
+ is processed.
+
+ For an example, see the definition of \index{draw brackets} from \reflibrary{linguistics}.
+
+\indexitem{propagator>for 1}, \dots\indexdef[not print]{propagator>for 2}\indexdef[not print]{propagator>for 3}\indexdef[not print]{propagator>for 4}\indexdef[not print]{propagator>for 5}\indexdef[not print]{propagator>for 6}\indexdef[not print]{propagator>for 7}\indexdef[not print]{propagator>for 8}, \indexdef{propagator>for 9}|=|\meta{keylist}
+ \itemnosep
+\indexitem{propagator>for -1}, \dots\indexdef[not print]{propagator>for -2}\indexdef[not print]{propagator>for -3}\indexdef[not print]{propagator>for -4}\indexdef[not print]{propagator>for -5}\indexdef[not print]{propagator>for -6}\indexdef[not print]{propagator>for -7}\indexdef[not print]{propagator>for -8}, \indexdef{propagator>for -9}|=|\meta{keylist}
+
+ Although \index{for step} normally cannot precede short forms of steps, an exception is made
+ for \index{ss 1}\index[not print]{ss 2,ss 3,ss 4,ss 5,ss 6,ss 7,ss 8}, \dots, \index{ss 9}. (These keys will work even if the short steps are redefined.)
+
+ |for |$n$ passes the \meta{keylist} to the $n$th child of the current node. |for -|$n$ starts counting at the last child.
+\indexitem{node key>Nodewalk}|=|\meta{keylist: config}\meta{nodewalk}\meta{keylist: every-step}
+
+Configures and executes the \meta{nodewalk}. This key is a nodekey-space copy of nodewalk step
+\index{step>Nodewalk}.
+
+ \begin{advise}
+ \item Use this key carefully as it can change the current node!
+ \item The envisioned purpose of this key is to change the current node within the every-step
+ keylist of (an outer) nodewalk, where only node keys are accepted. The config defaults
+ (independent every-step, shared history) are set to facilitate that purpose.
+ \end{advise}
+
+\indexitem{node key>node walk}|=|\meta{node walk} \textbf{Deprecated!!!} Please use \index{for
+ step=\index{nodewalk}} in new code. From the old documentation:
+
+ \begin{quote}
+ This is the most general way to use a \meta{node walk}.
+
+ Before starting the \meta{node walk}, key \indexdef{node key>node walk/before walk} is processed.
+ Then, the \meta{step}s composing the \meta{node walk} are processed: making a step (normally)
+ changes the current node. After every step, key \indexdef{node key>node walk/every step} is
+ processed. After the walk, key \indexdef{node key>node walk/after walk} is processed.
+
+ \keyname{node walk/before walk}, \keyname{node walk/every step} and \keyname{node walk/after
+ walk} are processed with \keyname{/forest} as the default path: thus, \foRest;'s node keys can
+ be used normally inside their definitions.
+
+ \begin{advise}
+ \item Node walks can be tail-recursive, i.e.\ you can call another node walk from \keyname{node
+ walk/after walk} --- embedding another node walk in \keyname{node walk/before walk} or
+ \keyname{node walk/every step} will probably fail, because the three node walk styles are not
+ saved and restored (a node walk doesn't create a \TeX\ group).
+ \item \keyname{every step} and \keyname{after walk} can be redefined even during the walk.
+ Obviously, redefining \keyname{before walk} during the walk has no effect (in the current
+ walk).
+ \end{advise}
+ \end{quote}
+\end{syntax}
+
+\subsection{Node keys}
+\label{ref:node-keys}
+
+\FoRest; is mostly controlled using \PGF;'s key management utility |pgfkeys|
+\citep[\S55]{tikzpgf2.10}. Most of the keys can be given next to the content in the bracket
+representation of a tree (\S\ref{ref:bracket}): we call these \emph{node keys}. Some keys,
+notably \emph{nodewalk steps} (\S\ref{ref:nodewalks}), must be used as arguments of specific
+commands.
+
+Most node keys perform some operation on the \emph{current node}. When the keylist given after the
+content of a node is processed, the current node is set to that node. However, the current node can
+be temporarily changed, for example by spatial propagators (\S\ref{ref:spatial-propagators}) or,
+more genarally, nodewalks (\S\ref{ref:nodewalks}).
+
+The most common function that node keys perform is to set or modify an \emph{option} of the current
+node (\S\ref{sec:options-and-registers}), usually to determine the appearance or position of the
+node and its edge (\S\ref{sec:formatting-tree}), but there are also several kinds of more exotic
+keys like spatial (\S\ref{ref:spatial-propagators}) propagators, which temporarily change the
+current node, temporal (\S\ref{ref:temporal-propagators}) propagators, which delay the processing of
+the keylist until some other stage in the workflow, keys that dynamically create and move nodes
+(\S\ref{ref:dynamic}), keys that control the way \foRest; processes the tree (\S\ref{ref:stages})
+etc. Finally, users can also define their own keys, either by defining |pgfkeys| styles\footnote{%
+ Styles are a feature of the \keyname{pgfkeys} package. They are named keylists, whose usage
+ ranges from mere abbreviations through templates to devices implementing recursion. To define a
+ style, use \PGF;'s handler \keyname{.style} \citep[\S55.4.4]{tikzpgf2.10}: \meta{style
+ name}\keyname{/.style=}\meta{keylist}.} \citep[\S55.4.4]{tikzpgf2.10} or using \foRest;'s option
+declaration mechanism (\S\ref{sec:option-declaring}).
+
+\begin{advise}
+\item The style definitions and option declarations given among the other keys in the bracket
+ specification are local to the current tree (but note that \foRest;'s keylist processing,
+ including temporal and spatial propagation, introduces no groups). To define globally accessible
+ styles and options (well, they are always local to the current \TeX\ group), use
+ macro \cmdname{forestset} outside the \index{forest} environment, e.g.\ in the preamble of the
+ document. (Although \index{forestset}\meta{keylist} is currently equivalent to
+ \cmdname{pgfkeys}\texttt{\{/forest,}\meta{keylist}\texttt{\}}, don't rely on this as it will
+ change in some (near) future version of the package, as there is a plan to introduce namespaces
+ \dots)
+\end{advise}
+
+The remainder of this section lists the general-purpose node keys, i.e.\ those which don't deal with
+tree formatting.
+
+\begin{syntax}
+
+\indexitem{style>afterthought}|=|\meta{toks} Provides the afterthought explicitely.
+
+ This key is normally not used by the end-user, but rather called by the bracket parser. By
+ default, this key is a style defined by |afterthought/.style={tikz+={#1}}|: afterthoughts are
+ interpreted as (cumulative) \TikZ; code. If you'd like to use afterthoughts for some other
+ purpose, redefine this style --- this will take effect even if you do it in the tree preamble.
+
+\indexitem{node key>autoforward}|=|\meta{option}\meta{keylist}, \indexdef{node key>autoforward register}|=|\meta{register}\meta{keylist}
+\itemnosep
+\indexitem{node key>autoforward'}|=|\meta{option}\meta{keylist}, \indexdef{node key>autoforward register'}|=|\meta{register}\meta{keylist}
+
+Whenever the value of an autoforwarded option or register is given or changed (via an augmented
+assignment), \meta{option}|=|\meta{new value} or \meta{register}|=|\meta{new value} is appended to
+\meta{keylist}. This can be used to ``intercept and remember'' \TikZ; options, like \index{option>anchor}
+and \index{rotate}.
+
+ The |autoforward'| variant keeps only a single instance of \meta{option} in \meta{keylist}.
+
+ If you ever need to use the non-forwarded version of the key, prefix it with word |autoforwarded|,
+ e.g.\ |autoforwarded_rotate|. Autoforwarding is limited to the current \TeX\ group.
+
+\indexitem{node key>Autoforward}|=|\meta{option}\meta{style definition}, \indexdef{node key>Autoforward register}|=|\meta{register}\meta{style definition}
+
+This is a more generic variant of autoforwarding. After the value of an option or register
+autoforwarded with this key is changed, the style defined by \meta{style definition} is called with
+the new option/register value as its argument.
+
+\begin{forestexample}[index={Autoforward,content,node options}]
+ \forestset{~Autoforward~={content}{node options={#1}}}
+ \begin{forest}
+ [red[blue][green]]
+ \end{forest}
+\end{forestexample}
+
+\indexitem{node key>unautoforward}|=|\meta{option or register} Undoes the autoforwarding of the
+option or register made by any of the autoforwarding keys.
+
+\indexitem{node key>content to}|=|\meta{key} When parsing the bracket representation of the tree,
+store the given content using \meta{key}|=|\meta{content}.
+
+\indexitem{node key>copy command key}|=|\meta{pgfkey: source}\meta{pgfkey: destination}
+
+ Copies the |pgf| key in a way that |.add code| and |.add style| handlers still work.
+
+\indexitem({{{{{}}}}}){register>default preamble}|=|\meta{keylist}
+ \itemnosep
+\indexitem{register>preamble}|=|\meta{keylist}
+
+ These registers hold the content of the default preamble and the preamble of the current tree.
+
+ |preamble| is set by the bracket parser. Set |default preamble| outside the \index{forest}
+ environment using \index{forestset}.
+
+ As |default preamble| and |preamble| are not styles but keylist registers, the |#| characters do
+ not need to be doubled: you can freely copy and paste your keylists between the node options of
+ the root node, the preamble and the default preamble. The only difference will be the order of
+ execution: first default preamble, then preamble, and finally the root node's options.
+
+\indexitem{node key>split}|=|\meta{toks}\meta{separator}\meta{keylist}
+ \itemnosep
+\indexitem{node key>split option}|=|\meta{option}\meta{separator}\meta{keylist}
+ \itemnosep
+\indexitem{node key>split register}|=|\meta{register}\meta{separator}\meta{keylist}
+
+Split \meta{toks} or the value of \meta{option} or \meta{register} at occurrences of
+\meta{separator} (which must be a single token), and process the keys in \meta{keylist} with the
+pieces of the split token list as arguments, in the order given.
+
+ The keys in \meta{keylist} can be any valid keys, including augmented assignments, non-current
+ option assignments, even \index{TeX}.
+
+ The difference in the number of split values and given keys is handled gracefully. If there is
+ not enough values, the superfluous keys are not processed; if there are too many values, the last
+ key is called repeatedly.
+
+ For an example, see \S\ref{sec:example-decision-tree}.
+
+\indexitem{node key>TeX}|=|\meta{toks: \TeX\ code} The given code is executed immediately.
+
+ This can be used for e.g.\ enumerating nodes:
+\begin{forestexample}[point=TeX,index={TeX,delay,where option,tier,content,GP1},label=ex:enumerate]
+ \newcount\xcount
+ \begin{forest} GP1,
+ delay={TeX={\xcount=0},
+ where tier={x}{TeX={\advance\xcount1},
+ content/.expanded={##1$_{\the\xcount}$}}{}}
+ [
+ [O[x[f]]]
+ [R[N[x[o]]]]
+ [O[x[r]]]
+ [R[N[x[e]]][x[s]]]
+ [O[x[t]]]
+ [R[N[x]]]
+ ]
+ \end{forest}
+\end{forestexample}
+
+\indexitem{node key>TeX'}|=|\meta{toks: \TeX\ code} This key is a combination of keys \index{TeX}
+and \index{TeX''}: the given code is both executed and externalized.
+
+\indexitem{node key>TeX''}|=|\meta{toks: \TeX\ code} The given code is externalized, i.e.\ it will be
+executed when the externalized images are loaded.
+
+The image-loading and \keyname{TeX'(')} produced code are intertwined.
+
+\indexitem{node key>typeout}|=|\meta{toks} A \foRest; version of \LaTeX\ macro |\typeout|. Useful
+for debugging, trust me on this one.
+
+\indexitem(node options){node key>unknown to}|=|\meta{key} Forward unknown keys to \meta{key}.
+
+\begin{advise}
+\item Do \emph{not} use handler |.unknown| to deal with unknown keys, as it is used internally by
+\foRest;, and is set up to make it possible to set options of non-current nodes (see
+\S\ref{sec:option-setting}).
+\end{advise}
+
+\indexitem{node key>unknown key error}|=|\meta{keyval} Produces an error.
+
+Write \index{unknown to}|=unknown key error| to produce an error when a key unknown to \foRest; is
+used.
+
+\end{syntax}
+
+
+
+\subsection{Options and registers}
+\label{sec:options-and-registers}
+
+\FoRest; introduces two types of data storage: \emph{node options} (or just \emph{options} for
+short) and \emph{registers}.
+
+Options store data related to particular nodes. Each node has its own set of option values, i.e.\
+the value of an option at some node is independent of its value at other nodes: in particular,
+setting an option of a node does \emph{not} set this option for the node's descendants. Register
+values are not associated to nodes.
+
+Note that option and register keys share the same ``namespace'' (|pgfkeys| path and |pgfmath|
+function names) so it is not possible to have an option and a register of the same name!
+
+\subsubsection{Setting}
+\label{sec:option-setting}
+
+The simplest way to set the value of an option or a register is to use the key of the same name.
+\begin{syntax}
+ \indexitem[index key={@@@opt},form={}]{prefix>assignment>current node=\meta{option}}|=|\meta{value}
+ Sets the value of \meta{option} of the current node to \meta{value}.
+
+ Note that option types \index{keylist} and \index{autowrapped toks} redefine this basic key.
+
+ \indexitem[index key={@@@reg},form={}]{prefix>assignment>current node=\meta{register}}|=|\meta{value}
+ Sets the value of \meta{register} to \meta{value}.
+
+ Note that register types \index{keylist} and \index{autowrapped toks} redefine this basic key.
+\end{syntax}
+
+Options can also be set for the non-current node:
+\begin{syntax}
+ % \indexitem[index key={@@@.},form={.},+print format={+result={\index(not print){relative node name}\index(not index)[+print format=definition]{relative node name}}},+index format={+result={\meta{relative node name}}}]{prefix>assignment>relative node=\meta{option}}|=|\meta{value}
+ \indexitem[index key={@@@.},form={.},+print format={+result={\index{relative node name}}},+index format={+result={\meta{relative node name}}}]{prefix>assignment>relative node=\meta{option}}|=|\meta{value}
+
+ Sets the value of \meta{option} of the node specified by \meta{relative node name} to \meta{value}.
+
+ Notes: \begin{enumerate*}[(i)]
+ \item\emph{\meta{value} is evaluated in the context of the current node.}
+ \item In general, the resolution of \meta{relative node name} depends on the
+ current node; see \S\ref{ref:relative-node-names}.
+ \item \meta{option} can also be an ``augmented assignment operator'' (see below) or, indeed, any
+ node key.
+ \end{enumerate*}
+\end{syntax}
+
+Additional keys for setting and modifying the value of an option or a register exist, depending on
+its data type. Informally, you can think of these keys as \emph{augmented operators} known from
+various programming languages.
+
+\begin{syntax}
+\indexitem{type>toks} contains \TeX's \meta{balanced text} \citep[275]{texbook}.
+
+ A toks \meta{option} additionally defines the following keys:
+ \begin{syntax}
+ \indexitem{suffix>augmented assignment=toks>+=\meta{option}}|=|\meta{toks} appends the given \meta{toks} to the
+ current value of the option.
+
+ \indexitem{prefix>augmented assignment=toks>+=\meta{option}}|=|\meta{toks} prepends the given \meta{toks} to the
+ current value of the option.
+
+ % \item \index{if in toks option=\meta{toks option}}| =|\meta{toks}\meta{true
+ % keylist}\meta{false keylist} checks if \meta{toks} occurs in the option value; if it does,
+ % \meta{true keylist} are executed, otherwise \meta{false keylist}.
+
+ % \item \index{where in toks option=\meta{toks option}}| =|\meta{toks}\meta{true
+ % keylist}\meta{false keylist} is a style equivalent to \index{for step=\index{tree}}|={|\keyname{if in }\meta{option}=\meta{toks}\meta{true keylist}\meta{false keylist}|}|: for every node in
+ % the subtree rooted in the current node, \keyname{if in }\meta{option} is executed in
+ % the context of that node.
+ \end{syntax}
+
+\indexitem{type>autowrapped toks} is a subtype of \index{toks} and contains \TeX's \meta{balanced
+text} \citep[275]{texbook}.
+
+ {\rstyle\meta{option}}|=|\meta{toks} of an autowrapped \meta{option} is redefined to
+ \meta{option}|/|\index{wrap value}|=|\meta{toks} of a normal \meta{toks} option.
+
+ Keyvals \indexdef{suffix>augmented assignment=autowrapped toks>+=\meta{option}}|=|\meta{toks} and
+ \indexdef{prefix>augmented assignment=autowrapped toks>+=\meta{option}}|=|\meta{toks} are redefined to
+ \index{toks+=\meta{option}}|/|\index{wrap value}|=|\meta{toks} and
+ \index{+toks=\meta{option}}|/|\index{wrap value}|=|\meta{toks}, respectively. The normal toks
+ behaviour can be accessed via keys \indexdef{suffix>augmented assignment=autowrapped toks>'=\meta{option}},
+ \indexdef{suffix>augmented assignment=autowrapped toks>+'=\meta{option}}, and
+ \indexdef[set={print format={result/.expanded=+\forestoption{argument}',pgfkey},index form=+\meta{autowrapped toks option}',index format=pgfkey,index key=+'}]{augmented assignment>+autowrapped toks'=\meta{option}}.
+
+\indexitem{type>keylist} is a subtype of \index{toks} and contains a comma-separated list of
+ \meta{key}[|=|\meta{value}] pairs.
+
+ Augmented assignment operators \indexdef{suffix>augmented assignment=keylist>+=\meta{option}} and
+ \indexdef{prefix>augmented assignment=keylist>+=\meta{option}} automatically insert a comma
+ before/after the appended/prepended material.
+
+ Augmented assignment operator \indexdef{suffix>augmented assignment=keylist>-=\meta{option}}|=|\meta{keylist} deletes the keys
+ from keylist \meta{option}. \meta{keylist} specifies which keys to delete. If a key is given no
+ value, all occurrences of that key will be deleted. If a key is given a value, only occurrences
+ with that value will be deleted. To delete occurrences without value, use special value
+ \indexdef{macro>forestnovalue}. (Note: if you include a key in \meta{keylist} more than once,
+ only the last occurrence counts.)
+
+ {\rstyle\meta{option}}|=|\meta{keylist} of a keylist option is redefined to
+ \meta{option}\keyname{+}|=|\meta{keylist}. In other words, keylists behave additively by
+ default. The rationale is that one usually wants to add keys to a keylist. The usual,
+ non-additive behaviour can be accessed by \indexdef{suffix>augmented assignment=keylist>'=\meta{option}}|=|\meta{keylist}.
+
+ Manipulating the keylist option using augmented assignments might have the side-effect of adding
+ an empty key to the list.
+
+\indexitem{type>dimen} contains a dimension.
+
+ The value given to a dimension option is automatically evaluated by |pgfmath|. In other words,
+ {\rstyle\meta{option}}|=|\meta{value} is implicitly understood as
+ \meta{option}|/|\index{pgfmath}|=|\meta{value}.
+
+ For a \meta{dimen} option \meta{option}, the following additional keys (``augmented
+ assignments'') are defined:
+ \begin{syntax}
+ \indexitem{suffix>augmented assignment=dimen>+=\meta{option}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()+|\meta{value}
+ \indexitem{suffix>augmented assignment=dimen>-=\meta{option}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()-|\meta{value}
+ \indexitem{suffix>augmented assignment=dimen>*=\meta{option}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()*|\meta{value}
+ \indexitem{suffix>augmented assignment=dimen>:=\meta{option}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()/|\meta{value}
+ \end{syntax}
+
+ The evaluation of \meta{pgfmath} can be quite slow. There are two tricks to speed things up
+ \emph{if} the \meta{pgfmath} expression is simple, i.e.\ just a \TeX\ \meta{dimen}:
+ \begin{enumerate}
+ \item |pgfmath| evaluation of simple values can be sped up by prepending |+| to the value
+ \citep[\S62.1]{tikzpgf2.10};
+ \item use the key \indexdef{suffix>augmented assignment=dimen>'=\meta{option}}|=|\meta{value} to invoke a normal \TeX\ assignment.
+ \end{enumerate}
+
+ The two above-mentioned speed-up tricks work for the augmented assignments as well. The keys for
+ the second, \TeX-only trick are: \indexdef{suffix>augmented assignment=dimen>'+}, \indexdef{suffix>augmented assignment=dimen>'-}, \indexdef{suffix>augmented assignment=dimen>'*}, \indexdef{suffix>augmented assignment=dimen>':} --- note that for the latter two,
+ the value should be an integer.
+
+\indexitem{type>count} contains an integer.
+
+ The additional keys and their behaviour are the same as for the \meta{dimen} options.%
+ \indexdef[not print]{suffix>augmented assignment=count>+}%
+ \indexdef[not print]{suffix>augmented assignment=count>-}%
+ \indexdef[not print]{suffix>augmented assignment=count>*}%
+ \indexdef[not print]{suffix>augmented assignment=count>:}%
+ \indexdef[not print]{suffix>augmented assignment=count>'}%
+ \indexdef[not print]{suffix>augmented assignment=count>'+}%
+ \indexdef[not print]{suffix>augmented assignment=count>'-}%
+ \indexdef[not print]{suffix>augmented assignment=count>'*}%
+ \indexdef[not print]{suffix>augmented assignment=count>':}%
+
+\indexitem{type>boolean} contains $0$ (false) or $1$ (true).
+
+ In the general case, the value given to a \meta{boolean} option is automatically
+ parsed by |pgfmath| (just as for \meta{count} and \meta{dimen}): if the computed value is
+ non-zero, $1$ is stored; otherwise, $0$ is stored. Note that |pgfmath| recognizes constants
+ |true| and |false|, so it is possible to write \meta{option}|=true| and
+ \meta{option}|=false|.
+
+ If key \meta{option} is given no argument, pgfmath evaluation does not apply and a true value is
+ set. To quickly set a false value, use key \indexdef{word prefix=boolean option>>not=\meta{option}} (with no arguments).
+\end{syntax}
+
+\subsubsection{Reading}
+\label{sec:option-reading}
+
+Option and register values can be accessed using the four macros listed below, handlers
+\index{handler>option} and \index{handler>register} (\S\ref{ref:handlers}) and |pgfmath| functions
+(\ref{ref:pgfmath}).
+
+\begin{syntax}
+ \indexitem{macro>forestoption}|{|\meta{option}|}|
+ \itemnosep
+ \indexitem{macro>foresteoption}|{|\meta{option}|}|
+ \itemnosep
+ \indexitem{macro>forestregister}|{|\meta{register}|}|
+ \itemnosep
+ \indexitem{macro>foresteregister}|{|\meta{register}|}|
+
+ These macros expand to the value of the given option or register. Note that
+ \index{macro>forestoption} and \index{macro>foresteoption} expand to the value of the given option
+ of the \emph{current node}; to access option values of a non-current node, use |pgfmath|
+ functions.
+
+ In the context of |\edef|, \cmdname{forestoption} and \cmdname{forestregister} expand precisely to
+ the token list of the option value, while \cmdname{foresteoption} and \cmdname{foresteregister}
+ fully expand the value.
+
+ \begin{advise}
+ \item These macros can be useful in \TeX\ code introduced by \index{TeX} or \PGF;'s handler
+ |.expanded| \citep[\S55.4.6]{tikzpgf2.10}.
+ \end{advise}
+\end{syntax}
+
+
+\subsubsection{Declaring}
+\label{sec:option-declaring}
+
+Using the following keys, users can also declare their own options and registers. The new options
+and registers will behave exactly like the predefined ones.
+
+Note that the declaration of an option must provide a default value, while the declaration of a
+register must not do that. The default value of an option will be assigned to any newly created
+nodes; the existing nodes are not affected.
+
+\begin{syntax}
+ \indexitem{node key>declare toks}|=|\meta{option name}\meta{default value}
+ Declares a \meta{toks} option.
+
+ \indexitem{node key>declare autowrapped toks}|=|\meta{option name}\meta{default value}
+ Declares an \meta{autowrapped toks} option.
+
+ \indexitem{node key>declare keylist}|=|\meta{option name}\meta{default value}
+ Declares a \meta{keylist} option.
+
+ \indexitem{node key>declare dimen}|=|\meta{option name}\meta{default value}
+ Declares a \meta{dimen} option.
+
+ \indexitem{node key>declare count}|=|\meta{option name}\meta{default value}
+ Declares a \meta{count} option.
+
+ \indexitem{node key>declare boolean}|=|\meta{option name}\meta{default value}
+ Declares a \meta{boolean} option.
+
+ \indexitem{node key>declare toks register}|=|\meta{register name}
+ Declares a \meta{toks} register.
+
+ \indexitem{node key>declare autowrapped toks register}|=|\meta{register name}
+ Declares an \meta{autowrapped toks} register.
+
+ \indexitem{node key>declare keylist register}|=|\meta{register name}
+ Declares a \meta{keylist} register.
+
+ \indexitem{node key>declare dimen register}|=|\meta{register name}
+ Declares a \meta{dimen} register.
+
+ \indexitem{node key>declare count register}|=|\meta{register name}
+ Declares a \meta{count} register.
+
+ \indexitem{node key>declare boolean register}|=|\meta{register name}
+ Declares a \meta{boolean} register.
+\end{syntax}
+
+Several scratch registers are predefined:
+\begin{syntax}
+ \indexitem{register>temptoksa}, \indexdef{register>temptoksb}, \indexdef{register>temptoksc}, \indexdef{register>temptoksd} Predefined \meta{toks} registers.
+
+ \indexitem{register>tempkeylista}, \indexdef{register>tempkeylistb}, \indexdef{register>tempkeylistc}, \indexdef{register>tempkeylistd} Predefined \meta{keylist} registers.
+
+ \indexitem{register>tempdima}, \indexdef{register>tempdimb}, \indexdef{register>tempdimc}, \indexdef{register>tempdimd}, \indexdef{register>tempdimx}, \indexdef{register>tempdimy}, \indexdef{register>tempdiml}, \indexdef{register>tempdims} Predefined \meta{dimen} registers.
+
+ \indexitem{register>tempcounta}, \indexdef{register>tempcountb}, \indexdef{register>tempcountc}, \indexdef{register>tempcountd} Predefined \meta{count} registers.
+
+ \indexitem{register>tempboola}, \indexdef{register>tempboolb}, \indexdef{register>tempboolc}, \indexdef{register>tempboold} Predefined \meta{boolean} registers.
+\end{syntax}
+
+
+
+\subsection{Formatting the tree}
+\label{sec:formatting-tree}
+
+
+\subsubsection{Node appearance}
+\label{ref:node-appearance}
+
+The following options apply at stage \index{typeset nodes}. Changing them
+afterwards has no effect in the normal course of events.
+
+\begin{syntax}
+\indexitem({{{{{}}}}}){option>align}|=|\index{value=align>left}\OR\index{value=align>center}\OR\index{value=align>right}\OR\meta{toks: tabular header}
+
+ Creates a left/center/right-aligned multiline node, or a tabular node. In the
+ \index{content} option, the lines of the node should separated by |\\| and the columns (if
+ any) by |&|, as usual.
+
+ The vertical alignment of the multiline/tabular node can be specified by option \index{base}.
+
+\begin{forestexample}[index={l sep,align,base}]
+ \begin{forest} l sep+=2ex
+ [special value&actual value\\\hline
+ \indexdef{value=align>left}&||\texttt{@\{\}l@\{\}}\\
+ \indexdef{value=align>center}&||\texttt{@\{\}c@\{\}}\\
+ \indexdef{value=align>right}&||\texttt{@\{\}r@\{\}}\\
+ ,~align~=ll,draw
+ [top base\\right aligned, ~align~=right,~base~=top]
+ [left aligned\\bottom base, ~align~=left,~base~=bottom]
+ ]
+ \end{forest}
+\end{forestexample}
+
+ Internally, setting this option has two effects:
+ \begin{enumerate}
+ \item The option value (a |tabular| environment header specification) is set. The special
+ values \keyname{left}, \keyname{center} and \keyname{right} invoke styles setting the actual
+ header to the value shown in the above example.
+ \begin{advise}
+ \item If you know that the \keyname{align} was set with a special value, you can easily check
+ the value using \index{if in toks option=\index{align}}.
+ \end{advise}
+ \item Option \index{content format} is set to the following value:
+ \begin{lstlisting}
+ \noexpand\begin{tabular}[\forestoption{base}]{\forestoption{align}}%
+ \forestoption{content}%
+ \noexpand\end{tabular}%
+ \end{lstlisting}
+ As you can see, it is this value that determines that options \keyname{base}, \keyname{align} and
+ \keyname{content} specify the vertical alignment, header and content of the table.
+ \end{enumerate}
+
+\indexitem(t){option>base}|=|\meta{toks: vertical alignment}
+
+This option controls the vertical alignment of multiline (and in general, \texttt{tabular}) nodes
+created with \index{align}. Its value becomes the optional argument to the \texttt{tabular}
+environment. Thus, sensible values are \indexdef{value=base>t} (the top line of the table will
+be the baseline) and \indexdef{value=base>b} (the bottom line of the table will be the baseline).
+Note that this will only have effect if the node is anchored on a baseline, like in the default
+case of \index{option>anchor}|=base|.
+
+For readability, you can use \indexdef{value=base>top} and \indexdef{value=base>bottom} instead
+of \keyname{t} and \keyname{b}. (\keyname{top} and \keyname{bottom} are still stored as
+\keyname{t} and \keyname{b}.)
+
+ \indexitem({{{{{}}}}}){option>content}|=|\meta{autowrapped toks} The content of the node.
+
+ Normally, the value of option \keyname{content} is given implicitely by virtue of the special
+ (initial) position of content in the bracket representation (see~\S\ref{ref:bracket}). However,
+ the option also be set explicitely, as any other option.
+
+\begin{forestexample}[index={for step,tree,if option,option>n,option>n'},point={content,delay},index={content,delay}]
+ \begin{forest}
+ delay={for tree={
+ if n=1{content=L}
+ {if n'=1{content=R}
+ {content=C}}}}
+ [[[][][]][[][][]]]
+ \end{forest}
+\end{forestexample}
+ Note that the execution of the \keyname{content} option should usually be delayed: otherwise, the
+ implicitely given content (in the example below, the empty string) will override the explicitely
+ given content.
+
+\begin{forestexample}[index={for step,tree,if option,option>n,option>n',content},point={content}]
+ \begin{forest}
+ for tree={
+ if n=1{content=L}
+ {if n'=1{content=R}
+ {content=C}}}
+ [[[][][]][[][][]]]
+ \end{forest}
+\end{forestexample}
+
+ \indexitem(\forestoption{content}){option>content format}|=|\meta{toks}
+
+ When typesetting the node under the default conditions (see option \index{node format}), the
+ value of this option is passed to the \TikZ; \texttt{node} operation as its \meta{text} argument
+ \citep[\S16.2]{tikzpgf2.10}. The default value of the option simply puts the content in the
+ node.
+
+ This is a fairly low level option, but sometimes you might still want to change its value. If
+ you do so, take care of what is expanded when. Most importantly, if you use a formatting
+ command such as |\textbf| in the default setting of \index{node format}, be sure to precede
+ it with |\noexpand|. For details, read the documentation of option \index{node format} and
+ macros \index{forestoption} and \index{foresteoption}; for an example, see option
+ \index{align}.
+
+\indexitem{node key>math content} Changes \index{content format} so that the content of the node
+ will be typeset in a math environment.
+
+\indexitem{node key>plain content} Resets \index{content format} to the default value.
+
+\indexitem{option>node format}|=|\meta{toks}
+ \hfill|\noexpand\node(\forestoption{name})|\\
+ \mbox{}\hfill|[\forestoption{node options}]{\foresteoption{content format}};|
+
+ The node is typeset by executing the expansion of this option's value in a |tikzpicture|
+ environment.
+
+ Important: the value of this option is first expanded using |\edef| and only then executed. Note
+ that in its default value, \index{content format} is fully expanded using
+ \index{foresteoption}: this is necessary for complex content formats, such as |tabular|
+ environments.
+
+ This is a low level option. Ideally, there should be no need to change its value. If you do,
+ note that the \TikZ; node you create should be named using the value of option \index{option>name};
+ otherwise, parent--child edges can't be drawn, see option \index{edge path}.
+
+\indexitem{node key>node format'}|=|\meta{toks}
+
+Sets \index{node format}, automatically wrapping the given \meta{toks} by
+|\noexpand\node(\forestoption{name})| and |;|. Only the node options and content must therefore be
+given.
+
+\indexitem(anchor=base){option>node options}|=|\meta{keylist}
+
+ When the node is being typeset under the default conditions (see option \index{node format}),
+ the content of this option is passed to \TikZ; as options to the
+ \TikZ; |node| operation \citep[\S16]{tikzpgf2.10}.
+
+ This option is rarely manipulated manually: almost all options unknown to \foRest; are
+ automatically appended to \keyname{node options}. Exceptions are (i) \index{label} and
+ \index{pin}, which require special attention in order to work; and (ii) \index{option>anchor},
+ which is saved in order to retain the information about the selected anchor.
+
+\begin{forestexample}[index={for step,descendants,option>anchor,option>child anchor,option>parent anchor,grow,l sep,tree,propagator>where,delay,content,node options,pgfmath}]
+ \begin{forest}
+ for descendants={anchor=east,child anchor=east},
+ grow=west,anchor=north,parent anchor=north,
+ l sep=1cm,
+ for tree={~fill=yellow~},where={n()<=3}{~draw=red~}{},
+ delay={for tree={content/.pgfmath=~node_options~}}
+ [root,rotate=90,
+ [,~fill=white~]
+ [,~node options'~]
+ []
+ []
+ [,~node options~={~ellipse~}]
+ ]
+ \end{forest}
+\end{forestexample}
+
+\indexitem(false){option>phantom}|=|\meta{boolean}
+
+ A phantom node and its surrounding edges are taken into account when packing, but not
+ drawn. (This option applies in stage \index{draw tree}.)
+\begin{forestexample}[point=phantom,index={option>phantom}]
+ \begin{forest}
+ [VP[DP][V',phantom[V][DP]]]
+ \end{forest}
+\end{forestexample}
+
+\end{syntax}
+
+
+
+\subsubsection{Node position}
+\label{ref:ref-node-position}
+
+Most of the following options apply at stage \index{pack}. Changing them afterwards has no effect
+in the normal course of events. (Options \index{option>l}, \index{option>s}, \index{x}, \index{y} and
+\index{option>anchor} are exceptions; see their documentation for details).
+
+\begin{syntax}
+
+ \indexitem(base){option>anchor}|=|\meta{toks: \foRest; anchor}
+
+ This is essentially a \TikZ; option \citep[see][\S16.5.1]{tikzpgf2.10} --- it is
+ \index{autoforward}ed to \TikZ; via option \index{node options} when the node is typeset (this
+ option thus applies in stage \index{typeset nodes}) --- but it is also saved by \foRest;.
+
+ The effect of this option is only observable when a node has a sibling: the anchors of all
+ siblings are s-aligned (if their \index{option>l}s have not been modified after packing).
+
+ In the \TikZ; code, you can refer to the node's anchor using \FoRest;'s anchor
+ \index{anchor>anchor}.
+
+ \meta{toks: \foRest; anchor} can be any \TikZ; anchor. Additionally, \FoRest; defines several tree hierarchy related anchors; for details, see \S\ref{sec:anchors}.
+
+ \indexitem(center){option>calign}|=|\alternative{child,child edge,midpoint,edge midpoint,fixed
+ angles,fixed edge angles}\\\alternative{first,last,center}.
+
+ The packing algorithm positions the children so that they don't overlap, effectively computing
+ the minimal distances between the node anchors of the children. This option (\keyname{calign}
+ stands for child alignment) specifies how the children are positioned
+ with respect to the parent (while respecting the above-mentioned minimal distances).
+
+ The child alignment methods refer to the primary and the secondary child, and to the primary and
+ the secondary angle. These are set using the keys described just after \keyname{calign}.
+
+ \let\outerleftmargin\leftmargin
+ \begin{syntax}
+ \item\keyname{calign}|=|\indexdef{value=calign>child} s-aligns the node anchors of the parent and
+ the primary child.
+ \item\keyname{calign}|=|\indexdef{value=calign>child edge} s-aligns the parent anchor of the parent
+ and the child anchor of the primary child.
+ \item \keyname{calign}|=|\indexdef{value=calign>first} is an abbreviation for
+ |calign=child,calign_child=1|.
+ \item \keyname{calign}|=|\indexdef{value=calign>last} is an abbreviation for
+ |calign=child,calign_child=-1|.
+ \item\keyname{calign}|=|\indexdef{value=calign>midpoint} s-aligns the parent's node anchor and the
+ midpoint between the primary and the secondary child's node anchor.
+ \item\keyname{calign}|=|\indexdef{value=calign>edge midpoint} s-aligns the parent's parent anchor
+ and the midpoint between the primary and the secondary child's child anchor.
+ \item \keyname{calign}|=|\indexdef{value=calign>center} is an abbreviation for\\
+ |calign=midpoint,| |calign_primary_child=1,| |calign_secondary_child=-1|.
+\begin{forestexample}
+ \begin{forest}
+ [center,calign=center[1]
+ [first,calign=first[A][B][C]][3][4][5][6]
+ [last,calign=last[A][B][C]][8]]
+ \end{forest}
+\end{forestexample}
+ \item\keyname{calign}|=|\indexdef{value=calign>fixed angles}: The angle between the direction of
+ growth at the current node (specified by option \index{grow}) and the line through the node
+ anchors of the parent and the primary/secondary child will equal the primary/secondary angle.
+
+ To achieve this, the block of children might be spread or further distanced from the parent.
+ \item\keyname{calign}|=|\indexdef{value=calign>fixed edge angles}: The angle between the direction of
+ growth at the current node (specified by option \index{grow}) and the line through the
+ parent's parent anchor and the primary/secondary child's child anchor will equal the
+ primary/secondary angle.
+
+ To achieve this, the block of children might be spread or further distanced from the parent.
+\begin{forestexample}[point=calign,index={calign,fixed edge angles,calign primary angle,calign secondary angle,for step,tree,option>l},index>={!}]
+ \begin{forest}
+ calign=fixed edge angles,
+ calign primary angle=-30,calign secondary angle=60,
+ for tree={l=2cm}
+ [CP[C][TP]]
+ \draw[dotted] (!1) -| coordinate(p) () (!2) -| ();
+ \path ()--(p) node[pos=0.4,left,inner sep=1pt]{-30};
+ \path ()--(p) node[pos=0.1,right,inner sep=1pt]{60};
+ \end{forest}
+\end{forestexample}
+ \end{syntax}
+\indexitem{option>calign child}|=|\meta{count} is an abbreviation for \index{calign primary
+ child}|=|\meta{count}.
+\indexitem(1){option>calign primary child}|=|\meta{count} Sets the primary child.
+ (See \index{calign}.)
+
+ \meta{count} is the child's sequence number. Negative numbers start counting at the last child.
+\indexitem(-1){option>calign secondary child}|=|\meta{count} Sets the secondary child.
+ (See \index{calign}.)
+
+ \meta{count} is the child's sequence number. Negative numbers start counting at the last child.
+\indexitem{option>calign angle}|=|\meta{count} is an abbreviation for \index{calign primary
+ angle}|=-|\meta{count}, \index{calign secondary angle}|=|\meta{count}.
+\indexitem(-35){option>calign primary angle}|=|\meta{count} Sets the primary angle.
+ (See \index{calign}.)
+\indexitem(35){option>calign secondary angle}|=|\meta{count} Sets the secondary angle.
+ (See \index{calign}.)
+\indexitem{option>calign with current} s-aligns the node anchors of the current node and its
+ parent. This key is an abbreviation for:\\
+ |for_parent/.wrap_pgfmath_arg={calign=child,calign primary child=##1}{n}|.
+\indexitem{option>calign with current edge} s-aligns the child anchor of the current node and the
+ parent anchor of its parent. This key is an abbreviation for:\\
+ |for_parent/.wrap_pgfmath_arg={calign=child edge,calign primary child=##1}{n}|.
+
+ \indexitem(tight){option>fit}|=|\alternative{tight,rectangle,band}
+
+\begin{forestexample}[layout=export,basicstyle=\footnotesize\ttfamily]
+ \makeatletter\tikzset{use path/.code={\tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}
+ \appto\tikz@preactions{\let\tikz@actions@path#1}}}\makeatother
+ \forestset{show boundary/.style={
+ before drawing tree={get min s tree boundary=\minboundary, get max s tree boundary=\maxboundary},
+ tikz+={\draw[red,use path=\minboundary]; \draw[red,use path=\maxboundary];}}}
+\end{forestexample}
+\input{\jobname.tmp}
+
+This option sets the type of the (s-)boundary that will be computed for the subtree rooted in the
+node, thereby determining how it will be packed into the subtree rooted in the node's parent.
+There are three choices:\footnote{Below is the definition of style \keyname{show boundary}. The
+\keyname{use path} trick is adjusted from \TeX\ Stackexchange question
+\href{http://tex.stackexchange.com/questions/26382/calling-a-previously-named-path-in-tikz}{Calling
+a previously named path in tikz}.
+
+\box\codebox}
+ \begin{itemize}
+ \item\keyname{fit}|=|\indexdef{value=fit>tight}: an exact boundary of the node's subtree is computed,
+ resulting in a compactly packed tree. Below, the boundary of subtree L is drawn.
+\begin{forestexample}[point={fit,tight},index={fit,{value=fit>tight},delay,for step,tree,option>name,content,pgfmath}]
+ \begin{forest}
+ delay={for tree={name/.pgfmath=content}}
+ [root
+ [L,fit=tight, % default
+ show boundary
+ [L1][L2][L3]]
+ [R]
+ ]
+ \end{forest}
+\end{forestexample}
+\makeatletter\tikzset{use path/.code={%
+ \tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}%
+ \appto\tikz@preactions{\let\tikz@actions@path#1}%
+ }}\makeatother
+\item\keyname{fit}|=|\indexdef{value=fit>rectangle}: puts the node's subtree in a rectangle and effectively
+ packs this rectangle; the resulting tree will usually be wider.
+\begin{forestexample}[point={fit,rectangle},index={fit,{value=fit>rectangle},delay,for step,tree,option>name,content,pgfmath}]
+ \begin{forest}
+ delay={for tree={name/.pgfmath=content}}
+ [root
+ [L,fit=rectangle,
+ show boundary
+ [L1][L2][L3]]
+ [R]
+ ]
+ \end{forest}
+\end{forestexample}
+\item\keyname{fit}|=|\indexdef{value=fit>band}: puts the node's subtree in a rectangle of ``infinite
+ depth'': the space under the node and its descendants will be kept clear.
+\begin{forestexample}[point={fit,band},index={fit,{value=fit>band},delay,for step,tree,option>name,content,pgfmath}]
+ \begin{forest}
+ delay={for tree={name/.pgfmath=content}}
+ [root
+ [L[L1][L2][L3]]
+ [C,fit=band]
+ [R[R1][R2][R3]]
+ ]
+ \draw[thin,red]
+ (C.south west)--(C.north west)
+ (C.north east)--(C.south east);
+ \draw[thin,red,dotted]
+ (C.south west)--+(0,-1)
+ (C.south east)--+(0,-1);
+ \end{forest}
+\end{forestexample}
+ \end{itemize}
+
+\indexitem(270){option>grow}|=|\meta{count}, \indexdef{node key>grow'}|=|\meta{count},
+ \indexdef{node key>grow''}|=|\meta{count}
+
+ The direction of the tree's growth at the node.
+
+ The growth direction is understood as in \TikZ;'s tree library \citep[\S18.5.2]{tikzpgf2.10}
+ when using the default growth method: the (node anchor's of the) children of the node are placed
+ on a line orthogonal to the current direction of growth. (The final result might be different,
+ however, if \index{option>l} is changed after packing or if some child undergoes tier alignment.)
+
+ This option is essentially numeric (|pgfmath| function \keyname{grow} will always return an
+ integer), but there are some twists. The growth direction can be specified either numerically
+ or as a compass direction (|east|, |north east|, \dots). Furthermore, like in \TikZ;, setting
+ the growth direction using key \keyname{grow} additionally sets the value of option
+ \index{reversed} to |false|, while setting it with \keyname{grow'} sets it to |true|; to
+ change the growth direction without influencing \index{reversed}, use key \index{grow''}.
+
+ Between stages \index{pack} and \index{compute xy}, the value of \keyname{grow} should not
+ be changed.
+
+\begin{forestexample}[index={delay,where in toks option,content,for step,current,grow,grow',grow'',pgfmath}]
+ \begin{forest}
+ delay={where in content={~grow~}{
+ for current/.pgfmath=content,
+ content=\texttt{#1}
+ }{}
+ }
+ [{~grow~=south}
+ [{~grow'~=west}[1][2][3]
+ [{~grow''~=90}[1][2][3]]]
+ [2][3][4]
+ [{~grow~=east}[1][2][3]
+ [{~grow''~=90}[1][2][3]]]]
+ \end{forest}
+\end{forestexample}
+
+\indexitem(false){option>ignore}|=|\meta{boolean}
+
+If this option is set, the packing mechanism ignores the node, i.e.\ it pretends that the node has
+no boundary. Note: this only applies to the node, not to the tree.
+
+Maybe someone will even find this option useful for some reason \dots
+
+\indexitem(false){option>ignore edge}|=|\meta{boolean}
+
+If this option is set, the packing mechanism ignores the edge from the node to the parent, i.e.\
+nodes and other edges can overlap it. (See \S\ref{sec:bugs} for some problematic situations.)
+
+\begin{forestexample}[index={ignore edge,option>l,dimen*=l}]
+ \begin{forest}
+ [A[B[B][B][B][B]][C
+ [\texttt{not ignore edge},l*=2]]]
+ \end{forest}
+ \begin{forest}
+ [A[B[B][B][B][B]][C
+ [\texttt{ignore edge},l*=2,~ignore edge~]]]
+ \end{forest}
+\end{forestexample}
+
+\indexitem{option>l}|=|\meta{dimen} The l-position of the node, in the parent's ls-coordinate system. (The
+origin of a node's ls-coordinate system is at its (node) anchor. The l-axis points in the
+direction of the tree growth at the node, which is given by option \index{grow}. The s-axis is
+orthogonal to the l-axis; the positive side is in the counter-clockwise direction from |l| axis.)
+
+The initial value of \keyname{l} is set from the standard node. By default, it equals:
+\[\index{l sep}+2\cdot\mbox{\texttt{outer ysep}}+\mbox{total
+height(standard node)}\]
+
+The value of \keyname{l} can be changed at any point, with different effects.
+\begin{itemize}
+\item The value of \keyname{l} at the beginning of stage \index{pack} determines the minimal
+ l-distance between the anchors of the node and its parent. Thus, changing \keyname{l} before
+ packing will influence this process. (During packing, \keyname{l} can be increased due to
+ parent's \index{l sep}, tier alignment, or \index{calign} methods
+ \index{fixed angles} and \index{fixed edge angles}.
+
+\item Changing \keyname{l} after packing but before stage \index{compute xy} will result in a
+ manual adjustment of the computed position. (The augmented assignment operators can be useful here.)
+
+\item Changing \keyname{l} after the absolute positions have been computed has no effect in the
+ normal course of events.
+\end{itemize}
+
+\indexitem{option>l sep}|=|\meta{dimen} The minimal l-distance between the node and its
+descendants.
+
+This option determines the l-distance between the \emph{boundaries} of the node and its descendants,
+not node anchors. The final effect is that there will be a \keyname{l sep} wide band,
+in the l-dimension, between the node and all its descendants.
+
+The initial value of \keyname{l sep} is set from the standard node and equals
+\[\mbox{height}(\mbox{strut})+\mbox{\texttt{inner ysep}}\]
+
+Note that despite the similar name, the semantics of \keyname{l sep} and \keyname{s sep} are
+quite different.
+
+\indexitem(false){option>reversed}|=|\meta{boolean}
+
+If |false|, the children are positioned around the node in the counter-clockwise direction; if
+|true|, in the clockwise direction. See also \index{grow}.
+
+\indexitem(0){option>rotate}|=|\meta{count}
+
+This option is saved and \index{autoforward}ed to \TikZ;'s |\node| command via \index{node options}.
+
+\indexitem{option>s}|=|\meta{dimen} The s-position of the node, in the parent's ls-coordinate system.
+(The origin of a node's ls-coordinate system is at its (node) anchor. The l-axis points in the
+direction of the tree growth at the node, which is given by option \index{grow}. The s-axis is
+orthogonal to the l-axis; the positive side is in the counter-clockwise direction from |l| axis.)
+
+The value of \keyname{s} is computed in stage \index{pack stage} and used in stage \index{compute xy
+ stage}, so it only makes sense to (inspect and) change it in \index{before computing xy} and
+during packing (\index{before packing node} and \index{after packing node}). \emph{Any value given
+ before packing is overridden, and changing the value after computing xy has no effect.}
+
+For example, consider the manual correction below. By default, B is closer to A than C because
+packing proceeds from the first to the last child --- the position of B would be the same if there
+was no C. Adjusting \keyname{s} at the right moment, it is easy to center B between A and C.
+\begin{forestexample}[tree bin=minipage,point=s,index={before computing xy,option>s}]
+ \begin{forest}
+ [no manual correction of B
+ [A[1][2][3][4]]
+ [B]
+ [C[1][2][3][4]]
+ ]
+ \end{forest}
+
+ \begin{forest}
+ [manual correction of B
+ [A[1][2][3][4]]
+ [B,before computing xy={s/.average={s}{siblings}}]
+ [C[1][2][3][4]]
+ ]
+ \end{forest}
+\end{forestexample}
+
+\indexitem{option>s sep}|=|\meta{dimen}
+
+The subtrees rooted in the node's children will be kept at least \keyname{s sep} apart in the
+s-dimension. Note that \keyname{s sep} is about the minimal distance between node
+\emph{boundaries}, not node anchors.
+
+The initial value of \keyname{s sep} is set from the standard node and equals
+$2\cdot\mbox{\texttt{inner xsep}}$.
+
+Note that despite the similar name, the semantics of \keyname{s sep} and \keyname{l sep} are
+quite different.
+
+\indexitem({{{{{}}}}}){option>tier}|=|\meta{toks}
+
+Setting this option to something non-empty ``puts a node on a tier.'' All the nodes on the same
+tier are aligned in the l-dimension.
+
+Tier alignment across changes in growth direction is impossible. In the case of incompatible
+options, \foRest; will yield an error.
+
+Tier alignment also does not work well with \index{calign}|=|\index{fixed angles} and \index{calign}|=|\index{fixed edge angles}, because these child alignment methods may change the
+l-position of the children. When this might happen, \foRest; will yield a warning.
+
+\indexitem{option>x}=\meta{dimen}
+\vspace{-\parskip}
+\indexitem{option>y}=\meta{dimen}
+
+\keyname{x} and \keyname{y} are the coordinates of the node in the ``normal'' (paper) coordinate
+system, relative to the root of the tree that is being drawn. So, essentially, they are absolute
+coordinates.
+
+The values of \keyname{x} and \keyname{y} are computed in stage \index{compute xy}. It only
+makes sense to inspect and change them (for manual adjustments) afterwards (normally, in the
+\index{before drawing tree} hook, see \S\ref{ref:stages}.) \keyname{x} and \keyname{y} of the
+(formal) root node are exceptions, as they are not changed in stage \index{compute xy}.
+\begin{forestexample}[label=ex:adjustxy,index={y,dimen-,grow',option>l,for step,tree,before drawing tree}]
+ \begin{forest}
+ for tree={grow'=45,l=1.5cm}
+ [A[B][C][D,before drawing tree={~y-~=4mm}[1][2][3][4][5]][E][F]]
+ \end{forest}
+\end{forestexample}
+
+\end{syntax}
+
+\subsubsection{Edges}
+\label{ref:ref-edge}
+
+These options determine the shape and position of the edge from a node to its parent. They apply
+at stage \index{draw tree}.
+
+\begin{syntax}
+\indexitem({{{{{}}}}}){option>child anchor}|=|\meta{toks: \foRest; anchor} See \index{option>parent anchor}.
+
+\indexitem(draw){option>edge}|=|\meta{keylist}
+
+ When \index{edge path} has its default value, the value of this option is passed as options to
+ the \TikZ; |\path| expression used to draw the edge between the node and its parent.
+
+ Also see key \index{no edge}.
+
+\begin{forestexample}[point=edge,index={edge,no edge,for step,tree,grow',option>l,option>anchor,option>child anchor}]
+ \begin{forest} for tree={grow'=0,l=2cm,anchor=west,child anchor=west},
+ [root
+ [normal]
+ [none,~no~ edge]
+ [dotted,edge=dotted]
+ [dashed,edge=dashed]
+ [dashed,edge={dashed,red}]
+ ]
+ \end{forest}
+\end{forestexample}
+
+\indexitem({{{{{}}}}}){option>edge label}|=|\meta{toks: \TikZ; code}
+
+When \index{edge path} has its default value, the value of this option is used at the end of
+the edge path specification to typeset a node (or nodes) along the edge.
+
+The packing mechanism is not sensitive to edge labels.
+
+\begin{forestexample}[index={edge label}]
+ \begin{forest}
+ [VP
+ [V,~edge label~={node[midway,left,font=\scriptsize]{head}}]
+ [DP,~edge label~={node[midway,right,font=\scriptsize]{complement}}]
+ ]
+ \end{forest}
+\end{forestexample}
+
+\indexitem{option>edge path}|=|\meta{toks: \TikZ; code}
+ \hfill |\noexpand\path[|\index{forestoption}|{|\index{edge}|}]|\\
+ \mbox{}\hfill |(|\index>{!}|u.|\index{anchor>parent anchor}|)--(.|\index{anchor>child anchor}|)|\index{forestoption}|{|\index{edge label}|};|
+
+This option contains the code that draws the edge from the node to its parent. By default, it
+creates a path consisting of a single line segment between the node's \index{option>child anchor} and
+its parent's \index{option>parent anchor}. Options given by \index{edge} are passed to the path; by
+default, the path is simply drawn. Contents of \index{edge label} are used to potentially place
+a node (or nodes) along the edge.
+
+When specifying the edge path, the values of options \index{edge} and \index{edge label} can be
+used. Furthermore, two anchors, \index{anchor>parent anchor} and \index{anchor>child anchor}, are defined,
+to facilitate access to options \index{option>parent anchor} and \index{option>child anchor} from the \TikZ; code.
+
+The node positioning algorithm is sensitive to edges, i.e.\ it will avoid a node overlapping an
+edge or two edges overlapping. However, the positioning algorithm always behaves as if the
+\keyname{edge path} had the default value --- \emph{changing the \keyname{edge path} does not
+influence the packing!} Sorry. (Parent--child edges can be ignored, however: see option
+\index{ignore edge}.)
+
+\indexitem{node key>edge path'}|=|\meta{toks: \TikZ; code}
+
+Sets \index{edge path}, automatically wrapping the given path by
+|\noexpand\path[\forestoption{edge}]| and |\forestoption{edge label};|.
+
+\indexitem({{{{{}}}}}){option>parent anchor}|=|\meta{toks: \foRest; anchor} (Information also applies to
+option \index{option>child anchor}.)
+
+\FoRest; defines anchors \index{anchor>parent anchor} and
+\index{anchor>child anchor} (which work only for \foRest; and not also \TikZ;
+nodes, of course) to facilitate reference to the desired endpoints of child--parent edges.
+Whenever one of these anchors is invoked, it looks up the value of the \keyname{parent anchor} or
+\keyname{child anchor} of the node named in the coordinate specification, and forwards the request
+to the (\TikZ;) anchor given as the value.
+
+The indented use of the two anchors is chiefly in \index{edge path} specification, but they can
+used in any \TikZ; code.
+\begin{forestexample}[index={anchor>parent anchor,anchor>child anchor,for step,tree},index>={!}]
+ \begin{forest}
+ for tree={~parent anchor~=south,~child anchor~=north}
+ [VP[V][DP]]
+ \path[fill=red] (.parent anchor) circle[radius=2pt]
+ (!1.child anchor) circle[radius=2pt]
+ (!2.child anchor) circle[radius=2pt];
+ \end{forest}
+\end{forestexample}
+
+The empty value (which is the default) is interpreted as in \TikZ;: as an edge to the appropriate
+border point. See also \S\ref{sec:anchors} for a list of additional anchors defined by \foRest;.
+
+\indexitem{node key>no edge} Clears the edge options (\index{edge}|'={}|) and sets \index{ignore
+edge}.
+
+\end{syntax}
+
+\subsubsection{Information about node}
+\label{ref:node-info}
+\label{ref:readonly-options}
+
+The values of these options provide various information about the tree and its nodes.
+
+\begin{syntax}
+\indexitem{node key>alias}|=|\meta{toks}
+\itemnosep
+\indexitem{node key>alias'}|=|\meta{toks} Sets the alias for the node's name.
+
+ Unlike \index{option>name}, \keyname{alias} is \emph{not} an option: you cannot e.g.\ query it's
+ value via a |pgfmath| expression.
+
+ If the given alias clashes with an existing node name, |alias| will yield an error, while |alias'|
+ will silently rename the node with this name to its default (|node@|\meta{id}) value. Use an
+ empty argument to reset the node's name to its default value.
+
+ Aliases can be used as the \meta{forest node name} part of a relative node name and as the
+ argument to the \index{step>name} step of a node walk. The latter includes the usage
+ as the argument of the \index{for step=\index{step>name}} propagator.
+
+ Technically speaking, \foRest; alias is \emph{not} a \TikZ; alias! However, you can still use
+ it as a ``node name'' in \TikZ; coordinates, since \foRest; hacks \TikZ;'s implicit node
+ coordinate system to accept relative node names; see \S\ref{ref:forest-cs}.
+
+\indexitem{readonly option>id}|=|\meta{count} The internal id of the node.
+
+\indexitem{readonly option>level}|=|\meta{count} The hierarchical level of the node. The root is on level $0$.
+
+\indexitem{readonly option>max x}|=|\meta{dimen} \vspace{-\parskip}
+\indexitem{readonly option>max y}|=|\meta{dimen} \vspace{-\parskip}
+\indexitem{readonly option>min x}|=|\meta{dimen} \vspace{-\parskip}
+\indexitem{readonly option>min y}|=|\meta{dimen}
+ Measures of the node, in the shape's coordinate system
+ \citep[see][\S16.2,\S48,\S75]{tikzpgf2.10} shifted so that the node anchor is at the origin.
+
+ In |pgfmath| expressions, these options are accessible as |max__x|, |max__y|, |min__x| and |min__y|.
+
+\indexitem{readonly option>n}|=|\meta{count} The child's sequence number in the list of its parent's
+ children.
+
+ The enumeration starts with 1. For a geometric root, \keyname{n} equals $0$.
+
+\indexitem{readonly option>n'}|=|\meta{count} Like \index{option>n}, but starts counting at the last child.
+
+ In |pgfmath| expressions, this option is accessible as |n__|.
+
+\indexitem(node@\meta{id}){option>name}|=|\meta{toks}
+\itemnosep
+\indexitem{node key>name'}|=|\meta{toks} Sets the name of the node.
+
+The expansion of \meta{toks} becomes the \meta{forest node name} of the node. The \TikZ; node
+created from the \foRest; node will get the name specified by this option.
+
+Node names must be unique. If a node with the given name already exists, |name| will yield an
+error, while |name'| will silently rename the node with this name to its default (|node@|\meta{id})
+value. Use an empty argument to reset the node's name to its default value.
+
+
+\indexitem{readonly option>n children}|=|\meta{count} The number of children of the node.
+
+ In |pgfmath| expressions, this option is accessible as |n__children|.
+\end{syntax}
+
+
+\subsubsection{Various}
+
+\begin{syntax}
+\indexitem{node key>baseline} The node's anchor becomes the baseline of the whole tree
+ \citep[cf.][\S69.3.1]{tikzpgf2.10}.
+
+ In plain language, when the tree is inserted in your (normal \TeX) text, it will be vertically
+ aligned to the anchor of the current node.
+
+ Behind the scenes, this style sets the alias of the current node to \keyname{forest@baseline@node}.
+\begin{forestexample}[index={baseline,use as bounding box'}]
+ {\tikzexternaldisable
+ Baseline at the
+ \begin{forest}
+ [parent,~baseline~,use as bounding box'
+ [child]]
+ \end{forest}
+ and baseline at the
+ \begin{forest}
+ [parent
+ [child,~baseline~,use as bounding box']]
+ \end{forest}.}
+\end{forestexample}
+
+\indexitem(\begin{tikzpicture}){node key>begin draw}|/.code=|\meta{toks: \TeX\ code} \vspace{-\parskip}
+\indexitem(\end{tikzpicture}){node key>end draw}|/.code=|\meta{toks: \TeX\ code}
+
+The code produced by \index{draw tree} is put in the environment specified by \keyname{begin
+draw} and \keyname{end draw}. Thus, it is this environment, normally a |tikzpicture|, that does
+the actual drawing.
+
+A common use of these keys might be to enclose the |tikzpicture| environment in a |center|
+environment, thereby automatically centering all trees; or, to provide the \TikZ; code to execute
+at the beginning and/or end of the picture.
+
+Note that \keyname{begin draw} and \keyname{end draw} are \emph{not} node options: they are
+|\pgfkeys|' code-storing keys \citep[\S55.4.3--4]{tikzpgf2.10}.
+
+\indexitem>{tikz key>fit to}|=|\meta{nodewalk} Fits the \TikZ; node to the nodes in the given
+ \meta{nodewalk}.
+
+This key should be used like \keyname{/tikz/fit} of the \TikZ;'s fitting library
+\citep[see][\S34]{tikzpgf2.10}: as an option to \emph{\TikZ;'s} |node| operation, the obvious
+restriction being that \keyname{fit to} must be used in the context of some \foRest; node.
+For an example, see footnote~\ref{fn:fit-to-tree}.
+
+This key works by calling \keyname{/tikz/fit} and providing it with the the coordinates of the
+subtree's boundary.
+
+The \meta{nodewalk} inherits its history from the outer nodewalk (if there is one). Its every-step
+keylist is empty.
+
+\indexitem{node key>get min s tree boundary}|=|\meta{cs} \vspace{-\parskip}
+\indexitem{node key>get max s tree boundary}|=|\meta{cs}
+
+Puts the boundary computed during the packing process into the given \meta{cs}. The boundary is
+in the form of \PGF; path. The |min| and |max| versions give the two sides of the node. For an
+example, see how the boundaries in the discussion of \index{fit} were drawn.
+
+\indexitem{option>label}|=|\meta{toks: \TikZ; node} The current node is labelled by a \TikZ; node.
+
+ The label is specified as a \TikZ; option \texttt{label} \citep[\S16.10]{tikzpgf2.10}.
+ Technically, the value of this option is passed to \TikZ;'s as a late option
+ \citep[\S16.14]{tikzpgf2.10}. (This is so because \foRest; must first typeset the nodes
+ separately to measure them (stage \index{typeset nodes}); the preconstructed nodes are inserted
+ in the big picture later, at stage \index{draw tree}.) Another option with the same
+ technicality is \index{pin}.
+
+\indexitem{option>pin}|=|\meta{toks: \TikZ; node} The current node gets a pin, see
+ \citep[\S16.10]{tikzpgf2.10}.
+¸
+ The technical details are the same as for \index{label}.
+
+
+\indexitem{node key>use as bounding box} The current node's box is used as a bounding box for the
+ whole tree.
+
+ \indexitem{node key>use as bounding box'} Like \index{use as bounding box}, but subtracts the
+ (current) inner and outer sep from the node's box. For an example, see \index{baseline}.
+
+ \indexitem({{{{{}}}}}){option>tikz}|=|\meta{toks: \TikZ; code} ``Decorations.''
+
+ The code given as the value of this option will be included in the |tikzpicture| environment
+ used to draw the tree. The code given to various nodes is appended in a depth-first,
+ parent-first fashion. The code is included after all nodes of the tree have been drawn, so it
+ can refer to any node of the tree. Furthermore, relative node names can be used to refer to
+ nodes of the tree, see \S\ref{ref:relative-node-names}.
+
+ By default, bracket parser's afterthoughts feed the value of this option. See
+ \index{afterthought}.
+
+\end{syntax}
+
+
+
+\subsection{Nodewalks}
+\label{ref:nodewalks}
+
+A \emph{nodewalk} is a sequence of \emph{steps} describing a path through the tree. Most steps
+are defined relative to the current node, for example \index{step>parent} steps to the parent of the
+current node, and \index{step>n}|=2| steps to the second child of the current node, where ``to make a
+step'' means to change the current node. Thus, nodewalk |parent,_parent,_n=2| describes the path
+which first steps to the parent of the \emph{origin} node, then to its grandparent and finally to
+the second child of the origin's grandparent.
+
+The origin of the nodewalk depends on how the nodewalk is invoked. When used after the \index>{!} in a
+relative node name (\S\ref{ref:relative-node-names}), the origin is the node with the name given
+before \index>{!}; when invoked by a spatial propagator such as \index{for step=\index{nodewalk}}
+(\S\ref{ref:spatial-propagators}), the origin is the current node.
+
+Formally, a \meta{nodewalk} is a list of |pgfkeys| key--value pairs. Steps in a nodewalk are thus
+separated by commas. However, \foRest; also recognizes \emph{short-form} steps, whose names consist
+of a single character and which do not need to be separated by a comma. For example, nodewalk
+|parent,_parent,_n=2| can be concisely written as |uu2|. Long and short forms can be mixed freely,
+like this: |next,_uu2,_previous|.
+
+Besides nodewalk keys, a \meta{nodewalk} can also contain node keys (or
+even \TikZ; keys).\footnote{The precise algorithm for keyname resulotion in nodewalks is as follows.
+\begin{itemize}
+\item First, \foRest; searches for the given \meta{keyname} in the \index{path>forest/nodewalk}
+ path. If found (a long-form step or a nodewalk style), it is executed.
+\item Next, it is checked whether \meta{keyname} is a sequence of short-form steps; is so, they are
+ executed.
+\item Otherwise, \meta{key} is executed in the \keyname{/forest} path. This includes both
+ \foRest;'s and \TikZ;'s keys. The latter are usually forwarded to \TikZ; via \index{node
+ options}.
+\end{itemize}
+There are some clashes between node key and nodewalk step names. For example, \keyname{l} is both a
+\meta{dimen} option and a short form of the step to the last child. According to the rules above,
+the nodewalk step will take precedence in case of a clash. Use nodewalk key \index{options} to
+execute a clashing node key.} These keys do their usual function, but within the context of the
+current node of the nodewalk: |parent, s=2em,| |parent, text=red| sets the parent's |s| to 2em and
+the grandparent's text color to red. It is worth noting that node keys include \index{TeX}, which
+makes it possible to execute any \TeX\ code while nodewalking.
+
+Some steps target a single node, like above-mentioned \index{step>parent} and \index{step>n}.
+Others, called multi-steps, describe mini-walks themselves: for example \index{step>children} visits
+each child of the node in turn, and \index{tree} visits each of the node's descendants (including
+the node itself). The path of many steps is determined by the geometric relations of the tree, or
+the value of some option. However, there are also keys for embedding nodewalks (\index{nodewalk
+ key>nodewalk}, \index{branch}, etc.), saving and loading nodewalks, sorting them, or even
+re-walking the history of steps made (like in a web browser).\footnote{Note that nesting operation
+ (\S\ref{ref:nodewalk-operations}) and history (\S\ref{ref:nodewalk-history}) steps, or embedding
+ nodewalks under these steps doesn't work, for most combinations, as many of them internally
+ manipulate nodewalk history.} Finally, if all this is not enough, you can define your own steps,
+see \S\ref{ref:defining-steps}.
+
+Each nodewalk has an associated \emph{every-step keylist}: a keylist of node keys\footnote{When
+ executing the \index{register>every step} keylist, \foRest; switches into the
+ \index{path>forest} path, which makes it impossible to directly include a nodewalk into the
+ every-step keylist. The reason is performance. Every time a \index{path>forest/nodewalk} key
+ is not found, the short-form nodewalk recognition algorithm is executed, and this algorithm is
+ slow. As \index{register>every step} is used a lot (it is for example used every invocation of
+ every spatial propagator) and the keys in \index{register>every step} are usually node options
+ from \index{path>forest} path, \foRest; would spend way too much time checking if a given node
+ option is actually a short-form nodewalk.
+
+ If you need to execute nodewalk keys within the every-step keylist, use node key
+ \index{node key>Nodewalk}.} which get executed after each step of the nodewalk. The every-step
+keylist of the current nodewalk is contained in register \index{register>every step} and can be
+changed at any point during the nodewalk. Its value at the start of the nodewalk depends on how the
+nodewalk was invoked. In most cases (e.g.\ \index{step>nodewalk} or prefix
+\index{for step}-based spatial propagators), it is given explicitely as an argument to the key
+that executes the nodewalk. However, see \index{step>Nodewalk} for information on how the
+every-step keylist of an embedded nodewalk can interact with the every-step keylist of its parent
+nodewalk.
+
+Each nodewalk step can be either \emph{real} or \emph{fake}. Fake steps only change the current
+node. Real steps also trigger execution of the every-step keylist and update of history. Fake
+steps are sometimes useful as a ``computational tool''. They can be introduced explicitely using
+\index{nodewalk key>fake}; some other keys (like some history nodewalk keys, \S\ref{ref:nodewalk-history})
+introduce fake steps implicitely.
+
+In some cases, the nodewalk might step ``out of the tree''. (Imagine using \index{step>parent} at the
+root of the tree, or \index{option>n}|=42| at a node with less that 42 children.) Our official term will
+be that the nodewalk stepped on an \emph{invalid node}; what happens formally is that the current
+node is changed to the node with \index{option>id}|=0|. Normally, such an event raises an
+error. However, the full story is told by \index{nodewalk key>on invalid}.
+
+Nodewalks can be hard to follow, especially when designing styles. \FoRest; does its best to
+help. First, it logs the nodewalk stack in case of error. Second, if package option
+\index{debug} is given, it logs every step made.
+
+
+\subsubsection{Single-step keys}
+\label{ref:single-step-keys}
+
+Single-step nodewalk keys visit a single node. If the node a single-step is trying to visit does
+not exist, the current node is set to the invalid node (i.e.\ node with \index{option>id}|=0|). This
+can be useful for looping, see \S\ref{ref:loops}. Use \index{last valid} or \index{last valid'}
+to return to the node that was current before the ``unsuccessful'' single-step.
+
+For each single-step key, propagator \index{for step=\meta{step}} is also defined.
+\index{for step=\meta{step}}|=|\meta{keylist} is equivalent to
+\index{propagator>for}|={|\meta{step}|}{|\meta{keylist}|}|. If the step takes an argument, then its
+\index{for step=\meta{step}} propagator takes two and the argument of the step precedes the
+\meta{keylist}. See also \S\ref{ref:spatial-propagators}.
+
+Linear order below means the order of nodes in the bracket representation, i.e.\ depth-first
+parent-first first-child-first.
+
+\begin{syntax}
+\indexitem{step>current} an ``empty'' step: the current node remains the same\footnote{While it
+ might at first sight seem stupid to have an empty step, this is not the case. For example,
+ using propagator \index{for step=\index{current}} derived from this step, one can process a \meta{keylist} constructed using \index[not index,print format+={result+={\index[not print]{wrap pgfmath arg}\index[not print]{wrap $n$ pgfmath args}}}]{handler>wrap ($n$) pgfmath arg(s)} or \index{wrap value}.}
+\indexitem{step>first} the first child
+\indexitem{step>first leaf}, \indexdef{step>first leaf'} the first leaf (terminal node) of the
+ current node's descendants (|first leaf|) or subtree (|first leaf'|), in the linear order
+\indexitem{step>id}|=|\meta{id} the node with the given id; this step does not depend on the current node
+\indexitem{step>last} the last child
+\indexitem{step>last leaf}, \indexdef{step>last leaf'} the last leaf (terminal node) of the
+ current node's descendants (|last leaf|) or subtree (|last leaf'|), in the linear order
+\indexitem{step>n}|=|$n$ the $n$th child; counting starts at $1$\footnote{Note that \keyname{n}
+ \emph{without} an argument is a short form of \keyname{next}.}
+\indexitem{step>n'}|=|$n$ the $n$th child, starting the count from the last child
+\indexitem{step>name}|=|\meta{name} the node with the given name or alias; this step does not depend on the current node
+\indexitem{step>next} the next sibling
+\indexitem{step>next leaf} the next node (in the linear order) which is a leaf (the current node need not be a leaf)
+\indexitem{step>next node} the next node of the entire tree, in the linear order
+\indexitem{step>next on tier}|=|\meta{tier} the next node (in the linear order) on the given tier; if no tier is given, assume the tier of the current node
+\indexitem{step>origin} the starting node of the nodewalk; note that the starting point does not automatically count as a step: if you want to step on it, use this key (or \index{current}, at the beginning of the nodewalk)
+\indexitem{step>parent} the parent
+\indexitem{step>previous} the previous sibling
+\indexitem{step>previous leaf} the previous node (in the linear order) which is a leaf (the current node need not be a leaf)
+\indexitem{step>previous node} the previous node of the entire tree, in the linear order
+\indexitem{step>previous on tier}|=|\meta{tier} the previous node (in the linear order) on the given tier; if no tier is given, assume the tier of the current node
+\indexitem{step>root} the root node, i.e.\ the ancestor of the current node without the parent; note that this key \emph{does} depend on the current node
+\indexitem{step>root'} the formal root node (see \index{set root} in \S\ref{ref:dynamic}); this key does not depend on the current node
+\indexitem{step>sibling} the sibling
+
+(don't use if the parent doesn't have exactly two children \dots)
+\indexitem{step>to tier}|=|\meta{tier} the first ancestor of the current node (or the node itself) on the given \meta{tier}
+\end{syntax}
+
+
+\subsubsection{Multi-step keys}
+\label{ref:multi-step-keys}
+
+Multi-step keys visit several nodes, in general. If a multi-step key visits no nodes, the current
+node remains unchanged.
+
+For each multi-step key, spatial propagator \index{for step=\meta{step}} is also defined, see
+\S\ref{ref:spatial-propagators}.
+
+Many of the keys below have a |reversed| variant. Those keys reverse the order of \emph{children}.
+Note that in general, this differs from operation key \index{reverse}, which reverses the order of
+the entire embedded nodewalk.
+
+Linear order below means the order of nodes in the bracket representation, i.e.\ depth-first
+parent-first first-child-first.
+
+\begin{syntax}
+ \indexitem{step>children}, \indexdef{step>children reversed}
+
+ Visit all the children of the current
+ node.
+
+\indexitem{step>tree}, \indexdef{step>tree reversed}
+ \itemnosep
+\indexitem{step>tree children-first}, \indexdef{step>tree children-first reversed}
+ \itemnosep
+\indexitem{step>tree breadth-first}, \indexdef{step>tree breadth-first reversed}
+
+ Visit the current node and all its descendants.
+
+ The above keys differ in the order the nodes are visited. The basic key, \keyname{tree},
+ traverses the nodes in the depth-first, parent-first first-child-first order, i.e.\ the order in
+ which they are given in the bracket representation: so it visits the parent before its children and
+ it visits the children from the first to the last.
+
+ |reversed| variants reverse the order of \emph{children}, visiting them from the last to the first
+ (from the viewpoint of the bracket representation).
+
+ |children-first| variants visit the children before the parent.
+
+ |breadth-first| variants behave like |level| steps below: they first visit level |0| nodes, then
+ level |1| nodes etc.
+
+ \begin{forestexample}[index={}]
+ \forestset{
+ enumerate/.style={
+ tempcounta=1,
+ for #1={
+ content/.pgfmath=tempcounta,
+ tempcounta+=1
+ }
+ }
+ }
+ \newcommand\enumtree[1]{%
+ \begin{forest}
+ [#1,l sep=0,for n=1{
+ l=0,no edge,delay={enumerate=#1}}
+ [[[[][]][[][]]][[[][]]]]
+ ]
+ \end{forest}
+ }
+ \renewcommand\arraystretch{2}
+ \begin{tabular}{cc}
+ \enumtree{tree}&
+ \enumtree{tree reversed}\\
+ \enumtree{tree children-first}&
+ \enumtree{tree children-first reversed}\\
+ \enumtree{tree breadth-first}&
+ \enumtree{tree breadth-first reversed}
+ \end{tabular}
+ \end{forestexample}
+
+\indexitem{step>descendants}, \indexdef{step>descendants reversed}
+ \itemnosep
+\indexitem{step>descendants children-first}, \indexdef{step>descendants children-first reversed}
+ \itemnosep
+\indexitem{step>descendants breadth-first}, \indexdef{step>descendants breadth-first reversed}
+
+ Visit all the descendants of the current node.
+
+ Like the |tree| keys, but the current node is not visited.
+
+\indexitem[print form+=\spaces{9}]{step>relative level <},
+ \indexdef[print form+=\spaces{9}]{step>relative level},
+ \indexdef[set={form=relative level \protect\greaterthan}]{step>relative level GT}\texttt{\spaces{9}}|=|\meta{count}
+ \itemnosep
+\indexitem{step>relative level reversed <},
+ \indexdef{step>relative level reversed},
+ \indexdef[set={form=relative level reversed \protect\greaterthan}]{step>relative level reversed GT}|=|\meta{count}
+ \itemnosep
+\indexitem[print form+=\spaces{9},+print form=\spaces{9}]{step>level <},
+ \indexdef[print form+=\spaces{9},+print form=\spaces{9}]{step>level},
+ \indexdef[set={form=level \protect\greaterthan},+print form=\spaces{9}]{step>level GT}\texttt{\spaces{9}}|=|\meta{count}
+ \itemnosep
+\indexitem[+print form=\spaces{9}]{step>level reversed <},
+ \indexdef[+print form=\spaces{9}]{step>level reversed},
+ \indexdef[set={form=level reversed \protect\greaterthan},+print form=\spaces{9}]{step>level reversed GT}|=|\meta{count}
+
+ Visits the nodes in the subtree of the current node whose level (depth) is less than \emph{or
+ equal to}, equal to, or greater than \emph{or equal to} the given level.
+
+ The |relative| variants consider the level as relative to the current node: relative level of the
+ current node is $0$; relative level of its children is $1$, of its grandchildren $2$, etc. The
+ absolute variants consider the depth with respect to the (geometric) root, i.e.\ as returned by
+ node option \index{option>level}.
+
+ The nodes are traversed in the breadth-first order. The |reversed| variants reverse the order of
+ the children within each level, but the levels are still traversed from the highest to the
+ deepest.
+
+\indexitem[+print form=\spaces{12},print form+=\spaces{9}]{step>preceding siblings}\quad\quad
+ \indexdef[+print form=\spaces{12}]{step>following siblings}%
+ \itemnosep
+\indexitem[print form+=\spaces{9}]{step>current and preceding siblings}\quad\quad
+ \indexdef{step>current and following siblings}%
+ \itemnosep
+\indexitem[+print form=\spaces{12}]{step>preceding siblings reversed}\quad\quad
+ \indexdef[+print form=\spaces{12}]{step>following siblings reversed}%
+ \itemnosep
+\indexitem{step>current and preceding siblings reversed}\quad\quad
+ \indexdef{step>current and following siblings reversed}%
+ \itemnosep
+\indexitem[+print form=\spaces{22},print form+=\spaces{9}]{step>siblings}%
+ \itemnosep
+\indexitem[+print form=\spaces{22},print form+=\spaces{9}]{step>siblings reversed}%
+
+Visit preceding, following or all siblings; visit the current node as well or not; visit in normal
+or reversed order.
+
+\indexitem{step>ancestors}
+ \itemnosep
+\indexitem{step>current and ancestors}
+
+Visit the ancestors of the current node, starting from the parent/current node, ending at the root node.
+
+\indexitem[+print form=\spaces{12}]{step>preceding nodes}\quad\quad
+ \indexdef[+print form=\spaces{12}]{step>following nodes}%
+ \itemnosep
+\indexitem{step>current and preceding nodes}\quad\quad
+ \indexdef{step>current and following nodes}%
+
+Visit all preceding or following nodes of the entire tree, in the linear order; visit the current node as well or not.
+
+\end{syntax}
+
+\subsubsection{Embedded nodewalks}
+\label{ref:embedded-walks}
+
+An embedded nodewalk is a nodewalk within a nodewalk. The embedded nodewalk has its own every-step
+keylist. While stepping through the inner nodewalk, the every-step keylist of the outer nodewalk is
+not executed. Modifying the every-step keylist of the inner walk (by \index{register>every step}) does not
+influence the outer nodewalk.
+
+After the embedded nodewalk finished, its final current node becomes the current node of the outer
+nodewalk. This is true even if the final node was reached by a fake step.
+
+\begin{advise}
+\item As node keys can be used within nodewalks, one can use spatial propagators
+ (\S\ref{ref:spatial-propagators}) like \index{for step=\index{step>nodewalk}} to embed a nodewalk
+ which (silently) returns to the current node of the outer nodewalk.
+\end{advise}
+
+An embedded nodewalk does not count as a step of the outer nodewalk (except if noted otherwise, see
+\index{group}). This means that the every-step keylist of the outer nodewalk is not executed at
+the final node of the embedded nodewalk. In other words, the step made by the embedded nodewalk as
+a unit is fake.
+
+Embedded nodewalks also have their own origin and history. Nodewalks can be nested to an arbitrary
+level.
+
+\begin{syntax}
+\indexitem{step>Nodewalk}|=|\meta{keylist: config}\meta{nodewalk}\meta{keylist: every-step}
+
+ Walks an (embedded) \meta{nodewalk} starting at the current node.
+
+ From the perspective of the outer nodewalk, the embedded nodewalk is an (implicitely) fake step
+ (and cannot be made real by \index{real}): the last node visited by the embedded
+ \meta{nodewalk} becomes the new current node of the outer nodewalk, even if it is invalid.
+
+ The \meta{config} argument serves to specify the interaction between the outer and embedded
+ nodewalk. It can contain the following keys:
+
+ \let\outerleftmargin\leftmargin
+ \begin{syntax}
+ \indexitem(independent){option of=Nodewalk>every step}|={|\alternative{independent,inherited,shared}|}|
+ \indexitem(shared){option of=Nodewalk>history}|={|\alternative{independent,inherited,shared}|}|
+
+ The following table shows what happens to the every-step keylist and history depending on the
+ value of \keyname{every step} and \keyname{history}, respectively. State B is \meta{every-step}
+ for every step and empty for history.
+
+ \begin{tabular}{l|ccc}
+ &\keyname{independent}&\keyname{inherited}&\keyname{shared}\\\hline
+ state of the outer nodewalk&A&A&A\\
+ initial state of the inner nodewalk&B&A&A\\
+ \dots\\
+ final state of the inner nodewalk&C&C&C\\
+ state of the outer nodewalk&A&A&C
+ \end{tabular}
+ \end{syntax}
+
+ As shown in the table above, argument \meta{every-step} is used to initialize the
+ embedded nodewalk's every-step keylist when it is independent of the outer nodewalk. In other
+ cases, this argument is ignored (use |{}|).
+
+ \begin{syntax}
+ \indexitem(inherited){option of=Nodewalk>on invalid}|={|\alternative{error,fake,step,inherited}|}|
+
+ Like \index{nodewalk key>on invalid}, but local to this nodewalk. The additional alternative
+ \indexdef{value=on invalid>inherited} (which is the default) means to behave as specified by
+ \index{nodewalk key>on invalid} (or the package default, \index{value=on invalid>error}, if no
+ \index{nodewalk key>on invalid} was given).
+ \end{syntax}
+
+\indexitem{step>nodewalk}|=|\meta{nodewalk}\meta{keylist: every-step}
+
+ This key is a shorthand for
+
+ \begin{center}
+ \index{step>Nodewalk}|={|\index{option of=Nodewalk>every step}|=independent,|\index{option of=Nodewalk>history}|=independent}|\meta{nodewalk}\meta{keylist: every-step}
+ \end{center}
+
+ \begin{advise}
+ \item \index{for step=\index{nodewalk}} is also defined.
+ \end{advise}
+
+\indexitem{step>nodewalk'}|=|\meta{nodewalk}
+
+ This key is a shorthand for
+
+ \begin{center}
+ \index{step>Nodewalk}|={|\index{option of=Nodewalk>every step}|=inherited,|\index{option of=Nodewalk>history}|=independent}|\meta{nodewalk}\meta{keylist: every-step}
+ \end{center}
+
+ \begin{advise}
+ \item \index{for step=\index{nodewalk'}} is also defined.
+ \end{advise}
+
+\indexitem{step>group}|=|\meta{nodewalk}
+
+ Treat \meta{nodewalk} as a single step of the (outer) nodewalk, i.e.\ the outer every-step keylist
+ is executed only at the end of the embedded nodewalk. The embedded \meta{nodewalk} inherits
+ history from the outer nodewalk. Using this key is equivalent to writing
+ \begin{center}
+ \index{step>Nodewalk}|={|\index{option of=Nodewalk>every step}|=independent,|\index{option
+ of=Nodewalk>history}|=inherited}|\meta{nodewalk}|{}, current|
+ \end{center}
+
+ \begin{advise}
+ \item It is safe to modify the every-step keylist of \meta{nodewalk}.
+ \item \index{for step=\index{group}} is also defined.
+ \end{advise}
+
+\indexitem{nodewalk key>filter}|=|\meta{nodewalk}\meta{pgfmath: condition}
+
+ Executes the every-step keylist of the outer nodewalk for every step in the inner \meta{nodewalk}
+ after which the given pgfmath condition is true.
+
+ This is the definition of |filter|:
+\begin{lstlisting}
+ filter/.style 2 args={% #1 = nodewalk, #2 = condition
+ nodewalk/.expanded={\unexpanded{#1}}{if={\unexpanded{#2}}{\forestnodewalkeverystep}{}}
+ },
+\end{lstlisting}
+
+ \begin{advise}
+ \item Do not change the every-step keylist of the (inner) \meta{nodewalk}: added keys will get
+ executed at every further step of the \meta{nodewalk}, regardless whether condition applies or
+ not.
+ \end{advise}
+
+\indexitem{nodewalk key>branch}|={|\meta{nodewalk$_1$}|,...,|\meta{nodewalk$_n$}|}|
+ \itemnosep
+\indexitem{nodewalk key>branch'}|={|\meta{nodewalk$_1$}|,...,|\meta{nodewalk$_n$}|}|
+
+ A ``cartesian product'' of any number of nodewalks. At every step of \meta{nodewalk$_i$}, \meta{nodewalk$_{i+1}$} is executed.
+
+ Both variants inherit the \index{register>every step} keylist of the containing nodewalk. More precisely, in the |branch'| variant this keylist is executed for every step at every level, while in the |branch| variant, this keylist is executed only for the innermost steps.
+
+ \begin{advise}
+ \item It is safe to add keys to the every-step keylist of the embedded nodewalks, but not to
+ remove them, as this will impair the functionality of |branch|. In other words, only use
+ \index{+keylist=\index{register>every step}} and \index{keylist+=\index{register>every step}} inside
+ \meta{nodewalk$_i$}.
+ \end{advise}
+
+ For an example, see \index{c-commanded}.
+
+\end{syntax}
+
+\subsubsection{Operations}
+\label{ref:nodewalk-operations}
+
+Most of the following keys have a |walk_and_...| variant, which first walks the given nodewalk and
+then performs the desired operation. All operation keys except |..._in_nodewalk| variants can be prefixed by \index{for step}.
+
+\begin{syntax}
+ \indexitem{step>reverse}|=|\meta{nodewalk}
+ \itemnosep
+ \indexitem{step>walk and reverse}|=|\meta{nodewalk}
+
+ Visits the nodes of the given \meta{nodewalk} in the reversed order.
+
+ \indexitem{nodewalk key>save}|=|\meta{toks: name}\meta{nodewalk}
+ \itemnosep
+ \indexitem{step>walk and save}|=|\meta{toks: name}\meta{nodewalk}
+
+ Saves the given \meta{nodewalk} under the given name.
+
+ \indexitem{step>load}|=|\meta{toks: name} Walks the nodewalk saved under the given name.
+
+ Note that it is node \index{option>id}s that are saved: loading a named nodewalk with in a context of
+ a different current node, or even with a tree whose geometry has changed (see \S\ref{ref:dynamic})
+ will still visit exactly the nodes that were visited when the nodewalk was saved.
+
+ \indexitem{step>sort}|=|\meta{nodewalk}
+ \itemnosep
+ \indexitem{step>sort'}|=|\meta{nodewalk}
+ \itemnosep
+ \indexitem{step>walk and sort}|=|\meta{nodewalk}
+ \itemnosep
+ \indexitem{step>walk and sort'}|=|\meta{nodewalk}
+
+ Walks the nodes of the nodewalk in the order specified by the last invokation of \index{sort
+ by}. The \keyname{sort} variants sort in the ascending order, the \keyname{sort'} variants in
+ the descending order. The \keyname{walk and sort} variants first visit the nodes in the order
+ specified by the given \meta{nodewalk}.
+
+ \indexitem{node key>sort by}|={|\meta{pgfmath}|,|\dots|,|\meta{pgfmath}|}|
+
+ Sets the sorting order used by all keys comparing nodes: \index{step>sort}, \index{step>min}
+ and \index{step>max} key families in the nodewalk namespace, and the \index{dynamic
+ tree>sort} key family in the option namespace (dynamic tree).
+
+ For each node being ordered, an ``$n$-dimensional coordinate'' is computed by evaluating the given
+ list of |pgfmath| expressions in the context of that node.\footnote{Don't worry, lazy evaluation
+ is used.} Nodes are then ordered by the usual sort order for multi-dimensional arrays: the
+ first item is the most important, the second item is the second most important, etc.
+
+ Simply put, if you want to sort first by the number of children and then by content, say
+ |sort_by={|\index[+print format=pgfmath]{n children}|,_|\index{content}|}|.
+
+ In the simplest case, the given \meta{pgfmath} expressions are simply node options. However, as
+ any |pgfmath| expression is allowed in the sort key, you can easily sort by the product of the
+ content of the current node and the content of its first child:
+ |sort_by={|\index{content}|()*|\index{content}|("|\index>{!}|1")|. Note, however, that the value returned by these expression
+ must be numeric, i.e.\ alphabetic comparison of strings is not implemented.
+
+
+\indexitem{step>min}|=|\meta{nodewalk}, \indexdef{step>max}|=|\meta{nodewalk}
+ \itemnosep
+ \indexitem{step>walk and min}|=|\meta{nodewalk}, \indexdef{step>walk and max}|=|\meta{nodewalk}
+ \itemnosep
+ \indexitem{step>mins}|=|\meta{nodewalk}, \indexdef{step>maxs}|=|\meta{nodewalk}
+ \itemnosep
+ \indexitem{step>walk and mins}|=|\meta{nodewalk}, \indexdef{step>walk and maxs}|=|\meta{nodewalk}
+
+
+ Visit the node(s) in the given \meta{nodewalk} with a minimum/maximum value with
+ respect to the sort order previously specified by \index{sort by}.
+
+ Variants \keyname{mins}/\keyname{maxs} visit all the nodes that with the minimum/maximum value of
+ the sorting key; variants \keyname{min}/\keyname{max} visit only the first such node (first in the order specified by the given nodewalk).
+
+ \indexitem{step>min in nodewalk}, \indexdef{step>max in nodewalk}
+ \itemnosep
+ \indexitem{step>mins in nodewalk}, \indexdef{step>maxs in nodewalk}
+ \itemnosep
+ \indexitem{step>min in nodewalk'}, \indexdef{step>max in nodewalk'}
+
+ These keys search for the minimum/maximum among the nodes that were already visited in the current
+ nodewalk.
+
+ Keys \keyname{mins in nodewalk} and \keyname{maxs in nodewalk} visits all nodes that reach the minimum/maximum, while keys \keyname{min in nodewalk} and \keyname{max in nodewalk} variants visit only the first such node.
+
+ Keys \keyname{min in nodewalk'} and \keyname{max in nodewalk'} visit the first minimal/maximal
+ node by moving back in the history, see \index{back}.
+\end{syntax}
+
+\subsubsection{History}
+\label{ref:nodewalk-history}
+
+\FoRest; keeps track of nodes visited in a nodewalk and makes it possible to revisit them, in a
+fashion similar to clicking the back and forward button in a web browser.
+
+These keys cannot be prefixed by \index{for step}.
+
+\begin{syntax}
+ \indexitem{step>back}|=|\meta{count: n}
+ \itemnosep
+ \indexitem{step>jump back}|=|\meta{count: n}
+ \itemnosep
+ \indexitem{step>walk back}|=|\meta{count: n}
+
+ Move $n$ steps back in the history. In the \keyname{back} variant, all steps are fake; in
+ the \keyname{step back} variant, the final step is real; and in the \keyname{walk back} variant,
+ all steps are real.
+
+ Note that as the origin is not a part of the history, these keys will \emph{not} step there
+ (unless \index{current} was the first step of your nodewalk). (Use \index{origin} to move
+ to the origin of the nodewalk.)
+
+ \indexitem{step>forward}|=|\meta{count: n}
+ \itemnosep
+ \indexitem{step>jump forward}|=|\meta{count: n}
+ \itemnosep
+ \indexitem{step>walk forward}|=|\meta{count: n}
+
+ Move $n$ steps forward in the history. In the \keyname{forward} variant, all steps are fake; in
+ the \keyname{step forward} variant, the final step is real; and in the \keyname{walk forward} variant,
+ all steps are real.
+
+\indexitem{node key>save history}|=|\meta{toks: back name}\meta{toks: forward name}
+
+Saves the backwards and forwards history under the given names. (Load them using \index{load}.) The
+backwards history is saved in the reverse order of how it was walked, i.e.\ outward from the
+perspective of the current position in the nodewalk.
+\end{syntax}
+
+
+\subsubsection{Miscellaneous}
+\label{ref:nodewalk-miscellaneous}
+
+The following nodewalk keys are not steps. Rather, they influence the behaviour of nodewalk steps in
+various ways. The keys in this section having \meta{nodewalk} arguments do not start a new nodewalk
+in the sense of \S\ref{ref:embedded-walks}; the given nodewalk steps rather become a part of the
+current nodewalk.
+
+\begin{syntax}
+\indexitem{register>every step}|=|\meta{keylist} Contains the every-step keylist of the current
+ nodewalk.
+
+\indexitem{nodewalk key>fake}|=|\meta{nodewalk}
+ \itemnosep
+\indexitem{nodewalk key>real}|=|\meta{nodewalk}
+
+ The \meta{nodewalk} embedded under |fake| consists of ``fake'' steps: while
+ the current node is changed, every-step keylist is not executed and the history is not updated.
+
+ Note that these keys do not introduce an embedded nodewalk. The given \meta{nodewalk} will not
+ have its own history and every-step keylist.
+
+ |real| undoes the effect of |fake|, but cannot make real the implicitely fake steps, such as the
+ return to the origin in spatial propagators like \index{for step=\index{nodewalk}}.
+ |fake| and |real| can be nested without limit.
+
+\indexitem{step>last valid}
+ \itemnosep
+\indexitem{step>last valid'}
+
+ If the current node is valid, these keys do nothing. If the current node of the nodewalk is
+ invalid (i.e.\ its \index{option>id} is $0$), they step to the last valid visited node. If
+ there was no such node, they step to the origin of the nodewalk.
+
+ The variant \emph{without} |'| makes a fake step. More precisely, it behaves as if both
+ \index{nodewalk key>fake} and \index{nodewalk key>on invalid}|=fake| are in effect.
+
+\indexitem(error){nodewalk key>on invalid}|={|\alternative{error,fake,step}|}|\meta{nodewalk}
+
+ This key determines what should happen if a nodewalk step landed on the invalid node, i.e.\ the node
+ with \index{option>id}|=0|.
+
+ There is a moment within the step when the current node is changed but the step itself is not yet
+ really done, is ``still fake'', i.e.\ the history is not yet updated and the every-step keylist is
+ not yet executed. If the new current node is invalid, this key determines what should happen next.
+
+ \let\outerleftmargin\leftmargin
+ \begin{syntax}
+ \item |on invalid=|\indexdef{value=on invalid>error} produces an error;
+ \item |on invalid=|\indexdef{value=on invalid>fake} does nothing: history is not updated and the
+ every-step keylist is not executed, thus making the step essentialy fake;
+ \item |on invalid=|\indexdef{value=on invalid>step} makes a step, either real or fake, depending
+ on the environment.
+ \end{syntax}
+
+ Loops with the implicit |id=0| condition (\S\ref{ref:loops}) automatically switch to
+ |on_invalid=fake| mode.
+
+\indexitem{nodewalk key>options}=\meta{keylist: node keys}
+
+ Execute the given node options in the context of the current node.
+
+ There is not much need to use this key, as any keys that are not (long) steps or sequences of
+ short steps are automatically used as \foRest; node options any way, but there are still usage
+ cases, for example whenever the names of node options and (long) steps are the same, or in a style
+ that wants to ensure there is no overlap.
+
+\indexitem{nodewalk key>strip fake steps}|=|\meta{nodewalk}
+
+ If \meta{nodewalk} ends with fake steps, return to the last node current before those steps were made. For details, see \index{define long step}.
+
+\end{syntax}
+
+
+\subsubsection{Short-form steps}
+\label{ref:short-form-steps}
+
+All short forms of steps are one token long. When using them, there is no need to separate them by
+commas. Here's the list of predefined short steps and their corresponding long-form steps.
+
+\begin{syntax}
+\indexitem{short step>1}, \indexdef{short step>2}, \indexdef{short step>3}, \indexdef{short step>4}, \indexdef{short step>5}, \indexdef{short step>6}, \indexdef{short step>7}, \indexdef{short step>8}, \indexdef{short step>9} the first, \dots, ninth child --- \index{option>n}|=1|,\dots,|,9|
+\indexitem{short step>l} the last child --- \index{step>last}
+\indexitem{short step>u} the parent (up) --- \index{step>parent}
+\indexitem{short step>p} the previous sibling --- \index{previous}
+\indexitem{short step>n} the next sibling --- \index{next}
+\indexitem{short step>s} the sibling --- \index{sibling}
+\indexitem{short step>P} the previous leaf --- \index{previous leaf}
+\indexitem{short step>N} the next leaf --- \index{next leaf}
+\indexitem{short step>F} the first leaf --- \index{first leaf}
+\indexitem{short step>L} the last leaf --- \index{last leaf}
+\indexitem[set={index key={<GT},form=\protect\greaterthan}]{short step>GT}
+ the next node on the current tier --- \index{next on tier}
+\indexitem{short step><} the previous node on the current tier --- \index{previous on tier}
+\indexitem{short step>c} the current node --- \index{current}
+\indexitem{short step>o} the origin --- \index{origin}
+\indexitem{short step>r} the root node --- \index{root}
+\indexitem{short step>R} the formal root node --- \index{root'}
+\indexitem{short step>b} back one fake step in history --- \index{back}|=1|
+\indexitem{short step>f} forward one fake step in history --- \index{forward}|=1|
+\indexitem{short step>v} last valid node in the current nodewalk, fake version --- \index{last valid}
+\indexitem{short step>*}\meta{count: n}\meta{keylist} repeat keylist $n$ times --- \index{repeat}|=|\meta{count: n}\meta{keylist}
+\item {\rstyle $\{$}\meta{keylist}{\rstyle $\}$} put keylist in a group --- \index{group}|=|\meta{keylist}
+\end{syntax}
+
+\subsubsection{Defining steps}
+\label{ref:defining-steps}
+
+You can define your own steps, both long and short, or even redefine predefined steps. Note,
+though, that it is not advisable to redefine long steps, as their definitions are interdependent;
+redefining short steps is always ok, however, as they are never used in the code of the package.
+
+\begin{syntax}
+\indexitem{node key>define long step}|=|\meta{name}\meta{options}\meta{nodewalk}
+
+ Define a long-form step named \meta{name} as equivalent to \meta{nodewalk}. \meta{options} control the exact behaviour or the defined step.
+
+ \let\outerleftmargin\leftmargin
+ \begin{syntax}
+ \item\indexdef{option of=define long step>n args}|=|\meta{number}\hfill |1|
+ \item\indexdef{option of=define long step>make for}|=|\meta{boolean}\hfill |true|
+
+ Should we make a \index{for step} prefix for the step?
+ \item\indexdef{option of=define long step>strip fake steps}|=|\meta{boolean}\hfill |true|
+
+ Imagine that \meta{nodewalk} ends with fake steps. Now, fake steps are usually just a computational tool, so we normally wouldn't want the current node after the walk to be one of them. As far as the outer world is concerned, we want the node to end at the last real step. However, simply appending \index{last valid} to our style will not work. Imagine that the nodewalk results in no steps. In this case, we'd want to remain at the origin of our empty nodewalk. However, imagine further that the (outer) step just before the empty nodewalk was fake. Then \index{last valid} will not step to the correct node: instead of staying at the origin, it will go to the node that the last real step prior to our nodewalk stepped to. In case there was no such real step, we'd even step to the invalid node (normally getting an error).
+
+ Defining the step using |strip fake steps| ensures the correct behaviour described
+ above. Set |strip fake steps=false| only when the fake steps at the end of the nodewalk at
+ important to you.
+
+ \begin{advise}
+ \item See also nodewalk key \index{nodewalk key>strip fake steps}.
+ \end{advise}
+
+ \end{syntax}
+
+\begin{forestexample}[index={define long step,option of=define long step>n args,conditional>if,step>n,while,option>n,next}]
+ \forestset{
+ ~define long step~={children from to}{n args=2}{
+ if={#1>#2}{}{n=#1,while={n()<#2}{next}}
+ }
+ }
+ \begin{forest}
+ for children from to={2}{5}{draw}
+ [root[1][2][3][4][5][6]]
+ \end{forest}
+\end{forestexample}
+
+
+\indexitem{node key>define short step}|=|\meta{token: short step}\meta{n args}\meta{nodewalk}
+
+Define short step taking $n$ arguments as the given \meta{nodewalk}. Refer to the arguments in the usual way, via |#1|, \dots.
+
+To (re)define braces, |{}|, write |define short step={group}{1}{...}|.
+\end{syntax}
+
+
+\subsection{Conditionals and loops}
+\label{ref:conditionals}
+\label{ref:loops}
+
+All conditionals take arguments \meta{true keylist} and \meta{false keylist}, and all loops take an
+argument \meta{keylist}. The interpretation of the keys in these keylists depends on the
+environment the conditional/loop appears in. If it is a part of a nodewalk
+specification, the keys are taken to be nodewalk keys (\S\ref{ref:nodewalks}), otherwise node keys
+(\S\ref{ref:node-keys}).
+
+All the loops and conditionals can be nested safely.
+
+\begin{advise}
+\item Except in special circumstances, you probably don't want to embed keys from the \index{where
+ option} family within a \index{for step=\index{tree}}, as this results in two nested loops. It
+ is more usual to use an \index{conditional>if} family key there. For an example where using
+ \index{where option} actually does the wrong thing, see question
+ \href{http://tex.stackexchange.com/questions/167978/smaller-roofs-for-forest}{Smaller roofs for
+ forest} on \TeX\ Stackexchange.
+\end{advise}
+
+\begin{syntax}
+\indexitem{conditional>if}|=|\meta{pgfmath condition}\meta{true keylist}\meta{false keylist}
+
+ If \meta{pgfmath condition} evaluates to |true| (non-zero), \meta{true keylist} is processed (in
+ the context of the current node); otherwise, \meta{false keylist} is processed.
+
+ For a detailed description of |pgfmath| expressions, see \cite[part VI]{tikzpgf2.10}. (In short:
+ write the usual mathematical expressions.)
+
+\indexitem{word prefix=option>conditional>if=\meta{option}}|=|\meta{value}\meta{true keylist}\meta{false keylist}
+
+ A simple conditional is defined for every \meta{option}: if \meta{value} equals the value of the
+ option at the current node, \meta{true keylist} is executed; otherwise, \meta{false keylist}.
+
+\indexitem{word prefix=boolean option>conditional>if=\meta{boolean option}}|=|\meta{true keylist}\meta{false keylist}
+
+ Execute \meta{true keylist} if \meta{boolean option} is true; otherwise, execute \meta{false
+ keylist}.
+
+\indexitem{word prefix=toks option>conditional>if in=\meta{toks option}}|=|\meta{toks}\meta{true keylist}\meta{false
+ keylist}
+
+ Checks if \meta{toks} occurs in the option value; if it does, \meta{true keylist} are executed,
+ otherwise \meta{false keylist}.
+
+ This conditional is defined only for \meta{toks} options, see \S\ref{sec:option-setting}.
+
+\indexitem{conditional>if nodewalk valid}|=|\meta{keylist: test nodewalk}\meta{true keylist}\meta{false keylist}
+
+ If the test nodewalk finished on a valid node, \meta{true keylist} is processed (in the context of
+ the current node); otherwise, \meta{false keylist} is processed.
+
+\indexitem{conditional>if nodewalk empty}|=|\meta{keylist: test nodewalk}\meta{true keylist}\meta{false keylist}
+
+ If the test nodewalk contains no (real) steps, \meta{true keylist} is processed (in the context of
+ the current node); otherwise, \meta{false keylist} is processed.
+
+\indexitem{conditional>if in saved nodewalk}|=|\meta{nodewalk}\meta{toks: nodewalk name}\meta{true keylist}\meta{false keylist}
+
+If the node at the end of \meta{nodewalk} occurs in the saved nodewalk, \meta{true keylist} is
+processed (in the context of the current node); otherwise, \meta{false keylist} is processed.
+
+\indexitem{propagator>if have delayed}|=|\meta{true keylist}\meta{false keylist} If any options were
+ delayed in the current cycle (more precisely, up to the point of the execution of this key),
+ process \meta{true keylist}, otherwise process \meta{false keylist}. (\index{delay n} will
+ trigger ``true'' for the intermediate cycles.)
+
+ This key assumes that the processing order of the innermost invocation of \index{process
+ keylist} or \index{process keylist'} is given by \index{processing order}. If this is not
+ the case, explicitely supply the processing order using \index{if have delayed'}.
+
+\indexitem{propagator>if have delayed'}|=|\meta{nodewalk}\meta{true keylist}\meta{false keylist}
+ Like \index{if have delayed}, but assume the processing order given by \meta{nodewalk}.
+
+\indexitem{propagator>where}|=|\meta{value}\meta{true keylist}\meta{false keylist}
+\itemnosep
+\indexitem{word prefix=option>conditional>where=\meta{option}}|=|\meta{value}\meta{true keylist}\meta{false keylist}
+\itemnosep
+\indexitem{word prefix=toks option>conditional>where in=\meta{toks option}}|=|\meta{toks}\meta{true keylist}\meta{false keylist}
+\itemnosep
+\indexitem{step>where nodewalk valid}|=|\meta{toks: nodewalk name}\meta{true keylist}\meta{false keylist}
+\itemnosep
+\indexitem{step>where nodewalk empty}|=|\meta{toks: nodewalk name}\meta{true keylist}\meta{false keylist}
+\itemnosep
+\indexitem{step>where in saved nodewalk}|=|\meta{nodewalk}\meta{toks: nodewalk name}\meta{true keylist}\meta{false keylist}
+
+These keys execute their corresponding |if ...| conditional for every node in the subtree of the current node (including the node itself). In other words:
+
+\begin{center}
+ |where ...|\meta{arg$_1$}\dots\meta{arg$_1$}|/.style={for tree={if ...=|\meta{arg$_1$}\dots\meta{arg$_1$}|}}|
+\end{center}
+
+\indexitem{loop>repeat}|=|\meta{number}\meta{keylist}
+
+ The \meta{keylist} is processed \meta{number} times.
+
+ The \meta{number} expression is evaluated using |pgfmath|.
+
+\indexitem{loop>while}|=|\meta{pgfmath condition}\meta{keylist}
+ \itemnosep
+\indexitem{loop>do while}|=|\meta{pgfmath condition}\meta{keylist}
+ \itemnosep
+\indexitem{loop>until}|=|\meta{pgfmath condition}\meta{keylist}
+ \itemnosep
+\indexitem{loop>do until}|=|\meta{pgfmath condition}\meta{keylist}
+
+ \keyname{while} loops cycle while the condition is true, \keyname{until} loops terminate when the
+ condition becomes true.
+
+ The \keyname{do} variants check the condition after processing the \meta{keylist}; thus, the
+ keylist is executed at least once. The variants without the \keyname{do} prefix check the
+ condition before processing the \meta{keylist}, which might therefore not be processed at all.
+
+ When \meta{pgfmath condition} is an empty string, condition \index{valid} is implicitely used,
+ and \meta{keylist} is implicitely embedded in \index{nodewalk key>on invalid}|=fake|. Thus, the |while|
+ loops will cycle until they ``walk out of the tree'', and |until| loops will cycle until they
+ ``walk into the tree.''
+
+ \begin{advise}
+ \item If a loop ``walks out of the tree'', you can get it back in using \index{last valid} or
+ \index{nodewalk key>strip fake steps}.
+ \end{advise}
+
+
+\begin{forestexample}[index={root',content,step>n,delay,for step,nodewalk,do until}]
+ \pgfmathsetseed{1234}
+ \begin{forest}
+ try/.style={root',content+={#1,\ },n=#1},
+ delay={
+ for nodewalk={~do until~={}{try/.pgfmath={random(1,20)}},draw}{},
+ },
+ [tried:\ [1][2][3][4][5]]
+ \end{forest}
+\end{forestexample}
+
+\indexitem{loop>while nodewalk valid}|=|\meta{nodewalk}\meta{keylist}
+ \itemnosep
+\indexitem{loop>do while nodewalk valid}|=|\meta{nodewalk}\meta{keylist}
+ \itemnosep
+\indexitem{loop>until nodewalk valid}|=|\meta{nodewalk}\meta{keylist}
+ \itemnosep
+\indexitem{loop>do until nodewalk valid}|=|\meta{nodewalk}\meta{keylist}
+ \itemnosep
+\indexitem{loop>while nodewalk empty}|=|\meta{nodewalk}\meta{keylist}
+ \itemnosep
+\indexitem{loop>do while nodewalk empty}|=|\meta{nodewalk}\meta{keylist}
+ \itemnosep
+\indexitem{loop>until nodewalk empty}|=|\meta{nodewalk}\meta{keylist}
+ \itemnosep
+\indexitem{loop>do until nodewalk empty}|=|\meta{nodewalk}\meta{keylist}
+
+ \meta{nodewalk} is embedded within \index{nodewalk key>on invalid}|=fake|.
+
+
+\indexitem(0){loop>break}|=|$n$ Break out of the loop.
+
+ The loop is only exited after all the keys in the current cycle have been processed.
+
+ The optional argument $n$ ($n\geq0$) specifies which level of embedding to break from; the default
+ is to break out of the innermost loop.
+
+\end{syntax}
+
+
+\subsection{Dynamic tree}
+\label{ref:dynamic}
+
+The following keys can be used to change the geometry of the tree by creating new nodes and
+integrating them into the tree, moving and copying nodes around the tree, and removing nodes from
+the tree.
+
+The \meta{node} that will be (re)integrated into the tree can be specified in the following ways:
+\begin{syntax}
+\item \meta{empty}: uses the last non-integrated (i.e.\ created/removed/replaced) node.
+\item \meta{node}: a new node is created using the given bracket representation (the node may
+ contain children, i.e.\ a tree may be specified), and used as the argument to the key.
+
+ The bracket representation must be enclosed in brackets, which will usually be enclosed in
+ braces to prevent them being parsed while parsing the ``host tree.''
+ \begin{advise}
+ \item Unlike the bracket representation in a \index{environment>forest} environment, the bracket
+ representation of a dynamically created node \emph{must} start with |[|. Specifically, it cannot
+ begin with a preamble or the action character.
+ \end{advise}
+\item \index{relative node name}: the node \meta{relative node name} resolves to will be used.
+\end{syntax}
+
+A dynamic tree operation is made in two steps:
+\begin{itemize}
+\item If the argument is given by a \meta{node} argument, the new node is created immediately,
+ i.e.\ while the dynamic tree key is being processed. Any options of the new node are
+ implicitely \index{delay}ed.
+\item The requested changes in the tree structure are actually made between the cycles of keylist
+ processing.
+\end{itemize}
+
+\begin{advise}
+\item Such a two-stage approach is employed because changing the tree structure during the dynamic
+ tree key processing would lead to an unmanageable order of keylist processing.
+\item A consequence of this approach is that nested dynamic tree keys take several cycles to
+ complete. Therefore, be careful when using \index{delay} and dynamic tree keys
+ simultaneously: in such a case, it is often safer to use \index{before typesetting nodes}
+ instead of \index{delay}, see example (\ref{ex:append}).
+\item Examples: title page (in style |random tree|) and (\ref{ex:niceemptynodes}) (in style
+ |xlist|).
+\end{advise}
+
+Here is the list of dynamic tree keys:
+
+\begin{syntax}
+\indexitem{dynamic tree>append}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
+
+ The specified node becomes the new final child of the current node. If the specified node had a
+ parent, it is first removed from its old position.
+
+\begin{forestexample}[label=ex:append,point=append,index={append,delay,for step,tree,option>n,content,option>n',repeat}]
+ \begin{forest}
+ before typesetting nodes={for tree={
+ if n=1{content=L}
+ {if n'=1{content=R}
+ {content=C}}}}
+ [,repeat=2{append={[
+ ,repeat=3{append={[]}}
+ ]}}]
+ \end{forest}
+\end{forestexample}
+
+\indexitem{dynamic tree>create}|=[|\meta{node}|]|
+
+Create a new node. The new node becomes the last node.
+
+\indexitem{dynamic tree>create'}|=[|\meta{node}|]|
+
+Create a new node and process its given options immediately. The new node becomes the last node.
+
+\indexitem{dynamic tree>insert after}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
+
+ The specified node becomes the new following sibling of the current node. If the specified node had a
+ parent, it is first removed from its old position.
+
+\indexitem{dynamic tree>insert before}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
+
+ The specified node becomes the new previous sibling of the current node. If the specified node had a
+ parent, it is first removed from its old position.
+
+\indexitem{dynamic tree>prepend}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
+
+ The specified node becomes the new first child of the current node. If the specified node had a
+ parent, it is first removed from its old position.
+
+\indexitem{dynamic tree>remove}
+
+The current node is removed from the tree and becomes the last node.
+
+The node itself is not deleted: it is just not integrated in the tree anymore. Removing the root
+node has no effect.
+
+\indexitem{dynamic tree>replace by}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
+
+ The current node is replaced by the specified node. The current node becomes the last node.
+
+ If the specified node is a new node containing a dynamic tree key, it can refer to the replaced
+ node by the \meta{empty} specification. This works even if multiple replacements are made.
+
+ If \keyname{replace by} is used on the root node, the ``replacement'' becomes the root node
+ (\index{set root} is used).
+
+\end{syntax}
+
+If given an existing node, most of the above keys \emph{move} this node
+(and its subtree, of course). Below are the versions of these operations which rather \emph{copy}
+the node: either the whole subtree (|'|) or just the node itself (|''|).
+\begin{syntax}
+\indexitem{dynamic tree>append'}, \indexdef{dynamic tree>insert after'}, \indexdef{dynamic tree>insert before'}, \indexdef{dynamic tree>prepend'},
+ \indexdef{dynamic tree>replace by'}
+
+ Same as versions without |'| (also the same arguments), but it is the copy of the specified node
+ and its subtree that is integrated in the new place.
+\indexitem{dynamic tree>append''}, \indexdef{dynamic tree>insert after''}, \indexdef{dynamic tree>insert before''}, \indexdef{dynamic tree>prepend''},
+ \indexdef{dynamic tree>replace by''}
+
+ Same as versions without |''| (also the same arguments), but it is the copy of the specified node
+ (without its subtree) that is integrated in the new place.
+
+\begin{advise}
+\item You might want to \index{delay} the processing of the copying operations, giving the
+ original nodes the chance to process their keys first!
+\end{advise}
+
+\indexitem{dynamic tree>copy name template}|=|\meta{empty}\OR\meta{macro definition} \hfill\meta{empty}
+
+Defines a template for constructing the \index{option>name} of the copy from the name of the
+original. \meta{macro definition} should be either empty (then, the \index{option>name} is
+constructed from the \index{option>id}, as usual), or an expandable macro taking one argument (the
+name of the original).
+
+\begin{forestexample}
+ \begin{forest}
+ copy name template={copy of #1}
+ [CP,delay={prepend'=subject}
+ [VP[DP,name=subject[D][NP]][V'[V][DP]]]]
+ \draw[->,dotted] (subject)--(copy of subject);
+ \end{forest}
+\end{forestexample}
+
+\indexitem{dynamic tree>set root}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
+
+The specified node becomes the new \emph{formal} root of the tree.
+
+Note: If the specified node has a parent, it is \emph{not} removed from it. The node becomes the
+root only in the sense that the default implementation of stage-processing will consider it a
+root, and thus typeset/pack/draw the (sub)tree rooted in this root. The processing of keys such
+as \index{for step=\index{step>parent}} and \index{for step=\index{root}} is not affected: \index{for step=\index{root}} finds the
+real, geometric root of the current node. To access the formal root, use nodewalk step
+\index{root'}, or the corresponding propagator \index{for step=\index{root'}}.
+
+\indexitem{dynamic tree>sort}, \indexdef{dynamic tree>sort'} Sort the children of the current node,
+ using the currently active sort key specified in \index{sort by} (see
+ \S\ref{ref:nodewalk-operations}). |sort| sorts in ascending and |sort'| in descending order.
+
+\end{syntax}
+
+
+\subsection{Handlers}
+\label{ref:handlers}
+
+\begin{syntax}
+\indexitem{handler>option}|=|\meta{option}
+
+The result is the value of \meta{option} at the current node.
+
+\indexitem{handler>register}|=|\meta{register}
+
+The result is the value of \meta{register}.
+
+\indexitem{handler>pgfmath}|=|\meta{pgfmath expression}
+
+The result is the evaluation of \meta{pgfmath expression} in the context of the current node.
+
+\begin{advise}
+\item
+ If you only need to access an option or register value, using \index{handler>option} or
+ \index{handler>register} is much faster than using \keyname{.pgfmath}.
+\end{advise}
+
+\indexitem{handler>wrap value}|=|\meta{macro definition}
+
+The result is the (single) expansion of the given
+ \meta{macro definition}. The defined macro takes one parameter. The current value of the
+ handled option will be passed as that parameter.
+
+\indexitem{handler>wrap $n$ pgfmath args}|=|\meta{macro definition}\meta{arg $1$}\dots\meta{arg $n$}
+
+ The result is the (single) expansion of the given \meta{macro definition}. The defined macro
+ takes $n$ parameters, where $n\in\{2,\dots,8\}$. Expressions \meta{arg $1$} to \meta{arg $n$}
+ are evaluated using |pgfmath| and passed as arguments to the defined macro.
+
+\indexitem{handler>wrap pgfmath arg}|=|\meta{macro definition}\meta{arg}
+
+ Like \index{wrap $n$ pgfmath args} would work for $n=1$.
+
+\indexitem{handler>process args}|=|\meta{argument types}\meta{arg $1$}\dots\meta{arg $n$}
+
+ The result is a list of processed arguments. Arguments
+ are processed individually according to their given type. The types are given sequentially in
+ \meta{argument types}, one character (no spaces) for each argument. The meanings of the characters are given in the table below. The exception to the one character -- one argument rule are characters
+ connected by |+|, which apply iteratively (in the given order) to a single argument. If the
+ argument type list is shorter than the number of argument, the remaining arguments are assumed to
+ require no processing.
+
+ \begin{tabular}{ll}
+ |__|&no processing\\
+ |o|&expand once\\
+ |x|&fully expand\\
+ |O|&argument is an option name\\
+ |R|&argument is a register name\\
+ |P|&argument is a pgfmath expression\\
+ |r|&the argument should be a comma-separated list: reverse it\\
+ |+|&chain processors)\\
+ \end{tabular}
+
+ Example: \index{split option} is defined by preprocessing the first argument of \index{split}
+ as an option.
+\lstinputregion{forest.dtx}{split_option}
+
+\begin{forestexample}[index={delay,append,strequal,split,process args}]
+ \begin{forest}
+ [
+ {1,2,3,4,5},
+ delay={
+ my append/.style={if={strequal("#1","")}{}{append={[#1]}}},
+ split/.~process args~={O+r}{content}{,}{my append},
+ }
+ ]
+ \end{forest}
+\end{forestexample}
+
+\end{syntax}
+
+\subsubsection{Aggregate functions}
+\label{ref:aggregate-functions}
+
+Aggregate functions are defined as handlers over options. They walk a nodewalk, use the values of visited options to calculate something, and store the result in the handled option.
+
+Aggregate functions cannot be nested.
+
+\begin{syntax}
+ \indexitem{aggregate>count}|=|\meta{nodewalk}
+
+ Store the number of nodes visited in the nodewalk into the handled option.
+
+\indexitem{aggregate>sum}|=|\meta{pgfmath}\meta{nodewalk}\itemnosep
+\indexitem{aggregate>average}|=|\meta{pgfmath}\meta{nodewalk}\itemnosep
+\indexitem{aggregate>product}|=|\meta{pgfmath}\meta{nodewalk}\itemnosep
+\indexitem{aggregate>min}|=|\meta{pgfmath}\meta{nodewalk}\itemnosep
+\indexitem{aggregate>max}|=|\meta{pgfmath}\meta{nodewalk}
+
+ Calculate the value of \meta{pgfmath} expression at each visited node. Store the sum / average / product / minimum / maximum of these values into the handled option.
+
+\indexitem{aggregate>aggregate}|=|\meta{pgfmath: start value}\meta{pgfmath: every step}\meta{pgfmath: after walk}\meta{nodewalk}
+
+ The generic aggregate function. First, the result is set to \meta{pgfmath: start value}. Then,
+ the given nodewalk is walked. After each step of the \meta{nodewalk}, \meta{pgfmath: every step} expression is evaluated in the context of the new current node and stored as the result. After the walk, the current node is reset to the origin. \meta{pgfmath: after walk} expression is then evaluated in its context and stored as the result.
+
+ Use (appropriately escaped) |#1| to refer to the current value of the result in \meta{pgfmath:
+ every step} and \meta{pgfmath: after walk}. Use count register \index{aggregate n} to refer
+ to the current step number (in \meta{pgfmath: every step}) or the total number of steps (in \meta{pgfmath: after walk})
+
+ Example 1: see \index{option>s}.
+
+ Example 2: the definition of \index{aggregate>average} below. Note that as we are using
+ |.aggregate| inside a style definition, |##1| must be used to refer to the current value of the
+ result.
+\begin{lstlisting}[]
+ /handlers/~.average~/.style 2 args={
+ /handlers/~.aggregate~=
+ {0}
+ {(##1)+(#1)}
+ {##1/\forestregister{aggregate n}}
+ {#2}
+ }
+\end{lstlisting}
+ Example 3: randomly generate the content of leaves; the content of a parent is the sum of it's children's content.
+
+\begin{forestexample}[index={delay,aggregate postparse,for step,tree children-first,if option,n children,content,pgfmath,sum,step>children}]
+ \begin{forest}
+ delay={
+ aggregate postparse=int,
+ for tree children-first={
+ if n children=0
+ {content/.pgfmath={random(0,100)}}
+ {content/~.sum~={content}{children}}
+ }
+ }
+ [[[[][]][]][[][][[][][]]][[][[][]]]]
+ \end{forest}
+\end{forestexample}
+
+\indexitem{register>aggregate n}|=|\meta{count}
+ In the every-step expression of an aggregate function, refers to the (real) step number in the aggregate's \meta{nodewalk}. In the after-walk expression, refers to the total number of (real) steps made.
+
+\indexitem{node key>aggregate postparse}|=|\alternative{none,int,print,macro}
+
+ Roughly speaking, how should the result be formatted? For details, see \citep[\S89]{tikzpgf3.0.0}.
+
+ \begin{syntax}
+ \item\indexdef{value=aggregate postparse>none}
+ No formatting.
+ \item\indexdef{value=aggregate postparse>int}
+ The result is an integer.
+ \item\indexdef{value=aggregate postparse>print}
+ Use |pgf|'s number printing extension, see \citep[\S93]{tikzpgf3.0.0}.
+ \item\indexdef{value=aggregate postparse>macro}
+ Use a custom macro. Specify the macro using \indexdef{node key>aggregate postparse macro}|=|\meta{cs}.
+ \end{syntax}
+
+\end{syntax}
+
+
+\subsection{Relative node names}
+\label{ref:relative-node-names}
+
+\begin{syntax}
+\indexitem{meta>relative node name}|=|[\meta{forest node name}][\indexdef[set={code}]>{!}\meta{nodewalk}]
+
+ \meta{relative node name} refers to the \foRest; node at the end of the \meta{nodewalk}
+ starting at node named \meta{forest node name}. If \meta{forest node name} is omitted, the walk
+ starts at the current node. If \meta{nodewalk} is omitted, the ``walk'' ends at the start
+ node. (Thus, an empty \meta{relative node name} refers to the current node.)
+
+ The \meta{nodewalk} inherits its history from the outer nodewalk (if there is one). Its every-step
+ keylist is empty.
+\end{syntax}
+
+Relative node names can be used in the following contexts:
+\begin{itemize}
+\item \FoRest;'s |pgfmath| option functions (\S\ref{ref:pgfmath}) take a relative node name as
+ their argument, e.g.\ |content("!u")| and |content("!parent")| refer to the content of the
+ parent node.
+\item An option of a non-current node can be set by \meta{relative node name}|.|\meta{option
+ name}|=|\meta{value}, see \S\ref{sec:option-setting}.
+\item The |forest| coordinate system, both explicit and implicit; see \S\ref{ref:forest-cs}.
+\end{itemize}
+
+\subsection{The \texttt{forest} coordinate system}
+\label{ref:forest-cs}
+
+Unless package options \index{tikzcshack} is set to |false|, \TikZ;'s implicit node coordinate
+system \citep[\S13.2.3]{tikzpgf2.10} is hacked to accept relative node names.\footnote{Actually,
+the hack can be switched on and off on the fly, using \cmdname{i}\keyname{foresttikzcshack}.}.
+
+The explicit \texttt{forest} coordinate system is called simply |forest| and used like this:
+|(forest_cs:|\meta{forest cs spec}|)|; see \citep[\S13.2.5]{tikzpgf2.10}. \meta{forest cs spec}
+is a keylist; the following keys are accepted.
+
+\begin{syntax}
+\indexitem{forest cs>name}|=|\meta{node name} The node with the given name becomed the current node. The
+resulting point is its (node) anchor.
+\indexitem{forest cs>id}|=|\meta{node id} The node with the given name becomed the current node. The
+resulting point is its (node) anchor.
+\indexitem{forest cs>go}|=|\meta{nodewalk} Walk the given nodewalk, starting at the current node. The
+ node at the end of the walk becomes the current node. The resulting point is its (node) anchor.
+ The embedded \meta{nodewalk} inherits history from the outer nodewalk.
+\indexitem{forest cs>anchor}|=|\meta{anchor} The resulting point is the given anchor of the current node.
+\indexitem{forest cs>l}|=|\meta{dimen} \vspace{-\parskip}
+\indexitem{forest cs>s}|=|\meta{dimen} Specify the \index{option>l} and \index{option>s}
+coordinate of the resulting point.
+
+The coordinate system is the node's ls-coordinate system: its origin is at its (node) anchor; the
+l-axis points in the direction of the tree growth at the node, which is given by option
+\index{grow}; the s-axis is orthogonal to the l-axis; the positive side is in the
+counter-clockwise direction from |l| axis.
+
+The resulting point is computed only after both \index{option>l} and \index{option>s} were given.
+\item Any other key is interpreted as a \index{relative node name}[.\meta{anchor}].
+\end{syntax}
+
+
+\subsection{Anchors}
+\label{sec:anchors}
+
+\FoRest; defines several anchors which can be used with any \TikZ; node belonging to a \FoRest;
+tree (manually added \TikZ; nodes are thus excluded).
+
+\begin{syntax}
+\indexitem{anchor>parent anchor}\itemnosep
+\indexitem{anchor>child anchor}\itemnosep
+\indexitem{anchor>anchor}
+
+ These anchors point to coordinates determined by node options \index{option>parent anchor},
+ \index{option>child anchor} and \index{option>anchor}.
+
+\indexitem{anchor>parent}, \indexdef{anchor>parent'}\itemnosep
+\indexitem{anchor>parent first}, \indexdef{anchor>parent first'}\itemnosep
+\indexitem{anchor>first}, \indexdef{anchor>first'}\itemnosep
+\indexitem{anchor>children first}, \indexdef{anchor>children first'}\itemnosep
+\indexitem{anchor>children}, \indexdef{anchor>children}\itemnosep
+\indexitem{anchor>children last}, \indexdef{anchor>children last}\itemnosep
+\indexitem{anchor>last}, \indexdef{anchor>last}\itemnosep
+\indexitem{anchor>parent last}, \indexdef{anchor>parent last}
+Growth direction based anchors.
+
+ \TikZ;'s ``compass anchors'' |east|, |north| etc.\ resolve to coordinates on the border of the
+ node facing east, north etc.\ (for the shapes that define these anchors). The above \FoRest;'s
+ anchors are similar in that they also resolve to coordinates on the border of the node. However,
+ the ``cardinal directions'' are determined by the \index{grow}th direction of the tree in the node, so
+ that
+ \begin{itemize}
+ \item anchor |parent| faces the parent node;
+ \item anchor |children| faces the children;
+ \item anchor |first| faces the first child;
+ \item anchor |last| faces the last child.
+ \end{itemize}
+ Combinations like |parent_children| work like combinations of compass directions, e.g.\
+ |north_west|. These anchors work as expected even if the node is \index{rotate}d, or if the
+ children are \index{reversed}.
+
+ The |'| variants refer precisely to
+ the point where the cardinal growth direction intersects the border. Variants without |'| snap to
+ the closest compass anchor of the node.
+
+ For simple examples, see definitions of \index{sn edges} and \index{roof}; for more involved
+ examples, see the \reflibrary{edges} library.
+\end{syntax}
+
+\subsection{Additional \texttt{pgfmath} functions}
+\label{ref:pgfmath}
+
+For every option and register, \foRest; defines a pgfmath function with the same name, with the
+proviso that all non-alphanumeric characters in the option/register name are replaced by an underscore
+|__| in the pgfmath function name.
+
+Pgfmath functions corresponding to options take one argument, a \index{relative node name}
+(see~\S\ref{ref:relative-node-names}) expression, making it possible to refer to option values of
+non-current nodes. The \meta{relative node name} expression must be enclosed in double quotes in
+order to
+prevent pgfmath evaluation: for example, to refer to the content of the parent, write
+\index{content}|("|\index>{!}|u")|. To refer to the option of the current node, use empty parentheses:
+\index{content}|()|.\footnote{In most cases, the parentheses are optional, so \texttt{content}
+is ok. A known case where this doesn't work is preceding an operator: \texttt{l+1cm} will fail.}
+
+If the \index{relative node name} resolves to the invalid node, these functions will an return empty
+token list (for \meta{toks} options), 0pt (for \meta{dimen} options) or 0 (for \meta{count}
+options).
+
+Note that the nodewalk in the relative node name inherits its history from the outer nodewalk (if
+there is one), so strange but useful constructions like the following are possible.
+
+\begin{forestexample}[index={tikz,wrap pgfmath arg,nodewalk}]
+ \begin{forest}
+ for tree={no edge},
+ before typesetting nodes={
+ for nodewalk={
+ c,
+ every step={
+ tikz/.wrap pgfmath arg=
+ {\draw[<-] ()--(#1);}
+ {name("~!b~")}
+ },
+ 21{up1},ancestors
+ }{}
+ },
+ [1[2[3]][4[5]]]
+ \end{forest}
+\end{forestexample}
+
+Boolean function \indexdef{pgfmath>valid} returns true if the node's \index{option>id}$\neq0$, i.e.\ if the node is a real, valid node; see \S\ref{ref:spatial-propagators} and \S\ref{ref:nodewalks}. Boolean function \indexdef{pgfmath>invalid} is a negation of |valid|.
+
+\begin{syntax}
+\indexitem[set={+format={detokenize}}]{pgfmath>min_l}|=(|\meta{nodewalk: node}|,|\meta{nodewalk: context node}|)| \itemnosep
+\indexitem[set={+format={detokenize}}]{pgfmath>min_s}|=(|\meta{nodewalk: node}|,|\meta{nodewalk: context node}|)| \itemnosep
+\indexitem[set={+format={detokenize}}]{pgfmath>max_l}|=(|\meta{nodewalk: node}|,|\meta{nodewalk: context node}|)| \itemnosep
+\indexitem[set={+format={detokenize}}]{pgfmath>max_s}|=(|\meta{nodewalk: node}|,|\meta{nodewalk: context node}|)|
+
+ These functions return the minimum/maximum value of \index{option>l}/\index{option>s} of node at the end of \meta{nodewalk:
+ node} in the context (i.e.\ growth direction) of node at the end of \meta{nodewalk: context
+ node}.
+\end{syntax}
+
+Three string functions are also added to |pgfmath|: \indexdef{pgfmath>strequal} tests the equality of
+its two arguments; \indexdef{pgfmath>instr} tests if the first string is a substring of the second one;
+\indexdef{pgfmath>strcat} joins an arbitrary number of strings.
+
+\bigskip
+
+Some random notes on |pgfmath|: \begin{enumerate*}[(i)]
+\item |&&|, \verb!||! and |!| are boolean ``and'', ``or'' and ``not'', respectively.
+\item The equality operator (for numbers and dimensions) is |==|, \emph{not} |=|.
+\end{enumerate*} And some examples:
+
+\begin{forestexample}[layout=tree on top,index={for step,tree,grow',calign,option>l,l sep,option>child
+anchor,option>anchor,fit,tier,option>level,delay,before typesetting nodes,content,wrap $n$ pgfmath args,pgfmath},index>={!}]
+ \begin{forest}
+ for tree={grow'=0,calign=first,l=0,l sep=2em,child anchor=west,anchor=base
+ west,fit=band,tier/.pgfmath=~level~()},
+ fullpath/.style={if n=0{}{content/.wrap 2
+ pgfmath args={##1/##2}{~content~("!u")}{~content~()}}},
+ delay={for tree=fullpath,content=/},
+ before typesetting nodes={for tree={content=\strut#1}}
+ [
+ [home
+ [joe
+ [\TeX]]
+ [saso
+ [\TeX]]
+ [a user with a long name
+ [\TeX]]]
+ [usr]]
+ \end{forest}
+\end{forestexample}
+
+\begin{forestexample}[point=instr,index={delay,for step,tree,conditional>if,content,n children}]
+ % mark non-phrasal terminal nodes
+ \begin{forest}
+ delay={for tree={if=
+ {!instr("P",~content~) && ~n_children~==0}
+ {fill=yellow}
+ {}
+ }}
+ [CP[DP][C'[C][TP[DP][T'[T][VP[DP][V'[V][DP]]]]]]]
+ \end{forest}
+\end{forestexample}
+
+\begin{forestexample}[point=instr,index={where option,n children,tier,content,no edge,tikz},index>={!}]
+ % roof terminal phrases
+ \begin{forest}
+ where n children=0{tier=word,
+ if={~instr~("P",~content~("!u"))}{no edge,
+ tikz={\draw (!.north west)--
+ (!.north east)--(!u.south)--cycle;
+ }}{}
+ }{},
+ [VP[DP[Mary]][V'[V[loves]][DP[her cat]]]]
+ \end{forest}
+\end{forestexample}
+
+
+\subsection{Standard node}
+\label{ref:standard-node}
+
+\begin{syntax}
+\indexitem{macro>forestStandardNode}\meta{node}\meta{environment fingerprint}\meta{calibration
+ procedure}\meta{exported options}
+
+ This macro defines the current \emph{standard node}. The standard node declares some options as
+ \emph{exported}. When a new node is created, the values of the exported options are initialized
+ from the standard node. At the beginning of every \index{forest} environment, it is checked whether
+ the \emph{environment fingerprint} of the standard node has changed. If it did, the standard
+ node is \emph{calibrated}, adjusting the values of exported options. The \emph{raison d'etre} for
+ such a system is given in \S\ref{tut:defaults}.
+
+ In \meta{node}, the standard node's content and possibly other options are specified, using the
+ usual bracket representation. The \meta{node}, however, \emph{must not contain children}. The
+ default: \texttt{[dj]}.
+
+ The \meta{environment fingerprint} must be an expandable macro definition. It's expansion
+ should change whenever the calibration is necessary.
+
+ \meta{calibration procedure} is a keylist (processed in the |/forest| path) which calculates the
+ values of exported options.
+
+ \meta{exported options} is a comma-separated list of exported options.
+
+ This is how the default standard node is created:
+\begin{lstlisting}
+ \forestStandardNode[dj]
+ {%
+ \forestOve{\csname forest@id@of@standard node\endcsname}{content},%
+ \the\ht\strutbox,\the\pgflinewidth,%
+ \pgfkeysvalueof{/pgf/inner ysep},\pgfkeysvalueof{/pgf/outer ysep},%
+ \pgfkeysvalueof{/pgf/inner xsep},\pgfkeysvalueof{/pgf/outer xsep}%
+ }
+ {
+ l sep={\the\ht\strutbox+\pgfkeysvalueof{/pgf/inner ysep}},
+ l={l_sep()+abs(max_y()-min_y())+2*\pgfkeysvalueof{/pgf/outer ysep}},
+ s sep={2*\pgfkeysvalueof{/pgf/inner xsep}}
+ }
+ {l sep,l,s sep}
+ \end{lstlisting}
+\end{syntax}
+
+\subsection{Externalization}
+\label{ref:externalization}
+
+Externalized tree pictures are compiled only once. The result of the compilation is saved into a
+separate |.pdf| file and reused on subsequent compilations of the document. If the code of the
+tree (or the context, see below) is changed, the tree is automatically recompiled.
+
+Externalization is enabled by:
+\begin{lstlisting}
+ \usepackage[~external~]{forest}
+ ~\tikzexternalize~
+\end{lstlisting}
+Both lines are necessary. \TikZ;'s externalization library is automatically loaded if necessary.
+
+\begin{syntax}
+\indexitem{node key>external/optimize} Parallels \keyname{/tikz/external/optimize}: if |true| (the
+default), the processing of non-current trees is skipped during the embedded compilation.
+\indexitem{node key>external/context} If the expansion of the macro stored in
+this option changes, the tree is recompiled.
+\indexitem{node key>external/depends on macro}|=|\meta{cs} Adds the definition of macro \meta{cs} to
+\keyname{external/context}. Thus, if the definition of \meta{cs} is changed, the tree will be
+recompiled.
+\end{syntax}
+
+\foRest; respects or is compatible with several (not all) keys and commands of \TikZ;'s
+externalization library. In particular, the following keys and commands might be useful; see
+\cite[\S32]{tikzpgf2.10}.
+\begin{itemize}
+\item\keyname{/tikz/external/remake next}
+\item\keyname{/tikz/external/prefix}
+\item\keyname{/tikz/external/system call}
+\item\cmdname{tikzexternalize}
+\item\cmdname{tikzexternalenable}
+\item\cmdname{tikzexternaldisable}
+\end{itemize}
+\FoRest; does not disturbe the externalization of non-\foRest; pictures. (At least it
+shouldn't \dots)
+
+The main auxiliary file for externalization has suffix |.for|. The externalized pictures have
+suffices |-forest-|$n$ (their prefix can be set by \keyname{/tikz/external/prefix}, e.g.\ to a
+subdirectory). Information on all trees that were ever externalized in the document (even if
+they were changed or deleted) is kept. If you need a ``clean'' |.for| file, delete it and
+recompile. Deleting |-forest-|$n$|.pdf| will result in recompilation of a specific tree.
+
+Using \keyname{draw tree} and \keyname{draw tree'} multiple times \emph{is} compatible with
+externalization, as is drawing the tree in the box (see \index{draw tree box}). If you are
+trying to externalize a \index{forest} environment which utilizes \index{TeX} to produce a
+visible effect, you will probably need to use \index{TeX'} and/or \index{TeX''}.
+
+\setcounter{CodelineNo}{0}
+\DocInput{forest-libs.dtx}
+
+\section{Gallery}
+\label{sec:gallery}
+
+\subsection{Decision tree}
+\label{sec:example-decision-tree}
+
+The following example was inspired by a question on \TeX\ Stackexchange:
+\href{http://tex.stackexchange.com/questions/39103/how-to-change-the-level-distance-in-tikz-qtree-for-one-level-only}{How to change the level distance in tikz-qtree for one level only?}. The question is about |tikz-qtree|: how to adjust the level distance for the first level only, in order to avoid first-level labels crossing the parent--child edge. While this example solves the problem (by manually shifting the offending labels; see \texttt{elo} below), it does more: the preamble is setup so that inputing the tree is very easy.
+
+\begin{forestexample}[layout=tree on top,index={if option,option>n,no edge,tikz,strequal,strcat,option>child anchor,option>parent
+anchor,option>anchor,anchor>anchor,calign,for step,tree,s sep,option>l,n children,declare toks,delay,content,before typesetting nodes,descendants,keylist+=tikz,wrap pgfmath arg,wrap $n$ pgfmath args,split option},index>={!}]
+ \forestset{
+ declare toks={elo}{}, % Edge Label Options
+ anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
+ dot/.style={tikz+={\fill (.child anchor) circle[radius=#1];}},
+ dot/.default=2pt,
+ decision edge label/.style n args=3{
+ edge label/.expanded={node[midway,auto=#1,anchor=#2,\forestoption{elo}]{\strut$\unexpanded{#3}$}}
+ },
+ decision/.style={if n=1
+ {decision edge label={left}{east}{#1}}
+ {decision edge label={right}{west}{#1}}
+ },
+ decision tree/.style={
+ for tree={
+ s sep=0.5em,l=8ex,
+ if n children=0{anchors=north}{
+ if n=1{anchors=south east}{anchors=south west}},
+ math content,
+ },
+ anchors=south, outer sep=2pt,
+ dot=3pt,for descendants=dot,
+ delay={for descendants={~split option~={content}{;}{content,decision}}},
+ }
+ }
+ \begin{forest} decision tree
+ [N,plain content
+ [I;{p_1=0.5},plain content,elo={yshift=4pt}
+ [{5,1};a]
+ [II;b,plain content
+ [{1,2};m]
+ [{2,3};n]
+ ]
+ ]
+ [II;{p_2=0.5},plain content,elo={yshift=4pt}
+ [;c
+ [{1,0};z]
+ [{2,2};t]
+ ]
+ [;d
+ [{3,1};z]
+ [{0,0};t]
+ ]
+ ] {\draw[dashed](!1.anchor)--(!2.anchor) node[pos=0.5,above]{I};}
+ ]
+ \end{forest}
+\end{forestexample}
+
+\setcounter{CodelineNo}{0}
+\DocInput{forest-index.dtx}
+
+\section{Past, present and future}
+\label{sec:changes}
+
+\paragraph{Roadmap} What's planned for future releases?
+\begin{itemize}
+\item filling up the libraries
+\item faster externalization
+\item custom-edge aware packing algorithm and a more flexible (successor of) \index{calign}
+\item support for specialized |forest| environments, including:
+ \begin{itemize}
+ \item selectable input parser,
+ \item namespaces (different function, different options),
+ \item better support for different output types.
+ \end{itemize}
+ In short, everything you need to make \foRest; your favourite spreadsheet! ;-)
+\item code cleanup and extraction of sub-packages possibly useful to other package writers
+\end{itemize}
+
+\subsection{Changelog}
+\label{sec:changelog}
+
+\subsubsection{v2.0}
+
+\begin{description}
+\item[v2.0 (2015/11/??)] \mbox{}
+
+ Backwards incompatible changes (\emph{without} a \index{compat} key --- sorry!):
+ \begin{itemize}
+ \item The unintended and undocumented way to specify defaults using |\forestset{.style={...}}|
+ (see question
+ \href{http://tex.stackexchange.com/questions/167972/making-a-certain-tree-style-the-default-for-forest}{Making
+ a certain tree style the default for forest} at \TeX\ SE) does not work anymore. (Actually, it
+ has never truly worked, and that's why it has not \index{compat} key.) Use \index{default
+ preamble}.
+ \item Renamed augmented assignment operator \meta{option}|-| for prepending to \meta{toks} and
+ \meta{keylist} options \index{+toks=\meta{option}}\index[not print]{+keylist}. A new
+ \index{keylist-=\meta{option}} is defined for keylist options and means ``delete key from keylist.''
+ \item Short nodewalk steps are not simply styles anymore: use \index{define short step} to
+ define them.
+ \end{itemize}
+
+ Backwards incompatible changes with a \index{compat} key:
+ \lstinputregion{forest-compat.sty}{compat_1.0}
+
+ \begin{syntax}
+ \item |compat=|\indexdef{option of=compat>1.0-stages}
+
+ Processing of \index{given options}, which is now exposed, and the new keylists \index{default
+ preamble} and \index{preamble} is now included at the start of the default \index{stages}
+ style. When changing \index{stages}, the instruction to process these keylists must now be
+ given explicitely.
+
+ \item |compat=|\indexdef{option of=compat>1.0-forstep}
+
+ In v1.0, a spatial propagator \index{for step=\meta{step}} could never fail. This turned out to
+ be difficult to debug. In this version, when a propagator steps ``out of the tree'', an error
+ is raised by default. Check out \index{option of=Nodewalk>on invalid} to learn how to simulate
+ the old behaviour without using this compatibility key.
+
+ \item |compat=|\indexdef{option of=compat>1.0-rotate}
+
+ This version of the package introduces
+ option \index{rotate} and \index{autoforward}s it to \index{node options}. This is needed to
+ handle the new \foRest; anchors (\S\ref{sec:anchors}). However, in some rare cases (like the
+ tree on the title page of this manual) it can lead to a discrepancy between the versions, as the
+ time when the value given to \index{rotate} is processed is different. |1.0-rotate| removes
+ option \index{rotate}.
+
+ \item |compat=|\indexdef{option of=compat>1.0-name}
+
+ Documentation of v1.0 requested that node names be unique, but this was not enforced by the
+ package, sometimes leading to errors. v2.0 enforces node name uniqueness. If this causes
+ problems, use this compatibility key. In most cases using \index{name'} instead of
+ \index{option>name} should fix the problem without using compatibility mode.
+
+ \item These keys have been renamed:
+
+ \begin{tabularx}{\linewidth}{lll}
+ old&new&\index{compat} key\\\hline
+ \keyname{node walk}&\index{for step=nodewalk}\footnote{Nodewalks are much improved in v2.0, so some syntax and keys are different than in v1.0!}&\indexdef{option of=compat>1.0-nodewalk}\\
+ \keyname{for}&\index{for step=\index{group}}&\indexdef{option of=compat>1.0-for}\\
+ \keyname{for all next}&\index{for step=\index{following siblings}}&\indexdef{option of=compat>1.0-forall}\\
+ \keyname{for all previous}&\index{for step=\index{preceding siblings}}&\indexdef{option of=compat>1.0-forall}\\
+ \keyname{for ancestors'}&\index{for step=\index{current and ancestors}}&\indexdef{option of=compat>1.0-ancestors}\\
+ (\keyname{for}) \keyname{linear next}&(\index{for step}) \index{next node}&\indexdef{option of=compat>1.0-linear}\\
+ (\keyname{for}) \keyname{linear previous}&(\index{for step}) \index{previous node}&\indexdef{option of=compat>1.0-linear}\\
+ \keyname{triangle}&\index{roof} (library \reflibrary{linguistics})&\indexdef{option of=compat>1.0-triangle}\\
+ \keyname{/tikz/fit to tree}&\index{fit to}\keyname{=}\index{tree}\footnote{The v1.0 key \keyname{/tikz/fit to tree} also set \keyname{inner sep=0}; the v2.0 key \index{fit to} does not do that.}&\indexdef{option of=compat>1.0-fittotree}\\
+ \keyname{begin forest}, \keyname{end forest}&none (use \index{stages}&\index{1.0-stages}\\
+ \keyname{end forest}, \keyname{end forest}&none (use \index{stages}&\index{1.0-stages}\\
+ \end{tabularx}
+ \end{syntax}
+
+ Good news:
+ \begin{itemize}
+ \item Added temporal propagators \index{before packing node} and \index{after packing node}.
+ \item \emph{Much} improved nodewalks, see \S\ref{ref:nodewalks} and \S\ref{ref:spatial-propagators}.
+ \item Implemented looping mechanisms and more conditionals, see \S\ref{ref:conditionals}.
+ \item Implemented library support and started filling up the libraries:
+ \begin{itemize}
+ \item \reflibrary{linguistics}: \index{sn edges}, \index{nice empty nodes}, \index{draw
+ brackets}, \index{c-commanded} and \index{c-commanders}
+ \item \reflibrary{edges}: \index{forked edges} and \index{folder}
+ \end{itemize}
+ \item Implemented aggregate functions, see \S\ref{ref:aggregate-functions}.
+ \item Added key \index{default preamble}.
+ \item Implemented anchors \index{anchor>parent}, \index{anchor>children}, \index{anchor>first},
+ \index{anchor>last}, etc.
+ \item Added key \index{split} and friends.
+ \item Implemented sorting of children, see \S\ref{ref:dynamic}.
+ \item Introduced registers, see \S\ref{sec:options-and-registers}.
+ \item Implemented handlers \index{handler>option}, \index{handler>register} and \index{process args}.
+ \item Implemented several friends to \index{process keylist}, introduced \index{processing order}s
+ and \index{draw tree method}.
+ \item Added the optional argument |(|\meta{stages}|)| to the \index{forest} environment and
+ \index{Forest} macro.
+ \item Implemented \index{autoforward}ing.
+ \item Implemented flexible handling of unknown keys using \index{unknown to}.
+ \item Implemented |pgfmath| functions \index{pgfmath>min_l}, \index{pgfmath>max_l}, \index{pgfmath>min_s}, \index{pgfmath>max_s}.
+ \item Implemented augmented assignment operator \index{keylist-=\meta{keylist option}} for removing keys from keylists.
+ \item Implemented a generalized \index{fit to} key.
+ \item Implemented a very slow \foRest;-based indexing system (used to index this documentation)
+ and included it in the gallery (\S\ref{sec:forest-index}).
+ \item Added some minor keys: \index{edge path'}, \index{node format'}, \index{create'} and \index{plain content}.
+ \item Added some developer keys: \index{copy command key}, \index{typeout}.
+ \end{itemize}
+
+ Bugfixes:
+ \begin{itemize}
+ \item In computation of numeric tree-structure info, when called for a non-root node.
+ \item \TikZ;'s externalization internals (signature of
+ |\tikzexternal@externalizefig@systemcall@uptodatecheck|) have changed: keep up to date,
+ though only formally.
+ \item \index{delay} was not behaving additively.
+ \item \index{option>name}, \index{alias} and \index{baseline} didn't work properly when
+ setting them for a non-current node.
+ \item Augmented assignments for count options were leaking `.0pt'.
+ \item \index{create} didn't work properly in some cases.
+ \item \keyname{triangle} (now \index{roof} in \reflibrary{linguistics}) didn't use |cycle| in the edge path
+ \end{itemize}
+
+\end{description}
+
+\subsubsection{v1.0}
+
+\begin{description}
+\item[v1.0.10 (2015/07/22)] \mbox{}
+ \begin{compactitem}
+ \item Bugfix: a left-over debugging |\typeout| command was interfering with a |forest| within |tabular|, see \href{http://tex.stackexchange.com/questions/256509/odd-incompatibility-between-multi-line-forest-nodes-and-tabular}{this question on TeX.SE}.
+ \item A somewhat changed versioning scheme \dots
+ \end{compactitem}
+\item[v1.09 (2015/07/15)] \mbox{}
+ \begin{compactitem}
+ \item Bugfix: child alignment was not done in nodes with a single child, see \href{http://tex.stackexchange.com/questions/255309/elementary-forest-question-meaning-of-calign-parent-anchor-and-child-anchor}{this question on TeX.SE}.
+ \end{compactitem}
+\item[v1.08 (2015/07/10)] \mbox{}
+ \begin{compactitem}
+ \item Fix externalization (compatibility with new |tikz| features).
+ \end{compactitem}
+\item[v1.07 (2015/05/29)] \mbox{}
+ \begin{compactitem}
+ \item Require package |elocalloc| for local boxes, which were previously defined by package |etex|.
+ \end{compactitem}
+\item[v1.06 (2015/05/04)] \mbox{}
+ \begin{compactitem}
+ \item Load |etex| package: since v2.1a, |etoolbox| doesn't do it anymore.
+ \end{compactitem}
+\item[v1.05 (2014/03/07)] \mbox{}
+ \begin{compactitem}
+ \item Fix the node boundary code for rounded rectangle. (Patch contributed by Paul Gaborit.)
+ \end{compactitem}
+\item[v1.04 (2013/10/17)] \mbox{}
+ \begin{compactitem}
+ \item Fixed an \href{http://tex.stackexchange.com/questions/138986/error-using-tikzexternalize-with-forest/139145}{externalization bug}.
+ \end{compactitem}
+\item[v1.03 (2013/01/28)] \mbox{}
+ \begin{compactitem}
+ \item Bugfix: options of dynamically created nodes didn't get processed.
+ \item Bugfix: the bracket parser was losing spaces before opening braces.
+ \item Bugfix: a family of utility macros dealing with affixing token lists was not expanding
+ content correctly.
+ \item Added style \index{math content}.
+ \item Replace key \keyname{tikz preamble} with more general \index{begin draw} and
+ \index{end draw}.
+ \item Add keys \keyname{begin forest} and \keyname{end forest}.
+ \end{compactitem}
+\item[v1.02 (2013/01/20)] \mbox{}
+ \begin{compactitem}
+ \item Reworked style \index{stages}: it's easier to modify the processing flow now.
+ \item Individual stages must now be explicitely called in the context of some (usually root)
+ node.
+ \item Added \index{delay n} and \index{if have delayed}.
+ \item Added (experimental) \index{pack'}.
+ \item Added reference to the \href{https://github.com/sasozivanovic/forest-styles}{style
+ repository}.
+ \end{compactitem}
+\item[v1.01 (2012/11/14)] \mbox{}
+
+ \begin{compactitem}
+ \item Compatibility with the |standalone| package: temporarily disable the effect of
+ |standalone|'s package option |tikz| while typesetting nodes.
+ \item Require at least the [2010/08/21] (v2.0) release of package |etoolbox|.
+ \item Require version [2010/10/13] (v2.10, rcs-revision 1.76) of \PGF;/\TikZ;. Future
+ compatibility: adjust to the change of the ``not yet positioned'' node name (2.10 |@|
+ $\rightarrow$ 2.10-csv |PGFINTERNAL|).
+ \item Add this changelog.
+ \end{compactitem}
+\item[v1.0 (2012/10/31)] First public version
+\end{description}
+
+
+\paragraph{Acknowledgements}
+Many thanks to the \href{http://tex.stackexchange.com}{\TeX\ SE community} and all the people who
+have provided comments, sent patches and/or reported bugs! I can happily report that the list grows
+too fast to maintain \dots\@ I'll rather work on the package! ;-) And anyway, you know who you are
+\dots\@ thanks!
+
+\subsection{Known bugs}
+\label{sec:bugs}
+
+If you find a bug (there are bound to be some \dots), please contact
+me at \href{mailto:saso.zivanovic@guest.arnes.si}{saso.zivanovic@guest.arnes.si}.
+
+\subsubsection*{System requirements}
+
+This package requires \LaTeX\ and e\TeX. If you use something
+else: sorry.
+
+The requirement for \LaTeX\ might be dropped in the future, when I get some time and energy for a
+code-cleanup (read: to remedy the consequences of my bad programming practices and general
+disorganization).
+
+The requirement for e\TeX\ will probably stay. If nothing else, \foRest; is heavy on boxes: every
+node requires its own \dots\ and consequently, I have freely used e\TeX\ constructs in the code
+\dots
+
+\subsubsection*{\PGF; internals}
+
+\FoRest; relies on some details of \PGF; implementation, like the name
+of the ``not yet positioned'' nodes. Thus, a new bug might appear with the development of \PGF;.
+If you notice one, please let me know.
+
+\subsubsection*{Edges cutting through sibling nodes}
+\label{sec:cutting-edge}
+
+In the following example, the R--B edge crosses the AAA node, although \index{ignore edge} is
+set to the default |false|.
+\begin{forestexample}[index={calign,{value=calign>first},align,{value=align>center},base,{value=base>bottom}}]
+ \begin{forest}
+ calign=first
+ [R[AAAAAAAAAA\\AAAAAAAAAA\\AAAAAAAAAA,align=center,base=bottom][B]]
+ \end{forest}
+\end{forestexample}
+This happens because s-distances between the adjacent children are
+computed before child alignment (which is obviously the correct order in the general case), but
+child alignment non-linearly influences the edges. Observe that the with a different value of
+\index{calign}, the problem does not arise.
+\begin{forestexample}[index={calign,{value=calign>last},align,{value=align>center},base,{value=base>bottom}}]
+ \begin{forest}
+ calign=last
+ [R[AAAAAAAAAA\\AAAAAAAAAA\\AAAAAAAAAA,align=center,base=bottom][B]]
+ \end{forest}
+\end{forestexample}
+While it would be possible to fix the situation after child alignment (at least for some child
+alignment methods), I have decided against that, since the distances between siblings would soon
+become too large. If the AAA node in the example above was large enough, B could easily be pushed
+off the paper. The bottomline is, please use manual adjustment to fix such situations.
+
+\subsubsection*{Orphans}
+\label{sec:orphans}
+
+If the \index{option>l} coordinates of adjacent children are too different (as a result of manual adjustment or
+tier alignment), the packing algorithm might have nothing so say about the desired distance
+between them: in this sense, node C below is an ``orphan.''
+\begin{forestexample}[index={for step,tree,s sep,option>l,dimen*}]
+ \begin{forest}
+ for tree={s sep=0,draw},
+ [R[A][B][C,l*=2][D][E]]
+ \end{forest}
+\end{forestexample}
+To prevent orphans from ending up just anywhere, I have decided to vertically align them with
+their preceding sibling --- although I'm not certain that's really the best solution. In other
+words, you can rely that the sequence of s-coordinates of siblings is non-decreasing.
+
+The decision also influences a similar situation illustrated below. The packing algorithm puts
+node E immediately next to B (i.e.\ under C): however, the monotonicity-retaining mechanism then
+vertically aligns it with its preceding sibling, D.
+\begin{forestexample}[index={for step,tree,s sep,tier}]
+ \begin{forest}
+ for tree={s sep=0,draw},
+ [R[A[B,tier=bottom]][C][D][E,tier=bottom]]
+ \end{forest}
+\end{forestexample}
+
+Obviously, both examples also create the situation of an edge crossing some sibling node(s).
+Again, I don't think anything sensible can be done about this, in general.
+
+
+\addcontentsline{toc}{section}{References}
+\bibliography{tex}
+\bibliographystyle{plain}
+
+\newpage
+\phantomsection
+\addcontentsline{toc}{section}{\indexname}
+\addtocontents{toc}{\protect\setbox0=\protect\vbox{\protect\iffalse}\protect\fi}
+\PrintIndex
+\addtocontents{toc}{\protect\iffalse{\protect\fi}}
+
+\end{document}
+
+%%% Local Variables:
+%%% mode: latex
+%%% fill-column: 100
+%%% TeX-command-default: "Make PDF"
+%%% TeX-master: t
+%%% End:
diff --git a/Master/texmf-dist/doc/latex/forest/forest.pdf b/Master/texmf-dist/doc/latex/forest/forest.pdf
index 78c3a9b1a85..31adef8bbb5 100644
--- a/Master/texmf-dist/doc/latex/forest/forest.pdf
+++ b/Master/texmf-dist/doc/latex/forest/forest.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/forest/tex.bib b/Master/texmf-dist/doc/latex/forest/tex.bib
new file mode 100644
index 00000000000..0f0b8795c7c
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/forest/tex.bib
@@ -0,0 +1,20 @@
+@Manual{tikzpgf2.10,
+ title = {TikZ \& PGF, Manual for Version 2.10},
+ author = {Till Tantau},
+ year = 2007,
+ url = {http://sourceforge.net/projects/pgf}
+}
+
+@book{texbook,
+ author = "Donald E. Knuth",
+ title = "The {TeX}book",
+ publisher = "Addison-Wesley",
+ year = 1996,
+}
+
+@Manual{tikzpgf3.0.0,
+ title = {TikZ \& PGF, Manual for Version 3.0.0},
+ author = {Till Tantau},
+ year = 2013,
+ url = {http://sourceforge.net/projects/pgf}
+}
diff --git a/Master/texmf-dist/makeindex/forest/forest-doc.ist b/Master/texmf-dist/makeindex/forest/forest-doc.ist
new file mode 100644
index 00000000000..8d3fec14b02
--- /dev/null
+++ b/Master/texmf-dist/makeindex/forest/forest-doc.ist
@@ -0,0 +1,25 @@
+%% This file is based on `gind.ist'.
+
+actual '='
+quote '&'
+level '>'
+preamble
+"\n \\begin{theindex} \n \\makeatletter\\scan@allowedfalse\n"
+postamble
+"\n\n \\end{theindex}\n"
+item_x1 "\\efill \n \\subitem "
+item_x2 "\\efill \n \\subsubitem "
+delim_0 "\\pfill "
+delim_1 "\\pfill "
+delim_2 "\\pfill "
+% The next lines will produce some warnings when
+% running Makeindex as they try to cover two different
+% versions of the program:
+lethead_prefix "{\\bfseries\\hfil\\indexlettertotoc "
+lethead_suffix "\\relax\\hfil}\\nopagebreak\n"
+lethead_flag 1
+heading_prefix "{\\bfseries\\hfil\\indexlettertotoc "
+heading_suffix "\\relax\\hfil}\\nopagebreak\n"
+% heading_prefix "{\\bfseries\\hfil "
+% heading_suffix "\\hfil}\\nopagebreak\n"
+headings_flag 1
diff --git a/Master/texmf-dist/source/latex/forest/forest-doc.ins b/Master/texmf-dist/source/latex/forest/forest-doc.ins
new file mode 100644
index 00000000000..41e872e40b7
--- /dev/null
+++ b/Master/texmf-dist/source/latex/forest/forest-doc.ins
@@ -0,0 +1,26 @@
+%% forest-doc.ins
+%%
+%% Copyright (c) 2015 Saso Zivanovic
+%% saso.zivanovic@guest.arnes.si
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% of this license or (at your option) any later version.
+%% The latest version of this license is in
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This file is a part of package `forest'. For the list of files
+%% constituting the package see main source file of the package,
+%% `forest.dtx', or the derived `forest.sty'.
+%%
+\input docstrip.tex
+\keepsilent
+\preamble
+\endpreamble
+\askforoverwritefalse
+\generate{\file{forest-index.sty}{\from{forest-index.dtx}{}}}
+\endbatchfile
diff --git a/Master/texmf-dist/source/latex/forest/forest-index.dtx b/Master/texmf-dist/source/latex/forest/forest-index.dtx
new file mode 100644
index 00000000000..eee8a627218
--- /dev/null
+++ b/Master/texmf-dist/source/latex/forest/forest-index.dtx
@@ -0,0 +1,788 @@
+% \CheckSum{557}
+% \iffalse meta-comment
+% forest-index.dtx
+%% `forest-index' is an indexing system for the documentation of package `forest', using the package itself.
+%%
+%% Copyright (c) 2015 Saso Zivanovic
+%% (Sa\v{s}o \v{Z}ivanovi\'{c})
+%% saso.zivanovic@guest.arnes.si
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% of this license or (at your option) any later version.
+%% The latest version of this license is in
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `author-maintained'.
+%%
+%% This file is a part of package `forest'. For the list of files
+%% constituting the package see main source file of the package,
+%% `forest.dtx', or the derived `forest.sty'.
+%%
+% \fi
+%
+% \newcommand\entry[1]{{``#1''}}
+%
+% \subsection{\protect{\texttt{forest-index}}}
+% \label{sec:forest-index}
+%
+% The indexing system used to document the \foRest; package uses the
+% package itself quite heavily. While this might be a bit surprising
+% at first sight, as indexing draws no trees, the indexing package
+% illustrates the usage of some of the more exotic features and
+% usage-cases of the \foRest; package, which is why its source is
+% included in this documentation.\footnote{Indexing with this package
+% makes the compilation very slow, so I cannot whole-heartedly
+% recommend it, but I still hope that it will make a useful example.}
+%
+% This package has three main functions:
+% \begin{itemize}
+% \item It is possible to index subentries using a \emph{short form}
+% of their index key, i.e.\ without referring to their ancestor
+% entries. For example, instead of writing |\index{option>content}|
+% one can simply write |\index{content}|. (Obviously, the subentry
+% must \entry{content} be defined as belonging to entry
+% \entry{option} first. This is done using
+% |\indexdef{option>content}|.) This works for all keys which are a
+% subentry of a single entry.
+% \item All subentries are automatically entered as main entries as
+% well, with a qualificator of which entry they belong to. So,
+% |\index{option>content}| produces two index entries: entry
+% \entry{option} with subentry \entry{content} and entry
+% \entry{content \scriptsize option}. This works for an arbitrary
+% number of subentry levels.
+% \item Entries can be given options that format the appearance of the
+% entry and/or its descendants in both text and index. (Entries that
+% format the appearance of their descendants are called categories
+% below.)
+% \item If |hyperref| package is loaded, the following hyperlinks are
+% created besides the standard ones linking the page numbers in
+% index to text:
+% \begin{enumerate*}[(i)]
+% \item entries in text link to the definition in text,
+% \item definitions in the text link to the index entry,
+% \item categories in index are cross-linked.
+% \end{enumerate*}
+%
+% \end{itemize}
+%
+% The \foRest; package mainly enters the picture with respect to the
+% entry formatting. A simple (narrow) tree is built containing an entry
+% and all its ancestors. Formatting instructions are then processed
+% using \foRest;'s option processing mechanisms.
+%
+% Finally, note that this package might change without retaining
+% backwards compatibility, and that changes of this package will not
+% be entered into the changelog.
+%
+% Identification.
+% \begin{macrocode}
+\ProvidesPackage{forest-index}
+\RequirePackage{forest}
+% \end{macrocode}
+% Remember the original \LaTeX's |\index| command.
+% \begin{macrocode}
+\let\forestindex@LaTeX@index\index
+% \end{macrocode}
+%
+% \subsubsection*{The user interface macros}
+%
+% \DescribeMacro{\index} is the general purpose macro.
+% \DescribeMacro{\indexdef} and \DescribeMacro{\indexex} are
+% shorthands for indexing definitions and
+% examples. \DescribeMacro{\indexitem} is a combination of |\indexdef|
+% and the |\item| of the |lstdoc| package. It automatically indexes
+% the command being documented. \DescribeMacro{\indexset} neither
+% typesets or indexes the entry, but only configures it; it is usually
+% used to configure categories. All these macros parse their
+% arguments using |xparse|. The arguments, listed in the reverse
+% order:
+% \begin{itemize}
+% \item The final argument, which is the only mandatory argument, is a
+% comma-separated list of index keys.
+% \item The boolean switch |>| just before the mandatory argument
+% signals that the keys are given in the full form. Otherwise, keys
+% without a level separator are considered short.
+% \item Indexing options are given by the |[|optional |]| argument.
+% \item The first |(|optional|)| argument of:
+% \begin{compactitem}
+% \item |\indexitem|: specifies the default value of the command.
+% \item |\index|: is used to
+% provide ``early'' options.
+% \end{compactitem}
+% \end{itemize}
+%
+% Among the options of these commands, three keylists are of special
+% importance: |index_key_format|, |index_form_format| and
+% |print_format|. These hold instructions on how to format the index
+% key, the form of the entry in the index and the form of the entry in
+% the main text. They work by modifying the contents of an
+% \indexex{autowrapped toks} register |result|.
+%
+% An example: how macros are indexed in this documentation. Style
+% |macro| defined below does everything needed to format a macro name:
+% it detokenizes the given name (in case the name contains some funny
+% characters), prefixes the backslash, wraps in in the typewriter
+% font, adds color and hyperlink (the final two styles are defined in
+% below this package). Note the usage of |\protect|: it is needed
+% because we want to use these styles to format entries not just in
+% the main next, but also in the index.
+% \lstinputregion{forest-doc.tex}{index_macro_style} Then, we
+% configure the main level entry \entry{macro}: the child of this
+% entry will be formatted (both in index and in the main text) using
+% the previously defined style.
+% \lstinputregion{forest-doc.tex}{index_macro_category} Usage is then
+% simple: we write |\indexex{macro>forestoption}| (or simply
+% |\indexex{forestoption}| to get \indexex{forestoption}.
+%
+% \begin{macrocode}
+\DeclareDocumentCommand\indexdef{O{} t> m}{%
+ \IfBooleanTF{#2}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@long}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
+ \forestindex@index{definition}{#1}{#3}}
+\DeclareDocumentCommand\indexex{O{} t> m}{%
+ \IfBooleanTF{#2}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@long}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
+ \forestindex@index{example}{#1}{#3}}
+\DeclareDocumentCommand\indexitem{D(){} O{} t> m}{%
+ \IfBooleanTF{#3}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@long}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
+ \forestindex@index{definition}{default={#1},print format=item,#2}{#4}}
+\DeclareDocumentCommand\indexset{O{} t> m}{%
+ \IfBooleanTF{#2}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@long}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
+ \forestindex@index{not print,not index,definition}{set={#1}}{#3}}
+\DeclareDocumentCommand\index{D(){} O{} t> m}{%
+ \IfBooleanTF{#3}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@long}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
+ \forestindex@index{#1}{#2}{#4}%
+}
+% \end{macrocode}
+% All UI macros call this macro.
+% \begin{arguments}
+% \item early option keylist
+% \item late option keylist
+% \item a comma-sep list of forest index key (full or short form). A
+% key can be given an argument using |key=argument| syntax. How the
+% argument is used is up to the user. For example, the
+% \entry{environment} entry of the \foRest; documentation uses it to
+% typeset the contents of the environment:
+% \lstinputregion{forest-doc.tex}{forest_environment_doc}
+% \end{arguments}
+% \begin{macrocode}
+\def\forestindex@index#1#2#3{%
+% \end{macrocode}
+% Partition the index keylist into single keys.
+% \begin{macrocode}
+ \forcsvlist{\forestindex@forkey{#1}{#2}}{#3}%
+}
+\def\forestindex@forkey#1#2#3{%
+% \end{macrocode}
+% Short-key resolution. The result is stored into |\forestindex@fullkey|.
+% \begin{macrocode}
+ \forestindex@resolvekey{#3}%
+% \end{macrocode}
+% Call the central processing command, style |@index|. See how
+% \indexex{process args} is used to expand (once) the last argument.
+% \begin{macrocode}
+ \forestset{@index/.process args={__o}{#1}{#2}{\forestindex@fullkey}}%
+}
+\forestset{
+% \end{macrocode}
+% \subsubsection*{Declarations}
+%
+% Should we print and/or index the entry? For example,
+% |\index[not_print]{...}| will index silently (as \LaTeX's |\index|
+% command does).
+% \begin{macrocode}
+ declare boolean register=print,
+ declare boolean register=index,
+% \end{macrocode}
+% Options |name|, |content|, |key| and |argument| hold info about the
+% current entry. We need to declare only the latter two, the former
+% two we steal from \foRest;.
+% \begin{macrocode}
+ declare toks={key}{},
+ declare toks={argument}{},
+% \end{macrocode}
+% These options will hold first the initial, and then the calculated
+% values of the index key, index form and the form in text. When
+% (late) options are executed, these options are initialized to the
+% value of option |key|; it is safe to modify them at this point.
+% Afterwards, they will be further processed by keylists
+% |index_key_format|, |index_form_format| and |print_format|,
+% respectively.
+% \begin{macrocode}
+ declare toks={index key}{},
+ declare toks={index form}{},
+ declare toks={print form}{},
+% \end{macrocode}
+% The customization of entries' appearance is done by specifying the
+% following three keylists. The keylists work by modifying register
+% |result|.
+% \begin{macrocode}
+ declare keylist={index key format}{},
+ declare keylist={index format}{},
+ declare keylist={print format}{},
+ declare autowrapped toks register=result,
+% \end{macrocode}
+% Some shorthands.
+% \begin{macrocode}
+ format'/.style={print format'={#1}, index format'={#1}},
+ format/.style={print format={#1}, index format={#1}},
+ format+/.style={print format+={#1}, index format+={#1}},
+ +format/.style={+print format={#1}, +index format={#1}},
+ form/.style={print form={#1},index form={#1}},
+ form+/.style={print form+={#1},index form+={#1}},
+ +form/.style={+print form={#1},+index form={#1}},
+% \end{macrocode}
+% Entry types are normal (default), definition, example. Only
+% definitions are special, as their options are automatically saved.
+% \begin{macrocode}
+ declare toks register=index entry type,
+ definition/.style={index entry type=definition},
+ normal/.style={index entry type=normal},
+ example/.style={index entry type=example},
+ normal,
+% \end{macrocode}
+% This option is used internally to store the hyper ids.
+% \begin{macrocode}
+ declare toks={index@hypertarget}{},
+ every index begin/.style={},
+ every index end/.style={},
+% \end{macrocode}
+% Some formatting tools need to know whether we're typesetting text or
+% index: this info is stored in the |stage| register.\indexex[margin]{declare toks register}
+% \begin{macrocode}
+ declare toks register=stage,
+% \end{macrocode}
+%
+% \subsubsection*{The central processing command}
+% \begin{arguments}
+% \item early option keylist (these are only used to define category
+% ``@unknown'' at the end of this package)
+% \item late option keylist
+% \item index key (full form)
+% \end{arguments}
+% \begin{macrocode}
+ @index/.style n args={3}{
+% \end{macrocode}
+% Set the defaults.
+% \begin{macrocode}
+ print, index, index entry type=normal, set'={},
+% \end{macrocode}
+% Create the tree structure:
+% |[entry[subentry[subsubentry...]]]|. Three options of every node
+% created:
+% \begin{compactitem}
+% \item |key| contains the key of the (sub)entry
+% \item |name| contains the full path to the (sub)entry
+% \item |arguments| contains the arguments given to the (sub)entry's key
+% \item |content| contains the full key, with arguments for all but
+% the most deeply embedded subentry
+% \end{compactitem}
+% \indexex{for step=\indexex{nodewalk}} is used because
+% |create@subentry@node| walks down the created tree. At |if n=0|
+% below, we're thus positioned at the lowest node.\indexex[margin]{option>nodewalk}
+% \begin{macrocode}
+ for nodewalk={
+% \end{macrocode}
+% The components of the full key are separated using \indexex{split},
+% with different keys being executed for the first component and the
+% rest.
+% \begin{macrocode}
+ split={#3}{>}{create@main@entry@node, create@subentry@node},
+% \end{macrocode}
+% Remove the argument from the most deeply embedded subentry.
+% \begin{macrocode}
+ if n=0{
+ content/.option=key,
+ }{
+ content/.wrap 2 pgfmath args={##1>##2}{content("!parent")}{key},
+ }
+ }{},
+ for root'={
+% \end{macrocode}
+% Option |print_form| is what will be typeset in the text. Option
+% |index_key| is the key that will be used for sorting the
+% index. Option |index_form| is what will be typeset in the index. All
+% these are initialized to the |key|. See how
+% \indexex{handler>option} is used to assign an option value to
+% another option.
+% \begin{macrocode}
+ for tree={
+ print form/.option=key,
+ index key/.option=key,
+ index form/.option=key,
+ },
+% \end{macrocode}
+% Below, \indexex{node key>on invalid} is set to \indexex{value=on invalid>fake} at four points.
+% This is so we won't get in trouble when |\indexset|ting the
+% categories: when the category formatting code will try to step into
+% the child, it will fail as the child does not exist when |\indexset|
+% is called for the category; but we ignore the failure.
+%
+% Go to the the most deeply embedded subentry.\indexex[margin]{first leaf'}
+% \begin{macrocode}
+ for first leaf'={
+% \end{macrocode}
+% Execute every index options and the given early options.
+% \begin{macrocode}
+ on invalid={fake}{
+ every index begin,
+ #1,
+ },
+% \end{macrocode}
+% Ancestors are walked in the \indexex{reverse} order (top down). At
+% every node, the saved configuration is executed (if it exists).
+% \begin{macrocode}
+ for reverse={ancestors}{on invalid={fake}{@@index/\forestoption{name}/.try}},
+% \end{macrocode}
+% We don't execute the saved configuration for definitions, as
+% definitions are where the configuration is set.
+% \begin{macrocode}
+ if index entry type={definition}{}{%
+ on invalid={fake}{@@index/\forestoption{name}/.try},
+ },
+% \end{macrocode}
+% Execute late (well, normal) options. See the discussion about early
+% options above.
+% \begin{macrocode}
+ on invalid={fake}{
+ #2,
+ every index end
+ },
+% \end{macrocode}
+% Remember the given config for the rest of the document.
+% \begin{macrocode}
+ if set={}{}{save@session},
+% \end{macrocode}
+% If we're at a definition, save the config into the auxiliary file.
+% \begin{macrocode}
+ if index entry type={definition}{save@foridx}{},
+ },
+ stage={},
+% \end{macrocode}
+% Create hyperlink targets of the form |.entry.subentry.subsubentry...|.
+%
+% \FoRest; points:
+% \begin{enumerate*}[(i)]
+% \item the generic conditional \indexex{if},
+% \item handler \index[print form=wrap 2 pgfmath args]{wrap $n$ pgfmath args},
+% \item long nodewalk in the relative node name, which is an argument
+% to a |pgfmath| option function, automatically created for the
+% |index@hypertarget| option declared in this package.
+% \end{enumerate*}
+% \begin{macrocode}
+ if={index()||print()}{
+ index@hypertarget/.expanded={.\forestoption{index key}},
+ for descendants={
+ index@hypertarget/.wrap 2 pgfmath args={##1.##2}%
+ {index@hypertarget("!parent")}{index_key},
+ },
+ }{},
+% \end{macrocode}
+% Index.
+% \begin{macrocode}
+ if index={
+ begingroup,
+ stage=index,
+% \end{macrocode}
+% For each (sub)entry, format the |index_key| using the instructions
+% in |index_key_format|.
+% \begin{macrocode}
+ for tree={
+ result/.option=index key,
+ process keylist'={index key format}{current},
+ index key/.register=result,
+ },
+% \end{macrocode}
+% For each (sub)entry, format the |index_form| using the instructions
+% in |index_form_format|.
+% \begin{macrocode}
+ for tree={
+ result/.option=index form,
+ process keylist'={index format}{current},
+ index form/.register=result,
+ },
+% \end{macrocode}
+% Create an index entry for all nodes where |index_form| is non-empty.
+% \begin{macrocode}
+ where index form={}{}{
+% \end{macrocode}
+% All the ancestor nodes with an non-empty |index_form| will be
+% appended (in script size, as a hyperlink) to the |index_form| of the
+% current node.
+% \begin{macrocode}
+ if n=0{
+ temptoksb={},
+ }{
+ temptoksc={},
+ for ancestors={
+ if index form={}{}{
+ temptoksb+/.expanded={\forestregister{temptoksc}%
+ \noexpand\protect\noexpand\hyperlinknocolor{%
+ \forestoption{index@hypertarget}}{\forestoption{index form}}},
+ temptoksc={,\space},
+ },
+ },
+ if temptoksb={}{}{
+ +temptoksb={\protect\space\begingroup\protect\scriptsize},
+ temptoksb+={\endgroup},
+ },
+ },
+ temptoksa={},
+ result={},
+ if n children=0{tempboola}{not tempboola},
+ where index form={}{}{
+% \end{macrocode}
+% If the (outer) current node has no children, make it the hypertarget
+% that the definitions in text will point to.
+% \begin{macrocode}
+ if tempboola={temptoksd/.expanded={\noexpand\protect\noexpand\hypertarget{%
+ \forestoption{index@hypertarget}}{}}}{temptoksd={}},
+% \end{macrocode}
+% Add the (inner) current node to the index entry of the (outer) current node.
+% \begin{macrocode}
+ result+/.expanded={%
+ \forestregister{temptoksa}%
+ \forestoption{index key}%
+ =\forestoption{index form}%
+ \forestregister{temptoksd}%
+ \forestregister{temptoksb}%
+ },
+ temptoksa={>},
+ temptoksb={},
+ },
+% \end{macrocode}
+% Do the actual indexing.
+% \begin{macrocode}
+ result+/.expanded={|indexpagenumber\forestregister{index entry type}},
+ TeX/.expanded={\noexpand\forestindex@LaTeX@index{\forestregister{result}}},
+ },
+ endgroup
+ }{},
+ if print={
+ begingroup,
+ stage=print,
+% \end{macrocode}
+% For each (sub)entry, format the |print_form| using the instructions
+% in |print_form_format|.
+% \begin{macrocode}
+ for tree={
+ result/.option=print form,
+ process keylist'={print format}{current},
+ print form/.register=result,
+ },
+% \end{macrocode}
+% Typeset the entry in the text.
+% \begin{macrocode}
+ for first leaf'={TeX={\forestoption{print form}}},
+ endgroup,
+ }{},
+ }
+ },
+% \end{macrocode}
+% Create the main entry node and set to be the root.
+% \begin{macrocode}
+ create@main@entry@node/.style={% #1 = subentry
+ set root={[]},
+ do dynamics, for root'={process delayed=tree},
+ root',
+ setup@entry@node={#1}
+ },
+% \end{macrocode}
+% Create a subentry node and move into it.
+% \begin{macrocode}
+ create@subentry@node/.style={
+ append={[]},
+ do dynamics, for root'={process delayed=tree},
+ n=1,
+ setup@entry@node={#1}
+ },
+% \end{macrocode}
+% Parse \#1 into |key| and |argument|, and assign |name| and |content|.
+% \begin{macrocode}
+ setup@entry@node/.style={
+ options={
+ split={#1}{=}{key,argument},
+ if n=0{
+ name'/.option=key,
+ content={#1},
+ }{
+ name'/.wrap 2 pgfmath args={##1>##2}{name("!parent")}{key},
+ content/.wrap pgfmath arg={##1>#1}{content("!parent")},
+ },
+ }
+ },
+}
+% \end{macrocode}
+% \subsubsection*{Saving and loading the options}
+% \begin{macrocode}
+\forestset{
+% \end{macrocode}
+% This register holds whatever we need to remember.
+% \begin{macrocode}
+ declare keylist register=set,
+% \end{macrocode}
+% Besides storing the keylist in the register, also immediately
+% execute it.\indexex[margin]{Autoforward register}.
+% \begin{macrocode}
+ Autoforward register={set}{##1},
+% \end{macrocode}
+% Remember things by saving them in a global style.
+% \begin{macrocode}
+ save@session/.style={@@index/\forestoption{name}/.global style/.register=set},
+% \end{macrocode}
+% Save thinks to the auxiliary file.
+% \begin{macrocode}
+ save@foridx/.style={
+% \end{macrocode}
+% Don't save entries of unknown category.
+% \begin{macrocode}
+ if={strequal(name("!root"),"@unknown")}{}{
+% \end{macrocode}
+% Don't save if nothing is set.
+% \begin{macrocode}
+ if set={}{}{
+ TeX={%
+ \immediate\write\forestindex@out{%
+ \string\indexloadsettings{\forestoption{name}}{\forestregister{set}}%
+ }%
+ },
+ },
+% \end{macrocode}
+% Save the full form of the key in the auxiliary file. Obviously, do
+% it only for subentries. The full form contains whatever arguments
+% were given to the non-last component.
+% \begin{macrocode}
+ if={strequal(key(),content())}{}{
+ TeX={%
+ \immediate\write\forestindex@out{%
+ \string\indexdefineshortkey{\forestoption{key}}{\forestoption{content}}%
+ }%
+ }
+ }
+ }
+ },
+}
+% \end{macrocode}
+% Load settings from the auxiliary file into the global style. Warn
+% if anything was configured more than once (e.g.\ by |\indexdef|ing
+% the same key twice).
+% \begin{macrocode}
+\def\indexloadsettings#1#2{%
+ \pgfkeysifdefined{/forest/@@index/#1/.@cmd}{%
+ \forestindex@loadsettings@warning{#1}%
+ }{}%
+ \forestset{@@index/#1/.global style={#2}}%
+}
+\def\forestindex@loadsettings@warning#1{%
+ \PackageWarning{forest-index}{Forest index key "#1" was configured more than once!
+ I'm using the last configuration.}%
+}
+% \end{macrocode}
+% Load the full form of a short key from the auxiliary file. Out of
+% kindness for the end user, remember all the full keys corresponding
+% to a short key: this will make a more informative warning below.
+% \begin{macrocode}
+\def\indexdefineshortkey#1#2{%
+ \def\forestindex@temp@short{#1}%
+ \def\forestindex@temp@long{#2}%
+ \ifx\forestindex@temp@short\forestindex@temp@long
+ \else
+ \ifcsdef{index@long@#1}{%
+ \global\cslet{index@long@#1}\relax
+ \csgappto{index@alllong@#1}{,#2}%
+ }{%
+ \global\csgdef{index@long@#1}{#2}%
+ \global\csgdef{index@alllong@#1}{#2}%
+ }%
+ \fi
+}
+% \end{macrocode}
+% \subsubsection*{Short key resolution}
+%
+% Nothing to do for a long key.
+% \begin{macrocode}
+\def\forestindex@resolvekey@long#1{\def\forestindex@fullkey{#1}}
+% \end{macrocode}
+% Decide whether a key is short or long based on the absence or
+% presence of the level separator |>|.
+% \begin{macrocode}
+\def\forestindex@resolvekey@shortorlong#1{%
+ \pgfutil@in@>{#1}%
+ \ifpgfutil@in@
+ \expandafter\def\expandafter\forestindex@fullkey
+ \else
+ \expandafter\forestindex@resolvekey@short
+ \fi
+ {#1}%
+}
+% \end{macrocode}
+% Before resolving the short key, we need to split the user input into
+% the key and the argument. The latter is then appended to the full
+% key (which can, in principle, contain arguments for other components
+% as well).
+% \begin{macrocode}
+\def\forestindex@resolvekey@short#1{%
+ \forestset{split={#1}{=}{index@resolveshortkey@key,index@resolveshortkey@arg}}%
+}
+\forestset{
+ index@resolveshortkey@key/.code={%
+ \ifcsvoid{index@long@#1}{%
+ \forestindex@resolveshortkey@warning{#1}%
+ \def\forestindex@fullkey{@unknown>#1}%
+ }{%
+ \letcs\forestindex@fullkey{index@long@#1}%
+ }%
+ },
+ index@resolveshortkey@arg/.code={%
+ \appto\forestindex@fullkey{=#1}%
+ },
+}
+\def\forestindex@resolveshortkey@warning#1{%
+ \PackageWarning{forest-index}{Cannot resolve short forest index key "#1".
+ These are the definitions I found (from the previous run):
+ "\csuse{index@alllong@#1}"}%
+}
+% \end{macrocode}
+% \subsubsection*{Formatting styles}
+%
+% Define default colors for index entry types and provide a style that
+% typesets the entry in text (but not index) in the desired color.
+% \begin{macrocode}
+\forestset{
+ normal color/.initial=blue,
+ definition color/.initial=red,
+ example color/.initial=darkgreen,
+ print in color/.style={if stage={print}{result=\protect\textcolor{%
+ \pgfkeysvalueof{/forest/#1 color}}{##1}}{}},
+ print in color/.default=\forestregister{index entry type},
+% \end{macrocode}
+% Use this style in |..._format| keylists if you want the index
+% entries to be hyperlinks to the definition, and the definition to be
+% a hyperlink to the index.
+% \begin{macrocode}
+ hyper/.style={
+ if stage={index}{}{
+ if index entry type={definition}{
+ result/.expanded={\noexpand\hypertarget{\forestoption{name}}%
+ {\noexpand\hyperlink{\forestoption{index@hypertarget}}{\forestregister{result}}}}
+ }{
+ result/.expanded=\noexpand\hyperlink{\forestoption{name}}{\forestregister{result}}
+ }
+ }
+ },
+}
+% \end{macrocode}
+% Color page numbers in the index, with or without |hyperref| package.
+% \begin{macrocode}
+\ifdef\hyperpage{%
+ \newcommand\indexpagenumbernormal[1]{{%
+ \hypersetup{linkcolor=\pgfkeysvalueof{/forest/normal color}}\hyperpage{#1}}}
+ \newcommand\indexpagenumberdefinition[1]{{%
+ \hypersetup{linkcolor=\pgfkeysvalueof{/forest/definition color}}\hyperpage{#1}}}
+ \newcommand\indexpagenumberexample[1]{{%
+ \hypersetup{linkcolor=\pgfkeysvalueof{/forest/example color}}\hyperpage{#1}}}
+}{
+ \newcommand\indexpagenumbernormal[1]{%
+ \textcolor{\pgfkeysvalueof{/forest/normal color}}{#1}}
+ \newcommand\indexpagenumberdefinition[1]{%
+ \textcolor{\pgfkeysvalueof{/forest/definition color}}{#1}}
+ \newcommand\indexpagenumberexample[1]{%
+ \textcolor{\pgfkeysvalueof{/forest/example color}}{#1}}
+}
+% \end{macrocode}
+% Provide dummy |\hyper...| commands if |hyperref| is not loaded.
+% \begin{macrocode}
+\providecommand\hyperlink[2]{#2}
+\providecommand\hypertarget[2]{#2}
+\providecommand\hypersetup[1]{}
+% \end{macrocode}
+% This is used by entry qualifiers: we want them to be hyperlinks, but black.
+% \begin{macrocode}
+\newcommand\hyperlinknocolor[2]{{\hypersetup{linkcolor=black}\hyperlink{#1}{#2}}}
+% \end{macrocode}
+%
+% Use style |item| to have the index entry (in text) function as the
+% |\item| of a |lstdoc|'s |syntax| environment.
+% \begin{macrocode}
+\forestset{
+ declare toks register=default,
+ default={},
+ item/.style={result/.wrap 4 pgfmath args={%
+ \item[,##2,##3]{##4}%
+ }{}{default}{print_form("!parent")}{result},
+ },
+}
+% \end{macrocode}
+%
+% \subsubsection*{Utilities}
+%
+% We will need a global version of several |pgfkeys| commands.
+% \begin{macrocode}
+\pgfkeys{/handlers/.global style/.code=\pgfkeys{\pgfkeyscurrentpath/.global code=\pgfkeysalso{#1}}}
+\pgfkeysdef{/handlers/.global code}{\pgfkeysglobaldef{\pgfkeyscurrentpath}{#1}}
+\long\def\pgfkeysglobaldef#1#2{%
+ \long\def\pgfkeys@temp##1\pgfeov{#2}%
+ \pgfkeysgloballet{#1/.@cmd}{\pgfkeys@temp}%
+ \pgfkeysglobalsetvalue{#1/.@body}{#2}%
+}
+\def\pgfkeysgloballet#1#2{%
+ \expandafter\global\expandafter\let\csname pgfk@#1\endcsname#2%
+}
+\long\def\pgfkeysglobalsetvalue#1#2{%
+ \pgfkeys@temptoks{#2}\expandafter\xdef\csname pgfk@#1\endcsname{\the\pgfkeys@temptoks}%
+}
+% \end{macrocode}
+% Begin and end group, \foRest;-style:
+% \begin{macrocode}
+\forestset{
+ begingroup/.code={\begingroup},
+ endgroup/.code={\endgroup},
+}
+% \end{macrocode}
+%
+% \subsubsection*{Initialize}
+%
+% Declare category ``@unknown''.
+% \begin{macrocode}
+\index(not print,not index)[%
+ set={
+ index key=unknown,
+ form={\textbf{unknown!!}},
+ for first={format={result/.expanded=\noexpand\textbf{\forestregister{result}??}}}
+ },
+ ]>{@unknown}
+% \end{macrocode}
+% Load the auxiliary file made in the previous compilation, and open
+% it for writing to save data from this compilation.
+% \begin{macrocode}
+\def\forestindex@filename{\jobname.foridx}
+\IfFileExists{\forestindex@filename}{%
+ \input\forestindex@filename
+}{}%
+\newwrite\forestindex@out
+\immediate\openout\forestindex@out=\forestindex@filename
+\AtEndDocument{%
+ \immediate\closeout\forestindex@out
+}
+\endinput
+% \end{macrocode}
+%
+%%% \iffalse
+%%% Local Variables:
+%%% mode: doctex
+%%% TeX-master: "forest-doc.tex"
+%%% End:
+%%% \fi
diff --git a/Master/texmf-dist/source/latex/forest/forest-libs.dtx b/Master/texmf-dist/source/latex/forest/forest-libs.dtx
new file mode 100644
index 00000000000..74803e98289
--- /dev/null
+++ b/Master/texmf-dist/source/latex/forest/forest-libs.dtx
@@ -0,0 +1,516 @@
+% \CheckSum{231}
+% \iffalse meta-comment
+% forest-libs.dtx
+%% `forest-libs' is a collection of libraries for package `forest'.
+%%
+%% Copyright (c) 2015 Saso Zivanovic
+%% (Sa\v{s}o \v{Z}ivanovi\'{c})
+%% saso.zivanovic@guest.arnes.si
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% of this license or (at your option) any later version.
+%% The latest version of this license is in
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `author-maintained'.
+%%
+%% This file is a part of package `forest'. For the list of files
+%% constituting the package see main source file of the package,
+%% `forest.dtx', or the derived `forest.sty'.
+%%
+% \fi
+%
+% \section{Libraries}
+%
+% This chapter contains not only the reference of commands found in libraries and some examples of
+% their usage, but also their definitions. This is done in the hope that these definitions, being
+% mostly styles, will be useful as examples of the core features of the package. I even managed to
+% comment them a bit \dots
+%
+% \paragraph{Disclaimer.} At least in the initial stages of a library's development, the function
+% and interface of macros and keys defined in a library might change without backwards compatibility
+% support!
+%
+% \begin{macrocode}
+\RequirePackage{forest}
+% \end{macrocode}
+%
+%\iffalse
+%<*linguistics>
+%\fi
+% \librarysection{linguistics}
+% \begin{macrocode}
+\ProvidesForestLibrary{linguistics}[2015/11/14 v0.1]
+% \end{macrocode}
+%
+% Defaults:
+% \begin{macrocode}
+\forestset{
+ libraries/linguistics/defaults/.style={
+ default preamble={
+% \end{macrocode}
+% Edges of the children will ``meet'' under the node:
+% \begin{macrocode}
+ sn edges,
+% \end{macrocode}
+% The root of the tree will be aligned with the text \dots\ or, more commonly, the example number.
+% \begin{macrocode}
+ baseline,
+% \end{macrocode}
+% Enable (centered) multi-line nodes.
+% \begin{macrocode}
+ for tree={align=center},
+ },
+ },
+}
+% \end{macrocode}
+%
+% There's no linguistics without c-command\footnote{The definition of c-command is as follows: a node c-commands its siblings and their subtrees.} \dots
+% \begin{syntax}
+% \indexitem{step>c-commanded} Visit all the nodes c-commanded by the current node.
+% \indexitem{step>c-commanders} Visit all the c-commanders of the current node, starting from the closest.
+%
+% \begin{forestexample}[tree bin=minipage,index={branch',c-commanded}]
+% ``manual'' c-command:\\[1ex]
+% \begin{forest}
+% [VP
+% [DP[John]]
+% [V'
+% [V, draw, for c-commanded={draw,circle}
+% [sent]
+% ]
+% [DP[Mary]]
+% [DP[D[a]][NP[letter]]]
+% ]
+% ]
+% \end{forest}
+% \end{forestexample}
+%
+% See how \indexex{branch'} is used to define |c-commanded|, and how \indexex{while nodewalk valid} and \indexex{nodewalk key>fake} are combined in the definition of |c-commanders|.
+% \begin{macrocode}
+\forestset{
+ define long step={c-commanded}{style}{branch'={siblings,descendants}},
+ define long step={c-commanders}{style}{while nodewalk valid={parent}{siblings,fake=parent}},
+}
+% \end{macrocode}
+%
+%
+%
+% \indexitem{node key>sn edges}
+%
+% In linguistics, most people want the parent-child edge to go from the \emph{s}outh of the parent
+% to the \emph{n}orth of the child. This is achieved by this (badly named) style, which makes the
+% entire (sub)tree have such edges.
+%
+% \begin{forestexample}
+% \begin{forest}
+% sn edges
+% [VP
+% [DP]
+% [V'
+% [V]
+% [DP]
+% ]
+% ]
+% \end{forest}
+% \end{forestexample}
+%
+% \begin{macrocode}
+\forestset{
+ sn edges/.style={
+ for tree={
+ parent anchor=children, child anchor=parent
+ }
+ },
+}
+% \end{macrocode}
+%
+% A note on implementation. Despite its name, this style does not refer to the |south| and |north|
+% anchor of the parent and the child node directly. If it did so, it would only work for trees with
+% standard linguistic \index{grow}|=-90|. So we rather use \FoRest;'s growth direction based
+% anchors: \index{anchor>children} always faces the children and \index{anchor>parent} always faces
+% the parent, so the edge will always be between them, and the normal, upward growing trees will
+% look good as well.
+%
+% \begin{forestexample}[index={anchor>south,anchor>north,option>parent anchor,option>child anchor}]
+% \begin{forest}
+% [bad![VP,no edge, for tree={grow=90, edge=red},
+% for tree={parent anchor=south, child anchor=north} % bad
+% [DP][V'[V][DP]]]]
+% \end{forest}
+% \begin{forest}
+% [good![VP, no edge, for tree={grow=90, edge=green},
+% ~sn edges~ % good!
+% [DP][V'[V][DP]]]]
+% \end{forest}
+% \end{forestexample}
+%
+% \indexitem{node key>roof} Makes the edge to parent a triangular roof.
+% \begin{macrocode}
+\forestset{
+ roof/.style={edge path'={%
+ (.parent first)--(!u.children)--(.parent last)--cycle
+ }
+ },
+}
+% \end{macrocode}
+%
+% \indexitem{node key>nice empty nodes}
+%
+% We often need empty nodes: tree (\ref{ex:niceemptynodes}a) shows how they look like by default:
+% ugly.
+%
+% First, we don't want the gaps: we change the shape of empty nodes to coordinate. We get tree
+% (\ref{ex:niceemptynodes}b).
+%
+% Second, the empty nodes seem too close
+% to the other (especially empty) nodes (this is a result of a small
+% default |s_sep|). We could use a greater \index{s sep}, but a better solution seems
+% to be to use |calign=node_angle|. The result is shown in (\ref{ex:niceemptynodes}c).
+%
+% However, at the transitions from empty to non-empty nodes, tree (\ref{ex:niceemptynodes}c)
+% seems to zigzag (although the base points of the spine nodes
+% are perfectly in line), and the edge to the empty node left to VP
+% seems too long (it reaches to the level of VP's base, while we'd
+% prefer it to stop at the same level as the edge to VP itself). The
+% first problem is solved by substituting |node_angle| for
+% |edge_angle|; the second one, by anchoring siblings of
+% empty nodes at north. Voilà, (\ref{ex:niceemptynodes}d)!
+%
+% \begin{forestexample}[label=ex:niceemptynodes,layout=tree on bottom,index={fixed angles,fixed edge angles,calign,tree,delay,where option,content,for step,step>parent,step>children,option>anchor}]
+% \forestset{
+% xlist/.style={
+% phantom,
+% for children={no edge,replace by={[,append,
+% delay={content/.wrap pgfmath arg={\@alph{##1}.}{n()+#1}}
+% ]}}
+% },
+% xlist/.default=0
+% }
+% \begin{forest}
+% [,~xlist~,
+% for tree={after packing node={s+=0.1pt}}, % hack!!!
+% [CP, %(a)
+% [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
+% [CP, delay={where content={}{shape=coordinate}{}} %(b)
+% [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
+% [CP, for tree={calign=fixed angles}, %(c)
+% delay={where content={}{shape=coordinate}{}}
+% [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
+% [CP, ~nice empty nodes~ %(d)
+% [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
+% ]
+% \end{forest}
+% \end{forestexample}
+%
+% \begin{macrocode}
+\forestset{
+ nice empty nodes/.style={
+ for tree={calign=fixed edge angles},
+ delay={where content={}{shape=coordinate,for parent={
+ for children={anchor=north}}}{}}
+ },
+}
+% \end{macrocode}
+%
+% \indexitem{node key>draw brackets} Outputs the bracket representation of the tree.
+% \indexitem{node key>draw brackets compact}
+% \itemnosep
+% \indexitem{node key>draw brackets wide} These keys control whether the brackets have extra
+% spaces around them (|wide|) or not (|compact|).
+% \begin{macrocode}
+\providecommand\text[1]{\mbox{\scriptsize#1}}
+\forestset{
+ draw brackets compact/.code={\let\drawbracketsspace\relax},
+ draw brackets wide/.code={\let\drawbracketsspace\space},
+ draw brackets/.style={
+% \end{macrocode}
+% There's stuff to do both before (output the opening bracket and the content) and after (output the
+% closing bracket) processing the children, so we use \indexex{for tree'}.
+% \begin{macrocode}
+ for tree'={
+ TeX={[%
+% \end{macrocode}
+% Complication: \index{content format} must be expanded in advance, to correctly process tabular environments implicitely loaded by \index{align}|=|\index{value=align>center}, which is the default in this library. (Not that one would want a multiline output in the bracket representation, but it's better than crashing.)
+% \begin{macrocode}
+ \edef\forestdrawbracketscontentformat{\foresteoption{content format}}%
+ },
+ if n children=0{
+ TeX={\drawbracketsspace\forestdrawbracketscontentformat\drawbracketsspace}
+ }{
+ TeX={\textsubscript{\text{\forestdrawbracketscontentformat}}\drawbracketsspace}
+ },
+ }{
+ TeX={]\drawbracketsspace},
+ }
+ },
+ draw brackets wide
+}
+% \end{macrocode}
+% \end{syntax}
+%
+% \subsubsection{GP1}
+%
+% \begin{syntax}
+% \indexitem{node key>GP1}
+%
+% For Government Phonology (v1) representations. Here, the big trick
+% is to evenly space $\times$s by having a large enough |outer_xsep|
+% (adjustable), and then, before drawing (timing control option
+% |before_drawing_tree|), setting |outer_xsep| back to 0pt. The last step
+% is important, otherwise the arrows between $\times$s won't draw!
+%
+% An example of an ``embedded'' |GP1| style:
+% \begin{forestexample}[layout=tree on bottom,index={where option,tier,for step,step>children,content,tikz,option>l,dimen+,no edge},index>={!}]
+% \begin{forest}
+% myGP1/.style={
+% ~GP1~,
+% delay={where tier={x}{
+% for children={content=\textipa{##1}}}{}},
+% tikz={\draw[dotted](.south)--
+% (!1.north west)--(!l.north east)--cycle;},
+% for children={l+=5mm,no edge}
+% }
+% [VP[DP[John,tier=word,myGP1
+% [O[x[dZ]]]
+% [R[N[x[6]]]]
+% [O[x[n]]]
+% [R[N[x]]]
+% ]][V'[V[loves,tier=word,myGP1
+% [O[x[l]]]
+% [R[N[x[a]]]]
+% [O[x[v]]]
+% [R[N[x]]]
+% [O[x[z]]]
+% [R[N[x]]]
+% ]][DP[Mary,tier=word,myGP1
+% [O[x[m]]]
+% [R[N[x[e]]]]
+% [O[x[r]]]
+% [R[N[x[i]]]]
+% ]]]]
+% \end{forest}%
+% \end{forestexample}
+%
+% And an example of annotations.
+% \begin{forestexample}
+% \begin{forest}[,phantom,s sep=1cm
+% [{[ei]}, GP1
+% [R[N[x[A,~el~[I,~head~,~associate=N~]]][x]]]
+% ]
+% [{[mars]}, GP1
+% [O[x[m]]]
+% [R[N[x[a]]][x,~encircle~,densely dotted[r]]]
+% [O[x,~encircle~,~govern=<~[s]]]
+% [R,~fen~[N[x]]]
+% ]
+% ]\end{forest}
+% \end{forestexample}
+%
+% \begin{macrocode}
+\newbox\standardnodestrutbox
+\setbox\standardnodestrutbox=\hbox to 0pt{\phantom{\forestOve{standard node}{content}}}
+\def\standardnodestrut{\copy\standardnodestrutbox}
+\forestset{
+ GP1/.style 2 args={
+ for n={1}{baseline},
+ s sep=0pt, l sep=0pt,
+ for descendants={
+ l sep=0pt, l={#1},
+ anchor=base,calign=first,child anchor=north,
+ inner xsep=1pt,inner ysep=2pt,outer sep=0pt,s sep=0pt,
+ },
+ delay={
+ if content={}{phantom}{for children={no edge}},
+ for tree={
+ if content={O}{tier=OR}{},
+ if content={R}{tier=OR}{},
+ if content={N}{tier=N}{},
+ if content={x}{
+ tier=x,content={$\times$},outer xsep={#2},
+ for tree={calign=center},
+ for descendants={content format={\noexpand\standardnodestrut\forestoption{content}}},
+ before drawing tree={outer xsep=0pt,delay={typeset node}},
+ s sep=4pt
+ }{},
+ },
+ },
+ before drawing tree={where content={}{parent anchor=center,child anchor=center}{}},
+ },
+ GP1/.default={5ex}{8.0pt},
+ associate/.style={%
+ tikz+={\draw[densely dotted](!)--(!#1);}},
+ spread/.style={
+ before drawing tree={tikz+={\draw[dotted](!)--(!#1);}}},
+ govern/.style={
+ before drawing tree={tikz+={\draw[->](!)--(!#1);}}},
+ p-govern/.style={
+ before drawing tree={tikz+={\draw[->](.north) to[out=150,in=30] (!#1.north);}}},
+ no p-govern/.style={
+ before drawing tree={tikz+={\draw[->,loosely dashed](.north) to[out=150,in=30] (!#1.north);}}},
+ encircle/.style={before drawing tree={circle,draw,inner sep=0pt}},
+ fen/.style={pin={[font=\footnotesize,inner sep=1pt,pin edge=<-]10:\textsc{Fen}}},
+ el/.style={content=\textsc{\textbf{##1}}},
+ head/.style={content=\textsc{\textbf{\underline{##1}}}}
+}
+% \end{macrocode}
+% \end{syntax}
+%\iffalse
+%</linguistics>
+%\fi
+%
+%
+%
+%\iffalse
+%<*edges>
+%\fi
+% \librarysection{edges}
+% \begin{macrocode}
+\ProvidesForestLibrary{edges}[2015/11/14 v0.1]
+% \end{macrocode}
+%
+% \begin{syntax}
+%
+% \indexitem{node key>forked edge}
+%
+% Sets a forked edge to the current node. Arbitrary growth direction and node rotation are
+% supported.
+%
+% Using this key does \emph{not} change the current values of \index{option>parent anchor} and
+% \index{option>child anchor}.
+%
+% \indexitem{node key>forked edges}
+%
+% Sets forked edges to the entire (sub)tree rooted in the current node. Arbitrary growth
+% direction and node rotation are supported.
+%
+% \index{option>parent anchor} and \index{option>child anchor} are set to \index{anchor>children} and
+% \index{anchor>parent}, repectively.
+%
+% \indexitem{option>fork sep} The \index{forest cs>l}-distance between the parent anchor and the
+% fork.
+%
+% \end{syntax}
+%
+% \begin{forestexample}[index={for step,tree,grow',forked edges}]
+% \begin{forest}
+% for tree={grow'=0,draw},
+% forked edges,
+% [/
+% [home
+% [saso
+% [Download]
+% [TeX]
+% ]
+% [alja]
+% [joe]
+% ]
+% [usr
+% [bin]
+% [share]
+% ]
+% ]
+% \end{forest}
+% \end{forestexample}
+%
+% See how \indexex{anchor>parent anchor} and \indexex{anchor>parent anchor} are used in the
+% definition of |forked_edge| to easily take care of arbitrary \index{grow} and \index{rotate}.
+% \begin{macrocode}
+\forestset{
+ declare dimen={fork sep}{0.5em},
+ forked edge/.style={
+ edge={rotate/.pgfmath=grow()},
+ edge path'={(!u.parent anchor) -- ++(\forestoption{fork sep},0) |- (.child anchor)},
+ },
+ forked edges/.style={
+ for tree={parent anchor=children},
+ for descendants={child anchor=parent,forked edge}
+ },
+}
+% \end{macrocode}
+%
+% \begin{syntax}
+% \indexitem{node key>folder} The children of the node are drawn like folders.
+%
+% All growth directions are supported (well, cardinal directions work perfectly; the others await
+% the sensitivity of packing to \index{edge path}), as well as node rotation and \index{reversed}
+% order of children.
+%
+% The outlook of the folder can be influenced by setting standard \foRest;'s options \index{l sep}
+% and \index{s sep} any time before packing, or \index{option>l} and \index{option>s} after
+% packing. Setting \index{option>l} and \index{option>s} before packing will have no influence on
+% the layout of the tree.
+%
+% \begin{syntax}
+% \indexitem(.45em){register>folder indent}|=|\meta{dimen}
+%
+% Specifies the shift of the parent's side of the edge in the \index{forest cs>l}-direction.
+% \end{syntax}
+%
+% \end{syntax}
+%
+% \begin{forestexample}[index={for step,tree,grow',folder}]
+% \begin{forest}
+% for tree={grow'=0,~folder~,draw}
+% [/
+% [home
+% [saso
+% [Download]
+% [TeX]
+% ]
+% [alja]
+% [joe]
+% ]
+% [usr
+% [bin]
+% [share]
+% ]
+% ]
+% \end{forest}
+% \end{forestexample}
+% \begin{macrocode}
+\forestset{
+ declare dimen register=folder indent,
+ folder indent=.45em,
+ folder/.style={
+ parent anchor=parent last,
+ anchor=parent first,
+ calign=child,
+ calign primary child=1,
+ for children={
+ child anchor=parent,
+ anchor=parent first,
+ edge={rotate/.pgfmath=grow()},
+ edge path'/.expanded={
+ ([xshift=\forestregister{folder indent}]!u.parent anchor) |- (.child anchor)
+ },
+ },
+ after packing node={
+ if n children=0{}{
+ tempdiml=l_sep()-l("!1"),
+ tempdims={-abs(max_s("","")-min_s("",""))-s_sep()},
+ for children={
+ l+=tempdiml,
+ s+=tempdims()*(reversed()-0.5)*2,
+ },
+ },
+ },
+ }
+}
+% \end{macrocode}
+%\iffalse
+%</edges>
+%\fi
+% \forestset{every index end/.style={}}
+% \endinput
+% Local Variables:
+% mode: doctex
+% TeX-command-default: "sty"
+% fill-column: 100
+% TeX-master: "forest"
+% End:
diff --git a/Master/texmf-dist/source/latex/forest/forest.dtx b/Master/texmf-dist/source/latex/forest/forest.dtx
index 681696ed27e..19aba56df68 100644
--- a/Master/texmf-dist/source/latex/forest/forest.dtx
+++ b/Master/texmf-dist/source/latex/forest/forest.dtx
@@ -1,4 +1,4 @@
-% \CheckSum{12884}
+% \CheckSum{12479}
% \iffalse meta-comment
% forest.dtx
%% `forest' is a `pgf/tikz'-based package for drawing (linguistic) trees.
@@ -17,4034 +17,66 @@
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
-%% This work has the LPPL maintenance status `maintained'.
+%% This work has the LPPL maintenance status `author-maintained'.
+%%
+%% This work consists of the following files:
+%% - forest.dtx: central sources (with rudimentary implementation documentation)
+%% - forest-libs.dtx: sources and documentation for libraries
+%% + forest-compat.sty: sources/runtime for compatibility mode
+%% - forest.ins: produces derived runtime .sty files
+%% + forest.sty: main package
+%% + forest-lib-*.sty: libraries (for the list, see forest.ins)
+%% - forest-doc.tex: central documentation
+%% - forest-doc.sty: private package needed to compile the documentation
+%% - forest-index.dtx: sources of indexing package used in the documentation,
+%% and also part of the documentation itself
+%% - forest-doc.ins: produces derived .sty files needed to compile the documentation
+%% - forest-index.sty
+%% - forest-doc.ist: index style file needed to compile the documentation
+%% - forest.pdf: documentation of core package implementation
+%% - forest-doc.pdf: user's guide
+%% - README
+%% - LICENCE
+%% To use the package, only the files marked with + need to be installed.
%%
-%% The Current Maintainer of this work is Saso Zivanovic.
-%%
-%% This work consists of the files forest.dtx and forest.ins
-%% and the derived file forest.sty.
-%%
-%
%<*driver>
\documentclass[a4paper]{ltxdoc}
-\usepackage{fullpage}
-\usepackage[external]{forest}
-%\tikzexternalize
-\tikzset{
- external/prefix={forest.for.dir/},
- external/system call={
- pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=nonstopmode
- -jobname "\image" "\texsource"},
-}
-%\usepackage[trace]{trace-pgfkeys}
+\usepackage{forest}
+\usepackage{forest-doc}
-\usepackage[colorlinks=true,linkcolor=blue,citecolor=blue,hyperindex=false]{hyperref}
+\usepackage{fullpage}
+\usepackage{hyperref}
+\hypersetup{colorlinks=true,linkcolor=blue,citecolor=blue,hyperindex=false}
\usepackage{url}
-\usepackage[numbers]{natbib}
-\usepackage[multiple]{footmisc}
-\usepackage{tipa}
-\usepackage{paralist}
-\usepackage{printlen}
-
-\makeatletter
-\DeleteShortVerb\|
-\newcommand\OR{\ensuremath{\,|\,}}%
-
-%%%%%%%%
-%\usepackage{lstdoc} %%% copy/paste most of the file, but omit and adjust some stuff like
-%section-modifications
-\usepackage{listings}
-\def\lst@sampleInput{%
- \MakePercentComment\catcode`\^^M=10\relax
- \small\lst@sample
- {\setkeys{lst}{SelectCharTable=\lst@ReplaceInput{\^\^I}%
- {\lst@ProcessTabulator}}%
- \leavevmode \input{\jobname.tmp}}\MakePercentIgnore}
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-\def\rstyle{\color{red}}
-\def\advise{\par\list\labeladvise
- {\advance\linewidth\@totalleftmargin
- \@totalleftmargin\z@
- \@listi
- \let\small\footnotesize \small\sffamily
- \parsep \z@ \@plus\z@ \@minus\z@
- \topsep6\p@ \@plus1\p@\@minus2\p@
- \def\makelabel##1{\hss\llap{##1}}}}
-\let\endadvise\endlist
-\def\advisespace{\hbox{}\qquad}
-\def\labeladvise{$\to$}
-\newenvironment{syntax}
- {\list{}{\itemindent-\leftmargin
- \def\makelabel##1{\hss\lst@syntaxlabel##1,,,,\relax}}}
- {\endlist}
-\def\lst@syntaxlabel#1,#2,#3,#4\relax{%
- \llap{\scriptsize\itshape#3}%
- \def\lst@temp{#2}%
- \expandafter\lst@syntaxlabel@\meaning\lst@temp\relax
- \rlap{\hskip-\itemindent\hskip\itemsep\hskip\linewidth
- \llap{\ttfamily\lst@temp}\hskip\labelwidth
- \def\lst@temp{#1}%
- \ifx\lst@temp\lstdoc@currversion#1\fi}}
-\def\lst@syntaxlabel@#1>#2\relax
- {\edef\lst@temp{\zap@space#2 \@empty}}
-\newcommand*\syntaxnewline{\newline\hbox{}\kern\labelwidth}
-\newcommand*\syntaxor{\qquad or\qquad}
-\newcommand*\syntaxbreak
- {\hfill\kern0pt\discretionary{}{\kern\labelwidth}{}}
-\let\syntaxfill\hfill
-\def\alternative#1{\lst@true \alternative@#1,\relax,}
-\def\alternative@#1,{%
- \ifx\relax#1\@empty
- \expandafter\@gobble
- \else
- \ifx\@empty#1\@empty\else %\if
- \lst@if \lst@false \else $\vert$\fi
- \textup{\texttt{#1}}%
- \fi
- \fi
- \alternative@}
-\lst@RequireAspects{writefile}
-\lst@InstallKeywords{p}{point}{pointstyle}\relax{keywordstyle}{}ld
-\def\pstyle{\color{darkgreen}}
-\lstset{language={[LaTeX]TeX},tabsize=4,gobble=4,%
- basicstyle=\small\ttfamily,basewidth=0.51em,boxpos=t,pointstyle=\pstyle,moredelim=[is][\pstyle]{~}{~}}%
-\newbox\sampleoutputbox
-\newbox\lst@samplebox
-\newdimen\forestexample@code
-\newdimen\forestexample@sample
-\newdimen\forestexample@hsep
-\forestexample@hsep=1em
-\lst@Key{hsep}\relax{\forestexample@hsep=#1}%
-\pgfqkeys{/forestexample}{%
- samplebox/.code={\let\sampleoutputbox#1},
- codebox/.code={\let\lst@samplebox#1},
- pos/.initial=l, % example is left of the code
- before/.code={\gdef\lst@sample{#1}},
- labelformat/.initial={\def\@currentlabel{#1}},
- no numbering/.code={\addtocounter{lstlisting}{-1}\pgfkeysalso{labelformat={}}},
- .unknown/.code={\lstset{\pgfkeyscurrentname={#1}}},
- ekeynames/.code={\def\myindex@for@temp##1{\ekeyname[example]{##1}}\forcsvlist\myindex@for@temp{#1}},
- ecmdnames/.code={\forcsvlist{\ecmdname[example]}{#1}},
- filename/.initial={},
-}
-\lstnewenvironment{forestexample}[1][]{%
- \global\let\lst@intname\@empty
- \def\@currentlabel{(\arabic{lstlisting})}%
- \addtocounter{lstlisting}{1}%
- \gdef\lst@sample{}%
- \pgfqkeys{/forestexample}{#1}%
- \setbox\lst@samplebox=\hbox\bgroup
- \xdef\samplebox@baselineskip{\the\baselineskip}%
- \catcode`~=9\relax
- \lst@BeginAlsoWriteFile{\jobname.tmp}%
-}{%
- \lst@EndWriteFile\egroup
- \immediate\write18{cat \jobname.tmp}%
- \pgfkeysgetvalue{/forestexample/pos}\fe@pos
- \if x\fe@pos %%%%%%%% user position: boxes are stored in cs given in samplebox and codebox args
- \forest@temp@count=\@listdepth
- \pgfutil@tempdima=0pt
- \loop
- \ifnum\forest@temp@count>0
- \advance\pgfutil@tempdima\csname leftmargin\romannumeral\the\forest@temp@count\endcsname\relax
- \advance\forest@temp@count-1
- \repeat
- \global\setbox\lst@samplebox=\hbox{\hskip-\pgfutil@tempdima\box\lst@samplebox\hskip\pgfutil@tempdima}%
- \global\setbox\sampleoutputbox=\hbox{\lst@sampleInput}%
- \else
- \if l\fe@pos %%%% example is left of the code
- % move the code left for each list's \leftmargin ... have no idea why this must be done
- \forest@temp@count=\@listdepth
- \pgfutil@tempdima=0pt
- \loop
- \ifnum\forest@temp@count>0
- \advance\pgfutil@tempdima\csname leftmargin\romannumeral\the\forest@temp@count\endcsname\relax
- \advance\forest@temp@count-1
- \repeat
- \setbox\lst@samplebox=\hbox{\hskip-\pgfutil@tempdima\box\lst@samplebox\hskip\pgfutil@tempdima}%
- \setbox\sampleoutputbox=\hbox{\lst@sampleInput}%
- \pgfutil@tempdima=\wd\sampleoutputbox
- \advance\pgfutil@tempdima\wd\lst@samplebox
- \advance\pgfutil@tempdima\forestexample@hsep
- \ifdim\pgfutil@tempdima>\linewidth
- \forestexample@code=\linewidth
- \advance\forestexample@code-\wd\lst@samplebox
- \forestexample@sample=\forestexample@code
- \advance\forestexample@sample-\forestexample@hsep
- \advance\forestexample@sample-\wd\sampleoutputbox
- \else
- \pgfutil@tempdima=\wd\sampleoutputbox
- \advance\pgfutil@tempdima\forestexample@hsep
- \ifdim\pgfutil@tempdima>.5\linewidth
- \forestexample@sample=0pt
- \forestexample@code=\wd\sampleoutputbox
- \advance\forestexample@code\forestexample@hsep
- \else
- \pgfutil@tempdima=\wd\lst@samplebox
- \advance\pgfutil@tempdima\forestexample@hsep
- \ifdim\pgfutil@tempdima>.5\linewidth
- \forestexample@code=\linewidth
- \advance\forestexample@code-\wd\lst@samplebox
- \forestexample@sample=0pt
- \else
- \forestexample@sample=0pt
- \forestexample@code=.5\linewidth
- \fi
- \fi
- \fi
- \begin{trivlist}\item\relax
- $%
- \vcenter{
- \hbox{%
- \hbox to 0pt{\hskip\linewidth\llap{\@currentlabel}}%
- \hbox to 0pt{%
- \hskip\forestexample@code
- \raise\samplebox@baselineskip\box\lst@samplebox
- }%
- }%
- }%
- \vcenter{%
- \hbox to 0pt{%
- \hskip\forestexample@sample
- \box\sampleoutputbox
- }%
- }%
- $%
- \end{trivlist}%
- \else
- \if t\fe@pos %%%% example is above the code
- \forest@temp@count=\@listdepth
- \pgfutil@tempdima=0pt
- \loop
- \ifnum\forest@temp@count>0
- \advance\pgfutil@tempdima\csname leftmargin\romannumeral\the\forest@temp@count\endcsname\relax
- \advance\forest@temp@count-1
- \repeat
- \setbox\lst@samplebox=\hbox{\hskip-\pgfutil@tempdima\box\lst@samplebox\hskip\pgfutil@tempdima}%
- \setbox\sampleoutputbox=\hbox{\lst@sampleInput}%
- \begin{trivlist}%
- \item
- \hfil\box\sampleoutputbox\hfil
- \item
- \hbox{%
- \hbox to 0pt{\hskip\linewidth\llap{\@currentlabel}}%
- \hbox to 0pt{%
- \raise\samplebox@baselineskip\box\lst@samplebox
- }%
- }%
- \end{trivlist}%
- \else
- \if b\fe@pos %%% example is below the code
- \forest@temp@count=\@listdepth
- \pgfutil@tempdima=0pt
- \loop
- \ifnum\forest@temp@count>0
- \advance\pgfutil@tempdima\csname leftmargin\romannumeral\the\forest@temp@count\endcsname\rel ax
- \advance\forest@temp@count-1
- \repeat
- \setbox\lst@samplebox=\hbox{\hskip-\pgfutil@tempdima\box\lst@samplebox\hskip\pgfutil@tempdima}%
- \setbox\sampleoutputbox=\hbox{\lst@sampleInput}%
- \begin{trivlist}%
- \item
- \hbox{%
- \hbox to 0pt{\hskip\linewidth\llap{\@currentlabel}}%
- \hbox to 0pt{%
- \raise\samplebox@baselineskip\box\lst@samplebox
- }%
- }%
- \item
- \hfil\box\sampleoutputbox\hfil
- \end{trivlist}%
- \else %%% insert other pos here....
- \fi
- \fi
- \fi
- \fi
-}%
-\def\myisaspect#1#2#3{% #1=aspect id, #2=aspect display, #3=entry ids
- \csdef{myaspect@display@#1}{#2}%
- \edef\myisaspect@##1{%
- \csdef{myaspect@of@##1}{#1}%
- }%
- \forcsvlist\myisaspect@{#3}%
-}
-\def\my@index#1#2#3#4{% #1=entry id,#2=entry display,#3=aspect id,#4=pagestyle
- \ifstrempty{#3}{%
- \edef\mytemp{%
- \noexpand\index{#1=\unexpanded{#2}#4}%
- }%
- }{%
- \edef\mytemp{%
- \noexpand\index{%
- #1=\unexpanded{#2}\protect\noexpand\space
- {\protect\noexpand\scriptsize
- \expandafter\expandafter\expandafter\unexpanded
- \expandafter\expandafter\expandafter
- {\csname myaspect@display@#3\endcsname}%
- }%
- #4%
- }%
- \noexpand\index{#3=\expandafter\expandafter\expandafter\unexpanded
- \expandafter\expandafter\expandafter
- {\csname myaspect@display@#3\endcsname}\levelchar
- #1=\unexpanded{#2}%
- #4%
- }%
- }%
- }%
- \mytemp
-}%
-\newcommand\myindex[1]{%
- \@bsphack
- \pgfqkeys{/myindex}{#1}%
- \pgfkeysgetvalue{/myindex/id}\myindex@temp@entryid
- \pgfkeysgetvalue{/myindex/display}\myindex@temp@entrydisplay
- \pgfkeysgetvalue{/myindex/aspect}\myindex@temp@aspectid
- \pgfkeysgetvalue{/myindex/pagestyle}\myindex@temp@pagestyle
- \edef\myindex@temp{\noexpand\my@index
- {\expandonce{\myindex@temp@entryid}}{\expandonce{\myindex@temp@entrydisplay}}{\expandonce{\myindex@temp@aspectid}}{\myindex@temp@pagestyle}%
- }\myindex@temp
- \@esphack
- \pgfkeysvalueof{/myindex/text}%
-}
-\def\stripfirst#1#2\stripfirst{#2}%
-\pgfqkeys{/myindex}{%
- /handlers/.wrap/.code={%
- \edef\myindex@currentpath{\pgfkeyscurrentpath}%
- \pgfkeysgetvalue{\myindex@currentpath}\myindex@keyvalue
- \forest@def@with@pgfeov\myindex@wrap@code{#1}%
- \expandafter\edef\expandafter\myindex@wrapped@value\expandafter{\expandafter\expandonce\expandafter{\expandafter\myindex@wrap@code\myindex@keyvalue\pgfeov}}%
- \pgfkeysalso{\myindex@currentpath/.expand once=\myindex@wrapped@value}%
- },
- /handlers/.ewrap/.code={% not used!
- \edef\myindex@currentpath{\pgfkeyscurrentpath}%
- \pgfkeysgetvalue{\myindex@currentpath}\myindex@keyvalue
- \forest@def@with@pgfeov\myindex@wrap@code{#1}%
- \edef\myindex@wrapped@value{\expandafter\myindex@wrap@code\expandafter{\myindex@keyvalue}\pgfeov}%
- \pgfkeysalso{\myindex@currentpath/.expand once=\myindex@wrapped@value}%
- },
- id/.code={%
- \pgfkeyssetvalue{/myindex/id}{#1}%
- \pgfkeysgetvalue{/myindex/id}\myindex@temp
- \pgfkeyslet{/myindex/display}\myindex@temp
- \pgfkeyslet{/myindex/text}\myindex@temp
- \pgfkeyssetvalue{/myindex/pagestyle}{}%
- \pgfkeyssetvalue{/myindex/version}{}%
- \ifcsname myaspect@of@#1\endcsname
- \pgfkeysalso{aspect/.expand once=\csname myaspect@of@#1\endcsname}%
- \else
- \pgfkeyssetvalue{/myindex/aspect}{}%
- \pgfkeyssetvalue{/myindex/margin}{}%
- \fi
- },
- id'/.code={\pgfkeyssetvalue{/myindex/id}{#1}},
- .unknown/.code={%
- \edef\myindex@temp{%
- \noexpand\pgfkeysalso{id={\pgfkeyscurrentname}}%
- }\myindex@temp
- },
- display/.initial={},
- pagestyle/.initial={},
- text/.initial={},
- aspect/.code={%
- \edef\myindex@temp{%
- \noexpand\pgfkeyssetvalue{/myindex/aspect}{#1}%
- }\myindex@temp
- \ifcsname myaspect@display@#1\endcsname
- \edef\myindex@temp{%
- \noexpand\pgfkeyslet{/myindex/margin}\expandonce{\csname myaspect@display@#1\endcsname}%
- }\myindex@temp
- \else
- \pgfkeyssetvalue{/myindex/margin}{}%
- \fi
- },
- nfc/.style={% no first char (in id)
- id'/.expanded={\expandafter\stripfirst\romannumeral-`0\pgfkeysvalueof{/myindex/id}\stripfirst}
- },
- rstyle/.style={text/.wrap={\begingroup\rstyle##1\endgroup}},
- example/.style={pagestyle=|indextextexample},
- def/.style={pagestyle=|indextextdef},
- normal/.style={pagestyle=|indextextnormal},
- item/.style={% #1=default
- text/.wrap={% ##1=current text
- \item[\pgfkeysvalueof{/myindex/version},#1,\pgfkeysvalueof{/myindex/margin}]{##1}%
- }
- },
- item/.default={},
- version/.initial={},
- margin/.initial={},
-}
-\newcommand\indextextexample[1]{\hyperlink{page.#1}{\textcolor{darkgreen}{#1}}}
-\newcommand\indextextdef[1]{\hyperlink{page.#1}{\textcolor{red}{#1}}}
-\newcommand\indextextnormal[1]{\hyperlink{page.#1}{\textcolor{blue}{#1}}}
-\let\keyname\texttt
-\newcommand\rkeyname[2][]{\myindex{%
- #2,
- display/.wrap=\protect\texttt{##1},
- text/.wrap=\hypertarget{\pgfkeysvalueof{/myindex/id}}{{\rstyle\keyname{##1}}},
- def,
- #1
- }}
-\newcommand\ikeyname[2][]{\myindex{%
- #2,
- display/.wrap=\protect\texttt{##1},
- text/.wrap=\hyperlink{\pgfkeysvalueof{/myindex/id}}{\keyname{##1}},
- normal,
- #1
- }}
-\newcommand\ekeyname[2][]{\myindex{%
- #2,
- display/.wrap=\protect\texttt{##1},
- text={},
- normal,
- #1
- }}
-\newcommand\rmeta[2][]{\myindex{%
- #2,
- display/.wrap=\protect\meta{##1},
- %text/.wrap=\begingroup\rstyle\meta{##1}\endgroup,
- text/.wrap=\hypertarget{\pgfkeysvalueof{/myindex/id}}{{\rstyle\meta{##1}}},
- def,
- #1
- }}
-\newcommand\imeta[2][]{\myindex{%
- #2,
- display/.wrap=\protect\meta{##1},
- text/.wrap=\hyperlink{\pgfkeysvalueof{/myindex/id}}{\meta{##1}},
- normal,
- #1
- }}
-\newcommand\cmdname[1]{\expandafter\texttt\expandafter{\expandafter\string\csname#1\endcsname}}
-\newcommand\rcmdname[2][]{\myindex{%
- #2,
- id'/.expanded=\pgfkeysvalueof{/myindex/id} macro,
- display/.wrap=\protect\cmdname{##1},
- text/.wrap=\hypertarget{\pgfkeysvalueof{/myindex/id}}{{\rstyle\cmdname{##1}}},
- def,
- #1
- }}
-\newcommand\icmdname[2][]{\myindex{%
- #2,
- id'/.expanded=\pgfkeysvalueof{/myindex/id} macro,
- text/.wrap=\hyperlink{\pgfkeysvalueof{/myindex/id}}{\cmdname{##1}},
- normal,
- #1
- }}
-\newcommand\ecmdname[2][]{\myindex{%
- #2,
- id'/.expanded=\pgfkeysvalueof{/myindex/id} macro,
- display/.wrap=\protect\cmdname{##1},
- text={},
- normal,
- #1
- }}
-\makeatother
-\myisaspect{environment}{environment}{forest}
-\myisaspect{option}{option}{align,content,content format,node format,base,node options,phantom,anchor,calign,calign primary angle,calign secondary angle,calign primary child,calign secondary child,fit,grow,ignore,ignore edge,reversed,l,s,l sep,s sep,tier,x,y,child anchor,edge,edge label,edge path,parent anchor,name,tikz,anchor,level,n,n',n children,id,max x,max y,min x,min y}
-\myisaspect{propagator}{propagator}{for,if,where,for tree,repeat,delay,delay n,if have delayed,for ancestors,for ancestors',for children,for descendants,for descendants',for all next,for all previous,for previous siblings,before typesetting nodes,before packing,before computing xy,before drawing tree,repeat}
-\myisaspect{type}{type}{toks,autowrapped toks,keylist,dimen,count,boolean}%relative node name,node walk,step}
-\myisaspect{handler}{handler}{.pgfmath,.wrap value,.wrap pgfmath arg,.wrap $n$ pgfmath args,.wrap 2 pgfmath args,.wrap 3 pgfmath args,.wrap 4 pgfmath args,.wrap 5 pgfmath args,.wrap 6 pgfmath args,.wrap 7 pgfmath args,.wrap 8 pgfmath args,.wrap 9 pgfmath args}
-\myisaspect{key prefix}{key prefix}{if in ,where in ,if ,where ,not ,for }
-\myisaspect{key suffix}{key suffix}{',+,-,*,:,'+,'-,'*,':}
-\myisaspect{key}{}{afterthought,baseline,label,pin,alias,TeX,TeX',TeX'',no edge,typeset node,repeat,use as bounding box,use as bounding box',draw tree box}
-\myisaspect{style}{style}{stages,typeset nodes stage,pack stage,compute xy stage,draw tree
- stage,math content}
-\myisaspect{stage}{stage}{typeset nodes,typeset nodes',pack,compute xy,draw tree,draw tree'}
-\myisaspect{package option}{package option}{external,tikzcshack,tikzinstallkeys}
-\myisaspect{dynamic tree}{dynamic tree}{create,remove,prepend,append,insert after,insert before,set
- root,replace by,prepend',append',insert after',insert before',replace by',prepend'',append'',insert after'',insert before'',replace by'',copy name template}
-\myisaspect{forest cs}{forest cs}{}
-
-\myisaspect{calign}{\keyname{calign} value}{}%{child,first,last,child edge,midpoint,center,edge midpoint,fixed angles,fixed edge angles}
-\myisaspect{align}{\keyname{align} value}{}%{left,center,right}
-\myisaspect{fit}{\keyname{fit} value}{}%{tight,rectangle,band}
-\myisaspect{base}{\keyname{base} value}{}%{top,bottom}
-
-\myisaspect{step}{\meta{step}}{current,next,previous,parent,sibling,previous leaf,next leaf,
- linear next,linear previous,first leaf,last leaf,to tier,next on tier,previous on tier,
- root,embed,trip,group,first,last
- %,n,n',name,id, % these equal option names
-}
-\myisaspect{short step}{\meta{short step}}{1,2,3,4,5,6,7,8,9,u,p,%
- %,n,l,s equal option names
- P,N,F,L,<,%> is a level char
- c,r}
-\myisaspect{generic anchor}{generic anchor}{}%
-{\catcode`\|=12 \gdef\myindexgt{\texttt{>}}}
-{\makeatletter % an dirty patch: \lst@nolig can sneak in the name...
-\gdef\myexampleindex#1{{\def\lst@nolig{}\lstaspectindex{#1}{}}}
-}
-\lstset{indexstyle={[1]\myexampleindex}}
-\makeindex
-%%% end lst-related stuff
-
-\EnableCrossrefs
- %\DisableCrossrefs % Say \DisableCrossrefs if index is ready
- %\CodelineIndex
- %\RecordChanges % Gather update information
- %\OnlyDescription % comment out for implementation details
-\setlength\hfuzz{15pt} % dont make so many
-\hbadness=7000 % over and under full box warnings
-\def\partname{Part}
-
-\def\TikZ;{{\rm Ti\emph{k}Z}}\def\PGF;{\textsc{pgf}}\def\foRest;{\textsc{Forest}}\def\FoRest;{\textsc{Forest}}
-\usetikzlibrary{intersections}
-\tikzset{>=latex}
-\forestset{
- background tree/.style={
- for tree={text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
-}
-
-\def\getforestversion#1/#2/#3 v#4 #5\getforestversion{v#4}
-\edef\forestversion{\expandafter\expandafter\expandafter\getforestversion\csname ver@forest.sty\endcsname\getforestversion}
-
-\def\getforestdate#1/#2/#3 v#4 #5\getforestdate{#1/#2/#3}
-\edef\forestdate{\expandafter\expandafter\expandafter\getforestdate\csname ver@forest.sty\endcsname\getforestdate}
-
-\title{\FoRest;: a \PGF;/\TikZ;-based package for drawing linguistic trees\\\normalsize\forestversion}
-\author{Sa\v so \v Zivanovi\'c\footnote{e-mail:
- \href{mailto:saso.zivanovic@guest.arnes.si}{saso.zivanovic@guest.arnes.si};
- web:
- \href{http://spj.ff.uni-lj.si/zivanovic/}{http://spj.ff.uni-lj.si/zivanovic/}}}
-\def\settodayfromforestdateA#1/#2/#3 v#4 #5\settodayfromforestdateA{\def\year{#1}\def\month{#2}\def\day{#3}}
-\def\settodayfromforestdate{\expandafter\expandafter\expandafter\settodayfromforestdateA\csname ver@forest.sty\endcsname\settodayfromforestdateA}
+%\input forest-common
\begin{document}
\DocInput{forest.dtx}
\end{document}
%</driver>
% \fi
-%
-% ^^A short verbatim: | (changes spaces into _)
-% \DeleteShortVerb\|
-% {\catcode`\_=12 \def\marshal{^^A
-% \lstMakeShortInline[basicstyle=\ttfamily,literate={_}{ }1 {__}{_}1]}^^A
-% \expandafter}\marshal |
%
-% \newbox\treebox
-% \newbox\codebox
-%
-%
-%
-% {\settodayfromforestdate\maketitle}
-%
-% \begin{abstract}
-% \FoRest; is a \PGF;/\TikZ;-based package for drawing linguistic (and
-% other kinds of) trees. Its main features are
-% \begin{inparaenum}[(i)]
-% \item a packing algorithm which can produce very compact trees;
-% \item a user-friendly interface consisting of the familiar bracket encoding of trees plus the
-% key--value interface to option-setting;
-% \item many tree-formatting options, with control over option values of individual nodes and
-% mechanisms for their manipulation;
-% \item the possibility to decorate the tree using the full power of \PGF;/\TikZ;;
-% \item an externalization mechanism sensitive to code-changes.
-% \end{inparaenum}
-% \end{abstract}
-%
-% {\lstset{basicstyle=\ttfamily\scriptsize}^^A
-% \begin{forestexample}[samplebox=\treebox,codebox=\codebox,pos=x,ekeynames={content,{id=.pgfmath,nfc},if,repeat,append,before drawing tree,where,y,alias,for ,name,for children,edge,before typesetting nodes,for tree,s sep,l,+,,for ancestors',typeset node}]
-% \pgfmathsetseed{14285}
-% \begin{forest}
-% random tree/.style n args={3}{% #1=max levels, #2=max children, #3=max content
-% content/.pgfmath={random(0,#3)},
-% if={#1>0}{repeat={random(0,#2)}{append={[,random tree={#1-1}{#2}{#3}]}}}{}},
-% for deepest/.style={before drawing tree={
-% alias=deepest,
-% where={y()<y("deepest")}{alias=deepest}{},
-% for name={deepest}{#1}}},
-% colorone/.style={fill=yellow,for children=colortwo}, colortwo/.style={fill=green,for children=colorone},
-% important/.style={draw=red,line width=1.5pt,edge={red,line width=1.5pt,draw}},
-% before typesetting nodes={colorone, for tree={draw,s sep=2pt,rotate={int(30*rand)},l+={5*rand}}},
-% for deepest={for ancestors'={important,typeset node}}
-% [,random tree={9}{3}{100}]
-% \end{forest}
-% \end{forestexample}%
-% \begin{center}\mbox{}\box\treebox\\\box\codebox\end{center}}
-% \newpage
-% {\parskip 0pt ^^A We have to reset \parskip
-% ^^A (bug in \LaTeX)
-% \tableofcontents
-% }
-%
-% \newpage
-% \part{User's Guide}
-% \section{Introduction}
-%
-% Over several years, I had been a grateful user of various packages
-% for typesetting linguistic trees. My main experience was with
-% |qtree| and |synttree|, but as far as I can tell, all of the tools
-% on the market had the same problem: sometimes, the trees were just
-% too wide. They looked something like the tree on the left,
-% while I wanted something like the tree on the right.
-% \begin{center}
-% \begin{forest}
-% baseline,
-% for tree={parent anchor=south,child anchor=north,l=7ex,s sep=10pt},
-% for children={fit=rectangle}
-% [CP
-% [DP
-% [D][NP[N][CP[C][TP[T][vP[v][VP[DP][V'[V][DP]]]]]]]]
-% [TP
-% [T][vP[v][VP[DP][V'[V][DP]]]]]
-% ]
-% \end{forest}
-% \hfill
-% \begin{forest}
-% baseline,
-% for tree={parent anchor=south,child anchor=north,l=7ex,s sep=10pt},
-% [CP
-% [DP
-% [D][NP[N][CP[C][TP[T][vP[v][VP[DP][V'[V][DP]]]]]]]]
-% [TP
-% [T][vP[v][VP[DP][V'[V][DP]]]]]
-% ]
-% \end{forest}
-% \end{center}
-%
-% Luckily, it was possible to tweak some parameters by hand to get a
-% narrower tree, but as I quite dislike constant manual adjustments, I
-% eventually started to develop \foRest;. It started out as
-% xyforest, but lost the xy prefix as I became increasingly fond
-% of \PGF;/\TikZ;, which offered not only a drawing package but also a
-% `programming paradigm.' It is due to the awesome power of the
-% supplementary facilities of \PGF;/\TikZ; that \foRest; is now, I
-% believe, the most flexible tree typesetting package for \LaTeX\ you can get.
-%
-% After all the advertising, a disclaimer. Although the present version
-% is definitely usable (and has been already used), the package and
-% its documentation are still under development: comments, criticism,
-% suggestions and code are all very welcome!
-%
-% \FoRest; is \href{http://www.ctan.org/pkg/forest}{available} at \href{http://www.ctan.org}{CTAN},
-% and I have also started a \href{https://github.com/sasozivanovic/forest-styles}{style repository}
-% at \href{https://github.com}{GitHub}.
-%
-% \section{Tutorial}
-% \label{sec:tutorial}
-%
-% This short tutorial progresses from basic through useful to
-% obscure \dots
-%
-% \subsection{Basic usage}
-% \label{sec:basic-usage}
-%
-% A tree is input by enclosing its specification in a \ikeyname{forest}
-% environment. The tree is encoded by \emph{the bracket syntax}:
-% every node is enclosed in square brackets; the children of a
-% node are given within its brackets, after its content.
-% {\lstdefinelanguage[my]{TeX}[LaTeX]{TeX}{keywords=forest,
-% otherkeywords={[,]},keywordstyle=\pstyle,texcsstyle={}}^^A
-% \lstset{language={[my]TeX}}^^A
-% \begin{forestexample}
-% \begin{forest}
-% [VP
-% [DP]
-% [V'
-% [V]
-% [DP]
-% ]
-% ]
-% \end{forest}
-% \end{forestexample}}
-% Binary trees are nice, but not the only thing this package can draw.
-% Note that by default, the children are vertically centered with
-% respect to their parent, i.e.\ the parent is vertically aligned with the midpoint between the
-% first and the last child.
-% \begin{forestexample}
-% \begin{forest}
-% [VP
-% [DP[John]]
-% [V'
-% [V[sent]]
-% [DP[Mary]]
-% [DP[D[a]][NP[letter]]]
-% ]
-% ]
-% \end{forest}
-% \end{forestexample}
-% Spaces around brackets are ignored --- format your code as you
-% desire!
-% \begin{forestexample}
-% \begin{forest}
-% [VP[DP][V'[V][DP]]]
-% \end{forest}
-% \quad
-% \begin{forest}[VP
-% [DP ] [ V'[V][ DP]]
-% ]\end{forest}
-% \end{forestexample}
-% If you need a square bracket as part of a node's content, use
-% braces. The same is true for the other characters which have a
-% special meaning in the \foRest; package: comma
-% |,| and equality sign |=|.
-% \begin{forestexample}
-% \begin{forest}
-% [V{P,}
-% [{[DP]}]
-% [V'
-% [V]
-% [{===DP===}]]]
-% \end{forest}
-% \end{forestexample}
-% Macros in a node specification will be expanded when the node is
-% drawn --- you can freely use formatting commands inside nodes!
-% \begin{forestexample}
-% \begin{forest}
-% [VP
-% [{~\textbf~{DP}}]
-% [V'
-% [V]
-% [DP]]]
-% \end{forest}
-% \end{forestexample}
-%
-% \newbox\GPone
-% \begin{forestexample}[pos=x,samplebox=\treebox,codebox=\GPone]
-% \newbox\standardnodestrutbox
-% \setbox\standardnodestrutbox=\hbox to 0pt{\phantom{\forestOve{standard node}{content}}}
-% \def\standardnodestrut{\copy\standardnodestrutbox}
-% \forestset{
-% ~GP1~/.style 2 args={
-% for n={1}{baseline},
-% s sep=0pt, l sep=0pt,
-% for descendants={
-% l sep=0pt, l={#1},
-% anchor=base,calign=first,child anchor=north,
-% inner xsep=1pt,inner ysep=2pt,outer sep=0pt,s sep=0pt,
-% },
-% delay={
-% if content={}{phantom}{for children={no edge}},
-% for tree={
-% if content={O}{tier=OR}{},
-% if content={R}{tier=OR}{},
-% if content={N}{tier=N}{},
-% if content={x}{
-% tier=x,content={$\times$},outer xsep={#2},
-% for tree={calign=center},
-% for descendants={content format={\standardnodestrut\forestoption{content}}},
-% before drawing tree={outer xsep=0pt,delay={typeset node}},
-% s sep=4pt
-% }{},
-% },
-% },
-% before drawing tree={where content={}{parent anchor=center,child anchor=center}{}},
-% },
-% GP1/.default={5ex}{8.0pt},
-% associate/.style={%
-% tikz+={\draw[densely dotted](!)--(!#1);}},
-% spread/.style={
-% before drawing tree={tikz+={\draw[dotted](!)--(!#1);}}},
-% govern/.style={
-% before drawing tree={tikz+={\draw[->](!)--(!#1);}}},
-% p-govern/.style={
-% before drawing tree={tikz+={\draw[->](.north) to[out=150,in=30] (!#1.north);}}},
-% no p-govern/.style={
-% before drawing tree={tikz+={\draw[->,loosely dashed](.north) to[out=150,in=30] (!#1.north);}}},
-% encircle/.style={before drawing tree={circle,draw,inner sep=0pt}},
-% fen/.style={pin={[font=\footnotesize,inner sep=1pt,pin edge=<-]10:\textsc{Fen}}},
-% el/.style={content=\textsc{\textbf{##1}}},
-% head/.style={content=\textsc{\textbf{\underline{##1}}}}
-% }
-% \end{forestexample}
-% \input{\jobname.tmp}
+% \title{Implementation of \FoRest;, a \PGF;/\TikZ;-based package for drawing linguistic
+% trees\\\normalsize\forestversion}
%
-% All the examples given above produced top-down trees with centered
-% children. The other sections of this manual explain how various
-% properties of a tree can be changed, making it possible to typeset
-% radically different-looking trees. However, you don't have to learn
-% everything about this package to profit from its power. Using
-% styles, you can draw predefined types of trees with ease. For
-% example, a phonologist can use the \ikeyname{GP1} style from \S\ref{sec:gallery} to easily typeset
-% (Government Phonology) phonological
-% representations. The style is applied simply by writing its name
-% before the first (opening) bracket of the tree.
-% \begin{forestexample}[label=ex:gp1-frost]
-% \begin{forest} ~GP1~ [
-% [O[x[f]][x[r]]]
-% [R[N[x[o]]][x[s]]]
-% [O[x[t]]]
-% [R[N[x]]]
-% ]\end{forest}
-% \end{forestexample}
-% Of course, someone needs to develop the style --- you, me, your
-% local \TeX nician \dots\@ Furtunately, designing styles is not very
-% difficult once you know your \foRest; options. If you write one,
-% please contribute!
-%
-% I have started a \href{https://github.com/sasozivanovic/forest-styles}{style repository} at
-% GitHub. Hopefully, it will grow \dots\@ Check it out, download the styles \dots\ and contribute
-% them!
-%
-% \subsection{Options}
-% \label{sec:options}
-%
-% A node can be given various options, which control various
-% properties of the node and the tree. For example, at the end of
-% section~\ref{sec:basic-usage}, we have seen that the \ikeyname{GP1} style
-% vertically aligns the parent with the first
-% child. This is achieved by setting option \ikeyname{calign} (for
-% \emph{c}hild-\emph{align}ment) to \ikeyname{first,aspect=calign} (child).
-%
-% Let's try. Options are given inside the brackets, following the
-% content, but separated from it by a comma. (If multiple options are
-% given, they are also separated by commas.) A single option
-% assignment takes the form \meta{option name}|=|\meta{option value}. (There are
-% also options which do not require a value or have a default value:
-% these are given simply as \meta{option name}.)
-% \begin{forestexample}[label=ex:numerals-simple,ekeynames={calign,{first,aspect=calign}}]
-% \begin{forest}
-% [\LaTeX\ numerals, ~calign=first~
-% [arabic[1][2][3][4]]
-% [roman[i][ii][iii][iv]]
-% [alph[a][b][c][d]]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% The experiment has succeeded only partially. The root node's
-% children are aligned as desired (so \ikeyname{calign}|=|\ikeyname{first,aspect=calign} applied to the
-% root node), but the value of the \ikeyname{calign} option didn't get
-% automatically assigned to the root's children! \emph{An option given
-% at some node applies only to that node.} In \foRest;, the options
-% are passed to the node's relatives via special options, called
-% \emph{propagators}. (We'll
-% call the options that actually change some property of the node
-% \emph{node options}.) What we need above is the \ikeyname{for tree} propagator. Observe:
-% \begin{forestexample}[label=ex:numerals-manual]
-% \begin{forest}
-% [\LaTeX\ numerals,
-% ~for tree~={calign=first}
-% [arabic[1][2][3][4]]
-% [roman[i][ii][iii][iv]]
-% [alph[a][b][c][d]]
-% ]
-% \end{forest}
-% \end{forestexample}
-% The value of propagator \ikeyname{for tree} is the option string that we
-% want to process. This option string is propagated to all the nodes in
-% the subtree\footnote{It might be more precise to call this option
-% \texttt{for subtree} \dots\@ but this name at least saves some typing.}
-% rooted in the current node (i.e.\ the node where \ikeyname{for tree} was
-% given), including the node itself. (Propagator \ikeyname{for descendants} is
-% just like \ikeyname{for tree}, only that it excludes the node itself. There
-% are many other \ikeyname{id={{for }}}|...| propagators; for the complete list, see
-% sections~\ref{ref:propagators} and \ref{ref:node-walk}.)
+% \author{Sa\v so \v Zivanovi\'c\footnote{e-mail:
+% \href{mailto:saso.zivanovic@guest.arnes.si}{saso.zivanovic@guest.arnes.si}; web:
+% \href{http://spj.ff.uni-lj.si/zivanovic/}{http://spj.ff.uni-lj.si/zivanovic/}}}
%
-% Some other useful options are \ikeyname{parent anchor}, \ikeyname{child anchor}
-% and \ikeyname{tier}. The \ikeyname{parent anchor} and \ikeyname{child anchor} options tell
-% where the parent's and child's endpoint of the edge between them
-% should be, respectively: usually, the value is either empty
-% (meaning a smartly determined border point \citep[see][\S16.11]{tikzpgf2.10}; this is the default)
-% or a compass direction \citep[see][\S16.5.1]{tikzpgf2.10}. (Note: the \ikeyname{parent anchor}
-% determines where the
-% edge from the child will arrive to this node, not where the node's
-% edge to its parent will start!)
-%
-% Option \ikeyname{tier} is what makes the
-% skeletal points $\times$ in example \ref{ex:gp1-frost} align horizontally although they
-% occur at different levels in the logical structure of the tree.
-% Using option \ikeyname{tier} is very simple: just set |tier=tier_name| at
-% all the nodes that you want to align horizontally. Any tier name
-% will do, as long as the tier names of different tiers are
-% different \dots\@ (Yes, you can have multiple tiers!)
-% \begin{forestexample}[point={tier},ekeynames={parent anchor,child anchor,tier},label=ex:tier-manual]
-% \begin{forest}
-% [VP, for tree={~parent anchor~=south, ~child anchor~=north}
-% [DP[John,tier=word]]
-% [V'
-% [V[sent,tier=word]]
-% [DP[Mary,tier=word]]
-% [DP[D[a,tier=word]][NP[letter,tier=word]]]
-% ]
-% ]
-% \end{forest}
-% \end{forestexample}
-% Before discussing the variety of \foRest;'s options, it is worth
-% mentioning that \foRest;'s node accepts all options \citep[see
-% \S16]{tikzpgf2.10} that \TikZ;'s node does --- mostly, it just passes
-% them on to \TikZ;. For example, you can easily encircle a node like
-% this:\footnote{If option \texttt{draw} was not given, the shape of the node
-% would still be circular, but the edge would not be drawn. For
-% details, see \cite[\S16]{tikzpgf2.10}.}
-% \begin{forestexample}
-% \begin{forest}
-% [VP,~circle~,~draw~
-% [DP][V'[V][DP]]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% Let's have another look at example \ref{ex:gp1-frost}. You will note that the skeletal
-% positions were input by typing |x|s, while the result looks like
-% this: $\times$ (input as |\times| in math mode). Obviously, the
-% content of the node can be changed. Even more, it can be
-% manipulated: added to, doubled, boldened, emphasized, etc. We will
-% demonstrate this by making example \ref{ex:numerals-manual} a bit
-% fancier: we'll write the input in the arabic numbers and have
-% \LaTeX\ convert it to the other formats. We'll start with the
-% easiest case of roman numerals: to get them, we can use the (plain)
-% \TeX\ command |\romannumeral|. To change the content of the node,
-% we use option \ikeyname{content}. When specifying its new value, we can use
-% |#1| to insert the current content.\footnote{This mechanism is called
-% \emph{wrapping}. \ikeyname{content} is the only option where wrapping works implicitely (simply
-% because I assume that wrapping will be almost exclusively used with this option). To wrap values
-% of other options, use handler \ikeyname{id=.wrap value,nfc}; see~\S\ref{ref:handlers}.}
-% \begin{forestexample}[point={content,delay},ekeynames={for children,content,delay},label=ex:romannumeral]
-% \begin{forest}
-% [roman, delay={for children={content=\romannumeral#1}}
-% [1][2][3][4]
-% ]
-% \end{forest}
-% \end{forestexample}
-% This example introduces another option: \ikeyname{delay}. Without it, the
-% example wouldn't work: we would get arabic numerals. This is so
-% because of the order in which the options are processed. The
-% processing proceeds through the tree in a depth-first, parent-first fashion (first
-% the parent is processed, and then its children, recursively). The option string of a node is
-% processed linearly, in the order they were given. (Option \keyname{content}
-% is specified implicitely and is always the first.) If a propagator
-% is encountered, the options given as its value are propagated \emph{immediately}. The net effect
-% is that if the
-% above example contained simply |roman,for_children={content=...}|, the
-% \keyname{content} option given there would be processed \emph{before} the
-% implicit content options given to the children (i.e.\ numbers |1|,
-% |2|, |3| and |4|). Thus, there would be nothing for the
-% |\romannumeral| to change --- it would actually crash; more generally, the content assigned
-% in such a way would get overridden by the implicit content. Option
-% \ikeyname{delay} is true to its name. It delays the processing of its option
-% string argument until the whole tree was processed. In other words,
-% it introduces cyclical option processing. Whatever is delayed in
-% one cycle, gets processed in the next one. The number of cycles is
-% not limited --- you can nest \ikeyname{delay}s as deep as you need.
-%
-% Unlike \ikeyname{id={{for }}}|_...| options we have met before, option \ikeyname{delay} is not a
-% spatial, but a temporal propagator. Several other temporal propagators options exist, see
-% \S\ref{ref:stages}.
-%
-% We are now ready to learn about simple conditionals. Every node option has the corresponding
-% \ikeyname{id={{if }}}|...| and \ikeyname{id={{where }}}|...| keys.
-% \ikeyname{id={{if }}}\meta{option}|=|\meta{value}\meta{true options}\meta{false options} checks whether
-% the value of \meta{option} equals \meta{value}. If so, \meta{true options} are
-% processed, otherwise \meta{false options}. The \ikeyname{id={{where }}}|_...| keys are
-% the same, but do this for the every node in the subtree; informally
-% speaking, |where| = |for_tree| + |if|. To see this in action,
-% consider the rewrite of the \ikeyname{tier} example \ref{ex:tier-manual} from above. We don't set
-% the tiers manually, but rather put the terminal nodes (option
-% \ikeyname{n children} is a read-only option containing the number
-% of children) on tier \keyname{word}.\footnote{We could omit the braces around \texttt{0} because
-% it is a single character. If we were hunting for nodes with 42 children, we'd have to write
-% \texttt{where n children=\{42\}...}.}
-% \begin{forestexample}[ekeynames={tier,where ,n children}]
-% \begin{forest}
-% ~where n children~=0{tier=word}{}
-% [VP
-% [DP[John]]
-% [V'
-% [V[sent]]
-% [DP[Mary]]
-% [DP[D[a]][NP[letter]]]
-% ]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% Finally, let's talk about styles. Styles are simply collections of
-% options. (They are not actually defined in the \foRest; package, but
-% rather inherited from |pgfkeys|.) If you often want to have non-default
-% parent/child anchors, say south/north as in example \ref{ex:tier-manual}, you would save some
-% typing by defining a style. Styles are defined using \PGF;'s handler
-% |.style|. (In the example below, style |ns_edges| is first defined and then used.)
-% \begin{forestexample}[ekeynames={tier,parent anchor,child anchor}]
-% \begin{forest}
-% ~sn edges~/~.style~={for tree={
-% parent anchor=south, child anchor=north}},
-% ~sn edges~
-% [VP,
-% [DP[John,tier=word]]
-% [V'
-% [V[sent,tier=word]]
-% [DP[Mary,tier=word]]
-% [DP[D[a,tier=word]][NP[letter,tier=word]]]]]
-% \end{forest}
-% \end{forestexample}
-% If you want to use a style in more than one tree, you have to define it outside the \ikeyname{forest}
-% environment. Use macro \icmdname{forestset} to do this.
-% \begin{lstlisting}
-% ~\forestset~{
-% sn edges/.style={for tree={parent anchor=south, child anchor=north}},
-% background tree/.style={for tree={
-% text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
-% }
-% \end{lstlisting}
-%
-% You might have noticed that the last two examples contain options (actually, keys) even before the
-% first opening bracket, contradicting was said at the beginning of this section. This is mainly
-% just syntactic sugar (it can separate the design and the content): such preamble
-% keys behave as if they were given in the root node, the only difference (which often does not
-% matter) being that they get processed before all other root node options, even the implicit
-% content.
-%
-% \subsection{Decorating the tree}
-% \label{sec:decorating}
-%
-% The tree can be decorated (think movement arrows) with arbitrary
-% \TikZ; code.
-% \begin{forestexample}
-% \begin{forest}
-% [XP
-% [specifier]
-% [X$'$
-% [X$^0$]
-% [complement]
-% ]
-% ]
-% ~\node at (current bounding box.south)
-% [below=1ex,draw,cloud,aspect=6,cloud puffs=30]
-% {\emph{Figure 1: The X' template}};~
-% \end{forest}
-% \end{forestexample}
-%
-% However, decorating the tree would make little sense if one could
-% not refer to the nodes. The simplest way to do so is to give them a
-% \TikZ; name using the \ikeyname{name} option, and then use this name in \TikZ;
-% code as any other (\TikZ;) node name.
-% \begin{forestexample}[point=name,ekeynames={phantom,name}]
-% \begin{forest}
-% [CP
-% [DP,name=spec CP]
-% [\dots
-% [,phantom]
-% [VP
-% [DP]
-% [V'
-% [V]
-% [DP,name=object]]]]]
-% \draw[->,dotted] ~(object)~ to[out=south west,in=south] ~(spec CP)~;
-% \end{forest}
-% \end{forestexample}
-%
-% It gets better than this, however! In the previous examples, we put
-% the \TikZ; code after the tree specification, i.e.\ after the closing
-% bracket of the root node. In fact, you can put \TikZ; code after
-% \emph{any} closing bracket, and \foRest; will know what the current
-% node is. (Putting the code after a node's bracket is actually just a
-% special way to provide a value for option \ikeyname{tikz} of that node.) To
-% refer to the current node, simply use an empty node name. This works both with and without
-% anchors \citep[see][\S16.11]{tikzpgf2.10}: below, |(.south east)| and |()|.
-% \begin{forestexample}[ekeynames={phantom,name}]
-% \begin{forest}
-% [CP
-% [DP,name=spec CP]
-% [\dots
-% [,phantom]
-% [VP
-% [DP]
-% [V'
-% [V]
-% [DP,draw] ~{~
-% \draw[->,dotted] ~()~ to[out=south west,in=south] (spec CP);
-% \draw[<-,red] ~(.south east)~--++(0em,-4ex)--++(-2em,0pt)
-% node[anchor=east,align=center]{This guy\\has moved!};
-% ~}~
-% ]]]]
-% \end{forest}
-% \end{forestexample}
-%
-% Important: \emph{the \TikZ; code should usually be enclosed in braces} to hide
-% it from the bracket parser. You don't want all the bracketed code
-% (e.g.\ |[->,dotted]|) to become tree nodes, right? (Well, they
-% probably wouldn't anyway, because \TeX\ would spit out a thousand
-% errors.)
+% \settodayfromforestdate
%
+% \maketitle
+% \tableofcontents
% \bigskip
-%
-% Finally, the most powerful tool in the node reference toolbox:
-% \emph{relative nodes}. It is possible to refer to other nodes which stand
-% in some (most often geometrical) relation to the current node. To
-% do this, follow the node's name with a |!| and a \emph{node walk}
-% specification.
-%
-% A node walk is a concise\footnote{Actually, \foRest; distinguishes two kinds of
-% steps in node walks: long and short steps. This section introduces only short steps. See
-% \S\ref{ref:node-walk}.} way of expressing node
-% relations. It is simply a string of steps, which are represented by single
-% characters, where: \ikeyname{u} stands for the parent node (up); \ikeyname{p} for the
-% previous sibling; \ikeyname{n,aspect=short step} for the next sibling; \ikeyname{s,aspect=short step} for \emph{the}
-% sibling (useful only in binary trees);\ekeyname{3} \ikeyname{1}, \ikeyname{2},
-% \ekeyname{3}\ekeyname{4}\ekeyname{5}\ekeyname{6}\ekeyname{7}\ekeyname{8}\dots\
-% \ikeyname{9} for first,
-% second, \dots\ ninth child; \ikeyname{l,aspect=short step}, for the last child, etc. For the
-% complete specification, see section~\ref{ref:node-walk}.
-%
-% To see the node walk in action, consider the following examples.
-% In the first example, the agree arrow connects the V node, specified
-% simply as |()|, since the \TikZ; code follows |[V]|, and the DP node,
-% which is described as ``a sister of V's parent'': |!us| = up +
-% sibling.
-% \begin{forestexample}
-% \begin{forest}
-% [VP
-% [DP]
-% [V'
-% [V] {\draw[<->] ~()~
-% .. controls +(left:1cm) and +(south west:0.4cm) ..
-% node[very near start,below,sloped]{\tiny agree}
-% ~(!us)~;}
-% [DP]
-% ]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% {\footnotesize\begin{forestexample}[ekeynames={phantom,tikz,fit to tree},samplebox=\treebox,codebox=\codebox,pos=x,basicstyle=\footnotesize\ttfamily]
-% \begin{forest}
-% [CP
-% [DP$_1$]
-% [\dots
-% [,phantom]
-% [VP,tikz={\node [draw,red,~fit to tree~]{};}
-% [DP$_2$]
-% [V'
-% [V]
-% [DP$_3$]
-% ]]]]
-% \end{forest}
-% \end{forestexample}}
-% The second example uses \TikZ;'s fitting library to compute the
-% smallest rectangle containing node VP, its first child (DP$_2$) and its last grandchild (DP$_3$).
-% The example also illustrates that the \TikZ; code
-% can be specified via the ``normal'' option syntax, i.e.\ as a value
-% to option \ikeyname{tikz}.\footnote{\label{fn:fit-to-tree}Actually, there's a simpler way to do this: use \ikeyname{fit to tree}!\\\raisebox{\dimexpr-\dp\codebox+1ex\relax}{\box\treebox}\hfill\box\codebox}
-% \begin{forestexample}[point=tikz,ekeynames={phantom,tikz}]
-% \begin{forest}
-% [CP
-% [DP$_1$]
-% [\dots
-% [,phantom]
-% [VP,tikz={\node [draw,red,fit=~()(!1)(!ll)~] {};}
-% [DP$_2$]
-% [V'
-% [V]
-% [DP$_3$]
-% ]]]]
-% \end{forest}
-% \end{forestexample}
-%
-%
-% \subsection{Node positioning}
-% \label{sec:node-positioning}
-%
-% \FoRest; positions the nodes by a recursive bottom-up algorithm which, for every non-terminal node,
-% computes the positions of the node's children relative to their parent. By default, all the
-% children will be aligned horizontally some distance down from their parent: the ``normal'' tree
-% grows down. More generally, however, the direction of growth can change from node to node; this is
-% controlled by option \ikeyname{grow}=\meta{direction}.\footnote{The direction can be specified either in
-% degrees (following the standard mathematical convention that $0$ degrees is to the right, and that
-% degrees increase counter-clockwise) or by the compass directions: \texttt{east}, \texttt{north east},
-% \texttt{north}, etc.} The system thus computes and stores the positions of children using a
-% coordinate system dependent on the parent, called an \emph{ls-coordinate system}: the origin is the
-% parent's anchor; l-axis is in the direction of growth in the parent; s-axis is orthogonal to the
-% l-axis (positive side in the counter-clockwise direction from $l$-axis); l stands for \emph{l}evel,
-% s for \emph{s}ibling. The example shows the ls-coordinate system for a node with |grow=45|.
-%
-% \begin{forestexample}[point=grow,ekeynames=grow]
-% \begin{forest} background tree
-% [parent, grow=45
-% [child 1][child 2][child 3][child 4][child 5]
-% ]
-% \draw[,->](-135:1cm)--(45:3cm) node[below]{$l$};
-% \draw[,->](-45:1cm)--(135:3cm) node[right]{$s$};
-% \end{forest}
-% \end{forestexample}
-%
-% \begin{forestexample}[basicstyle=\scriptsize\ttfamily,samplebox=\treebox,codebox=\codebox,pos=x]
-% \newcommand\measurexdistance[5][####1]{\measurexorydistance{#2}{#3}{#4}{#5}{\x}{-|}{(5pt,0)}{#1}}
-% \newcommand\measureydistance[5][####1]{\measurexorydistance{#2}{#3}{#4}{#5}{\y}{|-}{(0,5pt)}{#1}}
-% \tikzset{dimension/.style={<->,>=latex,thin,every rectangle node/.style={midway,font=\scriptsize}},
-% guideline/.style=dotted}
-% \newdimen\absmd
-% \def\measurexorydistance#1#2#3#4#5#6#7#8{%
-% \path #1 #3 #6 coordinate(md1) #1; \draw[guideline] #1 -- (md1);
-% \path (md1) #6 coordinate(md2) #2; \draw[guideline] #2 -- (md2);
-% \path let \p1=($(md1)-(md2)$), \n1={abs(#51)} in \pgfextra{\xdef\md{#51}\global\absmd=\n1\relax};
-% \def\distancelabelwrapper##1{#8}%
-% \ifdim\absmd>5mm
-% \draw[dimension] (md1)--(md2) node[#4]{\distancelabelwrapper{\uselengthunit{mm}\rndprintlength\absmd}};
-% \else
-% \ifdim\md>0pt
-% \draw[dimension,<-] (md1)--+#7; \draw[dimension,<-] let \p1=($(0,0)-#7$) in (md2)--+(\p1);
-% \else
-% \draw[dimension,<-] let \p1=($(0,0)-#7$) in (md1)--+(\p1); \draw[dimension,<-] (md2)--+#7;
-% \fi
-% \draw[dimension,-] (md1)--(md2) node[#4]{\distancelabelwrapper{\uselengthunit{mm}\rndprintlength\absmd}};
-% \fi}
-% \end{forestexample}
-% \input{\jobname.tmp}
-%
-% The l-coordinate of children is (almost) completely under your control, i.e.\ you set what is
-% often called the level distance by yourself. Simply set option \ikeyname{l} to change the
-% distance of a node from its parent. More precisely, \ikeyname{l}, and the related option
-% \ikeyname{s}, control the distance between the (node) anchors of a node and its parent. The
-% anchor of a node can be changed using option \ikeyname{anchor}: by default, nodes are anchored at
-% their base; see \cite[\S16.5.1]{tikzpgf2.10}.) In the example below, positions of the anchors are
-% shown by dots: observe that anchors of nodes with the same \ikeyname{l} are aligned and that the
-% distances between the anchors of the children and the parent are as specified in the
-% code.\footnote{Here are the definitons of the macros for measuring distances. Args: the x or y
-% distance between points \#2 and \#3 is measured; \#4 is where the distance line starts (given as an
-% absolute coordinate or an offset to \#2); \#5 are node options; the optional arg \#1 is the format of
-% label. (Lengths are printed using package \texttt{printlen}.)
-%
-% \vskip-2ex \box\codebox}
-% \begin{forestexample}[pos=t,ekeynames={for tree,tikz,l,anchor}]
-% \begin{forest} background tree,
-% for tree={draw,tikz={\fill[](.anchor)circle[radius=1pt];}}
-% [parent
-% [child 1, ~l~=10mm, ~anchor~=north west]
-% [child 2, ~l~=10mm, ~anchor~=south west]
-% [child 3, ~l~=12mm, ~anchor~=south]
-% [child 4, ~l~=12mm, ~anchor~=base east]
-% ]
-% \measureydistance[\texttt{l(child)}=#1]{(!2.anchor)}{(.anchor)}{(!1.anchor)+(-5mm,0)}{left}
-% \measureydistance[\texttt{l(child)}=#1]{(!3.anchor)}{(.anchor)}{(!4.anchor)+(5mm,0)}{right}
-% \measurexdistance[\texttt{s sep(parent)}=#1]{(!1.south east)}{(!2.south west)}{+(0,-5mm)}{below}
-% \measurexdistance[\texttt{s sep(parent)}=#1]{(!2.south east)}{(!3.south west)}{+(0,-5mm)}{below}
-% \measurexdistance[\texttt{s sep(parent)}=#1]{(!3.south east)}{(!4.south west)}{+(0,-8mm)}{below}
-% \end{forest}
-% \end{forestexample}
-%
-% Positioning the chilren in the s-dimension is the job and \emph{raison d'etre} of the package. As a
-% first approximation: the children are positioned so that the distance between them is at least the
-% value of option \ikeyname{s sep} (s-separation), which defaults to double \PGF;'s |inner_xsep| (and this
-% is 0.3333em by default). As you can see from the example above, s-separation is the distance
-% between the borders of the nodes, not their anchors!
-%
-% A fuller story is that \ikeyname{s sep} does not control the s-distance between two siblings, but rather
-% the distance between the subtrees rooted in the siblings. When the green and the yellow child of
-% the white node are s-positioned in the example below, the horizontal
-% distance between the green and the yellow subtree is computed. It can be seen with the naked eye
-% that the closest nodes of the subtrees are the TP and the DP with a red border. Thus, the children
-% of the root CP (top green DP and top yellow TP) are positioned so that the horizontal distance
-% between the red-bordered TP and DP equals \ikeyname{s sep}.
-% \begin{forestexample}[ekeynames={for tree,s sep}]
-% \begin{forest}
-% important/.style={name=#1,draw={red,thick}}
-% [CP, ~s sep~=3mm, for tree=draw
-% [DP, for tree={fill=green}
-% [D][NP[N][CP[C][TP,important=left
-% [T][vP[v][VP[DP][V'[V][DP]]]]]]]]
-% [TP,for tree={fill=yellow}
-% [T][vP[v][VP[DP,important=right][V'[V][DP]]]]]
-% ]
-% \measurexdistance[\texttt{s sep(root)}=#1]
-% {(left.north east)}{(right.north west)}{(.north)+(0,3mm)}{above}
-% \end{forest}
-% \end{forestexample}
-%
-% Note that \foRest; computes the same distances between nodes
-% regardless of whether the nodes are filled or not, or whether their
-% border is drawn or not. Filling the node or drawing its border does
-% not change its size. You can change the size by adjusting \TikZ;'s
-% |inner_sep| and |outer_sep| \citep[\S16.2.2]{tikzpgf2.10}, as shown
-% below:
-% \begin{forestexample}[ekeynames={for tree,s sep}]
-% \begin{forest}
-% important/.style={name=#1,draw={red,thick}}
-% [CP, s sep=3mm, for tree=draw
-% [DP, for tree={fill=green,~inner sep~=0}
-% [D][NP,important=left[N][CP[C][TP[T][vP[v]
-% [VP[DP][V'[V][DP]]]]]]]]
-% [TP,for tree={fill=yellow,~outer sep~=2pt}
-% [T,important=right][vP[v][VP[DP][V'[V][DP]]]]]
-% ]
-% \measurexdistance[\texttt{s sep(root)}=#1]
-% {(left.north east)}{(right.north west)}{(.north)+(0,3mm)}{above}
-% \end{forest}
-% \end{forestexample}
-% (This looks ugly!) Observe that having increased |outer sep| makes the edges stop touching
-% borders of the nodes. By (\PGF;'s) default, the |outer sep| is exactly half of the border
-% line width, so that the edges start and finish precisely at the border.
-%
-% Let's play a bit and change the \ikeyname{l} of the root of the yellow subtree. Below, we set the
-% vertical
-% distance of the yellow TP to its parent to 3\,cm: and the yellow submarine sinks diagonally \dots\@
-% Now, the closest nodes are the higher yellow DP and the green VP.
-% \begin{forestexample}[ekeynames={l,s sep,for tree}]
-% \begin{forest}
-% important/.style={name=#1,draw={red,thick}}
-% [CP, s sep=3mm, for tree=draw
-% [DP, for tree={fill=green}
-% [D][NP[N][CP[C][TP
-% [T][vP[v][VP,important=left[DP][V'[V][DP]]]]]]]]
-% [TP,for tree={fill=yellow}, l=3cm
-% [T][vP[v][VP[DP,important=right][V'[V][DP]]]]]
-% ]
-% \measurexdistance[\texttt{s sep(root)}=#1]
-% {(left.north east)}{(right.north west)}{(.north)+(0,3mm)}{above}
-% \end{forest}
-% \end{forestexample}
-%
-% Note that the yellow and green nodes are not vertically aligned anymore. The positioning algorithm
-% has no problem with that. But you, as a user, might have, so here's a neat trick. (This only works
-% in the ``normal'' circumstances, which are easier to see than describe.)
-% \begin{forestexample}[label=ex:l*,ekeynames={l,*,phantom,for tree}]
-% \begin{forest}
-% [CP, for tree=draw
-% [DP, for tree={fill=green},~l*~=3
-% [D][NP]]
-% [TP,for tree={fill=yellow}
-% [T][VP[DP][V'[V][DP]]]]
-% ]
-% \end{forest}
-% \end{forestexample}
-% We have changed DP's \ikeyname{l}'s value via ``augmented assignment'' known from
-% many programming languages: above, we have used |l*=3| to triple
-% \ekeyname{l}'s value; we could have also said |l+=5mm| or |l-=5mm| to
-% increase or decrease its value by 5\,mm, respectively. This
-% mechanism works for every numeric and dimensional option in \foRest;.
-%
-% Let's now play with option \ikeyname{s sep}.
-% \begin{forestexample}[ekeynames={s sep,l,*,for tree}]
-% \begin{forest}
-% [CP, for tree=draw, ~s sep~=0
-% [DP, for tree={fill=green},l*=3
-% [D][NP]]
-% [TP,for tree={fill=yellow}
-% [T][VP[DP][V'[V][DP]]]]
-% ]
-% \end{forest}
-% \end{forestexample}
-% Surprised? You shouldn't be. The value of \ikeyname{s sep} at a given node controls the s-distance
-% \emph{between the subtrees rooted in the children of that node}! It has no influence over the
-% internal geometry of these subtrees. In the above example, we have set |s_sep=0| only for the root
-% node, so the green and the yellow subtree are touching, although internally, their nodes are not.
-% Let's play a bit more. In the following example, we set the \ikeyname{s sep} to: $0$ at the last
-% branching level (level 3; the root is level 0), to 2\,mm at level 2, to 4\,mm at level 1 and to
-% 6\,mm at level 0.
-%
-% \begin{forestexample}[label=ex:spread-s,point={level},ekeynames={level,for tree,s sep}]
-% \begin{forest}
-% for tree={~s sep~=(3-level)*2mm}
-% [CP, for tree=draw
-% [DP, for tree={fill=green},l*=3
-% [D][NP]]
-% [TP,for tree={fill=yellow}
-% [T][VP[DP][V'[V][DP]]]]
-% ]
-% \measurexdistance{(!11.south east)}{(!12.south west)}{+(0,-5mm)}{below}
-% \path(md2)-|coordinate(md)(!221.south east);
-% \measurexdistance{(!221.south east)}{(!222.south west)}{(md)}{below}
-% \measurexdistance{(!21.north east)}{(!22.north west)}{+(0,2cm)}{above}
-% \measurexdistance{(!1.north east)}{(!221.north west)}{+(0,-2.4cm)}{below}
-% \end{forest}
-% \end{forestexample}
-% As we go up the tree, the nodes ``spread.'' At the lowest level, V and DP are touching. In the
-% third level, the \ikeyname{s sep} of level 2 applies, so DP and V' are 2\,mm apart. At the second
-% level we
-% have two pairs of nodes, D and NP, and T and TP: they are 4\,mm apart. Finally, at level 1, the
-% \ikeyname{s sep} of level 0 applies, so the green and yellow DP are 6\,mm apart. (Note that D and NP are
-% at level 2, not 4! Level is a matter of structure, not geometry.)
-%
-% As you have probably noticed, this example also demostrated that we can compute the value of an
-% option using an (arbitrarily complex) formula. This is thanks to \PGF;'s module |pgfmath|.
-% \FoRest; provides an interface to |pgfmath| by defining |pgfmath| functions for every node option,
-% and some other information, like the \ikeyname{level} we have used above, the number of children
-% \ikeyname{n children}, the sequential number of the child \ikeyname{n}, etc. For details, see
-% \S\ref{ref:pgfmath}.
-%
-% The final separation parameter is \ikeyname{l sep}. It determines the minimal
-% separation of a
-% node from its descendants. It the value of \ikeyname{l} is too small, then \emph{all} the
-% children (and thus their subtrees)
-% are pushed
-% away from the parent (by increasing their \ikeyname{l}s), so that the distance between the node's
-% and each child's subtree
-% boundary is at least \ikeyname{l sep}. The initial \ikeyname{l} can be too small for
-% two reasons: either
-% some child is too high, or the parent is too deep. The first problem is easier to see: we force the
-% situation using a bottom-aligned multiline node. (Multiline nodes can be easily created using |\\|
-% as a line-separator. However, you must first specify the horizontal alignment using option
-% \ikeyname{align} (see \S\ref{ref:node-appearance}).
-% Bottom vertical alignment is achieved by setting \ikeyname{base}|=|\ikeyname{bottom,aspect=base};
-% the default, unlike in \TikZ;, is \ikeyname{base}|=|\ikeyname{top,aspect=base}).
-% \begin{forestexample}[point={align,base},ekeynames={align,base}]
-% \begin{forest}
-% [parent
-% [child]
-% [child]
-% [a very\\tall\\child, align=center, base=bottom]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% The defaults for \ikeyname{l} and \ikeyname{l sep} are set so that they ``cooperate.''
-% What this
-% means and why it is necessary is a complex issue explained in \S\ref{sec:defaults}, which you will
-% hopefully never have to read \dots\@ You might be out of luck, however. What if you
-% needed to decrease the level distance? And nothing happened, like below on the left? Or, what if
-% you used lots of parenthesis in your nodes? And got a strange vertical misalignment, like below
-% on the right? Then rest assured that these (at least) are features not bugs and read
-% \S\ref{sec:defaults}.
-% \begin{forestexample}[pos=t,label=ex:misalignments,ekeynames={phantom,for children,fit,for,baseline,edge,for descendants,content,{id=.pgfmath,nfc}}]
-% \begin{forest}
-% [,phantom,for children={l sep=1ex,fit=band,
-% for=1{edge'=,l=0},baseline}
-% [{l+=5mm},for descendants/.pgfmath=content
-% [AdjP[AdvP][Adj'[Adj][PP]]]]
-% [default
-% [AdjP[AdvP][Adj'[Adj][PP]]]]
-% [{l-=5mm},for descendants/.pgfmath=content
-% [AdjP[AdvP][Adj'[Adj][PP]]]]
-% ]
-% \path (current bounding box.west)|-coordinate(l1)(!212.base);
-% \path (current bounding box.west)|-coordinate(l2)(!2121.base);
-% \path (current bounding box.east)|-coordinate(r1)(!212.base);
-% \path (current bounding box.east)|-coordinate(r2)(!2121.base);
-% \draw[dotted] (l1)--(r1) (l2)--(r2);
-% \end{forest}
-% \hspace{4cm}
-% \raisebox{0pt}[\height][0pt]{\begin{forest}
-% [x forest, baseline
-% [x[x[x[x[x[x[x[x[x[x[x[x[x]]]]]]]]]]]]]
-% [(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)]]]]]]]]]]]]]
-% ]
-% \end{forest}}
-% \end{forestexample}
-%
-% \subsubsection{The defaults, or the hairy details of vertical alignment}
-% \label{sec:defaults}
-%
-% In this section we discuss the default values of options controlling the l-alignment of the nodes.
-% The defaults are set with top-down trees in mind, so l-alignment is actually vertical alignment.
-% There are two desired effects of the defaults. First, the spacing between the nodes of a tree
-% should adjust to the current font size. Second, the nodes of a given level should be vertically
-% aligned (at the base), if possible.
-%
-% Let us start with the base alignment: \TikZ;'s default is to anchor the nodes at their center,
-% while \foRest;, given the usual content of nodes in linguistic representations, rather anchors them
-% at the base \cite[\S16.5.1]{tikzpgf2.10}. The difference is particularly clear for a ``phonological''
-% representation:
-% \begin{forestexample}[ekeynames={for tree,anchor}]
-% \begin{forest} for tree={anchor=center}
-% [maybe[m][a][y][b][e]]
-% \end{forest}\quad
-% \begin{forest}
-% [maybe[m][a][y][b][e]]
-% \end{forest}
-% \end{forestexample}
-% The following example shows that the vertical distance between nodes depends on the current font size.
-% \begin{forestexample}
-% \hbox{\small A small tree
-% \begin{forest} baseline
-% [VP[DP][V'[V][DP]]]
-% \end{forest}
-% \normalsize and
-% \large
-% a large tree
-% \begin{forest} baseline
-% [VP[DP][V'[V][DP]]]
-% \end{forest}}
-% \end{forestexample}
-% Furthermore, the distance between nodes also depends on the value of \PGF;'s |inner_sep| (which
-% also depends on the font size by default: it equals 0.3333\,em).
-% \[\ikeyname{l sep}=\mbox{height}(\mbox{strut})+\mbox{\texttt{inner ysep}}\]
-% The default value of \ikeyname{s sep} depends on |inner_xsep|: more precisely, it equals double
-% |inner_xsep|).
-% \begin{forestexample}[ekeynames={baseline,for tree}]
-% \begin{forest} baseline,for tree=draw
-% [VP[DP][V'[V][DP]]]
-% \end{forest}
-% \pgfkeys{/pgf/inner sep=0.6666em}
-% \begin{forest} baseline,for tree=draw
-% [VP[DP][V'[V][DP]]]
-% \end{forest}
-% \end{forestexample}
-% Now a hairy detail: the formula for the default \ikeyname{l}.
-% \[\ikeyname{l}=\ikeyname{l sep}+2\cdot\mbox{\texttt{outer ysep}}+\mbox{total
-% height}(\mbox{`dj'})\]
-%
-% To understand what this is all about we must first explain why it is necessary to set the default
-% \ikeyname{l} at all? Wouldn't it be enough to simply set \ikeyname{l sep} (leaving
-% \ikeyname{l} at 0)?
-% The problem is that not all letters have the same height and depth. A tree where the vertical
-% position of the nodes would be controlled solely by (a constant) \ikeyname{l sep} could
-% result in a ragged tree (although the height of the child--parent edges would be constant).
-% \begin{forestexample}[ekeynames={baseline,for children,no edge,name,for descendants,l}]
-% \begin{forest}
-% [default,baseline,for children={no edge}
-% [DP
-% [AdjP[Adj]]
-% [D'[D][NP,name=np]]]]
-% \path (current bounding box.west)|-coordinate(l)(np.base);
-% \path (current bounding box.east)|-coordinate(r)(np.base);
-% \draw[dotted] (l)--(r);
-% \end{forest}
-% \begin{forest}
-% [{l=0},baseline,for children={no edge}
-% [DP,for descendants={l=0}
-% [AdjP[Adj]]
-% [D'[D][NP,name=np]]]]
-% \path (current bounding box.west)|-coordinate(l)(np.base);
-% \path (current bounding box.east)|-coordinate(r)(np.base);
-% \draw[dotted] (l)--(r);
-% \end{forest}
-% \end{forestexample}
-% The vertical misalignment of Adj in the right tree is a consequence of the fact that letter j is the
-% only letter with non-zero depth in the tree. Since only \ikeyname{l sep} (which is constant
-% throughout the tree) controls the vertical positioning, Adj, child of Ad\emph{j}P, is pushed lower
-% than the other nodes on level 2. If the content of the nodes is variable enough (various heights
-% and depths), the cumulative effect can be quite strong, see the right tree of example
-% \ref{ex:misalignments}.
-%
-% Setting only a default \ikeyname{l sep} thus does not work well enough in general. The same
-% is true for the reverse possibility, setting a default \ikeyname{l} (and leaving \ikeyname{l sep} at 0). In the example below, the depth of the multiline node (anchored at the top
-% line) is such that the child--parent edges are just too short if the level distance is kept constant.
-% Sometimes, misalignment is much preferred \dots
-% \begin{forestexample}[ekeynames={align,{center,aspect=align},for tree,l sep}]
-% \mbox{}\begin{forest}
-% [default
-% [first child[a][b][c]]
-% [second child\\\scriptsize(a copy),
-% align=center[a][b][c]]
-% ]
-% \end{forest}\\
-% \begin{forest} for tree={l sep=0}
-% [{\texttt{l sep}=0}
-% [first child[a][b][c]]
-% [second child\\\scriptsize(a copy),
-% align=center[a][b][c]]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% Thus, the idea is to make \ikeyname{l} and \ikeyname{l sep} work as a team:
-% \ikeyname{l} prevents
-% misalignments, if possible, while \ikeyname{l sep} determines the minimal vertical distance
-% between levels. Each of the two options deals with a certain kind of a ``deviant'' node, i.e.\ a
-% node which is too high or too deep, or a node which is not high or deep enough, so we need to
-% postulate what a \emph{standard} node is, and synchronize them so that their effect on standard
-% nodes is the same.
-%
-% By default, \foRest; sets the standard node to be a node containing letters d and j. Linguistic
-% representations consist mainly of letters, and in the \TeX's default Computer Modern font, d is the
-% highest letter (not character!), and j the deepest, so this decision guarantees that trees
-% containing only letters will look nice. If the tree contains many parentheses, like the right
-% tree of example \ref{ex:misalignments}, the default will of course fail
-% and the standard node needs to be modified. But for many applications, including nodes with
-% indices, the default works.
-%
-% The standard node can be changed using macro \icmdname{forestStandardNode};
-% see \ref{ref:standard-node}.
-%
-% \subsection{Advanced option setting}
-% \label{sec:advanced-option-setting}
-%
-% We have already seen that the value of options can be manipulated: in \ref{ex:romannumeral} we have
-% converted numeric content from arabic into roman numerals using the \emph{wrapping} mechanism
-% |content=\romannumeral#1|; in \ref{ex:l*}, we have tripled the value of |l|
-% by saying |l*=3|. In this section, we will learn about the mechanisms for setting and
-% referring to option values offered by \foRest;.
-%
-% One other way to access an option value is using macro \icmdname{forestoption}. The macro takes a
-% single argument: an option name. (For details, see \S\ref{ref:options-and-keys}.) In the
-% following example, the node's child sequence number is appended to the existing content. (This is
-% therefore also an example of wrapping.)
-% \begin{forestexample}[label=ex:forestoption,ekeynames={phantom,delay,for descendants,content,n},ecmdnames={forestoption}]
-% \begin{forest}
-% [,phantom,delay={for descendants={
-% content=#1$_{~\forestoption~{n}}$}}
-% [c][o][u][n][t]]
-% \end{forest}
-% \end{forestexample}
-%
-% However, only options of the current node can be accessed using \icmdname{forestoption}. To
-% access option values of other nodes, \foRest;'s extensions to the \PGF;'s mathematical library
-% |pgfmath|, documented in \citep[part VI]{tikzpgf2.10}, must be used. To see |pgfmath| in action,
-% first take a look at the crazy tree on the title page, and observe how the nodes are
-% rotated: the value given to (\TikZ;) option \texttt{rotate} is a full-fledged |pgfmath| expression
-% yielding an integer
-% in the range from $-30$ to $30$. Similiarly, \ikeyname{l}\ikeyname{+} adds a random float
-% in the $[-5,5]$ range to the current value of \ikeyname{l}.
-%
-% Example \ref{ex:spread-s} demonstrated that information about
-% the node, like the node's level, can be accessed within |pgfmath| expressions. All
-% options are accessible in this way, i.e.\ every option has a corresponding |pgfmath| function.
-% For example, we could rotate the node based on its content:
-% \begin{forestexample}[ekeynames={delay,for tree,rotate,content}]
-% \begin{forest}
-% delay={for tree={~rotate=content~}}
-% [30[-10[5][0]][-90[180]][90[-60][90]]]
-% \end{forest}
-% \end{forestexample}
-%
-% All numeric, dimensional and boolean options of \foRest; automatically pass the given value
-% through |pgfmath|. If you need pass the value through |pgfmath|
-% for a string option, use the \ikeyname{id=.pgfmath,nfc} handler. The following example sets the node's
-% content to its child sequence number (the root has child sequence number 0).
-% \begin{forestexample}[ekeynames={delay,for tree,content,n,{id=.pgfmath,nfc}}]
-% \begin{forest}
-% delay={for tree={content/~.pgfmath~=int(n)}}
-% [[[][][]][[][]]]
-% \end{forest}
-% \end{forestexample}
-%
-% As mentioned above, using |pgfmath| it is possible to access options of non-current nodes. This
-% is achieved by providing the option function with a \imeta{relative node name}
-% (see~\S\ref{ref:relative-node-names}) argument.\footnote{The form without
-% parentheses \texttt{option\string_name} that we have been using until now to refer to an option of
-% the
-% current node is just a short-hand notation for \texttt{option\string_name()} --- note that in some
-% contexts, like preceding \texttt{+} or \texttt{-}, the short form does not work! (The same
-% seems to be true for all pgfmath functions with ``optional'' arguments.)} In the next example, we
-% rotate the node based on the content of its parent.
-% \begin{forestexample}[ekeynames={delay,for tree,rotate,content,u}]
-% \begin{forest}
-% delay={for descendants={rotate=content~("!u")~}}
-% [30[-10[5][0]][-90[180]][90[-60][90]]]
-% \end{forest}
-% \end{forestexample}
-% Note that the argument of the option function is surrounded by double quotation marks: this is
-% to prevent evaluation of the relative node name as a |pgfmath| function --- which it is not.
-%
-% Handlers \ikeyname{id=.wrap pgfmath arg,nfc} and \ikeyname{id=.wrap $n$ pgfmath args,nfc}
-% (for $n=2,\dots,8$) combine the wrapping mechanism with the |pgfmath| evaluation. The
-% idea is to compute (most often, just access option values) arguments using |pgfmath| and then
-% wrap them with the given macro. Below, this is used to include the number of parent's children in
-% the index.
-% \begin{forestexample}[ekeynames={phantom,delay,for descendants,content,n,n children,{id=.wrap 3 pgfmath args,nfc}}]
-% \begin{forest} [,phantom,delay={for descendants={
-% ~content/.wrap 3 pgfmath args=
-% {#1$_{#2/#3}$}{content}{n}{n_children("!u")}~}}
-% [c][o][u][n][t]]
-% \end{forest}
-% \end{forestexample}
-% Note the underscore |__| character in |n__children|: in |pgfmath| function names, spaces,
-% apostrophes and other non-alphanumeric characters from option names are all replaced by
-% underscores.
-%
-% As another example, let's make the numerals example \ref{ex:numerals-simple} a bit fancier.
-% The numeral type is read off the parent's content and used to construct the appropriate control
-% sequence (|\@arabic|, |\@roman| and |\@alph|). (Also, the numbers are not specified in content
-% anymore: we simply read the sequence number \ikeyname{n}. And, to save some horizontal space for the
-% code, each child of the root is pushed further down.)
-% \begin{forestexample}[ekeynames={delay,where ,level,content,n,for children,l,{id=.wrap 2 pgfmath args,nfc}}]
-% \begin{forest}
-% delay={where level={2}{~content/.wrap 2 pgfmath args=
-% {\csname @#1\endcsname{#2}}{content("!u")}{n}~}{}},
-% for children={l*=n},
-% [\LaTeX numerals,
-% [arabic[][][][]]
-% [roman[][][][]]
-% [alph[][][][]]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% The final way to use |pgfmath| expressions in \foRest;: \ikeyname{if} clauses. In
-% section~\ref{sec:options}, we have seen that every option has a corresponding \ikeyname{id={{if }}}|...|
-% (and \ikeyname{id={{where }}}|...|) option. However, these are just a matter of convenience. The full
-% power resides
-% in the general \ikeyname{if} option, which takes three arguments:
-% |if=|\meta{condition}\meta{true options}\meta{false options}, where \meta{condition} can be any
-% |pgfmath| expression
-% (non-zero means true, zero means false). (Once again, option \ikeyname{where} is an abbreviation
-% for \ikeyname{for tree}|={|\ikeyname{if}|=...}|.) In the following example, \ikeyname{if} option
-% is used to orient the
-% arrows from the smaller number to the greater, and to color the odd and even numbers differently.
-%
-% \forestset{random tree/.style n args={3}{^^A #1=max levels, #2=max children, #3=max content
-% content/.pgfmath={random(0,#3)},
-% if={#1>0}{repeat={random(0,#2)}{append={[,random tree={#1-1}{#2}{#3}]}}}{}}}
-% \begin{forestexample}[ekeynames={before typesetting nodes,for descendants,if,content,edge,edge label,for tree,if},point=if]
-% \pgfmathsetseed{314159}
-% \begin{forest}
-% before typesetting nodes={
-% for descendants={
-% if={content()>content("!u")}{edge=->}{
-% if={content()<content("!u")}{edge=<-}{}},
-% edge label/.wrap pgfmath arg=
-% {node[midway,above,sloped,font=\scriptsize]{+#1}}
-% {int(abs(content()-content("!u")))}
-% },
-% for tree={circle,if={mod(content(),2)==0}
-% {fill=yellow}{fill=green}}
-% }
-% [,random tree={3}{3}{100}]
-% \end{forest}
-% \end{forestexample}
-%
-% This exhausts the ways of using |pgfmath| in forest. We continue by introducing \emph{relative
-% node setting}: write \imeta{relative node name}|.|\meta{option}|=|\meta{value} to set the
-% value of \meta{option} of the specified relative node. Important: computation (pgfmath or wrap) of
-% the value is
-% done in the context of the original node. The following example defines style \keyname{move} which
-% not only draws an arrow from the source to the target, but also moves the content of the source
-% to the target (leaving a trace). Note the difference between |#1| and |##1|: |#1| is the argument
-% of the style \keyname{move}, i.e.\ the given node walk, while |##1| is the original option value
-% (in this case, content).
-% \begin{forestexample}[ekeynames={for tree,calign,tikz,delay,content}]
-% \begin{forest}
-% for tree={calign=fixed edge angles},
-% move/.style={
-% tikz={\draw[->] () to[out=south west,in=south] (#1);},
-% delay={~#1.content~={##1},content=$t$}},
-% [CP[][C'[C][\dots[,phantom][VP[DP][V'[V][DP,move=!r1]]]]]]
-% \end{forest}
-% \end{forestexample}
-%
-% In the following example, the content of the branching nodes is computed by \foRest;: a branching
-% node is a sum of its
-% children. Besides the use of the relative node setting, this example notably uses a recursive
-% style: for each child of the node, style \keyname{calc} first applies itself to the child and then
-% adds the result to the node; obviously, recursion is made to stop at terminal nodes.
-% \begin{forestexample}[ekeynames={id={{if }},n children,content,for children,delay,{id=.pgfmath,nfc}}]
-% \begin{forest}
-% calc/.style={if n children={0}{}{content=0,for children={
-% calc,~!u.content~/.pgfmath=int(content("!u")+content())}}},
-% delay=calc,
-% [[[3][4][5]][[3][9]][8][[[1][2][3]]]]
-% \end{forest}
-% \end{forestexample}
-%
-%
-% \subsection{Externalization}
-% \label{tut:externalization}
-%
-% \FoRest; can be quite slow, due to the slowness of both \PGF;/\TikZ; and its own computations.
-% However, using \emph{externalization}, the amount of time spent in \foRest; in everyday life can
-% be reduced dramatically. The idea is to typeset the trees only once, saving them in separate
-% PDFs, and then, on the subsequent compilations of the document, simply include these PDFs instead
-% of doing the lenghty tree-typesetting all over again.
-%
-% \FoRest;'s externalization mechanism is built on top of \TikZ;'s |external| library. It
-% enhances it by automatically detecting the code and context changes: the tree is recompiled if and
-% only if either the code in the \ikeyname{forest} environment or the context (arbitrary parameters; by
-% default, the parameters of the standard node) changes.
-%
-% To use \foRest;'s externalization facilities, say:\footnote{When you switch on
-% the externalization for a document containing many \keyname{forest} environments, the first
-% compilation can take quite a while, much more than the compilation without externalization. (For
-% example, more than ten minutes for the document you are reading!) Subsequent compilations,
-% however, will be very fast.}\ekeyname{external}
-% \begin{lstlisting}[point=external]
-% \usepackage[external]{forest}
-% ~\tikzexternalize~
-% \end{lstlisting}
-%
-% If your \ikeyname{forest} environment contains some macro, you will probably want the externalized
-% tree to be recompiled when the definition of the macro changes. To achieve this, use
-% \icmdname{forestset}|{|\ikeyname{id={external/depends on macro}}|=|\cmdname{macro}|}|. The effect is
-% local to the \TeX\ group.
-%
-% \TikZ;'s externalization library promises a |\label| inside the externalized graphics to work
-% out-of-box, while |\ref| inside the externalized graphics should work only if the externalization
-% is run manually or by |make| \citep[\S32.4.1]{tikzpgf2.10}. A bit surprisingly perhaps, the
-% situation is roughly reversed in \foRest;. |\ref| inside the externalized graphics will work
-% out-of-box. |\label| inside the externalized graphics will not work at all. Sorry. (The reason
-% is that \foRest; prepares the node content in advance, before merging it in the whole tree, which
-% is when \TikZ;'s externalization is used.)
-%
-% \subsection{Expansion control in the bracket parser}
-% \label{tut:bracket}
-%
-% By default, macros in the bracket encoding of a tree are not
-% expanded until nodes are being drawn --- this way, node
-% specification can contain formatting instructions, as illustrated in
-% section~\ref{sec:basic-usage}. However, sometimes it is useful to
-% expand macros while parsing the bracket representation, for example to
-% define tree templates such as the X-bar template, familiar
-% to generative grammarians:\footnote{Honestly, dynamic node creation might be a better way to do
-% this; see~\S\ref{ref:dynamic}.}
-% \begin{forestexample}[ecmdnames=bracketset,ekeynames={action character}]
-% ~\bracketset{action character=@}~
-% \def\XP#1#2#3{#1P[#2][#1'[#1][#3]]}
-% \begin{forest}
-% [~@~\XP T{DP}{~@~\XP V{DP}{DP}}]
-% \end{forest}
-% \end{forestexample}
-% In the above example, the |\XP| macro is preceded by the \emph{action character} |@|: as
-% the result, the token following the action character was expanded before the parsing proceeded.
-%
-% The action character is not hard coded into \foRest;. Actually, there is no action character by
-% default. (There's enough special characters in \foRest; already, anyway, and the situations where
-% controlling the expansion is preferable to using the pgfkeys interface are not numerous.) It is
-% defined at the top of the example by processing key \ikeyname{action character} in the
-% \ikeyname{id={/bracket},nfc} path; the definition is local to the \TeX\ group.
-%
-% Let us continue with the description of the expansion control facilities of the bracket parser.
-% The expandable token following the
-% action character is expanded only once. Thus, if one defined macro
-% |\VP| in terms of the general |\XP| and tried to use it in the same
-% fashion as |\XP| above, he would fail. The correct way is to follow
-% the action character by a braced expression: the braced expression
-% is fully expanded before bracket-parsing is resumed.
-% \begin{forestexample}[ecmdnames=bracketset,ekeynames=action character]
-% \bracketset{action character=@}
-% \def\XP#1#2#3{#1P[#2][#1'[#1][#3]]}
-% \def\VP#1#2{\XP V{#1}{#2}}
-% \begin{forest}
-% [@\XP T{DP}{~@{~\VP{DP}{DP}~}~}]
-% \end{forest}
-% \end{forestexample}
-%
-% In some applications, the need for macro expansion might be much
-% more common than the need to embed formatting instructions.
-% Therefore, the bracket parser provides commands |@+| and |@-|: |@+|
-% switches to full expansion mode --- all tokens are fully expanded
-% before parsing them; |@-| switches back to the default mode, where
-% nothing is automatically expanded.
-% \begin{forestexample}[ecmdnames=bracketset,ekeynames=action character]
-% \bracketset{action character=@}
-% \def\XP#1#2#3{#1P[#2][#1'[#1][#3]]}
-% \def\VP#1#2{\XP V{#1}{#2}}
-% \begin{forest} ~@+~
-% [\XP T{DP}{\VP{DP}{DP}}]
-% \end{forest}
-% \end{forestexample}
-%
-% All the action commands discussed above were dealing only with
-% \TeX's macro expansion. There is one final action command, |@@|,
-% which yields control to the user code and expects it to call
-% |\bracketResume| to resume parsing. This is useful to e.g.\
-% implement automatic node enumeration:
-% \begin{forestexample}[ecmdnames=bracketset,ekeynames={action character,phantom,for
-% ,n,baseline,delay,where ,level,content}]
-% \bracketset{action character=@}
-% \newcount\xcount
-% \def\x#1{~@@~\advance\xcount1
-% \edef\xtemp{[$\noexpand\times_{\the\xcount}$[#1]]}%
-% \expandafter\bracketResume\xtemp
-% }
-% \begin{forest}
-% phantom,
-% delay={where level=1{content={\strut #1}}{}}
-% ~@+~
-% [\x{f}\x{o}\x{r}\x{e}\x{s}\x{t}]
-% \end{forest}
-% \end{forestexample}
-% This example is fairly complex, so let's discuss how it works. |@+| switches to the full
-% expansion mode, so that macro |\x| can be easily run. The real magic hides in this macro. In
-% order to be able to advance the node counter |\xcount|, the macro takes control from \foRest; by
-% the |@@| command. Since we're already in control, we can use |\edef| to define the node content.
-% Finally, the |\xtemp| macro containing the node specification is expanded with the resume command
-% sticked in front of the expansion.
-%
-% \section{Reference}
-% \label{sec:reference}
-%
-% \subsection{Environments}
-% \label{ref:environments}
-%
-% \begin{syntax}
-% \item[,,environment]|\begin{|\rkeyname{forest}|}|\meta{tree}|\end{|\rkeyname{forest}|}|
-% \rcmdname[item]{Forest}[*]\marg{tree}
-%
-% The environment and the starless version of the macro introduce a group; the starred macro does
-% not, so the created nodes can be used afterwards. (Note that this will leave a lot of temporary
-% macros lying around. This shouldn't be a problem, however, since all of them reside in the
-% |\forest| namespace.)
-% \end{syntax}
-%
-% \subsection{The bracket representation}
-% \label{ref:bracket}
-%
-% A bracket representation of a tree is a token list with the following syntax:
-% \begin{eqnarray*}
-% \meta{tree}&=&\left[\meta{preamble}\right]\meta{node}\\
-% \meta{node}&=&\texttt{[}\left[\meta{content}\right]\left[\texttt{,}\meta{keylist}\right]
-% \left[\meta{children}\right]\texttt{]}\meta{afterthought}\\
-% \meta{preamble}&=&\meta{keylist}\\
-% \meta{keylist}&=&\meta{key--value}\left[,\meta{keylist}\right]\\
-% \meta{key--value}&=&\meta{key}\OR\meta{key}\texttt{=}\meta{value}\\
-% \meta{children}&=&\meta{node}\left[\meta{children}\right]
-% \end{eqnarray*}
-%
-% The actual input might be different, though, since expansion may have occurred during the input
-% reading. Expansion control sequences of \foRest;'s bracket parser are shown below.
-% \begin{center}
-% \begin{tabular}{ll}
-% \rstyle\meta{action character}\texttt{-}&no-expansion mode (default): nothing is expanded\\
-% \rstyle\meta{action character}\texttt{+}&expansion mode: everything is fully expanded\\
-% \rstyle\meta{action character}\texttt{}\meta{token}&expand \meta{token}\\
-% \rstyle\meta{action character}\texttt{}\meta{\TeX-group}&fully expand \meta{\TeX-group}\\
-% \rstyle\meta{action character}\meta{action character}&yield control;\\&upon finishing its job,
-% user's code should call \texttt{\string\bracketResume}
-% \end{tabular}
-% \end{center}
-%
-% \paragraph{Customization} To customize the bracket parser, call
-% \rcmdname{bracketset}\meta{keylist}, where the keys can be the following.
-% \begin{syntax}
-% \rkeyname[item={[}]{opening bracket}|=|\meta{character}
-% \rkeyname[item={{{{]}}}}]{closing bracket}|=|\meta{character}
-% \rkeyname[item=none]{action character}|=|\meta{character}
-% \end{syntax}
-%
-% By redefining the following two keys, the bracket parser can be used outside \foRest;.
-% \begin{syntax}
-% \rkeyname[item]{new node}|=|\meta{preamble}\meta{node specification}\meta{csname}.
-% Required semantics: create a new node given the preamble (in the case of a new
-% root node) and the node specification and store the new node's id into \meta{csname}.
-% \rkeyname[item]{set afterthought}|=|\meta{afterthought}\meta{node id}.
-% Required semantics: store the afterthought in the node with given id.
-% \end{syntax}
-%
-% \subsection{Options and keys}
-% \label{ref:option-types}
-% \label{ref:options-and-keys}
-%
-% The position and outlook of nodes is controlled by \emph{options}. Many options can be set for a
-% node. \emph{Each node's options are set independently of other nodes:} in particular, setting an
-% option of a node does \emph{not} set this option for the node's descendants.
-%
-% Options are set using \PGF;'s key management utility |pgfkeys| \citep[\S55]{tikzpgf2.10}. In the
-% bracket representation of a tree (see~\S\ref{ref:bracket}), each node can be given a
-% \meta{keylist}. After parsing the representation of the tree, the keylists of the
-% nodes are processed (recursively, in a depth-first, parent-first fashion). The preamble is
-% processed first, in
-% the context of the root node.\footnote{The value of a key (if it is given) is interpreted as one
-% or more arguments to the key command.
-% If there is only one argument, the situation is simple: the whole value is the argument. When the
-% key takes more than one argument, each argument should be enclosed in braces, unless, as usual in
-% \TeX, the argument is a single token. (The pairs of braces can be separated by whitespace.) An
-% argument should also be enclosed in braces if it contains a special character: a comma \texttt{,}, an
-% equal sign \texttt{=} or a bracket \texttt{[]}.}
-%
-% The node whose keylist is being processed is the \emph{current node}. During the processing of
-% the keylist, the current node can temporarily change. This mainly happens when propagators
-% (\S\ref{ref:propagators}) are being processed.
-%
-% Options can be set in various ways, depending on the option type (the types are listed below).
-% The most straightforward way is to use the key with the same name as the option:
-% \begin{syntax}
-% \item \meta{option}|=|\meta{value} Sets the value of \meta{option} of the current node to
-% \meta{value}.
-%
-% Notes: (i) Obviously, this does not work for read-only options. (ii) Some option types override
-% this behaviour.
-% \end{syntax}
-% It is also possible to set a non-current option:
-% \begin{syntax}
-% \item
-% \imeta{relative node name}|.|\meta{option}|=|\meta{value} Sets the value of
-% \meta{option} of the node specified by \meta{relative node name} to \meta{value}.
-%
-% Notes: \begin{inparaenum}[(i)]
-% \item\emph{\meta{value} is evaluated in the context of the current node.}
-% \item In general, the resolution of \meta{relative node name} depends on the
-% current node; see \S\ref{ref:relative-node-names}.
-% \item \meta{option} can also be an ``augmented operator'' (see below) or an additional
-% option-setting key defined for a specific option.
-% \end{inparaenum}
-% \end{syntax}
-% The option values can be not only set, but also read.
-% \begin{itemize}
-% \item Using macros \rcmdname{forestoption}|{|\meta{option}|}| and
-% \rcmdname{foresteoption}|{|\meta{option}|}|, options of the current node can be accessed in \TeX\
-% code. (``\TeX\ code'' includes \meta{value} expressions!).
-%
-% In the context of |\edef| or \PGF;'s handler |.expanded| \citep[\S55.4.6]{tikzpgf2.10},
-% \cmdname{forestoption} expands precisely to the token list of the option value, while
-% \cmdname{foresteoption} allows the option value to be expanded as well.
-% \item Using |pgfmath| functions defined by \foRest;, options of both current and non-current nodes
-% can be accessed. For details, see \S\ref{ref:pgfmath}.
-% \end{itemize}
-%
-% We continue with listing of all keys defined for every option. The set of defined keys and their
-% meanings depends on the option type. Option types and the type-specific keys can be found in the
-% list below. Common to all types are two simple conditionals, \ikeyname{id={{if }}}\meta{option}
-% and \ikeyname{id={{where }}}\meta{option}, which are
-% defined for every \meta{option}; for details, see \S\ref{ref:conditionals}.
-%
-% \begin{syntax}
-% \rmeta[item]{toks} contains \TeX's \meta{balanced text} \citep[275]{texbook}.
-%
-% A toks \meta{option} additionally defines the following keys:
-% \begin{syntax}
-% \item {\rstyle\meta{option}}\rkeyname{+}|=|\meta{toks} appends the given \meta{toks} to the
-% current value of the option.
-%
-% \item {\rstyle\meta{option}}\rkeyname{-}|=|\meta{toks} prepends the given \meta{toks} to the
-% current value of the option.
-%
-% \rkeyname[margin={},item]{id={{if in }}}{\rstyle\meta{option}}|=|\meta{toks}\meta{true
-% keylist}\meta{false keylist} checks if \meta{toks} occurs in the option value; if it does,
-% \meta{true keylist} are executed, otherwise \meta{false keylist}.
-%
-% \rkeyname[margin={},item]{id={{where in }}}\meta{option}|=|\meta{toks}\meta{true
-% keylist}\meta{false keylist} is a style equivalent to \ikeyname{for tree}|={|\keyname{if in }\meta{option}=\meta{toks}\meta{true keylist}\meta{false keylist}|}|: for every node in
-% the subtree rooted in the current node, \keyname{if in }\meta{option} is executed in
-% the context of that node.
-% \end{syntax}
-%
-% \rmeta[item]{autowrapped toks} is a subtype of \imeta{toks} and contains \TeX's \meta{balanced
-% text} \citep[275]{texbook}.
-%
-% {\rstyle\meta{option}}|=|\meta{toks} of an autowrapped \meta{option} is equivalent to
-% \meta{option}|/|\ikeyname{id=.wrap value,nfc}|=|\meta{toks} of a normal \meta{toks} option.
-%
-% Keyvals {\rstyle\meta{option}}\rkeyname{+}|=|\meta{toks} and
-% {\rstyle\meta{option}\rkeyname{-}}|=|\meta{toks} are equivalent to
-% \meta{option}\keyname{+}|/|\ikeyname{id=.wrap value,nfc}|=|\meta{toks} and
-% \meta{option}\keyname{-}|/|\ikeyname{id=.wrap value,nfc}|=|\meta{toks}, respectively. The
-% normal toks behaviour can be accessed via keys {\rstyle\meta{option}|'|},
-% {\rstyle\meta{option}|+'|} and {\rstyle\meta{option}|-'|}.
-%
-% \rmeta[item]{keylist} is a subtype of \imeta{toks} and contains a comma-separated list of
-% \meta{key}[|=|\meta{value}] pairs.
-%
-% Augmented operators {\rstyle\meta{option}\keyname{+}} and {\rstyle\meta{option}\keyname{-}} automatically
-% insert a comma before/after the appended/prepended material.
-%
-% {\rstyle\meta{option}}|=|\meta{keylist} of a keylist option is equivalent to
-% \meta{option}\keyname{+}|=|\meta{keylist}. In other words, keylists behave additively by
-% default. The rationale is that one usually wants to add keys to a keylist. The usual,
-% non-additive behaviour can be accessed by {\rstyle\meta{option}\rkeyname{'}}|=|\meta{keylist}.
-%
-% \rmeta[item]{dimen} contains a dimension.
-%
-% The value given to a dimension option is automatically evaluated by pgfmath. In other words:
-%
-% {\rstyle\meta{option}}|=|\meta{pgfmath} is an implicit \meta{option}|/.pgfmath=|\meta{pgfmath}.
-%
-% For a \meta{dimen} option \meta{option}, the following additional keys (``augmented
-% assignments'') are defined:
-% \begin{itemize}
-% \item {\rstyle\meta{option}\rkeyname{+}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()+|\meta{value}
-% \item {\rstyle\meta{option}\rkeyname{-}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()-|\meta{value}
-% \item {\rstyle\meta{option}\rkeyname{*}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()*|\meta{value}
-% \item {\rstyle\meta{option}\rkeyname{:}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()/|\meta{value}
-% \end{itemize}
-%
-% The evaluation of \meta{pgfmath} can be quite slow. There are two tricks to speed things up
-% \emph{if} the \meta{pgfmath} expression is simple, i.e.\ just a \TeX\ \meta{dimen}:
-% \begin{enumerate}
-% \item |pgfmath| evaluation of simple values can be sped up by prepending \ikeyname{+} to the value
-% \citep[\S62.1]{tikzpgf2.10};
-% \item use the key {\rstyle\meta{option}\rkeyname{'}}|=|\meta{value} to invoke a normal \TeX\ assignment.
-% \end{enumerate}
-%
-% The two above-mentioned speed-up tricks work for the augmented assignments as well. The keys
-% for the second, \TeX-only trick are: {\rstyle\meta{option}\rkeyname{'+}},
-% {\rstyle\meta{option}\rkeyname{'-}}, {\rstyle\meta{option}\rkeyname{'*}} and
-% {\rstyle\meta{option}\rkeyname{':}} --- note that for the latter two, the value should be an
-% integer.
-%
-% \rmeta[item]{count} contains an integer.
-%
-% The additional keys and their behaviour are the same as for the \meta{dimen} options.
-%
-% \rmeta[item]{boolean} contains $0$ (false) or $1$ (true).
-%
-% In the general case, the value given to a \meta{boolean} option is automatically
-% parsed by pgfmath (just as for \meta{count} and \meta{dimen}): if the computed value is
-% non-zero, $1$ is stored; otherwise, $0$ is stored. Note that |pgfmath| recognizes constants
-% |true| and |false|, so it is possible to write \meta{option}|=true| and
-% \meta{option}|=false|.
-%
-% If key \meta{option} is given no argument, pgfmath evaluation does not apply and a true value is
-% set. To quickly set a false value, use key {\rstyle\rkeyname{id={{not }}}\meta{option}} (with
-% no arguments).
-% \end{syntax}
-%
-% The following subsections are a complete reference to the part of the user interface residing in
-% the |pgfkeys|' path \keyname{/forest}. In plain language, they list all the options known to
-% \foRest;. More precisely, however, not only options are listed, but also other keys, such as
-% propagators, conditionals, etc.
-%
-% Before listing the keys, it is worth mentioning that users can also define their own keys. The
-% easiest way to do this is by using \emph{styles}. Styles are a feature of the |pgfkeys| package.
-% They are
-% named keylists, whose usage ranges from mere abbreviations through templates to devices
-% implementing recursion. To define a style, use \PGF;'s handler \keyname{.style}
-% \citep[\S55.4.4]{tikzpgf2.10}: \meta{style name}|/.style=|\meta{keylist}.
-%
-% Using the following keys, users can also declare their own options. The new options will behave
-% exactly like the predefined ones.
-% \begin{syntax}
-% \rkeyname[item]{declare toks}|=|\meta{option name}\meta{default value} Declares a \meta{toks} option.
-% \rkeyname[item]{declare autowrapped toks}|=|\meta{option name}\meta{default value} Declares an
-% \meta{autowrapped toks} option.
-% \rkeyname[item]{declare keylist}|=|\meta{option name}\meta{default value} Declares a
-% \meta{keylist} option.
-% \rkeyname[item]{declare dimen}|=|\meta{option name}\meta{default value} Declares a \meta{dimen} option.
-% \rkeyname[item]{declare count}|=|\meta{option name}\meta{default value} Declares a \meta{count} option.
-% \rkeyname[item]{declare boolean}|=|\meta{option name}\meta{default value} Declares a
-% \meta{boolean} option.
-% \end{syntax}
-%
-% The style definitions and option declarations given
-% among the other keys in the bracket specification are local to the current tree. To define
-% globally accessible styles and options (well, definitions are always local to the current \TeX\
-% group), use macro |\forestset| outside the
-% \ikeyname{forest} environment:\footnote{\cmdname{forestset}\meta{keylist} is equivalent to
-% \cmdname{pgfkeys}\texttt{\{}/forest,\meta{keylist}\texttt{\}}.}
-% \begin{syntax}
-% \rcmdname[item]{forestset}\marg{keylist}
-%
-% Execute \meta{keylist} with the default path set to \keyname{/forest}.
-% \begin{advise}
-% \item Usually, no current node is set when this macro is called. Thus, executing node options
-% in this place will \emph{fail}. However, if you have some nodes lying around, you can use
-% propagator \ikeyname{for name}|=|\meta{node name} to set the node with the given name as
-% current.
-% \end{advise}
-% \end{syntax}
-%
-% \subsubsection{Node appearance}
-% \label{ref:node-appearance}
-%
-% The following options apply at stage \ikeyname{typesetting nodes}. Changing them
-% afterwards has no effect in the normal course of events.
-%
-% \begin{syntax}
-% \rkeyname[item={{{{{}}}}}]{align}|=|\keyname{left,aspect=align}\OR\keyname{center,aspect=align}\OR\keyname{right,aspect=align}\OR\meta{toks: tabular header}
-%
-% Creates a left/center/right-aligned multiline node, or a tabular node. In the
-% \ikeyname{content} option, the lines of the node should separated by |\\| and the columns (if
-% any) by |&|, as usual.
-%
-% The vertical alignment of the multiline/tabular node can be specified by option \ikeyname{base}.
-%
-% \begin{forestexample}[ekeynames={l sep,align,base}]
-% \begin{forest} l sep+=2ex
-% [special value&actual value\\\hline
-% \rkeyname{left,aspect=align}&||\texttt{@\{\}l@\{\}}\\
-% \rkeyname{center,aspect=align}&||\texttt{@\{\}c@\{\}}\\
-% \rkeyname{right,aspect=align}&||\texttt{@\{\}r@\{\}}\\
-% ,~align~=ll,draw
-% [top base\\right aligned, ~align~=right,~base~=top]
-% [left aligned\\bottom base, ~align~=left,~base~=bottom]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% Internally, setting this option has two effects:
-% \begin{enumerate}
-% \item The option value (a |tabular| environment header specification) is set. The special
-% values \keyname{left}, \keyname{center} and \keyname{right} invoke styles setting the actual
-% header to the value shown in the above example.
-% \begin{advise}
-% \item If you know that the \keyname{align} was set with a special value, you can easily check
-% the value using \ikeyname{id={{if in }}}\ikeyname{align}.
-% \end{advise}
-% \item Option \ikeyname{content format} is set to the following value:
-% \begin{lstlisting}
-% \noexpand\begin{tabular}[\forestoption{base}]{\forestoption{align}}%
-% \forestoption{content}%
-% \noexpand\end{tabular}%
-% \end{lstlisting}
-% As you can see, it is this value that determines that options \keyname{base}, \keyname{align} and
-% \keyname{content} specify the vertical alignment, header and content of the table.
-% \end{enumerate}
-%
-% \rkeyname[item=t]{base}|=|\meta{toks: vertical alignment}
-%
-% This option controls the vertical alignment of multiline (and in general, \texttt{tabular}) nodes
-% created with \ikeyname{align}. Its value becomes the optional argument to the \texttt{tabular}
-% environment. Thus, sensible values are \rkeyname{t,aspect=base} (the top line of the table will
-% be the baseline) and \rkeyname{b,aspect=base} (the bottom line of the table will be the baseline).
-% Note that this will only have effect if the node is anchored on a baseline, like in the default
-% case of \ikeyname{anchor}|=base|.
-%
-% For readability, you can use \rkeyname{top,aspect=base} and \rkeyname{bottom,aspect=base} instead
-% of \keyname{t} and \keyname{b}. (\keyname{top} and \keyname{bottom} are still stored as
-% \keyname{t} and \keyname{b}.)
-%
-% \rkeyname[item={{{{{}}}}}]{content}|=|\meta{autowrapped toks} The content of the node.
-%
-% Normally, the value of option \keyname{content} is given implicitely by virtue of the special
-% (initial) position of content in the bracket representation (see~\S\ref{ref:bracket}). However,
-% the option also be set explicitely, as any other option.
-%
-% \begin{forestexample}[ekeynames={for tree,id={{if }},n,n'},point={content,delay},ekeynames={content,delay}]
-% \begin{forest}
-% delay={for tree={
-% if n=1{content=L}
-% {if n'=1{content=R}
-% {content=C}}}}
-% [[[][][]][[][][]]]
-% \end{forest}
-% \end{forestexample}
-% Note that the execution of the \keyname{content} option should usually be delayed: otherwise, the
-% implicitely given content (in the example below, the empty string) will override the explicitely
-% given content.
-%
-% \begin{forestexample}[ekeynames={for tree,id={{if }},n,n',content},point={content}]
-% \begin{forest}
-% for tree={
-% if n=1{content=L}
-% {if n'=1{content=R}
-% {content=C}}}
-% [[[][][]][[][][]]]
-% \end{forest}
-% \end{forestexample}
-%
-% \rkeyname[item=\forestoption{content}]{content format}|=|\meta{toks}
-%
-% When typesetting the node under the default conditions (see option \ikeyname{node format}), the
-% value of this option is passed to the \TikZ; \texttt{node} operation as its \meta{text} argument
-% \citep[\S16.2]{tikzpgf2.10}. The default value of the option simply puts the content in the
-% node.
-%
-% This is a fairly low level option, but sometimes you might still want to change its value. If
-% you do so, take care of what is expanded when. For details, read the documentation of option
-% \ikeyname{node format} and macros \icmdname{forestoption} and \icmdname{foresteoption}; for an
-% example, see option \ikeyname{align}.
-%
-% \rkeyname[item]{math content} The content of the node will be typeset in a math environment.
-%
-% This style is just an abbreviation for \ikeyname{content
-% format}|={\ensuremath{\forestoption{content}}}|.
-%
-% \rkeyname[item]{node format}|=|\meta{toks}
-% \hfill|\noexpand\node|\\
-% \mbox{}\hfill|[\forestoption{node options},anchor=\forestoption{anchor}]|\\
-% \mbox{}\hfill|(\forestoption{name}){\foresteoption{content format}};|
-%
-% The node is typeset by executing the expansion of this option's value in a |tikzpicture|
-% environment.
-%
-% Important: the value of this option is first expanded using |\edef| and only then executed. Note
-% that in its default value, \ikeyname{content format} is fully expanded using
-% \icmdname{foresteoption}: this is necessary for complex content formats, such as |tabular|
-% environments.
-%
-% This is a low level option. Ideally, there should be no need to change its value. If you do,
-% note that the \TikZ; node you create should be named using the value of option \ikeyname{name};
-% otherwise, parent--child edges can't be drawn, see option \ikeyname{edge path}.
-%
-% \rkeyname[item={{{{{}}}}}]{node options}|=|\meta{keylist}
-%
-% When the node is being typeset under the default conditions (see option \ikeyname{node format}),
-% the content of this option is passed to \TikZ; as options to the
-% \TikZ; |node| operation \citep[\S16]{tikzpgf2.10}.
-%
-% This option is rarely manipulated manually: almost all options unknown to \foRest; are
-% automatically appended to \keyname{node options}. Exceptions are (i) \ikeyname{label} and
-% \ikeyname{pin}, which require special attention in order to work; and (ii) \ikeyname{anchor},
-% which is saved in order to retain the information about the selected anchor.
-%
-% \begin{forestexample}[ekeynames={for descendants,anchor,child anchor,parent anchor,grow,l sep,for tree,where,delay,content,node options,rotate,{id=.pgfmath,nfc}}]
-% \begin{forest}
-% for descendants={anchor=east,child anchor=east},
-% grow=west,anchor=north,parent anchor=north,
-% l sep=1cm,
-% for tree={~fill=yellow~},where={n()>3}{~draw=red~}{},
-% delay={for tree={content/.pgfmath=~node_options~}}
-% [root,rotate=90,
-% [,~fill=white~]
-% [,~node options'~]
-% []
-% []
-% [,~node options~={~ellipse~}]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-%
-%
-% \rkeyname[item=false]{phantom}|=|\meta{boolean}
-%
-% A phantom node and its surrounding edges are taken into account when packing, but not
-% drawn. (This option applies in stage \ikeyname{draw tree}.)
-% \begin{forestexample}[point=phantom,ekeynames=phantom]
-% \begin{forest}
-% [VP[DP][V',phantom[V][DP]]]
-% \end{forest}
-% \end{forestexample}
-%
-% \end{syntax}
-%
-%
-%
-% \subsubsection{Node position}
-% \label{ref:ref-node-position}
-%
-% Most of the following options apply at stage \ikeyname{pack}. Changing them
-% afterwards has no effect in the normal course of events. (Options \ikeyname{l},
-% \ikeyname{s}, \ikeyname{x}, \ikeyname{y} and \ikeyname{anchor} are exceptions; see their documentation for
-% details).
-%
-% \begin{syntax}
-%
-% \rkeyname[item=base]{anchor}|=|\meta{toks: \TikZ; anchor name}
-%
-% This is essentially a \TikZ; option \citep[see][\S16.5.1]{tikzpgf2.10} --- it is passed to
-% \TikZ; as a node option when the node is typeset (this option thus applies in stage
-% \ikeyname{typeset nodes}) --- but it is also saved by \foRest;.
-%
-% The effect of this option is only observable when a node has a sibling: the anchors of all
-% siblings are s-aligned (if their \ikeyname{l}s have not been modified after packing).
-%
-% In the \TikZ; code, you can refer to the node's anchor using the generic anchor
-% \rkeyname{anchor,aspect=generic anchor}.
-%
-% \rkeyname[item=center]{calign}|=|\alternative{child,child edge,midpoint,edge midpoint,fixed
-% angles,fixed edge angles}\\\alternative{first,last,center}.
-%
-% The packing algorithm positions the children so that they don't overlap, effectively computing
-% the minimal distances between the node anchors of the children. This option (\keyname{calign}
-% stands for child alignment) specifies how the children are positioned
-% with respect to the parent (while respecting the above-mentioned minimal distances).
-%
-% The child alignment methods refer to the primary and the secondary child, and to the primary and
-% the secondary angle. These are set using the keys described just after \keyname{calign}.
-%
-% \let\outerleftmargin\leftmargin
-% \begin{syntax}
-% \item\keyname{calign}|=|\rkeyname{child,aspect=calign} s-aligns the node anchors of the parent and
-% the primary child.
-% \item\keyname{calign}|=|\rkeyname{child edge,aspect=calign} s-aligns the parent anchor of the parent
-% and the child anchor of the primary child.
-% \item \keyname{calign}|=|\rkeyname{first,aspect=calign} is an abbreviation for
-% |calign=child,calign_child=1|.
-% \item \keyname{calign}|=|\rkeyname{last,aspect=calign} is an abbreviation for
-% |calign=child,calign_child=-1|.
-% \item\keyname{calign}|=|\rkeyname{midpoint,aspect=calign} s-aligns the parent's node anchor and the
-% midpoint between the primary and the secondary child's node anchor.
-% \item\keyname{calign}|=|\rkeyname{edge midpoint,aspect=calign} s-aligns the parent's parent anchor
-% and the midpoint between the primary and the secondary child's child anchor.
-% \item \keyname{calign}|=|\rkeyname{center,aspect=calign} is an abbreviation for\\
-% |calign=midpoint,| |calign_primary_child=1,| |calign_secondary_child=-1|.
-% \begin{forestexample}
-% \begin{forest}
-% [center,calign=center[1]
-% [first,calign=first[A][B][C]][3][4][5][6]
-% [last,calign=last[A][B][C]][8]]
-% \end{forest}
-% \end{forestexample}
-% \item\keyname{calign}|=|\rkeyname{fixed angles,aspect=calign}: The angle between the direction of
-% growth at the current node (specified by option \ikeyname{grow}) and the line through the node
-% anchors of the parent and the primary/secondary child will equal the primary/secondary angle.
-%
-% To achieve this, the block of children might be spread or further distanced from the parent.
-% \item\keyname{calign}|=|\rkeyname{fixed edge angles,aspect=calign}: The angle between the direction of
-% growth at the current node (specified by option \ikeyname{grow}) and the line through the
-% parent's parent anchor and the primary/secondary child's child anchor will equal the
-% primary/secondary angle.
-%
-% To achieve this, the block of children might be spread or further distanced from the parent.
-% \begin{forestexample}[point=calign,ekeynames={calign,fixed edge angles,calign primary angle,calign secondary angle,for tree,l}]
-% \begin{forest}
-% calign=fixed edge angles,
-% calign primary angle=-30,calign secondary angle=60,
-% for tree={l=2cm}
-% [CP[C][TP]]
-% \draw[dotted] (!1) -| coordinate(p) () (!2) -| ();
-% \path ()--(p) node[pos=0.4,left,inner sep=1pt]{-30};
-% \path ()--(p) node[pos=0.1,right,inner sep=1pt]{60};
-% \end{forest}
-% \end{forestexample}
-% \end{syntax}
-% \rkeyname[item]{calign child}|=|\meta{count} is an abbreviation for \ikeyname{calign primary
-% child}|=|\meta{count}.
-% \rkeyname[item=1]{calign primary child}|=|\meta{count} Sets the primary child.
-% (See \ikeyname{calign}.)
-%
-% \meta{count} is the child's sequence number. Negative numbers start counting at the last child.
-% \rkeyname[item=-1]{calign secondary child}|=|\meta{count} Sets the secondary child.
-% (See \ikeyname{calign}.)
-%
-% \meta{count} is the child's sequence number. Negative numbers start counting at the last child.
-% \rkeyname[item]{calign angle}|=|\meta{count} is an abbreviation for \ikeyname{calign primary
-% angle}|=-|\meta{count}, \ikeyname{calign secondary angle}|=|\meta{count}.
-% \rkeyname[item=-35]{calign primary angle}|=|\meta{count} Sets the primary angle.
-% (See \ikeyname{calign}.)
-% \rkeyname[item=35]{calign secondary angle}|=|\meta{count} Sets the secondary angle.
-% (See \ikeyname{calign}.)
-% \rkeyname[item]{calign with current} s-aligns the node anchors of the current node and its
-% parent. This key is an abbreviation for:\\
-% |for_parent/.wrap_pgfmath_arg={calign=child,calign primary child=##1}{n}|.
-% \rkeyname[item]{calign with current edge} s-aligns the child anchor of the current node and the
-% parent anchor of its parent. This key is an abbreviation for:\\
-% |for_parent/.wrap_pgfmath_arg={calign=child edge,calign primary child=##1}{n}|.
-%
-% \rkeyname[item=tight]{fit}|=|\alternative{tight,rectangle,band}
-%
-% \begin{forestexample}[pos=x,samplebox=\treebox,codebox=\codebox,basicstyle=\footnotesize\ttfamily]
-% \makeatletter\tikzset{use path/.code={\tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}
-% \appto\tikz@preactions{\let\tikz@actions@path#1}}}\makeatother
-% \forestset{show boundary/.style={
-% before drawing tree={get min s tree boundary=\minboundary, get max s tree boundary=\maxboundary},
-% tikz+={\draw[red,use path=\minboundary]; \draw[red,use path=\maxboundary];}}}
-% \end{forestexample}
-% \input{\jobname.tmp}
-%
-% This option sets the type of the (s-)boundary that will be computed for the subtree rooted in the
-% node, thereby determining how it will be packed into the subtree rooted in the node's parent.
-% There are three choices:\footnote{Below is the definition of style \keyname{show boundary}. The
-% \keyname{use path} trick is adjusted from \TeX\ Stackexchange question
-% \href{http://tex.stackexchange.com/questions/26382/calling-a-previously-named-path-in-tikz}{Calling
-% a previously named path in tikz}.
-%
-% \vskip-2ex \box\codebox}
-% \begin{itemize}
-% \item\keyname{fit}|=|\rkeyname{tight,aspect=fit}: an exact boundary of the node's subtree is computed,
-% resulting in a compactly packed tree. Below, the boundary of subtree L is drawn.
-% \begin{forestexample}[point={fit,tight},ekeynames={fit,{tight,aspect=fit},delay,for tree,name,content,{id=.pgfmath,nfc}}]
-% \begin{forest}
-% delay={for tree={name/.pgfmath=content}}
-% [root
-% [L,fit=tight, % default
-% show boundary
-% [L1][L2][L3]]
-% [R]
-% ]
-% \end{forest}
-% \end{forestexample}
-% \makeatletter\tikzset{use path/.code={%
-% \tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}%
-% \appto\tikz@preactions{\let\tikz@actions@path#1}%
-% }}\makeatother
-% \item\keyname{fit}|=|\rkeyname{rectangle,aspect=fit}: puts the node's subtree in a rectangle and effectively
-% packs this rectangle; the resulting tree will usually be wider.
-% \begin{forestexample}[point={fit,rectangle},ekeynames={fit,{rectangle,aspect=fit},delay,for tree,name,content,{id=.pgfmath,nfc}}]
-% \begin{forest}
-% delay={for tree={name/.pgfmath=content}}
-% [root
-% [L,fit=rectangle,
-% show boundary
-% [L1][L2][L3]]
-% [R]
-% ]
-% \end{forest}
-% \end{forestexample}
-% \item\keyname{fit}|=|\rkeyname{band,aspect=fit}: puts the node's subtree in a rectangle of ``infinite
-% depth'': the space under the node and its descendants will be kept clear.
-% \begin{forestexample}[point={fit,band},ekeynames={fit,{band,aspect=fit},delay,for tree,name,content,{id=.pgfmath,nfc}}]
-% \begin{forest}
-% delay={for tree={name/.pgfmath=content}}
-% [root
-% [L[L1][L2][L3]]
-% [C,fit=band]
-% [R[R1][R2][R3]]
-% ]
-% \draw[thin,red]
-% (C.south west)--(C.north west)
-% (C.north east)--(C.south east);
-% \draw[thin,red,dotted]
-% (C.south west)--+(0,-1)
-% (C.south east)--+(0,-1);
-% \end{forest}
-% \end{forestexample}
-% \end{itemize}
-%
-% \rkeyname[item=270]{grow}|=|\meta{count} The direction of the tree's growth at the node.
-%
-% The growth direction is understood as in \TikZ;'s tree library \citep[\S18.5.2]{tikzpgf2.10}
-% when using the default growth method: the (node anchor's of the) children of the node are placed
-% on a line orthogonal to the current direction of growth. (The final result might be different,
-% however, if \ikeyname{l} is changed after packing or if some child undergoes tier alignment.)
-%
-% This option is essentially numeric (|pgfmath| function \keyname{grow} will always return an
-% integer), but there are some twists. The growth direction can be specified either numerically
-% or as a compass direction (|east|, |north east|, \dots). Furthermore, like in \TikZ;, setting
-% the growth direction using key \keyname{grow} additionally sets the value of option
-% \ikeyname{reversed} to |false|, while setting it with \rkeyname{grow'} sets it to |true|; to
-% change the growth direction without influencing \ikeyname{reversed}, use key \rkeyname{grow''}.
-%
-% Between stages \ikeyname{pack} and \ikeyname{compute xy}, the value of \keyname{grow} should not
-% be changed.
-%
-% \begin{forestexample}[ekeynames={delay,id={{where in }},content,for ,current,grow,grow',grow'',{id=.pgfmath,nfc}}]
-% \begin{forest}
-% delay={where in content={~grow~}{
-% for current/.pgfmath=content,
-% content=\texttt{#1}
-% }{}
-% }
-% [{~grow~=south}
-% [{~grow'~=west}[1][2][3]
-% [{~grow''~=90}[1][2][3]]]
-% [2][3][4]
-% [{~grow~=east}[1][2][3]
-% [{~grow''~=90}[1][2][3]]]]
-% \end{forest}
-% \end{forestexample}
-%
-% \rkeyname[item=false]{ignore}|=|\meta{boolean}
-%
-% If this option is set, the packing mechanism ignores the node, i.e.\ it pretends that the node has
-% no boundary. Note: this only applies to the node, not to the tree.
-%
-% Maybe someone will even find this option useful for some reason \dots
-%
-% \rkeyname[item=false]{ignore edge}|=|\meta{boolean}
-%
-% If this option is set, the packing mechanism ignores the edge from the node to the parent, i.e.\
-% nodes and other edges can overlap it. (See \S\ref{sec:bugs} for some problematic situations.)
-%
-% \begin{forestexample}[ekeynames={ignore edge,l,*}]
-% \begin{forest}
-% [A[B[B][B][B][B]][C
-% [\texttt{not ignore edge},l*=2]]]
-% \end{forest}
-% \begin{forest}
-% [A[B[B][B][B][B]][C
-% [\texttt{ignore edge},l*=2,~ignore edge~]]]
-% \end{forest}
-% \end{forestexample}
-%
-% \rkeyname[item]{l}|=|\meta{dimen} The l-position of the node, in the parent's ls-coordinate system. (The
-% origin of a node's ls-coordinate system is at its (node) anchor. The l-axis points in the
-% direction of the tree growth at the node, which is given by option \ikeyname{grow}. The s-axis is
-% orthogonal to the l-axis; the positive side is in the counter-clockwise direction from |l| axis.)
-%
-% The initial value of \keyname{l} is set from the standard node. By default, it equals:
-% \[\ikeyname{l sep}+2\cdot\mbox{\texttt{outer ysep}}+\mbox{total
-% height(standard node)}\]
-%
-% The value of \keyname{l} can be changed at any point, with different effects.
-% \begin{itemize}
-% \item The value of \keyname{l} at the beginning of stage \ikeyname{pack} determines the minimal
-% l-distance between the anchors of the node and its parent. Thus, changing \keyname{l} before
-% packing will influence this process. (During packing, \keyname{l} can be increased due to
-% parent's \ikeyname{l sep}, tier alignment, or \ikeyname{calign} method \keyname{fixed (edge)
-% angles}\ekeyname{fixed angles},\ekeyname{fixed edge angles}.)
-%
-% \item Changing \keyname{l} after packing but before stage \ikeyname{compute xy} will result in a
-% manual adjustment of the computed position. (The augmented operators can be useful here.)
-%
-% \item Changing \keyname{l} after the absolute positions have been computed has no effect in the
-% normal course of events.
-% \end{itemize}
-%
-% \rkeyname[item]{l sep}|=|\meta{dimen} The minimal l-distance between the node and its
-% descendants.
-%
-% This option determines the l-distance between the \emph{boundaries} of the node and its descendants,
-% not node anchors. The final effect is that there will be a \keyname{l sep} wide band,
-% in the l-dimension, between the node and all its descendants.
-%
-% The initial value of \keyname{l sep} is set from the standard node and equals
-% \[\mbox{height}(\mbox{strut})+\mbox{\texttt{inner ysep}}\]
-%
-% Note that despite the similar name, the semantics of \keyname{l sep} and \keyname{s sep} are
-% quite different.
-%
-% \rkeyname[item=false]{reversed}|=|\meta{boolean}
-%
-% If |false|, the children are positioned around the node in the counter-clockwise direction; if
-% |true|, in the clockwise direction. See also \ikeyname{grow}.
-%
-% \rkeyname[item]{s}|=|\meta{dimen} The s-position of the node, in the parent's ls-coordinate system.
-% (The origin of a node's ls-coordinate system is at its (node) anchor. The l-axis points in the
-% direction of the tree growth at the node, which is given by option \ikeyname{grow}. The s-axis is
-% orthogonal to the l-axis; the positive side is in the counter-clockwise direction from |l| axis.)
-%
-% The value of \keyname{s} is computed by the packing mechanism. Any value given before packing is
-% overridden. In short, it only makes sense to (inspect and) change this option after stage
-% \ikeyname{pack}, which can be useful for manual corrections, like below. (B is closer to A than C
-% because packing proceeds from the first to the last child --- the position of B would be the same
-% if there was no C.) Changing the value of \keyname{s} after stage \ikeyname{compute xy} has no
-% effect.
-% \begin{forestexample}[point=s,ekeynames={before computing xy,s}]
-% \begin{minipage}{.5\linewidth}
-% \begin{forest}
-% [no manual correction of B
-% [A[1][2][3][4]]
-% [B]
-% [C[1][2][3][4]]
-% ]
-% \end{forest}
-%
-% \begin{forest}
-% [manual correction of B
-% [A[1][2][3][4]]
-% [B,before computing xy={s=(s("!p")+s("!n"))/2}]
-% [C[1][2][3][4]]
-% ]
-% \end{forest}
-% \end{minipage}
-% \end{forestexample}
-%
-% \rkeyname[item]{s sep}|=|\meta{dimen}
-%
-% The subtrees rooted in the node's children will be kept at least \keyname{s sep} apart in the
-% s-dimension. Note that \keyname{s sep} is about the minimal distance between node
-% \emph{boundaries}, not node anchors.
-%
-% The initial value of \keyname{s sep} is set from the standard node and equals
-% $2\cdot\mbox{\texttt{inner xsep}}$.
-%
-% Note that despite the similar name, the semantics of \keyname{s sep} and \keyname{l sep} are
-% quite different.
-%
-% \rkeyname[item={{{{{}}}}}]{tier}|=|\meta{toks}
-%
-% Setting this option to something non-empty ``puts a node on a tier.'' All the nodes on the same
-% tier are aligned in the l-dimension.
-%
-% Tier alignment across changes in growth direction is impossible. In the case of incompatible
-% options, \foRest; will yield an error.
-%
-% Tier alignment also does not work well with \ikeyname{calign}|=|\keyname{fixed (edge)
-% angles}\ekeyname{fixed angles}\ekeyname{fixed edge angles}, because these child alignment methods
-% may change the l-position of the children. When this might happen, \foRest; will yield a warning.
-%
-% \rkeyname[item]{x}=\meta{dimen}
-% \vspace{-\parskip}
-% \rkeyname[item]{y}=\meta{dimen}
-%
-% \keyname{x} and \keyname{y} are the coordinates of the node in the ``normal'' (paper) coordinate
-% system, relative to the root of the tree that is being drawn. So, essentially, they are absolute
-% coordinates.
-%
-% The values of \keyname{x} and \keyname{y} are computed in stage \ikeyname{compute xy}. It only
-% makes sense to inspect and change them (for manual adjustments) afterwards (normally, in the
-% \ikeyname{before drawing tree} hook, see \S\ref{ref:stages}.)
-% \begin{forestexample}[label=ex:adjustxy,ekeynames={y,-,grow',l,for tree,before drawing tree}]
-% \begin{forest}
-% for tree={grow'=45,l=1.5cm}
-% [A[B][C][D,before drawing tree={~y-~=4mm}[1][2][3][4][5]][E][F]]
-% \end{forest}
-% \end{forestexample}
-%
-% \end{syntax}
-%
-% \subsubsection{Edges}
-% \label{ref:ref-edge}
-%
-% These options determine the shape and position of the edge from a node to its parent. They apply
-% at stage \ikeyname{draw tree}.
-%
-% \begin{syntax}
-% \rkeyname[item={{{{{}}}}}]{child anchor}|=|\meta{toks} See \ikeyname{parent anchor}.
-%
-% \rkeyname[item=draw]{edge}|=|\meta{keylist}
-%
-% When \ikeyname{edge path} has its default value, the value of this option is passed as options to
-% the \TikZ; |\path| expression used to draw the edge between the node and its parent.
-%
-% Also see key \ikeyname{no edge}.
-%
-% \begin{forestexample}[point=edge,ekeynames={edge,no edge,for tree,grow',l,anchor,child anchor}]
-% \begin{forest} for tree={grow'=0,l=2cm,anchor=west,child anchor=west},
-% [root
-% [normal]
-% [none,~no~ edge]
-% [dotted,edge=dotted]
-% [dashed,edge=dashed]
-% [dashed,edge={dashed,red}]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% \rkeyname[item={{{{{}}}}}]{edge label}|=|\meta{toks: \TikZ; code}
-%
-% When \ikeyname{edge path} has its default value, the value of this option is used at the end of
-% the edge path specification to typeset a node (or nodes) along the edge.
-%
-% The packing mechanism is not sensitive to edge labels.
-%
-% \begin{forestexample}[ekeynames={edge label}]
-% \begin{forest}
-% [VP
-% [V,~edge label~={node[midway,left,font=\scriptsize]{head}}]
-% [DP,~edge label~={node[midway,right,font=\scriptsize]{complement}}]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% \rkeyname[item]{edge path}|=|\meta{toks: \TikZ; code}
-% \hfill |\noexpand\path[\forestoption{edge}]|\\
-% \mbox{}\hfill |(!u.parent anchor)--(.child anchor)\forestoption{edge label};|
-%
-% This option contains the code that draws the edge from the node to its parent. By default, it
-% creates a path consisting of a single line segment between the node's \ikeyname{child anchor} and
-% its parent's \ikeyname{parent anchor}. Options given by \ikeyname{edge} are passed to the path; by
-% default, the path is simply drawn. Contents of \ikeyname{edge label} are used to potentially place
-% a node (or nodes) along the edge.
-%
-% When setting this option, the values of options \ikeyname{edge} and \ikeyname{edge label} can be
-% used in the edge path specification to include the values of options \ikeyname{edge} and \ikeyname{edge
-% node}. Furthermore, two generic anchors, \ikeyname{parent anchor,aspect=generic anchor} and \ikeyname{child anchor,aspect=generic anchor}, are defined,
-% to facilitate access to options \ikeyname{parent anchor} and \ikeyname{child anchor} from the \TikZ; code.
-%
-% The node positioning algorithm is sensitive to edges, i.e.\ it will avoid a node overlapping an
-% edge or two edges overlapping. However, the positioning algorithm always behaves as if the
-% \keyname{edge path} had the default value --- \emph{changing the \keyname{edge path} does not
-% influence the packing!} Sorry. (Parent--child edges can be ignored, however: see option
-% \ikeyname{ignore edge}.)
-%
-% \rkeyname[item={{{{{}}}}}]{parent anchor}|=|\meta{toks: \TikZ; anchor} (Information also applies to
-% option \ikeyname{child anchor}.)
-%
-% \FoRest; defines generic anchors \rkeyname{parent anchor,aspect=generic anchor} and
-% \rkeyname{child anchor,aspect=generic anchor} (which work only for \foRest; and not also \TikZ;
-% nodes, of course) to facilitate reference to the desired endpoints of child--parent edges.
-% Whenever one of these anchors is invoked, it looks up the value of the \keyname{parent anchor} or
-% \keyname{child anchor} of the node named in the coordinate specification, and forwards the request
-% to the (\TikZ;) anchor given as the value.
-%
-% The indented use of the two anchors is chiefly in \ikeyname{edge path} specification, but they can
-% used in any \TikZ; code.
-% \begin{forestexample}[ekeynames={parent anchor,child anchor,for tree}]
-% \begin{forest}
-% for tree={~parent anchor~=south,~child anchor~=north}
-% [VP[V][DP]]
-% \path[fill=red] (.parent anchor) circle[radius=2pt]
-% (!1.child anchor) circle[radius=2pt]
-% (!2.child anchor) circle[radius=2pt];
-% \end{forest}
-% \end{forestexample}
-%
-% The empty value (which is the default) is interpreted as in \TikZ;: as an edge to the appropriate
-% border point.
-%
-%
-% \rkeyname[item]{no edge} Clears the edge options (\ikeyname{edge}|'={}|) and sets \ikeyname{ignore
-% edge}.
-%
-% \rkeyname[item]{triangle} Makes the edge to parent a triangular roof. Works only for south-growing
-% trees. Works by changing the value of \ikeyname{edge path}.
-%
-% \end{syntax}
-%
-% \subsubsection{Readonly}
-% \label{ref:readonly-options}
-%
-% The values of these options provide various information about the tree and its nodes.
-%
-% \begin{syntax}
-% \rkeyname[item]{id=id}|=|\meta{count}) The internal id of the node.
-%
-% \rkeyname[item]{level}|=|\meta{count} The hierarchical level of the node. The root is on level $0$.
-%
-% \rkeyname[item]{max x}|=|\meta{dimen} \vspace{-\parskip}
-% \rkeyname[item]{max y}|=|\meta{dimen} \vspace{-\parskip}
-% \rkeyname[item]{min x}|=|\meta{dimen} \vspace{-\parskip}
-% \rkeyname[item]{min y}|=|\meta{dimen}
-% Measures of the node, in the shape's coordinate system
-% \citep[see][\S16.2,\S48,\S75]{tikzpgf2.10} shifted so that the node anchor is at the origin.
-%
-% In |pgfmath| expressions, these options are accessible as |max__x|, |max__y|, |min__x| and |min__y|.
-%
-% \rkeyname[item]{n}|=|\meta{count} The child's sequence number in the list of its parent's
-% children.
-%
-% The enumeration starts with 1. For the root node, \keyname{n} equals $0$.
-%
-% \rkeyname[item]{n'}|=|\meta{count} Like \ikeyname{n}, but starts counting at the last child.
-%
-% In |pgfmath| expressions, this option is accessible as |n__|.
-%
-% \rkeyname[item]{n children}|=|\meta{count} The number of children of the node.
-%
-% In |pgfmath| expressions, this option is accessible as |n__children|.
-% \end{syntax}
-%
-% \subsubsection{Miscellaneous}
-% \label{ref:miscellaneous}
-%
-% \begin{syntax}
-% \rkeyname[item]{afterthought}|=|\meta{toks} Provides the afterthought explicitely.
-%
-% This key is normally not used by the end-user, but rather called by the bracket parser. By
-% default, this key is a style defined by |afterthought/.style={tikz+={#1}}|: afterthoughts are
-% interpreted as (cumulative) \TikZ; code. If you'd like to use afterthoughts for some other
-% purpose, redefine the key --- this will take effect even if you do it in the tree preamble.
-%
-% \rkeyname[item]{alias}|=|\meta{toks} Sets the alias for the node's name.
-%
-% Unlike \ikeyname{name}, \keyname{alias} is \emph{not} an option: you cannot e.g.\ query it's
-% value via a |pgfmath| expression.
-%
-% Aliases can be used as the \meta{forest node name} part of a relative node name and as the
-% argument to the \ikeyname{name,aspect=step} step of a node walk. The latter includes the usage
-% as the argument of the \ikeyname{id={{for }}}\ikeyname{name} propagator.
-%
-% Technically speaking, \foRest; alias is \emph{not} a \TikZ; alias! However, you can still use
-% it as a ``node name'' in \TikZ; coordinates, since \foRest; hacks \TikZ;'s implicit node
-% coordinate system to accept relative node names; see \S\ref{ref:forest-cs}.
-%
-% \rkeyname[item]{baseline} The node's anchor becomes the baseline of the whole tree
-% \citep[cf.][\S69.3.1]{tikzpgf2.10}.
-%
-% In plain language, when the tree is inserted in your (normal \TeX) text, it will be vertically
-% aligned to the anchor of the current node.
-%
-% Behind the scenes, this style sets the alias of the current node to \keyname{forest@baseline@node}.
-% \begin{forestexample}[ekeynames={baseline,use as bounding box'}]
-% {\tikzexternaldisable
-% Baseline at the
-% \begin{forest}
-% [parent,~baseline~,use as bounding box'
-% [child]]
-% \end{forest}
-% and baseline at the
-% \begin{forest}
-% [parent
-% [child,~baseline~,use as bounding box']]
-% \end{forest}.}
-% \end{forestexample}
-%
-% \rkeyname[item=\begin{tikzpicture}]{begin draw}|/.code=|\meta{toks: \TeX\ code} \vspace{-\parskip}
-% \rkeyname[item=\end{tikzpicture}]{end draw}|/.code=|\meta{toks: \TeX\ code}
-%
-% The code produced by \ikeyname{draw tree} is put in the environment specified by \keyname{begin
-% draw} and \keyname{end draw}. Thus, it is this environment, normally a |tikzpicture|, that does
-% the actual drawing.
-%
-% A common use of these keys might be to enclose the |tikzpicture| environment in a |center|
-% environment, thereby automatically centering all trees; or, to provide the \TikZ; code to execute
-% at the beginning and/or end of the picture.
-%
-% Note that \keyname{begin draw} and \keyname{end draw} are \emph{not} node options: they are
-% |\pgfkeys|' code-storing keys \citep[\S55.4.3--4]{tikzpgf2.10}.
-%
-%
-% \rkeyname[item={{{{{}}}}}]{begin forest}|/.code=|\meta{toks: \TeX\ code} \vspace{-\parskip}
-% \rkeyname[item={{{{{}}}}}]{end forest}|/.code=|\meta{toks: \TeX\ code}
-%
-% The code stored in these (|\pgfkeys|) keys is executed at the beginning and end of the
-% \ikeyname{forest} environment / \icmdname{Forest} macro.
-%
-% Using these keys is only effective \emph{outside} the \ikeyname{forest} environment, and the
-% effect lasts until the end of the current \TeX\ group.
-%
-% For example, executing \icmdname{forestset}|{begin forest/.code=\small}| will typeset all trees (and only
-% trees) in the small font size.
-%
-%
-% \rkeyname[item]{fit to tree} Fits the \TikZ; node to the current node's subtree.
-%
-% This key should be used like \keyname{/tikz/fit} of the \TikZ;'s fitting library
-% \citep[see][\S34]{tikzpgf2.10}: as an option to \emph{\TikZ;'s} |node| operation, the obvious
-% restriction being that \keyname{fit to tree} must be used in the context of some \foRest; node.
-% For an example, see footnote~\ref{fn:fit-to-tree}.
-%
-% This key works by calling \keyname{/tikz/fit} and providing it with the the coordinates of the
-% subtree's boundary.
-%
-% \rkeyname[item]{get min s tree boundary}|=|\meta{cs} \vspace{-\parskip}
-% \rkeyname[item]{get max s tree boundary}|=|\meta{cs}
-%
-% Puts the boundary computed during the packing process into the given \meta{cs}. The boundary is
-% in the form of \PGF; path. The |min| and |max| versions give the two sides of the node. For an
-% example, see how the boundaries in the discussion of \ikeyname{fit} were drawn.
-%
-% \rkeyname[item]{label}|=|\meta{toks: \TikZ; node} The current node is labelled by a \TikZ; node.
-%
-% The label is specified as a \TikZ; option \texttt{label} \citep[\S16.10]{tikzpgf2.10}.
-% Technically, the value of this option is passed to \TikZ;'s as a late option
-% \citep[\S16.14]{tikzpgf2.10}. (This is so because \foRest; must first typeset the nodes
-% separately to measure them (stage \ikeyname{typeset nodes}); the preconstructed nodes are inserted
-% in the big picture later, at stage \ikeyname{draw tree}.) Another option with the same
-% technicality is \ikeyname{pin}.
-%
-% \rkeyname[item]{name}|=|\meta{toks} Sets the name of the node.\hfill\texttt{node@}\meta{id}
-%
-% The expansion of \meta{toks} becomes the \meta{forest node name} of the node. Node names must
-% be unique. The \TikZ; node created from the \foRest; node will get the name specified by this
-% option.
-%
-% \rkeyname[item]{node walk}|=|\meta{node walk} This key is the most general way to use a \meta{node
-% walk}.
-%
-% Before starting the \meta{node walk}, key \rkeyname{id={node walk/before walk}} is processed.
-% Then, the \meta{step}s composing the \meta{node walk} are processed: making a step (normally)
-% changes the current node. After every step, key \rkeyname{id={node walk/every step}} is
-% processed. After the walk, key \rkeyname{id={node walk/after walk}} is processed.
-%
-% \keyname{node walk/before walk}, \keyname{node walk/every step} and \keyname{node walk/after
-% walk} are processed with \keyname{/forest} as the default path: thus, \foRest;'s options and
-% keys described in \S\ref{ref:options-and-keys} can be used normally inside their definitions.
-%
-% \begin{advise}
-% \item Node walks can be tail-recursive, i.e.\ you can call another node walk from \keyname{node
-% walk/after walk} --- embedding another node walk in \keyname{node walk/before walk} or
-% \keyname{node walk/every step} will probably fail, because the three node walk styles are not
-% saved and restored (a node walk doesn't create a \TeX\ group).
-% \item \keyname{every step} and \keyname{after walk} can be redefined even during the walk.
-% Obviously, redefining \keyname{before walk} during the walk has no effect (in the current
-% walk).
-% \end{advise}
-%
-% \rkeyname[item]{pin}|=|\meta{toks: \TikZ; node} The current node gets a pin, see
-% \citep[\S16.10]{tikzpgf2.10}.
-%
-% The technical details are the same as for \ikeyname{label}.
-%
-% \rkeyname[item]{use as bounding box} The current node's box is used as a bounding box for the
-% whole tree.
-%
-% \rkeyname[item]{use as bounding box'} Like \ikeyname{use as bounding box}, but subtracts the
-% (current) inner and outer sep from the node's box. For an example, see \ikeyname{baseline}.
-%
-% \rkeyname[item]{TeX}|=|\meta{toks: \TeX\ code} The given code is executed immediately.
-%
-% This can be used for e.g.\ enumerating nodes:
-% \begin{forestexample}[point=TeX,ekeynames={TeX,delay,where ,tier,content,GP1},label=ex:enumerate]
-% \newcount\xcount
-% \begin{forest} GP1,
-% delay={TeX={\xcount=0},
-% where tier={x}{TeX={\advance\xcount1},
-% content/.expanded={##1$_{\the\xcount}$}}{}}
-% [
-% [O[x[f]]]
-% [R[N[x[o]]]]
-% [O[x[r]]]
-% [R[N[x[e]]][x[s]]]
-% [O[x[t]]]
-% [R[N[x]]]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% \rkeyname[item]{TeX'}|=|\meta{toks: \TeX\ code} This key is a combination of keys \ikeyname{TeX}
-% and \ikeyname{TeX''}: the given code is both executed and externalized.
-%
-% \rkeyname[item]{TeX''}|=|\meta{toks: \TeX\ code} The given code is externalized, i.e.\ it will be
-% executed when the externalized images are loaded.
-%
-% The image-loading and \keyname{TeX'(')} produced code are intertwined.
-%
-% \rkeyname[item={{{{{}}}}}]{tikz}|=|\meta{toks: \TikZ; code} ``Decorations.''
-%
-% The code given as the value of this option will be included in the |tikzpicture| environment
-% used to draw the tree. The code given to various nodes is appended in a depth-first,
-% parent-first fashion. The code is included after all nodes of the tree have been drawn, so it
-% can refer to any node of the tree. Furthermore, relative node names can be used to refer to
-% nodes of the tree, see \S\ref{ref:relative-node-names}.
-%
-% By default, bracket parser's afterthoughts feed the value of this option. See
-% \ikeyname{afterthought}.
-%
-% \end{syntax}
-%
-% \subsubsection{Propagators}
-% \label{ref:propagators}
-%
-% Propagators pass the given \meta{keylist} to other node(s), delay their processing, or cause them
-% to be processed only under certain conditions.
-%
-% A propagator can never fail --- i.e.\ if you use \keyname{for next} on the last child of some node,
-% no error will arise: the \meta{keylist} will simply not be passed to any node. (The generic
-% node walk propagator \keyname{for} is
-% an exception. While it will not fail if the final node of the walk does not exist (is null), its node walk
-% can fail when trying to walk away from the null node.)
-%
-% \paragraph{Spatial propagators}
-% pass the given \meta{keylist} to other node(s) in the tree. (\keyname{for} and \keyname{for
-% }\meta{step} always pass the \meta{keylist} to a single node.)
-%
-% \begin{syntax}
-% \rkeyname[item]{for}|=|\meta{node walk}\meta{keylist} Processes \meta{keylist} in the context of the final
-% node in the \meta{node walk} starting at the current node.
-%
-% \rkeyname[item]{id={{for }}}\meta{step}|=|\meta{keylist} Walks a single-step node-walk
-% \meta{step} from the current node and passes the given \meta{keylist} to the final (i.e.\ second) node.
-%
-% \meta{step} must be a long node walk step; see \S\ref{ref:node-walk}. \keyname{for
-% }\meta{step}|=|\meta{keylist} is equivalent to \ikeyname{for}|=|\meta{step}{keylist}.
-%
-% Examples: |for_parent={l_sep+=3mm}|, |for_n=2{circle,draw}|.
-%
-% \rkeyname[item]{for ancestors}|=|\meta{keylist}
-% \rkeyname[item]{for ancestors'}|=|\meta{keylist} Passes the \meta{keylist} to itself, too.
-% \begin{forestexample}[ekeynames={for ancestors',delay,content,edge}]
-% \pgfkeys{/forest,
-% inptr/.style={%
-% red,delay={content={\textbf{##1}}},
-% edge={draw,line width=1pt,red}},
-% ptr/.style={~for ancestors'~=inptr}
-% }
-% \begin{forest}
-% [x
-% [x[x[x][x]][x[x,ptr][x]]]
-% [x[x[x][x]][x[x][x]]]]
-% \end{forest}
-% \end{forestexample}
-%
-% \rkeyname[item]{for all next}|=|\meta{keylist} Passes the \meta{keylist} to all the following siblings.
-%
-% \rkeyname[item]{for all previous}|=|\meta{keylist} Passes the \meta{keylist} to all the preceding siblings.
-%
-% \rkeyname[item]{for children}|=|\meta{keylist}
-%
-% \rkeyname[item]{for descendants}|=|\meta{keylist}
-%
-% \rkeyname[item]{for tree}|=|\meta{keylist}
-%
-% Passes the key to the current node and its the descendants.
-%
-% This key should really be named \keyname{for subtree} \dots
-%
-% \end{syntax}
-%
-% \paragraph{Conditionals}
-% \label{ref:conditionals}
-%
-% For all conditionals, both the true and the false keylist are obligatory! Either keylist can be
-% empty, however --- but don't omit the braces!
-%
-% \begin{syntax}
-% \rkeyname[item]{if}|=|\meta{pgfmath condition}\meta{true keylist}\meta{false keylist}
-%
-% If \meta{pgfmath condition} evaluates to |true| (non-zero), \meta{true keylist} is processed (in
-% the context of the current node); otherwise, \meta{false keylist} is processed.
-%
-% For a detailed description of
-% |pgfmath| expressions, see \cite[part VI]{tikzpgf2.10}. (In short: write the usual mathematical
-% expressions.)
-%
-% \rkeyname[item]{id={{if }}}\meta{option}|=|\meta{value}\meta{true keylist}\meta{false keylist}
-%
-% A simple conditional is defined for every \meta{option}: if \meta{value} equals the value of the
-% option at the current node, \meta{true keylist} is executed; otherwise, \meta{false keylist}.
-%
-% \rkeyname[item]{where}|=|\meta{value}\meta{true keylist}\meta{false keylist}
-%
-% Executes conditional \ikeyname{if} for every node in the current subtree.
-%
-% \rkeyname[item]{id={{where }}}\meta{option}|=|\meta{value}\meta{true keylist}\meta{false keylist}
-%
-% Executes simple conditional \ikeyname{id={{if }}}\meta{option} for every node in the current subtree.
-%
-% \rkeyname[item]{id={{if in }}}\meta{option}|=|\meta{toks}\meta{true keylist}\meta{false
-% keylist}
-%
-% Checks if \meta{toks} occurs in the option value; if it does, \meta{true keylist} are executed,
-% otherwise \meta{false keylist}.
-%
-% This conditional is defined only for \meta{toks} options, see \S\ref{ref:options-and-keys}.
-%
-% \rkeyname[item]{id={{where in }}}\meta{toks option}|=|\meta{toks}\meta{true keylist}\meta{false keylist}
-%
-% A style equivalent to \ikeyname{for tree}|=|\ikeyname{id={{if in }}}\meta{option}=\meta{toks}\meta{true
-% keylist}\meta{false keylist}: for every node in the subtree rooted in the current node,
-% \ikeyname{id={{if in }}}\meta{option} is executed in the context of that node.
-%
-% This conditional is defined only for \meta{toks} options, see \S\ref{ref:options-and-keys}.
-% \end{syntax}
-%
-% \paragraph{Temporal propagators}
-% There are two kinds of temporal propagators. The |before_...| propagators defer the processing of
-% the given keys to a hook just before some stage in the computation. The \keyname{delay}
-% propagator is ``internal'' to the current hook (the first hook, the given options, is
-% implicit): the keys in a hook are processed cyclically, and \keyname{delay} delays the
-% processing of the given options until the next cycle. All these keys can be nested without
-% limit. For details, see~\S\ref{ref:stages}.
-% \begin{syntax}
-% \rkeyname[item]{delay}|=|\meta{keylist} Defers the processing of the \meta{keylist} until the next
-% cycle.
-% \rkeyname[item]{delay n}|=|\meta{integer}\meta{keylist} Defers the processing of the
-% \meta{keylist} for $n$ cycles. $n$ may be $0$, and it may be given as a |pgfmath| expression.
-% \rkeyname[item]{if have delayed}|=|\meta{true keylist}\meta{false keylist} If any options were
-% delayed in the current cycle (more precisely, up to the point of the execution of this key),
-% process \meta{true keylist}, otherwise process \meta{false keylist}. (\ikeyname{delay n} will
-% trigger ``true'' for the intermediate cycles.)
-% \rkeyname[item]{before typesetting nodes}|=|\meta{keylist} Defers the processing of the
-% \meta{keylist} to until just before the nodes are typeset.
-% \rkeyname[item]{before packing}|=|\meta{keylist} Defers the processing of the
-% \meta{keylist} to until just before the nodes are packed.
-% \rkeyname[item]{before computing xy}|=|\meta{keylist} Defers the processing of the
-% \meta{keylist} to until just before the absolute positions of the nodes are computed.
-% \rkeyname[item]{before drawing tree}|=|\meta{keylist} Defers the processing of the
-% \meta{keylist} to until just before the tree is drawn.
-% \end{syntax}
-%
-% \paragraph{Other propagators}
-% \begin{syntax}
-% \rkeyname[item]{repeat}|=|\meta{number}\meta{keylist} The \meta{keylist} is processed \meta{number}
-% times.
-%
-% The \meta{number} expression is evaluated using |pgfmath|. Propagator \keyname{repeat} also
-% works in node walks.
-% \end{syntax}
-%
-% \subsubsection{Stages}
-% \label{ref:stages}
-%
-% \FoRest; does its job in several steps. The normal course of events is the following:
-% \begin{enumerate}
-% \item\label{step:parsing-bracket} The bracket representation of the tree if parsed and stored in a
-% data structure.
-% \item\label{step:given-options} The given options are processed, including the options in the
-% preamble, which are processed first (in the context of the root node).
-% \item\label{step:typeset-nodes} Each node is typeset in its own |tikzpicture| environment, saved
-% in a box and its measures are taken.
-% \item\label{step:pack} The nodes of the tree are \emph{packed}, i.e.\ the relative positions of the nodes are
-% computed so that the nodes don't overlap. That's difficult. The result: option \ikeyname{s} is
-% set for all nodes. (Sometimes, the value of \ikeyname{l} is adjusted as well.)
-% \item\label{step:compute-xy} Absolute positions, or rather, positions of the nodes relative to the
-% root node are computed. That's easy. The result: options \ikeyname{x} and \ikeyname{y} are
-% set.
-% \item\label{step:draw-tree} The \TikZ; code that will draw the tree is produced. (The nodes are
-% drawn by using the boxes typeset in step~\ref{step:typeset-nodes}.)
-% \end{enumerate}
-%
-% Steps~\ref{step:parsing-bracket} and \ref{step:given-options} collect user input and are thus
-% ``fixed''. However, the other steps, which do the actual work, are under user's control.
-%
-% First, hooks exist which make it possible (and easy) to change node's properties between the
-% processing stages. For a simple example, see example~\ref{ex:adjustxy}: the manual adjustment of
-% \ikeyname{y} can only be done after the absolute positions have been computed, so the processing
-% of this option is deferred by \ikeyname{before drawing tree}. For a more realistic example, see
-% the definition of style \ikeyname{GP1}: before packing, \texttt{outer xsep} is set to a high (user
-% determined) value to keep the $\times$s uniformly spaced; before drawing the tree, the
-% \texttt{outer xsep} is set to \texttt{0pt} to make the arrows look better.
-%
-% Second, the execution of the processing stages \ref{step:typeset-nodes}--\ref{step:draw-tree} is
-% \emph{completely} under user's control. To facilitate adjusting the processing flow, the approach
-% is twofold. The outer level: \foRest; initiates the processing by executing style
-% \keyname{stages}, which by default executes the processing stages
-% \ref{step:typeset-nodes}--\ref{step:draw-tree}, preceding the execution of each stage by
-% processing the options embedded in temporal propagators \keyname{before ...} (see
-% \S\ref{ref:propagators}). The inner level: each processing step is the sole resident of a
-% stage-style, which makes it easy to adjust the workings of a single step. What follows is the
-% default content of style \keyname{stages}, including the default content of the individual
-% stage-styles.
-% \begin{syntax}
-% \rkeyname[item]{stages}
-% \begin{syntax}
-% \item \ikeyname{process keylist}|=|\ikeyname{before typesetting nodes}
-% \rkeyname[item]{typeset nodes stage}\hfill
-% |{|\ikeyname{id={{for }}}\ikeyname{root'}|=|\ikeyname{typeset nodes}|}|
-% \item \ikeyname{process keylist}|=|\ikeyname{before packing}
-% \rkeyname[item]{pack stage}\hfill
-% |{|\ikeyname{id={{for }}}\ikeyname{root'}|=|\ikeyname{pack}|}|
-% \item \ikeyname{process keylist}|=|\ikeyname{before computing xy}
-% \rkeyname[item]{compute xy stage}\hfill
-% |{|\ikeyname{id={{for }}}\ikeyname{root'}|=|\ikeyname{compute xy}|}|
-% \item \ikeyname{process keylist}|=|\ikeyname{before drawing tree}
-% \rkeyname[item]{draw tree stage}\hfill
-% |{|\ikeyname{id={{for }}}\ikeyname{root'}|=|\ikeyname{draw tree}|}|
-% \end{syntax}
-% \end{syntax}
-%
-% Both style \keyname{stages} and the individual stage-styles may be freely modified by the user.
-% Obviously, a style must be redefined before it is processed, so it is safest to do so either
-% outside the \ikeyname{forest} environment (using macro \icmdname{forestset}) or in the preamble
-% (in a non-deferred fashion).
-%
-% Here's the list of keys used either in the default processing or useful in an alternative
-% processing flow.
-% \begin{syntax}
-% \rkeyname[item]{typeset nodes} Typesets each node of the current node's subtree in its own
-% |tikzpicture| environment. The result is saved in a box and its measures are taken.
-%
-% \rkeyname[item]{typeset nodes'} Like \ikeyname{typeset nodes}, but the node box's content is not
-% overwritten if the box already exists.
-%
-% \rkeyname[item]{typeset node} Typesets the \emph{current} node, saving the result in the node box.
-%
-% This key can be useful also in the default \ikeyname{stages}. If, for example, the node's content
-% is changed and the node retypeset just before drawing the tree, the node will be positioned as if
-% it contained the ``old'' content, but have the new content: this is how the constant distance
-% between $\times$s is implemented in the \ikeyname{GP1} style.
-%
-% \rkeyname[item]{pack} The nodes of the tree are \emph{packed}, i.e.\ the relative positions of
-% the nodes are computed so that the nodes don't overlap. The result: option \ikeyname{s} is set
-% for all nodes; sometimes (in tier alignment and for some values of \ikeyname{calign}), the value
-% of some nodes' \ikeyname{l} is adjusted as well.
-%
-% \rkeyname[item]{pack'} ``Non-recursive'' packing: packs the children of the current node only.
-% (Experimental, use with care, especially when combining with tier alignment.)
-%
-% \rkeyname[item]{compute xy} Computes the positions of the nodes relative to the (formal) root
-% node. The results are stored into options \ikeyname{x} and \ikeyname{y}.
-%
-% \rkeyname[item]{draw tree} Produces the \TikZ; code that will draw the tree. First, the nodes
-% are drawn (using the boxes typeset in step~\ref{step:typeset-nodes}), followed by edges and
-% custom code (see option \ikeyname{tikz}).
-%
-% \rkeyname[item]{draw tree'} Like \ikeyname{draw tree}, but the node boxes are included in the
-% picture using \cmdname{copy}, not \cmdname{box}, thereby preserving them.
-%
-% \rkeyname[item]{draw tree box}|=|[\meta{\TeX\ box}] The picture drawn by the subsequent
-% invocations of \ikeyname{draw tree} and \ikeyname{draw tree'} is put into \meta{\TeX\ box}. If
-% the argument is omitted, the subsequent pictures are typeset normally (the default).
-%
-% \rkeyname[item]{process keylist}|=|\meta{keylist option name} Processes the keylist saved in
-% option \meta{keylist option name} for all the nodes in the \emph{whole} tree.
-%
-% This key is not sensitive to the current node: it processes the keylists for the whole tree.
-% The calls of this key should \emph{not} be nested.
-%
-% Keylist-processing proceeds in cycles. In a given cycle, the value of option \meta{keylist
-% option name} is processed for every node, in a recursive (parent-first, depth-first) fashion.
-% During a cycle, keys may be \emph{delayed} using key \ikeyname{delay}. (Keys of the dynamically
-% created nodes are automatically delayed.) Keys delayed in a cycle are processed in the next
-% cycle. The number of cycles in unlimited. When no keys are delayed in a cycle, the processing
-% of a hook is finished.
-% \end{syntax}
-%
-% \subsubsection{Dynamic tree}
-% \label{ref:dynamic}
-%
-% The following keys can be used to change the geometry of the tree by creating new nodes and
-% integrating them into the tree, moving and copying nodes around the tree, and removing nodes from
-% the tree.
-%
-% The node that will be (re)integrated into the tree can be specified in the following ways:
-% \begin{syntax}
-% \item \meta{empty}: uses the last (non-integrated, i.e.\ created/removed/replaced) node.
-% \item \meta{node}: a new node is created using the given bracket representation (the node may
-% contain children, i.e.\ a tree may be specified), and used as the argument to the key.
-%
-% The bracket representation must be enclosed in brackets, which will usually be enclosed in
-% braces to prevent them being parsed while parsing the ``host tree.''
-% \item \imeta{relative node name}: the node \meta{relative node name} resolves to will be used.
-% \end{syntax}
-%
-% Here is the list of dynamic tree keys:
-%
-% \begin{syntax}
-% \rkeyname[item]{append}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
-%
-% The specified node becomes the new final child of the current node. If the specified node had a
-% parent, it is first removed from its old position.
-%
-% \begin{forestexample}[label=ex:append,point=append,ekeynames={append,delay,for tree,n,content,n',repeat}]
-% \begin{forest}
-% before typesetting nodes={for tree={
-% if n=1{content=L}
-% {if n'=1{content=R}
-% {content=C}}}}
-% [,repeat=2{append={[
-% ,repeat=3{append={[]}}
-% ]}}]
-% \end{forest}
-% \end{forestexample}
-%
-% \rkeyname[item]{create}|=[|\meta{node}|]|
-%
-% Create a new node. The new node becomes the last node.
-%
-% \rkeyname[item]{insert after}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
-%
-% The specified node becomes the new following sibling of the current node. If the specified node had a
-% parent, it is first removed from its old position.
-%
-% \rkeyname[item]{insert before}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
-%
-% The specified node becomes the new previous sibling of the current node. If the specified node had a
-% parent, it is first removed from its old position.
-%
-% \rkeyname[item]{prepend}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
-%
-% The specified node becomes the new first child of the current node. If the specified node had a
-% parent, it is first removed from its old position.
-%
-% \rkeyname[item]{remove}
-%
-% The current node is removed from the tree and becomes the last node.
-%
-% The node itself is not deleted: it is just not integrated in the tree anymore. Removing the root
-% node has no effect.
-%
-% \rkeyname[item]{replace by}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
-%
-% The current node is replaced by the specified node. The current node becomes the last node.
-%
-% It the specified node is a new node containing a dynamic tree key, it can refer to the replaced
-% node by the \meta{empty} specification. This works even if multiple replacements are made.
-%
-% If \keyname{replace by} is used on the root node, the ``replacement'' becomes the root node
-% (\ikeyname{set root} is used).
-%
-% \rkeyname[item]{set root}
-%
-% The current node becomes the new \emph{formal} root of the tree.
-%
-% Note: If the current node has a parent, it is \emph{not} removed from it. The node becomes the
-% root only in the sense that the default implementation of stage-processing will consider it a
-% root, and thus typeset/pack/draw the (sub)tree rooted in this root. The processing of keys such
-% as \ikeyname{for parent} and \ikeyname{for root} is not affected: \ikeyname{for root} finds the
-% real, geometric root of the current node. To access the formal root, use node walk step
-% \ikeyname{root'}, or the corresponding propagator \ikeyname{id={{for }}}\ikeyname{root'}.
-% \end{syntax}
-%
-% If given an existing node, most of the above keys \emph{move} this node
-% (and its subtree, of course). Below are the versions of these operations which rather \emph{copy}
-% the node: either the whole subtree (|'|) or just the node itself (|''|).
-% \begin{syntax}
-% \rkeyname[item]{append'}, \rkeyname{insert after'}, \rkeyname{insert before'}, \rkeyname{prepend'},
-% \rkeyname{replace by'}
-%
-% Same as versions without |'| (also the same arguments), but it is the copy of the specified node
-% and its subtree that is integrated in the new place.
-% \rkeyname[item]{append''}, \rkeyname{insert after''}, \rkeyname{insert before''}, \rkeyname{prepend''},
-% \rkeyname{replace by''}
-%
-% Same as versions without |''| (also the same arguments), but it is the copy of the specified node
-% (without its subtree) that is integrated in the new place.
-% \rkeyname[item]{copy name template}|=|\meta{empty}\OR\meta{macro definition} \hfill\meta{empty}
-%
-% Defines a template for constructing the \ikeyname{name} of the copy from the name of the
-% original. \meta{macro definition} should be either empty (then, the \ikeyname{name} is
-% constructed from the \ikeyname{id=id}, as usual), or an expandable macro taking one argument (the
-% name of the original).
-% \end{syntax}
-%
-% \begin{advise}
-% \item You might want to \ikeyname{delay} the processing of the copying operations, giving the
-% original nodes the chance to process their keys first!
-% \end{advise}
-%
-% \begin{forestexample}
-% \begin{forest}
-% copy name template={copy of #1}
-% [CP,delay={prepend'=subject}
-% [VP[DP,name=subject[D][NP]][V'[V][DP]]]]
-% \draw[->,dotted] (subject)--(copy of subject);
-% \end{forest}
-% \end{forestexample}
-%
-% A dynamic tree operation is made in two steps:
-% \begin{itemize}
-% \item If the argument is given by a \meta{node} argument, the new node is created immediately,
-% i.e.\ while the dynamic tree key is being processed. Any options of the new node are
-% implicitely \ikeyname{delay}ed.
-% \item The requested changes in the tree structure are actually made between the cycles of keylist
-% processing.
-% \end{itemize}
-%
-% \begin{advise}
-% \item Such a two-stage approach is employed because changing the tree structure during the dynamic
-% tree key processing would lead to an unmanageable order of keylist processing.
-% \item A consequence of this approach is that nested dynamic tree keys take several cycles to
-% complete. Therefore, be careful when using \ikeyname{delay} and dynamic tree keys
-% simultaneously: in such a case, it is often safer to use \ikeyname{before typesetting nodes}
-% instead of \ikeyname{delay}, see example \ref{ex:append}.
-% \item Further examples: title page (in style |random tree|), \ref{ex:xlist}.
-% \end{advise}
-%
-% \subsection{Handlers}
-% \label{ref:handlers}
-%
-% \begin{syntax}
-% \rkeyname[item]{id=.pgfmath,nfc}|=|\meta{pgfmath expression}
-%
-% The result is the evaluation of \meta{pgfmath expression} in the context of the current node.
-%
-% \rkeyname[item]{id=.wrap value,nfc}|=|\meta{macro definition}
-%
-% The result is the (single) expansion of the given
-% \meta{macro definition}. The defined macro takes one parameter. The current value of the
-% handled option will be passed as that parameter.
-%
-% \rkeyname[item]{id=.wrap $n$ pgfmath args,nfc}|=|\meta{macro definition}\meta{arg $1$}\dots\meta{arg $n$}
-%
-% The result is the (single) expansion of the given \meta{macro definition}. The defined macro
-% takes $n$ parameters, where $n\in\{2,\dots,8\}$. Expressions \meta{arg $1$} to \meta{arg $n$}
-% are evaluated using |pgfmath| and passed as arguments to the defined macro.
-%
-% \rkeyname[item]{id=.wrap pgfmath arg,nfc}|=|\meta{macro definition}\meta{arg}
-%
-% Like \ikeyname{id=.wrap $n$ pgfmath args,nfc} for $n=1$.
-% \end{syntax}
-%
-% \subsection{Relative node names}
-% \label{ref:relative-node-names}
-%
-% \begin{syntax}
-% \item\rmeta{relative node name}|=|[\meta{forest node name}][|!|\meta{node walk}]
-%
-% \meta{relative node name} refers to the \foRest; node at the end of the \meta{node walk}
-% starting at node named \meta{forest node name}. If \meta{forest node name} is omitted, the walk
-% starts at the current node. If \meta{node walk} is omitted, the ``walk'' ends at the start
-% node. (Thus, an empty \meta{relative node name} refers to the current node.)
-% \end{syntax}
-%
-% Relative node names can be used in the following contexts:
-% \begin{itemize}
-% \item \FoRest;'s |pgfmath| option functions (\S\ref{ref:pgfmath}) take a relative node name as
-% their argument, e.g.\ |content("!u")| and |content("!parent")| refer to the content of the
-% parent node.
-% \item An option of a non-current node can be set by \meta{relative node name}|.|\meta{option
-% name}|=|\meta{value}, see \S\ref{ref:options-and-keys}.
-% \item The |forest| coordinate system, both explicit and implicit; see \S\ref{ref:forest-cs}.
-% \end{itemize}
-%
-% \subsubsection{Node walk}
-% \label{ref:node-walk}
-%
-% A \rmeta{node walk} is a sequence of \rmeta{step}s describing a path through the tree.
-% The primary use of node walks is in relative node names. However, they can also be used in a
-% ``standalone'' way, using key \ikeyname{node walk}; see \S\ref{ref:miscellaneous}.
-%
-% Steps are keys in the \keyname{/forest/node walk} path. (\foRest; always sets this path as
-% default when a node walk is to be used, so step keynames can be used.) Formally, a \meta{node
-% walk} is thus a keylist, and steps must be separated by commas. There is a twist, however. Some
-% steps also have \emph{short} names, which consist of a single character. The comma between two
-% adjacent short steps can be omitted. Examples:
-% \begin{itemize}
-% \item |parent,parent,n=2| or |uu2|: the grandparent's second child (of the current node)
-% \item |first leaf,uu|: the grandparent of the first leaf (of the current node)
-% \end{itemize}
-% The list of long steps:
-% \newcommand\nwritem[1]{\rkeyname[item]{#1,aspect=step}\ekeyname{for #1,aspect=propagator,def}}
-% \begin{syntax}
-% \nwritem{current} an ``empty'' step: the current node remains the same\footnote{While it
-% might at first sight seem stupid to have an empty step, this is not the case. For example,
-% using propagator \ikeyname{for current} derived from this step, one can process a \meta{keylist}
-% constructed using \texttt{.wrap (n) pgfmath arg(s)}\ekeyname{id=.wrap
-% pgfmath arg,nfc}\ekeyname{id=.wrap $n$ pgfmath args,nfc} or \ikeyname{id=.wrap value,nfc}.}
-% \nwritem{first} the primary child
-% \nwritem{first leaf} the first leaf (terminal node)
-% \rkeyname[item]{group,aspect=step}|=|\meta{node walk} treat the given \meta{node walk} as a single step
-% \nwritem{last} the last child
-% \nwritem{last leaf} the last leaf
-% \nwritem{id=id}|=|\meta{id} the node with the given id
-% \nwritem{linear next} the next node, in the processing order
-% \nwritem{linear previous} the previous node, in the processing order
-% \nwritem{n}|=|$n$ the $n$th child; counting starts at $1$ (not $0$)
-% \nwritem{n'}|=|$n$ the $n$th child, starting the count from the last child
-% \nwritem{name} the node with the given name
-% \nwritem{next} the next sibling
-% \nwritem{next leaf} the next leaf
-%
-% (the current node need not be a leaf)
-% \nwritem{next on tier} the next node on the same tier as the current node
-% \rkeyname[item]{node walk,aspect=step}|=|\meta{node walk} embed the given \meta{node walk}
-%
-% (the \ikeyname{id={node walk/before walk}} and \ikeyname{id={node walk/after walk}} are processed)
-% \nwritem{parent} the parent
-% \nwritem{previous} the previous sibling
-% \nwritem{previous leaf} the previous leaf
-%
-% (the current node need not be a leaf)
-% \nwritem{previous on tier} the next node on the same tier as the current node
-% \rkeyname[item]{repeat}|=|$n$\meta{node walk} repeat the given \meta{node walk} $n$ times
-%
-% (each step in every repetition counts as a step)
-% \nwritem{root} the root node
-% \nwritem{root'} the formal root node (see \ikeyname{set root} in \S\ref{ref:dynamic})
-% \nwritem{sibling} the sibling
-%
-% (don't use if the parent doesn't have exactly two children \dots)
-% \nwritem{to tier}|=|\meta{tier} the first ancestor of the current node on the given \meta{tier}
-% \rkeyname[item]{trip,aspect=step}|=|\meta{node walk} after walking the embedded \meta{node walk}, return to the
-% current node; the return does not count as a step
-% \end{syntax}
-%
-% For each long \meta{step} except \keyname{node walk}, \keyname{group}, \keyname{trip} and
-% \keyname{repeat}, propagator \ikeyname{id={{for }}}\meta{step} is also defined. Each such
-% propagator takes a \meta{keylist} argument. If the step takes an argument, then so does its
-% propagator; this argument precedes the \meta{keylist}. See also \S\ref{ref:propagators}.
-%
-% Short steps are single-character keys in the \keyname{/forest/node walk} path. They are defined
-% as styles resolving to long steps, e.g.\ |1/.style={n=1}|. The list of predefined short steps
-% follows.
-% \begin{syntax}
-% \rkeyname[item]{1},
-% \rkeyname{2},
-% \rkeyname{3},
-% \rkeyname{4},
-% \rkeyname{5},
-% \rkeyname{6},
-% \rkeyname{7},
-% \rkeyname{8},
-% \rkeyname{9} the first, \dots, ninth child
-% \rkeyname[item]{l,aspect=short step} the last child
-% \rkeyname[item]{u} the parent (up)
-% \rkeyname[item]{p} the previous sibling
-% \rkeyname[item]{n,aspect=short step} the next sibling
-% \rkeyname[item]{s,aspect=short step} the sibling
-% \rkeyname[item]{P} the previous leaf
-% \rkeyname[item]{N} the next leaf
-% \rkeyname[item]{F} the first leaf
-% \rkeyname[item]{L} the last leaf
-% \rkeyname[item]{id=<<<,display=\protect\myindexgt,text=>,aspect=short step}
-% the next node on the current tier
-% \rkeyname[item]{<} the previous node on the current tier
-% \rkeyname[item]{c} the current node
-% \rkeyname[item]{r} the root node
-% \end{syntax}
-% \begin{advise}
-% \item You can define your own short steps, or even redefine predefined short steps!
-% \end{advise}
-%
-% \subsubsection{The \texttt{forest} coordinate system}
-% \label{ref:forest-cs}
-%
-% Unless package options \ikeyname{tikzcshack} is set to |false|, \TikZ;'s implicit node coordinate
-% system \citep[\S13.2.3]{tikzpgf2.10} is hacked to accept relative node names.\footnote{Actually,
-% the hack can be switched on and off on the fly, using \cmdname{i}\keyname{fforesttikzcshack}.}.
-%
-% The explicit \texttt{forest} coordinate system is called simply |forest| and used like this:
-% |(forest_cs:|\meta{forest cs spec}|)|; see \citep[\S13.2.5]{tikzpgf2.10}. \meta{forest cs spec}
-% is a keylist; the following keys are accepted.
-%
-% \begin{syntax}
-% \rkeyname[item]{name,aspect=forest cs}|=|\meta{node name} The node with the given name becomed the current node. The
-% resulting point is its (node) anchor.
-% \rkeyname[item]{id=id,aspect=forest cs}|=|\meta{node id} The node with the given name becomed the current node. The
-% resulting point is its (node) anchor.
-% \rkeyname[item]{go,aspect=forest cs}|=|\meta{node walk} Walk the given node walk, starting at the current node. The node
-% at the end of the walk becomes the current node. The resulting point is its (node) anchor.
-% \rkeyname[item]{anchor,aspect=forest cs}|=|\meta{anchor} The resulting point is the given anchor of the current node.
-% \rkeyname[item]{l,aspect=forest cs}|=|\meta{dimen} \vspace{-\parskip}
-% \rkeyname[item]{s,aspect=forest cs}|=|\meta{dimen} Specify the \ikeyname{l} and \ikeyname{s}
-% coordinate of the resulting point.
-%
-% The coordinate system is the node's ls-coordinate system: its origin is at its (node) anchor; the
-% l-axis points in the direction of the tree growth at the node, which is given by option
-% \ikeyname{grow}; the s-axis is orthogonal to the l-axis; the positive side is in the
-% counter-clockwise direction from |l| axis.
-%
-% The resulting point is computed only after both \ikeyname{l} and \ikeyname{s} were given.
-% \item Any other key is interpreted as a \imeta{relative node name}[.\meta{anchor}].
-% \end{syntax}
-%
-% \subsection{New \texttt{pgfmath} functions}
-% \label{ref:pgfmath}
-%
-% For every option, \foRest; defines a pgfmath function with the same name, with the
-% proviso that all non-alphanumeric characters in the option name are replaced by an underscore
-% |__| in the pgfmath function name.
-%
-% Pgfmath functions corresponding to options take one argument, a \imeta{relative node name}
-% (see~\S\ref{ref:relative-node-names}) expression, making it possible to refer to option values of
-% non-current nodes. The \meta{relative node name} expression must be enclosed in double quotes in
-% order to
-% prevent pgfmath evaluation: for example, to refer to the content of the parent, write
-% \ikeyname{content}|("!u")|. To refer to the option of the current node, use empty parentheses:
-% \ikeyname{content}|()|.\footnote{In most cases, the parentheses are optional, so \texttt{content}
-% is ok. A known case where this doesn't work is preceding an operator: \texttt{l+1cm} will fail.}
-%
-% Three string functions are also added to |pgfmath|: \rkeyname{strequal} tests the equality of
-% its two arguments; \rkeyname{instr} tests if the first string is a substring of the second one;
-% \rkeyname{strcat} joins an arbitrary number of strings.
-%
-% Some random notes on |pgfmath|: \begin{inparaenum}[(i)]
-% \item |&&|, \verb!||! and |!| are boolean ``and'', ``or'' and ``not'', respectively.
-% \item The equality operator (for numbers and dimensions) is |==|, \emph{not} |=|.
-% \end{inparaenum} And some examples:
-%
-% \begin{forestexample}[pos=t,ekeynames={for tree,grow',calign,l,l sep,child
-% anchor,anchor,fit,tier,level,delay,before typesetting nodes,content,{id=.wrap 2 pgfmath args,nfc},{id=.pgfmath,nfc}}]
-% \begin{forest}
-% for tree={grow'=0,calign=first,l=0,l sep=2em,child anchor=west,anchor=base
-% west,fit=band,tier/.pgfmath=~level~()},
-% fullpath/.style={if n=0{}{content/.wrap 2
-% pgfmath args={##1/##2}{~content~("!u")}{~content~()}}},
-% delay={for tree=fullpath,content=/},
-% before typesetting nodes={for tree={content=\strut#1}}
-% [
-% [home
-% [joe
-% [\TeX]]
-% [saso
-% [\TeX]]
-% [a user with a long name
-% [\TeX]]]
-% [usr]]
-% \end{forest}
-% \end{forestexample}
-%
-% \begin{forestexample}[point=instr,ekeynames={delay,for tree,if,content,n children}]
-% \begin{forest}
-% delay={for tree={if=
-% {!instr("!P",~content~) && ~n_children~==0}
-% {fill=yellow}
-% {}
-% }}
-% [CP[DP][C'[C][TP[DP][T'[T][VP[DP][V'[V][DP]]]]]]]
-% \end{forest}
-% \end{forestexample}
-%
-% \begin{forestexample}[point=instr,ekeynames={where ,n children,tier,content,no edge,tikz}]
-% \begin{forest}
-% where n children=0{tier=word,
-% if={~instr~("!P",~content~("!u"))}{no edge,
-% tikz={\draw (!.north west)--
-% (!.north east)--(!u.south)--cycle;
-% }}{}
-% }{},
-% [VP[DP[John]][V'[V[loves]][DP[Mary]]]]
-% \end{forest}
-% \end{forestexample}
-%
-%
-% \subsection{Standard node}
-% \label{ref:standard-node}
-%
-% \begin{syntax}
-% \item\rcmdname{forestStandardNode}\meta{node}\meta{environment fingerprint}\meta{calibration
-% procedure}\meta{exported options}
-%
-% This macro defines the current \emph{standard node}. The standard node declares some options as
-% \emph{exported}. When a new node is created, the values of the exported options are initialized
-% from the standard node. At the beginning of every \ikeyname{forest} environment, it is checked whether
-% the \emph{environment fingerprint} of the standard node has changed. If it did, the standard
-% node is \emph{calibrated}, adjusting the values of exported options. The \emph{raison d'etre} for
-% such a system is given in \S\ref{sec:defaults}.
-%
-% In \meta{node}, the standard node's content and possibly other options are specified, using the
-% usual bracket representation. The \meta{node}, however, \emph{must not contain children}. The
-% default: \texttt{[dj]}.
-%
-% The \meta{environment fingerprint} must be an expandable macro definition. It's expansion
-% should change whenever the calibration is necessary.
-%
-% \meta{calibration procedure} is a keylist (processed in the |/forest| path) which calculates the
-% values of exported options.
-%
-% \meta{exported options} is a comma-separated list of exported options.
-%
-% This is how the default standard node is created:
-% \begin{lstlisting}
-% \forestStandardNode[dj]
-% {%
-% \forestOve{\csname forest@id@of@standard node\endcsname}{content},%
-% \the\ht\strutbox,\the\pgflinewidth,%
-% \pgfkeysvalueof{/pgf/inner ysep},\pgfkeysvalueof{/pgf/outer ysep},%
-% \pgfkeysvalueof{/pgf/inner xsep},\pgfkeysvalueof{/pgf/outer xsep}%
-% }
-% {
-% l sep={\the\ht\strutbox+\pgfkeysvalueof{/pgf/inner ysep}},
-% l={l_sep()+abs(max_y()-min_y())+2*\pgfkeysvalueof{/pgf/outer ysep}},
-% s sep={2*\pgfkeysvalueof{/pgf/inner xsep}}
-% }
-% {l sep,l,s sep}
-% \end{lstlisting}
-% \end{syntax}
-%
-% \subsection{Externalization}
-% \label{ref:externalization}
-%
-% Externalized tree pictures are compiled only once. The result of the compilation is saved into a
-% separate |.pdf| file and reused on subsequent compilations of the document. If the code of the
-% tree (or the context, see below) is changed, the tree is automatically recompiled.
-%
-% Externalization is enabled by:
-% \begin{lstlisting}
-% \usepackage[~external~]{forest}
-% ~\tikzexternalize~
-% \end{lstlisting}
-% Both lines are necessary. \TikZ;'s externalization library is automatically loaded if necessary.
-%
-% \begin{syntax}
-% \rkeyname[item]{id={external/optimize}} Parallels \keyname{/tikz/external/optimize}: if |true| (the
-% default), the processing of non-current trees is skipped during the embedded compilation.
-% \rkeyname[item]{id={external/context}} If the expansion of the macro stored in
-% this option changes, the tree is recompiled.
-% \rkeyname[item]{id={external/depends on macro}}|=|\meta{cs} Adds the definition of macro \meta{cs} to
-% \keyname{external/context}. Thus, if the definition of \meta{cs} is changed, the tree will be
-% recompiled.
-% \end{syntax}
-%
-% \foRest; respects or is compatible with several (not all) keys and commands of \TikZ;'s
-% externalization library. In particular, the following keys and commands might be useful; see
-% \cite[\S32]{tikzpgf2.10}.
-% \begin{itemize}
-% \item\keyname{/tikz/external/remake next}
-% \item\keyname{/tikz/external/prefix}
-% \item\keyname{/tikz/external/system call}
-% \item\cmdname{tikzexternalize}
-% \item\cmdname{tikzexternalenable}
-% \item\cmdname{tikzexternaldisable}
-% \end{itemize}
-% \FoRest; does not disturbe the externalization of non-\foRest; pictures. (At least it
-% shouldn't \dots)
-%
-% The main auxiliary file for externalization has suffix |.for|. The externalized pictures have
-% suffices |-forest-|$n$ (their prefix can be set by \keyname{/tikz/external/prefix}, e.g.\ to a
-% subdirectory). Information on all trees that were ever externalized in the document (even if
-% they were changed or deleted) is kept. If you need a ``clean'' |.for| file, delete it and
-% recompile. Deleting |-forest-|$n$|.pdf| will result in recompilation of a specific tree.
-%
-% Using \keyname{draw tree} and \keyname{draw tree'} multiple times \emph{is} compatible with
-% externalization, as is drawing the tree in the box (see \ikeyname{draw tree box}). If you are
-% trying to externalize a \ikeyname{forest} environment which utilizes \ikeyname{TeX} to produce a
-% visible effect, you will probably need to use \ikeyname{TeX'} and/or \ikeyname{TeX''}.
-%
-% \subsection{Package options}
-% \label{ref:package-options}
-%
-% \begin{syntax}
-% \rkeyname[item=false]{external}|=|\alternative{true,false}
-%
-% Enable/disable externalization, see \S\ref{ref:externalization}.
-% \rkeyname[item=true]{tikzcshack}|=|\alternative{true,false}
-%
-% Enable/disable the hack into \TikZ;'s implicite coordinate syntax hacked, see
-% \S\ref{ref:relative-node-names}.
-%
-% \rkeyname[item=true]{tikzinstallkeys}|=|\alternative{true,false}
-%
-% Install certain keys into the \keyname{/tikz} path. Currently: \ikeyname{fit to tree}.
-% \end{syntax}
-%
-% \section{Gallery}
-% \label{sec:gallery}
-%
-%
-% \subsection{Styles}
-% \label{sec:gallery-styles}
-%
-% \paragraph{\rkeyname{GP1}}
-% For Government Phonology (v1) representations. Here, the big trick
-% is to evenly space $\times$s by having a large enough |outer_xsep|
-% (adjustable), and then, before drawing (timing control option
-% |before_drawing_tree|), setting |outer_xsep| back to 0pt. The last step
-% is important, otherwise the arrows between $\times$s won't draw!
-%
-% \box\GPone
-%
-% An example of an ``embedded'' |GP1| style:
-% \begin{forestexample}[pos=b,ekeynames={where ,tier,for children,content,tikz,l,+,no edge}]
-% \begin{forest}
-% myGP1/.style={
-% ~GP1~,
-% delay={where tier={x}{
-% for children={content=\textipa{##1}}}{}},
-% tikz={\draw[dotted](.south)--
-% (!1.north west)--(!l.north east)--cycle;},
-% for children={l+=5mm,no edge}
-% }
-% [VP[DP[John,tier=word,myGP1
-% [O[x[dZ]]]
-% [R[N[x[6]]]]
-% [O[x[n]]]
-% [R[N[x]]]
-% ]][V'[V[loves,tier=word,myGP1
-% [O[x[l]]]
-% [R[N[x[a]]]]
-% [O[x[v]]]
-% [R[N[x]]]
-% [O[x[z]]]
-% [R[N[x]]]
-% ]][DP[Mary,tier=word,myGP1
-% [O[x[m]]]
-% [R[N[x[e]]]]
-% [O[x[r]]]
-% [R[N[x[i]]]]
-% ]]]]
-% \end{forest}%
-% \end{forestexample}
-%
-% And an example of annotations.
-% \begin{forestexample}
-% \begin{forest}[,phantom,s sep=1cm
-% [{[ei]}, GP1
-% [R[N[x[A,~el~[I,~head~,~associate=N~]]][x]]]
-% ]
-% [{[mars]}, GP1
-% [O[x[m]]]
-% [R[N[x[a]]][x,~encircle~,densely dotted[r]]]
-% [O[x,~encircle~,~govern=<~[s]]]
-% [R,~fen~[N[x]]]
-% ]
-% ]\end{forest}
-% \end{forestexample}
-%
-%
-% \paragraph{rlap and llap} The \foRest; versions of \TeX's \cmdname{rlap}\ and \cmdname{llap}: the
-% ``content'' added by these styles will influence neither the packing algorithm nor the anchor
-% positions.
-% \begin{forestexample}[pos=b,point={rlap,llap},ekeynames={TeX,delay,where ,tier,content,GP1}]
-% \forestset{
-% llap/.style={tikz+={
-% \edef\forest@temp{\noexpand\node[\forestoption{node options},
-% anchor=base east,at=(.base east)]}
-% \forest@temp{#1\phantom{\forestoption{content format}}};
-% }},
-% rlap/.style={tikz+={
-% \edef\forest@temp{\noexpand\node[\forestoption{node options},
-% anchor=base west,at=(.base west)]}
-% \forest@temp{\phantom{\forestoption{content format}}#1};
-% }}
-% }
-% \newcount\xcount
-% \begin{forest} GP1,
-% delay={
-% TeX={\xcount=0},
-% where tier={x}{TeX={\advance\xcount1},rlap/.expanded={$_{\the\xcount}$}}{}
-% }
-% [
-% [O[x[f]]]
-% [R[N[x[o]]]]
-% [O[x[r]]]
-% [R[N[x[e]]][x[s]]]
-% [O[x[t]]]
-% [R[N[x]]]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-% \paragraph{xlist} This style makes it easy to put ``separate''
-% trees in a picture and enumerate them. For an example, see the |nice_empty_nodes|
-% style.
-% \begin{forestexample}[pos=t,label=ex:xlist]
-% \makeatletter
-% \forestset{
-% xlist/.style={
-% phantom,
-% for children={no edge,replace by={[,append,
-% delay={content/.wrap pgfmath arg={\@alph{##1}.}{n()+#1}}
-% ]}}
-% },
-% xlist/.default=0
-% }
-% \makeatother
-% \end{forestexample}
-% \input{\jobname.tmp}
-%
-% \paragraph{nice empty nodes}
-% We often need empty nodes: tree (a) shows how they look like by
-% default: ugly.
-%
-% First, we don't want the gaps: we change the shape of empty nodes to coordinate. We get tree (b).
-%
-% Second, the empty nodes seem too close
-% to the other (especially empty) nodes (this is a result of a small
-% default |s_sep|). We could use a greater \ikeyname{s sep}, but a better solution seems
-% to be to use |calign=node_angle|. The result is shown in (c).
-%
-% However, at the transitions from empty to non-empty nodes, tree (d)
-% above seems to zigzag (although the base points of the spine nodes
-% are perfectly in line), and the edge to the empty node left to VP
-% seems too long (it reaches to the level of VP's base, while we'd
-% prefer it to stop at the same level as the edge to VP itself). The
-% first problem is solved by substituting |node_angle| for
-% |edge_angle|; the second one, by anchoring siblings of
-% empty nodes at north.
-% \begin{forestexample}[pos=b,ekeynames={fixed angles,fixed edge angles,calign,for tree,delay,where
-% ,content,for ,parent,for children,anchor}]
-% \forestset{
-% ~nice empty nodes~/.style={
-% for tree={calign=fixed edge angles},
-% delay={where content={}{shape=coordinate,for parent={for children={anchor=north}}}{}}
-% }}
-% \begin{forest}
-% [,~xlist~
-% [CP, %(a)
-% [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
-% [CP, delay={where content={}{shape=coordinate}{}} %(b)
-% [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
-% [CP, for tree={calign=fixed angles}, %(c)
-% delay={where content={}{shape=coordinate}{}}
-% [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
-% [CP, ~nice empty nodes~ %(d)
-% [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-%
-% \subsection{Examples}
-% \label{sec:examples}
-%
-% The following example was inspired by a question on \TeX\ Stackexchange:
-% \href{http://tex.stackexchange.com/questions/39103/how-to-change-the-level-distance-in-tikz-qtree-for-one-level-only}{How to change the level distance in tikz-qtree for one level only?}. The question is about |tikz-qtree|: how to adjust the level distance for the first level only, in order to avoid first-level labels crossing the parent--child edge. While this example solves the problem (by manually shifting the offending labels; see \texttt{elo} below), it does more: the preamble is setup so that inputing the tree is very easy.
-%
-% \begin{forestexample}[pos=t,ekeynames={id={{if }},n,no edge,tikz,strequal,strcat,child anchor,parent
-% anchor,anchor,calign,for tree,s sep,l,n children,declare toks,delay,content,before typesetting nodes,for descendants,+,{id=.wrap pgfmath arg,nfc},{id=.wrap 2 pgfmath args,nfc}}]
-% \def\getfirst#1;#2\endget{#1}
-% \def\getsecond#1;#2\endget{#2}
-% \forestset{declare toks={elo}{}} % edge label options
-% \begin{forest}
-% anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
-% for tree={
-% s sep=0.5em,l=8ex,
-% if n children=0{anchors=north}{
-% if n=1{anchors=south east}{anchors=south west}},
-% content format={$\forestoption{content}$}
-% },
-% anchors=south, outer sep=2pt,
-% nomath/.style={content format=\forestoption{content}},
-% dot/.style={tikz+={\fill (.child anchor) circle[radius=#1];}},
-% dot/.default=2pt,
-% dot=3pt,for descendants=dot,
-% decision edge label/.style n args=3{
-% edge label/.expanded={node[midway,auto=#1,anchor=#2,\forestoption{elo}]{\strut$#3$}}
-% },
-% decision/.style={if n=1
-% {decision edge label={left}{east}{#1}}
-% {decision edge label={right}{west}{#1}}
-% },
-% delay={for descendants={
-% decision/.expanded/.wrap pgfmath arg={\getsecond#1\endget}{content},
-% content/.expanded/.wrap pgfmath arg={\getfirst#1\endget}{content},
-% }},
-% [N,nomath
-% [I;{p_1=0.5},nomath,elo={yshift=4pt}
-% [{5,1};a]
-% [II;b,nomath
-% [{1,2};m]
-% [{2,3};n]
-% ]
-% ]
-% [II;{p_2=0.5},nomath,elo={yshift=4pt}
-% [;c
-% [{1,0};z]
-% [{2,2};t]
-% ]
-% [;d
-% [{3,1};z]
-% [{0,0};t]
-% ]
-% ] {\draw[dashed](!1.anchor)--(!2.anchor) node[pos=0.5,above]{I};}
-% ]
-% \end{forest}
-% \end{forestexample}
-%
-%
-% \section{Known bugs}
-% \label{sec:bugs}
-%
-% If you find a bug (there are bound to be some \dots), please contact
-% me at \href{mailto:saso.zivanovic@guest.arnes.si}{saso.zivanovic@guest.arnes.si}.
-%
-% \paragraph{System requirements} This package requires \LaTeX\ and e\TeX. If you use something
-% else: sorry.
-%
-% The requirement for \LaTeX\ might be dropped in the future, when I get some time and energy for a
-% code-cleanup (read: to remedy the consequences of my bad programming practices and general
-% disorganization).
-%
-% The requirement for e\TeX\ will probably stay. If nothing else, \foRest; is heavy on boxes: every
-% node requires its own \dots\ and consequently, I have freely used e\TeX\ constructs in the code
-% \dots
-%
-% \paragraph{\PGF; internals} \FoRest; relies on some details of \PGF; implementation, like the name
-% of the ``not yet positioned'' nodes. Thus, a new bug might appear with the development of \PGF;.
-% If you notice one, please let me know.
-%
-% \paragraph{Edges cutting through sibling nodes}
-% \label{sec:cutting-edge}
-%
-% In the following example, the R--B edge crosses the AAA node, although \ikeyname{ignore edge} is
-% set to the default |false|.
-% \begin{forestexample}[ekeynames={calign,{first,aspect=calign},align,{center,aspect=align},base,{bottom,aspect=base}}]
-% \begin{forest}
-% calign=first
-% [R[AAAAAAAAAA\\AAAAAAAAAA\\AAAAAAAAAA,align=center,base=bottom][B]]
-% \end{forest}
-% \end{forestexample}
-% This happens because s-distances between the adjacent children are
-% computed before child alignment (which is obviously the correct order in the general case), but
-% child alignment non-linearly influences the edges. Observe that the with a different value of
-% \ikeyname{calign}, the problem does not arise.
-% \begin{forestexample}[ekeynames={calign,{last,aspect=calign},align,{center,aspect=align},base,{bottom,aspect=base}}]
-% \begin{forest}
-% calign=last
-% [R[AAAAAAAAAA\\AAAAAAAAAA\\AAAAAAAAAA,align=center,base=bottom][B]]
-% \end{forest}
-% \end{forestexample}
-% While it would be possible to fix the situation after child alignment (at least for some child
-% alignment methods), I have decided against that, since the distances between siblings would soon
-% become too large. If the AAA node in the example above was large enough, B could easily be pushed
-% off the paper. The bottomline is, please use manual adjustment to fix such situations.
-%
-% \paragraph{Orphans}
-% \label{sec:orphans}
-%
-% If the \ikeyname{l} coordinates of adjacent children are too different (as a result of manual adjustment or
-% tier alignment), the packing algorithm might have nothing so say about the desired distance
-% between them: in this sense, node C below is an ``orphan.''
-% \begin{forestexample}[ekeynames={for tree,s sep,l,*}]
-% \begin{forest}
-% for tree={s sep=0,draw},
-% [R[A][B][C,l*=2][D][E]]
-% \end{forest}
-% \end{forestexample}
-% To prevent orphans from ending up just anywhere, I have decided to vertically align them with
-% their preceding sibling --- although I'm not certain that's really the best solution. In other
-% words, you can rely that the sequence of s-coordinates of siblings is non-decreasing.
-%
-% The decision also incluences a similar situation, illustrated below. The packing algorithm puts
-% node E immediately next to B (i.e.\ under C): however, the monotonicity-retaining mechanism then
-% vertically aligns it with its preceding sibling, D.
-% \begin{forestexample}[ekeynames={for tree,s sep,tier}]
-% \begin{forest}
-% for tree={s sep=0,draw},
-% [R[A[B,tier=bottom]][C][D][E,tier=bottom]]
-% \end{forest}
-% \end{forestexample}
-%
-% Obviously, both examples also create the situation of an edge crossing some sibling node(s).
-% Again, I don't think anything sensible can be done about this, in general.
-%
-% \section{Changelog}
-%
-% \begin{description}
-% \item[v1.0.10 (2015/07/22)] \mbox{}
-% \begin{compactitem}
-% \item Bugfix: a left-over debugging |\typeout| command was interfering with a |forest| within |tabular|, see \href{http://tex.stackexchange.com/questions/256509/odd-incompatibility-between-multi-line-forest-nodes-and-tabular}{this question on TeX.SE}.
-% \item A somewhat changed versioning scheme \dots
-% \end{compactitem}
-% \item[v1.09 (2015/07/15)] \mbox{}
-% \begin{compactitem}
-% \item Bugfix: child alignment was not done in nodes with a single child, see \href{http://tex.stackexchange.com/questions/255309/elementary-forest-question-meaning-of-calign-parent-anchor-and-child-anchor}{this question on TeX.SE}.
-% \end{compactitem}
-% \item[v1.08 (2015/07/10)] \mbox{}
-% \begin{compactitem}
-% \item Fix externalization (compatibility with new |tikz| features).
-% \end{compactitem}
-% \item[v1.07 (2015/05/29)] \mbox{}
-% \begin{compactitem}
-% \item Require package |elocalloc| for local boxes, which were previously defined by package |etex|.
-% \end{compactitem}
-% \item[v1.06 (2015/05/04)] \mbox{}
-% \begin{compactitem}
-% \item Load |etex| package: since v2.1a, |etoolbox| doesn't do it anymore.
-% \end{compactitem}
-% \item[v1.05 (2014/03/07)] \mbox{}
-% \begin{compactitem}
-% \item Fix the node boundary code for rounded rectangle. (Patch contributed by Paul Gaborit.)
-% \end{compactitem}
-% \item[v1.04 (2013/10/17)] \mbox{}
-% \begin{compactitem}
-% \item Fixed an \href{http://tex.stackexchange.com/questions/138986/error-using-tikzexternalize-with-forest/139145}{externalization bug}.
-% \end{compactitem}
-% \item[v1.03 (2013/01/28)] \mbox{}
-% \begin{compactitem}
-% \item Bugfix: options of dynamically created nodes didn't get processed.
-% \item Bugfix: the bracket parser was losing spaces before opening braces.
-% \item Bugfix: a family of utility macros dealing with affixing token lists was not expanding
-% content correctly.
-% \item Added style \ikeyname{math content}.
-% \item Replace key \keyname{tikz preamble} with more general \ikeyname{begin draw} and
-% \ikeyname{end draw}.
-% \item Add keys \ikeyname{begin forest} and \ikeyname{end forest}.
-% \end{compactitem}
-% \item[v1.02 (2013/01/20)] \mbox{}
-% \begin{compactitem}
-% \item Reworked style \ikeyname{stages}: it's easier to modify the processing flow now.
-% \item Individual stages must now be explicitely called in the context of some (usually root)
-% node.
-% \item Added \ikeyname{delay n} and \ikeyname{if have delayed}.
-% \item Added (experimental) \ikeyname{pack'}.
-% \item Added reference to the \href{https://github.com/sasozivanovic/forest-styles}{style
-% repository}.
-% \end{compactitem}
-% \item[v1.01 (2012/11/14)] \mbox{}
-%
-% \begin{compactitem}
-% \item Compatibility with the |standalone| package: temporarily disable the effect of
-% |standalone|'s package option |tikz| while typesetting nodes.
-% \item Require at least the [2010/08/21] (v2.0) release of package |etoolbox|.
-% \item Require version [2010/10/13] (v2.10, rcs-revision 1.76) of \PGF;/\TikZ;. Future
-% compatibility: adjust to the change of the ``not yet positioned'' node name (2.10 |@|
-% $\rightarrow$ 2.10-csv |PGFINTERNAL|).
-% \item Add this changelog.
-% \end{compactitem}
-% \item[v1.0 (2012/10/31)] First public version
-% \end{description}
-%
-% \paragraph{Acknowledgements} Many thanks to the \TeX\ SE community and the people who have reported bugs! In the
-% chronological order: Markus P\"ochtrager, Timothy Dozat, Ignasi Furio.\footnote{If you're in the
-% list but don't want to be, my apologies and please let me know about it!}
-%
-% \newpage
-% \part{Implementation}
-%
% A disclaimer: the code could've been much cleaner and better-documented \dots
%
% Identification.
% \begin{macrocode}
-\ProvidesPackage{forest}[2015/07/15 v1.0.10 Drawing (linguistic) trees]
+\ProvidesPackage{forest}[2015/01/30 v2.0.0 Drawing (linguistic) trees]
-\RequirePackage{tikz}[2010/10/13]
+\RequirePackage{tikz}[2013/12/13]
\usetikzlibrary{shapes}
\usetikzlibrary{fit}
\usetikzlibrary{calc}
@@ -4054,8 +86,10 @@
\RequirePackage{etoolbox}[2010/08/21]
\RequirePackage{elocalloc}% for \locbox
\RequirePackage{environ}
+\RequirePackage{xparse}
+
+% \usepackage[trace]{trace-pgfkeys}
- %\usepackage[trace]{trace-pgfkeys}
% \end{macrocode}
%
% |/forest| is the root of the key hierarchy.
@@ -4064,267 +98,80 @@
\def\forestset#1{\pgfqkeys{/forest}{#1}}
% \end{macrocode}
%
-% \section{Patches}
-% These patches apply to pgf/tikz 2.10.
-%
-% Serious: forest cannot load if this is not patched; disable
-% \texttt{/handlers/.wrap n pgfmath} for n=6,7,8 if you cannot patch.
+% \section{Package options}
% \begin{macrocode}
-\long\def\forest@original@pgfkeysdefnargs@#1#2#3#4{%
- \ifcase#2\relax
- \pgfkeyssetvalue{#1/.@args}{}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8##9}%
- \else
- \pgfkeys@error{\string\pgfkeysdefnargs: expected <= 9 arguments, got #2}%
- \fi
- \pgfkeysgetvalue{#1/.@args}\pgfkeys@tempargs
- \def\pgfkeys@temp{\expandafter#4\csname pgfk@#1/.@@body\endcsname}%
- \expandafter\pgfkeys@temp\pgfkeys@tempargs{#3}%
- % eliminate the \pgfeov at the end such that TeX gobbles spaces
- % by using
- % \pgfkeysdef{#1}{\pgfkeysvalueof{#1/.@@body}##1}
- % (with expansion of '#1'):
- \edef\pgfkeys@tempargs{\noexpand\pgfkeysvalueof{#1/.@@body}}%
- \def\pgfkeys@temp{\pgfkeysdef{#1}}%
- \expandafter\pgfkeys@temp\expandafter{\pgfkeys@tempargs##1}%
- \pgfkeyssetvalue{#1/.@body}{#3}%
+\newif\ifforest@external@
+\newif\ifforesttikzcshack
+\newif\ifforest@install@keys@to@tikz@path@
+\newif\ifforestdebug
+\def\forest@compat{}
+\forestset{package@options/.cd,
+ external/.is if=forest@external@,
+ tikzcshack/.is if=foresttikzcshack,
+ tikzinstallkeys/.is if=forest@install@keys@to@tikz@path@,
+ debug/.is if=forestdebug,
+ compat/.store in=\forest@compat,
+ compat/.default=most,
+ .unknown/.code={% load library
+ \eappto\forest@loadlibrarieslater{%
+ \noexpand\useforestlibrary{\pgfkeyscurrentname}%
+ \noexpand\forestapplylibrarydefaults{\pgfkeyscurrentname}%
+ }%
+ },
}
-
-\long\def\forest@patched@pgfkeysdefnargs@#1#2#3#4{%
- \ifcase#2\relax
- \pgfkeyssetvalue{#1/.@args}{}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
- %%%%% removed:
- %%%%% \or
- %%%%% \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8##9}%
- \else
- \pgfkeys@error{\string\pgfkeysdefnargs: expected <= 9 arguments, got #2}%
- \fi
- \pgfkeysgetvalue{#1/.@args}\pgfkeys@tempargs
- \def\pgfkeys@temp{\expandafter#4\csname pgfk@#1/.@@body\endcsname}%
- \expandafter\pgfkeys@temp\pgfkeys@tempargs{#3}%
- % eliminate the \pgfeov at the end such that TeX gobbles spaces
- % by using
- % \pgfkeysdef{#1}{\pgfkeysvalueof{#1/.@@body}##1}
- % (with expansion of '#1'):
- \edef\pgfkeys@tempargs{\noexpand\pgfkeysvalueof{#1/.@@body}}%
- \def\pgfkeys@temp{\pgfkeysdef{#1}}%
- \expandafter\pgfkeys@temp\expandafter{\pgfkeys@tempargs##1}%
- \pgfkeyssetvalue{#1/.@body}{#3}%
-}
-\ifx\pgfkeysdefnargs@\forest@original@pgfkeysdefnargs@
- \let\pgfkeysdefnargs@\forest@patched@pgfkeysdefnargs@
-\fi
+\forest@install@keys@to@tikz@path@true
+\foresttikzcshacktrue
+\def\forest@loadlibrarieslater{}
+\AtEndOfPackage{\forest@loadlibrarieslater}
+\def\useforestlibrary#1{\forcsvlist\useforestlibrary@{#1}}
+\def\useforestlibrary@#1{\RequirePackage{forest-lib-#1}}
+\def\forestapplylibrarydefaults#1{\forcsvlist\forestapplylibrarydefaults@{#1}}
+\def\forestapplylibrarydefaults@#1{\forestset{libraries/#1/defaults/.try}}
+\NewDocumentCommand\ProvidesForestLibrary{m O{}}{\ProvidesPackage{forest-lib-#1}[#2]}
+\ProcessPgfPackageOptions{/forest/package@options}
% \end{macrocode}
+% \section{Patches}
%
-% Minor: a leaking space in the very first line.
-% \begin{macrocode}
-\def\forest@original@pgfpointintersectionoflines#1#2#3#4{%
- {
- %
- % Compute orthogonal vector to #1--#2
- %
- \pgf@process{#2}%
- \pgf@xa=\pgf@x%
- \pgf@ya=\pgf@y%
- \pgf@process{#1}%
- \advance\pgf@xa by-\pgf@x%
- \advance\pgf@ya by-\pgf@y%
- \pgf@ya=-\pgf@ya%
- % Normalise a bit
- \c@pgf@counta=\pgf@xa%
- \ifnum\c@pgf@counta<0\relax%
- \c@pgf@counta=-\c@pgf@counta\relax%
- \fi%
- \c@pgf@countb=\pgf@ya%
- \ifnum\c@pgf@countb<0\relax%
- \c@pgf@countb=-\c@pgf@countb\relax%
- \fi%
- \advance\c@pgf@counta by\c@pgf@countb\relax%
- \divide\c@pgf@counta by 65536\relax%
- \ifnum\c@pgf@counta>0\relax%
- \divide\pgf@xa by\c@pgf@counta\relax%
- \divide\pgf@ya by\c@pgf@counta\relax%
- \fi%
- %
- % Compute projection
- %
- \pgf@xc=\pgf@sys@tonumber{\pgf@ya}\pgf@x%
- \advance\pgf@xc by\pgf@sys@tonumber{\pgf@xa}\pgf@y%
- %
- % The orthogonal vector is (\pgf@ya,\pgf@xa)
- %
- %
- % Compute orthogonal vector to #3--#4
- %
- \pgf@process{#4}%
- \pgf@xb=\pgf@x%
- \pgf@yb=\pgf@y%
- \pgf@process{#3}%
- \advance\pgf@xb by-\pgf@x%
- \advance\pgf@yb by-\pgf@y%
- \pgf@yb=-\pgf@yb%
- % Normalise a bit
- \c@pgf@counta=\pgf@xb%
- \ifnum\c@pgf@counta<0\relax%
- \c@pgf@counta=-\c@pgf@counta\relax%
- \fi%
- \c@pgf@countb=\pgf@yb%
- \ifnum\c@pgf@countb<0\relax%
- \c@pgf@countb=-\c@pgf@countb\relax%
- \fi%
- \advance\c@pgf@counta by\c@pgf@countb\relax%
- \divide\c@pgf@counta by 65536\relax%
- \ifnum\c@pgf@counta>0\relax%
- \divide\pgf@xb by\c@pgf@counta\relax%
- \divide\pgf@yb by\c@pgf@counta\relax%
- \fi%
- %
- % Compute projection
- %
- \pgf@yc=\pgf@sys@tonumber{\pgf@yb}\pgf@x%
- \advance\pgf@yc by\pgf@sys@tonumber{\pgf@xb}\pgf@y%
- %
- % The orthogonal vector is (\pgf@yb,\pgf@xb)
- %
- % Setup transformation matrx (this is just to use the matrix
- % inversion)
- %
- \pgfsettransform{{\pgf@sys@tonumber\pgf@ya}{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@xa}{\pgf@sys@tonumber\pgf@xb}{0pt}{0pt}}%
- \pgftransforminvert%
- \pgf@process{\pgfpointtransformed{\pgfpoint{\pgf@xc}{\pgf@yc}}}%
+% This macro implements a fairly safe patching mechanism: the code is only patched if the original
+% hasn't changed. If it did change, a warning message is printed. (This produces a spurious warning
+% when the new version of the code fixes something else too, but what the heck.)
+%
+% \begin{macrocode}
+\def\forest@patch#1#2#3#4#5{%
+ % #1 = cs to be patched
+ % %2 = purpose of the patch
+ % #3 = macro arguments
+ % #4 = original code
+ % #5 = patched code
+ \csdef{forest@original@#1}#3{#4}%
+ \csdef{forest@patched@#1}#3{#5}%
+ \ifcsequal{#1}{forest@original@#1}{%
+ \csletcs{#1}{forest@patched@#1}%
+ }{%
+ \ifcsequal{#1}{forest@patched@#1}{% all is good, the patch is in!
+ }{%
+ \PackageWarning{forest}{Failed patching '\expandafter\string\csname #1\endcsname'. Purpose of the patch: #2}%
+ }%
}%
}
-\def\forest@patched@pgfpointintersectionoflines#1#2#3#4{%
- {% added the percent sign in this line
- %
- % Compute orthogonal vector to #1--#2
- %
- \pgf@process{#2}%
- \pgf@xa=\pgf@x%
- \pgf@ya=\pgf@y%
- \pgf@process{#1}%
- \advance\pgf@xa by-\pgf@x%
- \advance\pgf@ya by-\pgf@y%
- \pgf@ya=-\pgf@ya%
- % Normalise a bit
- \c@pgf@counta=\pgf@xa%
- \ifnum\c@pgf@counta<0\relax%
- \c@pgf@counta=-\c@pgf@counta\relax%
- \fi%
- \c@pgf@countb=\pgf@ya%
- \ifnum\c@pgf@countb<0\relax%
- \c@pgf@countb=-\c@pgf@countb\relax%
- \fi%
- \advance\c@pgf@counta by\c@pgf@countb\relax%
- \divide\c@pgf@counta by 65536\relax%
- \ifnum\c@pgf@counta>0\relax%
- \divide\pgf@xa by\c@pgf@counta\relax%
- \divide\pgf@ya by\c@pgf@counta\relax%
- \fi%
- %
- % Compute projection
- %
- \pgf@xc=\pgf@sys@tonumber{\pgf@ya}\pgf@x%
- \advance\pgf@xc by\pgf@sys@tonumber{\pgf@xa}\pgf@y%
- %
- % The orthogonal vector is (\pgf@ya,\pgf@xa)
- %
- %
- % Compute orthogonal vector to #3--#4
- %
- \pgf@process{#4}%
- \pgf@xb=\pgf@x%
- \pgf@yb=\pgf@y%
- \pgf@process{#3}%
- \advance\pgf@xb by-\pgf@x%
- \advance\pgf@yb by-\pgf@y%
- \pgf@yb=-\pgf@yb%
- % Normalise a bit
- \c@pgf@counta=\pgf@xb%
- \ifnum\c@pgf@counta<0\relax%
- \c@pgf@counta=-\c@pgf@counta\relax%
- \fi%
- \c@pgf@countb=\pgf@yb%
- \ifnum\c@pgf@countb<0\relax%
- \c@pgf@countb=-\c@pgf@countb\relax%
- \fi%
- \advance\c@pgf@counta by\c@pgf@countb\relax%
- \divide\c@pgf@counta by 65536\relax%
- \ifnum\c@pgf@counta>0\relax%
- \divide\pgf@xb by\c@pgf@counta\relax%
- \divide\pgf@yb by\c@pgf@counta\relax%
- \fi%
- %
- % Compute projection
- %
- \pgf@yc=\pgf@sys@tonumber{\pgf@yb}\pgf@x%
- \advance\pgf@yc by\pgf@sys@tonumber{\pgf@xb}\pgf@y%
- %
- % The orthogonal vector is (\pgf@yb,\pgf@xb)
- %
- % Setup transformation matrx (this is just to use the matrix
- % inversion)
- %
- \pgfsettransform{{\pgf@sys@tonumber\pgf@ya}{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@xa}{\pgf@sys@tonumber\pgf@xb}{0pt}{0pt}}%
- \pgftransforminvert%
- \pgf@process{\pgfpointtransformed{\pgfpoint{\pgf@xc}{\pgf@yc}}}%
- }%
+% \end{macrocode}
+%
+% Patches for \PGF; 3.0.0 --- required version is [2013/12/13].
+% \begin{macrocode}
+\forest@patch{pgfgettransform}{fix a leaking space}{#1}{%
+ \edef#1{{\pgf@pt@aa}{\pgf@pt@ab}{\pgf@pt@ba}{\pgf@pt@bb}{\the\pgf@pt@x}{\the\pgf@pt@y}}
+}{%
+ \edef#1{{\pgf@pt@aa}{\pgf@pt@ab}{\pgf@pt@ba}{\pgf@pt@bb}{\the\pgf@pt@x}{\the\pgf@pt@y}}%
}
-
-\ifx\pgfpointintersectionoflines\forest@original@pgfpointintersectionoflines
- \let\pgfpointintersectionoflines\forest@patched@pgfpointintersectionoflines
-\fi
-
- % hah: hacking forest --- it depends on some details of PGF implementation
-\def\forest@pgf@notyetpositioned{not yet positionedPGFINTERNAL}%
-\expandafter\ifstrequal\expandafter{\pgfversion}{2.10}{%
- \def\forest@pgf@notyetpositioned{not yet positioned@}%
-}{}
% \end{macrocode}
-%
+%
% \section{Utilities}
%
% Escaping |\if|s.
% \begin{macrocode}
\long\def\@escapeif#1#2\fi{\fi#1}
\long\def\@escapeifif#1#2\fi#3\fi{\fi\fi#1}
+\long\def\@escapeififif#1#2\fi#3\fi#4\fi{\fi\fi\fi#1}
% \end{macrocode}
%
% A factory for creating |\...loop...| macros.
@@ -4349,15 +196,70 @@
}%
}%
% \end{macrocode}
+%
+% 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.
+% \begin{macrocode}
+\def\newsafeloop#1{%
+ \csdef{safeloop@#1}##1\saferepeat{%
+ \edef\safeloop@marshal{%
+ \noexpand\csdef{safeiterate@#1}{%
+ \unexpanded{##1}\relax
+ \noexpand\expandafter
+ \expandonce{\csname safeiterate@#1\endcsname}%
+ \noexpand\fi
+ }%
+ }\safeloop@marshal
+ \csuse{safeiterate@#1}%
+ \advance\noexpand\safeloop@depth-1\relax
+ \cslet{safeiterate@#1}\relax
+ }%
+}%
+\newcount\safeloop@depth
+\def\safeloop{%
+ \advance\safeloop@depth1
+ \ifcsdef{safeloop@\the\safeloop@depth}{}{\expandafter\newsafeloop\expandafter{\the\safeloop@depth}}%
+ \csdef{safeloopn@\the\safeloop@depth}{0}%
+ \csuse{safeloop@\the\safeloop@depth}%
+ \csedef{safeloopn@\the\safeloop@depth}{\number\numexpr\csuse{safeloopn@\the\safeloop@depth}+1}%
+}
+\let\saferepeat\fi
+\def\safeloopn{\csuse{safeloopn@\the\safeloop@depth}}%
+% \end{macrocode}
+%
+% Another safeloop for usage with ``repeat'' / ``while'' // ``until'' keys, so that the user can refer to loop $n$s for outer loops.
+% \begin{macrocode}
+\def\newsafeRKloop#1{%
+ \csdef{safeRKloop@#1}##1\safeRKrepeat{%
+ \edef\safeRKloop@marshal{%
+ \noexpand\csdef{safeRKiterate@#1}{%
+ \unexpanded{##1}\relax
+ \noexpand\expandafter
+ \expandonce{\csname safeRKiterate@#1\endcsname}%
+ \noexpand\fi
+ }%
+ }\safeRKloop@marshal
+ \csuse{safeRKiterate@#1}%
+ \advance\noexpand\safeRKloop@depth-1\relax
+ \cslet{safeRKiterate@#1}\relax
+ }%
+ \expandafter\newif\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
+}%
+\newcount\safeRKloop@depth
+\def\safeRKloop{%
+ \advance\safeRKloop@depth1
+ \ifcsdef{safeRKloop@\the\safeRKloop@depth}{}{\expandafter\newsafeRKloop\expandafter{\the\safeRKloop@depth}}%
+ \csdef{safeRKloopn@\the\safeRKloop@depth}{0}%
+ \csuse{safeRKbreak@\the\safeRKloop@depth false}%
+ \csuse{safeRKloop@\the\safeRKloop@depth}%
+ \csedef{safeRKloopn@\the\safeRKloop@depth}{\number\numexpr\csuse{safeRKloopn@\the\safeRKloop@depth}+1}%
+}
+\let\safeRKrepeat\fi
+\def\safeRKloopn{\csuse{safeRKloopn@\the\safeRKloop@depth}}%
+% \end{macrocode}
%
% Additional loops (for embedding).
% \begin{macrocode}
\newloop\forest@loop
-\newloop\forest@loopa
-\newloop\forest@loopb
-\newloop\forest@loopc
-\newloop\forest@sort@loop
-\newloop\forest@sort@loopA
% \end{macrocode}
% New counters, dimens, ifs.
% \begin{macrocode}
@@ -4366,10 +268,12 @@
\newcount\forest@n
\newif\ifforest@temp
\newcount\forest@temp@global@count
+\newtoks\forest@temp@toks
% \end{macrocode}
%
% Appending and prepending to token lists.
% \begin{macrocode}
+\def\etotoks#1#2{\edef\pot@temp{#2}\expandafter#1\expandafter{\pot@temp}}
\def\apptotoks#1#2{\expandafter#1\expandafter{\the#1#2}}
\long\def\lapptotoks#1#2{\expandafter#1\expandafter{\the#1#2}}
\def\eapptotoks#1#2{\edef\pot@temp{#2}\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter#1\pot@temp}}
@@ -4485,6 +389,157 @@
}
% \end{macrocode}
%
+% Utilities dealing with pgfkeys.
+% \begin{macrocode}
+\def\forest@copycommandkey#1#2{% copies command of #1 into #2
+ \pgfkeysifdefined{#1/.@cmd}{}{%
+ \PackageError{forest}{Key #1 is not a command key}{}%
+ }%
+ \pgfkeysgetvalue{#1/.@cmd}\forest@temp
+ \pgfkeyslet{#2/.@cmd}\forest@temp
+ \pgfkeysifdefined{#1/.@args}{%
+ \pgfkeysgetvalue{#1/.@args}\forest@temp
+ \pgfkeyslet{#2/.@args}\forest@temp
+ }{}%
+ \pgfkeysifdefined{#1/.@body}{%
+ \pgfkeysgetvalue{#1/.@body}\forest@temp
+ \pgfkeyslet{#2/.@body}\forest@temp
+ }{}%
+ \pgfkeysifdefined{#1/.@@body}{%
+ \pgfkeysgetvalue{#1/.@@body}\forest@temp
+ \pgfkeyslet{#2/.@@body}\forest@temp
+ }{}%
+ \pgfkeysifdefined{#1/.@def}{%
+ \pgfkeysgetvalue{#1/.@def}\forest@temp
+ \pgfkeyslet{#2/.@def}\forest@temp
+ }{}%
+}
+\forestset{
+ copy command key/.code 2 args={\forest@copycommandkey{#1}{#2}},
+ autoforward/.code 2 args={\forest@autoforward{#1}{#2={#1={##1}}}{true}},
+ autoforward'/.code 2 args={\forest@autoforward{#1}{#2-=#1,#2={#1={##1}}}{true}},
+ Autoforward/.code 2 args={\forest@autoforward{#1}{#2}{true}},
+ autoforward register/.code 2 args={\forest@autoforward{#1}{#2={#1={##1}}}{false}},
+ autoforward register'/.code 2 args={\forest@autoforward{#1}{#2-=#1,#2={#1={##1}}}{false}},
+ Autoforward register/.code 2 args={\forest@autoforward{#1}{#2}{false}},
+ copy command key@if it exists/.code 2 args={%
+ \pgfkeysifdefined{#1/.@cmd}{%
+ \forest@copycommandkey{#1}{#2}%
+ }{}%
+ },
+ unautoforward/.style={
+ typeout={unautoforwarding #1},
+ copy command key@if it exists={/forest/autoforwarded #1}{/forest/#1},
+ copy command key@if it exists={/forest/autoforwarded #1+}{/forest/#1+},
+ copy command key@if it exists={/forest/autoforwarded #1-}{/forest/#1-},
+ copy command key@if it exists={/forest/autoforwarded #1*}{/forest/#1*},
+ copy command key@if it exists={/forest/autoforwarded #1:}{/forest/#1:},
+ copy command key@if it exists={/forest/autoforwarded #1'}{/forest/#1'},
+ copy command key@if it exists={/forest/autoforwarded #1+'}{/forest/#1+'},
+ copy command key@if it exists={/forest/autoforwarded #1-'}{/forest/#1-'},
+ copy command key@if it exists={/forest/autoforwarded #1*'}{/forest/#1*'},
+ copy command key@if it exists={/forest/autoforwarded #1:'}{/forest/#1:'},
+ copy command key@if it exists={/forest/autoforwarded +#1}{/forest/+#1},
+ },
+ /handlers/.undef/.code={\csundef{pgfk@\pgfkeyscurrentpath}},
+ undef option/.style={
+ /forest/#1/.undef,
+ /forest/#1/.@cmd/.undef,
+ /forest/#1+/.@cmd/.undef,
+ /forest/#1-/.@cmd/.undef,
+ /forest/#1*/.@cmd/.undef,
+ /forest/#1:/.@cmd/.undef,
+ /forest/#1'/.@cmd/.undef,
+ /forest/#1+'/.@cmd/.undef,
+ /forest/#1-'/.@cmd/.undef,
+ /forest/#1*'/.@cmd/.undef,
+ /forest/#1:'/.@cmd/.undef,
+ /forest/+#1/.@cmd/.undef,
+ /forest/TeX={\patchcmd{\forest@node@init}{\forestoinit{#1}}{}{}{}},
+ },
+ undef register/.style={undef option={#1}},
+}
+\def\forest@autoforward#1#2#3{%
+ % #1 = option name
+ % #2 = code of a style taking one arg (new option value),
+ % which expands to whatever should be done with the new value
+ % autoforward(') adds to the keylist (arg#2)
+ % #3 = true=option, false=register
+ \forest@autoforward@createforwarder{}{#1}{}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{+}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{-}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{*}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{:}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{'}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{+'}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{-'}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{*'}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{:'}{#2}{#3}%
+ \forest@autoforward@createforwarder{+}{#1}{}{#2}{#3}%
+}
+\def\forest@autoforward@createforwarder#1#2#3#4#5{%
+ % #1=prefix, #2=option name, #3=suffix, #4=macro code (#2 above), #5=option or register
+ \pgfkeysifdefined{/forest/#1#2#3/.@cmd}{%
+ \forest@copycommandkey{/forest/#1#2#3}{/forest/autoforwarded #1#2#3}%
+ \pgfkeyssetvalue{/forest/autoforwarded #1#2#3/option@name}{#2}%
+ \pgfkeysdef{/forest/#1#2#3}{%
+ \pgfkeysalso{autoforwarded #1#2#3={##1}}%
+ \def\forest@temp@macro####1{#4}%
+ \csname forest@temp#5\endcsname
+ \edef\forest@temp@value{\ifforest@temp\expandafter\forestOv\expandafter{\expandafter\forest@setter@node\expandafter}\else\expandafter\forestrv\fi{#2}}%
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\pgfkeysalso\expandafter\expandafter\expandafter{\expandafter\forest@temp@macro\expandafter{\forest@temp@value}}%
+ }%
+ }{}%
+}
+\def\forest@node@removekeysfromkeylist#1#2{% #1 = keys to remove, #2 = option name
+ \edef\forest@marshal{%
+ \noexpand\forest@removekeysfromkeylist{\unexpanded{#1}}{\forestov{#2}}\noexpand\forest@temp@toks}\forest@marshal
+ \forestoeset{#2}{\the\forest@temp@toks}%
+}
+\def\forest@removekeysfromkeylist#1#2#3{%
+ % #1 = keys to remove (a keylist: an empty value means remove a key with any value)
+ % #2 = keylist
+ % #3 = toks cs for result
+ \forest@temp@toks{}%
+ \def\forestnovalue{\forestnovalue}%
+ \pgfqkeys{/forest/remove@key@installer}{#1}%
+ \let\forestnovalue\pgfkeysnovaluetext
+ \pgfqkeys{/forest/remove@key}{#2}%
+ \pgfqkeys{/forest/remove@key@uninstaller}{#1}%
+ #3\forest@temp@toks
+}
+\def\forest@remove@key@novalue{\forest@remove@key@novalue}%
+\forestset{
+ remove@key@installer/.unknown/.code={% #1 = (outer) value
+ \def\forest@temp{#1}%
+ \ifx\forest@temp\pgfkeysnovalue@text
+ \pgfkeysdef{/forest/remove@key/\pgfkeyscurrentname}{}%
+ \else
+ \ifx\forest@temp\forestnovalue
+ \expandafter\forest@remove@key@installer@defwithvalue\expandafter{\pgfkeyscurrentname}{\pgfkeysnovalue}%
+ \else
+ \expandafter\forest@remove@key@installer@defwithvalue\expandafter{\pgfkeyscurrentname}{#1}%
+ \fi
+ \fi
+ },
+ remove@key/.unknown/.code={% #1 = (inner) value
+ \expandafter\apptotoks\expandafter\forest@temp@toks\expandafter{\pgfkeyscurrentname={#1},}%
+ },
+ remove@key@uninstaller/.unknown/.code={%
+ \pgfkeyslet{/forest/remove@key/\pgfkeyscurrentname/.@cmd}\@undefined},
+}
+\def\forest@remove@key@installer@defwithvalue#1#2{% #1=key name, #2 = outer value
+ \pgfkeysdef{/forest/remove@key/#1}{% ##1 = inner value
+ \def\forest@temp@outer{#2}%
+ \def\forest@temp@inner{##1}%
+ \ifx\forest@temp@outer\forest@temp@inner
+ \else
+ \apptotoks\forest@temp@toks{#1={##1},}%
+ \fi
+ }%
+}
+% \end{macrocode}
+%
% \subsection{Sorting}
%
% Macro |\forest@sort| is the user interface to sorting.
@@ -4564,6 +619,8 @@
% Quick sort macro (adapted from
% \href{http://www.ctan.org/pkg/laansort}{laansort}).
% \begin{macrocode}
+\newloop\forest@sort@loop
+\newloop\forest@sort@loopA
\def\forest@quicksort#1#2{%
% \end{macrocode}
% Compute the index of the middle element (|\forest@sort@m|).
@@ -4644,10 +701,11 @@
% We defines the item-exchange macro in terms of the (user-provided)
% array let macro.
% \begin{macrocode}
+\def\forest@sort@aux{aux}
\def\forest@sort@xch#1#2{%
- \forest@sort@let{aux}{#1}%
+ \forest@sort@let{\forest@sort@aux}{#1}%
\forest@sort@let{#1}{#2}%
- \forest@sort@let{#2}{aux}%
+ \forest@sort@let{#2}{\forest@sort@aux}%
}
% \end{macrocode}
% Insertion sort.
@@ -4663,7 +721,7 @@
}
\newif\ifforest@insertionsort@loop
\def\forest@insertionsort@Qbody{%
- \forest@sort@let{aux}{\the\forest@sort@m}%
+ \forest@sort@let{\forest@sort@aux}{\the\forest@sort@m}%
\forest@sort@k\forest@sort@m
\advance\forest@sort@k -1
\forest@insertionsort@looptrue
@@ -4672,10 +730,10 @@
\forest@insertionsort@qbody
\forest@sort@repeat
\advance\forest@sort@k 1
- \forest@sort@let{\the\forest@sort@k}{aux}%
+ \forest@sort@let{\the\forest@sort@k}{\forest@sort@aux}%
}
\def\forest@insertionsort@qbody{%
- \forest@sort@cmp{\the\forest@sort@k}{aux}%
+ \forest@sort@cmp{\the\forest@sort@k}{\forest@sort@aux}%
\ifx\forest@sort@direction\forest@sort@cmp@result\relax
\forest@sort@p=\forest@sort@k
\advance\forest@sort@p 1
@@ -4754,12 +812,12 @@
\c@pgf@countc=#2
\c@pgf@countd=#3
\advance\c@pgf@countd -1
- \forest@loopa
+ \safeloop
\ifnum\c@pgf@countc<\c@pgf@countd\relax
\forest@sort@xch{\the\c@pgf@countc}{\the\c@pgf@countd}%
\advance\c@pgf@countc 1
\advance\c@pgf@countd -1
- \forest@repeata
+ \saferepeat
}
% \end{macrocode}
%
@@ -4782,9 +840,9 @@
action character,
new node/.code n args={3}{% #1=preamble, #2=node spec, #3=cs receiving the id
\forest@node@new#3%
- \forestOset{#3}{given options}{content'=#2}%
+ \forestOeset{#3}{given options}{\forest@contentto=\unexpanded{#2}}%
\ifblank{#1}{}{%
- \forestOpreto{#3}{given options}{#1,}%
+ \forestrset{preamble}{#1}%
}%
},
set afterthought/.code 2 args={% #1=node id, #2=afterthought
@@ -5184,9 +1242,14 @@
% full expansion expands all the way
\def\forestove#1{\pgfkeysvalueof{/forest/@node/\forest@cn/#1}}
% full expansion expands to the cs holding the value
-\def\forestom#1{\expandafter\expandonce\expandafter{\pgfkeysvalueof{/forest/@node/\forest@cn/#1}}}\def\forestoget#1#2{\pgfkeysgetvalue{/forest/@node/\forest@cn/#1}{#2}}
+\def\forestom#1{\expandafter\expandonce\expandafter{\pgfkeysvalueof{/forest/@node/\forest@cn/#1}}}
\def\forestoget#1#2{\pgfkeysgetvalue{/forest/@node/\forest@cn/#1}{#2}}
\def\forestolet#1#2{\pgfkeyslet{/forest/@node/\forest@cn/#1}{#2}}
+\def\forestocslet#1#2{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeyslet{/forest/@node/\forest@cn/#1}{\expandonce{\csname#2\endcsname}}%
+ }\forest@marshal
+}
\def\forestoset#1#2{\pgfkeyssetvalue{/forest/@node/\forest@cn/#1}{#2}}
\def\forestoeset#1#2{%
\edef\forest@option@temp{%
@@ -5215,6 +1278,11 @@
\def\forestOget#1#2#3{\pgfkeysgetvalue{/forest/@node/#1/#2}{#3}}
\def\forestOget#1#2#3{\pgfkeysgetvalue{/forest/@node/#1/#2}{#3}}
\def\forestOlet#1#2#3{\pgfkeyslet{/forest/@node/#1/#2}{#3}}
+\def\forestOcslet#1#2#3{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeyslet{/forest/@node/#1/#2}{\expandonce{\csname#3\endcsname}}%
+ }\forest@marshal
+}
\def\forestOset#1#2#3{\pgfkeyssetvalue{/forest/@node/#1/#2}{#3}}
\def\forestOeset#1#2#3{%
\edef\forestoption@temp{%
@@ -5249,6 +1317,43 @@
\forestoget{#2}\forestoption@temp
\forestolet{#1}\forestoption@temp}
% \end{macrocode}
+% Macros for retrieving/setting registers.
+% \begin{macrocode}
+ % full expansion expands precisely to the value
+\def\forestrv#1{\expandafter\expandafter\expandafter\expandonce
+ \pgfkeysvalueof{/forest/@node/register/#1}}
+ % full expansion expands all the way
+\def\forestrve#1{\pgfkeysvalueof{/forest/@node/register/#1}}
+ % full expansion expands to the cs holding the value
+\def\forestrm#1{\expandafter\expandonce\expandafter{\pgfkeysvalueof{/forest/@node/register/#1}}}
+\def\forestrget#1#2{\pgfkeysgetvalue{/forest/@node/register/#1}{#2}}
+\def\forestrlet#1#2{\pgfkeyslet{/forest/@node/register/#1}{#2}}
+\def\forestrcslet#1#2{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeyslet{/forest/@node/register/#1}{\expandonce{\csname#2\endcsname}}%
+ }\forest@marshal
+}
+\def\forestrset#1#2{\pgfkeyssetvalue{/forest/@node/register/#1}{#2}}
+\def\forestreset#1#2{%
+ \edef\forest@option@temp{%
+ \noexpand\pgfkeyssetvalue{/forest/@node/register/#1}{#2}%
+ }\forest@option@temp
+}
+\def\forestrappto#1#2{%
+ \forestreset{#1}{\forestrv{#1}\unexpanded{#2}}%
+}
+\def\forestrpreto#1#2{%
+ \forestreset{#1}{\unexpanded{#2}\forestrv{#1}}%
+}
+\def\forestrifdefined#1#2#3{%
+ \pgfkeysifdefined{/forest/@node/register/#1}{#2}{#3}%
+}
+% \end{macrocode}
+% User macros for retrieving node options of the current node.
+% \begin{macrocode}
+\def\forestregister#1{\forestrv{#1}}
+\def\foresteregister#1{\forestrve{#1}}
+% \end{macrocode}
% Node initialization. Node option declarations append to |\forest@node@init|.
% \begin{macrocode}
\def\forest@node@init{%
@@ -5275,7 +1380,7 @@
\let\forestoinit@orig\forestoinit
\def\forest@node@copy#1#2{% #1=from node id, cs receiving the new node id
\advance\forest@node@maxid1
- \def\forestoinit##1{\forestoletO{##1}{#1}{##1}}%
+ \def\forestoinit##1{\ifstrequal{##1}{name}{\forestoset{name}{node@\forest@cn}}{\forestoletO{##1}{#1}{##1}}}%
\forest@fornode{\the\forest@node@maxid}{%
\forest@node@init
\forest@node@setname{\forest@copy@name@template{\forestOve{#1}{name}}}%
@@ -5401,7 +1506,7 @@
\fi
}
% \end{macrocode}
-% Looping methods.
+% Do some stuff and return to the current node.
% \begin{macrocode}
\def\forest@forthis#1{%
\edef\forest@node@marshal{\unexpanded{#1}\def\noexpand\forest@cn}%
@@ -5411,13 +1516,9 @@
\edef\forest@node@marshal{\edef\noexpand\forest@cn{#1}\unexpanded{#2}\def\noexpand\forest@cn}%
\expandafter\forest@node@marshal\expandafter{\forest@cn}%
}
-\def\forest@fornode@ifexists#1#2{%
- \edef\forest@node@temp{#1}%
- \ifnum\forest@node@temp=0
- \else
- \@escapeif{\expandnumberarg\forest@fornode{\forest@node@temp}{#2}}%
- \fi
-}
+% \end{macrocode}
+% Looping methods: children.
+% \begin{macrocode}
\def\forest@node@foreachchild#1{\forest@node@Foreachchild{\forest@cn}{#1}}
\def\forest@node@Foreachchild#1#2{%
\forest@fornode{\forestOve{#1}{@first}}{\forest@node@@forselfandfollowingsiblings{#2}}%
@@ -5432,25 +1533,172 @@
}%
\fi
}
-\def\forest@node@foreach#1{\forest@node@Foreach{\forest@cn}{#1}}
-\def\forest@node@Foreach#1#2{%
- \forest@fornode{#1}{\forest@node@@foreach{#2}}%
+\def\forest@node@@forselfandfollowingsiblings@reversed#1{%
+ \ifnum\forest@cn=0
+ \else
+ \@escapeif{%
+ \edef\forest@marshal{%
+ \noexpand\def\noexpand\forest@cn{\forestove{@next}}%
+ \noexpand\forest@node@@forselfandfollowingsiblings@reversed{\unexpanded{#1}}%
+ \noexpand\forest@fornode{\forest@cn}{\unexpanded{#1}}%
+ }\forest@marshal
+ }%
+ \fi
}
-\def\forest@node@@foreach#1{%
- \forest@forthis{#1}%
- \ifnum\forestove{@first}=0
- \else\@escapeif{%
- \edef\forest@cn{\forestove{@first}}%
- \forest@node@@forselfandfollowingsiblings{\forest@node@@foreach{#1}}%
+\def\forest@node@foreachchild@reversed#1{\forest@node@Foreachchild@reversed{\forest@cn}{#1}}
+\def\forest@node@Foreachchild@reversed#1#2{%
+ \forest@fornode{\forestOve{#1}{@last}}{\forest@node@@forselfandprecedingsiblings@reversed{#2}}%
+}
+\def\forest@node@@forselfandprecedingsiblings@reversed#1{%
+ \ifnum\forest@cn=0
+ \else
+ \forest@forthis{#1}%
+ \@escapeif{%
+ \edef\forest@cn{\forestove{@previous}}%
+ \forest@node@@forselfandprecedingsiblings@reversed{#1}%
+ }%
+ \fi
+}
+\def\forest@node@@forselfandprecedingsiblings#1{%
+ \ifnum\forest@cn=0
+ \else
+ \@escapeif{%
+ \edef\forest@marshal{%
+ \noexpand\def\noexpand\forest@cn{\forestove{@previous}}%
+ \noexpand\forest@node@@forselfandprecedingsiblings{\unexpanded{#1}}%
+ \noexpand\forest@fornode{\forest@cn}{\unexpanded{#1}}%
+ }\forest@marshal
}%
\fi
}
-\def\forest@node@foreachdescendant#1{\forest@node@Foreachdescendant{\forest@cn}{#1}}
+% \end{macrocode}
+% Looping methods: (sub)tree and descendants.
+% \begin{macrocode}
+\def\forest@node@@foreach#1#2#3#4{%
+ % #1 = do what
+ % #2 = do that -1=before,1=after processing children
+ % #3 & #4: normal or reversed order of children?
+ % #3 = @first/@last
+ % #4 = \forest@node@@forselfandfollowingsiblings / \forest@node@@forselfandprecedingsiblings@reversed
+ \ifnum#2<0 \forest@forthis{#1}\fi
+ \ifnum\forestove{#3}=0
+ \else\@escapeif{%
+ \forest@forthis{%
+ \edef\forest@cn{\forestove{#3}}%
+ #4{\forest@node@@foreach{#1}{#2}{#3}{#4}}%
+ }%
+ }\fi
+ \ifnum#2>0 \forest@forthis{#1}\fi
+}
+\def\forest@node@foreach#1{%
+ \forest@node@@foreach{#1}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}
+\def\forest@node@Foreach#1#2{%
+ \forest@fornode{#1}{\forest@node@@foreach{#2}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
+\def\forest@node@foreach@reversed#1{%
+ \forest@node@@foreach{#1}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}
+\def\forest@node@Foreach@reversed#1#2{%
+ \forest@fornode{#1}{\forest@node@@foreach{#2}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@foreach@childrenfirst#1{%
+ \forest@node@@foreach{#1}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}
+\def\forest@node@Foreach@childrenfirst#1#2{%
+ \forest@fornode{#1}{\forest@node@@foreach{#2}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
+\def\forest@node@foreach@childrenfirst@reversed#1{%
+ \forest@node@@foreach{#1}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}
+\def\forest@node@Foreach@childrenfirst@reversed#1#2{%
+ \forest@fornode{#1}{\forest@node@@foreach{#2}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@foreachdescendant#1{%
+ \forest@node@foreachchild{\forest@node@@foreach{#1}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
\def\forest@node@Foreachdescendant#1#2{%
- \forest@node@Foreachchild{#1}{%
- \forest@node@foreach{#2}%
+ \forest@node@Foreachchild{#1}{\forest@node@@foreach{#2}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
+\def\forest@node@foreachdescendant@reversed#1{%
+ \forest@node@foreachchild@reversed{\forest@node@@foreach{#1}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@Foreachdescendant@reversed#1#2{%
+ \forest@node@Foreachchild@reversed{#1}{\forest@node@@foreach{#2}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@foreachdescendant@childrenfirst#1{%
+ \forest@node@foreachchild{\forest@node@@foreach{#1}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
+\def\forest@node@Foreachdescendant@childrenfirst#1#2{%
+ \forest@node@Foreachchild{#1}{\forest@node@@foreach{#2}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
+\def\forest@node@foreachdescendant@childrenfirst@reversed#1{%
+ \forest@node@foreachchild@reversed{\forest@node@@foreach{#1}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@Foreachdescendant@childrenfirst@reversed#1#2{%
+ \forest@node@Foreachchild@reversed{#1}{\forest@node@@foreach{#2}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+% \end{macrocode}
+% Looping methods: breadth-first.
+% \begin{macrocode}
+\def\forest@node@foreach@breadthfirst#1#2{% #1 = max level, #2 = code
+ \forest@node@Foreach@breadthfirst@{\forest@cn}{@first}{@next}{#1}{#2}}
+\def\forest@node@foreach@breadthfirst@reversed#1#2{% #1 = max level, #2 = code
+ \forest@node@Foreach@breadthfirst@{\forest@cn}{@last}{@previous}{#1}{#2}}
+\def\forest@node@Foreach@breadthfirst#1#2#3{% #1 = node id, #2 = max level, #3 = code
+ \forest@node@Foreach@breadthfirst@{#1}{@first}{@next}{#2}{#3}}
+\def\forest@node@Foreach@breadthfirst@reversed#1#2#3{% #1 = node id, #2 = max level, #3 = code
+ \forest@node@Foreach@breadthfirst@{#1}{@last}{@previous}{#2}{#3}}
+\def\forest@node@Foreach@breadthfirst@#1#2#3#4#5{%
+ % #1 = root node,
+ % #2 = @first/@last, #3 = @next/@previous (must be in sync with #2),
+ % #4 = max level (< 0 means infinite)
+ % #5 = code to execute at each node
+ \forest@node@Foreach@breadthfirst@processqueue{#1,}{#2}{#3}{#4}{#5}%
+}
+\def\forest@node@Foreach@breadthfirst@processqueue#1#2#3#4#5{%
+ % #1 = queue,
+ % #2 = @first/@last, #3 = @next/@previous (must be in sync with #2),
+ % #4 = max level (< 0 means infinite)
+ % #5 = code to execute at each node
+ \ifstrempty{#1}{}{%
+ \forest@node@Foreach@breadthfirst@processqueue@#1\forest@node@Foreach@breadthfirst@processqueue@
+ {#2}{#3}{#4}{#5}%
+ }%
+}
+\def\forest@node@Foreach@breadthfirst@processqueue@#1,#2\forest@node@Foreach@breadthfirst@processqueue@#3#4#5#6{%
+ % #1 = first,
+ % #2 = rest,
+ % #3 = @first/@last, #4 = next/previous (must be in sync with #2),
+ % #5 = max level (< 0 means infinite)
+ % #6 = code to execute at each node
+ \forest@fornode{#1}{%
+ #6%
+ \ifnum#5<0
+ \forest@node@getlistofchildren\forest@temp{#3}{#4}%
+ \else
+ \ifnum\forestove{level}>#5\relax
+ \def\forest@temp{}%
+ \else
+ \forest@node@getlistofchildren\forest@temp{#3}{#4}%
+ \fi
+ \fi
+ \edef\forest@marshal{%
+ \noexpand\forest@node@Foreach@breadthfirst@processqueue{\unexpanded{#2}\forest@temp}%
+ {#3}{#4}{#5}{\unexpanded{#6}}%
+ }\forest@marshal
}%
}
+\def\forest@node@getlistofchildren#1#2#3{% #1 = list cs, #2 = @first/@last, #3 = @next/@previous
+ \forest@node@Getlistofchildren{\forest@cn}{#1}{#2}{#3}%
+}
+\def\forest@node@Getlistofchildren#1#2#3#4{% #1 = node, #2 = list cs, #3 = @first/@last, #4 = @next/@previous
+ \def#2{}%
+ \ifnum\forestove{#3}=0
+ \else
+ \eappto#2{\forestOve{#1}{#3},}%
+ \@escapeif{%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@Getlistofchildren@{\forestOve{#1}{#3}}\noexpand#2{#4}%
+ }\forest@marshal
+ }%
+ \fi
+}
+\def\forest@node@Getlistofchildren@#1#2#3{% #1 = node, #2 = list cs, #3 = @next/@previous
+ \ifnum\forestOve{#1}{#3}=0
+ \else
+ \eappto#2{\forestOve{#1}{#3},}%
+ \@escapeif{%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@Getlistofchildren@{\forestOve{#1}{#3}}\noexpand#2{#3}%
+ }\forest@marshal
+ }%
+ \fi
+}
% \end{macrocode}
%
% Compute |n|, |n'|, |n children| and |level|.
@@ -5459,7 +1707,12 @@
\forest@node@Foreach{#1}{\forest@node@@compute@numeric@ts@info}%
\ifnum\forestOve{#1}{@parent}=0
\else
- \fornode{#1}{\forest@node@@compute@numeric@ts@info@nbar}%
+ \forest@fornode{#1}{\forest@node@@compute@numeric@ts@info@nbar}%
+ % hack: the parent of the node we called the update for gets +1 for n_children
+ \edef\forest@node@temp{\forestOve{#1}{@parent}}%
+ \forestOeset{\forest@node@temp}{n children}{%
+ \number\numexpr\forestOve{\forest@node@temp}{n children}-1%
+ }%
\fi
\forest@node@Foreachdescendant{#1}{\forest@node@@compute@numeric@ts@info@nbar}%
}
@@ -5606,6 +1859,9 @@
\@escapeif{\expandnumberarg\forest@node@nextleafid@Godown{\forestOve{#1}{@first}}}%
\fi
}
+
+
+
\def\forest@node@linearnextid{%
\ifnum\forestove{@first}=0
\expandafter\forest@node@linearnextnotdescendantid
@@ -5618,11 +1874,17 @@
}
\def\forest@node@Linearnextnotdescendantid#1{%
\ifnum\forestOve{#1}{@next}=0
- \@escapeif{\expandnumberarg\forest@node@Linearnextnotdescendantid{\forestOve{#1}{@parent}}}%
+ \ifnum\forestOve{#1}{@parent}=0
+ 0%
+ \else
+ \@escapeifif{\expandnumberarg\forest@node@Linearnextnotdescendantid{\forestOve{#1}{@parent}}}%
+ \fi
\else
\forestOve{#1}{@next}%
\fi
}
+
+
\def\forest@node@linearpreviousid{%
\ifnum\forestove{@previous}=0
\forestove{@parent}%
@@ -5648,203 +1910,6 @@
% \end{macrocode}
%
%
-% \subsection{Node walk}
-%
-% \begin{macrocode}
-\newloop\forest@nodewalk@loop
-\forestset{
- @handlers@save@currentpath/.code={%
- \edef\pgfkeyscurrentkey{\pgfkeyscurrentpath}%
- \let\forest@currentkey\pgfkeyscurrentkey
- \pgfkeys@split@path
- \edef\forest@currentpath{\pgfkeyscurrentpath}%
- \let\forest@currentname\pgfkeyscurrentname
- },
- /handlers/.step 0 args/.style={
- /forest/@handlers@save@currentpath,
- \forest@currentkey/.code={#1\forestset{node walk/every step}},
- /forest/for \forest@currentname/.style/.expanded={%
- for={\forest@currentname}{####1}%
- }
- },
- /handlers/.step 1 arg/.style={%
- /forest/@handlers@save@currentpath,
- \forest@currentkey/.code={#1\forestset{node walk/every step}},
- /forest/for \forest@currentname/.style 2 args/.expanded={%
- for={\forest@currentname=####1}{####2}%
- }
- },
- node walk/.code={%
- \forestset{%
- node walk/before walk,%
- node walk/.cd,
- #1,%
- /forest/.cd,
- node walk/after walk
- }%
- },
- for/.code 2 args={%
- \forest@forthis{%
- \pgfkeysalso{%
- node walk/before walk/.style={},%
- node walk/every step/.style={},%
- node walk/after walk/.style={/forest,if id=0{}{#2}},%
- %node walk/after walk/.style={#2},%
- node walk={#1}%
- }%
- }%
- },
- node walk/.cd,
- before walk/.code={},
- every step/.code={},
- after walk/.code={},
- current/.step 0 args={},
- current/.default=1,
- next/.step 0 args={\edef\forest@cn{\forestove{@next}}},
- next/.default=1,
- previous/.step 0 args={\edef\forest@cn{\forestove{@previous}}},
- previous/.default=1,
- parent/.step 0 args={\edef\forest@cn{\forestove{@parent}}},
- parent/.default=1,
- first/.step 0 args={\edef\forest@cn{\forestove{@first}}},
- first/.default=1,
- last/.step 0 args={\edef\forest@cn{\forestove{@last}}},
- last/.default=1,
- n/.step 1 arg={%
- \def\forest@nodewalk@temp{#1}%
- \ifx\forest@nodewalk@temp\pgfkeysnovalue@text
- \edef\forest@cn{\forestove{@next}}%
- \else
- \edef\forest@cn{\forest@node@nthchildid{#1}}%
- \fi
- },
- n'/.step 1 arg={\edef\forest@cn{\forest@node@nbarthchildid{#1}}},
- sibling/.step 0 args={%
- \edef\forest@cn{%
- \ifnum\forestove{@previous}=0
- \forestove{@next}%
- \else
- \forestove{@previous}%
- \fi
- }%
- },
- previous leaf/.step 0 args={\edef\forest@cn{\forest@node@previousleafid}},
- previous leaf/.default=1,
- next leaf/.step 0 args={\edef\forest@cn{\forest@node@nextleafid}},
- next leaf/.default=1,
- linear next/.step 0 args={\edef\forest@cn{\forest@node@linearnextid}},
- linear previous/.step 0 args={\edef\forest@cn{\forest@node@linearpreviousid}},
- first leaf/.step 0 args={%
- \forest@nodewalk@loop
- \edef\forest@cn{\forestove{@first}}%
- \unless\ifnum\forestove{@first}=0
- \forest@nodewalk@repeat
- },
- last leaf/.step 0 args={%
- \forest@nodewalk@loop
- \edef\forest@cn{\forestove{@last}}%
- \unless\ifnum\forestove{@last}=0
- \forest@nodewalk@repeat
- },
- to tier/.step 1 arg={%
- \def\forest@nodewalk@giventier{#1}%
- \forest@nodewalk@loop
- \forestoget{tier}\forest@nodewalk@tier
- \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
- \forestoget{@parent}\forest@cn
- \forest@nodewalk@repeat
- },
- next on tier/.step 0 args={\forest@nodewalk@nextontier},
- next on tier/.default=1,
- previous on tier/.step 0 args={\forest@nodewalk@previousontier},
- previous on tier/.default=1,
- name/.step 1 arg={\edef\forest@cn{\forest@node@Nametoid{#1}}},
- root/.step 0 args={\edef\forest@cn{\forest@node@rootid}},
- root'/.step 0 args={\edef\forest@cn{\forest@root}},
- id/.step 1 arg={\edef\forest@cn{#1}},
- % maybe it's not wise to have short-step sequences and names potentially clashing
- % .unknown/.code={%
- % \forest@node@Ifnamedefined{\pgfkeyscurrentname}%
- % {\pgfkeysalso{name=\pgfkeyscurrentname}}%
- % {\expandafter\forest@nodewalk@shortsteps\pgfkeyscurrentname\forest@nodewalk@endshortsteps}%
- % },
- .unknown/.code={%
- \expandafter\forest@nodewalk@shortsteps\pgfkeyscurrentname\forest@nodewalk@endshortsteps
- },
- node walk/.style={/forest/node walk={#1}},
- trip/.code={\forest@forthis{\pgfkeysalso{#1}}},
- group/.code={\forest@go{#1}\forestset{node walk/every step}},
- % repeat is taken later from /forest/repeat
- p/.style={previous=1},
- %n/.style={next=1}, % defined in "long" n
- u/.style={parent=1},
- s/.style={sibling},
- c/.style={current=1},
- r/.style={root},
- P/.style={previous leaf=1},
- N/.style={next leaf=1},
- F/.style={first leaf=1},
- L/.style={last leaf=1},
- >/.style={next on tier=1},
- </.style={previous on tier=1},
- 1/.style={n=1},
- 2/.style={n=2},
- 3/.style={n=3},
- 4/.style={n=4},
- 5/.style={n=5},
- 6/.style={n=6},
- 7/.style={n=7},
- 8/.style={n=8},
- 9/.style={n=9},
- l/.style={last=1},
- %{...} is short for group={...}
-}
-\def\forest@nodewalk@nextontier{%
- \forestoget{tier}\forest@nodewalk@giventier
- \edef\forest@cn{\forest@node@linearnextnotdescendantid}%
- \forest@nodewalk@loop
- \forestoget{tier}\forest@nodewalk@tier
- \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
- \edef\forest@cn{\forest@node@linearnextid}%
- \forest@nodewalk@repeat
-}
-\def\forest@nodewalk@previousontier{%
- \forestoget{tier}\forest@nodewalk@giventier
- \forest@nodewalk@loop
- \edef\forest@cn{\forest@node@linearpreviousid}%
- \forestoget{tier}\forest@nodewalk@tier
- \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
- \forest@nodewalk@repeat
-}
-\def\forest@nodewalk@shortsteps{%
- \futurelet\forest@nodewalk@nexttoken\forest@nodewalk@shortsteps@
-}
-\def\forest@nodewalk@shortsteps@#1{%
- \ifx\forest@nodewalk@nexttoken\forest@nodewalk@endshortsteps
- \else
- \ifx\forest@nodewalk@nexttoken\bgroup
- \pgfkeysalso{group=#1}%
- \@escapeifif\forest@nodewalk@shortsteps
- \else
- \pgfkeysalso{#1}%
- \@escapeifif\forest@nodewalk@shortsteps
- \fi
- \fi
-}
-\def\forest@go#1{%
- {%
- \forestset{%
- node walk/before walk/.code={},%
- node walk/every step/.code={},%
- node walk/after walk/.code={},%
- node walk={#1}%
- }%
- \expandafter
- }%
- \expandafter\def\expandafter\forest@cn\expandafter{\forest@cn}%
-}
-% \end{macrocode}
-%
% \subsection{Node options}
%
% \subsubsection{Option-declaration mechanism}
@@ -5854,6 +1919,7 @@
\def\forest@declarehandler#1#2#3{%#1=handler for specific type,#2=option name,#3=default value
\pgfkeyssetvalue{/forest/#2}{#3}%
\appto\forest@node@init{\forestoinit{#2}}%
+ \pgfkeyssetvalue{/forest/#2/node@or@reg}{\forest@cn}%
\forest@convert@others@to@underscores{#2}\forest@pgfmathoptionname
\edef\forest@marshal{%
\noexpand#1{/forest/#2}{/forest}{#2}{\forest@pgfmathoptionname}%
@@ -5865,23 +1931,25 @@
% \end{macrocode}
% Option-declaration handlers.
% \begin{macrocode}
-\newtoks\forest@temp@toks
-\def\forest@declaretoks@handler#1#2#3#4{%
+\def\forest@declaretoks@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
\forest@declaretoks@handler@A{#1}{#2}{#3}{#4}{}%
}
-\def\forest@declarekeylist@handler#1#2#3#4{%
+\def\forest@declarekeylist@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
\forest@declaretoks@handler@A{#1}{#2}{#3}{#4}{,}%
- \pgfkeysgetvalue{#1/.@cmd}\forest@temp
- \pgfkeyslet{#1'/.@cmd}\forest@temp
+ \forest@copycommandkey{#1}{#1'}%
\pgfkeyssetvalue{#1'/option@name}{#3}%
- \pgfkeysgetvalue{#1+/.@cmd}\forest@temp
- \pgfkeyslet{#1/.@cmd}\forest@temp
- }
+ \forest@copycommandkey{#1+}{#1}%
+ \pgfkeysalso{#1-/.code={%
+ \forest@fornode{\forest@setter@node}{%
+ \forest@node@removekeysfromkeylist{##1}{#3}%
+ }}}%
+ \pgfkeyssetvalue{#1-/option@name}{#3}%
+}
\def\forest@declaretoks@handler@A#1#2#3#4#5{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
\pgfkeysalso{%
#1/.code={\forestOset{\forest@setter@node}{#3}{##1}},
#1+/.code={\forestOappto{\forest@setter@node}{#3}{#5##1}},
- #1-/.code={\forestOpreto{\forest@setter@node}{#3}{##1#5}},
+ #2/+#3/.code={\forestOpreto{\forest@setter@node}{#3}{##1#5}},
#2/if #3/.code n args={3}{%
\forestoget{#3}\forest@temp@option@value
\edef\forest@temp@compared@value{\unexpanded{##1}}%
@@ -5906,22 +1974,20 @@
}%
\pgfkeyssetvalue{#1/option@name}{#3}%
\pgfkeyssetvalue{#1+/option@name}{#3}%
+ \pgfkeyssetvalue{#2/+#3/option@name}{#3}%
\pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@toks{##1}{#3}}%
}
\def\forest@declareautowrappedtoks@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
\forest@declaretoks@handler{#1}{#2}{#3}{#4}%
- \pgfkeysgetvalue{#1/.@cmd}\forest@temp
- \pgfkeyslet{#1'/.@cmd}\forest@temp
+ \forest@copycommandkey{#1}{#1'}%
\pgfkeysalso{#1/.style={#1'/.wrap value={##1}}}%
\pgfkeyssetvalue{#1'/option@name}{#3}%
- \pgfkeysgetvalue{#1+/.@cmd}\forest@temp
- \pgfkeyslet{#1+'/.@cmd}\forest@temp
+ \forest@copycommandkey{#1+}{#1+'}%
\pgfkeysalso{#1+/.style={#1+'/.wrap value={##1}}}%
\pgfkeyssetvalue{#1+'/option@name}{#3}%
- \pgfkeysgetvalue{#1-/.@cmd}\forest@temp
- \pgfkeyslet{#1-'/.@cmd}\forest@temp
- \pgfkeysalso{#1-/.style={#1-'/.wrap value={##1}}}%
- \pgfkeyssetvalue{#1-'/option@name}{#3}%
+ \forest@copycommandkey{#2/+#3}{#2/+#3'}%
+ \pgfkeysalso{#2/+#3/.style={#2/+#3'/.wrap value={##1}}}%
+ \pgfkeyssetvalue{#2/+#3'/option@name}{#3}%
}
\def\forest@declarereadonlydimen@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
\pgfkeysalso{%
@@ -6020,25 +2086,25 @@
\forestOlet{\forest@setter@node}{#3}\forest@temp
},
#1+/.code={%
- \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfmathtruncatemacro\forest@temp{##1}%
\c@pgf@counta=\forestove{#3}\relax
\advance\c@pgf@counta\forest@temp\relax
\forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
},
#1-/.code={%
- \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfmathtruncatemacro\forest@temp{##1}%
\c@pgf@counta=\forestove{#3}\relax
\advance\c@pgf@counta-\forest@temp\relax
\forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
},
#1*/.code={%
- \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfmathtruncatemacro\forest@temp{##1}%
\c@pgf@counta=\forestove{#3}\relax
\multiply\c@pgf@counta\forest@temp\relax
\forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
},
#1:/.code={%
- \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfmathtruncatemacro\forest@temp{##1}%
\c@pgf@counta=\forestove{#3}\relax
\divide\c@pgf@counta\forest@temp\relax
\forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
@@ -6085,8 +2151,12 @@
\ifstrequal{##1}{1}{%
\forestOset{\forest@setter@node}{#3}{1}%
}{%
- \pgfmathifthenelse{##1}{1}{0}%
- \forestOlet{\forest@setter@node}{#3}\pgfmathresult
+ \ifstrequal{##1}{0}{%
+ \forestOset{\forest@setter@node}{#3}{0}%
+ }{%
+ \pgfmathifthenelse{##1}{1}{0}%
+ \forestOlet{\forest@setter@node}{#3}\pgfmathresult
+ }%
}%
},
#1/.default=1,
@@ -6104,7 +2174,7 @@
\pgfkeyssetvalue{#1/option@name}{#3}%
\pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@count{##1}{#3}}%
}
-\pgfkeys{/forest,
+\forestset{
declare toks/.code 2 args={%
\forest@declarehandler\forest@declaretoks@handler{#1}{#2}%
},
@@ -6129,6 +2199,12 @@
declare boolean/.code 2 args={%
\forest@declarehandler\forest@declareboolean@handler{#1}{#2}%
},
+ /handlers/.restore default value/.code={%
+ \edef\forest@handlers@currentpath{\pgfkeyscurrentpath}%
+ \pgfkeysgetvalue{\pgfkeyscurrentpath/option@name}\forest@currentoptionname
+ \pgfkeysgetvalue{/forest/\forest@currentoptionname}\forest@temp
+ \expandafter\pgfkeysalso\expandafter{\forest@handlers@currentpath/.expand once=\forest@temp}%
+ },
/handlers/.pgfmath/.code={%
\pgfmathparse{#1}%
\pgfkeysalso{\pgfkeyscurrentpath/.expand once=\pgfmathresult}%
@@ -6136,11 +2212,21 @@
/handlers/.wrap value/.code={%
\edef\forest@handlers@wrap@currentpath{\pgfkeyscurrentpath}%
\pgfkeysgetvalue{\forest@handlers@wrap@currentpath/option@name}\forest@currentoptionname
- \expandafter\forestoget\expandafter{\forest@currentoptionname}\forest@option@value
+ \forestOget{\pgfkeysvalueof{/forest/\forest@currentoptionname/node@or@reg}}{\forest@currentoptionname}\forest@option@value
\forest@def@with@pgfeov\forest@wrap@code{#1}%
\expandafter\edef\expandafter\forest@wrapped@value\expandafter{\expandafter\expandonce\expandafter{\expandafter\forest@wrap@code\forest@option@value\pgfeov}}%
\pgfkeysalso{\forest@handlers@wrap@currentpath/.expand once=\forest@wrapped@value}%
},
+ /handlers/.option/.code={%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\pgfkeyscurrentpath={\forestoption{#1}}}%
+ }\forest@marshal
+ },
+ /handlers/.register/.code={%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\pgfkeyscurrentpath={\forestregister{#1}}}%
+ }\forest@marshal
+ },
/handlers/.wrap pgfmath arg/.code 2 args={%
\pgfmathparse{#2}\let\forest@wrap@arg@i\pgfmathresult
\edef\forest@wrap@args{{\expandonce\forest@wrap@arg@i}}%
@@ -6174,6 +2260,9 @@
/handlers/.wrap 8 pgfmath args/.code n args={9}{%
\forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}{8}%
\forest@wrap@n@pgfmath@do{#1}{8}},
+ /handlers/.process args/.code={%
+ \forest@processargs#1\forest@eov\forest@END
+ },
}
\def\forest@wrap@n@pgfmath@args#1#2#3#4#5#6#7#8#9{%
\pgfmathparse{#1}\let\forest@wrap@arg@i\pgfmathresult
@@ -6209,49 +2298,556 @@
\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\forest@wrapped\expandafter\expandafter\expandafter{\expandafter\forest@wrap@code\forest@wrap@args}%
\pgfkeysalso{\pgfkeyscurrentpath/.expand once=\forest@wrapped}%
}
+\newtoks\forest@processargs@result
+\newtoks\forest@processargs@current
+\newif\ifforest@processargs@append
+\def\forest@eov{\forest@eov}
+\def\forest@processargs#1#2\forest@END{% #1 = processing instructions, #2 = args
+ \forest@processargs@result{}%
+ \forest@processargs@current{}%
+ \forest@processargs@appendfalse
+ \forest@processargs@getins#1.\forest@END#2\forest@END
+}
+\def\forest@processargs@maybeappend{%
+ \ifforest@processargs@append
+ \eapptotoks\forest@processargs@result{{\the\forest@processargs@current}}%
+ \forest@processargs@current{}%
+ \fi
+}
+\def\forest@processargs@getins#1#2\forest@END#3\forest@END{% #1 = first instruction, #2 = rest of instructions, #3 = args
+ \csname forest@processargs@ins@#1\endcsname#2\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@.}\forest@END#1\forest@END{%
+ \forest@processargs@maybeappend
+ \forest@processargs@appremainingargs#1\forest@END
+}
+\def\forest@processargs@appremainingargs#1#2\forest@END{%
+ \edef\forest@temp{\unexpanded{#1}}%
+ \ifx\forest@temp\forest@eov
+ \let\forest@processargs@next\forest@processargs@done
+ \else
+ \apptotoks\forest@processargs@result{{#1}}%
+ \let\forest@processargs@next\forest@processargs@appremainingargs
+ \fi
+ \forest@processargs@next#2\forest@END
+}
+\def\forest@processargs@done#1\forest@END{%
+ \pgfkeysalso{\pgfkeyscurrentpath/.expanded=\the\forest@processargs@result}%
+}
+\csdef{forest@processargs@ins@_}#1\forest@END#2#3\forest@END{% no processing
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \forest@processargs@current{#2}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@x}#1\forest@END#2#3\forest@END{% expand
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \etotoks\forest@processargs@current{#2}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@o}#1\forest@END#2#3\forest@END{% expand once
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \expandafter\forest@processargs@current\expandafter{#2}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@O}#1\forest@END#2#3\forest@END{% option
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \etotoks\forest@processargs@current{\forestoption{#2}}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@R}#1\forest@END#2#3\forest@END{% register
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \etotoks\forest@processargs@current{\forestregister{#2}}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@P}#1\forest@END#2#3\forest@END{% pgfmath expression
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \pgfmathparse{#2}%
+ \expandafter\forest@processargs@current\expandafter{\pgfmathresult}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@+}#1\forest@END#2\forest@END{% join processors
+ \forest@processargs@appendfalse
+ \edef\forest@marshal{%
+ \unexpanded{\forest@processargs@getins#1\forest@END}{\the\forest@processargs@current}\unexpanded{#2\forest@END}%
+ }\forest@marshal
+}
+\csdef{forest@processargs@ins@r}#1\forest@END#2#3\forest@END{% reverse keylist
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \forest@processargs@current{}%
+ \pgfqkeys{/forest}{split={#2}{,}{reverse@keylist}}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\forestset{%
+ reverse@keylist/.code={%
+ \epretotoks\forest@processargs@current{#1,}%
+ },
+}
% \end{macrocode}
%
+% \subsubsection{Registers}
+% Register declaration mechanism is an adjusted copy-paste of the option declaration mechanism.
+% \begin{macrocode}
+\def\forest@pgfmathhelper@register@toks#1#2{% #1 is discarded: it is present only for analogy with options
+ \forestrget{#2}\pgfmathresult
+}
+\def\forest@pgfmathhelper@register@dimen#1#2{%
+ \forestrget{#2}\forest@temp
+ \pgfmathparse{+\forest@temp}%
+}
+\def\forest@pgfmathhelper@register@count#1#2{%
+ \forestrget{#2}\forest@temp
+ \pgfmathtruncatemacro\pgfmathresult{\forest@temp}%
+}
+\def\forest@declareregisterhandler#1#2{%#1=handler for specific type,#2=option name
+ \pgfkeyssetvalue{/forest/#2/node@or@reg}{register}%
+ \forest@convert@others@to@underscores{#2}\forest@pgfmathoptionname
+ \edef\forest@marshal{%
+ \noexpand#1{/forest/#2}{/forest}{#2}{\forest@pgfmathoptionname}%
+ }\forest@marshal
+}
+\def\forest@declaretoksregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \forest@declaretoksregister@handler@A{#1}{#2}{#3}{#4}{}%
+}
+\def\forest@declarekeylistregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \forest@declaretoksregister@handler@A{#1}{#2}{#3}{#4}{,}%
+ \forest@copycommandkey{#1}{#1'}%
+ \pgfkeyssetvalue{#1'/option@name}{#3}%
+ \forest@copycommandkey{#1+}{#1}%
+ \pgfkeysalso{#1-/.code={%
+ \forest@fornode{register}{%
+ \forest@node@removekeysfromkeylist{##1}{#3}%
+ }}}%
+ \pgfkeyssetvalue{#1-/option@name}{#3}%
+}
+\def\forest@declaretoksregister@handler@A#1#2#3#4#5{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
+ \pgfkeysalso{%
+ #1/.code={\forestrset{#3}{##1}},
+ #1+/.code={\forestrappto{#3}{#5##1}},
+ #2/+#3/.code={\forestrpreto{#3}{##1#5}},
+ #2/if #3/.code n args={3}{%
+ \forestrget{#3}\forest@temp@option@value
+ \edef\forest@temp@compared@value{\unexpanded{##1}}%
+ \ifx\forest@temp@option@value\forest@temp@compared@value
+ \pgfkeysalso{##2}%
+ \else
+ \pgfkeysalso{##3}%
+ \fi
+ },
+ #2/if in #3/.code n args={3}{%
+ \forestrget{#3}\forest@temp@option@value
+ \edef\forest@temp@compared@value{\unexpanded{##1}}%
+ \expandafter\expandafter\expandafter\pgfutil@in@\expandafter\expandafter\expandafter{\expandafter\forest@temp@compared@value\expandafter}\expandafter{\forest@temp@option@value}%
+ \ifpgfutil@in@
+ \pgfkeysalso{##2}%
+ \else
+ \pgfkeysalso{##3}%
+ \fi
+ },
+ }%
+ \pgfkeyssetvalue{#1/option@name}{#3}%
+ \pgfkeyssetvalue{#1+/option@name}{#3}%
+ \pgfkeyssetvalue{#2/+#3/option@name}{#3}%
+ \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@toks{##1}{#3}}%
+}
+\def\forest@declareautowrappedtoksregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
+ \forest@declaretoksregister@handler{#1}{#2}{#3}{#4}%
+ \forest@copycommandkey{#1}{#1'}%
+ \pgfkeysalso{#1/.style={#1'/.wrap value={##1}}}%
+ \pgfkeyssetvalue{#1'/option@name}{#3}%
+ \forest@copycommandkey{#1+}{#1+'}%
+ \pgfkeysalso{#1+/.style={#1+'/.wrap value={##1}}}%
+ \pgfkeyssetvalue{#1+'/option@name}{#3}%
+ \forest@copycommandkey{#2/+#3}{#2/+#3'}%
+ \pgfkeysalso{#2/+#3/.style={#2/+#3'/.wrap value={##1}}}%
+ \pgfkeyssetvalue{#2/+#3'/option@name}{#3}%
+}
+\def\forest@declarereadonlydimenregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \pgfkeysalso{%
+ #2/if #3/.code n args={3}{%
+ \forestrget{#3}\forest@temp@option@value
+ \ifdim\forest@temp@option@value=##1\relax
+ \pgfkeysalso{##2}%
+ \else
+ \pgfkeysalso{##3}%
+ \fi
+ },
+ }%
+ \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@dimen{##1}{#3}}%
+}
+\def\forest@declaredimenregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \forest@declarereadonlydimenregister@handler{#1}{#2}{#3}{#4}%
+ \pgfkeysalso{%
+ #1/.code={%
+ \pgfmathsetlengthmacro\forest@temp{##1}%
+ \forestrlet{#3}\forest@temp
+ },
+ #1+/.code={%
+ \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfutil@tempdima=\forestrve{#3}
+ \advance\pgfutil@tempdima\forest@temp\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1-/.code={%
+ \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfutil@tempdima=\forestrve{#3}
+ \advance\pgfutil@tempdima-\forest@temp\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1*/.style={%
+ #1={#4()*(##1)}%
+ },
+ #1:/.style={%
+ #1={#4()/(##1)}%
+ },
+ #1'/.code={%
+ \pgfutil@tempdima=##1\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1'+/.code={%
+ \pgfutil@tempdima=\forestrve{#3}\relax
+ \advance\pgfutil@tempdima##1\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1'-/.code={%
+ \pgfutil@tempdima=\forestrve{#3}\relax
+ \advance\pgfutil@tempdima-##1\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1'*/.style={%
+ \pgfutil@tempdima=\forestrve{#3}\relax
+ \multiply\pgfutil@tempdima##1\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1':/.style={%
+ \pgfutil@tempdima=\forestrve{#3}\relax
+ \divide\pgfutil@tempdima##1\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ }%
+ \pgfkeyssetvalue{#1/option@name}{#3}%
+ \pgfkeyssetvalue{#1+/option@name}{#3}%
+ \pgfkeyssetvalue{#1-/option@name}{#3}%
+ \pgfkeyssetvalue{#1*/option@name}{#3}%
+ \pgfkeyssetvalue{#1:/option@name}{#3}%
+ \pgfkeyssetvalue{#1'/option@name}{#3}%
+ \pgfkeyssetvalue{#1'+/option@name}{#3}%
+ \pgfkeyssetvalue{#1'-/option@name}{#3}%
+ \pgfkeyssetvalue{#1'*/option@name}{#3}%
+ \pgfkeyssetvalue{#1':/option@name}{#3}%
+}
+\def\forest@declarereadonlycountregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \pgfkeysalso{
+ #2/if #3/.code n args={3}{%
+ \forestrget{#3}\forest@temp@option@value
+ \ifnum\forest@temp@option@value=##1\relax
+ \pgfkeysalso{##2}%
+ \else
+ \pgfkeysalso{##3}%
+ \fi
+ },
+ }%
+ \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@count{##1}{#3}}%
+}
+\def\forest@declarecountregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \forest@declarereadonlycountregister@handler{#1}{#2}{#3}{#4}%
+ \pgfkeysalso{
+ #1/.code={%
+ \pgfmathtruncatemacro\forest@temp{##1}%
+ \forestrlet{#3}\forest@temp
+ },
+ #1+/.code={%
+ \pgfmathtruncatemacro\forest@temp{##1}%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \advance\c@pgf@counta\forest@temp\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1-/.code={%
+ \pgfmathtruncatemacro\forest@temp{##1}%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \advance\c@pgf@counta-\forest@temp\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1*/.code={%
+ \pgfmathtruncatemacro\forest@temp{##1}%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \multiply\c@pgf@counta\forest@temp\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1:/.code={%
+ \pgfmathtruncatemacro\forest@temp{##1}%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \divide\c@pgf@counta\forest@temp\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1'/.code={%
+ \c@pgf@counta=##1\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1'+/.code={%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \advance\c@pgf@counta##1\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1'-/.code={%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \advance\c@pgf@counta-##1\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1'*/.style={%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \multiply\c@pgf@counta##1\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1':/.style={%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \divide\c@pgf@counta##1\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ }%
+ \pgfkeyssetvalue{#1/option@name}{#3}%
+ \pgfkeyssetvalue{#1+/option@name}{#3}%
+ \pgfkeyssetvalue{#1-/option@name}{#3}%
+ \pgfkeyssetvalue{#1*/option@name}{#3}%
+ \pgfkeyssetvalue{#1:/option@name}{#3}%
+ \pgfkeyssetvalue{#1'/option@name}{#3}%
+ \pgfkeyssetvalue{#1'+/option@name}{#3}%
+ \pgfkeyssetvalue{#1'-/option@name}{#3}%
+ \pgfkeyssetvalue{#1'*/option@name}{#3}%
+ \pgfkeyssetvalue{#1':/option@name}{#3}%
+}
+\def\forest@declarebooleanregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \pgfkeysalso{%
+ #1/.code={%
+ \ifstrequal{##1}{1}{%
+ \forestrset{#3}{1}%
+ }{%
+ \ifstrequal{##1}{0}{%
+ \forestrset{#3}{0}%
+ }{%
+ \pgfmathifthenelse{##1}{1}{0}%
+ \forestrlet{#3}\pgfmathresult
+ }%
+ }%
+ },
+ #1/.default=1,
+ #2/not #3/.code={\forestrset{#3}{0}},
+ #2/if #3/.code 2 args={%
+ \forestrget{#3}\forest@temp@option@value
+ \ifnum\forest@temp@option@value=1
+ \pgfkeysalso{##1}%
+ \else
+ \pgfkeysalso{##2}%
+ \fi
+ },
+ }%
+ \pgfkeyssetvalue{#1/option@name}{#3}%
+ \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@count{##1}{#3}}%
+}
+\forestset{
+ declare toks register/.code={%
+ \forest@declareregisterhandler\forest@declaretoksregister@handler{#1}%
+ },
+ declare autowrapped toks register/.code={%
+ \forest@declareregisterhandler\forest@declareautowrappedtoksregister@handler{#1}%
+ },
+ declare keylist register/.code={%
+ \forest@declareregisterhandler\forest@declarekeylistregister@handler{#1}%
+ },
+ declare dimen register/.code={%
+ \forest@declareregisterhandler\forest@declaredimenregister@handler{#1}%
+ },
+ declare count register/.code={%
+ \forest@declareregisterhandler\forest@declarecountregister@handler{#1}%
+ },
+ declare boolean register/.code={%
+ \forest@declareregisterhandler\forest@declarebooleanregister@handler{#1}%
+ },
+}
+% \end{macrocode}
+% Declare some temporary registers.
+% \begin{macrocode}
+\forestset{
+ declare toks register=temptoksa,temptoksa={},
+ declare toks register=temptoksb,temptoksb={},
+ declare toks register=temptoksc,temptoksc={},
+ declare toks register=temptoksd,temptoksd={},
+ declare keylist register=tempkeylista,tempkeylista'={},
+ declare keylist register=tempkeylistb,tempkeylistb'={},
+ declare keylist register=tempkeylistc,tempkeylistc'={},
+ declare keylist register=tempkeylistd,tempkeylistd'={},
+ declare dimen register=tempdima,tempdima'={0pt},
+ declare dimen register=tempdimb,tempdimb'={0pt},
+ declare dimen register=tempdimc,tempdimc'={0pt},
+ declare dimen register=tempdimd,tempdimd'={0pt},
+ declare dimen register=tempdimx,tempdimx'={0pt},
+ declare dimen register=tempdimy,tempdimy'={0pt},
+ declare dimen register=tempdiml,tempdiml'={0pt},
+ declare dimen register=tempdims,tempdims'={0pt},
+ declare count register=tempcounta,tempcounta'={0},
+ declare count register=tempcountb,tempcountb'={0},
+ declare count register=tempcountc,tempcountc'={0},
+ declare count register=tempcountd,tempcountd'={0},
+ declare boolean register=tempboola,tempboola={0},
+ declare boolean register=tempboolb,tempboolb={0},
+ declare boolean register=tempboolc,tempboolc={0},
+ declare boolean register=tempboold,tempboold={0},
+}
+% \end{macrocode}
% \subsubsection{Declaring options}
%
% \begin{macrocode}
-\def\forest@node@setname#1{%
- \forestoeset{name}{#1}%
- \csedef{forest@id@of@#1}{\forest@cn}%
-}
\def\forest@node@Nametoid#1{% #1 = name
\csname forest@id@of@#1\endcsname
}
-\def\forest@node@Ifnamedefined#1{% #1 = name, #2=true,#3=false
- \ifcsname forest@id@of@#1\endcsname
- \expandafter\@firstoftwo
+\def\forest@node@Ifnamedefined#1#2#3{% #1 = name, #2=true,#3=false
+ \ifcsvoid{forest@id@of@#1}{#3}{#2}%
+}
+\def\forest@node@setname#1{%
+ \def\forest@temp@setname{y}%
+ \def\forest@temp@silent{n}%
+ \def\forest@temp@propagating{n}%
+ \forest@node@setnameoralias{#1}%
+}
+\def\forest@node@setname@silent#1{%
+ \def\forest@temp@setname{y}%
+ \def\forest@temp@silent{y}%
+ \def\forest@temp@propagating{n}%
+ \forest@node@setnameoralias{#1}%
+}
+\def\forest@node@setalias#1{%
+ \def\forest@temp@setname{n}%
+ \def\forest@temp@silent{n}%
+ \def\forest@temp@propagating{n}%
+ \forest@node@setnameoralias{#1}%
+}
+\def\forest@node@setalias@silent#1{%
+ \def\forest@temp@setname{n}%
+ \def\forest@temp@silent{y}%
+ \def\forest@temp@propagating{n}%
+ \forest@node@setnameoralias{#1}%
+}
+\def\forest@node@setnameoralias#1{%
+ \ifstrempty{#1}{%
+ \forest@node@setnameoralias{node@\forest@cn}%
+ }{%
+ \forest@node@Ifnamedefined{#1}{%
+ \if y\forest@temp@propagating
+ % this will find a unique name, eventually:
+ \@escapeif{\forest@node@setnameoralias{#1@\forest@cn}}%
+ \else\@escapeif{%
+ \if y\forest@temp@setname
+ \@escapeif{\forest@node@setnameoralias@nameclash{#1}}%
+ \else\@escapeif{% setting an alias: clashing with alias is not a problem
+ \forestOget{\forest@node@Nametoid{#1}}{name}\forest@temp
+ \expandafter\ifstrequal\expandafter{\forest@temp}{#1}{%
+ \forest@node@setnameoralias@nameclash{#1}%
+ }{%
+ \forest@node@setnameoralias@do{#1}%
+ }%
+ }\fi
+ }\fi
+ }{%
+ \forest@node@setnameoralias@do{#1}%
+ }%
+ }%
+}
+\def\forest@node@setnameoralias@nameclash#1{%
+ \if y\forest@temp@silent
+ \forest@fornode{\forest@node@Nametoid{#1}}{%
+ \def\forest@temp@propagating{y}%
+ \forest@node@setnameoralias{}%
+ }%
+ \forest@node@setnameoralias@do{#1}%
\else
- \expandafter\@secondoftwo
+ \PackageError{forest}{Node name "#1" is already used}{}%
\fi
}
-\def\forest@node@setalias#1{%
- \csedef{forest@id@of@#1}{\forest@cn}%
+\def\forest@node@setnameoralias@do#1{%
+ \if y\forest@temp@setname
+ \csdef{forest@id@of@\forestove{name}}{}%
+ \forestoeset{name}{#1}%
+ \fi
+ \csedef{forest@id@of@#1}{\forest@cn}%
}
-\def\forest@node@Setalias#1#2{%
- \csedef{forest@id@of@#2}{#1}%
-}
\forestset{
TeX/.code={#1},
TeX'/.code={\appto\forest@externalize@loadimages{#1}#1},
TeX''/.code={\appto\forest@externalize@loadimages{#1}},
+ options/.code={\forestset{#1}},
+ typeout/.style={TeX={\typeout{#1}}},
declare toks={name}{},
name/.code={% override the default setter
- \forest@node@setname{#1}%
+ \forest@fornode{\forest@setter@node}{\forest@node@setname{#1}}%
+ },
+ name/.default={},
+ name'/.code={% override the default setter
+ \forest@fornode{\forest@setter@node}{\forest@node@setname@silent{#1}}%
},
- alias/.code={\forest@node@setalias{#1}},
+ name'/.default={},
+ alias/.code={\forest@fornode{\forest@setter@node}{\forest@node@setalias{#1}}},
+ alias'/.code={\forest@fornode{\forest@setter@node}{\forest@node@setalias@silent{#1}}},
begin draw/.code={\begin{tikzpicture}},
end draw/.code={\end{tikzpicture}},
- begin forest/.code={},
- end forest/.code={},
+ declare keylist register=default preamble,
+ default preamble'={},
+ declare keylist register=preamble,
+ preamble'={},
declare autowrapped toks={content}{},
+ % #1 = which option to split, #2 = separator (one char!), #3 = receiving options
+ %%% begin listing region: split_option
+ split option/.style n args=3{split/.process args={O}{#1}{#2}{#3}}
+ %%% end listing region: split_option
+ ,
+ split register/.style n args=3{% #1 = which register to split, #2 = separator (one char!), #3 = receiving options
+ split/.process args={R}{#1}{#2}{#3},
+ },
+ TeX={%
+ \def\forest@split@sourcevalues{}%
+ \def\forest@split@sourcevalue{}%
+ \def\forest@split@receivingoptions{}%
+ \def\forest@split@receivingoption{}%
+ },
+ split/.code n args=3{% #1 = string to split, #2 = separator (one char!), #3 = receiving options
+ \forest@saveandrestoremacro\forest@split@sourcevalues{%
+ \forest@saveandrestoremacro\forest@split@sourcevalue{%
+ \forest@saveandrestoremacro\forest@split@receivingoptions{%
+ \forest@saveandrestoremacro\forest@split@receivingoption{%
+ \def\forest@split@sourcevalues{#1#2}%
+ \edef\forest@split@receivingoptions{#3,}%
+ \def\forest@split@receivingoption{}%
+ \safeloop
+ \expandafter\forest@split\expandafter{\forest@split@sourcevalues}{#2}\forest@split@sourcevalue\forest@split@sourcevalues
+ \ifdefempty\forest@split@receivingoptions{}{%
+ \expandafter\forest@split\expandafter{\forest@split@receivingoptions}{,}\forest@temp\forest@split@receivingoptions
+ \ifdefempty\forest@temp{}{\let\forest@split@receivingoption\forest@temp\def\forest@temp{}}%
+ }%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\forest@split@receivingoption={\expandonce{\forest@split@sourcevalue}}}%
+ }\forest@marshal
+ \ifdefempty\forest@split@sourcevalues{\forest@tempfalse}{\forest@temptrue}%
+ \ifforest@temp
+ \saferepeat
+ }}}}%
+ },
declare count={grow}{270},
TeX={% a hack for grow-reversed connection, and compass-based grow specification
- \pgfkeysgetvalue{/forest/grow/.@cmd}\forest@temp
- \pgfkeyslet{/forest/grow@@/.@cmd}\forest@temp
+ \forest@copycommandkey{/forest/grow}{/forest/grow@@}%
+ %\pgfkeysgetvalue{/forest/grow/.@cmd}\forest@temp
+ %\pgfkeyslet{/forest/grow@@/.@cmd}\forest@temp
},
grow/.style={grow@={#1},reversed=0},
grow'/.style={grow@={#1},reversed=1},
@@ -6271,10 +2867,26 @@
declare toks={parent anchor}{},
declare toks={child anchor}{},
declare toks={anchor}{base},
+ Autoforward={anchor}{
+ node options-=anchor,
+ node options+={anchor={##1}}
+ },
+ anchor'/.style={anchor@no@compass=true,anchor=#1},
+ anchor+'/.style={anchor@no@compass=true,anchor+=#1},
+ anchor-'/.style={anchor@no@compass=true,anchor-=#1},
+ anchor*'/.style={anchor@no@compass=true,anchor*=#1},
+ anchor:'/.style={anchor@no@compass=true,anchor:=#1},
+ anchor'+'/.style={anchor@no@compass=true,anchor'+=#1},
+ anchor'-'/.style={anchor@no@compass=true,anchor'-=#1},
+ anchor'*'/.style={anchor@no@compass=true,anchor'*=#1},
+ anchor':'/.style={anchor@no@compass=true,anchor':=#1},
+ % /tikz/forest anchor/.style={
+ % /forest/TeX={\forestanchortotikzanchor{#1}\forest@temp@anchor},
+ % anchor/.expand once=\forest@temp@anchor
+ % },
declare toks={calign}{midpoint},
TeX={%
- \pgfkeysgetvalue{/forest/calign/.@cmd}\forest@temp
- \pgfkeyslet{/forest/calign'/.@cmd}\forest@temp
+ \forest@copycommandkey{/forest/calign}{/forest/calign'}%
},
calign/.is choice,
calign/child/.style={calign'=child},
@@ -6303,10 +2915,18 @@
declare keylist={edge}{draw},
declare toks={edge path}{%
\noexpand\path[\forestoption{edge}]%
- (\forestOve{\forestove{@parent}}{name}.parent anchor)--(\forestove{name}.child anchor)\forestoption{edge label};},
- triangle/.style={edge path={%
+ (\forestOve{\forestove{@parent}}{name}.parent anchor)--(\forestove{name}.child anchor)
+ % =
+ % (!u.parent anchor)--(.child anchor)\forestoption{edge label};
+ \forestoption{edge label};%
+ },
+ edge path'/.style={
+ edge path={%
\noexpand\path[\forestoption{edge}]%
- (\forestove{name}.north east)--(\forestOve{\forestove{@parent}}{name}.south)--(\forestove{name}.north west)--(\forestove{name}.north east)\forestoption{edge label};}},
+ #1%
+ \forestoption{edge label};
+ }
+ },
declare toks={edge label}{},
declare boolean={phantom}{0},
baseline/.style={alias={forest@baseline@node}},
@@ -6314,13 +2934,13 @@
declare readonly count={n'},
declare readonly count={n children},
declare readonly count={level},
- declare dimen=x{},
- declare dimen=y{},
+ declare dimen=x{0pt},
+ declare dimen=y{0pt},
declare dimen={s}{0pt},
declare dimen={l}{6ex}, % just in case: should be set by the calibration
declare dimen={s sep}{0.6666em},
declare dimen={l sep}{1ex}, % just in case: calibration!
- declare keylist={node options}{},
+ declare keylist={node options}{anchor=base},
declare toks={tikz}{},
afterthought/.style={tikz+={#1}},
label/.style={tikz={\path[late options={%
@@ -6328,21 +2948,28 @@
pin/.style={tikz={\path[late options={%
name=\forestoption{name},pin={#1}}];}},
declare toks={content format}{\forestoption{content}},
- math content/.style={content format={\ensuremath{\forestoption{content}}}},
+ plain content/.style={content format={\forestoption{content}}},
+ math content/.style={content format={\noexpand\ensuremath{\forestoption{content}}}},
declare toks={node format}{%
\noexpand\node
- [\forestoption{node options},anchor=\forestoption{anchor}]%
(\forestoption{name})%
+ [\forestoption{node options}]%
{\foresteoption{content format}};%
},
+ node format'/.style={
+ node format={\noexpand\node(\forestoption{name})#1;}
+ },
tabular@environment/.style={content format={%
\noexpand\begin{tabular}[\forestoption{base}]{\forestoption{align}}%
\forestoption{content}%
\noexpand\end{tabular}%
}},
declare toks={align}{},
- TeX={\pgfkeysgetvalue{/forest/align/.@cmd}\forest@temp
- \pgfkeyslet{/forest/align'/.@cmd}\forest@temp},
+ TeX={%
+ \forest@copycommandkey{/forest/align}{/forest/align'}%
+ %\pgfkeysgetvalue{/forest/align/.@cmd}\forest@temp
+ %\pgfkeyslet{/forest/align'/.@cmd}\forest@temp
+ },
align/.is choice,
align/.unknown/.code={%
\edef\forest@marshal{%
@@ -6356,24 +2983,32 @@
align/left/.style={align'={@{}l@{}},tabular@environment},
align/right/.style={align'={@{}r@{}},tabular@environment},
declare toks={base}{t},
- TeX={\pgfkeysgetvalue{/forest/base/.@cmd}\forest@temp
- \pgfkeyslet{/forest/base'/.@cmd}\forest@temp},
+ TeX={%
+ \forest@copycommandkey{/forest/base}{/forest/base'}%
+ %\pgfkeysgetvalue{/forest/base/.@cmd}\forest@temp
+ %\pgfkeyslet{/forest/base'/.@cmd}\forest@temp
+ },
base/.is choice,
base/top/.style={base'=t},
base/bottom/.style={base'=b},
base/.unknown/.style={base'/.expand once=\pgfkeyscurrentname},
+ unknown to/.store in=\forest@unknownto,
+ unknown to=node options,
+ unknown key error/.code={\PackageError{forest}{Unknown keyval: \detokenize{#1}}{}},
+ content to/.store in=\forest@contentto,
+ content to=content,
.unknown/.code={%
\expandafter\pgfutil@in@\expandafter.\expandafter{\pgfkeyscurrentname}%
\ifpgfutil@in@
\expandafter\forest@relatednode@option@setter\pgfkeyscurrentname=#1\forest@END
\else
\edef\forest@marshal{%
- \noexpand\pgfkeysalso{node options={\pgfkeyscurrentname=\unexpanded{#1}}}%
+ \noexpand\pgfkeysalso{\forest@unknownto={\pgfkeyscurrentname=\unexpanded{#1}}}%
}\forest@marshal
\fi
},
get node boundary/.code={%
- \forestoget{boundary}\forest@node@boundary
+ \forestoget{@boundary}\forest@node@boundary
\def#1{}%
\forest@extendpath#1\forest@node@boundary{\pgfpoint{\forestove{x}}{\forestove{y}}}%
},
@@ -6385,15 +3020,6 @@
\forest@get@tree@boundary{negative}{\forestove{grow}}#1},
get max s tree boundary/.code={%
\forest@get@tree@boundary{positive}{\forestove{grow}}#1},
- fit to tree/.code={%
- \pgfkeysalso{%
- /forest/get min s tree boundary=\forest@temp@negative@boundary,
- /forest/get max s tree boundary=\forest@temp@positive@boundary
- }%
- \edef\forest@temp@boundary{\expandonce{\forest@temp@negative@boundary}\expandonce{\forest@temp@positive@boundary}}%
- \forest@path@getboundingrectangle@xy\forest@temp@boundary
- \pgfkeysalso{inner sep=0,fit/.expanded={(\the\pgf@xa,\the\pgf@ya)(\the\pgf@xb,\the\pgf@yb)}}%
- },
use as bounding box/.style={%
before drawing tree={
tikz+/.expanded={%
@@ -6419,72 +3045,280 @@
}
},
}%
+\def\forest@iftikzkey#1#2#3{% #1 = key name, #2 = true code, #3 = false code
+ \forest@temptrue
+ \pgfkeysifdefined{/tikz/\pgfkeyscurrentname}{}{%
+ \pgfkeysifdefined{/tikz/\pgfkeyscurrentname/.@cmd}{}{%
+ \pgfkeysifdefined{/pgf/\pgfkeyscurrentname}{}{%
+ \pgfkeysifdefined{/pgf/\pgfkeyscurrentname/.@cmd}{}{%
+ \forest@tempfalse
+ }}}}%
+ \ifforest@temp\@escapeif{#2}\else\@escapeif{#3}\fi
+}
+\def\forest@ifoptionortikzkey#1#2#3{% #1 = key name, #2 = true code, #3 = false code
+ \forest@temptrue
+ \pgfkeysifdefined{/forest/\pgfkeyscurrentname}{}{%
+ \pgfkeysifdefined{/forest/\pgfkeyscurrentname/.@cmd}{}{%
+ \forest@iftikzkey{#1}{}{}%
+ }}%
+ \ifforest@temp\@escapeif{#2}\else\@escapeif{#3}\fi
+}
\def\forest@get@tree@boundary#1#2#3{%#1=pos/neg,#2=grow,#3=receiving cs
\def#3{}%
\forest@node@getedge{#1}{#2}\forest@temp@boundary
\forest@extendpath#3\forest@temp@boundary{\pgfpoint{\forestove{x}}{\forestove{y}}}%
}
\def\forest@setter@node{\forest@cn}%
+\def\forest@relatednode@option@compat@ignoreinvalidsteps#1{#1}
\def\forest@relatednode@option@setter#1.#2=#3\forest@END{%
\forest@forthis{%
- \forest@nameandgo{#1}%
- \let\forest@setter@node\forest@cn
+ \forest@relatednode@option@compat@ignoreinvalidsteps{%
+ \forest@nameandgo{#1}%
+ \let\forest@setter@node\forest@cn
+ }%
}%
- \pgfkeysalso{#2={#3}}%
+ \ifnum\forest@setter@node=0
+ \else
+ \forestset{#2={#3}}%
+ \fi
\def\forest@setter@node{\forest@cn}%
}%
+\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
+ \def\forest@split@@##1#2##2\forest@split@@##3##4{\def##3{##1}\def##4{##2}}%
+ \forest@split@@#1\forest@split@@{#3}{#4}}
% \end{macrocode}
%
% \subsubsection{Option propagation}
%
-% The propagators targeting single nodes are automatically defined by node walk steps definitions.
+% The propagators targeting single nodes are automatically defined by nodewalk steps definitions.
%
% \begin{macrocode}
\forestset{
- for tree/.code={\forest@node@foreach{\pgfkeysalso{#1}}},
+ for tree'/.style 2 args={#1,for children={for tree'={#1}{#2}},#2},
if/.code n args={3}{%
\pgfmathparse{#1}%
- \ifnum\pgfmathresult=0 \pgfkeysalso{#3}\else\pgfkeysalso{#2}\fi
+ \ifnum\pgfmathresult=0
+ \@escapeif{\pgfkeysalso{#3}}%
+ \else
+ \@escapeif{\pgfkeysalso{#2}}%
+ \fi
},
+ if nodewalk valid/.code n args={3}{%
+ \edef\forest@marshal{%
+ \unexpanded{\forest@forthis{%
+ \forest@nodewalk{%
+ on invalid={fake}{#1},
+ TeX={\global\let\forest@global@temp\forest@cn}
+ }{}%
+ }%
+ \def\forest@cn}{\forest@cn}\unexpanded{%
+ \ifnum\forest@global@temp=0
+ \@escapeif{\pgfkeysalso{#3}}%
+ \else
+ \@escapeif{\pgfkeysalso{#2}}%
+ \fi}%
+ }\forest@marshal
+ },
+ if nodewalk empty/.code n args={3}{%
+ \forest@forthis{%
+ \forest@nodewalk{%
+ on invalid={fake}{#1},
+ TeX={\global\let\forest@global@temp\forest@nodewalk@n},
+ }{}%
+ }%
+ \ifnum\forest@global@temp=0
+ \@escapeif{\pgfkeysalso{#2}}%
+ \else
+ \@escapeif{\pgfkeysalso{#3}}%
+ \fi
+ },
where/.style n args={3}{for tree={if={#1}{#2}{#3}}},
- for descendants/.code={\forest@node@foreachdescendant{\pgfkeysalso{#1}}},
- for all next/.style={for next={#1,for all next={#1}}},
- for all previous/.style={for previous={#1,for all previous={#1}}},
- for siblings/.style={for all previous={#1},for all next={#1}},
- for ancestors/.style={for parent={#1,for ancestors={#1}}},
- for ancestors'/.style={#1,for ancestors={#1}},
- for children/.code={\forest@node@foreachchild{\pgfkeysalso{#1}}},
- for c-commanded={for sibling={for tree={#1}}},
- for c-commanders={for sibling={#1},for parent={for c-commanders={#1}}}
-}
-% \end{macrocode}
-%
-% A bit of complication to allow for nested \keyname{repeat}s without \TeX\ groups.
-% \begin{macrocode}
-\newcount\forest@repeat@key@depth
-\forestset{%
+ where nodewalk valid/.style n args={3}{for tree={if nodewalk valid={#1}{#2}{#3}}},
+ where nodewalk empty/.style n args={3}{for tree={if nodewalk empty={#1}{#2}{#3}}},
repeat/.code 2 args={%
- \advance\forest@repeat@key@depth1
- \pgfmathparse{int(#1)}%
- \csedef{forest@repeat@key@\the\forest@repeat@key@depth}{\pgfmathresult}%
- \expandafter\newloop\csname forest@repeat@key@loop@\the\forest@repeat@key@depth\endcsname
- \def\forest@marshal{%
- \csname forest@repeat@key@loop@\the\forest@repeat@key@depth\endcsname
- \forest@temp@count=\csname forest@repeat@key@\the\forest@repeat@key@depth\endcsname\relax
- \ifnum\forest@temp@count>0
- \advance\forest@temp@count-1
- \csedef{forest@repeat@key@\the\forest@repeat@key@depth}{\the\forest@temp@count}%
- \pgfkeysalso{#2}%
- }%
- \expandafter\forest@marshal\csname forest@repeat@key@repeat@\the\forest@repeat@key@depth\endcsname
- \advance\forest@repeat@key@depth-1
- },
-}
-\pgfkeysgetvalue{/forest/repeat/.@cmd}\forest@temp
-\pgfkeyslet{/forest/node walk/repeat/.@cmd}\forest@temp
+ \pgfmathtruncatemacro\forest@temp{#1}%
+ \expandafter\forest@repeatkey\expandafter{\forest@temp}{#2}%
+ },
+ until/.code 2 args={%
+ \ifstrempty{#1}{%
+ \forest@untilkey{\ifnum\forest@cn=0\else\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
+ }{%
+ \forest@untilkey{\pgfmathifthenelse{#1}{"\noexpand\forestloopbreak"}{""}\pgfmathresult}{#2}%
+ }%
+ },
+ while/.code 2 args={%
+ \ifstrempty{#1}{%
+ \forest@untilkey{\ifnum\forest@cn=0\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
+ }{%
+ \forest@untilkey{\pgfmathifthenelse{not(#1)}{"\noexpand\forestloopbreak"}{""}\pgfmathresult}{#2}%
+ }%
+ },
+ do until/.code 2 args={%
+ \ifstrempty{#1}{%
+ \forest@dountilkey{\ifnum\forest@cn=0\else\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
+ }{%
+ \forest@dountilkey{\pgfmathifthenelse{#1}{"\noexpand\forestloopbreak"}{""}\pgfmathresult}{#2}%
+ }%
+ },
+ do while/.code 2 args={%
+ \ifstrempty{#1}{%
+ \forest@dountilkey{\ifnum\forest@cn=0\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
+ }{%
+ \forest@dountilkey{\pgfmathifthenelse{not(#1)}{"\noexpand\forestloopbreak"}{""}\pgfmathresult}{#2}%
+ }%
+ },
+ until nodewalk valid/.code 2 args={%
+ \forest@untilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
+ },
+ while nodewalk valid/.code 2 args={%
+ \forest@untilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\forestloopbreak\fi}}{}}}{#2}%
+ },
+ do until nodewalk valid/.code 2 args={%
+ \forest@dountilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
+ },
+ do while nodewalk valid/.code 2 args={%
+ \forest@dountilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\forestloopbreak\fi}}{}}}{#2}%
+ },
+ until nodewalk empty/.code 2 args={%
+ \forest@untilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\forestloopbreak\fi}}{}}}{#2}%
+ },
+ while nodewalk empty/.code 2 args={%
+ \forest@untilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
+ },
+ do until nodewalk empty/.code 2 args={%
+ \forest@dountilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\forestloopbreak\fi}}{}}}{#2}%
+ },
+ do while nodewalk empty/.code 2 args={%
+ \forest@dountilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
+ },
+ break/.code={\forestloopBreak{#1}},
+ break/.default=0,
+}
+\def\forest@repeatkey#1#2{%
+ \safeRKloop
+ \ifnum\safeRKloopn>#1\relax
+ \csuse{safeRKbreak@\the\safeRKloop@depth true}%
+ \fi
+ \expandafter\unless\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
+ \pgfkeysalso{#2}%
+ \safeRKrepeat
+}
+\def\forest@untilkey#1#2{% #1 = condition, #2 = keys
+ \safeRKloop
+ #1%
+ \expandafter\unless\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
+ \pgfkeysalso{#2}%
+ \safeRKrepeat
+}
+\def\forest@dountilkey#1#2{% #1 = condition, #2 = keys
+ \safeRKloop
+ \pgfkeysalso{#2}%
+ #1%
+ \expandafter\unless\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
+ \safeRKrepeat
+}
+\def\forestloopbreak{%
+ \csname safeRKbreak@\the\safeRKloop@depth true\endcsname
+}
+\def\forestloopBreak#1{%
+ \csname safeRKbreak@\number\numexpr\the\safeRKloop@depth-#1\relax true\endcsname
+}
+\def\forestloopcount{%
+ \csname safeRKloopn@\number\numexpr\the\safeRKloop@depth\endcsname
+}
+\def\forestloopCount#1{%
+ \csname safeRKloopn@\number\numexpr\the\safeRKloop@depth-#1\endcsname
+}
+\pgfmathdeclarefunction{forestloopcount}{1}{%
+ \edef\pgfmathresult{\forestloopCount{\ifstrempty{#1}{0}{#1}}}%
+}
+\forest@copycommandkey{/forest/repeat}{/forest/nodewalk/repeat}
+\forest@copycommandkey{/forest/while}{/forest/nodewalk/while}
+\forest@copycommandkey{/forest/do while}{/forest/nodewalk/do while}
+\forest@copycommandkey{/forest/until}{/forest/nodewalk/until}
+\forest@copycommandkey{/forest/do until}{/forest/nodewalk/do until}
+\forest@copycommandkey{/forest/if}{/forest/nodewalk/if}
+\forest@copycommandkey{/forest/if nodewalk valid}{/forest/nodewalk/if nodewalk valid}
%
% \end{macrocode}
%
+% \subsection{Aggregate functions}
+%
+% \begin{macrocode}
+\forestset{
+ aggregate postparse/.is choice,
+ aggregate postparse/int/.code={%
+ \let\forest@aggregate@pgfmathpostparse\forest@aggregate@pgfmathpostparse@toint},
+ aggregate postparse/none/.code={%
+ \let\forest@aggregate@pgfmathpostparse\relax},
+ aggregate postparse/print/.code={%
+ \let\forest@aggregate@pgfmathpostparse\forest@aggregate@pgfmathpostparse@print},
+ aggregate postparse/macro/.code={%
+ \let\forest@aggregate@pgfmathpostparse\forest@aggregate@pgfmathpostparse@usemacro},
+ aggregate postparse macro/.store in=\forest@aggregate@pgfmathpostparse@macro,
+}
+\def\forest@aggregate@pgfmathpostparse@print{%
+ \pgfmathprintnumberto{\pgfmathresult}{\pgfmathresult}%
+}
+\def\forest@aggregate@pgfmathpostparse@toint{%
+ \expandafter\forest@split\expandafter{\pgfmathresult.}{.}\pgfmathresult\forest@temp
+}
+\def\forest@aggregate@pgfmathpostparse@usemacro{%
+ \forest@aggregate@pgfmathpostparse@macro
+}
+\let\forest@aggregate@pgfmathpostparse\relax
+\pgfkeys{
+ /handlers/.aggregate/.code n args=4{%
+ % #1 = start value
+ % #2 = pgfmath expression for every step
+ % #3 = pgfmath expression for after walk
+ % #4 = nodewalk
+ \edef\forest@marshal{%
+ \unexpanded{\forest@aggregate{#1}{#2}{#3}{#4}}{\pgfkeyscurrentpath}%
+ }\forest@marshal
+ },
+ /handlers/.sum/.style 2 args={/handlers/.aggregate={0}{(##1)+(#1)}{##1}{#2}},
+ /handlers/.count/.style={/handlers/.aggregate={0}{1+(##1)}{##1}{#1}},
+ /handlers/.average/.style 2 args={/handlers/.aggregate={0}{(##1)+(#1)}{##1/\forestregister{aggregate n}}{#2}},
+ /handlers/.product/.style 2 args={/handlers/.aggregate={1}{(#1)*(##1)}{##1}{#2}},
+ /handlers/.min/.style 2 args={/handlers/.aggregate={}{min(#1,##1)}{##1}{#2}},
+ /handlers/.max/.style 2 args={/handlers/.aggregate={}{max(#1,##1)}{##1}{#2}},
+ /forest/declare count register={aggregate n},
+}
+
+\def\forest@aggregate#1#2#3#4#5{%
+ % #5 = current path
+ \def\forest@aggregate@result{#1}%
+ \forest@forthis{%
+ \forestrset{aggregate n}{0}%
+ \forest@nodewalk{#4}{%
+ TeX={%
+ \forestreset{aggregate n}{\number\numexpr\forestrv{aggregate n}+1}%
+ \def\forest@marshal##1{\pgfmathparse{#2}}%
+ \expandafter\forest@marshal\expandafter{\forest@aggregate@result}%
+ \let\forest@aggregate@result\pgfmathresult
+ }%
+ }{}%
+ }%
+ \def\forest@marshal##1{\pgfmathparse{#3}}%
+ \expandafter\forest@marshal\expandafter{\forest@aggregate@result}%
+ \let\forest@aggregate@result\pgfmathresult
+ \let\forest@temp@pgfmathpostparse\pgfmathpostparse
+ \let\pgfmathpostparse\forest@aggregate@pgfmathpostparse
+ \pgfmathqparse{\forest@aggregate@result pt}%
+ \let\pgfmathpostparse\forest@temp@pgfmathpostparse
+ \let\forest@aggregate@result\pgfmathresult
+ \pgfkeysalso{#5/.expand once=\forest@aggregate@result}%
+}
+% \end{macrocode}
% \subsubsection{\texttt{pgfmath} extensions}
%
% \begin{macrocode}
@@ -6498,24 +3332,104 @@
\pgfmathdeclarefunction{strcat}{...}{%
\edef\pgfmathresult{\forest@strip@braces{#1}}%
}
+\pgfmathdeclarefunction{min_s}{2}{% #1 = node, #2 = context node (for growth rotation)
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \forest@compute@minmax@ls{#2}%
+ \pgfmathsetmacro\pgfmathresult{\forestove{min@s}}%
+ }%
+}
+\pgfmathdeclarefunction{min_l}{2}{% #1 = node, #2 = context node (for growth rotation)
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \forest@compute@minmax@ls{#2}%
+ \pgfmathsetmacro\pgfmathresult{\forestove{min@l}}%
+ }%
+}
+\pgfmathdeclarefunction{max_s}{2}{% #1 = node, #2 = context node (for growth rotation)
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \forest@compute@minmax@ls{#2}%
+ \pgfmathsetmacro\pgfmathresult{\forestove{max@s}}%
+ }%
+}
+\pgfmathdeclarefunction{max_l}{2}{% #1 = node, #2 = context node (for growth rotation)
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \forest@compute@minmax@ls{#2}%
+ \pgfmathsetmacro\pgfmathresult{\forestove{max@l}}%
+ }%
+}
+\def\forest@compute@minmax@ls#1{% #1 = nodewalk; in the context of which node?
+ {%
+ \pgftransformreset
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \pgftransformrotate{-\forestove{grow}}%
+ }%
+ \forestoget{min x}\forest@temp@minx
+ \forestoget{min y}\forest@temp@miny
+ \forestoget{max x}\forest@temp@maxx
+ \forestoget{max y}\forest@temp@maxy
+ \pgfpointtransformed{\pgfqpoint{\forest@temp@minx}{\forest@temp@miny}}%
+ \forestoeset{min@l}{\the\pgf@x}%
+ \forestoeset{min@s}{\the\pgf@y}%
+ \forestoeset{max@l}{\the\pgf@x}%
+ \forestoeset{max@s}{\the\pgf@y}%
+ \pgfpointtransformed{\pgfqpoint{\forest@temp@minx}{\forest@temp@maxy}}%
+ \ifdim\pgf@x<\forestove{min@l}\relax\forestoeset{min@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y<\forestove{min@s}\relax\forestoeset{min@s}{\the\pgf@y}\fi
+ \ifdim\pgf@x>\forestove{max@l}\relax\forestoeset{max@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y>\forestove{max@s}\relax\forestoeset{max@s}{\the\pgf@y}\fi
+ \pgfpointtransformed{\pgfqpoint{\forest@temp@maxx}{\forest@temp@miny}}%
+ \ifdim\pgf@x<\forestove{min@l}\relax\forestoeset{min@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y<\forestove{min@s}\relax\forestoeset{min@s}{\the\pgf@y}\fi
+ \ifdim\pgf@x>\forestove{max@l}\relax\forestoeset{max@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y>\forestove{max@s}\relax\forestoeset{max@s}{\the\pgf@y}\fi
+ \pgfpointtransformed{\pgfqpoint{\forest@temp@maxx}{\forest@temp@maxy}}%
+ \ifdim\pgf@x<\forestove{min@l}\relax\forestoeset{min@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y<\forestove{min@s}\relax\forestoeset{min@s}{\the\pgf@y}\fi
+ \ifdim\pgf@x>\forestove{max@l}\relax\forestoeset{max@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y>\forestove{max@s}\relax\forestoeset{max@s}{\the\pgf@y}\fi
+ % smuggle out
+ \edef\forest@marshal{%
+ \noexpand\forestoeset{min@l}{\forestove{min@l}}%
+ \noexpand\forestoeset{min@s}{\forestove{min@s}}%
+ \noexpand\forestoeset{max@l}{\forestove{max@l}}%
+ \noexpand\forestoeset{max@s}{\forestove{max@s}}%
+ }\expandafter
+ }\forest@marshal
+}
\def\forest@pgfmathhelper@attribute@toks#1#2{%
\forest@forthis{%
\forest@nameandgo{#1}%
- \forestoget{#2}\pgfmathresult
+ \ifnum\forest@cn=0
+ \def\pgfmathresult{}%
+ \else
+ \forestoget{#2}\pgfmathresult
+ \fi
}%
}
\def\forest@pgfmathhelper@attribute@dimen#1#2{%
\forest@forthis{%
\forest@nameandgo{#1}%
- \forestoget{#2}\forest@temp
- \pgfmathparse{+\forest@temp}%
+ \ifnum\forest@cn=0
+ \def\pgfmathresult{0pt}%
+ \else
+ \forestoget{#2}\forest@temp
+ \pgfmathparse{+\forest@temp}%
+ \fi
}%
}
\def\forest@pgfmathhelper@attribute@count#1#2{%
\forest@forthis{%
\forest@nameandgo{#1}%
- \forestoget{#2}\forest@temp
- \pgfmathtruncatemacro\pgfmathresult{\forest@temp}%
+ \ifnum\forest@cn=0
+ \def\pgfmathresult{0}%
+ \else
+ \forestoget{#2}\forest@temp
+ \pgfmathtruncatemacro\pgfmathresult{\forest@temp}%
+ \fi
}%
}
\pgfmathdeclarefunction{id}{1}{%
@@ -6536,6 +3450,1153 @@
}
% \end{macrocode}
%
+% \subsection{Nodewalk}
+%
+% Setup machinery.
+%
+% \begin{macrocode}
+\def\forest@nodewalk@n{0}
+\def\forest@nodewalk@historyback{0,}
+\def\forest@nodewalk@historyforward{0,}
+\def\forest@nodewalk@origin{0}
+\def\forest@nodewalk@config@everystep@independent@before#1{% #1 = every step keylist
+ \forestrset{every step}{#1}%
+}
+\def\forest@nodewalk@config@everystep@independent@after{%
+ \noexpand\forestrset{every step}{\forestrv{every step}}%
+}
+\def\forest@nodewalk@config@history@independent@before{%
+ \def\forest@nodewalk@n{0}%
+ \edef\forest@nodewalk@origin{\forest@cn}%
+ \def\forest@nodewalk@historyback{0,}%
+ \def\forest@nodewalk@historyforward{0,}%
+}
+\def\forest@nodewalk@config@history@independent@after{%
+ \edef\noexpand\forest@nodewalk@n{\expandonce{\forest@nodewalk@n}}%
+ \edef\noexpand\forest@nodewalk@origin{\expandonce{\forest@nodewalk@origin}}%
+ \edef\noexpand\forest@nodewalk@historyback{\expandonce{\forest@nodewalk@historyback}}%
+ \edef\noexpand\forest@nodewalk@historyforward{\expandonce{\forest@nodewalk@historyforward}}%
+}
+\def\forest@nodewalk@config@everystep@shared@before#1{}% #1 = every step keylist
+\def\forest@nodewalk@config@everystep@shared@after{}
+\def\forest@nodewalk@config@history@shared@before{}
+\def\forest@nodewalk@config@history@shared@after{}
+\def\forest@nodewalk@config@everystep@inherited@before#1{}% #1 = every step keylist
+\let\forest@nodewalk@config@everystep@inherited@after\forest@nodewalk@config@everystep@independent@after
+\def\forest@nodewalk@config@history@inherited@before{}
+\let\forest@nodewalk@config@history@inherited@after\forest@nodewalk@config@history@independent@after
+\def\forest@nodewalk#1#2{% #1 = nodewalk, #2 = every step keylist
+ \def\forest@nodewalk@config@everystep@method{independent}%
+ \def\forest@nodewalk@config@history@method{independent}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \forest@Nodewalk{#1}{#2}%
+ }%
+}
+\def\forest@Nodewalk#1#2{% #1 = nodewalk, #2 = every step keylist
+ \edef\forest@marshal{%
+ \noexpand\pgfqkeys{/forest/nodewalk}{\unexpanded{#1}}%
+ \csname forest@nodewalk@config@everystep@\forest@nodewalk@config@everystep@method @after\endcsname
+ \csname forest@nodewalk@config@history@\forest@nodewalk@config@history@method @after\endcsname
+ }%
+ \csname forest@nodewalk@config@everystep@\forest@nodewalk@config@everystep@method @before\endcsname{#2}%
+ \csname forest@nodewalk@config@history@\forest@nodewalk@config@history@method @before\endcsname
+ \forest@nodewalk@fakefalse
+ \forest@marshal
+}
+\pgfmathdeclarefunction{valid}{1}{%
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \edef\pgfmathresult{\ifnum\forest@cn=0 0\else 1\fi}%
+ }%
+}
+\pgfmathdeclarefunction{invalid}{1}{%
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \edef\pgfmathresult{\ifnum\forest@cn=0 1\else 0\fi}%
+ }%
+}
+\newif\ifforest@nodewalk@fake
+\def\forest@nodewalk@oninvalid{error}
+\def\forest@nodewalk@makestep{%
+ \ifnum\forest@cn=0
+ \csname forest@nodewalk@makestep@oninvalid@\forest@nodewalk@config@oninvalid\endcsname
+ \else
+ \forest@nodewalk@makestep@
+ \fi
+}
+\def\forest@nodewalk@makestep@oninvalid@step{\forest@nodewalk@makestep@}
+\def\forest@nodewalk@makestep@oninvalid@error{\PackageError{forest}{nodewalk stepped to the invalid node; stack: "\forest@nodewalk@currentstepname"}{}}%
+\let\forest@nodewalk@makestep@oninvalid@fake\relax
+\def\forest@nodewalk@makestep@oninvalid@compatfake{%
+ \forest@deprecated{last step in stack "\forest@nodewalk@currentstepname", which stepped on an invalid node; enabled by "compat=ignoreinvalidsteps". Use "on invalid={fake}{...}" or "for Nodewalk={on invalid=fake}{...}{...}" instead.}%
+}%
+\def\forest@nodewalk@makestep@oninvalid@inherited{\csname forest@nodewalk@makestep@oninvalid@\forest@nodewalk@oninvalid\endcsname}
+\def\forest@nodewalk@makestep@{%
+ \ifforest@nodewalk@fake
+ \else
+ \edef\forest@nodewalk@n{\number\numexpr\forest@nodewalk@n+1}%
+ \epreto\forest@nodewalk@historyback{\forest@cn,}%
+ \def\forest@nodewalk@historyforward{0,}%
+ \ifforestdebug\forest@nodewalk@makestep@debug\fi
+ \forest@process@keylist@register{every step}%
+ \fi
+}
+\def\forest@nodewalk@makestep@debug{%
+ \edef\forest@marshal{%
+ \noexpand\typeout{\ifforest@nodewalk@fake fake \fi "\forest@nodewalk@currentstepname" step to node id=\forest@cn, content=\forestoption{content}}%
+ }\forest@marshal
+}%
+\forestset{
+ debug/.is if=forestdebug,
+}
+\def\forest@handlers@savecurrentpath{%
+ \edef\pgfkeyscurrentkey{\pgfkeyscurrentpath}%
+ \let\forest@currentkey\pgfkeyscurrentkey
+ \pgfkeys@split@path
+ \edef\forest@currentpath{\pgfkeyscurrentpath}%
+ \let\forest@currentname\pgfkeyscurrentname
+}
+\pgfkeys{/handlers/save current path/.code={\forest@handlers@savecurrentpath}}
+\newif\ifforest@nodewalkstephandler@style
+\newif\ifforest@nodewalkstephandler@autostep
+\newif\ifforest@nodewalkstephandler@stripfakesteps
+\newif\ifforest@nodewalkstephandler@muststartatvalidnode
+\newif\ifforest@nodewalkstephandler@makefor
+\let\forest@nodewalkstephandler@styletrueorfalse\forest@nodewalkstephandler@stylefalse
+\def\forest@nodewalk@currentstepname{}
+\forestset{
+ /forest/define@step/style/.is if=forest@nodewalkstephandler@style,
+ /forest/define@step/autostep/.is if=forest@nodewalkstephandler@autostep,
+ % 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
+ /forest/define@step/strip fake steps/.is if=forest@nodewalkstephandler@stripfakesteps,
+ % this can never happen with autosteps ...
+ /forest/define@step/autostep/.append code={%
+ \ifforest@nodewalkstephandler@autostep
+ \forest@nodewalkstephandler@stripfakestepsfalse
+ \fi
+ },
+ /forest/define@step/must start at valid node/.is if=forest@nodewalkstephandler@muststartatvalidnode,
+ /forest/define@step/n args/.store in=\forest@nodewalkstephandler@nargs,
+ /forest/define@step/make for/.is if=forest@nodewalkstephandler@makefor,
+ /forest/define@step/@bare/.style={strip fake steps=false,must start at valid node=false,make for=false},
+ define long step/.code n args=3{%
+ \forest@nodewalkstephandler@styletrueorfalse % true for end users; but in the package, most of steps are defined by .code
+ \forest@nodewalkstephandler@autostepfalse
+ \forest@nodewalkstephandler@stripfakestepstrue
+ \forest@nodewalkstephandler@muststartatvalidnodetrue % most steps can only start at a valid node
+ \forest@nodewalkstephandler@makefortrue % make for prefix?
+ \def\forest@nodewalkstephandler@nargs{0}%
+ \pgfqkeys{/forest/define@step}{#2}%
+ \forest@temp@toks{#3}% handler code
+ \ifforest@nodewalkstephandler@style
+ \expandafter\forest@temp@toks\expandafter{%
+ \expandafter\pgfkeysalso\expandafter{\the\forest@temp@toks}%
+ }%
+ \fi
+ \ifforest@nodewalkstephandler@autostep
+ \apptotoks\forest@temp@toks{\forest@nodewalk@makestep}%
+ \fi
+ \ifforest@nodewalkstephandler@stripfakesteps
+ \expandafter\forest@temp@toks\expandafter{\expandafter\forest@nodewalk@stripfakesteps\expandafter{\the\forest@temp@toks}}%
+ \fi
+ \ifforest@nodewalkstephandler@muststartatvalidnode
+ \edef\forest@marshal{%
+ \noexpand\forest@temp@toks{%
+ \unexpanded{%
+ \ifnum\forest@cn=0
+ \csname forest@nodewalk@start@oninvalid@\forest@nodewalk@oninvalid\endcsname{#1}%
+ \else
+ }%
+ \noexpand\@escapeif{\the\forest@temp@toks}%
+ \noexpand\fi
+ }%
+ }\forest@marshal
+ \fi
+ \pretotoks\forest@temp@toks{\appto\forest@nodewalk@currentstepname{,#1}}%
+ \expandafter\forest@temp@toks\expandafter{\expandafter\forest@saveandrestoremacro\expandafter\forest@nodewalk@currentstepname\expandafter{\the\forest@temp@toks}}%
+ \ifforestdebug
+ \epretotoks\forest@temp@toks{\noexpand\typeout{Starting step "#1" from id=\forest@cn
+ \ifnum\forest@nodewalkstephandler@nargs>0 with args ####1\fi
+ \ifnum\forest@nodewalkstephandler@nargs>1 ,####2\fi
+ \ifnum\forest@nodewalkstephandler@nargs>2 ,####3\fi
+ \ifnum\forest@nodewalkstephandler@nargs>3 ,####4\fi
+ \ifnum\forest@nodewalkstephandler@nargs>4 ,####5\fi
+ \ifnum\forest@nodewalkstephandler@nargs>5 ,####6\fi
+ \ifnum\forest@nodewalkstephandler@nargs>6 ,####7\fi
+ \ifnum\forest@nodewalkstephandler@nargs>7 ,####8\fi
+ \ifnum\forest@nodewalkstephandler@nargs>8 ,####9\fi
+ }}%
+ \fi
+ \def\forest@temp{/forest/nodewalk/#1/.code}%
+ \ifnum\forest@nodewalkstephandler@nargs<2
+ \eappto\forest@temp{=}%
+ \else\ifnum\forest@nodewalkstephandler@nargs=2
+ \eappto\forest@temp{ 2 args=}%
+ \else
+ \eappto\forest@temp{ n args={\forest@nodewalkstephandler@nargs}}%
+ \fi\fi
+ \eappto\forest@temp{{\the\forest@temp@toks}}%
+ \expandafter\pgfkeysalso\expandafter{\forest@temp}%
+ \ifforest@nodewalkstephandler@makefor
+ \ifnum\forest@nodewalkstephandler@nargs=0
+ \forestset{%
+ for #1/.code={\forest@forstepwrapper{#1}{##1}},
+ }%
+ \else\ifnum\forest@nodewalkstephandler@nargs=1
+ \forestset{%
+ for #1/.code 2 args={\forest@forstepwrapper{#1={##1}}{##2}},
+ }%
+ \else
+ \forestset{%
+ for #1/.code n args/.expanded=%
+ {\number\numexpr\forest@nodewalkstephandler@nargs+1}%
+ {\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}},
+ }%
+ \fi\fi
+ \fi
+ },
+}
+% \end{macrocode}
+% |\forest@forstepwrapper| is defined so that it can be changed by |compat| to create unfailable spatial propagators from v1.0.
+% \begin{macrocode}
+\def\forest@forstepwrapper#1#2{\forest@forthis{\forest@nodewalk{#1}{#2}}}
+\def\forest@util@nargs#1#2#3{% #1 = prefix (#, ##, ...), #2 = n args, #3=start; returns {#start}{#start+1}...{#start+n}
+ \ifnum#2>0 {#1\number\numexpr#3+1}\fi
+ \ifnum#2>1 {#1\number\numexpr#3+2}\fi
+ \ifnum#2>2 {#1\number\numexpr#3+3}\fi
+ \ifnum#2>3 {#1\number\numexpr#3+4}\fi
+ \ifnum#2>4 {#1\number\numexpr#3+5}\fi
+ \ifnum#2>5 {#1\number\numexpr#3+6}\fi
+ \ifnum#2>6 {#1\number\numexpr#3+7}\fi
+ \ifnum#2>7 {#1\number\numexpr#3+8}\fi
+ \ifnum#2>8 {#1\number\numexpr#3+9}\fi
+}
+\def\forest@nodewalk@start@oninvalid@fake#1{}
+\def\forest@nodewalk@start@oninvalid@real#1{}
+\def\forest@nodewalk@start@oninvalid@error#1{\PackageError{forest}{nodewalk step "#1" cannot start at the invalid node}{}}
+% \end{macrocode}
+% Define long-form single-step walks.
+% \begin{macrocode}
+\forestset{
+ define long step={current}{autostep}{},
+ define long step={next}{autostep}{\edef\forest@cn{\forestove{@next}}},
+ define long step={previous}{autostep}{\edef\forest@cn{\forestove{@previous}}},
+ define long step={parent}{autostep}{\edef\forest@cn{\forestove{@parent}}},
+ define long step={first}{autostep}{\edef\forest@cn{\forestove{@first}}},
+ define long step={last}{autostep}{\edef\forest@cn{\forestove{@last}}},
+ define long step={sibling}{autostep}{%
+ \edef\forest@cn{%
+ \ifnum\forestove{@previous}=0
+ \forestove{@next}%
+ \else
+ \forestove{@previous}%
+ \fi
+ }%
+ },
+ define long step={next node}{autostep}{\edef\forest@cn{\forest@node@linearnextid}},
+ define long step={previous node}{autostep}{\edef\forest@cn{\forest@node@linearpreviousid}},
+ define long step={first leaf}{autostep}{%
+ \safeloop
+ \edef\forest@cn{\forestove{@first}}%
+ \unless\ifnum\forestove{@first}=0
+ \saferepeat
+ },
+ define long step={first leaf'}{autostep}{%
+ \safeloop
+ \unless\ifnum\forestove{@first}=0
+ \edef\forest@cn{\forestove{@first}}%
+ \saferepeat
+ },
+ define long step={last leaf}{autostep}{%
+ \safeloop
+ \edef\forest@cn{\forestove{@last}}%
+ \unless\ifnum\forestove{@last}=0
+ \saferepeat
+ },
+ define long step={last leaf'}{autostep}{%
+ \safeloop
+ \unless\ifnum\forestove{@last}=0
+ \edef\forest@cn{\forestove{@last}}%
+ \saferepeat
+ },
+ define long step={next leaf}{style,strip fake steps=false}{group={do until={n_children()==0}{next node}}},
+ define long step={previous leaf}{style,strip fake steps=false}{group={do until={n_children()==0}{previous node}}},
+ define long step={next on tier}{autostep}{%
+ \def\forest@temp{#1}%
+ \ifx\forest@temp\pgfkeysnovalue@text
+ \forestoget{tier}\forest@nodewalk@giventier
+ \else
+ \def\forest@nodewalk@giventier{#1}%
+ \fi
+ \edef\forest@cn{\forest@node@linearnextnotdescendantid}%
+ \safeloop
+ \forestoget{tier}\forest@nodewalk@tier
+ \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
+ \edef\forest@cn{\forest@node@linearnextid}%
+ \saferepeat
+ },
+ define long step={previous on tier}{autostep}{%
+ \def\forest@temp{#1}%
+ \ifx\forest@temp\pgfkeysnovalue@text
+ \forestoget{tier}\forest@nodewalk@giventier
+ \else
+ \def\forest@nodewalk@giventier{#1}%
+ \fi
+ \safeloop
+ \edef\forest@cn{\forest@node@linearpreviousid}%
+ \forestoget{tier}\forest@nodewalk@tier
+ \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
+ \saferepeat
+ },
+ %
+ define long step={root}{autostep,must start at valid node=false}{%
+ \edef\forest@cn{\forest@node@rootid}},
+ define long step={root'}{autostep,must start at valid node=false}{%
+ \forestOifdefined{\forest@root}{@parent}{\edef\forest@cn{\forest@root}}{\edef\forest@cn{0}}%
+ },
+ define long step={origin}{autostep,must start at valid node=false}{\edef\forest@cn{\forest@nodewalk@origin}},
+ %
+ define long step={n}{autostep,n args=1}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \edef\forest@cn{\forest@node@nthchildid{\forest@temp@n}}%
+ },
+ define long step={n}{autostep,make for=false,n args=1}{%
+ % Yes, twice. ;-)
+ % n=1 and n(ext)
+ \def\forest@nodewalk@temp{#1}%
+ \ifx\forest@nodewalk@temp\pgfkeysnovalue@text
+ \edef\forest@cn{\forestove{@next}}%
+ \else
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \edef\forest@cn{\forest@node@nthchildid{\forest@temp@n}}%
+ \fi
+ },
+ define long step={n'}{autostep,n args=1}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \edef\forest@cn{\forest@node@nbarthchildid{\forest@temp@n}}%
+ },
+ define long step={to tier}{autostep,n args=1}{%
+ \def\forest@nodewalk@giventier{#1}%
+ \safeloop
+ \forestoget{tier}\forest@nodewalk@tier
+ \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
+ \forestoget{@parent}\forest@cn
+ \saferepeat
+ },
+ %
+ define long step={name}{autostep,n args=1,must start at valid node=false}{%
+ \edef\forest@cn{%
+ \forest@node@Ifnamedefined{#1}{\forest@node@Nametoid{#1}}{0}%
+ }%
+ },
+ define long step={id}{autostep,n args=1,must start at valid node=false}{%
+ \forestOifdefined{#1}{@parent}{\edef\forest@cn{#1}}{\edef\forest@cn{0}}%
+ },
+ define long step={Nodewalk}{n args=3,@bare}{% #1 = config, #2 = nodewalk
+ \def\forest@nodewalk@config@everystep@method{independent}%
+ \def\forest@nodewalk@config@history@method{shared}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \pgfqkeys{/forest/nodewalk@config}{#1}%
+ \forest@Nodewalk{#2}{#3}%
+ }%
+ },
+ define long step={nodewalk}{n args=2,@bare}{% #1 = nodewalk, #2 = every step
+ \forest@nodewalk{#1}{#2}%
+ },
+ define long step={nodewalk'}{n args=1,@bare}{% #1 = nodewalk, #2 = every step
+ \def\forest@nodewalk@config@everystep@method{inherited}%
+ \def\forest@nodewalk@config@history@method{independent}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \forest@Nodewalk{#1}{}%
+ }%
+ },
+ % these must be defined explicitely, as prefix "for" normally introduces the every-step keylist
+ for nodewalk/.code 2 args={%
+ \forest@forthis{\forest@nodewalk{#1}{#2}}},
+ for nodewalk'/.code={%
+ \def\forest@nodewalk@config@everystep@method{inherited}%
+ \def\forest@nodewalk@config@history@method{independent}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \forest@forthis{\forest@Nodewalk{#1}{}}%
+ }%
+ },
+ for Nodewalk/.code n args=3{% #1 = config, #2 = nodewalk, #3 = every-step
+ \def\forest@nodewalk@config@everystep@method{inherited}%
+ \def\forest@nodewalk@config@history@method{independent}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \pgfqkeys{/forest/nodewalk@config}{#1}%
+ \forest@forthis{\forest@Nodewalk{#2}{#3}}%
+ }%
+ },
+ copy command key={/forest/for nodewalk}{/forest/nodewalk/for nodewalk},
+ copy command key={/forest/for nodewalk'}{/forest/nodewalk/for nodewalk'},
+ copy command key={/forest/for Nodewalk}{/forest/nodewalk/for Nodewalk},
+ declare keylist register=every step,
+ every step'={},
+ %%% begin nodewalk config
+ nodewalk@config/.cd,
+ every@step/.is choice,
+ every@step/independent/.code={},
+ every@step/inherited/.code={},
+ every@step/shared/.code={},
+ every step/.store in=\forest@nodewalk@config@everystep@method,
+ every step/.prefix style={every@step=#1},
+ @history/independent/.code={},
+ @history/inherited/.code={},
+ @history/shared/.code={},
+ history/.store in=\forest@nodewalk@config@history@method,
+ history/.prefix style={@history=#1},
+ on@invalid/.is choice,
+ on@invalid/error/.code={},
+ on@invalid/fake/.code={},
+ on@invalid/step/.code={},
+ on@invalid/inherited/.code={},
+ on invalid/.store in=\forest@nodewalk@config@oninvalid,
+ on invalid/.prefix style={on@invalid=#1},
+ %%% end nodewalk config
+}
+\forestset{
+ define long step={branch}{n args=1,@bare,style}{%
+ branch@@build/.style={branch@build={##1}{}},
+ @branch={#1},
+ },
+ define long step={branch'}{n args=1,@bare,style}{%
+ branch@@build/.style/.expanded={branch@build={####1}{\forestregister{every step},}},
+ @branch={#1},
+ },
+ nodewalk/@branch/.style={
+ TeX={\forest@temp@toks{}},
+ split/.process args={r}{#1}{,}{branch@@build},
+ branch@do,
+ },
+ nodewalk/branch@build/.code 2 args={% #1 = nodewalk for this branch, #2 = perhaps every step keylist
+ \ifstrempty{#1}{}{%
+ \expandafter\ifstrempty\expandafter{\the\forest@temp@toks}{%
+ \edef\forest@marshal{%
+ \noexpand\forest@temp@toks{for nodewalk={\unexpanded{#1}}{\forestregister{every step}}}%
+ }\forest@marshal
+ }{%
+ \edef\forest@marshal{%
+ \noexpand\forest@temp@toks{for nodewalk={\unexpanded{#1}}{#2\the\forest@temp@toks}}%
+ }\forest@marshal
+ }%
+ }%
+ },
+ nodewalk/branch@do/.code={%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{fake={\the\forest@temp@toks}}%
+ }\forest@marshal
+ },
+ define long step={group}{autostep}{\forest@go{#1}},
+ nodewalk/fake/.code={%
+ \forest@saveandrestoreifcs{forest@nodewalk@fake}{%
+ \forest@nodewalk@faketrue
+ \pgfkeysalso{#1}%
+ }%
+ },
+ nodewalk/real/.code={%
+ \forest@saveandrestoreifcs{forest@nodewalk@fake}{%
+ \forest@nodewalk@fakefalse
+ \pgfkeysalso{#1}%
+ }%
+ },
+ define long step={filter}{n args=2,@bare,style}{% #1 = nodewalk, #2 = condition
+ nodewalk/.expanded={\unexpanded{#1}}{if={\unexpanded{#2}}{\forestregister{every step}}{}}{}
+ },
+ on@invalid/.is choice,
+ on@invalid/error/.code={},
+ on@invalid/fake/.code={},
+ on@invalid/step/.code={},
+ on invalid/.code 2 args={%
+ \pgfkeysalso{/forest/on@invalid={#1}}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \def\forest@nodewalk@oninvalid{#1}%
+ \pgfkeysalso{#2}%
+ }%
+ },
+ define long step={strip fake steps}{n args=1,@bare}{%
+ \forest@nodewalk@stripfakesteps{\pgfkeysalso{#1}}},
+ define long step={walk back}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \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}%
+ \forest@nodewalk@back@updatehistory
+ },
+ nodewalk/walk back/.default=1,
+ define long step={jump back}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{(#1)+\ifnum\forest@cn=0 0\else1\fi}%
+ \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}%
+ \forest@nodewalk@back@updatehistory
+ },
+ nodewalk/jump back/.default=1,
+ define long step={back}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \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}}%
+ \forest@nodewalk@back@updatehistory
+ },
+ nodewalk/back/.default=1,
+ define long step={walk forward}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \forest@nodewalk@walklist{\forest@nodewalk@historyback}{\forest@nodewalk@historyforward}{0}{\forest@temp@n}{\let\forest@cn\forest@nodewalk@cn\forest@nodewalk@makestep}%
+ \forest@nodewalk@forward@updatehistory
+ },
+ nodewalk/walk forward/.default=1,
+ define long step={jump forward}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \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}%
+ \forest@nodewalk@forward@updatehistory
+ },
+ nodewalk/jump forward/.default=1,
+ define long step={forward}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \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}}%
+ \forest@nodewalk@forward@updatehistory
+ },
+ nodewalk/forward/.default=1,
+ define long step={last valid'}{@bare}{%
+ \ifnum\forest@cn=0
+ \forest@nodewalk@tolastvalid
+ \forest@nodewalk@makestep
+ \fi
+ },
+ define long step={last valid}{@bare}{%
+ \forest@nodewalk@tolastvalid
+ },
+ define long step={reverse}{n args=1,@bare,make for}{%
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ \global\let\forest@global@tempn\forest@nodewalk@n
+ }}{}%
+ \forest@nodewalk@walklist{}{\forest@global@temp}{0}{\forest@global@tempn}{\let\forest@cn\forest@nodewalk@cn\forest@nodewalk@makestep}%
+ },
+ define long step={walk and reverse}{n args=1,@bare,make for}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \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}%
+ }\forest@marshal
+ },
+ define long step={sort}{n args=1,@bare,make for}{%
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ \global\let\forest@global@tempn\forest@nodewalk@n
+ }}{}%
+ \forest@nodewalk@sortlist{\forest@global@temp}{\forest@global@tempn}\forest@sort@ascending
+ },
+ define long step={sort'}{n args=1,@bare,make for}{%
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ \global\let\forest@global@tempn\forest@nodewalk@n
+ }}{}%
+ \forest@nodewalk@sortlist{\forest@global@temp}{\forest@global@tempn}\forest@sort@descending
+ },
+ define long step={walk and sort}{n args=1,@bare,make for}{% walk as given, then walk sorted
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@sortlist{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}\noexpand\forest@sort@ascending
+ }\forest@marshal
+ },
+ define long step={walk and sort'}{n args=1,@bare,make for}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@sortlist{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}\noexpand\forest@sort@descending
+ }\forest@marshal
+ },
+ sort by/.store in=\forest@nodesort@by,
+ define long step={save}{n args=2,@bare,make for}{% #1 = name, #2 = nodewalk
+ \forest@forthis{%
+ \forest@nodewalk{#2,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ \global\let\forest@global@tempn\forest@nodewalk@n
+ }}{}%
+ }%
+ \forest@nodewalk@walklist{}{\forest@global@temp}{0}{\forest@global@tempn}\relax
+ \csedef{forest@nodewalk@saved@#1}{\forest@nodewalk@walklist@walked}%
+ },
+ define long step={walk and save}{n args=2,@bare,make for}{% #1 = name, #2 = nodewalk
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#2}}%
+ \noexpand\forest@nodewalk@walklist{}{\noexpand\forest@nodewalk@historyback}{0}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}\relax
+ }\forest@marshal
+ \csedef{forest@nodewalk@saved@#1}{\forest@nodewalk@walklist@walked}%
+ },
+ nodewalk/save history/.code 2 args={% #1 = back, forward
+ \csedef{forest@nodewalk@saved@#1}{\forest@nodewalk@historyback}%
+ \csedef{forest@nodewalk@saved@#2}{\forest@nodewalk@historyforward}%
+ },
+ define long step={load}{n args=1,@bare,make for}{%
+ \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}%
+ },
+ if in saved nodewalk/.code n args=4{% is node #1 in nodewalk #2; yes: #3, no: #4
+ \forest@forthis{%
+ \forest@go{#1}%
+ \edef\forest@marshal{%
+ \noexpand\pgfutil@in@{,\forest@cn,}{,\csuse{forest@nodewalk@saved@#2},}%
+ }\forest@marshal
+ }%
+ \ifpgfutil@in@
+ \@escapeif{\pgfkeysalso{#3}}%
+ \else
+ \@escapeif{\pgfkeysalso{#4}}%
+ \fi
+ },
+ where in saved nodewalk/.style n args=4{
+ for tree={if in saved nodewalk={#1}{#2}{#3}{#4}}
+ },
+ nodewalk/options/.code={\forestset{#1}},
+ nodewalk/TeX/.code={#1},
+ nodewalk/TeX'/.code={\appto\forest@externalize@loadimages{#1}#1},
+ nodewalk/TeX''/.code={\appto\forest@externalize@loadimages{#1}},
+ nodewalk/typeout/.style={TeX={\typeout{#1}}},
+ % repeat is taken later from /forest/repeat
+}
+\def\forest@nodewalk@walklist#1#2#3#4#5{%
+ % #1 = list of preceding, #2 = list to walk
+ % #3 = from, #4 = to
+ % #5 = every step code
+ \let\forest@nodewalk@cn\forest@cn
+ \edef\forest@marshal{%
+ \noexpand\forest@nodewalk@walklist@{#1}{#2}{\number\numexpr#3}{\number\numexpr#4}{1}{0}{\unexpanded{#5}}%
+ }\forest@marshal
+}
+\def\forest@nodewalk@walklist@#1#2#3#4#5#6#7{%
+ % #1 = list of walked, #2 = list to walk
+ % #3 = from, #4 = to
+ % #5 = current step n, #6 = steps made
+ % #7 = every step code
+ \def\forest@nodewalk@walklist@walked{#1}%
+ \def\forest@nodewalk@walklist@rest{#2}%
+ \edef\forest@nodewalk@walklist@stepsmade{#6}%
+ \ifnum#4<0
+ \forest@temptrue
+ \else
+ \ifnum#5>#4\relax
+ \forest@tempfalse
+ \else
+ \forest@temptrue
+ \fi
+ \fi
+ \ifforest@temp
+ \edef\forest@nodewalk@cn{\forest@csvlist@getfirst@{#2}}%
+ \ifnum\forest@nodewalk@cn=0
+ #7%
+ \else
+ \ifnum#5>#3\relax
+ #7%
+ \edef\forest@nodewalk@walklist@stepsmade{\number\numexpr#6+1}%
+ \fi
+ \forest@csvlist@getfirstrest@{#2}\forest@nodewalk@cn\forest@nodewalk@walklist@rest
+ \@escapeifif{%
+ \edef\forest@marshal{%
+ \noexpand\forest@nodewalk@walklist@
+ {\forest@nodewalk@cn,#1}{\forest@nodewalk@walklist@rest}{#3}{#4}{\number\numexpr#5+1}{\forest@nodewalk@walklist@stepsmade}{\unexpanded{#7}}%
+ }\forest@marshal
+ }%
+ \fi
+ \fi
+}
+
+\def\forest@nodewalk@back@updatehistory{%
+ \ifnum\forest@cn=0
+ \let\forest@nodewalk@historyback\forest@nodewalk@walklist@rest
+ \let\forest@nodewalk@historyforward\forest@nodewalk@walklist@walked
+ \else
+ \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalk@walklist@walked}\forest@temp\forest@nodewalk@historyforward
+ \edef\forest@nodewalk@historyback{\forest@temp,\forest@nodewalk@walklist@rest}%
+ \fi
+}
+\def\forest@nodewalk@forward@updatehistory{%
+ \let\forest@nodewalk@historyforward\forest@nodewalk@walklist@rest
+ \let\forest@nodewalk@historyback\forest@nodewalk@walklist@walked
+}
+\def\forest@go#1{%
+ \def\forest@nodewalk@config@everystep@method{independent}%
+ \def\forest@nodewalk@config@history@method{inherited}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \forest@Nodewalk{#1}{}%
+ }%
+}
+\def\forest@csvlist@getfirst@#1{% assuming that the list is nonempty and finishes with a comma
+ \forest@csvlist@getfirst@@#1\forest@csvlist@getfirst@@}
+\def\forest@csvlist@getfirst@@#1,#2\forest@csvlist@getfirst@@{#1}
+\def\forest@csvlist@getrest@#1{% assuming that the list is nonempty and finishes with a comma
+ \forest@csvlist@getrest@@#1\forest@csvlist@getrest@@}
+\def\forest@csvlist@getrest@@#1,#2\forest@csvlist@getrest@@{#2}
+\def\forest@csvlist@getfirstrest@#1#2#3{% assuming that the list is nonempty and finishes with a comma
+ % #1 = list, #2 = cs receiving first, #3 = cs receiving rest
+ \forest@csvlist@getfirstrest@@#1\forest@csvlist@getfirstrest@@{#2}{#3}}
+\def\forest@csvlist@getfirstrest@@#1,#2\forest@csvlist@getfirstrest@@#3#4{%
+ \def#3{#1}%
+ \def#4{#2}%
+}
+\def\forest@nodewalk@stripfakesteps#1{%
+ % go to the last valid node if the walk contained any nodes, otherwise restore the current node
+ \edef\forest@marshal{%
+ \unexpanded{#1}%
+ \noexpand\ifnum\noexpand\forest@nodewalk@n=\forest@nodewalk@n\relax
+ \def\noexpand\forest@cn{\forest@cn}%
+ \noexpand\else
+ \unexpanded{%
+ \edef\forest@cn{%
+ \expandafter\forest@csvlist@getfirst@\expandafter{\forest@nodewalk@historyback}%
+ }%
+ }%
+ \noexpand\fi
+ }\forest@marshal
+}
+\def\forest@nodewalk@tolastvalid{%
+ \ifnum\forest@cn=0
+ \edef\forest@cn{\expandafter\forest@csvlist@getfirst@\expandafter{\forest@nodewalk@historyback}}%
+ \ifnum\forest@cn=0
+ \let\forest@cn\forest@nodewalk@origin
+ \fi
+ \fi
+}
+\def\forest@nodewalk@sortlist#1#2#3{%#1=list,#2=to,#3=asc/desc
+ \edef\forest@nodewalksort@list{#1}%
+ \expandafter\forest@nodewalk@sortlist@\expandafter{\number\numexpr#2}{#3}%
+}
+\def\forest@nodewalk@sortlist@#1#2{%#1=to,#2=asc/desc
+ \safeloop
+ \unless\ifnum\safeloopn>#1\relax
+ \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalksort@list}\forest@nodewalksort@cn\forest@nodewalksort@list
+ \csedef{forest@nodesort@\safeloopn}{\forest@nodewalksort@cn}%
+ \saferepeat
+ \edef\forest@nodesort@sortkey{\forest@nodesort@by}%
+ \forest@sort\forest@nodesort@cmpnodes\forest@nodesort@let#2{1}{#1}%
+ \def\forest@nodewalksort@sorted{}%
+ \safeloop
+ \unless\ifnum\safeloopn>#1\relax
+ \edef\forest@cn{\csname forest@nodesort@\safeloopn\endcsname}%
+ \forest@nodewalk@makestep
+ \saferepeat
+}
+% \end{macrocode}
+%
+% Find minimal/maximal node in a walk.
+% \begin{macrocode}
+\forestset{
+ define long step={min}{n args=1,@bare,make for}{% the first min in the argument nodewalk
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ }}{}%
+ \forest@nodewalk@minmax{\forest@global@temp}{-1}{<}{\forest@nodewalk@minmax@node,}%
+ },
+ define long step={mins}{n args=1,@bare,make for}{% all mins in the argument nodewalk
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ }}{}%
+ \forest@nodewalk@minmax{\forest@global@temp}{-1}{<}{\forest@nodewalk@minmax@nodes}%
+ },
+ define long step={walk and min}{n args=1,@bare}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{<}{\noexpand\forest@nodewalk@minmax@node,}%%
+ }\forest@marshal
+ },
+ define long step={walk and mins}{n args=1,@bare}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{<}{\noexpand\forest@nodewalk@minmax@nodes}%%
+ }\forest@marshal
+ },
+ define long step={min in nodewalk}{@bare}{% find the first min in the preceding nodewalk, step to it
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{<}{\forest@nodewalk@minmax@node,}%
+ },
+ define long step={mins in nodewalk}{@bare}{% find mins in the preceding nodewalk, step to mins
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{<}{\forest@nodewalk@minmax@nodes}%
+ },
+ define long step={min in nodewalk'}{@bare}{% find the first min in the preceding nodewalk, step to min in history
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{<}{}%
+ },
+ %
+ define long step={max}{n args=1,@bare,make for}{% the first max in the argument nodewalk
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ }}{}%
+ \forest@nodewalk@minmax{\forest@global@temp}{-1}{>}{\forest@nodewalk@minmax@node,}%
+ },
+ define long step={maxs}{n args=1,@bare,make for}{% all maxs in the argument nodewalk
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ }}{}%
+ \forest@nodewalk@minmax{\forest@global@temp}{-1}{>}{\forest@nodewalk@minmax@nodes}%
+ },
+ define long step={walk and max}{n args=1,@bare}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{>}{\noexpand\forest@nodewalk@minmax@node,}%%
+ }\forest@marshal
+ },
+ define long step={walk and maxs}{n args=1,@bare}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{>}{\noexpand\forest@nodewalk@minmax@nodes}%%
+ }\forest@marshal
+ },
+ define long step={max in nodewalk}{@bare}{% find the first max in the preceding nodewalk, step to it
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{>}{\forest@nodewalk@minmax@node,}%
+ },
+ define long step={maxs in nodewalk}{@bare}{% find maxs in the preceding nodewalk, step to maxs
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{>}{\forest@nodewalk@minmax@nodes}%
+ },
+ define long step={max in nodewalk'}{@bare}{% find the first max in the preceding nodewalk, step to max in history
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{>}{}%
+ },
+}
+
+\def\forest@nodewalk@minmax#1#2#3#4{%
+ % #1 = list of nodes
+ % #2 = max index in list (start with 1)
+ % #3 = min/max = ascending/descending = </>
+ % #4 = how many results? 1 = {\forest@nodewalk@minmax@node,}, all={\forest@nodewalk@minmax@nodes}, walk in history={}
+ \edef\forest@nodesort@sortkey{\forest@nodesort@by}%
+ \edef\forest@nodewalk@minmax@N{\number\numexpr#2}%
+ \edef\forest@nodewalk@minmax@n{}%
+ \edef\forest@nodewalk@minmax@list{#1}%
+ \def\forest@nodewalk@minmax@nodes{}%
+ \def\forest@nodewalk@minmax@node{}%
+ \ifdefempty{\forest@nodewalk@minmax@list}{%
+ }{%
+ \safeloop
+ \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalk@minmax@list}\forest@nodewalk@minmax@cn\forest@nodewalk@minmax@list
+ \ifnum\forest@nodewalk@minmax@cn=0 \else
+ \ifdefempty{\forest@nodewalk@minmax@node}{%
+ \edef\forest@nodewalk@minmax@node{\forest@nodewalk@minmax@cn}%
+ \edef\forest@nodewalk@minmax@nodes{\forest@nodewalk@minmax@cn,}%
+ \edef\forest@nodewalk@minmax@n{\safeloopn}%
+ }{%
+ \csedef{forest@nodesort@1}{\forest@nodewalk@minmax@node}%
+ \csedef{forest@nodesort@2}{\forest@nodewalk@minmax@cn}%
+ \forest@nodesort@cmpnodes{2}{1}%
+ \if=\forest@sort@cmp@result
+ \edef\forest@nodewalk@minmax@node{\forest@nodewalk@minmax@cn}%
+ \epreto\forest@nodewalk@minmax@nodes{\forest@nodewalk@minmax@cn,}%
+ \edef\forest@nodewalk@minmax@n{\safeloopn}%
+ \else
+ \if#3\forest@sort@cmp@result
+ \edef\forest@nodewalk@minmax@node{\forest@nodewalk@minmax@cn}%
+ \edef\forest@nodewalk@minmax@nodes{\forest@nodewalk@minmax@cn,}%
+ \edef\forest@nodewalk@minmax@n{\safeloopn}%
+ \fi
+ \fi
+ }%
+ \fi
+ \ifdefempty{\forest@nodewalk@minmax@list}{\forest@tempfalse}{\forest@temptrue}%
+ \ifnum\safeloopn=\forest@nodewalk@minmax@N\relax\forest@temptrue\fi
+ \ifforest@temp
+ \saferepeat
+ \edef\forest@nodewalk@minmax@list{#4}%
+ \ifdefempty\forest@nodewalk@minmax@list{%
+ \forestset{nodewalk/jump back=\forest@nodewalk@minmax@n-1}% CHECK
+ }{%
+ \safeloop
+ \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalk@minmax@list}\forest@cn\forest@nodewalk@minmax@list
+ \forest@nodewalk@makestep
+ \ifdefempty{\forest@nodewalk@minmax@list}{\forest@tempfalse}{\forest@temptrue}%
+ \ifforest@temp
+ \saferepeat
+ }%
+ }%
+}
+% \end{macrocode}
+%
+% 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.
+% \begin{macrocode}
+\newtoks\forest@nodewalk@shortsteps@resolution
+\newif\ifforest@nodewalk@areshortsteps
+\pgfqkeys{/forest/nodewalk}{
+ .unknown/.code={%
+ \forest@nodewalk@areshortstepsfalse
+ \pgfkeysifdefined{/forest/\pgfkeyscurrentname/@.cmd}{%
+ }{%
+ \ifx\pgfkeyscurrentvalue\pgfkeysnovalue@text % no value, so possibly short steps
+ \forest@nodewalk@shortsteps@resolution{}%
+ \forest@nodewalk@areshortstepstrue
+ \expandafter\forest@nodewalk@shortsteps\pgfkeyscurrentname==========,% "=" and "," cannot be short steps, so they are good as delimiters
+ \fi
+ }%
+ \ifforest@nodewalk@areshortsteps
+ \@escapeif{\expandafter\pgfkeysalso\expandafter{\the\forest@nodewalk@shortsteps@resolution}}%
+ \else
+ \@escapeif{\pgfkeysalso{/forest/\pgfkeyscurrentname={#1}}}%
+ \fi
+ },
+}
+\def\forest@nodewalk@shortsteps{%
+ \futurelet\forest@nodewalk@nexttoken\forest@nodewalk@shortsteps@
+}
+\def\forest@nodewalk@shortsteps@{%
+ \ifx\forest@nodewalk@nexttoken=%
+ \let\forest@nodewalk@nextop\forest@nodewalk@shortsteps@end
+ \else
+ \ifx\forest@nodewalk@nexttoken\bgroup
+ \letcs\forest@nodewalk@nextop{forest@shortstep@group}%
+ \else
+ \let\forest@nodewalk@nextop\forest@nodewalk@shortsteps@@
+ \fi
+ \fi
+ \forest@nodewalk@nextop
+}
+\def\forest@nodewalk@shortsteps@@#1{%
+ \ifcsdef{forest@shortstep@#1}{%
+ \csname forest@shortstep@#1\endcsname
+ }{%
+ \forest@nodewalk@areshortstepsfalse
+ \forest@nodewalk@shortsteps@end
+ }%
+}
+% in the following definitions:
+% #1 = short step
+% #2 = (long) step, or a style in /forest/nodewalk (taking n args)
+\csdef{forest@nodewalk@defshortstep@0@args}#1#2{%
+ \csdef{forest@shortstep@#1}{%
+ \apptotoks\forest@nodewalk@shortsteps@resolution{,#2}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@1@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1{%
+ \edef\forest@marshal####1{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@2@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2{%
+ \edef\forest@marshal####1####2{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@3@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3{%
+ \edef\forest@marshal####1####2####3{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@4@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4{%
+ \edef\forest@marshal####1####2####3####4{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@5@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4##5{%
+ \edef\forest@marshal####1####2####3####4####5{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@6@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4##5##6{%
+ \edef\forest@marshal####1####2####3####4####5####6{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@7@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4##5##6##7{%
+ \edef\forest@marshal####1####2####3####4####5####6####7{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}{##7}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@8@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4##5##6##7##8{%
+ \edef\forest@marshal####1####2####3####4####5####6####7####8{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@9@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4##5##6##7##8##9{%
+ \edef\forest@marshal####1####2####3####4####5####6####7####8####9{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}{##9}}%
+ \forest@nodewalk@shortsteps}}
+\forestset{
+ define short step/.code n args=3{% #1 = short step, #2 = n args, #3 = long step
+ \csname forest@nodewalk@defshortstep@#2@args\endcsname{#1}{#3}%
+ },
+}
+\def\forest@nodewalk@shortsteps@end#1,{}
+% \end{macrocode}
+%
+% Define short-form steps.
+% \begin{macrocode}
+\forestset{
+ define short step={group}{1}{group={#1}}, % {braces} are special
+ define short step={p}{0}{previous},
+ define short step={n}{0}{next},
+ define short step={u}{0}{parent},
+ define short step={s}{0}{sibling},
+ define short step={c}{0}{current},
+ define short step={o}{0}{origin},
+ define short step={r}{0}{root},
+ define short step={R}{0}{root'},
+ define short step={P}{0}{previous leaf},
+ define short step={N}{0}{next leaf},
+ define short step={F}{0}{first leaf},
+ define short step={L}{0}{last leaf},
+ define short step={>}{0}{next on tier},
+ define short step={<}{0}{previous on tier},
+ define short step={1}{0}{n=1},
+ define short step={2}{0}{n=2},
+ define short step={3}{0}{n=3},
+ define short step={4}{0}{n=4},
+ define short step={5}{0}{n=5},
+ define short step={6}{0}{n=6},
+ define short step={7}{0}{n=7},
+ define short step={8}{0}{n=8},
+ define short step={9}{0}{n=9},
+ define short step={l}{0}{last},
+ define short step={b}{0}{back},
+ define short step={f}{0}{forward},
+ define short step={v}{0}{last valid},
+ define short step={*}{2}{repeat={#1}{#2}},
+ for 1/.style={for nodewalk={n=1}{#1}},
+ for 2/.style={for nodewalk={n=2}{#1}},
+ for 3/.style={for nodewalk={n=3}{#1}},
+ for 4/.style={for nodewalk={n=4}{#1}},
+ for 5/.style={for nodewalk={n=5}{#1}},
+ for 6/.style={for nodewalk={n=6}{#1}},
+ for 7/.style={for nodewalk={n=7}{#1}},
+ for 8/.style={for nodewalk={n=8}{#1}},
+ for 9/.style={for nodewalk={n=9}{#1}},
+ for -1/.style={for nodewalk={n'=1}{#1}},
+ for -2/.style={for nodewalk={n'=2}{#1}},
+ for -3/.style={for nodewalk={n'=3}{#1}},
+ for -4/.style={for nodewalk={n'=4}{#1}},
+ for -5/.style={for nodewalk={n'=5}{#1}},
+ for -6/.style={for nodewalk={n'=6}{#1}},
+ for -7/.style={for nodewalk={n'=7}{#1}},
+ for -8/.style={for nodewalk={n'=8}{#1}},
+ for -9/.style={for nodewalk={n'=9}{#1}},
+}
+% \end{macrocode}
+%
+% Define multiple-step walks.
+% \begin{macrocode}
+\forestset{
+ define long step={tree}{}{\forest@node@foreach{\forest@nodewalk@makestep}},
+ define long step={tree reversed}{}{\forest@node@foreach@reversed{\forest@nodewalk@makestep}},
+ define long step={tree children-first}{}{\forest@node@foreach@childrenfirst{\forest@nodewalk@makestep}},
+ define long step={tree children-first reversed}{}{\forest@node@foreach@childrenfirst@reversed{\forest@nodewalk@makestep}},
+ define long step={tree breadth-first}{}{\forest@node@foreach@breadthfirst{-1}{\forest@nodewalk@makestep}},
+ define long step={tree breadth-first reversed}{}{\forest@node@foreach@breadthfirst@reversed{-1}{\forest@nodewalk@makestep}},
+ define long step={descendants}{}{\forest@node@foreachdescendant{\forest@nodewalk@makestep}},
+ define long step={descendants reversed}{}{\forest@node@foreachdescendant@reversed{\forest@nodewalk@makestep}},
+ define long step={descendants children-first}{}{\forest@node@foreachdescendant@childrenfirst{\forest@nodewalk@makestep}},
+ define long step={descendants children-first reversed}{}{\forest@node@foreachdescendant@childrenfirst@reversed{\forest@nodewalk@makestep}},
+ define long step={descendants breadth-first}{}{\forest@node@foreach@breadthfirst{0}{\forest@nodewalk@makestep}},
+ define long step={descendants breadth-first reversed}{}{\forest@node@foreach@breadthfirst@reversed{0}{\forest@nodewalk@makestep}},
+ define long step={level}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{#1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {\forest@temp}%
+ {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={level>}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{#1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {-1}%
+ {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={level<}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)-1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {\forest@temp}%
+ {\noexpand\forest@nodewalk@makestep}%
+ }\forest@marshal
+ },
+ define long step={level reversed}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{#1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {\forest@temp}%
+ {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={level reversed>}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{#1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {-1}%
+ {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={level reversed<}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)-1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {\forest@temp}%
+ {\noexpand\forest@nodewalk@makestep}%
+ }\forest@marshal
+ },
+ %
+ define long step={relative level}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {\forest@temp}%
+ {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={relative level>}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {-1}%
+ {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={relative level<}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}-1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {\forest@temp}%
+ {\noexpand\forest@nodewalk@makestep}%
+ }\forest@marshal
+ },
+ define long step={relative level reversed}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {\forest@temp}%
+ {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={relative level reversed>}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {-1}%
+ {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={relative level reversed<}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}-1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {\forest@temp}%
+ {\noexpand\forest@nodewalk@makestep}%
+ }\forest@marshal
+ },
+ define long step={children}{}{\forest@node@foreachchild{\forest@nodewalk@makestep}},
+ define long step={children reversed}{}{\forest@node@foreachchild@reversed{\forest@nodewalk@makestep}},
+ define long step={current and following siblings}{}{\forest@node@@forselfandfollowingsiblings{\forest@nodewalk@makestep}},
+ define long step={following siblings}{style}{if nodewalk valid={next}{fake=next,current and following siblings}{}},
+ define long step={current and preceding siblings}{}{\forest@node@@forselfandprecedingsiblings{\forest@nodewalk@makestep}},
+ define long step={preceding siblings}{style}{if nodewalk valid={previous}{fake=previous,current and preceding siblings}{}},
+ define long step={current and following siblings reversed}{}{\forest@node@@forselfandfollowingsiblings@reversed{\forest@nodewalk@makestep}},
+ define long step={following siblings reversed}{style}{fake=next,current and following siblings reversed},
+ define long step={current and preceding siblings reversed}{}{\forest@node@@forselfandprecedingsiblings@reversed{\forest@nodewalk@makestep}},
+ define long step={preceding siblings reversed}{style}{fake=previous,current and preceding siblings reversed},
+ define long step={siblings}{style}{for nodewalk'={preceding siblings},following siblings},
+ define long step={siblings reversed}{style}{for nodewalk'={following siblings reversed},preceding siblings reversed},
+ define long step={ancestors}{style}{while={}{parent},last valid},
+ define long step={current and ancestors}{style}{current,ancestors},
+ define long step={following nodes}{style}{while={}{next node},last valid},
+ define long step={preceding nodes}{style}{while={}{previous node},last valid},
+ define long step={current and following nodes}{style}{current,following nodes},
+ define long step={current and preceding nodes}{style}{current,preceding nodes},
+}
+\let\forest@nodewalkstephandler@styletrueorfalse\forest@nodewalkstephandler@styletrue
+% \end{macrocode}
+%
%
% \subsection{Dynamic tree}
% \label{sec:impl:dynamic}
@@ -6555,6 +4616,9 @@
\else
\forest@forthis{%
\forest@nameandgo{#1#2}%
+ \ifnum\forest@cn=0
+ \PackageError{forest}{Cannot use a dynamic key on the invalid node}{}%
+ \fi
\let\forest@last@node\forest@cn
}%
\fi
@@ -6564,16 +4628,47 @@
\forest@last@node=#1\forest@end@create@node
}
\def\forest@create@collectafterthought#1\forest@end@create@node{%
- \forestOletO{\forest@last@node}{delay}{\forest@last@node}{given options}%
- \forestOset{\forest@last@node}{given options}{}%
- \forestOeappto{\forest@last@node}{delay}{,\unexpanded{#1}}%
-}
-\def\forest@create@collectafterthought#1\forest@end@create@node{%
\forest@node@Foreach{\forest@last@node}{%
\forestoleto{delay}{given options}%
\forestoset{given options}{}%
}%
\forestOeappto{\forest@last@node}{delay}{,\unexpanded{#1}}%
+ \forestOset{\forest@last@node}{given options}{delay={}}%
+}
+\def\forest@create@node@and@process@given@options#1{% #1=bracket representation
+ \bracketParse{\forest@createandprocess@collectafterthought}%
+ \forest@last@node=#1\forest@end@create@node
+}
+\def\forest@createandprocess@collectafterthought#1\forest@end@create@node{%
+ \forest@node@Compute@numeric@ts@info{\forest@last@node}%
+ \forest@saveandrestoremacro\forest@root{%
+ \let\forest@root\forest@last@node
+ \forestset{process keylist=given options}%
+ }%
+}
+\def\forest@saveandrestoremacro#1#2{% #1 = the (zero-arg) macro to save before and restore after processing code in #2
+ \edef\forest@marshal{%
+ \unexpanded{#2}%
+ \noexpand\def\noexpand#1{\expandonce{#1}}%
+ }\forest@marshal
+}
+\def\forest@saveandrestoreifcs#1#2{% #1 = the if cs to save before and restore after processing code in #2
+ \edef\forest@marshal{%
+ \unexpanded{#2}%
+ \ifbool{#1}{\noexpand\setbool{#1}{true}}{\noexpand\setbool{#1}{false}}
+ }\forest@marshal
+}
+\def\forest@saveandrestoretoks#1#2{% #1 = the toks to save before and restore after processing code in #2
+ \edef\forest@marshal{%
+ \unexpanded{#2}%
+ \noexpand#1{\the#1}%
+ }\forest@marshal
+}
+\def\forest@saveandrestoreregister#1#2{% #1 = the register to save before and restore after processing code in #2
+ \edef\forest@marshal{%
+ \unexpanded{#2}%
+ \noexpand\forestrset{#1}{\forestregister{#1}}%
+ }\forest@marshal
}
\def\forest@remove@node#1{%
\forest@node@Remove{#1}%
@@ -6594,6 +4689,9 @@
\forest@node@Remove{#2}%
\forest@node@Insertbefore{\forestOve{#1}{@parent}}{#2}{#1}%
}
+\def\forest@set@root#1#2{%
+ \def\forest@root{#2}%
+}
\def\forest@appto@do@dynamics#1#2{%
\forest@nodehandleby@name@nodewalk@or@bracket{#2}%
\ifcase\forest@dynamics@copyhow\relax\or
@@ -6605,14 +4703,20 @@
\forestOepreto{\forest@last@node}{delay}
{for id={\forest@node@Nametoid{forest@last@node}}{alias=forest@last@node},}%
}{}%
- \forest@havedelayedoptionstrue
\edef\forest@marshal{%
\noexpand\apptotoks\noexpand\forest@do@dynamics{%
\noexpand#1{\forest@cn}{\forest@last@node}}%
}\forest@marshal
}
\forestset{%
- create/.code={\forest@create@node{#1}},
+ create/.code={%
+ \forest@create@node{#1}%
+ \forest@fornode{\forest@last@node}{\forest@node@setalias{forest@last@node}}%
+ },
+ create'/.code={%
+ \forest@create@node@and@process@given@options{#1}%
+ \forest@fornode{\forest@last@node}{\forest@node@setalias{forest@last@node}}%
+ },
append/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@append@node{#1}},
prepend/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@prepend@node{#1}},
insert after/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@insertafter@node{#1}},
@@ -6631,16 +4735,29 @@
\expandafter\forest@remove@node\expandafter{\forest@cn}}%
},
set root/.code={%
- \forest@nodehandleby@name@nodewalk@or@bracket{#1}%
- \edef\forest@marshal{%
- \noexpand\apptotoks\noexpand\forest@do@dynamics{%
- \def\noexpand\forest@root{\forest@last@node}%
- }%
- }\forest@marshal
+ \def\forest@dynamics@copyhow{0}%
+ \forest@appto@do@dynamics\forest@set@root{#1}%
},
replace by/.code={\forest@replaceby@code{#1}{insert after}},
replace by'/.code={\forest@replaceby@code{#1}{insert after'}},
replace by''/.code={\forest@replaceby@code{#1}{insert after''}},
+ sort/.code={%
+ \eapptotoks\forest@do@dynamics{%
+ \noexpand\forest@nodesort
+ \noexpand\forest@sort@ascending
+ {\forest@cn}%
+ {\expandonce{\forest@nodesort@by}}%
+ }%
+ },
+ sort'/.code={%
+ \eapptotoks\forest@do@dynamics{%
+ \noexpand\forest@nodesort
+ \noexpand\forest@sort@descending
+ {\forest@cn}%
+ {\expandonce{\forest@nodesort@by}}%
+ }%
+ },
+ sort by/.store in=\forest@nodesort@by,
}
\def\forest@replaceby@code#1#2{%#1=node spec,#2=insert after['][']
\ifnum\forestove{@parent}=0
@@ -6654,13 +4771,75 @@
}%
\fi
}
+\def\forest@nodesort#1#2#3{% #1 = direction, #2 = parent node, #3 = sort key
+ \def\forest@nodesort@sortkey{#3}%
+ \forest@fornode{#2}{\forest@nodesort@#1}%
+}
+\def\forest@nodesort@#1{%
+ % prepare the array of child ids
+ \c@pgf@counta=0
+ \forestoget{@first}\forest@nodesort@id
+ \forest@loop
+ \ifnum\forest@nodesort@id>0
+ \advance\c@pgf@counta 1
+ \csedef{forest@nodesort@\the\c@pgf@counta}{\forest@nodesort@id}%
+ \forestOget{\forest@nodesort@id}{@next}\forest@nodesort@id
+ \forest@repeat
+ % sort
+ \forestoget{n children}\forest@nodesort@n
+ \forest@sort\forest@nodesort@cmpnodes\forest@nodesort@let#1{1}{\forest@nodesort@n}%
+ % remove all children
+ \forestoget{@first}\forest@nodesort@id
+ \forest@loop
+ \ifnum\forest@nodesort@id>0
+ \forest@node@Remove{\forest@nodesort@id}%
+ \forestoget{@first}\forest@nodesort@id
+ \forest@repeat
+ % insert the children in new order
+ \c@pgf@counta=0
+ \forest@loop
+ \ifnum\c@pgf@counta<\forest@nodesort@n\relax
+ \advance\c@pgf@counta 1
+ \edef\temp{\csname forest@nodesort@\the\c@pgf@counta\endcsname}%
+ \forest@node@append{\csname forest@nodesort@\the\c@pgf@counta\endcsname}%
+ \forest@repeat
+}
+\def\forest@nodesort@cmpnodes#1#2{%
+ \global\let\forest@nodesort@cmpresult\forest@sort@cmp@eq
+ \foreach \forest@temp@pgfmath in \forest@nodesort@sortkey {%
+ \forest@fornode{\csname forest@nodesort@#1\endcsname}{%
+ \pgfmathparse{\forest@temp@pgfmath}\global\let\forest@global@tempa\pgfmathresult}%
+ \forest@fornode{\csname forest@nodesort@#2\endcsname}{%
+ \pgfmathparse{\forest@temp@pgfmath}\global\let\forest@global@tempb\pgfmathresult}%
+ \ifdim\forest@global@tempa pt<\forest@global@tempb pt
+ \global\let\forest@nodesort@cmpresult\forest@sort@cmp@lt
+ \breakforeach
+ \else
+ \ifdim\forest@global@tempa pt>\forest@global@tempb pt
+ \global\let\forest@nodesort@cmpresult\forest@sort@cmp@gt
+ \breakforeach
+ \fi
+ \fi
+ }%
+ \forest@nodesort@cmpresult
+}
+\def\forest@nodesort@let#1#2{%
+ \csletcs{forest@nodesort@#1}{forest@nodesort@#2}%
+}
% \end{macrocode}
%
% \section{Stages}
%
% \begin{macrocode}
+\def\forest@root{0}
+ %%% begin listing region: stages
\forestset{
stages/.style={
+ for root'={
+ process keylist register=default preamble,
+ process keylist register=preamble
+ },
+ process keylist=given options,
process keylist=before typesetting nodes,
typeset nodes stage,
process keylist=before packing,
@@ -6668,33 +4847,68 @@
process keylist=before computing xy,
compute xy stage,
process keylist=before drawing tree,
- draw tree stage,
+ draw tree stage
},
typeset nodes stage/.style={for root'=typeset nodes},
pack stage/.style={for root'=pack},
compute xy stage/.style={for root'=compute xy},
draw tree stage/.style={for root'=draw tree},
- process keylist/.code={\forest@process@hook@keylist{#1}},
+}
+ %%% end listing region: stages
+\forestset{
+ process keylist/.code={%
+ \forest@process@hook@keylist{#1}{#1 processing order/.try,processing order/.lastretry}},
+ process keylist'/.code 2 args={\forest@process@hook@keylist@nodynamics{#1}{#2}},
+ process keylist''/.code 2 args={\forest@process@hook@keylist@{#1}{#2}},
+ process keylist register/.code={\forest@process@keylist@register{#1}},
+ process delayed/.code={%
+ \forest@havedelayedoptions{@delay}{#1}%
+ \ifforest@havedelayedoptions
+ \forest@process@hook@keylist@nodynamics{@delay}{#1}%
+ \fi
+ },
+ do dynamics/.code={%
+ \the\forest@do@dynamics
+ \forest@do@dynamics{}%
+ \forest@node@Compute@numeric@ts@info{\forest@root}%
+ },
declare keylist={given options}{},
declare keylist={before typesetting nodes}{},
declare keylist={before packing}{},
+ declare keylist={before packing node}{},
+ declare keylist={after packing node}{},
declare keylist={before computing xy}{},
declare keylist={before drawing tree}{},
declare keylist={delay}{},
- delay/.append code={\forest@havedelayedoptionstrue},
delay n/.style 2 args={if={#1==0}{#2}{delay@n={#1}{#2}}},
delay@n/.style 2 args={
if={#1==1}{delay={#2}}{delay={delay@n/.wrap pgfmath arg={{##1}{#2}}{#1-1}}}
},
- if have delayed/.code 2 args={%
- \ifforest@havedelayedoptions\pgfkeysalso{#1}\else\pgfkeysalso{#2}\fi
+ if have delayed/.style 2 args={if have delayed'={processing order}{#1}{#2}},
+ if have delayed'/.code n args=3{%
+ \forest@havedelayedoptionsfalse
+ \forest@forthis{%
+ \forest@nodewalk{#1}{%
+ TeX={%
+ \forestoget{delay}\forest@temp@delayed
+ \ifdefempty\forest@temp@delayed{}{\forest@havedelayedoptionstrue}%
+ }%
+ }%
+ }%
+ \ifforest@havedelayedoptions\pgfkeysalso{#2}\else\pgfkeysalso{#3}\fi
},
typeset nodes/.code={%
\forest@drawtree@preservenodeboxes@false
- \forest@node@foreach{\forest@node@typeset}},
+ \forest@nodewalk
+ {typeset nodes processing order/.try,processing order/.lastretry}%
+ {TeX={\forest@node@typeset}}%
+ },
typeset nodes'/.code={%
\forest@drawtree@preservenodeboxes@true
- \forest@node@foreach{\forest@node@typeset}},
+ \forest@nodewalk
+ {typeset nodes processing order/.try,processing order/.lastretry}%
+ {TeX={\forest@node@typeset}}%
+ },
typeset node/.code={%
\forest@drawtree@preservenodeboxes@false
\forest@node@typeset
@@ -6712,51 +4926,109 @@
\forest@drawtree@preservenodeboxes@true
\forest@node@drawtree
},
+ %%% begin listing region: draw_tree_method
+ draw tree method/.style={
+ for nodewalk={
+ draw tree nodes processing order/.try,
+ draw tree processing order/.retry,
+ processing order/.lastretry
+ }{draw tree node},
+ for nodewalk={
+ draw tree edges processing order/.try,
+ draw tree processing order/.retry,
+ processing order/.lastretry
+ }{draw tree edge},
+ for nodewalk={
+ draw tree tikz processing order/.try,
+ draw tree processing order/.retry,
+ processing order/.lastretry
+ }{draw tree tikz}
+ },
+ %%% end listing region: draw_tree_method
+ draw tree node/.code={\forest@draw@node},
+ draw tree edge/.code={\forest@draw@edge},
+ draw tree tikz/.code={\forest@draw@tikz},
+ for nodewalk={processing order/.style={tree}}{},
+ %given options processing order/.style={processing order},
+ %before typesetting nodes processing order/.style={processing order},
+ %before packing processing order/.style={processing order},
+ %before computing xy processing order/.style={processing order},
+ %before drawing tree processing order/.style={processing order},
}
\newtoks\forest@do@dynamics
\newif\ifforest@havedelayedoptions
-\def\forest@process@hook@keylist#1{%
- \forest@loopa
- \forest@havedelayedoptionsfalse
- \forest@do@dynamics={}%
- \forest@fornode{\forest@root}{\forest@process@hook@keylist@{#1}}%
+\def\forest@process@hook@keylist#1#2{%,#1=keylist,#2=processing order nodewalk
+ \safeloop
+ \forest@fornode{\forest@root}{\forest@process@hook@keylist@{#1}{#2}}%
\expandafter\ifstrempty\expandafter{\the\forest@do@dynamics}{}{%
\the\forest@do@dynamics
+ \forest@do@dynamics={}%
\forest@node@Compute@numeric@ts@info{\forest@root}%
- \forest@havedelayedoptionstrue
}%
+ \forest@fornode{\forest@root}{\forest@havedelayedoptions{#1}{#2}}%
+ \ifforest@havedelayedoptions
+ \saferepeat
+}
+\def\forest@process@hook@keylist@nodynamics#1#2{%#1=keylist,#2=processing order nodewalk
+ % note: this macro works on (nodewalk starting at) the current node
+ \safeloop
+ \forest@forthis{\forest@process@hook@keylist@{#1}{#2}}%
+ \forest@havedelayedoptions{#1}{#2}%
\ifforest@havedelayedoptions
- \forest@node@Foreach{\forest@root}{%
- \forestoget{delay}\forest@temp@delayed
- \forestolet{#1}\forest@temp@delayed
- \forestoset{delay}{}%
+ \saferepeat
+}
+\def\forest@process@hook@keylist@#1#2{%#1=keylist,#2=processing order nodewalk
+ \forest@nodewalk{#2}{%
+ TeX={%
+ \forestoget{#1}\forest@temp@keys
+ \ifdefvoid\forest@temp@keys{}{%
+ \forestoset{#1}{}%
+ \expandafter\forestset\expandafter{\forest@temp@keys}%
+ }%
}%
- \forest@repeata
+ }%
}
-\def\forest@process@hook@keylist@#1{%
- \forest@node@foreach{%
- \forestoget{#1}\forest@temp@keys
- \ifdefvoid\forest@temp@keys{}{%
- \forestoset{#1}{}%
- \expandafter\forestset\expandafter{\forest@temp@keys}%
+\def\forest@process@keylist@register#1{%
+ \edef\forest@marshal{%
+ \noexpand\forestset{\forestregister{#1}}%
+ }\forest@marshal
+}
+% \end{macrocode}
+% Clear the keylist, transfer delayed into it, and set |\ifforest@havedelayedoptions|.
+% \begin{macrocode}
+\def\forest@havedelayedoptions#1#2{%#1 = keylist, #2=nodewalk
+ \forest@havedelayedoptionsfalse
+ \forest@forthis{%
+ \forest@nodewalk{#2}{%
+ TeX={%
+ \forestoget{delay}\forest@temp@delayed
+ \ifdefempty\forest@temp@delayed{}{\forest@havedelayedoptionstrue}%
+ \forestolet{#1}\forest@temp@delayed
+ \forestoset{delay}{}%
+ }%
}%
}%
}
% \end{macrocode}
%
-%
% \subsection{Typesetting nodes}
%
% \begin{macrocode}
\def\forest@node@typeset{%
\let\forest@next\forest@node@typeset@
- \forestoifdefined{box}{%
- \ifforest@drawtree@preservenodeboxes@
- \let\forest@next\relax
- \fi
+ \forestoifdefined{@box}{%
+ \forestoget{@box}\forest@temp
+ \ifdefempty\forest@temp{%
+ \locbox\forest@temp@box
+ \forestolet{@box}\forest@temp@box
+ }{%
+ \ifforest@drawtree@preservenodeboxes@
+ \let\forest@next\relax
+ \fi
+ }%
}{%
\locbox\forest@temp@box
- \forestolet{box}\forest@temp@box
+ \forestolet{@box}\forest@temp@box
}%
\def\forest@node@typeset@restore{}%
\ifdefined\ifsa@tikz\forest@standalone@hack\fi
@@ -6776,52 +5048,39 @@
\fi
}
\newbox\forest@box
+\def\forest@pgf@notyetpositioned{not yet positionedPGFINTERNAL}
\def\forest@node@typeset@{%
+ \forestanchortotikzanchor{anchor}\forest@temp
+ \edef\forest@marshal{%
+ \noexpand\forestolet{anchor}\noexpand\forest@temp
+ \noexpand\forest@node@typeset@@
+ \noexpand\forestoset{anchor}{\forestov{anchor}}%
+ }\forest@marshal
+}
+\def\forest@node@typeset@@{%
\forestoget{name}\forest@nodename
\edef\forest@temp@nodeformat{\forestove{node format}}%
\gdef\forest@smuggle{}%
\setbox0=\hbox{%
- \begin{tikzpicture}%
+ \begin{tikzpicture}[%
+ /forest/copy command key={/tikz/anchor}{/tikz/forest@orig@anchor},
+ anchor/.style={%
+ /forest/TeX={\forestanchortotikzanchor{##1}\forest@temp@anchor},
+ forest@orig@anchor/.expand once=\forest@temp@anchor
+ }]
\pgfpositionnodelater{\forest@positionnodelater@save}%
\forest@temp@nodeformat
\pgfinterruptpath
\pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{forestcomputenodeboundary}%
\endpgfinterruptpath
- %\forest@compute@node@boundary\forest@temp
- %\xappto\forest@smuggle{\noexpand\forestoset{boundary}{\expandonce\forest@temp}}%
- \if\relax\forestove{parent anchor}\relax
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{center}%
- \else
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{\forestove{parent anchor}}%
- \fi
- \xappto\forest@smuggle{%
- \noexpand\forestoset{parent@anchor}{%
- \noexpand\noexpand\noexpand\pgf@x=\the\pgf@x\relax
- \noexpand\noexpand\noexpand\pgf@y=\the\pgf@y\relax}}%
- \if\relax\forestove{child anchor}\relax
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{center}%
- \else
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{\forestove{child anchor}}%
- \fi
- \xappto\forest@smuggle{%
- \noexpand\forestoeset{child@anchor}{%
- \noexpand\noexpand\noexpand\pgf@x=\the\pgf@x\relax
- \noexpand\noexpand\noexpand\pgf@y=\the\pgf@y\relax}}%
- \if\relax\forestove{anchor}\relax
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{center}%
- \else
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{\forestove{anchor}}%
- \fi
- \xappto\forest@smuggle{%
- \noexpand\forestoeset{@anchor}{%
- \noexpand\noexpand\noexpand\pgf@x=\the\pgf@x\relax
- \noexpand\noexpand\noexpand\pgf@y=\the\pgf@y\relax}}%
\end{tikzpicture}%
}%
- \setbox\forestove{box}=\box\forest@box % smuggle the box
- \forestolet{boundary}\forest@global@boundary
+ \setbox\forestove{@box}=\box\forest@box % smuggle the box
+ \forestolet{@boundary}\forest@global@boundary
\forest@smuggle % ... and the rest
}
+
+
\forestset{
declare readonly dimen={min x},
declare readonly dimen={min y},
@@ -6854,13 +5113,17 @@
\else
\let\forest@boxorcopy\box
\fi
- \forestoget{box}\forest@temp
+ \forestoget{@box}\forest@temp
\setbox\pgfpositionnodelaterbox=\forest@boxorcopy\forest@temp
\edef\pgfpositionnodelatername{\forestove{later@name}}%
\edef\pgfpositionnodelaterminx{\forestove{min x}}%
\edef\pgfpositionnodelaterminy{\forestove{min y}}%
\edef\pgfpositionnodelatermaxx{\forestove{max x}}%
\edef\pgfpositionnodelatermaxy{\forestove{max y}}%
+ \ifforest@drawtree@preservenodeboxes@
+ \else
+ \forestoset{@box}{}%
+ \fi
}
% \end{macrocode}
%
@@ -6879,24 +5142,34 @@
}
\def\forest@@pack{%
\ifnum\forestove{n children}>0
- \ifnum\forestove{uniform growth}>0
+ \ifnum\forestove{uniform growth}>0
\forest@pack@level@uniform
\forest@pack@aligntiers@ofsubtree
\forest@pack@sibling@uniform@recursive
\else
\forest@node@foreachchild{\forest@@pack}%
+ \forest@process@hook@keylist@nodynamics{before packing node}{current}%
\forest@pack@level@nonuniform
\forest@pack@aligntiers
\forest@pack@sibling@uniform@applyreversed
\fi
\fi
-}
+ \forestoget{after packing node}\forest@temp@keys
+ \forest@process@hook@keylist@nodynamics{after packing node}{current}%
+}
+% \forestset{recalculate tree boundary/.code={\forest@node@recalculate@edges}}
+% \def\forest@node@recalculate@edges{%
+% \edef\forest@marshal{%
+% \noexpand\forest@forthis{\noexpand\forest@node@getedges{\forestove{grow}}}%
+% }\forest@marshal
+% }
\def\forest@pack@onlythisnode{%
\ifnum\forestove{n children}>0
\forest@pack@computetiers
- \forest@pack@level@nonuniform
- \forest@pack@aligntiers
- \forest@pack@sibling@uniform@applyreversed
+ \forest@pack@level@nonuniform
+ \forest@pack@aligntiers
+ \forest@node@foreachchild{\forestoset{s}{0pt}}%
+ \forest@pack@sibling@uniform@applyreversed
\fi
}
% \end{macrocode}
@@ -6922,7 +5195,13 @@
\fi
\fi
}%
- \forestolet{uniform growth}\forest@pack@cgu@uniformity
+ \forestoget{before packing node}\forest@temp@a
+ \forestoget{after packing node}\forest@temp@b
+ \expandafter\expandafter\expandafter\ifstrempty\expandafter\expandafter\expandafter{\expandafter\forest@temp@a\forest@temp@b}{%
+ \forestolet{uniform growth}\forest@pack@cgu@uniformity
+ }{%
+ \forestoset{uniform growth}{0}%
+ }%
}
% \end{macrocode}
%
@@ -7043,9 +5322,9 @@
\def\forest@pack@sibling@uniform@applyreversed{%
\ifnum\forestove{n children}>1
\ifnum\forestove{reversed}=0
- \pack@sibling@uniform@main{first}{last}{next}{previous}%
+ \forest@pack@sibling@uniform@main{first}{last}{next}{previous}%
\else
- \pack@sibling@uniform@main{last}{first}{previous}{next}%
+ \forest@pack@sibling@uniform@main{last}{first}{previous}{next}%
\fi
\else
\ifnum\forestove{n children}=1
@@ -7060,7 +5339,7 @@
% Pack children in the sibling dimension in a uniform tree: the main
% routine.
% \begin{macrocode}
-\def\pack@sibling@uniform@main#1#2#3#4{%
+\def\forest@pack@sibling@uniform@main#1#2#3#4{%
% \end{macrocode}
% Loop through the children. At each iteration, we compute the
% distance between the negative edge of the current child and the
@@ -7072,14 +5351,14 @@
% positive edge of the first child.
% \begin{macrocode}
\forestoget{@#1}\forest@child
- \edef\forest@temp{%
+ \edef\forest@marshal{%
\noexpand\forest@fornode{\forestove{@#1}}{%
\noexpand\forest@node@getedge
- {positive}
- {\forestove{grow}}
+ {positive}%
+ {\forestove{grow}}%
\noexpand\forest@temp@edge
}%
- }\forest@temp
+ }\forest@marshal
\forest@pack@pgfpoint@childsposition\forest@child
\let\forest@previous@positive@edge\pgfutil@empty
\forest@extendpath\forest@previous@positive@edge\forest@temp@edge{}%
@@ -7088,7 +5367,7 @@
% Loop until the current child is the null node.
% \begin{macrocode}
\edef\forest@previous@child@s{0pt}%
- \forest@loopb
+ \safeloop
\unless\ifnum\forest@child=0
% \end{macrocode}
% Get the negative edge of the child.
@@ -7096,8 +5375,8 @@
\edef\forest@temp{%
\noexpand\forest@fornode{\forest@child}{%
\noexpand\forest@node@getedge
- {negative}
- {\forestove{grow}}
+ {negative}%
+ {\forestove{grow}}%
\noexpand\forest@temp@edge
}%
}\forest@temp
@@ -7132,7 +5411,7 @@
\else
\advance\pgfutil@tempdimb-\forest@csdistance\relax
\advance\pgfutil@tempdimb\forestove{s sep}\relax
- \forestOeset{\forest@child}{s}{\the\dimexpr\forestove{s}-\forest@csdistance+\forestove{s sep}}%
+ \forestOeset{\forest@child}{s}{\the\dimexpr\forestOve{\forest@child}{s}-\forest@csdistance+\forestove{s sep}}%
\fi
% \end{macrocode}
% Retain monotonicity (is this ok?). (This problem arises when the adjacent children's |l| are too
@@ -7151,8 +5430,8 @@
\edef\forest@temp{%
\noexpand\forest@fornode{\forest@child}{%
\noexpand\forest@node@getedge
- {positive}
- {\forestove{grow}}
+ {positive}%
+ {\forestove{grow}}%
\noexpand\forest@temp@edge
}%
}\forest@temp
@@ -7160,7 +5439,7 @@
\forest@extendpath\forest@previous@positive@edge\forest@temp@edge{}%
\forest@getpositivetightedgeofpath\forest@previous@positive@edge\forest@previous@positive@edge
\forestOget{\forest@child}{@#3}\forest@child
- \forest@repeatb
+ \saferepeat
% \end{macrocode}
% Shift the position of all children to achieve the desired alignment
% of the parent and its children.
@@ -7211,9 +5490,9 @@
\pgftransformrotate{\forestove{grow}}%
\pgfpointtransformed{\pgfqpoint{\forestOve{\forest@temp@child}{l}}{\forestOve{\forest@temp@child}{s}}}%
\pgf@xa=\pgf@x\relax\pgf@ya=\pgf@y\relax
- \forestOve{\forest@temp@child}{child@anchor}%
+ \forest@Pointanchor{\forest@temp@child}{child anchor}%
\advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
- \forestove{parent@anchor}%
+ \forest@pointanchor{parent anchor}%
\advance\pgf@xa-\pgf@x\relax\advance\pgf@ya-\pgf@y\relax
\edef\forest@marshal{%
\noexpand\pgftransformreset
@@ -7238,13 +5517,13 @@
\pgftransformrotate{\forestove{grow}}%
\pgfpointtransformed{\pgfqpoint{\forestOve{\forest@temp@firstchild}{l}}{\forestOve{\forest@temp@firstchild}{s}}}%
\pgf@xa=\pgf@x\relax\pgf@ya=\pgf@y\relax
- \forestOve{\forest@temp@firstchild}{child@anchor}%
+ \forest@Pointanchor{\forest@temp@firstchild}{child anchor}%
\advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
\edef\forest@marshal{%
\noexpand\pgfpointtransformed{\noexpand\pgfqpoint{\forestOve{\forest@temp@secondchild}{l}}{\forestOve{\forest@temp@secondchild}{s}}}%
}\forest@marshal
\advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
- \forestOve{\forest@temp@secondchild}{child@anchor}%
+ \forest@Pointanchor{\forest@temp@secondchild}{child anchor}%
\advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
\divide\pgf@xa2 \divide\pgf@ya2
\edef\forest@marshal{%
@@ -7328,16 +5607,13 @@
\fi
\forestOget{\forest@ca@first@child}{l}\forest@ca@first@l
\forestOget{\forest@ca@second@child}{l}\forest@ca@second@l
- \forestoget{parent@anchor}\forest@ca@parent@anchor
- \forest@ca@parent@anchor
+ \forest@pointanchor{parent anchor}%
\edef\forest@ca@parent@anchor@s{\the\pgf@x}%
\edef\forest@ca@parent@anchor@l{\the\pgf@y}%
- \forestOget{\forest@ca@first@child}{child@anchor}\forest@ca@first@child@anchor
- \forest@ca@first@child@anchor
+ \forest@Pointanchor{\forest@ca@first@child}{child anchor}%
\edef\forest@ca@first@child@anchor@s{\the\pgf@x}%
\edef\forest@ca@first@child@anchor@l{\the\pgf@y}%
- \forestOget{\forest@ca@second@child}{child@anchor}\forest@ca@second@child@anchor
- \forest@ca@second@child@anchor
+ \forest@Pointanchor{\forest@ca@second@child}{child anchor}%
\edef\forest@ca@second@child@anchor@s{\the\pgf@x}%
\edef\forest@ca@second@child@anchor@l{\the\pgf@y}%
\pgfmathsetlengthmacro\forest@ca@desired@second@edge@s{tan(\forestove{calign secondary angle})*%
@@ -7354,8 +5630,7 @@
\ifdim\forest@ca@actual@s@distance=0pt
\forestoget{n children}\forest@temp@n@children
\forest@node@foreachchild{%
- \forestoget{child@anchor}\forest@temp@child@anchor
- \forest@temp@child@anchor
+ \forest@pointanchor{child anchor}%
\edef\forest@temp@child@anchor@s{\the\pgf@x}%
\pgfmathsetlengthmacro\forest@temp{%
\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}%
@@ -7366,8 +5641,7 @@
\pgfmathsetmacro\forest@ca@ratio{%
\forest@ca@desired@s@distance/\forest@ca@actual@s@distance}%
\forest@node@foreachchild{%
- \forestoget{child@anchor}\forest@temp@child@anchor
- \forest@temp@child@anchor
+ \forest@pointanchor{child anchor}%
\edef\forest@temp@child@anchor@s{\the\pgf@x}%
\pgfmathsetlengthmacro\forest@temp{%
\forest@ca@ratio*(%
@@ -7387,8 +5661,7 @@
\pgfmathsetlengthmacro\forest@ca@ratio{%
\forest@ca@actual@s@distance/\forest@ca@desired@s@distance}%
\forest@node@foreachchild{%
- \forestoget{child@anchor}\forest@temp@child@anchor
- \forest@temp@child@anchor
+ \forest@pointanchor{child anchor}%
\edef\forest@temp@child@anchor@l{\the\pgf@y}%
\pgfmathsetlengthmacro\forest@temp{%
\forest@ca@ratio*(%
@@ -7441,7 +5714,7 @@
% Get the edge of the node itself.
% \begin{macrocode}
\ifnum\forestove{ignore}=0
- \forestoget{boundary}\forest@node@boundary
+ \forestoget{@boundary}\forest@node@boundary
\else
\def\forest@node@boundary{}%
\fi
@@ -7466,7 +5739,7 @@
% \end{macrocode}
% Remember the node's |parent anchor| and add it to the path (for breaking).
% \begin{macrocode}
- \forestove{parent@anchor}%
+ \forest@pointanchor{parent anchor}%
\edef\forest@getedge@pa@l{\the\pgf@x}%
\edef\forest@getedge@pa@s{\the\pgf@y}%
\eappto\forest@node@edge{\noexpand\pgfsyssoftpath@movetotoken{\forest@getedge@pa@l}{\forest@getedge@pa@s}}%
@@ -7474,6 +5747,7 @@
% Switch to this node's |(l,s)| coordinate system (origin at the
% node's anchor).
% \begin{macrocode}
+ \pgfgettransform\forest@temp@transform
\pgftransformreset
\pgftransformrotate{\forestove{grow}}%
% \end{macrocode}
@@ -7492,7 +5766,7 @@
\ifnum\forestove{ignore edge}=0
\pgfpointadd
{\pgfpointtransformed{\pgfqpoint{\forestove{l}}{\forestove{s}}}}%
- {\forestove{child@anchor}}%
+ {\forest@pointanchor{child anchor}}%
\pgfgetlastxy{\forest@getedge@ca@l}{\forest@getedge@ca@s}%
\eappto\forest@all@edges{%
\noexpand\pgfsyssoftpath@movetotoken{\forest@getedge@pa@l}{\forest@getedge@pa@s}%
@@ -7508,6 +5782,7 @@
\forest@merge@intersectionloop
\eappto\forest@node@edge{\expandonce{\forest@all@edges}\expandonce{\forest@edgenode@intersections}}%
}%
+ \pgfsettransform\forest@temp@transform
% \end{macrocode}
% Process the path into an edge and store the edge.
% \begin{macrocode}
@@ -7515,16 +5790,16 @@
\forestolet{#1@edge@#2}\forest@node@edge
\fi
}
-\newloop\forest@merge@loop
+%\newloop\forest@merge@loop
\def\forest@merge@intersectionloop{%
\c@pgf@counta=0
- \forest@merge@loop
+ \forest@loop
\ifnum\c@pgf@counta<\pgfintersectionsolutions\relax
\advance\c@pgf@counta1
\pgfpointintersectionsolution{\the\c@pgf@counta}%
\eappto\forest@edgenode@intersections{\noexpand\pgfsyssoftpath@movetotoken
{\the\pgf@x}{\the\pgf@y}}%
- \forest@merge@repeat
+ \forest@repeat
}
% \end{macrocode}
%
@@ -7532,7 +5807,7 @@
% grow.
% \begin{macrocode}
\def\forest@node@getboundingrectangle@ls#1{%
- \forestoget{boundary}\forest@node@boundary
+ \forestoget{@boundary}\forest@node@boundary
\forest@path@getboundingrectangle@ls\forest@node@boundary{#1}%
}
% \end{macrocode}
@@ -7701,7 +5976,7 @@
\def\forest@pack@tiers@computeprocessingorder{%
\def\forest@tiers@processingorder{}%
\forestoget{tiers}\forest@tiers@cpo@tierstodo
- \forest@loopa
+ \safeloop
\ifdefempty\forest@tiers@cpo@tierstodo{\forest@tempfalse}{\forest@temptrue}%
\ifforest@temp
\def\forest@tiers@cpo@tiersremaining{}%
@@ -7711,7 +5986,7 @@
\PackageError{forest}{Circular tiers!}{}}{}%
\forlistloop\forest@pack@tiers@cpo@forhandlerB\forest@tiers@cpo@tiersremaining
\let\forest@tiers@cpo@tierstodo\forest@tiers@cpo@tiersremaining
- \forest@repeata
+ \saferepeat
}
\def\forest@pack@tiers@cpo@forhandlerA#1{%
\ifcsempty{forest@tiers@higher@#1}{%
@@ -7792,7 +6067,7 @@
'\forestOve{\forestove{@parent}}{content}') was given 'calign=\forestove{calign}', while its
child \forest@cn\space (content: '\forestove{content}') was given 'tier=\forestove{tier}'.
The parent's 'calign' will only work if the child was the lowest node on its tier before the
- alignment.}{}
+ alignment.}%
}
% \end{macrocode}
%
@@ -7867,26 +6142,26 @@
\forest@lt{arc end}%
\forest@lt{arc start}%
}
-\newloop\forest@computenodeboundary@loop
+%\newloop\forest@computenodeboundary@loop
\csdef{forest@compute@node@boundary@regular polygon}{%
\forest@mt{corner 1}%
\c@pgf@counta=\sides\relax
- \forest@computenodeboundary@loop
+ \forest@loop
\ifnum\c@pgf@counta>0
\forest@lt{corner \the\c@pgf@counta}%
\advance\c@pgf@counta-1
- \forest@computenodeboundary@repeat
+ \forest@repeat
}%
\def\forest@compute@node@boundary@star{%
\forest@mt{outer point 1}%
\c@pgf@counta=\totalstarpoints\relax
\divide\c@pgf@counta2
- \forest@computenodeboundary@loop
+ \forest@loop
\ifnum\c@pgf@counta>0
\forest@lt{inner point \the\c@pgf@counta}%
\forest@lt{outer point \the\c@pgf@counta}%
\advance\c@pgf@counta-1
- \forest@computenodeboundary@repeat
+ \forest@repeat
}%
\csdef{forest@compute@node@boundary@isosceles triangle}{%
\forest@mt{apex}%
@@ -7930,23 +6205,23 @@
\getradii
\forest@mt{puff 1}%
\c@pgf@counta=\puffs\relax
- \forest@computenodeboundary@loop
+ \forest@loop
\ifnum\c@pgf@counta>0
\forest@lt{puff \the\c@pgf@counta}%
\advance\c@pgf@counta-1
- \forest@computenodeboundary@repeat
+ \forest@repeat
}
\def\forest@compute@node@boundary@starburst{
\calculatestarburstpoints
\forest@mt{outer point 1}%
\c@pgf@counta=\totalpoints\relax
\divide\c@pgf@counta2
- \forest@computenodeboundary@loop
+ \forest@loop
\ifnum\c@pgf@counta>0
\forest@lt{inner point \the\c@pgf@counta}%
\forest@lt{outer point \the\c@pgf@counta}%
\advance\c@pgf@counta-1
- \forest@computenodeboundary@repeat
+ \forest@repeat
}%
\def\forest@compute@node@boundary@signal{%
\forest@mt{east}%
@@ -8099,11 +6374,9 @@
% Stores the results in attributes |x| and |y|.
% \begin{macrocode}
\def\forest@node@computeabsolutepositions{%
- \forestoset{x}{0pt}%
- \forestoset{y}{0pt}%
\edef\forest@marshal{%
\noexpand\forest@node@foreachchild{%
- \noexpand\forest@node@computeabsolutepositions@{0pt}{0pt}{\forestove{grow}}%
+ \noexpand\forest@node@computeabsolutepositions@{\forestove{x}}{\forestove{y}}{\forestove{grow}}%
}%
}\forest@marshal
}
@@ -8203,7 +6476,7 @@
\fi
}
\def\forest@node@drawtree@{%
- \forest@node@foreach{\forest@draw@node}%
+ \forest@forthis{\forestset{draw tree method}}%
\forest@node@Ifnamedefined{forest@baseline@node}{%
\edef\forest@temp{%
\noexpand\pgfsetbaselinepointlater{%
@@ -8213,8 +6486,6 @@
}%
}\forest@temp
}{}%
- \forest@node@foreachdescendant{\forest@draw@edge}%
- \forest@node@foreach{\forest@draw@tikz}%
}
\def\forest@draw@node{%
\ifnum\forestove{phantom}=0
@@ -8229,10 +6500,12 @@
\fi
}
\def\forest@draw@edge{%
- \ifnum\forestove{phantom}=0
- \ifnum\forestOve{\forestove{@parent}}{phantom}=0
- \edef\forest@temp{\forestove{edge path}}%
- \forest@temp
+ \ifnum\forest@cn=\forest@root\relax\else
+ \ifnum\forestove{phantom}=0
+ \ifnum\forestOve{\forestove{@parent}}{phantom}=0
+ \edef\forest@temp{\forestove{edge path}}%
+ \forest@temp
+ \fi
\fi
\fi
}
@@ -8240,69 +6513,7 @@
\forestove{tikz}%
}
% \end{macrocode}
-% A hack into \TikZ;'s coordinate parser: implements relative node names!
-% \begin{macrocode}
-\def\forest@tikz@parse@node#1(#2){%
- \pgfutil@in@.{#2}%
- \ifpgfutil@in@
- \expandafter\forest@tikz@parse@node@checkiftikzname@withdot
- \else%
- \expandafter\forest@tikz@parse@node@checkiftikzname@withoutdot
- \fi%
- #1(#2)\forest@end
-}
-\def\forest@tikz@parse@node@checkiftikzname@withdot#1(#2.#3)\forest@end{%
- \forest@tikz@parse@node@checkiftikzname#1{#2}{.#3}}
-\def\forest@tikz@parse@node@checkiftikzname@withoutdot#1(#2)\forest@end{%
- \forest@tikz@parse@node@checkiftikzname#1{#2}{}}
-\def\forest@tikz@parse@node@checkiftikzname#1#2#3{%
- \expandafter\ifx\csname pgf@sh@ns@#2\endcsname\relax
- \forest@forthis{%
- \forest@nameandgo{#2}%
- \edef\forest@temp@relativenodename{\forestove{name}}%
- }%
- \else
- \def\forest@temp@relativenodename{#2}%
- \fi
- \expandafter\forest@original@tikz@parse@node\expandafter#1\expandafter(\forest@temp@relativenodename#3)%
-}
-\def\forest@nameandgo#1{%
- \pgfutil@in@!{#1}%
- \ifpgfutil@in@
- \forest@nameandgo@(#1)%
- \else
- \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
- \fi
-}
-\def\forest@nameandgo@(#1!#2){%
- \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
- \forest@go{#2}%
-}
-% \end{macrocode}
-% |parent/child anchor| are generic anchors which forward to the real one. There's a hack in there
-% to deal with link pointing to the ``border'' anchor.
-% \begin{macrocode}
-\pgfdeclaregenericanchor{parent anchor}{%
- \forest@generic@parent@child@anchor{parent }{#1}}
-\pgfdeclaregenericanchor{child anchor}{%
- \forest@generic@parent@child@anchor{child }{#1}}
-\pgfdeclaregenericanchor{anchor}{%
- \forest@generic@parent@child@anchor{}{#1}}
-\def\forest@generic@parent@child@anchor#1#2{%
- \forestOget{\forest@node@Nametoid{\pgfreferencednodename}}{#1anchor}\forest@temp@parent@anchor
- \ifdefempty\forest@temp@parent@anchor{%
- \pgf@sh@reanchor{#2}{center}%
- \xdef\forest@hack@tikzshapeborder{%
- \noexpand\tikz@shapebordertrue
- \def\noexpand\tikz@shapeborder@name{\pgfreferencednodename}%
- }\aftergroup\forest@hack@tikzshapeborder
- }{%
- \pgf@sh@reanchor{#2}{\forest@temp@parent@anchor}%
- }%
-}
-% \end{macrocode}
-%
-%
+%
% \section{Geometry}
% \label{imp:geometry}
%
@@ -8453,7 +6664,7 @@
% \begin{macrocode}
\c@pgf@counta=0
\c@pgf@countb=-1
- \loop
+ \safeloop
\ifnum\c@pgf@counta<\csname#1n\endcsname\relax
% \end{macrocode}
% Check if the projection tuple in the current raw item equals the
@@ -8510,7 +6721,7 @@
\cslet{#1\the\c@pgf@counta xp}\relax
\cslet{#1\the\c@pgf@counta yp}\relax
\advance\c@pgf@counta 1
- \repeat
+ \saferepeat
% \end{macrocode}
% Clean up the raw array length.
% \begin{macrocode}
@@ -8667,7 +6878,7 @@
% array order) the projections of the previous and the current point
% (both exclusive).
% \begin{macrocode}
- \loop
+ \safeloop
\advance\forest@temp@count\forest@breakpath@step\relax
\expandafter\ifnum\forest@breakpath@test
% \end{macrocode}
@@ -8704,7 +6915,7 @@
% Cache the projection of the new segment edge.
% \begin{macrocode}
\csedef{\forest@bp@prefix(\the\pgf@x,\the\pgf@y)}{\the\forest@temp@count}%
- \repeat
+ \saferepeat
\fi
% \end{macrocode}
% Add the current point.
@@ -8775,8 +6986,7 @@
% \end{macrocode}
% The auxiliary data is set up: do the work!
% \begin{macrocode}
- \forest@gettightedgeofpath@getedge
- \pgfsyssoftpath@getcurrentpath\forest@edge
+ \forest@gettightedgeofpath@getedge\forest@edge
% \end{macrocode}
% Where possible, merge line segments of the path into a single line
% segment. This is an important optimization, since the edges of the
@@ -8797,27 +7007,26 @@
% Reverse the order of items in the inner arrays.
% \begin{macrocode}
\c@pgf@counta=0
- \loop
+ \forest@loop
\ifnum\c@pgf@counta<\forest@pi@n\relax
\forest@ppi@deflet{forest@pi@\the\c@pgf@counta @}%
\forest@reversearray\forest@ppi@let
{0}%
{\csname forest@pi@\the\c@pgf@counta @n\endcsname}%
\advance\c@pgf@counta 1
- \repeat
+ \forest@repeat
% \end{macrocode}
% Calling |\forest@gettightedgeofpath@getedge| now will result in the
% positive edge.
% \begin{macrocode}
- \forest@gettightedgeofpath@getedge
- \pgfsyssoftpath@getcurrentpath\forest@edge
+ \forest@gettightedgeofpath@getedge\forest@edge
\forest@simplifypath\forest@edge\forest@gep@secondedge
% \end{macrocode}
% Smuggle the results out of the enclosing \TeX\ group.
% \begin{macrocode}
- \global\let\forest@gep@global@firstedge\forest@gep@firstedge
- \global\let\forest@gep@global@secondedge\forest@gep@secondedge
- }%
+ \global\let\forest@gep@global@firstedge\forest@gep@firstedge
+ \global\let\forest@gep@global@secondedge\forest@gep@secondedge
+ }%
\let#2\forest@gep@global@firstedge
\let#3\forest@gep@global@secondedge
}
@@ -8825,12 +7034,11 @@
%
% Sort the inner arrays of original points wrt the distance to the
% grow line. |#2| =
-% |\forest@sort@ascending|/|\forest@sort@descending|. (|\forest@loopa| is
-% used here because quicksort uses |\loop|.)
+% |\forest@sort@ascending|/|\forest@sort@descending|.
% \begin{macrocode}
\def\forest@sort@inner@arrays#1#2{%
\c@pgf@counta=0
- \forest@loopa
+ \safeloop
\ifnum\c@pgf@counta<\csname#1n\endcsname
\c@pgf@countb=\csname#1\the\c@pgf@counta @n\endcsname\relax
\ifnum\c@pgf@countb>1
@@ -8840,7 +7048,7 @@
\forest@sort\forest@ppi@cmp\forest@ppi@let#2{0}{\the\c@pgf@countb}%
\fi
\advance\c@pgf@counta 1
- \forest@repeata
+ \saferepeat
}
% \end{macrocode}
%
@@ -8922,7 +7130,7 @@
%
% In this macro, the edge is actually computed.
% \begin{macrocode}
-\def\forest@gettightedgeofpath@getedge{%
+\def\forest@gettightedgeofpath@getedge#1{% cs to store the edge into
% \end{macrocode}
% Clear the path and the last projection.
% \begin{macrocode}
@@ -8939,10 +7147,10 @@
\forest@temp@count=\forest@pi@n\relax
\advance\forest@temp@count -1
\edef\forest@nminusone{\the\forest@temp@count}%
- \forest@loopa
+ \safeloop
\ifnum\c@pgf@counta<\forest@nminusone\relax
\forest@gettightedgeofpath@getedge@loopa
- \forest@repeata
+ \saferepeat
% \end{macrocode}
% A special case: the edge ends with a degenerate subpath (a
% point).
@@ -8952,12 +7160,14 @@
\forest@gettightedgeofpath@maybemoveto{\forest@nminusone}{0}%
\fi
\fi
+ \pgfsyssoftpath@getcurrentpath#1%
+ \pgfsyssoftpath@setcurrentpath\pgfutil@empty
}
% \end{macrocode}
% The body of a loop containing an embedded loop must be put in a
% separate macro because it contains the |\if...| of the embedded
-% |\loop...| without the matching |\fi|: |\fi| is ``hiding'' in the
-% embedded |\loop|, which has not been expanded yet.
+% |\forest@loop...| without the matching |\fi|: |\fi| is ``hiding'' in the
+% embedded |\forest@loop|, which has not been expanded yet.
% \begin{macrocode}
\def\forest@gettightedgeofpath@getedge@loopa{%
\ifnum\csname forest@pi@\the\c@pgf@counta @n\endcsname>0
@@ -8972,10 +7182,10 @@
% distance to the grow line.
% \begin{macrocode}
\c@pgf@countb=0
- \forest@loopb
+ \safeloop
\ifnum\c@pgf@countb<\csname forest@pi@\the\c@pgf@counta @n\endcsname\relax
\forest@gettightedgeofpath@getedge@loopb
- \forest@repeatb
+ \saferepeat
\fi
\advance\c@pgf@counta 1
}
@@ -8988,7 +7198,7 @@
\advance\c@pgf@counta 1
\edef\forest@aplusone{\the\c@pgf@counta}%
\advance\c@pgf@counta -1
- \forest@loopc
+ \safeloop
\ifnum\c@pgf@countc<\csname forest@pi@\forest@aplusone @n\endcsname\relax
% \end{macrocode}
% Test whether [the current point]--[the next point] or [the next
@@ -9049,13 +7259,13 @@
\csname forest@pi@\forest@aplusone @\the\c@pgf@countc y\endcsname}%
\pgfsyssoftpath@lineto\forest@last@x\forest@last@y
% \end{macrocode}
-% Finally, ``break'' out of the |\forest@loopc| and |\forest@loopb|.
+% Finally, ``break'' out of the innermost two loops.
% \begin{macrocode}
\c@pgf@countc=\csname forest@pi@\forest@aplusone @n\endcsname
\c@pgf@countb=\csname forest@pi@\the\c@pgf@counta @n\endcsname
\fi
\advance\c@pgf@countc 1
- \forest@repeatc
+ \saferepeat
\advance\c@pgf@countb 1
}
% \end{macrocode}
@@ -9100,6 +7310,7 @@
\fi
\forest@restore@pgfsyssoftpath@tokendefs
\pgfsyssoftpath@getcurrentpath#2%
+ \pgfsyssoftpath@setcurrentpath\pgfutil@empty
}
% \end{macrocode}
% When a move-to is encountered, we flush whatever segment we were
@@ -9278,7 +7489,7 @@
% compute the distance
\let\forest@distance\relax
\c@pgf@countc=0
- \loop
+ \forest@loop
\ifnum\c@pgf@countc<\csname forest@PI1@n\endcsname\relax
\ifnum\csname forest@PI1@\the\c@pgf@countc @n\endcsname=0 \else
\ifnum\csname forest@PI2@\the\c@pgf@countc @n\endcsname=0 \else
@@ -9294,7 +7505,7 @@
\fi
\fi
\advance\c@pgf@countc 1
- \repeat
+ \forest@repeat
\let#3\forest@distance
}
% merge projections: we need two projection arrays, both containing
@@ -9387,13 +7598,13 @@
\forest@dbep@mp@iterateone\forest@input@prefix@two\c@pgf@countb\forest@output@prefix@two
}
\def\forest@dbep@mp@iterateone#1#2#3{%
- \loop
+ \forest@loop
\ifnum#2<\csname#1n\endcsname\relax
\forest@dbep@mp@@store@p#1#2%
\forest@dbep@mp@@store@o#1#2#3%
\advance\c@pgf@countc 1
\advance#21
- \repeat
+ \forest@repeat
}
% \end{macrocode}
%
@@ -9513,19 +7724,7 @@
%
% \section{The outer UI}
%
-% \subsection{Package options}
%
-% \begin{macrocode}
-\newif\ifforesttikzcshack
-\foresttikzcshacktrue
-\newif\ifforest@install@keys@to@tikz@path@
-\forest@install@keys@to@tikz@path@true
-\forestset{package@options/.cd,
- external/.is if=forest@external@,
- tikzcshack/.is if=foresttikzcshack,
- tikzinstallkeys/.is if=forest@install@keys@to@tikz@path@,
-}
-% \end{macrocode}
% \subsection{Externalization}
% \begin{macrocode}
\pgfkeys{/forest/external/.cd,
@@ -9548,12 +7747,17 @@
}{}%
\fi
}
-\newif\ifforest@external@
\newif\ifforest@external@optimize@
\forest@external@optimize@true
-\ProcessPgfPackageOptions{/forest/package@options}
\ifforest@install@keys@to@tikz@path@
- \tikzset{fit to tree/.style={/forest/fit to tree}}
+\tikzset{
+ fit to/.style={
+ /forest/for nodewalk=%
+ {TeX={\def\forest@fitto{}},#1}%
+ {TeX={\eappto\forest@fitto{(\forestove{name})}}},
+ fit/.expanded={\forest@fitto}
+ },
+}
\fi
\ifforest@external@
\ifdefined\tikzexternal@tikz@replacement\else
@@ -9596,19 +7800,29 @@
% \subsection{The \texttt{forest} environment}
% \label{imp:forest-environment}
%
-% There are three ways to invoke \foRest;: the environent and the starless and the starred version
+% There are three ways to invoke \foRest;: the environment and the starless and the starred version
% of the macro. The latter creates no group.
%
% Most of the code in this section deals with externalization.
%
% \begin{macrocode}
-\newenvironment{forest}{\pgfkeysalso{/forest/begin forest}\Collect@Body\forest@env}{}
-\long\def\Forest{\pgfkeysalso{/forest/begin forest}\@ifnextchar*{\forest@nogroup}{\forest@group}}
-\def\forest@group#1{{\forest@env{#1}}}
-\def\forest@nogroup*#1{\forest@env{#1}}
+\NewDocumentEnvironment{forest}{D(){stages}}{%
+ \forest@defstages{#1}%
+ \Collect@Body
+ \forest@env
+}{}
+\NewDocumentCommand{\Forest}{s D(){stages} m}{%
+ \forest@defstages{#2}%
+ \IfBooleanTF{#1}{\let\forest@next\forest@env}{\let\forest@next\forest@group@env}%
+ \forest@next{#3}%
+}
+\def\forest@defstages#1{%
+ \def\forest@stages{#1}%
+}
+\def\forest@group@env#1{{\forest@env{#1}}}
\newif\ifforest@externalize@tree@
\newif\ifforest@was@tikzexternalwasenable
-\long\def\forest@env#1{%
+\newcommand\forest@env[1]{%
\let\forest@external@next\forest@begin
\forest@was@tikzexternalwasenablefalse
\ifdefined\tikzexternal@tikz@replacement
@@ -9620,16 +7834,23 @@
\forest@externalize@tree@false
\ifforest@external@
\ifforest@was@tikzexternalwasenable
- \tikzifexternalizing{%
- \let\forest@external@next\forest@begin@externalizing
- }{%
- \let\forest@external@next\forest@begin@externalize
- }%
+ \forest@env@
\fi
\fi
\forest@standardnode@calibrate
\forest@external@next{#1}%
}
+\def\forest@env@{%
+ \iftikzexternalexportnext
+ \tikzifexternalizing{%
+ \let\forest@external@next\forest@begin@externalizing
+ }{%
+ \let\forest@external@next\forest@begin@externalize
+ }%
+ \else
+ \tikzexternalexportnexttrue
+ \fi
+}
% \end{macrocode}
% We're externalizing, i.e.\ this code gets executed in the embedded call.
% \begin{macrocode}
@@ -9737,8 +7958,7 @@
% \begin{macrocode}
\def\forest@includeexternal#1{%
\edef\forest@temp{\pgfkeysvalueof{/forest/external/context}}%
- \typeout{forest: Including external picture '#1' for forest context+code:
- '\expandafter\detokenize\expandafter{\forest@externalize@id}'}%
+ %\typeout{forest: Including external picture '#1' for forest context+code: '\expandafter\detokenize\expandafter{\forest@externalize@id}'}%
{%
%\def\pgf@declaredraftimage##1##2{\def\pgf@image{\hbox{}}}%
\tikzsetnextfilename{#1}%
@@ -9769,9 +7989,7 @@
}
\def\forest@do{%
\forest@node@Compute@numeric@ts@info{\forest@root}%
- \forestset{process keylist=given options}%
- \forestset{stages}%
- \pgfkeysalso{/forest/end forest}%
+ \expandafter\forestset\expandafter{\forest@stages}%
\ifforest@was@tikzexternalwasenable
\tikzexternalenable
\fi
@@ -9911,11 +8129,9 @@
}
}
\def\forest@forestcs@resetxy{%
- \ifnum\forest@cn=0
- \else
- \global\pgf@x\forestove{x}%
- \global\pgf@y\forestove{y}%
- \fi
+ \ifnum\forest@cn=0 \forest@cs@invalidnodeerror\fi
+ \global\pgf@x\forestove{x}%
+ \global\pgf@y\forestove{y}%
}
\def\forest@forestcs@ls{%
\ifdefined\forest@forestcs@l
@@ -9938,8 +8154,12 @@
}
\def\forest@forestcs@namegoanchor#1.#2\forest@end{%
\forest@nameandgo{#1}%
+ \ifnum\forest@cn=0 \forest@cs@invalidnodeerror\fi
\forest@forestcs@anchor{#2}%
}
+\def\forest@cs@invalidnodeerror{%
+ \PackageError{forest}{Attempt to refer to the invalid node by "forest cs"}%
+}
\tikzdeclarecoordinatesystem{forest}{%
\forest@forthis{%
\forest@forestcs@resetxy
@@ -9950,20 +8170,392 @@
}
% \end{macrocode}
%
-% \addcontentsline{toc}{section}{References}
-% \bibliography{tex}
-% \bibliographystyle{plain}
+% \subsection{Relative node names in \TikZ;}
+% \label{sec:relative-node-names}
%
-% \newpage
-% \addcontentsline{toc}{section}{Index}
-% \makeatletter\c@IndexColumns=2 \makeatother
-% \IndexPrologue{\section*{Index}}
-% \PrintIndex
+% A hack into \TikZ;'s coordinate parser: implements relative node names!
+% \begin{macrocode}
+\def\forest@tikz@parse@node#1(#2){%
+ \pgfutil@in@.{#2}%
+ \ifpgfutil@in@
+ \expandafter\forest@tikz@parse@node@checkiftikzname@withdot
+ \else%
+ \expandafter\forest@tikz@parse@node@checkiftikzname@withoutdot
+ \fi%
+ #1(#2)\forest@end
+}
+\def\forest@tikz@parse@node@checkiftikzname@withdot#1(#2.#3)\forest@end{%
+ \forest@tikz@parse@node@checkiftikzname#1{#2}{.#3}}
+\def\forest@tikz@parse@node@checkiftikzname@withoutdot#1(#2)\forest@end{%
+ \forest@tikz@parse@node@checkiftikzname#1{#2}{}}
+\def\forest@tikz@parse@node@checkiftikzname#1#2#3{%
+ \expandafter\ifx\csname pgf@sh@ns@#2\endcsname\relax
+ \forest@forthis{%
+ \forest@nameandgo{#2}%
+ \ifnum\forest@cn=0 \forest@cs@invalidnodeerror\fi
+ \edef\forest@temp@relativenodename{\forestove{name}}%
+ }%
+ \else
+ \def\forest@temp@relativenodename{#2}%
+ \fi
+ \expandafter\forest@original@tikz@parse@node\expandafter#1\expandafter(\forest@temp@relativenodename#3)%
+}
+\def\forest@nameandgo#1{%
+ \pgfutil@in@!{#1}%
+ \ifpgfutil@in@
+ \forest@nameandgo@(#1)%
+ \else
+ \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
+ \fi
+}
+\def\forest@nameandgo@(#1!#2){%
+ \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
+ \forest@go{#2}%
+}
+% \end{macrocode}
+%
+% \subsection{Anchors}
+% \label{sec:anchors}
%
+% \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|.
+%
+% We need to access |rotate| for the anchors below to work in general.
+% \begin{macrocode}
+\forestset{
+ declare count={rotate}{0},
+ autoforward'={rotate}{node options},
+}
+% \end{macrocode}
+% Variants of |parent/children_first/last| without |'| snap border anchors to the closest compass direction.
+% \begin{macrocode}
+\newif\ifforest@anchor@snapbordertocompass
+% \end{macrocode}
+% 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|.
+% \begin{macrocode}
+\newif\ifforest@anchor@forwardtotikz
+% \end{macrocode}
+% Growth-based anchors set this to true to signal that the result is a border anchor.
+% \begin{macrocode}
+\newif\ifforest@anchor@isborder
+% \end{macrocode}
+% The UI macro.
+% \begin{macrocode}
+\def\forestanchortotikzanchor#1#2{% #1 = forest anchor, #2 = macro to receive the tikz anchor
+ \forest@anchor@forwardtotikzfalse
+ \forest@anchor@do{}{#1}{\forest@cn}%
+ \let#2\forest@temp@anchor
+}
+% \end{macrocode}
+% Generic anchors.
+% \begin{macrocode}
+\pgfdeclaregenericanchor{child anchor}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{child anchor}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent anchor}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent anchor}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{anchor}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{anchor}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children first}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children first}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{first}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{first}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent first}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent first}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent last}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent last}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{last}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{last}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children last}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children last}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children first'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children first'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{first'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{first'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent first'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent first'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent last'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent last'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{last'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{last'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children last'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children last'}{\forest@referencednodeid}%
+}
+% \end{macrocode}
+% The driver. The result is being passed around in |\forest@temp@anchor|.
+% \begin{macrocode}
+\def\forest@anchor@do#1#2#3{% #1 = shape name, #2 = (potentially) forest anchor, #3 = node id
+ \forest@fornode{#3}{%
+ \def\forest@temp@anchor{#2}%
+ \forest@anchor@snapbordertocompassfalse
+ \forest@anchor@isborderfalse
+ \forest@anchor@to@tikz@anchor
+ \forest@anchor@border@to@compass
+ \ifforest@anchor@forwardtotikz
+ \forest@anchor@forward{#1}%
+ \else
+ \fi
+ }%
+}
+% \end{macrocode}
+% This macro will loop (resolving the anchor) until the result is not a \FoRest; macro.
+% \begin{macrocode}
+\def\forest@anchor@to@tikz@anchor{%
+ \ifcsdef{forest@anchor@@\forest@temp@anchor}{%
+ \csuse{forest@anchor@@\forest@temp@anchor}%
+ \forest@anchor@to@tikz@anchor
+ }{}%
+}
+% \end{macrocode}
+% Actual computation.
+% \begin{macrocode}
+\csdef{forest@anchor@@parent anchor}{%
+ \forestoget{parent anchor}\forest@temp@anchor}
+\csdef{forest@anchor@@child anchor}{%
+ \forestoget{child anchor}\forest@temp@anchor}
+\csdef{forest@anchor@@anchor}{%
+ \forestoget{anchor}\forest@temp@anchor}
+\csdef{forest@anchor@@children'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}}%
+}
+\csdef{forest@anchor@@parent'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}+180}%
+}
+\csdef{forest@anchor@@first'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 -\else+\fi90}%
+}
+\csdef{forest@anchor@@last'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 +\else-\fi90}%
+}
+\csdef{forest@anchor@@parent first'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor@parent{\number\numexpr\forestove{grow}-\forestove{rotate}+180}%
+ \edef\forest@temp@anchor@first{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 -\else+\fi90}%
+ \forest@getaverageangle{\forest@temp@anchor@parent}{\forest@temp@anchor@first}\forest@temp@anchor
+}
+\csdef{forest@anchor@@parent last'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor@parent{\number\numexpr\forestove{grow}-\forestove{rotate}+180}%
+ \edef\forest@temp@anchor@last{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 +\else-\fi90}%
+ \forest@getaverageangle{\forest@temp@anchor@parent}{\forest@temp@anchor@last}\forest@temp@anchor
+}
+\csdef{forest@anchor@@children first'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor@first{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 -\else+\fi90}%
+ \forest@getaverageangle{\forestove{grow}-\forestove{rotate}}{\forest@temp@anchor@first}\forest@temp@anchor
+}
+\csdef{forest@anchor@@children last'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor@last{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 +\else-\fi90}%
+ \forest@getaverageangle{\forestove{grow}-\forestove{rotate}}{\forest@temp@anchor@last}\forest@temp@anchor
+}
+\csdef{forest@anchor@@children}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@children'}%
+}
+\csdef{forest@anchor@@parent}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@parent'}%
+}
+\csdef{forest@anchor@@first}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@first'}%
+}
+\csdef{forest@anchor@@last}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@last'}%
+}
+\csdef{forest@anchor@@parent first}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@parent first'}%
+}
+\csdef{forest@anchor@@parent last}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@parent last'}%
+}
+\csdef{forest@anchor@@children first}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@children first'}%
+}
+\csdef{forest@anchor@@children last}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@children last'}%
+}
+% \end{macrocode}
+% This macro computes the "average" angle of |#1| and |#2| and stores in into |#3|.
+% The angle computed is the geometrically "closer" one. The formula is
+% adapted from \url{http://stackoverflow.com/a/1159336/624872}.
+% \begin{macrocode}
+\def\forest@getaverageangle#1#2#3{%
+ \edef\forest@temp{\number\numexpr #1-#2+540}%
+ \pgfmathMod{\forest@temp}{360}\pgfmathtruncatemacro\pgfmathresult{\pgfmathresult}
+ \edef\forest@temp{360+#2+((\pgfmathresult-180)/2)}%
+ \pgfmathMod{\forest@temp}{360}\pgfmathtruncatemacro#3{\pgfmathresult}%
+}
+% \end{macrocode}
+% The first macro changes border anchor to compass anchor. The second one does this only if the node shape allows it.
+% \begin{macrocode}
+\def\forest@anchor@border@to@compass{%
+ \ifforest@anchor@isborder
+ \ifforest@anchor@snapbordertocompass
+ \forest@anchor@snap@border@to@compass
+ \else
+ \pgfmathMod{\forest@temp@anchor}{360}%
+ \pgfmathtruncatemacro\forest@temp@anchor{\pgfmathresult}%
+ \fi
+ \ifforest@anchor@forwardtotikz
+ \ifcsname pgf@anchor%
+ @\csname pgf@sh@ns@\pgfreferencednodename\endcsname
+ @\csname forest@compass@\forest@temp@anchor\endcsname
+ \endcsname
+ \letcs\forest@temp@anchor{forest@compass@\forest@temp@anchor}%
+ \fi
+ \else
+ \ifforest@anchor@snapbordertocompass
+ \letcs\forest@temp@anchor{forest@compass@\forest@temp@anchor}%
+ \fi
+ \fi
+ \fi
+}
+\csdef{forest@compass@0}{east}
+\csdef{forest@compass@45}{north east}
+\csdef{forest@compass@90}{north}
+\csdef{forest@compass@135}{north west}
+\csdef{forest@compass@180}{west}
+\csdef{forest@compass@225}{south west}
+\csdef{forest@compass@270}{south}
+\csdef{forest@compass@315}{south east}
+\csdef{forest@compass@360}{east}
+% \end{macrocode}
+% This macro approximates an angle (stored in |\forest@temp@anchor|) with a compass direction (stores it in the same macro).
+% \begin{macrocode}
+\def\forest@anchor@snap@border@to@compass{%
+ \pgfmathMod{\forest@temp@anchor}{360}%
+ \pgfmathdivide{\pgfmathresult}{45}%
+ \pgfmathround{\pgfmathresult}%
+ \pgfmathmultiply{\pgfmathresult}{45}%
+ \pgfmathtruncatemacro\forest@temp@anchor{\pgfmathresult}%
+}
+% \end{macrocode}
+% This macro forwards the resulting anchor to \TikZ;.
+% \begin{macrocode}
+\def\forest@anchor@forward#1{% #1 = shape name
+ \ifdefempty\forest@temp@anchor{%
+ \pgf@sh@reanchor{#1}{center}%
+ \xdef\forest@hack@tikzshapeborder{%
+ \noexpand\tikz@shapebordertrue
+ \def\noexpand\tikz@shapeborder@name{\pgfreferencednodename}%
+ }\aftergroup\forest@hack@tikzshapeborder
+ }{%
+ \pgf@sh@reanchor{#1}{\forest@temp@anchor}%
+ }%
+}
+% \end{macrocode}
+%
+% Expandably strip "not yet positionedPGFINTERNAL" from |\pgfreferencednodename| if it is there.
+% \begin{macrocode}
+\def\forest@referencednodeid{\forest@node@Nametoid{\forest@referencednodename}}%
+\def\forest@referencednodename{%
+ \expandafter\expandafter\expandafter\forest@referencednodename@\expandafter\pgfreferencednodename\forest@pgf@notyetpositioned\relax
+}
+\expandafter\def\expandafter\forest@referencednodename@\expandafter#\expandafter1\forest@pgf@notyetpositioned#2\relax{%
+ \if\relax#1\relax\forest@referencednodename@stripafter#2\relax\fi
+ \if\relax#2\relax#1\fi
+}
+\expandafter\def\expandafter\forest@referencednodename@stripafter\expandafter#\expandafter1\forest@pgf@notyetpositioned\relax{#1}
+% \end{macrocode}
+%
+% 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.
+% \begin{macrocode}
+\def\forest@Pointanchor#1#2{% #1 = node id, #2 = anchor
+ {%
+ \def\forest@pa@temp@name{name}%
+ \forestOifdefined{#1}{@box}{%
+ \forestOget{#1}{@box}\forest@temp
+ \ifdefempty\forest@temp{}{%
+ \def\forest@pa@temp@name{later@name}%
+ }%
+ }{}%
+ \setbox0\hbox{%
+ \begin{pgfpicture}%
+ \if\relax\forestOve{#1}{#2}\relax
+ \pgfpointanchor{\forestOve{#1}{\forest@pa@temp@name}}{center}%
+ \else
+ \pgfpointanchor{\forestOve{#1}{\forest@pa@temp@name}}{\forestOve{#1}{#2}}%
+ \fi
+ \xdef\forest@global@marshal{%
+ \noexpand\global\noexpand\pgf@x=\the\pgf@x\relax
+ \noexpand\global\noexpand\pgf@y=\the\pgf@y
+ }%
+ \end{pgfpicture}%
+ }%
+ }%
+ \forest@global@marshal
+}
+\def\forest@pointanchor#1{% #1 = anchor
+ \forest@Pointanchor{\forest@cn}{#1}%
+}
+% \end{macrocode}
+%
+% \section{Compatibility with previous versions}
+% \begin{macrocode}
+\ifdefempty{\forest@compat}{}{%
+ \RequirePackage{forest-compat}
+}
+% \end{macrocode}
+%
% \endinput
%
% Local Variables:
% mode: doctex
% fill-column: 100
-% LaTeX-command: "forestlatex -shell-escape"
+% TeX-command-default: "sty"
+% TeX-master: t
% End:
diff --git a/Master/texmf-dist/source/latex/forest/forest.ins b/Master/texmf-dist/source/latex/forest/forest.ins
index 2dc3424ace3..1b9b63f6c3f 100644
--- a/Master/texmf-dist/source/latex/forest/forest.ins
+++ b/Master/texmf-dist/source/latex/forest/forest.ins
@@ -1,6 +1,6 @@
%% forest.ins
%%
-%% Copyright (c) 2012 Saso Zivanovic
+%% Copyright (c) 2015 Saso Zivanovic
%% saso.zivanovic@guest.arnes.si
%%
%% This work may be distributed and/or modified under the
@@ -13,11 +13,16 @@
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
-%% This work consists of the files forest.dtx and forest.ins
-%% and the derived file forest.sty.
+%% This file is a part of package `forest'. For the list of files
+%% constituting the package see main source file of the package,
+%% `forest.dtx', or the derived `forest.sty'.
+%%
\input docstrip.tex
+\keepsilent
\preamble
\endpreamble
\askforoverwritefalse
\generate{\file{forest.sty}{\from{forest.dtx}{}}}
+\generate{\file{forest-lib-linguistics.sty}{\from{forest-libs.dtx}{linguistics}}}
+\generate{\file{forest-lib-edges.sty}{\from{forest-libs.dtx}{edges}}}
\endbatchfile
diff --git a/Master/texmf-dist/tex/latex/forest/forest-compat.sty b/Master/texmf-dist/tex/latex/forest/forest-compat.sty
new file mode 100644
index 00000000000..8921cf5405a
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/forest/forest-compat.sty
@@ -0,0 +1,170 @@
+% \CheckSum{12884}
+% \iffalse meta-comment
+% forest-index.dtx
+%% `forest-compat' defines a compatibility layer of package `forest'.
+%%
+%% Copyright (c) 2015 Saso Zivanovic
+%% (Sa\v{s}o \v{Z}ivanovi\'{c})
+%% saso.zivanovic@guest.arnes.si
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% of this license or (at your option) any later version.
+%% The latest version of this license is in
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `author-maintained'.
+%%
+%% This file is a part of package `forest'. For the list of files
+%% constituting the package see main source file of the package,
+%% `forest.dtx', or the derived `forest.sty'.
+
+\ProvidesPackage{forest-compat}
+
+\def\forest@deprecated#1{%
+ \PackageWarning{forest}{Compatibility mode for #1}%
+}
+\forestset{@@deprecated/.code={\forest@deprecated{#1}}}
+\def\forestcompat#1{\pgfqkeys{/forest/@compat}{#1}}
+\forestcompat{
+ most/.style={1.0-most},
+ all/.style={1.0-all},
+ none/.style={},
+ silent/.style={\def\forest@deprecated##1{}},
+ %%% begin listing region: compat_1.0
+ 1.0-most/.style={
+ 1.0-triangle,1.0-linear,1.0-nodewalk,1.0-ancestors,
+ 1.0-fittotree,1.0-for,1.0-forall
+ },
+ 1.0-all/.style={
+ 1.0-most,
+ 1.0-ignoreinvalidsteps,1.0-rotate,1.0-stages,1.0-name
+ },
+ %%% end listing region: compat_1.0
+ 1.0-triangle/.style={
+ /forest/triangle/.style={
+ @@deprecated={key "triangle" from v1.0.x. Use key "roof" from library "linguistics" instead},
+ edge path'={%
+ (.north west)--(!u.south)--(.north east)--cycle
+ }
+ }
+ },
+ 1.0-linear/.style={
+ /forest/define long step={linear next}{autostep}{%
+ \forest@deprecated{nodewalk step "linear next" from v1.0. Use key "next node" instead.}%
+ \edef\forest@cn{\forest@node@linearnextid}},
+ /forest/define long step={linear previous}{autostep}{%
+ \forest@deprecated{nodewalk step "linear previous" from v1.0. Use key "previous node" instead.}%
+ \edef\forest@cn{\forest@node@linearpreviousid}},
+ },
+ 1.0-nodewalk/.style={
+ /forest/node walk/before walk/.style={},
+ /forest/node walk/every step/.style={},
+ /forest/node walk/after walk/.style={},
+ /forest/node walk/.style={
+ @@deprecated={key "node walk" from v1.0. Use key "nodewalk" instead.},
+ /forest/node walk/before walk,
+ /forest/nodewalk/before walk/.style={/forest/node walk/before walk},
+ /forest/nodewalk/every step/.style={/forest/node walk/every step},
+ /forest/nodewalk/after walk/.style={/forest/node walk/after walk},
+ /forest/nodewalk/node walk/.style={before walk,for nodewalk={####1,options={/forest/nodewalk/after walk}}{/forest/nodewalk/every step}},
+ for nodewalk={##1,options={/forest/nodewalk/after walk}}{/forest/nodewalk/every step},
+ },
+ },
+ 1.0-ancestors/.style={
+ /forest/for ancestors'/.style={
+ @@deprecated={key "for ancestors'" from v1.0.x. Use key "for current and ancestors" instead.},
+ for current and ancestors={##1}},
+ },
+ 1.0-fittotree/.style={%
+ /tikz/fit to tree/.style={
+ /forest/@@deprecated={key "/tikz/fit to tree" from v1.0.x. Use "/tikz/fit to=tree" instead.},
+ inner sep=0pt,fit to=tree
+ }
+ },
+ 1.0-for/.style={
+ /forest/for/.code 2 args={% #1 = nodewalk, #2 = after walk keylist
+ \forest@deprecated{Key "for" from v1.0.x. Use key "for group" instead.}%
+ \forest@forthis{\forest@nodewalk{##1,options={##2}}{}}%
+ }
+ },
+ 1.0-forall/.style={
+ /forest/for all next/.style={
+ @@deprecated={Key "for all next" from v1.0.x. Use key "for following siblings" instead.},
+ for following siblings={##1}},
+ /forest/for all previous/.style={
+ @@deprecated={Key "for all previous" from v1.0.x. Use key "for preceding siblings" instead.},
+ for preceding siblings={##1}},
+ },
+ 1.0-ignoreinvalidsteps/.code={%
+ \def\forest@forstepwrapper##1##2{%
+ \def\forest@nodewalk@config@everystep@method{independent}%
+ \def\forest@nodewalk@config@history@method{independent}%
+ \edef\forest@marshal{%
+ \def\noexpand\forest@nodewalk@config@oninvalid{compatfake}%
+ \unexpanded{\forest@Nodewalk{##1}{##2}}%
+ \def\noexpand\forest@cn{\forest@cn}%
+ \def\noexpand\forest@nodewalk@config@oninvalid{\forest@nodewalk@config@oninvalid}%
+ }\forest@marshal
+ }%
+ \def\forest@relatednode@option@compat@ignoreinvalidsteps##1{%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \def\forest@nodewalk@oninvalid{compatfake}%
+ ##1%
+ }%
+ }%
+ },
+ 1.0-rotate/.style={
+ /forest/undef option=rotate,
+ rotate/.style={
+ @@deprecate={Using non-autoforwarded key "rotate". Some keys, like "forked edges" and "folder", might produce a wrong result.},
+ node options={rotate={##1}},
+ },
+ },
+ 1.0-stages/.style={
+ /forest/@@deprecated={Using v1.0.x "stages" style},
+ /forest/stages/.style={
+ process keylist=before typesetting nodes,
+ typeset nodes stage,
+ process keylist=before packing,
+ pack stage,
+ process keylist=before computing xy,
+ compute xy stage,
+ process keylist=before drawing tree,
+ draw tree stage,
+ },
+ /forest/TeX={%
+ \def\forest@defstages##1{%
+ \def\forest@stages{%
+ begin forest,
+ for root'={
+ process keylist register=default preamble,
+ process keylist register=preamble
+ },
+ process keylist=given options,
+ ##1,
+ end forest
+ }%
+ }%
+ },
+ },
+ 1.0-name/.code={%
+ \forest@deprecated{key "name": using key "name" from v1.0.x, which does not enforce uniqueness. If you really need this, you're doing something wrong.}%
+ \def\forest@node@setname##1{%
+ \ifstrempty{##1}{}{%
+ \forestoeset{name}{##1}%
+ \csedef{forest@id@of@##1}{\forest@cn}%
+ }%
+ }%
+ \def\forest@node@setalias##1{%
+ \ifstrempty{##1}{}{%
+ \csedef{forest@id@of@##1}{\forest@cn}%
+ }%
+ }%
+ },
+}
+\expandafter\forestcompat\expandafter{\forest@compat}
diff --git a/Master/texmf-dist/tex/latex/forest/forest-doc.sty b/Master/texmf-dist/tex/latex/forest/forest-doc.sty
new file mode 100644
index 00000000000..70f84563179
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/forest/forest-doc.sty
@@ -0,0 +1,240 @@
+%% forest-doc.sty
+%% `forest-doc.sty` is an auxiliary package needed to compile the documentation of package `forest`.
+%%
+%% Copyright (c) 2015 Saso Zivanovic
+%% (Sa\v{s}o \v{Z}ivanovi\'{c})
+%% saso.zivanovic@guest.arnes.si
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% of this license or (at your option) any later version.
+%% The latest version of this license is in
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `author-maintained'.
+%%
+%% This file is a part of package `forest'. For the list of files
+%% constituting the package see main source file of the package,
+%% `forest.dtx', or the derived `forest.sty'.
+%%
+\ProvidesPackage{forest-doc}
+\RequirePackage{lstdoc}
+\RequirePackage{pgfkeys}
+\RequirePackage{forest-index}
+% if you want index support, load package "forest-index", but later
+
+\lstset{language={[LaTeX]TeX},tabsize=4,gobble=2,%
+ basicstyle=\small\ttfamily,basewidth=0.51em,boxpos=c,pointstyle=\pstyle,moredelim=[is][\pstyle]{~}{~}}
+%\lst@InstallKeywords{p}{point}{pointstyle}\relax{keywordstyle}{}ld
+\def\pstyle{\color{darkgreen}}
+\def\itemnosep{\vspace{-1.4ex}}
+\lstset{
+ rangebeginprefix=\ \ \%\%\%\ begin\ listing\ region:\ ,
+ rangebeginsuffix=,
+ rangeendprefix=\ \ \%\%\%\ end\ listing\ region:\ ,
+ rangeendsuffix=,
+ includerangemarker=false,
+ keepspaces=true,
+}
+\newcommand\lstinputregion[3][]{\lstinputlisting[linerange=#3-#3,#1]{#2}}
+\def\lst@outputspace{{\ifx\lst@bkgcolor\empty\color{white}\else\lst@bkgcolor\fi\lst@visiblespace}}% this works for acroread, but not for atril :-(
+
+\lstnewenvironment{forestexample}[1][]{%
+ \PackageWarning{forest-doc}{Compiling example}{}%
+ \global\let\lst@intname\@empty
+ \gdef\lst@sample{}%
+ \def\forestexample@layout{tree on left}%
+ \def\forestexample@treebin{box}%
+ \pgfqkeys{/forestexample}{label format,#1}%
+ \pgfkeysgetvalue{/forestexample/counter}\forestexample@temp
+ \ifdefempty\forestexample@temp{}{\addtocounter{\forestexample@temp}{1}}%
+ \setbox\lst@samplebox=\hbox\bgroup
+ \pgfkeysvalueof{/forestexample/tree prefix}%
+ \lst@BeginAlsoWriteFile{\jobname.tmp}%
+}{%
+ \lst@EndWriteFile
+ \pgfkeysvalueof{/forestexample/tree suffix}%
+ \egroup
+ \global\setbox\codebox=\box\lst@samplebox
+ \global\setbox
+ \treebox
+ \csname forestexample@treebin@\forestexample@treebin\endcsname
+ \pgfkeys{/forestexample/do layout/.expanded=\forestexample@layout}%
+}
+\pgfqkeys{/forestexample}{%
+ .unknown/.code={\lstset{\pgfkeyscurrentname={#1}}},
+ index/.code={\indexex[not print]{#1}},
+ index>/.code={\indexex[not print]>{#1}},
+ code prefix/.code={\gdef\lst@sample{#1}},
+ tree prefix/.initial={},
+ tree suffix/.initial={},
+ counter/.initial=lstlisting,
+ no label/.style={counter={}},
+ label format/.store in=\@currentlabel,
+ label format/.default={\arabic{\pgfkeysvalueof{/forestexample/counter}}},
+ tree width/.initial={\dimexpr\linewidth-\wd\codebox-
+ \glueexpr\pgfkeysvalueof{/forestexample/center skip}\relax\relax},
+ layout/.store in=\forestexample@layout,
+ tree bin/.store in=\forestexample@treebin,
+ do layout/.is choice,
+ do layout/export/.code={%
+ \pgfkeysgetvalue{/forestexample/counter}\forestexample@temp
+ \ifdefempty\forestexample@temp{}{\addtocounter{\forestexample@temp}{-1}}%
+ },
+ left skip/.initial={\glueexpr 0pt plus .4\linewidth minus \marginparsep + 0pt minus \@totalleftmargin + 0pt minus .75\marginparwidth},
+ center skip/.initial={3em plus 0.1\linewidth minus 2em},
+ right skip/.initial={0pt plus .4\linewidth},
+ tree left skip/.initial=0pt,
+ tree right skip/.initial=0pt,
+ code left skip/.initial=0pt,
+ code right skip/.initial=0pt,
+ label y offset/.initial={\height-1ex}, % looks better to me this way
+ do layout/tree on left/.code={%
+ \begin{list}{}{\leftmargin 0pt}
+ \item
+ \@tempdima=\ifdim\totalht\treebox>\totalht\codebox
+ \dimexpr0.5 \totalht\treebox\relax
+ \else
+ \dimexpr0.5 \totalht\codebox\relax
+ \fi
+ \mbox{%
+ \mbox{\hbox to \linewidth{%
+ \hskip\pgfkeysvalueof{/forestexample/left skip}\relax
+ \textvcenter{\box\treebox}%
+ \hskip\pgfkeysvalueof{/forestexample/center skip}\relax
+ \hbox{\hskip-\@totalleftmargin\box\codebox\hskip\@totalleftmargin}%
+ \hskip\pgfkeysvalueof{/forestexample/right skip}\relax
+ }}%
+ \forestexample@label
+ }%
+ \end{list}
+ },
+ v sep/.initial={1ex},
+ align/.initial=center,
+ do layout/tree on top/.code={%
+ \begin{list}{}{\leftmargin 0pt \parsep 0pt \itemsep \pgfkeysvalueof{/forestexample/v sep}\relax}
+ \item \forestexample@align{tree}\forestexample@label
+ \item \forestexample@align{code}
+ \end{list}
+ },
+ do layout/tree on bottom/.code={%
+ \begin{list}{}{\leftmargin 0pt \parsep 0pt \itemsep \pgfkeysvalueof{/forestexample/v sep}\relax}
+ \item \forestexample@align{code}\forestexample@label
+ \item \forestexample@align{tree}
+ \end{list}
+ },
+ do layout/only tree/.code={%
+ \forestexample@align{tree}\forestexample@label
+ },
+ do layout/only code/.code={%
+ \forestexample@align{code}\forestexample@label
+ },
+}
+\newbox\treebox
+\newbox\codebox
+\def\forestexample@treebin@box{%
+ \hbox{\lst@sampleInput}%
+}
+\def\forestexample@treebin@minipage{%
+ \hbox{%
+ \begin{minipage}{\pgfkeysvalueof{/forestexample/tree width}}%
+ \lst@sampleInput
+ \end{minipage}%
+ }%
+}
+\def\forestexample@label{%
+ \pgfkeysgetvalue{/forestexample/counter}\forestexample@temp
+ \ifdefempty\forestexample@temp{}{%
+ \makebox[0pt][l]{%
+ \hskip-\linewidth
+ \hskip-\@totalleftmargin
+ \hskip\textwidth
+ \hskip\marginparsep
+ \raisebox
+ {\dimexpr\@tempdima+\depth-\pgfkeysvalueof{/forestexample/label y offset}}%
+ {\hbox to 0pt{\scriptsize(\@currentlabel)}}%
+ }%
+ }%
+}
+\def\forestexample@align#1{%
+ \pgfkeysgetvalue{/forestexample/align}\forestexample@temp
+ \mbox{\hbox to \linewidth{%
+ \csname forestexample@align@left@\forestexample@temp\endcsname
+ \hspace*{\pgfkeysvalueof{/forestexample/#1 left skip}}%
+ \mbox{\expandafter\box\csname #1box\endcsname}%
+ \hspace*{\pgfkeysvalueof{/forestexample/#1 right skip}}%
+ \csname forestexample@align@right@\forestexample@temp\endcsname
+ }}%
+}
+\def\forestexample@align@left@left{}
+\def\forestexample@align@right@left{}
+\def\forestexample@align@left@right{\hfill}
+\def\forestexample@align@right@right{}
+\def\forestexample@align@left@center{\hfill}
+\def\forestexample@align@right@center{\hfill}
+\newcommand\forestexampleimport[1][]{%
+ \def\forestexample@layout{tree on left}%
+ \pgfkeysgetvalue{/forestexample/counter}\forestexample@temp
+ \ifdefempty\forestexample@temp{}{\addtocounter{\forestexample@temp}{1}}%
+ \pgfqkeys{/forestexample}{%
+ label format,
+ do layout/.expanded=\forestexample@layout
+ }%
+}
+
+\def\totalht#1{\dimexpr\ht#1 + \dp#1\relax}
+\def\textvcenter#1{\raisebox{\dimexpr .5\depth-.5\height}{#1}}
+
+% For some reason, lstdoc's version kills all spaces in defaults ...
+\def\lst@syntaxlabel@#1>#2\relax
+ %{\edef\lst@temp{\zap@space#2 \@empty}}
+ {\edef\lst@temp{#2}}
+
+
+
+
+\def\getforestversion#1/#2/#3 v#4 #5\getforestversion{v#4}
+\edef\forestversion{%
+\expandafter\expandafter\expandafter\getforestversion
+ \csname ver@forest.sty\endcsname\getforestversion}
+
+\def\settodayfromforestdateA#1/#2/#3 v#4 #5\settodayfromforestdateA{\def\year{#1}\def\month{#2}\def\day{#3}}
+\def\settodayfromforestdate{\expandafter\expandafter\expandafter\settodayfromforestdateA\csname ver@forest.sty\endcsname\settodayfromforestdateA}
+
+\def\TikZ;{{\rm Ti\emph{k}Z}}
+\def\PGF;{\textsc{pgf}}
+\def\foRest;{\textsc{Forest}}
+\def\FoRest;{\textsc{Forest}}
+
+\let\keyname\texttt
+\newcommand\cmdname[1]{\texttt{\char\escapechar#1}}
+
+\gdef\greaterthan{>}
+\def\gobbleone#1{}
+
+\newcommand{\Repeat}[1]{% from tex.se http://tex.stackexchange.com/a/16194/16819
+ \expandafter\@Repeat\expandafter{\the\numexpr #1\relax}%
+}
+\def\@Repeat#1{%
+ \ifnum#1>0
+ \expandafter\@@Repeat\expandafter{\the\numexpr #1-1\expandafter\relax\expandafter}%
+ \else
+ \expandafter\@gobble
+ \fi
+}
+\def\@@Repeat#1#2{%
+ \@Repeat{#1}{#2}#2%
+}
+\def\spaces#1{\Repeat{#1}\space}
+
+
+%%% Local Variables:
+%%% mode: latex
+%%% fill-column: 100
+%%% TeX-command-default: "Make PDF"
+%%% TeX-master: "forest-doc"
+%%% End:
diff --git a/Master/texmf-dist/tex/latex/forest/forest-index.sty b/Master/texmf-dist/tex/latex/forest/forest-index.sty
new file mode 100644
index 00000000000..116666290c4
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/forest/forest-index.sty
@@ -0,0 +1,383 @@
+%%
+%% This is file `forest-index.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% forest-index.dtx
+%%
+%% `forest-index' is an indexing system for the documentation of package `forest', using the package itself.
+%%
+%% Copyright (c) 2015 Saso Zivanovic
+%% (Sa\v{s}o \v{Z}ivanovi\'{c})
+%% saso.zivanovic@guest.arnes.si
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% of this license or (at your option) any later version.
+%% The latest version of this license is in
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `author-maintained'.
+%%
+%% This file is a part of package `forest'. For the list of files
+%% constituting the package see main source file of the package,
+%% `forest.dtx', or the derived `forest.sty'.
+%%
+\ProvidesPackage{forest-index}
+\RequirePackage{forest}
+\let\forestindex@LaTeX@index\index
+\DeclareDocumentCommand\indexdef{O{} t> m}{%
+ \IfBooleanTF{#2}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@long}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
+ \forestindex@index{definition}{#1}{#3}}
+\DeclareDocumentCommand\indexex{O{} t> m}{%
+ \IfBooleanTF{#2}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@long}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
+ \forestindex@index{example}{#1}{#3}}
+\DeclareDocumentCommand\indexitem{D(){} O{} t> m}{%
+ \IfBooleanTF{#3}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@long}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
+ \forestindex@index{definition}{default={#1},print format=item,#2}{#4}}
+\DeclareDocumentCommand\indexset{O{} t> m}{%
+ \IfBooleanTF{#2}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@long}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
+ \forestindex@index{not print,not index,definition}{set={#1}}{#3}}
+\DeclareDocumentCommand\index{D(){} O{} t> m}{%
+ \IfBooleanTF{#3}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@long}
+ {\let\forestindex@resolvekey\forestindex@resolvekey@shortorlong}%
+ \forestindex@index{#1}{#2}{#4}%
+}
+\def\forestindex@index#1#2#3{%
+ \forcsvlist{\forestindex@forkey{#1}{#2}}{#3}%
+}
+\def\forestindex@forkey#1#2#3{%
+ \forestindex@resolvekey{#3}%
+ \forestset{@index/.process args={__o}{#1}{#2}{\forestindex@fullkey}}%
+}
+\forestset{
+ declare boolean register=print,
+ declare boolean register=index,
+ declare toks={key}{},
+ declare toks={argument}{},
+ declare toks={index key}{},
+ declare toks={index form}{},
+ declare toks={print form}{},
+ declare keylist={index key format}{},
+ declare keylist={index format}{},
+ declare keylist={print format}{},
+ declare autowrapped toks register=result,
+ format'/.style={print format'={#1}, index format'={#1}},
+ format/.style={print format={#1}, index format={#1}},
+ format+/.style={print format+={#1}, index format+={#1}},
+ +format/.style={+print format={#1}, +index format={#1}},
+ form/.style={print form={#1},index form={#1}},
+ form+/.style={print form+={#1},index form+={#1}},
+ +form/.style={+print form={#1},+index form={#1}},
+ declare toks register=index entry type,
+ definition/.style={index entry type=definition},
+ normal/.style={index entry type=normal},
+ example/.style={index entry type=example},
+ normal,
+ declare toks={index@hypertarget}{},
+ every index begin/.style={},
+ every index end/.style={},
+ declare toks register=stage,
+ @index/.style n args={3}{
+ print, index, index entry type=normal, set'={},
+ for nodewalk={
+ split={#3}{>}{create@main@entry@node, create@subentry@node},
+ if n=0{
+ content/.option=key,
+ }{
+ content/.wrap 2 pgfmath args={##1>##2}{content("!parent")}{key},
+ }
+ }{},
+ for root'={
+ for tree={
+ print form/.option=key,
+ index key/.option=key,
+ index form/.option=key,
+ },
+ for first leaf'={
+ on invalid={fake}{
+ every index begin,
+ #1,
+ },
+ for reverse={ancestors}{on invalid={fake}{@@index/\forestoption{name}/.try}},
+ if index entry type={definition}{}{%
+ on invalid={fake}{@@index/\forestoption{name}/.try},
+ },
+ on invalid={fake}{
+ #2,
+ every index end
+ },
+ if set={}{}{save@session},
+ if index entry type={definition}{save@foridx}{},
+ },
+ stage={},
+ if={index()||print()}{
+ index@hypertarget/.expanded={.\forestoption{index key}},
+ for descendants={
+ index@hypertarget/.wrap 2 pgfmath args={##1.##2}%
+ {index@hypertarget("!parent")}{index_key},
+ },
+ }{},
+ if index={
+ begingroup,
+ stage=index,
+ for tree={
+ result/.option=index key,
+ process keylist'={index key format}{current},
+ index key/.register=result,
+ },
+ for tree={
+ result/.option=index form,
+ process keylist'={index format}{current},
+ index form/.register=result,
+ },
+ where index form={}{}{
+ if n=0{
+ temptoksb={},
+ }{
+ temptoksc={},
+ for ancestors={
+ if index form={}{}{
+ temptoksb+/.expanded={\forestregister{temptoksc}%
+ \noexpand\protect\noexpand\hyperlinknocolor{%
+ \forestoption{index@hypertarget}}{\forestoption{index form}}},
+ temptoksc={,\space},
+ },
+ },
+ if temptoksb={}{}{
+ +temptoksb={\protect\space\begingroup\protect\scriptsize},
+ temptoksb+={\endgroup},
+ },
+ },
+ temptoksa={},
+ result={},
+ if n children=0{tempboola}{not tempboola},
+ where index form={}{}{
+ if tempboola={temptoksd/.expanded={\noexpand\protect\noexpand\hypertarget{%
+ \forestoption{index@hypertarget}}{}}}{temptoksd={}},
+ result+/.expanded={%
+ \forestregister{temptoksa}%
+ \forestoption{index key}%
+ =\forestoption{index form}%
+ \forestregister{temptoksd}%
+ \forestregister{temptoksb}%
+ },
+ temptoksa={>},
+ temptoksb={},
+ },
+ result+/.expanded={|indexpagenumber\forestregister{index entry type}},
+ TeX/.expanded={\noexpand\forestindex@LaTeX@index{\forestregister{result}}},
+ },
+ endgroup
+ }{},
+ if print={
+ begingroup,
+ stage=print,
+ for tree={
+ result/.option=print form,
+ process keylist'={print format}{current},
+ print form/.register=result,
+ },
+ for first leaf'={TeX={\forestoption{print form}}},
+ endgroup,
+ }{},
+ }
+ },
+ create@main@entry@node/.style={% #1 = subentry
+ set root={[]},
+ do dynamics, for root'={process delayed=tree},
+ root',
+ setup@entry@node={#1}
+ },
+ create@subentry@node/.style={
+ append={[]},
+ do dynamics, for root'={process delayed=tree},
+ n=1,
+ setup@entry@node={#1}
+ },
+ setup@entry@node/.style={
+ options={
+ split={#1}{=}{key,argument},
+ if n=0{
+ name'/.option=key,
+ content={#1},
+ }{
+ name'/.wrap 2 pgfmath args={##1>##2}{name("!parent")}{key},
+ content/.wrap pgfmath arg={##1>#1}{content("!parent")},
+ },
+ }
+ },
+}
+\forestset{
+ declare keylist register=set,
+ Autoforward register={set}{##1},
+ save@session/.style={@@index/\forestoption{name}/.global style/.register=set},
+ save@foridx/.style={
+ if={strequal(name("!root"),"@unknown")}{}{
+ if set={}{}{
+ TeX={%
+ \immediate\write\forestindex@out{%
+ \string\indexloadsettings{\forestoption{name}}{\forestregister{set}}%
+ }%
+ },
+ },
+ if={strequal(key(),content())}{}{
+ TeX={%
+ \immediate\write\forestindex@out{%
+ \string\indexdefineshortkey{\forestoption{key}}{\forestoption{content}}%
+ }%
+ }
+ }
+ }
+ },
+}
+\def\indexloadsettings#1#2{%
+ \pgfkeysifdefined{/forest/@@index/#1/.@cmd}{%
+ \forestindex@loadsettings@warning{#1}%
+ }{}%
+ \forestset{@@index/#1/.global style={#2}}%
+}
+\def\forestindex@loadsettings@warning#1{%
+ \PackageWarning{forest-index}{Forest index key "#1" was configured more than once!
+ I'm using the last configuration.}%
+}
+\def\indexdefineshortkey#1#2{%
+ \def\forestindex@temp@short{#1}%
+ \def\forestindex@temp@long{#2}%
+ \ifx\forestindex@temp@short\forestindex@temp@long
+ \else
+ \ifcsdef{index@long@#1}{%
+ \global\cslet{index@long@#1}\relax
+ \csgappto{index@alllong@#1}{,#2}%
+ }{%
+ \global\csgdef{index@long@#1}{#2}%
+ \global\csgdef{index@alllong@#1}{#2}%
+ }%
+ \fi
+}
+\def\forestindex@resolvekey@long#1{\def\forestindex@fullkey{#1}}
+\def\forestindex@resolvekey@shortorlong#1{%
+ \pgfutil@in@>{#1}%
+ \ifpgfutil@in@
+ \expandafter\def\expandafter\forestindex@fullkey
+ \else
+ \expandafter\forestindex@resolvekey@short
+ \fi
+ {#1}%
+}
+\def\forestindex@resolvekey@short#1{%
+ \forestset{split={#1}{=}{index@resolveshortkey@key,index@resolveshortkey@arg}}%
+}
+\forestset{
+ index@resolveshortkey@key/.code={%
+ \ifcsvoid{index@long@#1}{%
+ \forestindex@resolveshortkey@warning{#1}%
+ \def\forestindex@fullkey{@unknown>#1}%
+ }{%
+ \letcs\forestindex@fullkey{index@long@#1}%
+ }%
+ },
+ index@resolveshortkey@arg/.code={%
+ \appto\forestindex@fullkey{=#1}%
+ },
+}
+\def\forestindex@resolveshortkey@warning#1{%
+ \PackageWarning{forest-index}{Cannot resolve short forest index key "#1".
+ These are the definitions I found (from the previous run):
+ "\csuse{index@alllong@#1}"}%
+}
+\forestset{
+ normal color/.initial=blue,
+ definition color/.initial=red,
+ example color/.initial=darkgreen,
+ print in color/.style={if stage={print}{result=\protect\textcolor{%
+ \pgfkeysvalueof{/forest/#1 color}}{##1}}{}},
+ print in color/.default=\forestregister{index entry type},
+ hyper/.style={
+ if stage={index}{}{
+ if index entry type={definition}{
+ result/.expanded={\noexpand\hypertarget{\forestoption{name}}%
+ {\noexpand\hyperlink{\forestoption{index@hypertarget}}{\forestregister{result}}}}
+ }{
+ result/.expanded=\noexpand\hyperlink{\forestoption{name}}{\forestregister{result}}
+ }
+ }
+ },
+}
+\ifdef\hyperpage{%
+ \newcommand\indexpagenumbernormal[1]{{%
+ \hypersetup{linkcolor=\pgfkeysvalueof{/forest/normal color}}\hyperpage{#1}}}
+ \newcommand\indexpagenumberdefinition[1]{{%
+ \hypersetup{linkcolor=\pgfkeysvalueof{/forest/definition color}}\hyperpage{#1}}}
+ \newcommand\indexpagenumberexample[1]{{%
+ \hypersetup{linkcolor=\pgfkeysvalueof{/forest/example color}}\hyperpage{#1}}}
+}{
+ \newcommand\indexpagenumbernormal[1]{%
+ \textcolor{\pgfkeysvalueof{/forest/normal color}}{#1}}
+ \newcommand\indexpagenumberdefinition[1]{%
+ \textcolor{\pgfkeysvalueof{/forest/definition color}}{#1}}
+ \newcommand\indexpagenumberexample[1]{%
+ \textcolor{\pgfkeysvalueof{/forest/example color}}{#1}}
+}
+\providecommand\hyperlink[2]{#2}
+\providecommand\hypertarget[2]{#2}
+\providecommand\hypersetup[1]{}
+\newcommand\hyperlinknocolor[2]{{\hypersetup{linkcolor=black}\hyperlink{#1}{#2}}}
+\forestset{
+ declare toks register=default,
+ default={},
+ item/.style={result/.wrap 4 pgfmath args={%
+ \item[,##2,##3]{##4}%
+ }{}{default}{print_form("!parent")}{result},
+ },
+}
+\pgfkeys{/handlers/.global style/.code=\pgfkeys{\pgfkeyscurrentpath/.global code=\pgfkeysalso{#1}}}
+\pgfkeysdef{/handlers/.global code}{\pgfkeysglobaldef{\pgfkeyscurrentpath}{#1}}
+\long\def\pgfkeysglobaldef#1#2{%
+ \long\def\pgfkeys@temp##1\pgfeov{#2}%
+ \pgfkeysgloballet{#1/.@cmd}{\pgfkeys@temp}%
+ \pgfkeysglobalsetvalue{#1/.@body}{#2}%
+}
+\def\pgfkeysgloballet#1#2{%
+ \expandafter\global\expandafter\let\csname pgfk@#1\endcsname#2%
+}
+\long\def\pgfkeysglobalsetvalue#1#2{%
+ \pgfkeys@temptoks{#2}\expandafter\xdef\csname pgfk@#1\endcsname{\the\pgfkeys@temptoks}%
+}
+\forestset{
+ begingroup/.code={\begingroup},
+ endgroup/.code={\endgroup},
+}
+\index(not print,not index)[%
+ set={
+ index key=unknown,
+ form={\textbf{unknown!!}},
+ for first={format={result/.expanded=\noexpand\textbf{\forestregister{result}??}}}
+ },
+ ]>{@unknown}
+\def\forestindex@filename{\jobname.foridx}
+\IfFileExists{\forestindex@filename}{%
+ \input\forestindex@filename
+}{}%
+\newwrite\forestindex@out
+\immediate\openout\forestindex@out=\forestindex@filename
+\AtEndDocument{%
+ \immediate\closeout\forestindex@out
+}
+\endinput
+%%
+%% End of file `forest-index.sty'.
diff --git a/Master/texmf-dist/tex/latex/forest/forest-lib-edges.sty b/Master/texmf-dist/tex/latex/forest/forest-lib-edges.sty
new file mode 100644
index 00000000000..5c737aabfeb
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/forest/forest-lib-edges.sty
@@ -0,0 +1,74 @@
+%%
+%% This is file `forest-lib-edges.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% forest-libs.dtx (with options: `edges')
+%%
+%% `forest-libs' is a collection of libraries for package `forest'.
+%%
+%% Copyright (c) 2015 Saso Zivanovic
+%% (Sa\v{s}o \v{Z}ivanovi\'{c})
+%% saso.zivanovic@guest.arnes.si
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% of this license or (at your option) any later version.
+%% The latest version of this license is in
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `author-maintained'.
+%%
+%% This file is a part of package `forest'. For the list of files
+%% constituting the package see main source file of the package,
+%% `forest.dtx', or the derived `forest.sty'.
+%%
+\RequirePackage{forest}
+\ProvidesForestLibrary{edges}[2015/11/14 v0.1]
+\forestset{
+ declare dimen={fork sep}{0.5em},
+ forked edge/.style={
+ edge={rotate/.pgfmath=grow()},
+ edge path'={(!u.parent anchor) -- ++(\forestoption{fork sep},0) |- (.child anchor)},
+ },
+ forked edges/.style={
+ for tree={parent anchor=children},
+ for descendants={child anchor=parent,forked edge}
+ },
+}
+\forestset{
+ declare dimen register=folder indent,
+ folder indent=.45em,
+ folder/.style={
+ parent anchor=parent last,
+ anchor=parent first,
+ calign=child,
+ calign primary child=1,
+ for children={
+ child anchor=parent,
+ anchor=parent first,
+ edge={rotate/.pgfmath=grow()},
+ edge path'/.expanded={
+ ([xshift=\forestregister{folder indent}]!u.parent anchor) |- (.child anchor)
+ },
+ },
+ after packing node={
+ if n children=0{}{
+ tempdiml=l_sep()-l("!1"),
+ tempdims={-abs(max_s("","")-min_s("",""))-s_sep()},
+ for children={
+ l+=tempdiml,
+ s+=tempdims()*(reversed()-0.5)*2,
+ },
+ },
+ },
+ }
+}
+\endinput
+%%
+%% End of file `forest-lib-edges.sty'.
diff --git a/Master/texmf-dist/tex/latex/forest/forest-lib-linguistics.sty b/Master/texmf-dist/tex/latex/forest/forest-lib-linguistics.sty
new file mode 100644
index 00000000000..9632361e964
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/forest/forest-lib-linguistics.sty
@@ -0,0 +1,133 @@
+%%
+%% This is file `forest-lib-linguistics.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% forest-libs.dtx (with options: `linguistics')
+%%
+%% `forest-libs' is a collection of libraries for package `forest'.
+%%
+%% Copyright (c) 2015 Saso Zivanovic
+%% (Sa\v{s}o \v{Z}ivanovi\'{c})
+%% saso.zivanovic@guest.arnes.si
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either version 1.3
+%% of this license or (at your option) any later version.
+%% The latest version of this license is in
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of LaTeX
+%% version 2005/12/01 or later.
+%%
+%% This work has the LPPL maintenance status `author-maintained'.
+%%
+%% This file is a part of package `forest'. For the list of files
+%% constituting the package see main source file of the package,
+%% `forest.dtx', or the derived `forest.sty'.
+%%
+\RequirePackage{forest}
+\ProvidesForestLibrary{linguistics}[2015/11/14 v0.1]
+\forestset{
+ libraries/linguistics/defaults/.style={
+ default preamble={
+ sn edges,
+ baseline,
+ for tree={align=center},
+ },
+ },
+}
+\forestset{
+ define long step={c-commanded}{style}{branch'={siblings,descendants}},
+ define long step={c-commanders}{style}{while nodewalk valid={parent}{siblings,fake=parent}},
+}
+\forestset{
+ sn edges/.style={
+ for tree={
+ parent anchor=children, child anchor=parent
+ }
+ },
+}
+\forestset{
+ roof/.style={edge path'={%
+ (.parent first)--(!u.children)--(.parent last)--cycle
+ }
+ },
+}
+\forestset{
+ nice empty nodes/.style={
+ for tree={calign=fixed edge angles},
+ delay={where content={}{shape=coordinate,for parent={
+ for children={anchor=north}}}{}}
+ },
+}
+\providecommand\text[1]{\mbox{\scriptsize#1}}
+\forestset{
+ draw brackets compact/.code={\let\drawbracketsspace\relax},
+ draw brackets wide/.code={\let\drawbracketsspace\space},
+ draw brackets/.style={
+ for tree'={
+ TeX={[%
+ \edef\forestdrawbracketscontentformat{\foresteoption{content format}}%
+ },
+ if n children=0{
+ TeX={\drawbracketsspace\forestdrawbracketscontentformat\drawbracketsspace}
+ }{
+ TeX={\textsubscript{\text{\forestdrawbracketscontentformat}}\drawbracketsspace}
+ },
+ }{
+ TeX={]\drawbracketsspace},
+ }
+ },
+ draw brackets wide
+}
+\newbox\standardnodestrutbox
+\setbox\standardnodestrutbox=\hbox to 0pt{\phantom{\forestOve{standard node}{content}}}
+\def\standardnodestrut{\copy\standardnodestrutbox}
+\forestset{
+ GP1/.style 2 args={
+ for n={1}{baseline},
+ s sep=0pt, l sep=0pt,
+ for descendants={
+ l sep=0pt, l={#1},
+ anchor=base,calign=first,child anchor=north,
+ inner xsep=1pt,inner ysep=2pt,outer sep=0pt,s sep=0pt,
+ },
+ delay={
+ if content={}{phantom}{for children={no edge}},
+ for tree={
+ if content={O}{tier=OR}{},
+ if content={R}{tier=OR}{},
+ if content={N}{tier=N}{},
+ if content={x}{
+ tier=x,content={$\times$},outer xsep={#2},
+ for tree={calign=center},
+ for descendants={content format={\noexpand\standardnodestrut\forestoption{content}}},
+ before drawing tree={outer xsep=0pt,delay={typeset node}},
+ s sep=4pt
+ }{},
+ },
+ },
+ before drawing tree={where content={}{parent anchor=center,child anchor=center}{}},
+ },
+ GP1/.default={5ex}{8.0pt},
+ associate/.style={%
+ tikz+={\draw[densely dotted](!)--(!#1);}},
+ spread/.style={
+ before drawing tree={tikz+={\draw[dotted](!)--(!#1);}}},
+ govern/.style={
+ before drawing tree={tikz+={\draw[->](!)--(!#1);}}},
+ p-govern/.style={
+ before drawing tree={tikz+={\draw[->](.north) to[out=150,in=30] (!#1.north);}}},
+ no p-govern/.style={
+ before drawing tree={tikz+={\draw[->,loosely dashed](.north) to[out=150,in=30] (!#1.north);}}},
+ encircle/.style={before drawing tree={circle,draw,inner sep=0pt}},
+ fen/.style={pin={[font=\footnotesize,inner sep=1pt,pin edge=<-]10:\textsc{Fen}}},
+ el/.style={content=\textsc{\textbf{##1}}},
+ head/.style={content=\textsc{\textbf{\underline{##1}}}}
+}
+\endinput
+%%
+%% End of file `forest-lib-linguistics.sty'.
diff --git a/Master/texmf-dist/tex/latex/forest/forest.sty b/Master/texmf-dist/tex/latex/forest/forest.sty
index bcba9acc8b8..6fdbb025c1b 100644
--- a/Master/texmf-dist/tex/latex/forest/forest.sty
+++ b/Master/texmf-dist/tex/latex/forest/forest.sty
@@ -22,16 +22,31 @@
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
-%% This work has the LPPL maintenance status `maintained'.
+%% This work has the LPPL maintenance status `author-maintained'.
%%
-%% The Current Maintainer of this work is Saso Zivanovic.
+%% This work consists of the following files:
+%% - forest.dtx: central sources (with rudimentary implementation documentation)
+%% - forest-libs.dtx: sources and documentation for libraries
+%% + forest-compat.sty: sources/runtime for compatibility mode
+%% - forest.ins: produces derived runtime .sty files
+%% + forest.sty: main package
+%% + forest-lib-*.sty: libraries (for the list, see forest.ins)
+%% - forest-doc.tex: central documentation
+%% - forest-doc.sty: private package needed to compile the documentation
+%% - forest-index.dtx: sources of indexing package used in the documentation,
+%% and also part of the documentation itself
+%% - forest-doc.ins: produces derived .sty files needed to compile the documentation
+%% - forest-index.sty
+%% - forest-doc.ist: index style file needed to compile the documentation
+%% - forest.pdf: documentation of core package implementation
+%% - forest-doc.pdf: user's guide
+%% - README
+%% - LICENCE
+%% To use the package, only the files marked with + need to be installed.
%%
-%% This work consists of the files forest.dtx and forest.ins
-%% and the derived file forest.sty.
-%%
-\ProvidesPackage{forest}[2015/07/15 v1.0.10 Drawing (linguistic) trees]
+\ProvidesPackage{forest}[2015/01/30 v2.0.0 Drawing (linguistic) trees]
-\RequirePackage{tikz}[2010/10/13]
+\RequirePackage{tikz}[2013/12/13]
\usetikzlibrary{shapes}
\usetikzlibrary{fit}
\usetikzlibrary{calc}
@@ -41,255 +56,65 @@
\RequirePackage{etoolbox}[2010/08/21]
\RequirePackage{elocalloc}% for \locbox
\RequirePackage{environ}
+\RequirePackage{xparse}
+
- %\usepackage[trace]{trace-pgfkeys}
\pgfkeys{/forest/.is family}
\def\forestset#1{\pgfqkeys{/forest}{#1}}
-\long\def\forest@original@pgfkeysdefnargs@#1#2#3#4{%
- \ifcase#2\relax
- \pgfkeyssetvalue{#1/.@args}{}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8##9}%
- \else
- \pgfkeys@error{\string\pgfkeysdefnargs: expected <= 9 arguments, got #2}%
- \fi
- \pgfkeysgetvalue{#1/.@args}\pgfkeys@tempargs
- \def\pgfkeys@temp{\expandafter#4\csname pgfk@#1/.@@body\endcsname}%
- \expandafter\pgfkeys@temp\pgfkeys@tempargs{#3}%
- % eliminate the \pgfeov at the end such that TeX gobbles spaces
- % by using
- % \pgfkeysdef{#1}{\pgfkeysvalueof{#1/.@@body}##1}
- % (with expansion of '#1'):
- \edef\pgfkeys@tempargs{\noexpand\pgfkeysvalueof{#1/.@@body}}%
- \def\pgfkeys@temp{\pgfkeysdef{#1}}%
- \expandafter\pgfkeys@temp\expandafter{\pgfkeys@tempargs##1}%
- \pgfkeyssetvalue{#1/.@body}{#3}%
+\newif\ifforest@external@
+\newif\ifforesttikzcshack
+\newif\ifforest@install@keys@to@tikz@path@
+\newif\ifforestdebug
+\def\forest@compat{}
+\forestset{package@options/.cd,
+ external/.is if=forest@external@,
+ tikzcshack/.is if=foresttikzcshack,
+ tikzinstallkeys/.is if=forest@install@keys@to@tikz@path@,
+ debug/.is if=forestdebug,
+ compat/.store in=\forest@compat,
+ compat/.default=most,
+ .unknown/.code={% load library
+ \eappto\forest@loadlibrarieslater{%
+ \noexpand\useforestlibrary{\pgfkeyscurrentname}%
+ \noexpand\forestapplylibrarydefaults{\pgfkeyscurrentname}%
+ }%
+ },
}
-
-\long\def\forest@patched@pgfkeysdefnargs@#1#2#3#4{%
- \ifcase#2\relax
- \pgfkeyssetvalue{#1/.@args}{}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
- %%%%% removed:
- %%%%% \or
- %%%%% \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8}%
- \or
- \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8##9}%
- \else
- \pgfkeys@error{\string\pgfkeysdefnargs: expected <= 9 arguments, got #2}%
- \fi
- \pgfkeysgetvalue{#1/.@args}\pgfkeys@tempargs
- \def\pgfkeys@temp{\expandafter#4\csname pgfk@#1/.@@body\endcsname}%
- \expandafter\pgfkeys@temp\pgfkeys@tempargs{#3}%
- % eliminate the \pgfeov at the end such that TeX gobbles spaces
- % by using
- % \pgfkeysdef{#1}{\pgfkeysvalueof{#1/.@@body}##1}
- % (with expansion of '#1'):
- \edef\pgfkeys@tempargs{\noexpand\pgfkeysvalueof{#1/.@@body}}%
- \def\pgfkeys@temp{\pgfkeysdef{#1}}%
- \expandafter\pgfkeys@temp\expandafter{\pgfkeys@tempargs##1}%
- \pgfkeyssetvalue{#1/.@body}{#3}%
-}
-\ifx\pgfkeysdefnargs@\forest@original@pgfkeysdefnargs@
- \let\pgfkeysdefnargs@\forest@patched@pgfkeysdefnargs@
-\fi
-\def\forest@original@pgfpointintersectionoflines#1#2#3#4{%
- {
- %
- % Compute orthogonal vector to #1--#2
- %
- \pgf@process{#2}%
- \pgf@xa=\pgf@x%
- \pgf@ya=\pgf@y%
- \pgf@process{#1}%
- \advance\pgf@xa by-\pgf@x%
- \advance\pgf@ya by-\pgf@y%
- \pgf@ya=-\pgf@ya%
- % Normalise a bit
- \c@pgf@counta=\pgf@xa%
- \ifnum\c@pgf@counta<0\relax%
- \c@pgf@counta=-\c@pgf@counta\relax%
- \fi%
- \c@pgf@countb=\pgf@ya%
- \ifnum\c@pgf@countb<0\relax%
- \c@pgf@countb=-\c@pgf@countb\relax%
- \fi%
- \advance\c@pgf@counta by\c@pgf@countb\relax%
- \divide\c@pgf@counta by 65536\relax%
- \ifnum\c@pgf@counta>0\relax%
- \divide\pgf@xa by\c@pgf@counta\relax%
- \divide\pgf@ya by\c@pgf@counta\relax%
- \fi%
- %
- % Compute projection
- %
- \pgf@xc=\pgf@sys@tonumber{\pgf@ya}\pgf@x%
- \advance\pgf@xc by\pgf@sys@tonumber{\pgf@xa}\pgf@y%
- %
- % The orthogonal vector is (\pgf@ya,\pgf@xa)
- %
- %
- % Compute orthogonal vector to #3--#4
- %
- \pgf@process{#4}%
- \pgf@xb=\pgf@x%
- \pgf@yb=\pgf@y%
- \pgf@process{#3}%
- \advance\pgf@xb by-\pgf@x%
- \advance\pgf@yb by-\pgf@y%
- \pgf@yb=-\pgf@yb%
- % Normalise a bit
- \c@pgf@counta=\pgf@xb%
- \ifnum\c@pgf@counta<0\relax%
- \c@pgf@counta=-\c@pgf@counta\relax%
- \fi%
- \c@pgf@countb=\pgf@yb%
- \ifnum\c@pgf@countb<0\relax%
- \c@pgf@countb=-\c@pgf@countb\relax%
- \fi%
- \advance\c@pgf@counta by\c@pgf@countb\relax%
- \divide\c@pgf@counta by 65536\relax%
- \ifnum\c@pgf@counta>0\relax%
- \divide\pgf@xb by\c@pgf@counta\relax%
- \divide\pgf@yb by\c@pgf@counta\relax%
- \fi%
- %
- % Compute projection
- %
- \pgf@yc=\pgf@sys@tonumber{\pgf@yb}\pgf@x%
- \advance\pgf@yc by\pgf@sys@tonumber{\pgf@xb}\pgf@y%
- %
- % The orthogonal vector is (\pgf@yb,\pgf@xb)
- %
- % Setup transformation matrx (this is just to use the matrix
- % inversion)
- %
- \pgfsettransform{{\pgf@sys@tonumber\pgf@ya}{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@xa}{\pgf@sys@tonumber\pgf@xb}{0pt}{0pt}}%
- \pgftransforminvert%
- \pgf@process{\pgfpointtransformed{\pgfpoint{\pgf@xc}{\pgf@yc}}}%
+\forest@install@keys@to@tikz@path@true
+\foresttikzcshacktrue
+\def\forest@loadlibrarieslater{}
+\AtEndOfPackage{\forest@loadlibrarieslater}
+\def\useforestlibrary#1{\forcsvlist\useforestlibrary@{#1}}
+\def\useforestlibrary@#1{\RequirePackage{forest-lib-#1}}
+\def\forestapplylibrarydefaults#1{\forcsvlist\forestapplylibrarydefaults@{#1}}
+\def\forestapplylibrarydefaults@#1{\forestset{libraries/#1/defaults/.try}}
+\NewDocumentCommand\ProvidesForestLibrary{m O{}}{\ProvidesPackage{forest-lib-#1}[#2]}
+\ProcessPgfPackageOptions{/forest/package@options}
+\def\forest@patch#1#2#3#4#5{%
+ % #1 = cs to be patched
+ % %2 = purpose of the patch
+ % #3 = macro arguments
+ % #4 = original code
+ % #5 = patched code
+ \csdef{forest@original@#1}#3{#4}%
+ \csdef{forest@patched@#1}#3{#5}%
+ \ifcsequal{#1}{forest@original@#1}{%
+ \csletcs{#1}{forest@patched@#1}%
+ }{%
+ \ifcsequal{#1}{forest@patched@#1}{% all is good, the patch is in!
+ }{%
+ \PackageWarning{forest}{Failed patching '\expandafter\string\csname #1\endcsname'. Purpose of the patch: #2}%
+ }%
}%
}
-\def\forest@patched@pgfpointintersectionoflines#1#2#3#4{%
- {% added the percent sign in this line
- %
- % Compute orthogonal vector to #1--#2
- %
- \pgf@process{#2}%
- \pgf@xa=\pgf@x%
- \pgf@ya=\pgf@y%
- \pgf@process{#1}%
- \advance\pgf@xa by-\pgf@x%
- \advance\pgf@ya by-\pgf@y%
- \pgf@ya=-\pgf@ya%
- % Normalise a bit
- \c@pgf@counta=\pgf@xa%
- \ifnum\c@pgf@counta<0\relax%
- \c@pgf@counta=-\c@pgf@counta\relax%
- \fi%
- \c@pgf@countb=\pgf@ya%
- \ifnum\c@pgf@countb<0\relax%
- \c@pgf@countb=-\c@pgf@countb\relax%
- \fi%
- \advance\c@pgf@counta by\c@pgf@countb\relax%
- \divide\c@pgf@counta by 65536\relax%
- \ifnum\c@pgf@counta>0\relax%
- \divide\pgf@xa by\c@pgf@counta\relax%
- \divide\pgf@ya by\c@pgf@counta\relax%
- \fi%
- %
- % Compute projection
- %
- \pgf@xc=\pgf@sys@tonumber{\pgf@ya}\pgf@x%
- \advance\pgf@xc by\pgf@sys@tonumber{\pgf@xa}\pgf@y%
- %
- % The orthogonal vector is (\pgf@ya,\pgf@xa)
- %
- %
- % Compute orthogonal vector to #3--#4
- %
- \pgf@process{#4}%
- \pgf@xb=\pgf@x%
- \pgf@yb=\pgf@y%
- \pgf@process{#3}%
- \advance\pgf@xb by-\pgf@x%
- \advance\pgf@yb by-\pgf@y%
- \pgf@yb=-\pgf@yb%
- % Normalise a bit
- \c@pgf@counta=\pgf@xb%
- \ifnum\c@pgf@counta<0\relax%
- \c@pgf@counta=-\c@pgf@counta\relax%
- \fi%
- \c@pgf@countb=\pgf@yb%
- \ifnum\c@pgf@countb<0\relax%
- \c@pgf@countb=-\c@pgf@countb\relax%
- \fi%
- \advance\c@pgf@counta by\c@pgf@countb\relax%
- \divide\c@pgf@counta by 65536\relax%
- \ifnum\c@pgf@counta>0\relax%
- \divide\pgf@xb by\c@pgf@counta\relax%
- \divide\pgf@yb by\c@pgf@counta\relax%
- \fi%
- %
- % Compute projection
- %
- \pgf@yc=\pgf@sys@tonumber{\pgf@yb}\pgf@x%
- \advance\pgf@yc by\pgf@sys@tonumber{\pgf@xb}\pgf@y%
- %
- % The orthogonal vector is (\pgf@yb,\pgf@xb)
- %
- % Setup transformation matrx (this is just to use the matrix
- % inversion)
- %
- \pgfsettransform{{\pgf@sys@tonumber\pgf@ya}{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@xa}{\pgf@sys@tonumber\pgf@xb}{0pt}{0pt}}%
- \pgftransforminvert%
- \pgf@process{\pgfpointtransformed{\pgfpoint{\pgf@xc}{\pgf@yc}}}%
- }%
+\forest@patch{pgfgettransform}{fix a leaking space}{#1}{%
+ \edef#1{{\pgf@pt@aa}{\pgf@pt@ab}{\pgf@pt@ba}{\pgf@pt@bb}{\the\pgf@pt@x}{\the\pgf@pt@y}}
+}{%
+ \edef#1{{\pgf@pt@aa}{\pgf@pt@ab}{\pgf@pt@ba}{\pgf@pt@bb}{\the\pgf@pt@x}{\the\pgf@pt@y}}%
}
-
-\ifx\pgfpointintersectionoflines\forest@original@pgfpointintersectionoflines
- \let\pgfpointintersectionoflines\forest@patched@pgfpointintersectionoflines
-\fi
-
- % hah: hacking forest --- it depends on some details of PGF implementation
-\def\forest@pgf@notyetpositioned{not yet positionedPGFINTERNAL}%
-\expandafter\ifstrequal\expandafter{\pgfversion}{2.10}{%
- \def\forest@pgf@notyetpositioned{not yet positioned@}%
-}{}
\long\def\@escapeif#1#2\fi{\fi#1}
\long\def\@escapeifif#1#2\fi#3\fi{\fi\fi#1}
+\long\def\@escapeififif#1#2\fi#3\fi#4\fi{\fi\fi\fi#1}
\def\newloop#1{%
\count@=\escapechar
\escapechar=-1
@@ -309,17 +134,66 @@
}%
}%
}%
+\def\newsafeloop#1{%
+ \csdef{safeloop@#1}##1\saferepeat{%
+ \edef\safeloop@marshal{%
+ \noexpand\csdef{safeiterate@#1}{%
+ \unexpanded{##1}\relax
+ \noexpand\expandafter
+ \expandonce{\csname safeiterate@#1\endcsname}%
+ \noexpand\fi
+ }%
+ }\safeloop@marshal
+ \csuse{safeiterate@#1}%
+ \advance\noexpand\safeloop@depth-1\relax
+ \cslet{safeiterate@#1}\relax
+ }%
+}%
+\newcount\safeloop@depth
+\def\safeloop{%
+ \advance\safeloop@depth1
+ \ifcsdef{safeloop@\the\safeloop@depth}{}{\expandafter\newsafeloop\expandafter{\the\safeloop@depth}}%
+ \csdef{safeloopn@\the\safeloop@depth}{0}%
+ \csuse{safeloop@\the\safeloop@depth}%
+ \csedef{safeloopn@\the\safeloop@depth}{\number\numexpr\csuse{safeloopn@\the\safeloop@depth}+1}%
+}
+\let\saferepeat\fi
+\def\safeloopn{\csuse{safeloopn@\the\safeloop@depth}}%
+\def\newsafeRKloop#1{%
+ \csdef{safeRKloop@#1}##1\safeRKrepeat{%
+ \edef\safeRKloop@marshal{%
+ \noexpand\csdef{safeRKiterate@#1}{%
+ \unexpanded{##1}\relax
+ \noexpand\expandafter
+ \expandonce{\csname safeRKiterate@#1\endcsname}%
+ \noexpand\fi
+ }%
+ }\safeRKloop@marshal
+ \csuse{safeRKiterate@#1}%
+ \advance\noexpand\safeRKloop@depth-1\relax
+ \cslet{safeRKiterate@#1}\relax
+ }%
+ \expandafter\newif\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
+}%
+\newcount\safeRKloop@depth
+\def\safeRKloop{%
+ \advance\safeRKloop@depth1
+ \ifcsdef{safeRKloop@\the\safeRKloop@depth}{}{\expandafter\newsafeRKloop\expandafter{\the\safeRKloop@depth}}%
+ \csdef{safeRKloopn@\the\safeRKloop@depth}{0}%
+ \csuse{safeRKbreak@\the\safeRKloop@depth false}%
+ \csuse{safeRKloop@\the\safeRKloop@depth}%
+ \csedef{safeRKloopn@\the\safeRKloop@depth}{\number\numexpr\csuse{safeRKloopn@\the\safeRKloop@depth}+1}%
+}
+\let\safeRKrepeat\fi
+\def\safeRKloopn{\csuse{safeRKloopn@\the\safeRKloop@depth}}%
\newloop\forest@loop
-\newloop\forest@loopa
-\newloop\forest@loopb
-\newloop\forest@loopc
-\newloop\forest@sort@loop
-\newloop\forest@sort@loopA
\newdimen\forest@temp@dimen
\newcount\forest@temp@count
\newcount\forest@n
\newif\ifforest@temp
\newcount\forest@temp@global@count
+\newtoks\forest@temp@toks
+\def\etotoks#1#2{\edef\pot@temp{#2}\expandafter#1\expandafter{\pot@temp}}
\def\apptotoks#1#2{\expandafter#1\expandafter{\the#1#2}}
\long\def\lapptotoks#1#2{\expandafter#1\expandafter{\the#1#2}}
\def\eapptotoks#1#2{\edef\pot@temp{#2}\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter#1\pot@temp}}
@@ -415,6 +289,153 @@
\def\forest@strip@braces@A#1#2\forest@strip@braces@end{%
#1\ifx\forest@strip@braces@preend#2\else\@escapeif{\forest@strip@braces@A#2\forest@strip@braces@end}\fi
}
+\def\forest@copycommandkey#1#2{% copies command of #1 into #2
+ \pgfkeysifdefined{#1/.@cmd}{}{%
+ \PackageError{forest}{Key #1 is not a command key}{}%
+ }%
+ \pgfkeysgetvalue{#1/.@cmd}\forest@temp
+ \pgfkeyslet{#2/.@cmd}\forest@temp
+ \pgfkeysifdefined{#1/.@args}{%
+ \pgfkeysgetvalue{#1/.@args}\forest@temp
+ \pgfkeyslet{#2/.@args}\forest@temp
+ }{}%
+ \pgfkeysifdefined{#1/.@body}{%
+ \pgfkeysgetvalue{#1/.@body}\forest@temp
+ \pgfkeyslet{#2/.@body}\forest@temp
+ }{}%
+ \pgfkeysifdefined{#1/.@@body}{%
+ \pgfkeysgetvalue{#1/.@@body}\forest@temp
+ \pgfkeyslet{#2/.@@body}\forest@temp
+ }{}%
+ \pgfkeysifdefined{#1/.@def}{%
+ \pgfkeysgetvalue{#1/.@def}\forest@temp
+ \pgfkeyslet{#2/.@def}\forest@temp
+ }{}%
+}
+\forestset{
+ copy command key/.code 2 args={\forest@copycommandkey{#1}{#2}},
+ autoforward/.code 2 args={\forest@autoforward{#1}{#2={#1={##1}}}{true}},
+ autoforward'/.code 2 args={\forest@autoforward{#1}{#2-=#1,#2={#1={##1}}}{true}},
+ Autoforward/.code 2 args={\forest@autoforward{#1}{#2}{true}},
+ autoforward register/.code 2 args={\forest@autoforward{#1}{#2={#1={##1}}}{false}},
+ autoforward register'/.code 2 args={\forest@autoforward{#1}{#2-=#1,#2={#1={##1}}}{false}},
+ Autoforward register/.code 2 args={\forest@autoforward{#1}{#2}{false}},
+ copy command key@if it exists/.code 2 args={%
+ \pgfkeysifdefined{#1/.@cmd}{%
+ \forest@copycommandkey{#1}{#2}%
+ }{}%
+ },
+ unautoforward/.style={
+ typeout={unautoforwarding #1},
+ copy command key@if it exists={/forest/autoforwarded #1}{/forest/#1},
+ copy command key@if it exists={/forest/autoforwarded #1+}{/forest/#1+},
+ copy command key@if it exists={/forest/autoforwarded #1-}{/forest/#1-},
+ copy command key@if it exists={/forest/autoforwarded #1*}{/forest/#1*},
+ copy command key@if it exists={/forest/autoforwarded #1:}{/forest/#1:},
+ copy command key@if it exists={/forest/autoforwarded #1'}{/forest/#1'},
+ copy command key@if it exists={/forest/autoforwarded #1+'}{/forest/#1+'},
+ copy command key@if it exists={/forest/autoforwarded #1-'}{/forest/#1-'},
+ copy command key@if it exists={/forest/autoforwarded #1*'}{/forest/#1*'},
+ copy command key@if it exists={/forest/autoforwarded #1:'}{/forest/#1:'},
+ copy command key@if it exists={/forest/autoforwarded +#1}{/forest/+#1},
+ },
+ /handlers/.undef/.code={\csundef{pgfk@\pgfkeyscurrentpath}},
+ undef option/.style={
+ /forest/#1/.undef,
+ /forest/#1/.@cmd/.undef,
+ /forest/#1+/.@cmd/.undef,
+ /forest/#1-/.@cmd/.undef,
+ /forest/#1*/.@cmd/.undef,
+ /forest/#1:/.@cmd/.undef,
+ /forest/#1'/.@cmd/.undef,
+ /forest/#1+'/.@cmd/.undef,
+ /forest/#1-'/.@cmd/.undef,
+ /forest/#1*'/.@cmd/.undef,
+ /forest/#1:'/.@cmd/.undef,
+ /forest/+#1/.@cmd/.undef,
+ /forest/TeX={\patchcmd{\forest@node@init}{\forestoinit{#1}}{}{}{}},
+ },
+ undef register/.style={undef option={#1}},
+}
+\def\forest@autoforward#1#2#3{%
+ % #1 = option name
+ % #2 = code of a style taking one arg (new option value),
+ % which expands to whatever should be done with the new value
+ % autoforward(') adds to the keylist (arg#2)
+ % #3 = true=option, false=register
+ \forest@autoforward@createforwarder{}{#1}{}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{+}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{-}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{*}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{:}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{'}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{+'}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{-'}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{*'}{#2}{#3}%
+ \forest@autoforward@createforwarder{}{#1}{:'}{#2}{#3}%
+ \forest@autoforward@createforwarder{+}{#1}{}{#2}{#3}%
+}
+\def\forest@autoforward@createforwarder#1#2#3#4#5{%
+ % #1=prefix, #2=option name, #3=suffix, #4=macro code (#2 above), #5=option or register
+ \pgfkeysifdefined{/forest/#1#2#3/.@cmd}{%
+ \forest@copycommandkey{/forest/#1#2#3}{/forest/autoforwarded #1#2#3}%
+ \pgfkeyssetvalue{/forest/autoforwarded #1#2#3/option@name}{#2}%
+ \pgfkeysdef{/forest/#1#2#3}{%
+ \pgfkeysalso{autoforwarded #1#2#3={##1}}%
+ \def\forest@temp@macro####1{#4}%
+ \csname forest@temp#5\endcsname
+ \edef\forest@temp@value{\ifforest@temp\expandafter\forestOv\expandafter{\expandafter\forest@setter@node\expandafter}\else\expandafter\forestrv\fi{#2}}%
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\pgfkeysalso\expandafter\expandafter\expandafter{\expandafter\forest@temp@macro\expandafter{\forest@temp@value}}%
+ }%
+ }{}%
+}
+\def\forest@node@removekeysfromkeylist#1#2{% #1 = keys to remove, #2 = option name
+ \edef\forest@marshal{%
+ \noexpand\forest@removekeysfromkeylist{\unexpanded{#1}}{\forestov{#2}}\noexpand\forest@temp@toks}\forest@marshal
+ \forestoeset{#2}{\the\forest@temp@toks}%
+}
+\def\forest@removekeysfromkeylist#1#2#3{%
+ % #1 = keys to remove (a keylist: an empty value means remove a key with any value)
+ % #2 = keylist
+ % #3 = toks cs for result
+ \forest@temp@toks{}%
+ \def\forestnovalue{\forestnovalue}%
+ \pgfqkeys{/forest/remove@key@installer}{#1}%
+ \let\forestnovalue\pgfkeysnovaluetext
+ \pgfqkeys{/forest/remove@key}{#2}%
+ \pgfqkeys{/forest/remove@key@uninstaller}{#1}%
+ #3\forest@temp@toks
+}
+\def\forest@remove@key@novalue{\forest@remove@key@novalue}%
+\forestset{
+ remove@key@installer/.unknown/.code={% #1 = (outer) value
+ \def\forest@temp{#1}%
+ \ifx\forest@temp\pgfkeysnovalue@text
+ \pgfkeysdef{/forest/remove@key/\pgfkeyscurrentname}{}%
+ \else
+ \ifx\forest@temp\forestnovalue
+ \expandafter\forest@remove@key@installer@defwithvalue\expandafter{\pgfkeyscurrentname}{\pgfkeysnovalue}%
+ \else
+ \expandafter\forest@remove@key@installer@defwithvalue\expandafter{\pgfkeyscurrentname}{#1}%
+ \fi
+ \fi
+ },
+ remove@key/.unknown/.code={% #1 = (inner) value
+ \expandafter\apptotoks\expandafter\forest@temp@toks\expandafter{\pgfkeyscurrentname={#1},}%
+ },
+ remove@key@uninstaller/.unknown/.code={%
+ \pgfkeyslet{/forest/remove@key/\pgfkeyscurrentname/.@cmd}\@undefined},
+}
+\def\forest@remove@key@installer@defwithvalue#1#2{% #1=key name, #2 = outer value
+ \pgfkeysdef{/forest/remove@key/#1}{% ##1 = inner value
+ \def\forest@temp@outer{#2}%
+ \def\forest@temp@inner{##1}%
+ \ifx\forest@temp@outer\forest@temp@inner
+ \else
+ \apptotoks\forest@temp@toks{#1={##1},}%
+ \fi
+ }%
+}
\def\forest@sort#1#2#3#4#5{%
\let\forest@sort@cmp#1\relax
\let\forest@sort@let#2\relax
@@ -450,6 +471,8 @@
sort}{The macro must take two arguments, indices of the array:
element 2 must be copied onto element 1.}%
}
+\newloop\forest@sort@loop
+\newloop\forest@sort@loopA
\def\forest@quicksort#1#2{%
\forest@sort@m=#2
\advance\forest@sort@m -#1
@@ -493,10 +516,11 @@
}%
\forest@sort@marshal
}
+\def\forest@sort@aux{aux}
\def\forest@sort@xch#1#2{%
- \forest@sort@let{aux}{#1}%
+ \forest@sort@let{\forest@sort@aux}{#1}%
\forest@sort@let{#1}{#2}%
- \forest@sort@let{#2}{aux}%
+ \forest@sort@let{#2}{\forest@sort@aux}%
}
\def\forest@insertionsort#1#2{%
\forest@sort@m=#1
@@ -509,7 +533,7 @@
}
\newif\ifforest@insertionsort@loop
\def\forest@insertionsort@Qbody{%
- \forest@sort@let{aux}{\the\forest@sort@m}%
+ \forest@sort@let{\forest@sort@aux}{\the\forest@sort@m}%
\forest@sort@k\forest@sort@m
\advance\forest@sort@k -1
\forest@insertionsort@looptrue
@@ -518,10 +542,10 @@
\forest@insertionsort@qbody
\forest@sort@repeat
\advance\forest@sort@k 1
- \forest@sort@let{\the\forest@sort@k}{aux}%
+ \forest@sort@let{\the\forest@sort@k}{\forest@sort@aux}%
}
\def\forest@insertionsort@qbody{%
- \forest@sort@cmp{\the\forest@sort@k}{aux}%
+ \forest@sort@cmp{\the\forest@sort@k}{\forest@sort@aux}%
\ifx\forest@sort@direction\forest@sort@cmp@result\relax
\forest@sort@p=\forest@sort@k
\advance\forest@sort@p 1
@@ -580,12 +604,12 @@
\c@pgf@countc=#2
\c@pgf@countd=#3
\advance\c@pgf@countd -1
- \forest@loopa
+ \safeloop
\ifnum\c@pgf@countc<\c@pgf@countd\relax
\forest@sort@xch{\the\c@pgf@countc}{\the\c@pgf@countd}%
\advance\c@pgf@countc 1
\advance\c@pgf@countd -1
- \forest@repeata
+ \saferepeat
}
\def\bracketset#1{\pgfqkeys{/bracket}{#1}}%
\bracketset{%
@@ -599,9 +623,9 @@
action character,
new node/.code n args={3}{% #1=preamble, #2=node spec, #3=cs receiving the id
\forest@node@new#3%
- \forestOset{#3}{given options}{content'=#2}%
+ \forestOeset{#3}{given options}{\forest@contentto=\unexpanded{#2}}%
\ifblank{#1}{}{%
- \forestOpreto{#3}{given options}{#1,}%
+ \forestrset{preamble}{#1}%
}%
},
set afterthought/.code 2 args={% #1=node id, #2=afterthought
@@ -837,9 +861,14 @@
% full expansion expands all the way
\def\forestove#1{\pgfkeysvalueof{/forest/@node/\forest@cn/#1}}
% full expansion expands to the cs holding the value
-\def\forestom#1{\expandafter\expandonce\expandafter{\pgfkeysvalueof{/forest/@node/\forest@cn/#1}}}\def\forestoget#1#2{\pgfkeysgetvalue{/forest/@node/\forest@cn/#1}{#2}}
+\def\forestom#1{\expandafter\expandonce\expandafter{\pgfkeysvalueof{/forest/@node/\forest@cn/#1}}}
\def\forestoget#1#2{\pgfkeysgetvalue{/forest/@node/\forest@cn/#1}{#2}}
\def\forestolet#1#2{\pgfkeyslet{/forest/@node/\forest@cn/#1}{#2}}
+\def\forestocslet#1#2{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeyslet{/forest/@node/\forest@cn/#1}{\expandonce{\csname#2\endcsname}}%
+ }\forest@marshal
+}
\def\forestoset#1#2{\pgfkeyssetvalue{/forest/@node/\forest@cn/#1}{#2}}
\def\forestoeset#1#2{%
\edef\forest@option@temp{%
@@ -862,6 +891,11 @@
\def\forestOget#1#2#3{\pgfkeysgetvalue{/forest/@node/#1/#2}{#3}}
\def\forestOget#1#2#3{\pgfkeysgetvalue{/forest/@node/#1/#2}{#3}}
\def\forestOlet#1#2#3{\pgfkeyslet{/forest/@node/#1/#2}{#3}}
+\def\forestOcslet#1#2#3{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeyslet{/forest/@node/#1/#2}{\expandonce{\csname#3\endcsname}}%
+ }\forest@marshal
+}
\def\forestOset#1#2#3{\pgfkeyssetvalue{/forest/@node/#1/#2}{#3}}
\def\forestOeset#1#2#3{%
\edef\forestoption@temp{%
@@ -895,6 +929,37 @@
\def\forestoleto#1#2{%
\forestoget{#2}\forestoption@temp
\forestolet{#1}\forestoption@temp}
+ % full expansion expands precisely to the value
+\def\forestrv#1{\expandafter\expandafter\expandafter\expandonce
+ \pgfkeysvalueof{/forest/@node/register/#1}}
+ % full expansion expands all the way
+\def\forestrve#1{\pgfkeysvalueof{/forest/@node/register/#1}}
+ % full expansion expands to the cs holding the value
+\def\forestrm#1{\expandafter\expandonce\expandafter{\pgfkeysvalueof{/forest/@node/register/#1}}}
+\def\forestrget#1#2{\pgfkeysgetvalue{/forest/@node/register/#1}{#2}}
+\def\forestrlet#1#2{\pgfkeyslet{/forest/@node/register/#1}{#2}}
+\def\forestrcslet#1#2{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeyslet{/forest/@node/register/#1}{\expandonce{\csname#2\endcsname}}%
+ }\forest@marshal
+}
+\def\forestrset#1#2{\pgfkeyssetvalue{/forest/@node/register/#1}{#2}}
+\def\forestreset#1#2{%
+ \edef\forest@option@temp{%
+ \noexpand\pgfkeyssetvalue{/forest/@node/register/#1}{#2}%
+ }\forest@option@temp
+}
+\def\forestrappto#1#2{%
+ \forestreset{#1}{\forestrv{#1}\unexpanded{#2}}%
+}
+\def\forestrpreto#1#2{%
+ \forestreset{#1}{\unexpanded{#2}\forestrv{#1}}%
+}
+\def\forestrifdefined#1#2#3{%
+ \pgfkeysifdefined{/forest/@node/register/#1}{#2}{#3}%
+}
+\def\forestregister#1{\forestrv{#1}}
+\def\foresteregister#1{\forestrve{#1}}
\def\forest@node@init{%
\forestoset{@parent}{0}%
\forestoset{@previous}{0}% previous sibling
@@ -919,7 +984,7 @@
\let\forestoinit@orig\forestoinit
\def\forest@node@copy#1#2{% #1=from node id, cs receiving the new node id
\advance\forest@node@maxid1
- \def\forestoinit##1{\forestoletO{##1}{#1}{##1}}%
+ \def\forestoinit##1{\ifstrequal{##1}{name}{\forestoset{name}{node@\forest@cn}}{\forestoletO{##1}{#1}{##1}}}%
\forest@fornode{\the\forest@node@maxid}{%
\forest@node@init
\forest@node@setname{\forest@copy@name@template{\forestOve{#1}{name}}}%
@@ -1039,13 +1104,6 @@
\edef\forest@node@marshal{\edef\noexpand\forest@cn{#1}\unexpanded{#2}\def\noexpand\forest@cn}%
\expandafter\forest@node@marshal\expandafter{\forest@cn}%
}
-\def\forest@fornode@ifexists#1#2{%
- \edef\forest@node@temp{#1}%
- \ifnum\forest@node@temp=0
- \else
- \@escapeif{\expandnumberarg\forest@fornode{\forest@node@temp}{#2}}%
- \fi
-}
\def\forest@node@foreachchild#1{\forest@node@Foreachchild{\forest@cn}{#1}}
\def\forest@node@Foreachchild#1#2{%
\forest@fornode{\forestOve{#1}{@first}}{\forest@node@@forselfandfollowingsiblings{#2}}%
@@ -1060,30 +1118,176 @@
}%
\fi
}
-\def\forest@node@foreach#1{\forest@node@Foreach{\forest@cn}{#1}}
-\def\forest@node@Foreach#1#2{%
- \forest@fornode{#1}{\forest@node@@foreach{#2}}%
+\def\forest@node@@forselfandfollowingsiblings@reversed#1{%
+ \ifnum\forest@cn=0
+ \else
+ \@escapeif{%
+ \edef\forest@marshal{%
+ \noexpand\def\noexpand\forest@cn{\forestove{@next}}%
+ \noexpand\forest@node@@forselfandfollowingsiblings@reversed{\unexpanded{#1}}%
+ \noexpand\forest@fornode{\forest@cn}{\unexpanded{#1}}%
+ }\forest@marshal
+ }%
+ \fi
}
-\def\forest@node@@foreach#1{%
- \forest@forthis{#1}%
- \ifnum\forestove{@first}=0
- \else\@escapeif{%
- \edef\forest@cn{\forestove{@first}}%
- \forest@node@@forselfandfollowingsiblings{\forest@node@@foreach{#1}}%
+\def\forest@node@foreachchild@reversed#1{\forest@node@Foreachchild@reversed{\forest@cn}{#1}}
+\def\forest@node@Foreachchild@reversed#1#2{%
+ \forest@fornode{\forestOve{#1}{@last}}{\forest@node@@forselfandprecedingsiblings@reversed{#2}}%
+}
+\def\forest@node@@forselfandprecedingsiblings@reversed#1{%
+ \ifnum\forest@cn=0
+ \else
+ \forest@forthis{#1}%
+ \@escapeif{%
+ \edef\forest@cn{\forestove{@previous}}%
+ \forest@node@@forselfandprecedingsiblings@reversed{#1}%
}%
\fi
}
-\def\forest@node@foreachdescendant#1{\forest@node@Foreachdescendant{\forest@cn}{#1}}
+\def\forest@node@@forselfandprecedingsiblings#1{%
+ \ifnum\forest@cn=0
+ \else
+ \@escapeif{%
+ \edef\forest@marshal{%
+ \noexpand\def\noexpand\forest@cn{\forestove{@previous}}%
+ \noexpand\forest@node@@forselfandprecedingsiblings{\unexpanded{#1}}%
+ \noexpand\forest@fornode{\forest@cn}{\unexpanded{#1}}%
+ }\forest@marshal
+ }%
+ \fi
+}
+\def\forest@node@@foreach#1#2#3#4{%
+ % #1 = do what
+ % #2 = do that -1=before,1=after processing children
+ % #3 & #4: normal or reversed order of children?
+ % #3 = @first/@last
+ % #4 = \forest@node@@forselfandfollowingsiblings / \forest@node@@forselfandprecedingsiblings@reversed
+ \ifnum#2<0 \forest@forthis{#1}\fi
+ \ifnum\forestove{#3}=0
+ \else\@escapeif{%
+ \forest@forthis{%
+ \edef\forest@cn{\forestove{#3}}%
+ #4{\forest@node@@foreach{#1}{#2}{#3}{#4}}%
+ }%
+ }\fi
+ \ifnum#2>0 \forest@forthis{#1}\fi
+}
+\def\forest@node@foreach#1{%
+ \forest@node@@foreach{#1}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}
+\def\forest@node@Foreach#1#2{%
+ \forest@fornode{#1}{\forest@node@@foreach{#2}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
+\def\forest@node@foreach@reversed#1{%
+ \forest@node@@foreach{#1}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}
+\def\forest@node@Foreach@reversed#1#2{%
+ \forest@fornode{#1}{\forest@node@@foreach{#2}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@foreach@childrenfirst#1{%
+ \forest@node@@foreach{#1}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}
+\def\forest@node@Foreach@childrenfirst#1#2{%
+ \forest@fornode{#1}{\forest@node@@foreach{#2}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
+\def\forest@node@foreach@childrenfirst@reversed#1{%
+ \forest@node@@foreach{#1}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}
+\def\forest@node@Foreach@childrenfirst@reversed#1#2{%
+ \forest@fornode{#1}{\forest@node@@foreach{#2}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@foreachdescendant#1{%
+ \forest@node@foreachchild{\forest@node@@foreach{#1}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
\def\forest@node@Foreachdescendant#1#2{%
- \forest@node@Foreachchild{#1}{%
- \forest@node@foreach{#2}%
+ \forest@node@Foreachchild{#1}{\forest@node@@foreach{#2}{-1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
+\def\forest@node@foreachdescendant@reversed#1{%
+ \forest@node@foreachchild@reversed{\forest@node@@foreach{#1}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@Foreachdescendant@reversed#1#2{%
+ \forest@node@Foreachchild@reversed{#1}{\forest@node@@foreach{#2}{-1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@foreachdescendant@childrenfirst#1{%
+ \forest@node@foreachchild{\forest@node@@foreach{#1}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
+\def\forest@node@Foreachdescendant@childrenfirst#1#2{%
+ \forest@node@Foreachchild{#1}{\forest@node@@foreach{#2}{1}{@first}{\forest@node@@forselfandfollowingsiblings}}}
+\def\forest@node@foreachdescendant@childrenfirst@reversed#1{%
+ \forest@node@foreachchild@reversed{\forest@node@@foreach{#1}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@Foreachdescendant@childrenfirst@reversed#1#2{%
+ \forest@node@Foreachchild@reversed{#1}{\forest@node@@foreach{#2}{1}{@last}{\forest@node@@forselfandprecedingsiblings@reversed}}}
+\def\forest@node@foreach@breadthfirst#1#2{% #1 = max level, #2 = code
+ \forest@node@Foreach@breadthfirst@{\forest@cn}{@first}{@next}{#1}{#2}}
+\def\forest@node@foreach@breadthfirst@reversed#1#2{% #1 = max level, #2 = code
+ \forest@node@Foreach@breadthfirst@{\forest@cn}{@last}{@previous}{#1}{#2}}
+\def\forest@node@Foreach@breadthfirst#1#2#3{% #1 = node id, #2 = max level, #3 = code
+ \forest@node@Foreach@breadthfirst@{#1}{@first}{@next}{#2}{#3}}
+\def\forest@node@Foreach@breadthfirst@reversed#1#2#3{% #1 = node id, #2 = max level, #3 = code
+ \forest@node@Foreach@breadthfirst@{#1}{@last}{@previous}{#2}{#3}}
+\def\forest@node@Foreach@breadthfirst@#1#2#3#4#5{%
+ % #1 = root node,
+ % #2 = @first/@last, #3 = @next/@previous (must be in sync with #2),
+ % #4 = max level (< 0 means infinite)
+ % #5 = code to execute at each node
+ \forest@node@Foreach@breadthfirst@processqueue{#1,}{#2}{#3}{#4}{#5}%
+}
+\def\forest@node@Foreach@breadthfirst@processqueue#1#2#3#4#5{%
+ % #1 = queue,
+ % #2 = @first/@last, #3 = @next/@previous (must be in sync with #2),
+ % #4 = max level (< 0 means infinite)
+ % #5 = code to execute at each node
+ \ifstrempty{#1}{}{%
+ \forest@node@Foreach@breadthfirst@processqueue@#1\forest@node@Foreach@breadthfirst@processqueue@
+ {#2}{#3}{#4}{#5}%
+ }%
+}
+\def\forest@node@Foreach@breadthfirst@processqueue@#1,#2\forest@node@Foreach@breadthfirst@processqueue@#3#4#5#6{%
+ % #1 = first,
+ % #2 = rest,
+ % #3 = @first/@last, #4 = next/previous (must be in sync with #2),
+ % #5 = max level (< 0 means infinite)
+ % #6 = code to execute at each node
+ \forest@fornode{#1}{%
+ #6%
+ \ifnum#5<0
+ \forest@node@getlistofchildren\forest@temp{#3}{#4}%
+ \else
+ \ifnum\forestove{level}>#5\relax
+ \def\forest@temp{}%
+ \else
+ \forest@node@getlistofchildren\forest@temp{#3}{#4}%
+ \fi
+ \fi
+ \edef\forest@marshal{%
+ \noexpand\forest@node@Foreach@breadthfirst@processqueue{\unexpanded{#2}\forest@temp}%
+ {#3}{#4}{#5}{\unexpanded{#6}}%
+ }\forest@marshal
}%
}
+\def\forest@node@getlistofchildren#1#2#3{% #1 = list cs, #2 = @first/@last, #3 = @next/@previous
+ \forest@node@Getlistofchildren{\forest@cn}{#1}{#2}{#3}%
+}
+\def\forest@node@Getlistofchildren#1#2#3#4{% #1 = node, #2 = list cs, #3 = @first/@last, #4 = @next/@previous
+ \def#2{}%
+ \ifnum\forestove{#3}=0
+ \else
+ \eappto#2{\forestOve{#1}{#3},}%
+ \@escapeif{%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@Getlistofchildren@{\forestOve{#1}{#3}}\noexpand#2{#4}%
+ }\forest@marshal
+ }%
+ \fi
+}
+\def\forest@node@Getlistofchildren@#1#2#3{% #1 = node, #2 = list cs, #3 = @next/@previous
+ \ifnum\forestOve{#1}{#3}=0
+ \else
+ \eappto#2{\forestOve{#1}{#3},}%
+ \@escapeif{%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@Getlistofchildren@{\forestOve{#1}{#3}}\noexpand#2{#3}%
+ }\forest@marshal
+ }%
+ \fi
+}
\def\forest@node@Compute@numeric@ts@info@#1{%
\forest@node@Foreach{#1}{\forest@node@@compute@numeric@ts@info}%
\ifnum\forestOve{#1}{@parent}=0
\else
- \fornode{#1}{\forest@node@@compute@numeric@ts@info@nbar}%
+ \forest@fornode{#1}{\forest@node@@compute@numeric@ts@info@nbar}%
+ % hack: the parent of the node we called the update for gets +1 for n_children
+ \edef\forest@node@temp{\forestOve{#1}{@parent}}%
+ \forestOeset{\forest@node@temp}{n children}{%
+ \number\numexpr\forestOve{\forest@node@temp}{n children}-1%
+ }%
\fi
\forest@node@Foreachdescendant{#1}{\forest@node@@compute@numeric@ts@info@nbar}%
}
@@ -1226,6 +1430,7 @@
\@escapeif{\expandnumberarg\forest@node@nextleafid@Godown{\forestOve{#1}{@first}}}%
\fi
}
+
\def\forest@node@linearnextid{%
\ifnum\forestove{@first}=0
\expandafter\forest@node@linearnextnotdescendantid
@@ -1238,11 +1443,16 @@
}
\def\forest@node@Linearnextnotdescendantid#1{%
\ifnum\forestOve{#1}{@next}=0
- \@escapeif{\expandnumberarg\forest@node@Linearnextnotdescendantid{\forestOve{#1}{@parent}}}%
+ \ifnum\forestOve{#1}{@parent}=0
+ 0%
+ \else
+ \@escapeifif{\expandnumberarg\forest@node@Linearnextnotdescendantid{\forestOve{#1}{@parent}}}%
+ \fi
\else
\forestOve{#1}{@next}%
\fi
}
+
\def\forest@node@linearpreviousid{%
\ifnum\forestove{@previous}=0
\forestove{@parent}%
@@ -1265,201 +1475,10 @@
\fi
\forest@ifancestorof@next{#2}{#3}%
}
-\newloop\forest@nodewalk@loop
-\forestset{
- @handlers@save@currentpath/.code={%
- \edef\pgfkeyscurrentkey{\pgfkeyscurrentpath}%
- \let\forest@currentkey\pgfkeyscurrentkey
- \pgfkeys@split@path
- \edef\forest@currentpath{\pgfkeyscurrentpath}%
- \let\forest@currentname\pgfkeyscurrentname
- },
- /handlers/.step 0 args/.style={
- /forest/@handlers@save@currentpath,
- \forest@currentkey/.code={#1\forestset{node walk/every step}},
- /forest/for \forest@currentname/.style/.expanded={%
- for={\forest@currentname}{####1}%
- }
- },
- /handlers/.step 1 arg/.style={%
- /forest/@handlers@save@currentpath,
- \forest@currentkey/.code={#1\forestset{node walk/every step}},
- /forest/for \forest@currentname/.style 2 args/.expanded={%
- for={\forest@currentname=####1}{####2}%
- }
- },
- node walk/.code={%
- \forestset{%
- node walk/before walk,%
- node walk/.cd,
- #1,%
- /forest/.cd,
- node walk/after walk
- }%
- },
- for/.code 2 args={%
- \forest@forthis{%
- \pgfkeysalso{%
- node walk/before walk/.style={},%
- node walk/every step/.style={},%
- node walk/after walk/.style={/forest,if id=0{}{#2}},%
- %node walk/after walk/.style={#2},%
- node walk={#1}%
- }%
- }%
- },
- node walk/.cd,
- before walk/.code={},
- every step/.code={},
- after walk/.code={},
- current/.step 0 args={},
- current/.default=1,
- next/.step 0 args={\edef\forest@cn{\forestove{@next}}},
- next/.default=1,
- previous/.step 0 args={\edef\forest@cn{\forestove{@previous}}},
- previous/.default=1,
- parent/.step 0 args={\edef\forest@cn{\forestove{@parent}}},
- parent/.default=1,
- first/.step 0 args={\edef\forest@cn{\forestove{@first}}},
- first/.default=1,
- last/.step 0 args={\edef\forest@cn{\forestove{@last}}},
- last/.default=1,
- n/.step 1 arg={%
- \def\forest@nodewalk@temp{#1}%
- \ifx\forest@nodewalk@temp\pgfkeysnovalue@text
- \edef\forest@cn{\forestove{@next}}%
- \else
- \edef\forest@cn{\forest@node@nthchildid{#1}}%
- \fi
- },
- n'/.step 1 arg={\edef\forest@cn{\forest@node@nbarthchildid{#1}}},
- sibling/.step 0 args={%
- \edef\forest@cn{%
- \ifnum\forestove{@previous}=0
- \forestove{@next}%
- \else
- \forestove{@previous}%
- \fi
- }%
- },
- previous leaf/.step 0 args={\edef\forest@cn{\forest@node@previousleafid}},
- previous leaf/.default=1,
- next leaf/.step 0 args={\edef\forest@cn{\forest@node@nextleafid}},
- next leaf/.default=1,
- linear next/.step 0 args={\edef\forest@cn{\forest@node@linearnextid}},
- linear previous/.step 0 args={\edef\forest@cn{\forest@node@linearpreviousid}},
- first leaf/.step 0 args={%
- \forest@nodewalk@loop
- \edef\forest@cn{\forestove{@first}}%
- \unless\ifnum\forestove{@first}=0
- \forest@nodewalk@repeat
- },
- last leaf/.step 0 args={%
- \forest@nodewalk@loop
- \edef\forest@cn{\forestove{@last}}%
- \unless\ifnum\forestove{@last}=0
- \forest@nodewalk@repeat
- },
- to tier/.step 1 arg={%
- \def\forest@nodewalk@giventier{#1}%
- \forest@nodewalk@loop
- \forestoget{tier}\forest@nodewalk@tier
- \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
- \forestoget{@parent}\forest@cn
- \forest@nodewalk@repeat
- },
- next on tier/.step 0 args={\forest@nodewalk@nextontier},
- next on tier/.default=1,
- previous on tier/.step 0 args={\forest@nodewalk@previousontier},
- previous on tier/.default=1,
- name/.step 1 arg={\edef\forest@cn{\forest@node@Nametoid{#1}}},
- root/.step 0 args={\edef\forest@cn{\forest@node@rootid}},
- root'/.step 0 args={\edef\forest@cn{\forest@root}},
- id/.step 1 arg={\edef\forest@cn{#1}},
- % maybe it's not wise to have short-step sequences and names potentially clashing
- % .unknown/.code={%
- % \forest@node@Ifnamedefined{\pgfkeyscurrentname}%
- % {\pgfkeysalso{name=\pgfkeyscurrentname}}%
- % {\expandafter\forest@nodewalk@shortsteps\pgfkeyscurrentname\forest@nodewalk@endshortsteps}%
- % },
- .unknown/.code={%
- \expandafter\forest@nodewalk@shortsteps\pgfkeyscurrentname\forest@nodewalk@endshortsteps
- },
- node walk/.style={/forest/node walk={#1}},
- trip/.code={\forest@forthis{\pgfkeysalso{#1}}},
- group/.code={\forest@go{#1}\forestset{node walk/every step}},
- % repeat is taken later from /forest/repeat
- p/.style={previous=1},
- %n/.style={next=1}, % defined in "long" n
- u/.style={parent=1},
- s/.style={sibling},
- c/.style={current=1},
- r/.style={root},
- P/.style={previous leaf=1},
- N/.style={next leaf=1},
- F/.style={first leaf=1},
- L/.style={last leaf=1},
- >/.style={next on tier=1},
- </.style={previous on tier=1},
- 1/.style={n=1},
- 2/.style={n=2},
- 3/.style={n=3},
- 4/.style={n=4},
- 5/.style={n=5},
- 6/.style={n=6},
- 7/.style={n=7},
- 8/.style={n=8},
- 9/.style={n=9},
- l/.style={last=1},
- %{...} is short for group={...}
-}
-\def\forest@nodewalk@nextontier{%
- \forestoget{tier}\forest@nodewalk@giventier
- \edef\forest@cn{\forest@node@linearnextnotdescendantid}%
- \forest@nodewalk@loop
- \forestoget{tier}\forest@nodewalk@tier
- \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
- \edef\forest@cn{\forest@node@linearnextid}%
- \forest@nodewalk@repeat
-}
-\def\forest@nodewalk@previousontier{%
- \forestoget{tier}\forest@nodewalk@giventier
- \forest@nodewalk@loop
- \edef\forest@cn{\forest@node@linearpreviousid}%
- \forestoget{tier}\forest@nodewalk@tier
- \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
- \forest@nodewalk@repeat
-}
-\def\forest@nodewalk@shortsteps{%
- \futurelet\forest@nodewalk@nexttoken\forest@nodewalk@shortsteps@
-}
-\def\forest@nodewalk@shortsteps@#1{%
- \ifx\forest@nodewalk@nexttoken\forest@nodewalk@endshortsteps
- \else
- \ifx\forest@nodewalk@nexttoken\bgroup
- \pgfkeysalso{group=#1}%
- \@escapeifif\forest@nodewalk@shortsteps
- \else
- \pgfkeysalso{#1}%
- \@escapeifif\forest@nodewalk@shortsteps
- \fi
- \fi
-}
-\def\forest@go#1{%
- {%
- \forestset{%
- node walk/before walk/.code={},%
- node walk/every step/.code={},%
- node walk/after walk/.code={},%
- node walk={#1}%
- }%
- \expandafter
- }%
- \expandafter\def\expandafter\forest@cn\expandafter{\forest@cn}%
-}
\def\forest@declarehandler#1#2#3{%#1=handler for specific type,#2=option name,#3=default value
\pgfkeyssetvalue{/forest/#2}{#3}%
\appto\forest@node@init{\forestoinit{#2}}%
+ \pgfkeyssetvalue{/forest/#2/node@or@reg}{\forest@cn}%
\forest@convert@others@to@underscores{#2}\forest@pgfmathoptionname
\edef\forest@marshal{%
\noexpand#1{/forest/#2}{/forest}{#2}{\forest@pgfmathoptionname}%
@@ -1468,23 +1487,25 @@
\def\forest@def@with@pgfeov#1#2{% \pgfeov mustn't occur in the arg of the .code handler!!!
\long\def#1##1\pgfeov{#2}%
}
-\newtoks\forest@temp@toks
-\def\forest@declaretoks@handler#1#2#3#4{%
+\def\forest@declaretoks@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
\forest@declaretoks@handler@A{#1}{#2}{#3}{#4}{}%
}
-\def\forest@declarekeylist@handler#1#2#3#4{%
+\def\forest@declarekeylist@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
\forest@declaretoks@handler@A{#1}{#2}{#3}{#4}{,}%
- \pgfkeysgetvalue{#1/.@cmd}\forest@temp
- \pgfkeyslet{#1'/.@cmd}\forest@temp
+ \forest@copycommandkey{#1}{#1'}%
\pgfkeyssetvalue{#1'/option@name}{#3}%
- \pgfkeysgetvalue{#1+/.@cmd}\forest@temp
- \pgfkeyslet{#1/.@cmd}\forest@temp
- }
+ \forest@copycommandkey{#1+}{#1}%
+ \pgfkeysalso{#1-/.code={%
+ \forest@fornode{\forest@setter@node}{%
+ \forest@node@removekeysfromkeylist{##1}{#3}%
+ }}}%
+ \pgfkeyssetvalue{#1-/option@name}{#3}%
+}
\def\forest@declaretoks@handler@A#1#2#3#4#5{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
\pgfkeysalso{%
#1/.code={\forestOset{\forest@setter@node}{#3}{##1}},
#1+/.code={\forestOappto{\forest@setter@node}{#3}{#5##1}},
- #1-/.code={\forestOpreto{\forest@setter@node}{#3}{##1#5}},
+ #2/+#3/.code={\forestOpreto{\forest@setter@node}{#3}{##1#5}},
#2/if #3/.code n args={3}{%
\forestoget{#3}\forest@temp@option@value
\edef\forest@temp@compared@value{\unexpanded{##1}}%
@@ -1509,22 +1530,20 @@
}%
\pgfkeyssetvalue{#1/option@name}{#3}%
\pgfkeyssetvalue{#1+/option@name}{#3}%
+ \pgfkeyssetvalue{#2/+#3/option@name}{#3}%
\pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@toks{##1}{#3}}%
}
\def\forest@declareautowrappedtoks@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
\forest@declaretoks@handler{#1}{#2}{#3}{#4}%
- \pgfkeysgetvalue{#1/.@cmd}\forest@temp
- \pgfkeyslet{#1'/.@cmd}\forest@temp
+ \forest@copycommandkey{#1}{#1'}%
\pgfkeysalso{#1/.style={#1'/.wrap value={##1}}}%
\pgfkeyssetvalue{#1'/option@name}{#3}%
- \pgfkeysgetvalue{#1+/.@cmd}\forest@temp
- \pgfkeyslet{#1+'/.@cmd}\forest@temp
+ \forest@copycommandkey{#1+}{#1+'}%
\pgfkeysalso{#1+/.style={#1+'/.wrap value={##1}}}%
\pgfkeyssetvalue{#1+'/option@name}{#3}%
- \pgfkeysgetvalue{#1-/.@cmd}\forest@temp
- \pgfkeyslet{#1-'/.@cmd}\forest@temp
- \pgfkeysalso{#1-/.style={#1-'/.wrap value={##1}}}%
- \pgfkeyssetvalue{#1-'/option@name}{#3}%
+ \forest@copycommandkey{#2/+#3}{#2/+#3'}%
+ \pgfkeysalso{#2/+#3/.style={#2/+#3'/.wrap value={##1}}}%
+ \pgfkeyssetvalue{#2/+#3'/option@name}{#3}%
}
\def\forest@declarereadonlydimen@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
\pgfkeysalso{%
@@ -1623,25 +1642,25 @@
\forestOlet{\forest@setter@node}{#3}\forest@temp
},
#1+/.code={%
- \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfmathtruncatemacro\forest@temp{##1}%
\c@pgf@counta=\forestove{#3}\relax
\advance\c@pgf@counta\forest@temp\relax
\forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
},
#1-/.code={%
- \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfmathtruncatemacro\forest@temp{##1}%
\c@pgf@counta=\forestove{#3}\relax
\advance\c@pgf@counta-\forest@temp\relax
\forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
},
#1*/.code={%
- \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfmathtruncatemacro\forest@temp{##1}%
\c@pgf@counta=\forestove{#3}\relax
\multiply\c@pgf@counta\forest@temp\relax
\forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
},
#1:/.code={%
- \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfmathtruncatemacro\forest@temp{##1}%
\c@pgf@counta=\forestove{#3}\relax
\divide\c@pgf@counta\forest@temp\relax
\forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
@@ -1688,8 +1707,12 @@
\ifstrequal{##1}{1}{%
\forestOset{\forest@setter@node}{#3}{1}%
}{%
- \pgfmathifthenelse{##1}{1}{0}%
- \forestOlet{\forest@setter@node}{#3}\pgfmathresult
+ \ifstrequal{##1}{0}{%
+ \forestOset{\forest@setter@node}{#3}{0}%
+ }{%
+ \pgfmathifthenelse{##1}{1}{0}%
+ \forestOlet{\forest@setter@node}{#3}\pgfmathresult
+ }%
}%
},
#1/.default=1,
@@ -1707,7 +1730,7 @@
\pgfkeyssetvalue{#1/option@name}{#3}%
\pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@count{##1}{#3}}%
}
-\pgfkeys{/forest,
+\forestset{
declare toks/.code 2 args={%
\forest@declarehandler\forest@declaretoks@handler{#1}{#2}%
},
@@ -1732,6 +1755,12 @@
declare boolean/.code 2 args={%
\forest@declarehandler\forest@declareboolean@handler{#1}{#2}%
},
+ /handlers/.restore default value/.code={%
+ \edef\forest@handlers@currentpath{\pgfkeyscurrentpath}%
+ \pgfkeysgetvalue{\pgfkeyscurrentpath/option@name}\forest@currentoptionname
+ \pgfkeysgetvalue{/forest/\forest@currentoptionname}\forest@temp
+ \expandafter\pgfkeysalso\expandafter{\forest@handlers@currentpath/.expand once=\forest@temp}%
+ },
/handlers/.pgfmath/.code={%
\pgfmathparse{#1}%
\pgfkeysalso{\pgfkeyscurrentpath/.expand once=\pgfmathresult}%
@@ -1739,11 +1768,21 @@
/handlers/.wrap value/.code={%
\edef\forest@handlers@wrap@currentpath{\pgfkeyscurrentpath}%
\pgfkeysgetvalue{\forest@handlers@wrap@currentpath/option@name}\forest@currentoptionname
- \expandafter\forestoget\expandafter{\forest@currentoptionname}\forest@option@value
+ \forestOget{\pgfkeysvalueof{/forest/\forest@currentoptionname/node@or@reg}}{\forest@currentoptionname}\forest@option@value
\forest@def@with@pgfeov\forest@wrap@code{#1}%
\expandafter\edef\expandafter\forest@wrapped@value\expandafter{\expandafter\expandonce\expandafter{\expandafter\forest@wrap@code\forest@option@value\pgfeov}}%
\pgfkeysalso{\forest@handlers@wrap@currentpath/.expand once=\forest@wrapped@value}%
},
+ /handlers/.option/.code={%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\pgfkeyscurrentpath={\forestoption{#1}}}%
+ }\forest@marshal
+ },
+ /handlers/.register/.code={%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\pgfkeyscurrentpath={\forestregister{#1}}}%
+ }\forest@marshal
+ },
/handlers/.wrap pgfmath arg/.code 2 args={%
\pgfmathparse{#2}\let\forest@wrap@arg@i\pgfmathresult
\edef\forest@wrap@args{{\expandonce\forest@wrap@arg@i}}%
@@ -1777,6 +1816,9 @@
/handlers/.wrap 8 pgfmath args/.code n args={9}{%
\forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}{8}%
\forest@wrap@n@pgfmath@do{#1}{8}},
+ /handlers/.process args/.code={%
+ \forest@processargs#1\forest@eov\forest@END
+ },
}
\def\forest@wrap@n@pgfmath@args#1#2#3#4#5#6#7#8#9{%
\pgfmathparse{#1}\let\forest@wrap@arg@i\pgfmathresult
@@ -1812,44 +1854,544 @@
\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\forest@wrapped\expandafter\expandafter\expandafter{\expandafter\forest@wrap@code\forest@wrap@args}%
\pgfkeysalso{\pgfkeyscurrentpath/.expand once=\forest@wrapped}%
}
-\def\forest@node@setname#1{%
- \forestoeset{name}{#1}%
- \csedef{forest@id@of@#1}{\forest@cn}%
+\newtoks\forest@processargs@result
+\newtoks\forest@processargs@current
+\newif\ifforest@processargs@append
+\def\forest@eov{\forest@eov}
+\def\forest@processargs#1#2\forest@END{% #1 = processing instructions, #2 = args
+ \forest@processargs@result{}%
+ \forest@processargs@current{}%
+ \forest@processargs@appendfalse
+ \forest@processargs@getins#1.\forest@END#2\forest@END
+}
+\def\forest@processargs@maybeappend{%
+ \ifforest@processargs@append
+ \eapptotoks\forest@processargs@result{{\the\forest@processargs@current}}%
+ \forest@processargs@current{}%
+ \fi
+}
+\def\forest@processargs@getins#1#2\forest@END#3\forest@END{% #1 = first instruction, #2 = rest of instructions, #3 = args
+ \csname forest@processargs@ins@#1\endcsname#2\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@.}\forest@END#1\forest@END{%
+ \forest@processargs@maybeappend
+ \forest@processargs@appremainingargs#1\forest@END
+}
+\def\forest@processargs@appremainingargs#1#2\forest@END{%
+ \edef\forest@temp{\unexpanded{#1}}%
+ \ifx\forest@temp\forest@eov
+ \let\forest@processargs@next\forest@processargs@done
+ \else
+ \apptotoks\forest@processargs@result{{#1}}%
+ \let\forest@processargs@next\forest@processargs@appremainingargs
+ \fi
+ \forest@processargs@next#2\forest@END
+}
+\def\forest@processargs@done#1\forest@END{%
+ \pgfkeysalso{\pgfkeyscurrentpath/.expanded=\the\forest@processargs@result}%
+}
+\csdef{forest@processargs@ins@_}#1\forest@END#2#3\forest@END{% no processing
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \forest@processargs@current{#2}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@x}#1\forest@END#2#3\forest@END{% expand
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \etotoks\forest@processargs@current{#2}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@o}#1\forest@END#2#3\forest@END{% expand once
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \expandafter\forest@processargs@current\expandafter{#2}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@O}#1\forest@END#2#3\forest@END{% option
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \etotoks\forest@processargs@current{\forestoption{#2}}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@R}#1\forest@END#2#3\forest@END{% register
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \etotoks\forest@processargs@current{\forestregister{#2}}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@P}#1\forest@END#2#3\forest@END{% pgfmath expression
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \pgfmathparse{#2}%
+ \expandafter\forest@processargs@current\expandafter{\pgfmathresult}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\csdef{forest@processargs@ins@+}#1\forest@END#2\forest@END{% join processors
+ \forest@processargs@appendfalse
+ \edef\forest@marshal{%
+ \unexpanded{\forest@processargs@getins#1\forest@END}{\the\forest@processargs@current}\unexpanded{#2\forest@END}%
+ }\forest@marshal
+}
+\csdef{forest@processargs@ins@r}#1\forest@END#2#3\forest@END{% reverse keylist
+ % #1 = rest of ins, #2 = first arg, #3 = rest of args
+ \forest@processargs@maybeappend
+ \forest@processargs@current{}%
+ \pgfqkeys{/forest}{split={#2}{,}{reverse@keylist}}%
+ \forest@processargs@appendtrue
+ \forest@processargs@getins#1\forest@END#3\forest@END
+}
+\forestset{%
+ reverse@keylist/.code={%
+ \epretotoks\forest@processargs@current{#1,}%
+ },
+}
+\def\forest@pgfmathhelper@register@toks#1#2{% #1 is discarded: it is present only for analogy with options
+ \forestrget{#2}\pgfmathresult
+}
+\def\forest@pgfmathhelper@register@dimen#1#2{%
+ \forestrget{#2}\forest@temp
+ \pgfmathparse{+\forest@temp}%
+}
+\def\forest@pgfmathhelper@register@count#1#2{%
+ \forestrget{#2}\forest@temp
+ \pgfmathtruncatemacro\pgfmathresult{\forest@temp}%
+}
+\def\forest@declareregisterhandler#1#2{%#1=handler for specific type,#2=option name
+ \pgfkeyssetvalue{/forest/#2/node@or@reg}{register}%
+ \forest@convert@others@to@underscores{#2}\forest@pgfmathoptionname
+ \edef\forest@marshal{%
+ \noexpand#1{/forest/#2}{/forest}{#2}{\forest@pgfmathoptionname}%
+ }\forest@marshal
+}
+\def\forest@declaretoksregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \forest@declaretoksregister@handler@A{#1}{#2}{#3}{#4}{}%
+}
+\def\forest@declarekeylistregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \forest@declaretoksregister@handler@A{#1}{#2}{#3}{#4}{,}%
+ \forest@copycommandkey{#1}{#1'}%
+ \pgfkeyssetvalue{#1'/option@name}{#3}%
+ \forest@copycommandkey{#1+}{#1}%
+ \pgfkeysalso{#1-/.code={%
+ \forest@fornode{register}{%
+ \forest@node@removekeysfromkeylist{##1}{#3}%
+ }}}%
+ \pgfkeyssetvalue{#1-/option@name}{#3}%
+}
+\def\forest@declaretoksregister@handler@A#1#2#3#4#5{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
+ \pgfkeysalso{%
+ #1/.code={\forestrset{#3}{##1}},
+ #1+/.code={\forestrappto{#3}{#5##1}},
+ #2/+#3/.code={\forestrpreto{#3}{##1#5}},
+ #2/if #3/.code n args={3}{%
+ \forestrget{#3}\forest@temp@option@value
+ \edef\forest@temp@compared@value{\unexpanded{##1}}%
+ \ifx\forest@temp@option@value\forest@temp@compared@value
+ \pgfkeysalso{##2}%
+ \else
+ \pgfkeysalso{##3}%
+ \fi
+ },
+ #2/if in #3/.code n args={3}{%
+ \forestrget{#3}\forest@temp@option@value
+ \edef\forest@temp@compared@value{\unexpanded{##1}}%
+ \expandafter\expandafter\expandafter\pgfutil@in@\expandafter\expandafter\expandafter{\expandafter\forest@temp@compared@value\expandafter}\expandafter{\forest@temp@option@value}%
+ \ifpgfutil@in@
+ \pgfkeysalso{##2}%
+ \else
+ \pgfkeysalso{##3}%
+ \fi
+ },
+ }%
+ \pgfkeyssetvalue{#1/option@name}{#3}%
+ \pgfkeyssetvalue{#1+/option@name}{#3}%
+ \pgfkeyssetvalue{#2/+#3/option@name}{#3}%
+ \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@toks{##1}{#3}}%
+}
+\def\forest@declareautowrappedtoksregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
+ \forest@declaretoksregister@handler{#1}{#2}{#3}{#4}%
+ \forest@copycommandkey{#1}{#1'}%
+ \pgfkeysalso{#1/.style={#1'/.wrap value={##1}}}%
+ \pgfkeyssetvalue{#1'/option@name}{#3}%
+ \forest@copycommandkey{#1+}{#1+'}%
+ \pgfkeysalso{#1+/.style={#1+'/.wrap value={##1}}}%
+ \pgfkeyssetvalue{#1+'/option@name}{#3}%
+ \forest@copycommandkey{#2/+#3}{#2/+#3'}%
+ \pgfkeysalso{#2/+#3/.style={#2/+#3'/.wrap value={##1}}}%
+ \pgfkeyssetvalue{#2/+#3'/option@name}{#3}%
+}
+\def\forest@declarereadonlydimenregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \pgfkeysalso{%
+ #2/if #3/.code n args={3}{%
+ \forestrget{#3}\forest@temp@option@value
+ \ifdim\forest@temp@option@value=##1\relax
+ \pgfkeysalso{##2}%
+ \else
+ \pgfkeysalso{##3}%
+ \fi
+ },
+ }%
+ \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@dimen{##1}{#3}}%
+}
+\def\forest@declaredimenregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \forest@declarereadonlydimenregister@handler{#1}{#2}{#3}{#4}%
+ \pgfkeysalso{%
+ #1/.code={%
+ \pgfmathsetlengthmacro\forest@temp{##1}%
+ \forestrlet{#3}\forest@temp
+ },
+ #1+/.code={%
+ \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfutil@tempdima=\forestrve{#3}
+ \advance\pgfutil@tempdima\forest@temp\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1-/.code={%
+ \pgfmathsetlengthmacro\forest@temp{##1}%
+ \pgfutil@tempdima=\forestrve{#3}
+ \advance\pgfutil@tempdima-\forest@temp\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1*/.style={%
+ #1={#4()*(##1)}%
+ },
+ #1:/.style={%
+ #1={#4()/(##1)}%
+ },
+ #1'/.code={%
+ \pgfutil@tempdima=##1\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1'+/.code={%
+ \pgfutil@tempdima=\forestrve{#3}\relax
+ \advance\pgfutil@tempdima##1\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1'-/.code={%
+ \pgfutil@tempdima=\forestrve{#3}\relax
+ \advance\pgfutil@tempdima-##1\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1'*/.style={%
+ \pgfutil@tempdima=\forestrve{#3}\relax
+ \multiply\pgfutil@tempdima##1\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ #1':/.style={%
+ \pgfutil@tempdima=\forestrve{#3}\relax
+ \divide\pgfutil@tempdima##1\relax
+ \forestreset{#3}{\the\pgfutil@tempdima}%
+ },
+ }%
+ \pgfkeyssetvalue{#1/option@name}{#3}%
+ \pgfkeyssetvalue{#1+/option@name}{#3}%
+ \pgfkeyssetvalue{#1-/option@name}{#3}%
+ \pgfkeyssetvalue{#1*/option@name}{#3}%
+ \pgfkeyssetvalue{#1:/option@name}{#3}%
+ \pgfkeyssetvalue{#1'/option@name}{#3}%
+ \pgfkeyssetvalue{#1'+/option@name}{#3}%
+ \pgfkeyssetvalue{#1'-/option@name}{#3}%
+ \pgfkeyssetvalue{#1'*/option@name}{#3}%
+ \pgfkeyssetvalue{#1':/option@name}{#3}%
+}
+\def\forest@declarereadonlycountregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \pgfkeysalso{
+ #2/if #3/.code n args={3}{%
+ \forestrget{#3}\forest@temp@option@value
+ \ifnum\forest@temp@option@value=##1\relax
+ \pgfkeysalso{##2}%
+ \else
+ \pgfkeysalso{##3}%
+ \fi
+ },
+ }%
+ \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@count{##1}{#3}}%
+}
+\def\forest@declarecountregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \forest@declarereadonlycountregister@handler{#1}{#2}{#3}{#4}%
+ \pgfkeysalso{
+ #1/.code={%
+ \pgfmathtruncatemacro\forest@temp{##1}%
+ \forestrlet{#3}\forest@temp
+ },
+ #1+/.code={%
+ \pgfmathtruncatemacro\forest@temp{##1}%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \advance\c@pgf@counta\forest@temp\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1-/.code={%
+ \pgfmathtruncatemacro\forest@temp{##1}%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \advance\c@pgf@counta-\forest@temp\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1*/.code={%
+ \pgfmathtruncatemacro\forest@temp{##1}%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \multiply\c@pgf@counta\forest@temp\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1:/.code={%
+ \pgfmathtruncatemacro\forest@temp{##1}%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \divide\c@pgf@counta\forest@temp\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1'/.code={%
+ \c@pgf@counta=##1\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1'+/.code={%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \advance\c@pgf@counta##1\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1'-/.code={%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \advance\c@pgf@counta-##1\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1'*/.style={%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \multiply\c@pgf@counta##1\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ #1':/.style={%
+ \c@pgf@counta=\forestrve{#3}\relax
+ \divide\c@pgf@counta##1\relax
+ \forestreset{#3}{\the\c@pgf@counta}%
+ },
+ }%
+ \pgfkeyssetvalue{#1/option@name}{#3}%
+ \pgfkeyssetvalue{#1+/option@name}{#3}%
+ \pgfkeyssetvalue{#1-/option@name}{#3}%
+ \pgfkeyssetvalue{#1*/option@name}{#3}%
+ \pgfkeyssetvalue{#1:/option@name}{#3}%
+ \pgfkeyssetvalue{#1'/option@name}{#3}%
+ \pgfkeyssetvalue{#1'+/option@name}{#3}%
+ \pgfkeyssetvalue{#1'-/option@name}{#3}%
+ \pgfkeyssetvalue{#1'*/option@name}{#3}%
+ \pgfkeyssetvalue{#1':/option@name}{#3}%
+}
+\def\forest@declarebooleanregister@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
+ \pgfkeysalso{%
+ #1/.code={%
+ \ifstrequal{##1}{1}{%
+ \forestrset{#3}{1}%
+ }{%
+ \ifstrequal{##1}{0}{%
+ \forestrset{#3}{0}%
+ }{%
+ \pgfmathifthenelse{##1}{1}{0}%
+ \forestrlet{#3}\pgfmathresult
+ }%
+ }%
+ },
+ #1/.default=1,
+ #2/not #3/.code={\forestrset{#3}{0}},
+ #2/if #3/.code 2 args={%
+ \forestrget{#3}\forest@temp@option@value
+ \ifnum\forest@temp@option@value=1
+ \pgfkeysalso{##1}%
+ \else
+ \pgfkeysalso{##2}%
+ \fi
+ },
+ }%
+ \pgfkeyssetvalue{#1/option@name}{#3}%
+ \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@register@count{##1}{#3}}%
+}
+\forestset{
+ declare toks register/.code={%
+ \forest@declareregisterhandler\forest@declaretoksregister@handler{#1}%
+ },
+ declare autowrapped toks register/.code={%
+ \forest@declareregisterhandler\forest@declareautowrappedtoksregister@handler{#1}%
+ },
+ declare keylist register/.code={%
+ \forest@declareregisterhandler\forest@declarekeylistregister@handler{#1}%
+ },
+ declare dimen register/.code={%
+ \forest@declareregisterhandler\forest@declaredimenregister@handler{#1}%
+ },
+ declare count register/.code={%
+ \forest@declareregisterhandler\forest@declarecountregister@handler{#1}%
+ },
+ declare boolean register/.code={%
+ \forest@declareregisterhandler\forest@declarebooleanregister@handler{#1}%
+ },
+}
+\forestset{
+ declare toks register=temptoksa,temptoksa={},
+ declare toks register=temptoksb,temptoksb={},
+ declare toks register=temptoksc,temptoksc={},
+ declare toks register=temptoksd,temptoksd={},
+ declare keylist register=tempkeylista,tempkeylista'={},
+ declare keylist register=tempkeylistb,tempkeylistb'={},
+ declare keylist register=tempkeylistc,tempkeylistc'={},
+ declare keylist register=tempkeylistd,tempkeylistd'={},
+ declare dimen register=tempdima,tempdima'={0pt},
+ declare dimen register=tempdimb,tempdimb'={0pt},
+ declare dimen register=tempdimc,tempdimc'={0pt},
+ declare dimen register=tempdimd,tempdimd'={0pt},
+ declare dimen register=tempdimx,tempdimx'={0pt},
+ declare dimen register=tempdimy,tempdimy'={0pt},
+ declare dimen register=tempdiml,tempdiml'={0pt},
+ declare dimen register=tempdims,tempdims'={0pt},
+ declare count register=tempcounta,tempcounta'={0},
+ declare count register=tempcountb,tempcountb'={0},
+ declare count register=tempcountc,tempcountc'={0},
+ declare count register=tempcountd,tempcountd'={0},
+ declare boolean register=tempboola,tempboola={0},
+ declare boolean register=tempboolb,tempboolb={0},
+ declare boolean register=tempboolc,tempboolc={0},
+ declare boolean register=tempboold,tempboold={0},
}
\def\forest@node@Nametoid#1{% #1 = name
\csname forest@id@of@#1\endcsname
}
-\def\forest@node@Ifnamedefined#1{% #1 = name, #2=true,#3=false
- \ifcsname forest@id@of@#1\endcsname
- \expandafter\@firstoftwo
+\def\forest@node@Ifnamedefined#1#2#3{% #1 = name, #2=true,#3=false
+ \ifcsvoid{forest@id@of@#1}{#3}{#2}%
+}
+\def\forest@node@setname#1{%
+ \def\forest@temp@setname{y}%
+ \def\forest@temp@silent{n}%
+ \def\forest@temp@propagating{n}%
+ \forest@node@setnameoralias{#1}%
+}
+\def\forest@node@setname@silent#1{%
+ \def\forest@temp@setname{y}%
+ \def\forest@temp@silent{y}%
+ \def\forest@temp@propagating{n}%
+ \forest@node@setnameoralias{#1}%
+}
+\def\forest@node@setalias#1{%
+ \def\forest@temp@setname{n}%
+ \def\forest@temp@silent{n}%
+ \def\forest@temp@propagating{n}%
+ \forest@node@setnameoralias{#1}%
+}
+\def\forest@node@setalias@silent#1{%
+ \def\forest@temp@setname{n}%
+ \def\forest@temp@silent{y}%
+ \def\forest@temp@propagating{n}%
+ \forest@node@setnameoralias{#1}%
+}
+\def\forest@node@setnameoralias#1{%
+ \ifstrempty{#1}{%
+ \forest@node@setnameoralias{node@\forest@cn}%
+ }{%
+ \forest@node@Ifnamedefined{#1}{%
+ \if y\forest@temp@propagating
+ % this will find a unique name, eventually:
+ \@escapeif{\forest@node@setnameoralias{#1@\forest@cn}}%
+ \else\@escapeif{%
+ \if y\forest@temp@setname
+ \@escapeif{\forest@node@setnameoralias@nameclash{#1}}%
+ \else\@escapeif{% setting an alias: clashing with alias is not a problem
+ \forestOget{\forest@node@Nametoid{#1}}{name}\forest@temp
+ \expandafter\ifstrequal\expandafter{\forest@temp}{#1}{%
+ \forest@node@setnameoralias@nameclash{#1}%
+ }{%
+ \forest@node@setnameoralias@do{#1}%
+ }%
+ }\fi
+ }\fi
+ }{%
+ \forest@node@setnameoralias@do{#1}%
+ }%
+ }%
+}
+\def\forest@node@setnameoralias@nameclash#1{%
+ \if y\forest@temp@silent
+ \forest@fornode{\forest@node@Nametoid{#1}}{%
+ \def\forest@temp@propagating{y}%
+ \forest@node@setnameoralias{}%
+ }%
+ \forest@node@setnameoralias@do{#1}%
\else
- \expandafter\@secondoftwo
+ \PackageError{forest}{Node name "#1" is already used}{}%
\fi
}
-\def\forest@node@setalias#1{%
+\def\forest@node@setnameoralias@do#1{%
+ \if y\forest@temp@setname
+ \csdef{forest@id@of@\forestove{name}}{}%
+ \forestoeset{name}{#1}%
+ \fi
\csedef{forest@id@of@#1}{\forest@cn}%
}
-\def\forest@node@Setalias#1#2{%
- \csedef{forest@id@of@#2}{#1}%
-}
\forestset{
TeX/.code={#1},
TeX'/.code={\appto\forest@externalize@loadimages{#1}#1},
TeX''/.code={\appto\forest@externalize@loadimages{#1}},
+ options/.code={\forestset{#1}},
+ typeout/.style={TeX={\typeout{#1}}},
declare toks={name}{},
name/.code={% override the default setter
- \forest@node@setname{#1}%
+ \forest@fornode{\forest@setter@node}{\forest@node@setname{#1}}%
},
- alias/.code={\forest@node@setalias{#1}},
+ name/.default={},
+ name'/.code={% override the default setter
+ \forest@fornode{\forest@setter@node}{\forest@node@setname@silent{#1}}%
+ },
+ name'/.default={},
+ alias/.code={\forest@fornode{\forest@setter@node}{\forest@node@setalias{#1}}},
+ alias'/.code={\forest@fornode{\forest@setter@node}{\forest@node@setalias@silent{#1}}},
begin draw/.code={\begin{tikzpicture}},
end draw/.code={\end{tikzpicture}},
- begin forest/.code={},
- end forest/.code={},
+ declare keylist register=default preamble,
+ default preamble'={},
+ declare keylist register=preamble,
+ preamble'={},
declare autowrapped toks={content}{},
+ % #1 = which option to split, #2 = separator (one char!), #3 = receiving options
+ %%% begin listing region: split_option
+ split option/.style n args=3{split/.process args={O}{#1}{#2}{#3}}
+ %%% end listing region: split_option
+ ,
+ split register/.style n args=3{% #1 = which register to split, #2 = separator (one char!), #3 = receiving options
+ split/.process args={R}{#1}{#2}{#3},
+ },
+ TeX={%
+ \def\forest@split@sourcevalues{}%
+ \def\forest@split@sourcevalue{}%
+ \def\forest@split@receivingoptions{}%
+ \def\forest@split@receivingoption{}%
+ },
+ split/.code n args=3{% #1 = string to split, #2 = separator (one char!), #3 = receiving options
+ \forest@saveandrestoremacro\forest@split@sourcevalues{%
+ \forest@saveandrestoremacro\forest@split@sourcevalue{%
+ \forest@saveandrestoremacro\forest@split@receivingoptions{%
+ \forest@saveandrestoremacro\forest@split@receivingoption{%
+ \def\forest@split@sourcevalues{#1#2}%
+ \edef\forest@split@receivingoptions{#3,}%
+ \def\forest@split@receivingoption{}%
+ \safeloop
+ \expandafter\forest@split\expandafter{\forest@split@sourcevalues}{#2}\forest@split@sourcevalue\forest@split@sourcevalues
+ \ifdefempty\forest@split@receivingoptions{}{%
+ \expandafter\forest@split\expandafter{\forest@split@receivingoptions}{,}\forest@temp\forest@split@receivingoptions
+ \ifdefempty\forest@temp{}{\let\forest@split@receivingoption\forest@temp\def\forest@temp{}}%
+ }%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\forest@split@receivingoption={\expandonce{\forest@split@sourcevalue}}}%
+ }\forest@marshal
+ \ifdefempty\forest@split@sourcevalues{\forest@tempfalse}{\forest@temptrue}%
+ \ifforest@temp
+ \saferepeat
+ }}}}%
+ },
declare count={grow}{270},
TeX={% a hack for grow-reversed connection, and compass-based grow specification
- \pgfkeysgetvalue{/forest/grow/.@cmd}\forest@temp
- \pgfkeyslet{/forest/grow@@/.@cmd}\forest@temp
+ \forest@copycommandkey{/forest/grow}{/forest/grow@@}%
+ %\pgfkeysgetvalue{/forest/grow/.@cmd}\forest@temp
+ %\pgfkeyslet{/forest/grow@@/.@cmd}\forest@temp
},
grow/.style={grow@={#1},reversed=0},
grow'/.style={grow@={#1},reversed=1},
@@ -1869,10 +2411,26 @@
declare toks={parent anchor}{},
declare toks={child anchor}{},
declare toks={anchor}{base},
+ Autoforward={anchor}{
+ node options-=anchor,
+ node options+={anchor={##1}}
+ },
+ anchor'/.style={anchor@no@compass=true,anchor=#1},
+ anchor+'/.style={anchor@no@compass=true,anchor+=#1},
+ anchor-'/.style={anchor@no@compass=true,anchor-=#1},
+ anchor*'/.style={anchor@no@compass=true,anchor*=#1},
+ anchor:'/.style={anchor@no@compass=true,anchor:=#1},
+ anchor'+'/.style={anchor@no@compass=true,anchor'+=#1},
+ anchor'-'/.style={anchor@no@compass=true,anchor'-=#1},
+ anchor'*'/.style={anchor@no@compass=true,anchor'*=#1},
+ anchor':'/.style={anchor@no@compass=true,anchor':=#1},
+ % /tikz/forest anchor/.style={
+ % /forest/TeX={\forestanchortotikzanchor{#1}\forest@temp@anchor},
+ % anchor/.expand once=\forest@temp@anchor
+ % },
declare toks={calign}{midpoint},
TeX={%
- \pgfkeysgetvalue{/forest/calign/.@cmd}\forest@temp
- \pgfkeyslet{/forest/calign'/.@cmd}\forest@temp
+ \forest@copycommandkey{/forest/calign}{/forest/calign'}%
},
calign/.is choice,
calign/child/.style={calign'=child},
@@ -1901,10 +2459,18 @@
declare keylist={edge}{draw},
declare toks={edge path}{%
\noexpand\path[\forestoption{edge}]%
- (\forestOve{\forestove{@parent}}{name}.parent anchor)--(\forestove{name}.child anchor)\forestoption{edge label};},
- triangle/.style={edge path={%
+ (\forestOve{\forestove{@parent}}{name}.parent anchor)--(\forestove{name}.child anchor)
+ % =
+ % (!u.parent anchor)--(.child anchor)\forestoption{edge label};
+ \forestoption{edge label};%
+ },
+ edge path'/.style={
+ edge path={%
\noexpand\path[\forestoption{edge}]%
- (\forestove{name}.north east)--(\forestOve{\forestove{@parent}}{name}.south)--(\forestove{name}.north west)--(\forestove{name}.north east)\forestoption{edge label};}},
+ #1%
+ \forestoption{edge label};
+ }
+ },
declare toks={edge label}{},
declare boolean={phantom}{0},
baseline/.style={alias={forest@baseline@node}},
@@ -1912,13 +2478,13 @@
declare readonly count={n'},
declare readonly count={n children},
declare readonly count={level},
- declare dimen=x{},
- declare dimen=y{},
+ declare dimen=x{0pt},
+ declare dimen=y{0pt},
declare dimen={s}{0pt},
declare dimen={l}{6ex}, % just in case: should be set by the calibration
declare dimen={s sep}{0.6666em},
declare dimen={l sep}{1ex}, % just in case: calibration!
- declare keylist={node options}{},
+ declare keylist={node options}{anchor=base},
declare toks={tikz}{},
afterthought/.style={tikz+={#1}},
label/.style={tikz={\path[late options={%
@@ -1926,21 +2492,28 @@
pin/.style={tikz={\path[late options={%
name=\forestoption{name},pin={#1}}];}},
declare toks={content format}{\forestoption{content}},
- math content/.style={content format={\ensuremath{\forestoption{content}}}},
+ plain content/.style={content format={\forestoption{content}}},
+ math content/.style={content format={\noexpand\ensuremath{\forestoption{content}}}},
declare toks={node format}{%
\noexpand\node
- [\forestoption{node options},anchor=\forestoption{anchor}]%
(\forestoption{name})%
+ [\forestoption{node options}]%
{\foresteoption{content format}};%
},
+ node format'/.style={
+ node format={\noexpand\node(\forestoption{name})#1;}
+ },
tabular@environment/.style={content format={%
\noexpand\begin{tabular}[\forestoption{base}]{\forestoption{align}}%
\forestoption{content}%
\noexpand\end{tabular}%
}},
declare toks={align}{},
- TeX={\pgfkeysgetvalue{/forest/align/.@cmd}\forest@temp
- \pgfkeyslet{/forest/align'/.@cmd}\forest@temp},
+ TeX={%
+ \forest@copycommandkey{/forest/align}{/forest/align'}%
+ %\pgfkeysgetvalue{/forest/align/.@cmd}\forest@temp
+ %\pgfkeyslet{/forest/align'/.@cmd}\forest@temp
+ },
align/.is choice,
align/.unknown/.code={%
\edef\forest@marshal{%
@@ -1954,24 +2527,32 @@
align/left/.style={align'={@{}l@{}},tabular@environment},
align/right/.style={align'={@{}r@{}},tabular@environment},
declare toks={base}{t},
- TeX={\pgfkeysgetvalue{/forest/base/.@cmd}\forest@temp
- \pgfkeyslet{/forest/base'/.@cmd}\forest@temp},
+ TeX={%
+ \forest@copycommandkey{/forest/base}{/forest/base'}%
+ %\pgfkeysgetvalue{/forest/base/.@cmd}\forest@temp
+ %\pgfkeyslet{/forest/base'/.@cmd}\forest@temp
+ },
base/.is choice,
base/top/.style={base'=t},
base/bottom/.style={base'=b},
base/.unknown/.style={base'/.expand once=\pgfkeyscurrentname},
+ unknown to/.store in=\forest@unknownto,
+ unknown to=node options,
+ unknown key error/.code={\PackageError{forest}{Unknown keyval: \detokenize{#1}}{}},
+ content to/.store in=\forest@contentto,
+ content to=content,
.unknown/.code={%
\expandafter\pgfutil@in@\expandafter.\expandafter{\pgfkeyscurrentname}%
\ifpgfutil@in@
\expandafter\forest@relatednode@option@setter\pgfkeyscurrentname=#1\forest@END
\else
\edef\forest@marshal{%
- \noexpand\pgfkeysalso{node options={\pgfkeyscurrentname=\unexpanded{#1}}}%
+ \noexpand\pgfkeysalso{\forest@unknownto={\pgfkeyscurrentname=\unexpanded{#1}}}%
}\forest@marshal
\fi
},
get node boundary/.code={%
- \forestoget{boundary}\forest@node@boundary
+ \forestoget{@boundary}\forest@node@boundary
\def#1{}%
\forest@extendpath#1\forest@node@boundary{\pgfpoint{\forestove{x}}{\forestove{y}}}%
},
@@ -1983,15 +2564,6 @@
\forest@get@tree@boundary{negative}{\forestove{grow}}#1},
get max s tree boundary/.code={%
\forest@get@tree@boundary{positive}{\forestove{grow}}#1},
- fit to tree/.code={%
- \pgfkeysalso{%
- /forest/get min s tree boundary=\forest@temp@negative@boundary,
- /forest/get max s tree boundary=\forest@temp@positive@boundary
- }%
- \edef\forest@temp@boundary{\expandonce{\forest@temp@negative@boundary}\expandonce{\forest@temp@positive@boundary}}%
- \forest@path@getboundingrectangle@xy\forest@temp@boundary
- \pgfkeysalso{inner sep=0,fit/.expanded={(\the\pgf@xa,\the\pgf@ya)(\the\pgf@xb,\the\pgf@yb)}}%
- },
use as bounding box/.style={%
before drawing tree={
tikz+/.expanded={%
@@ -2017,58 +2589,266 @@
}
},
}%
+\def\forest@iftikzkey#1#2#3{% #1 = key name, #2 = true code, #3 = false code
+ \forest@temptrue
+ \pgfkeysifdefined{/tikz/\pgfkeyscurrentname}{}{%
+ \pgfkeysifdefined{/tikz/\pgfkeyscurrentname/.@cmd}{}{%
+ \pgfkeysifdefined{/pgf/\pgfkeyscurrentname}{}{%
+ \pgfkeysifdefined{/pgf/\pgfkeyscurrentname/.@cmd}{}{%
+ \forest@tempfalse
+ }}}}%
+ \ifforest@temp\@escapeif{#2}\else\@escapeif{#3}\fi
+}
+\def\forest@ifoptionortikzkey#1#2#3{% #1 = key name, #2 = true code, #3 = false code
+ \forest@temptrue
+ \pgfkeysifdefined{/forest/\pgfkeyscurrentname}{}{%
+ \pgfkeysifdefined{/forest/\pgfkeyscurrentname/.@cmd}{}{%
+ \forest@iftikzkey{#1}{}{}%
+ }}%
+ \ifforest@temp\@escapeif{#2}\else\@escapeif{#3}\fi
+}
\def\forest@get@tree@boundary#1#2#3{%#1=pos/neg,#2=grow,#3=receiving cs
\def#3{}%
\forest@node@getedge{#1}{#2}\forest@temp@boundary
\forest@extendpath#3\forest@temp@boundary{\pgfpoint{\forestove{x}}{\forestove{y}}}%
}
\def\forest@setter@node{\forest@cn}%
+\def\forest@relatednode@option@compat@ignoreinvalidsteps#1{#1}
\def\forest@relatednode@option@setter#1.#2=#3\forest@END{%
\forest@forthis{%
- \forest@nameandgo{#1}%
- \let\forest@setter@node\forest@cn
+ \forest@relatednode@option@compat@ignoreinvalidsteps{%
+ \forest@nameandgo{#1}%
+ \let\forest@setter@node\forest@cn
+ }%
}%
- \pgfkeysalso{#2={#3}}%
+ \ifnum\forest@setter@node=0
+ \else
+ \forestset{#2={#3}}%
+ \fi
\def\forest@setter@node{\forest@cn}%
}%
+\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
+ \def\forest@split@@##1#2##2\forest@split@@##3##4{\def##3{##1}\def##4{##2}}%
+ \forest@split@@#1\forest@split@@{#3}{#4}}
\forestset{
- for tree/.code={\forest@node@foreach{\pgfkeysalso{#1}}},
+ for tree'/.style 2 args={#1,for children={for tree'={#1}{#2}},#2},
if/.code n args={3}{%
\pgfmathparse{#1}%
- \ifnum\pgfmathresult=0 \pgfkeysalso{#3}\else\pgfkeysalso{#2}\fi
+ \ifnum\pgfmathresult=0
+ \@escapeif{\pgfkeysalso{#3}}%
+ \else
+ \@escapeif{\pgfkeysalso{#2}}%
+ \fi
+ },
+ if nodewalk valid/.code n args={3}{%
+ \edef\forest@marshal{%
+ \unexpanded{\forest@forthis{%
+ \forest@nodewalk{%
+ on invalid={fake}{#1},
+ TeX={\global\let\forest@global@temp\forest@cn}
+ }{}%
+ }%
+ \def\forest@cn}{\forest@cn}\unexpanded{%
+ \ifnum\forest@global@temp=0
+ \@escapeif{\pgfkeysalso{#3}}%
+ \else
+ \@escapeif{\pgfkeysalso{#2}}%
+ \fi}%
+ }\forest@marshal
+ },
+ if nodewalk empty/.code n args={3}{%
+ \forest@forthis{%
+ \forest@nodewalk{%
+ on invalid={fake}{#1},
+ TeX={\global\let\forest@global@temp\forest@nodewalk@n},
+ }{}%
+ }%
+ \ifnum\forest@global@temp=0
+ \@escapeif{\pgfkeysalso{#2}}%
+ \else
+ \@escapeif{\pgfkeysalso{#3}}%
+ \fi
},
where/.style n args={3}{for tree={if={#1}{#2}{#3}}},
- for descendants/.code={\forest@node@foreachdescendant{\pgfkeysalso{#1}}},
- for all next/.style={for next={#1,for all next={#1}}},
- for all previous/.style={for previous={#1,for all previous={#1}}},
- for siblings/.style={for all previous={#1},for all next={#1}},
- for ancestors/.style={for parent={#1,for ancestors={#1}}},
- for ancestors'/.style={#1,for ancestors={#1}},
- for children/.code={\forest@node@foreachchild{\pgfkeysalso{#1}}},
- for c-commanded={for sibling={for tree={#1}}},
- for c-commanders={for sibling={#1},for parent={for c-commanders={#1}}}
-}
-\newcount\forest@repeat@key@depth
-\forestset{%
+ where nodewalk valid/.style n args={3}{for tree={if nodewalk valid={#1}{#2}{#3}}},
+ where nodewalk empty/.style n args={3}{for tree={if nodewalk empty={#1}{#2}{#3}}},
repeat/.code 2 args={%
- \advance\forest@repeat@key@depth1
- \pgfmathparse{int(#1)}%
- \csedef{forest@repeat@key@\the\forest@repeat@key@depth}{\pgfmathresult}%
- \expandafter\newloop\csname forest@repeat@key@loop@\the\forest@repeat@key@depth\endcsname
- \def\forest@marshal{%
- \csname forest@repeat@key@loop@\the\forest@repeat@key@depth\endcsname
- \forest@temp@count=\csname forest@repeat@key@\the\forest@repeat@key@depth\endcsname\relax
- \ifnum\forest@temp@count>0
- \advance\forest@temp@count-1
- \csedef{forest@repeat@key@\the\forest@repeat@key@depth}{\the\forest@temp@count}%
- \pgfkeysalso{#2}%
+ \pgfmathtruncatemacro\forest@temp{#1}%
+ \expandafter\forest@repeatkey\expandafter{\forest@temp}{#2}%
+ },
+ until/.code 2 args={%
+ \ifstrempty{#1}{%
+ \forest@untilkey{\ifnum\forest@cn=0\else\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
+ }{%
+ \forest@untilkey{\pgfmathifthenelse{#1}{"\noexpand\forestloopbreak"}{""}\pgfmathresult}{#2}%
+ }%
+ },
+ while/.code 2 args={%
+ \ifstrempty{#1}{%
+ \forest@untilkey{\ifnum\forest@cn=0\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
+ }{%
+ \forest@untilkey{\pgfmathifthenelse{not(#1)}{"\noexpand\forestloopbreak"}{""}\pgfmathresult}{#2}%
}%
- \expandafter\forest@marshal\csname forest@repeat@key@repeat@\the\forest@repeat@key@depth\endcsname
- \advance\forest@repeat@key@depth-1
},
+ do until/.code 2 args={%
+ \ifstrempty{#1}{%
+ \forest@dountilkey{\ifnum\forest@cn=0\else\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
+ }{%
+ \forest@dountilkey{\pgfmathifthenelse{#1}{"\noexpand\forestloopbreak"}{""}\pgfmathresult}{#2}%
+ }%
+ },
+ do while/.code 2 args={%
+ \ifstrempty{#1}{%
+ \forest@dountilkey{\ifnum\forest@cn=0\relax\forestloopbreak\fi}{on invalid={fake}{#2}}%
+ }{%
+ \forest@dountilkey{\pgfmathifthenelse{not(#1)}{"\noexpand\forestloopbreak"}{""}\pgfmathresult}{#2}%
+ }%
+ },
+ until nodewalk valid/.code 2 args={%
+ \forest@untilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
+ },
+ while nodewalk valid/.code 2 args={%
+ \forest@untilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\forestloopbreak\fi}}{}}}{#2}%
+ },
+ do until nodewalk valid/.code 2 args={%
+ \forest@dountilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
+ },
+ do while nodewalk valid/.code 2 args={%
+ \forest@dountilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@cn=0\relax\forestloopbreak\fi}}{}}}{#2}%
+ },
+ until nodewalk empty/.code 2 args={%
+ \forest@untilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\forestloopbreak\fi}}{}}}{#2}%
+ },
+ while nodewalk empty/.code 2 args={%
+ \forest@untilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
+ },
+ do until nodewalk empty/.code 2 args={%
+ \forest@dountilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\forestloopbreak\fi}}{}}}{#2}%
+ },
+ do while nodewalk empty/.code 2 args={%
+ \forest@dountilkey{\forest@forthis{%
+ \forest@nodewalk{on invalid={fake}{#1},TeX={\ifnum\forest@nodewalk@n=0\relax\else\forestloopbreak\fi}}{}}}{#2}%
+ },
+ break/.code={\forestloopBreak{#1}},
+ break/.default=0,
+}
+\def\forest@repeatkey#1#2{%
+ \safeRKloop
+ \ifnum\safeRKloopn>#1\relax
+ \csuse{safeRKbreak@\the\safeRKloop@depth true}%
+ \fi
+ \expandafter\unless\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
+ \pgfkeysalso{#2}%
+ \safeRKrepeat
+}
+\def\forest@untilkey#1#2{% #1 = condition, #2 = keys
+ \safeRKloop
+ #1%
+ \expandafter\unless\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
+ \pgfkeysalso{#2}%
+ \safeRKrepeat
+}
+\def\forest@dountilkey#1#2{% #1 = condition, #2 = keys
+ \safeRKloop
+ \pgfkeysalso{#2}%
+ #1%
+ \expandafter\unless\csname ifsafeRKbreak@\the\safeRKloop@depth\endcsname
+ \safeRKrepeat
+}
+\def\forestloopbreak{%
+ \csname safeRKbreak@\the\safeRKloop@depth true\endcsname
+}
+\def\forestloopBreak#1{%
+ \csname safeRKbreak@\number\numexpr\the\safeRKloop@depth-#1\relax true\endcsname
+}
+\def\forestloopcount{%
+ \csname safeRKloopn@\number\numexpr\the\safeRKloop@depth\endcsname
+}
+\def\forestloopCount#1{%
+ \csname safeRKloopn@\number\numexpr\the\safeRKloop@depth-#1\endcsname
+}
+\pgfmathdeclarefunction{forestloopcount}{1}{%
+ \edef\pgfmathresult{\forestloopCount{\ifstrempty{#1}{0}{#1}}}%
+}
+\forest@copycommandkey{/forest/repeat}{/forest/nodewalk/repeat}
+\forest@copycommandkey{/forest/while}{/forest/nodewalk/while}
+\forest@copycommandkey{/forest/do while}{/forest/nodewalk/do while}
+\forest@copycommandkey{/forest/until}{/forest/nodewalk/until}
+\forest@copycommandkey{/forest/do until}{/forest/nodewalk/do until}
+\forest@copycommandkey{/forest/if}{/forest/nodewalk/if}
+\forest@copycommandkey{/forest/if nodewalk valid}{/forest/nodewalk/if nodewalk valid}
+\forestset{
+ aggregate postparse/.is choice,
+ aggregate postparse/int/.code={%
+ \let\forest@aggregate@pgfmathpostparse\forest@aggregate@pgfmathpostparse@toint},
+ aggregate postparse/none/.code={%
+ \let\forest@aggregate@pgfmathpostparse\relax},
+ aggregate postparse/print/.code={%
+ \let\forest@aggregate@pgfmathpostparse\forest@aggregate@pgfmathpostparse@print},
+ aggregate postparse/macro/.code={%
+ \let\forest@aggregate@pgfmathpostparse\forest@aggregate@pgfmathpostparse@usemacro},
+ aggregate postparse macro/.store in=\forest@aggregate@pgfmathpostparse@macro,
+}
+\def\forest@aggregate@pgfmathpostparse@print{%
+ \pgfmathprintnumberto{\pgfmathresult}{\pgfmathresult}%
+}
+\def\forest@aggregate@pgfmathpostparse@toint{%
+ \expandafter\forest@split\expandafter{\pgfmathresult.}{.}\pgfmathresult\forest@temp
+}
+\def\forest@aggregate@pgfmathpostparse@usemacro{%
+ \forest@aggregate@pgfmathpostparse@macro
+}
+\let\forest@aggregate@pgfmathpostparse\relax
+\pgfkeys{
+ /handlers/.aggregate/.code n args=4{%
+ % #1 = start value
+ % #2 = pgfmath expression for every step
+ % #3 = pgfmath expression for after walk
+ % #4 = nodewalk
+ \edef\forest@marshal{%
+ \unexpanded{\forest@aggregate{#1}{#2}{#3}{#4}}{\pgfkeyscurrentpath}%
+ }\forest@marshal
+ },
+ /handlers/.sum/.style 2 args={/handlers/.aggregate={0}{(##1)+(#1)}{##1}{#2}},
+ /handlers/.count/.style={/handlers/.aggregate={0}{1+(##1)}{##1}{#1}},
+ /handlers/.average/.style 2 args={/handlers/.aggregate={0}{(##1)+(#1)}{##1/\forestregister{aggregate n}}{#2}},
+ /handlers/.product/.style 2 args={/handlers/.aggregate={1}{(#1)*(##1)}{##1}{#2}},
+ /handlers/.min/.style 2 args={/handlers/.aggregate={}{min(#1,##1)}{##1}{#2}},
+ /handlers/.max/.style 2 args={/handlers/.aggregate={}{max(#1,##1)}{##1}{#2}},
+ /forest/declare count register={aggregate n},
+}
+
+\def\forest@aggregate#1#2#3#4#5{%
+ % #5 = current path
+ \def\forest@aggregate@result{#1}%
+ \forest@forthis{%
+ \forestrset{aggregate n}{0}%
+ \forest@nodewalk{#4}{%
+ TeX={%
+ \forestreset{aggregate n}{\number\numexpr\forestrv{aggregate n}+1}%
+ \def\forest@marshal##1{\pgfmathparse{#2}}%
+ \expandafter\forest@marshal\expandafter{\forest@aggregate@result}%
+ \let\forest@aggregate@result\pgfmathresult
+ }%
+ }{}%
+ }%
+ \def\forest@marshal##1{\pgfmathparse{#3}}%
+ \expandafter\forest@marshal\expandafter{\forest@aggregate@result}%
+ \let\forest@aggregate@result\pgfmathresult
+ \let\forest@temp@pgfmathpostparse\pgfmathpostparse
+ \let\pgfmathpostparse\forest@aggregate@pgfmathpostparse
+ \pgfmathqparse{\forest@aggregate@result pt}%
+ \let\pgfmathpostparse\forest@temp@pgfmathpostparse
+ \let\forest@aggregate@result\pgfmathresult
+ \pgfkeysalso{#5/.expand once=\forest@aggregate@result}%
}
-\pgfkeysgetvalue{/forest/repeat/.@cmd}\forest@temp
-\pgfkeyslet{/forest/node walk/repeat/.@cmd}\forest@temp
\pgfmathdeclarefunction{strequal}{2}{%
\ifstrequal{#1}{#2}{\def\pgfmathresult{1}}{\def\pgfmathresult{0}}%
}
@@ -2079,24 +2859,104 @@
\pgfmathdeclarefunction{strcat}{...}{%
\edef\pgfmathresult{\forest@strip@braces{#1}}%
}
+\pgfmathdeclarefunction{min_s}{2}{% #1 = node, #2 = context node (for growth rotation)
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \forest@compute@minmax@ls{#2}%
+ \pgfmathsetmacro\pgfmathresult{\forestove{min@s}}%
+ }%
+}
+\pgfmathdeclarefunction{min_l}{2}{% #1 = node, #2 = context node (for growth rotation)
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \forest@compute@minmax@ls{#2}%
+ \pgfmathsetmacro\pgfmathresult{\forestove{min@l}}%
+ }%
+}
+\pgfmathdeclarefunction{max_s}{2}{% #1 = node, #2 = context node (for growth rotation)
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \forest@compute@minmax@ls{#2}%
+ \pgfmathsetmacro\pgfmathresult{\forestove{max@s}}%
+ }%
+}
+\pgfmathdeclarefunction{max_l}{2}{% #1 = node, #2 = context node (for growth rotation)
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \forest@compute@minmax@ls{#2}%
+ \pgfmathsetmacro\pgfmathresult{\forestove{max@l}}%
+ }%
+}
+\def\forest@compute@minmax@ls#1{% #1 = nodewalk; in the context of which node?
+ {%
+ \pgftransformreset
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \pgftransformrotate{-\forestove{grow}}%
+ }%
+ \forestoget{min x}\forest@temp@minx
+ \forestoget{min y}\forest@temp@miny
+ \forestoget{max x}\forest@temp@maxx
+ \forestoget{max y}\forest@temp@maxy
+ \pgfpointtransformed{\pgfqpoint{\forest@temp@minx}{\forest@temp@miny}}%
+ \forestoeset{min@l}{\the\pgf@x}%
+ \forestoeset{min@s}{\the\pgf@y}%
+ \forestoeset{max@l}{\the\pgf@x}%
+ \forestoeset{max@s}{\the\pgf@y}%
+ \pgfpointtransformed{\pgfqpoint{\forest@temp@minx}{\forest@temp@maxy}}%
+ \ifdim\pgf@x<\forestove{min@l}\relax\forestoeset{min@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y<\forestove{min@s}\relax\forestoeset{min@s}{\the\pgf@y}\fi
+ \ifdim\pgf@x>\forestove{max@l}\relax\forestoeset{max@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y>\forestove{max@s}\relax\forestoeset{max@s}{\the\pgf@y}\fi
+ \pgfpointtransformed{\pgfqpoint{\forest@temp@maxx}{\forest@temp@miny}}%
+ \ifdim\pgf@x<\forestove{min@l}\relax\forestoeset{min@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y<\forestove{min@s}\relax\forestoeset{min@s}{\the\pgf@y}\fi
+ \ifdim\pgf@x>\forestove{max@l}\relax\forestoeset{max@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y>\forestove{max@s}\relax\forestoeset{max@s}{\the\pgf@y}\fi
+ \pgfpointtransformed{\pgfqpoint{\forest@temp@maxx}{\forest@temp@maxy}}%
+ \ifdim\pgf@x<\forestove{min@l}\relax\forestoeset{min@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y<\forestove{min@s}\relax\forestoeset{min@s}{\the\pgf@y}\fi
+ \ifdim\pgf@x>\forestove{max@l}\relax\forestoeset{max@l}{\the\pgf@x}\fi
+ \ifdim\pgf@y>\forestove{max@s}\relax\forestoeset{max@s}{\the\pgf@y}\fi
+ % smuggle out
+ \edef\forest@marshal{%
+ \noexpand\forestoeset{min@l}{\forestove{min@l}}%
+ \noexpand\forestoeset{min@s}{\forestove{min@s}}%
+ \noexpand\forestoeset{max@l}{\forestove{max@l}}%
+ \noexpand\forestoeset{max@s}{\forestove{max@s}}%
+ }\expandafter
+ }\forest@marshal
+}
\def\forest@pgfmathhelper@attribute@toks#1#2{%
\forest@forthis{%
\forest@nameandgo{#1}%
- \forestoget{#2}\pgfmathresult
+ \ifnum\forest@cn=0
+ \def\pgfmathresult{}%
+ \else
+ \forestoget{#2}\pgfmathresult
+ \fi
}%
}
\def\forest@pgfmathhelper@attribute@dimen#1#2{%
\forest@forthis{%
\forest@nameandgo{#1}%
- \forestoget{#2}\forest@temp
- \pgfmathparse{+\forest@temp}%
+ \ifnum\forest@cn=0
+ \def\pgfmathresult{0pt}%
+ \else
+ \forestoget{#2}\forest@temp
+ \pgfmathparse{+\forest@temp}%
+ \fi
}%
}
\def\forest@pgfmathhelper@attribute@count#1#2{%
\forest@forthis{%
\forest@nameandgo{#1}%
- \forestoget{#2}\forest@temp
- \pgfmathtruncatemacro\pgfmathresult{\forest@temp}%
+ \ifnum\forest@cn=0
+ \def\pgfmathresult{0}%
+ \else
+ \forestoget{#2}\forest@temp
+ \pgfmathtruncatemacro\pgfmathresult{\forest@temp}%
+ \fi
}%
}
\pgfmathdeclarefunction{id}{1}{%
@@ -2115,6 +2975,1121 @@
},
where id/.style n args={3}{for tree={if id={#1}{#2}{#3}}}
}
+\def\forest@nodewalk@n{0}
+\def\forest@nodewalk@historyback{0,}
+\def\forest@nodewalk@historyforward{0,}
+\def\forest@nodewalk@origin{0}
+\def\forest@nodewalk@config@everystep@independent@before#1{% #1 = every step keylist
+ \forestrset{every step}{#1}%
+}
+\def\forest@nodewalk@config@everystep@independent@after{%
+ \noexpand\forestrset{every step}{\forestrv{every step}}%
+}
+\def\forest@nodewalk@config@history@independent@before{%
+ \def\forest@nodewalk@n{0}%
+ \edef\forest@nodewalk@origin{\forest@cn}%
+ \def\forest@nodewalk@historyback{0,}%
+ \def\forest@nodewalk@historyforward{0,}%
+}
+\def\forest@nodewalk@config@history@independent@after{%
+ \edef\noexpand\forest@nodewalk@n{\expandonce{\forest@nodewalk@n}}%
+ \edef\noexpand\forest@nodewalk@origin{\expandonce{\forest@nodewalk@origin}}%
+ \edef\noexpand\forest@nodewalk@historyback{\expandonce{\forest@nodewalk@historyback}}%
+ \edef\noexpand\forest@nodewalk@historyforward{\expandonce{\forest@nodewalk@historyforward}}%
+}
+\def\forest@nodewalk@config@everystep@shared@before#1{}% #1 = every step keylist
+\def\forest@nodewalk@config@everystep@shared@after{}
+\def\forest@nodewalk@config@history@shared@before{}
+\def\forest@nodewalk@config@history@shared@after{}
+\def\forest@nodewalk@config@everystep@inherited@before#1{}% #1 = every step keylist
+\let\forest@nodewalk@config@everystep@inherited@after\forest@nodewalk@config@everystep@independent@after
+\def\forest@nodewalk@config@history@inherited@before{}
+\let\forest@nodewalk@config@history@inherited@after\forest@nodewalk@config@history@independent@after
+\def\forest@nodewalk#1#2{% #1 = nodewalk, #2 = every step keylist
+ \def\forest@nodewalk@config@everystep@method{independent}%
+ \def\forest@nodewalk@config@history@method{independent}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \forest@Nodewalk{#1}{#2}%
+ }%
+}
+\def\forest@Nodewalk#1#2{% #1 = nodewalk, #2 = every step keylist
+ \edef\forest@marshal{%
+ \noexpand\pgfqkeys{/forest/nodewalk}{\unexpanded{#1}}%
+ \csname forest@nodewalk@config@everystep@\forest@nodewalk@config@everystep@method @after\endcsname
+ \csname forest@nodewalk@config@history@\forest@nodewalk@config@history@method @after\endcsname
+ }%
+ \csname forest@nodewalk@config@everystep@\forest@nodewalk@config@everystep@method @before\endcsname{#2}%
+ \csname forest@nodewalk@config@history@\forest@nodewalk@config@history@method @before\endcsname
+ \forest@nodewalk@fakefalse
+ \forest@marshal
+}
+\pgfmathdeclarefunction{valid}{1}{%
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \edef\pgfmathresult{\ifnum\forest@cn=0 0\else 1\fi}%
+ }%
+}
+\pgfmathdeclarefunction{invalid}{1}{%
+ \forest@forthis{%
+ \forest@nameandgo{#1}%
+ \edef\pgfmathresult{\ifnum\forest@cn=0 1\else 0\fi}%
+ }%
+}
+\newif\ifforest@nodewalk@fake
+\def\forest@nodewalk@oninvalid{error}
+\def\forest@nodewalk@makestep{%
+ \ifnum\forest@cn=0
+ \csname forest@nodewalk@makestep@oninvalid@\forest@nodewalk@config@oninvalid\endcsname
+ \else
+ \forest@nodewalk@makestep@
+ \fi
+}
+\def\forest@nodewalk@makestep@oninvalid@step{\forest@nodewalk@makestep@}
+\def\forest@nodewalk@makestep@oninvalid@error{\PackageError{forest}{nodewalk stepped to the invalid node; stack: "\forest@nodewalk@currentstepname"}{}}%
+\let\forest@nodewalk@makestep@oninvalid@fake\relax
+\def\forest@nodewalk@makestep@oninvalid@compatfake{%
+ \forest@deprecated{last step in stack "\forest@nodewalk@currentstepname", which stepped on an invalid node; enabled by "compat=ignoreinvalidsteps". Use "on invalid={fake}{...}" or "for Nodewalk={on invalid=fake}{...}{...}" instead.}%
+}%
+\def\forest@nodewalk@makestep@oninvalid@inherited{\csname forest@nodewalk@makestep@oninvalid@\forest@nodewalk@oninvalid\endcsname}
+\def\forest@nodewalk@makestep@{%
+ \ifforest@nodewalk@fake
+ \else
+ \edef\forest@nodewalk@n{\number\numexpr\forest@nodewalk@n+1}%
+ \epreto\forest@nodewalk@historyback{\forest@cn,}%
+ \def\forest@nodewalk@historyforward{0,}%
+ \ifforestdebug\forest@nodewalk@makestep@debug\fi
+ \forest@process@keylist@register{every step}%
+ \fi
+}
+\def\forest@nodewalk@makestep@debug{%
+ \edef\forest@marshal{%
+ \noexpand\typeout{\ifforest@nodewalk@fake fake \fi "\forest@nodewalk@currentstepname" step to node id=\forest@cn, content=\forestoption{content}}%
+ }\forest@marshal
+}%
+\forestset{
+ debug/.is if=forestdebug,
+}
+\def\forest@handlers@savecurrentpath{%
+ \edef\pgfkeyscurrentkey{\pgfkeyscurrentpath}%
+ \let\forest@currentkey\pgfkeyscurrentkey
+ \pgfkeys@split@path
+ \edef\forest@currentpath{\pgfkeyscurrentpath}%
+ \let\forest@currentname\pgfkeyscurrentname
+}
+\pgfkeys{/handlers/save current path/.code={\forest@handlers@savecurrentpath}}
+\newif\ifforest@nodewalkstephandler@style
+\newif\ifforest@nodewalkstephandler@autostep
+\newif\ifforest@nodewalkstephandler@stripfakesteps
+\newif\ifforest@nodewalkstephandler@muststartatvalidnode
+\newif\ifforest@nodewalkstephandler@makefor
+\let\forest@nodewalkstephandler@styletrueorfalse\forest@nodewalkstephandler@stylefalse
+\def\forest@nodewalk@currentstepname{}
+\forestset{
+ /forest/define@step/style/.is if=forest@nodewalkstephandler@style,
+ /forest/define@step/autostep/.is if=forest@nodewalkstephandler@autostep,
+ % 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
+ /forest/define@step/strip fake steps/.is if=forest@nodewalkstephandler@stripfakesteps,
+ % this can never happen with autosteps ...
+ /forest/define@step/autostep/.append code={%
+ \ifforest@nodewalkstephandler@autostep
+ \forest@nodewalkstephandler@stripfakestepsfalse
+ \fi
+ },
+ /forest/define@step/must start at valid node/.is if=forest@nodewalkstephandler@muststartatvalidnode,
+ /forest/define@step/n args/.store in=\forest@nodewalkstephandler@nargs,
+ /forest/define@step/make for/.is if=forest@nodewalkstephandler@makefor,
+ /forest/define@step/@bare/.style={strip fake steps=false,must start at valid node=false,make for=false},
+ define long step/.code n args=3{%
+ \forest@nodewalkstephandler@styletrueorfalse % true for end users; but in the package, most of steps are defined by .code
+ \forest@nodewalkstephandler@autostepfalse
+ \forest@nodewalkstephandler@stripfakestepstrue
+ \forest@nodewalkstephandler@muststartatvalidnodetrue % most steps can only start at a valid node
+ \forest@nodewalkstephandler@makefortrue % make for prefix?
+ \def\forest@nodewalkstephandler@nargs{0}%
+ \pgfqkeys{/forest/define@step}{#2}%
+ \forest@temp@toks{#3}% handler code
+ \ifforest@nodewalkstephandler@style
+ \expandafter\forest@temp@toks\expandafter{%
+ \expandafter\pgfkeysalso\expandafter{\the\forest@temp@toks}%
+ }%
+ \fi
+ \ifforest@nodewalkstephandler@autostep
+ \apptotoks\forest@temp@toks{\forest@nodewalk@makestep}%
+ \fi
+ \ifforest@nodewalkstephandler@stripfakesteps
+ \expandafter\forest@temp@toks\expandafter{\expandafter\forest@nodewalk@stripfakesteps\expandafter{\the\forest@temp@toks}}%
+ \fi
+ \ifforest@nodewalkstephandler@muststartatvalidnode
+ \edef\forest@marshal{%
+ \noexpand\forest@temp@toks{%
+ \unexpanded{%
+ \ifnum\forest@cn=0
+ \csname forest@nodewalk@start@oninvalid@\forest@nodewalk@oninvalid\endcsname{#1}%
+ \else
+ }%
+ \noexpand\@escapeif{\the\forest@temp@toks}%
+ \noexpand\fi
+ }%
+ }\forest@marshal
+ \fi
+ \pretotoks\forest@temp@toks{\appto\forest@nodewalk@currentstepname{,#1}}%
+ \expandafter\forest@temp@toks\expandafter{\expandafter\forest@saveandrestoremacro\expandafter\forest@nodewalk@currentstepname\expandafter{\the\forest@temp@toks}}%
+ \ifforestdebug
+ \epretotoks\forest@temp@toks{\noexpand\typeout{Starting step "#1" from id=\forest@cn
+ \ifnum\forest@nodewalkstephandler@nargs>0 with args ####1\fi
+ \ifnum\forest@nodewalkstephandler@nargs>1 ,####2\fi
+ \ifnum\forest@nodewalkstephandler@nargs>2 ,####3\fi
+ \ifnum\forest@nodewalkstephandler@nargs>3 ,####4\fi
+ \ifnum\forest@nodewalkstephandler@nargs>4 ,####5\fi
+ \ifnum\forest@nodewalkstephandler@nargs>5 ,####6\fi
+ \ifnum\forest@nodewalkstephandler@nargs>6 ,####7\fi
+ \ifnum\forest@nodewalkstephandler@nargs>7 ,####8\fi
+ \ifnum\forest@nodewalkstephandler@nargs>8 ,####9\fi
+ }}%
+ \fi
+ \def\forest@temp{/forest/nodewalk/#1/.code}%
+ \ifnum\forest@nodewalkstephandler@nargs<2
+ \eappto\forest@temp{=}%
+ \else\ifnum\forest@nodewalkstephandler@nargs=2
+ \eappto\forest@temp{ 2 args=}%
+ \else
+ \eappto\forest@temp{ n args={\forest@nodewalkstephandler@nargs}}%
+ \fi\fi
+ \eappto\forest@temp{{\the\forest@temp@toks}}%
+ \expandafter\pgfkeysalso\expandafter{\forest@temp}%
+ \ifforest@nodewalkstephandler@makefor
+ \ifnum\forest@nodewalkstephandler@nargs=0
+ \forestset{%
+ for #1/.code={\forest@forstepwrapper{#1}{##1}},
+ }%
+ \else\ifnum\forest@nodewalkstephandler@nargs=1
+ \forestset{%
+ for #1/.code 2 args={\forest@forstepwrapper{#1={##1}}{##2}},
+ }%
+ \else
+ \forestset{%
+ for #1/.code n args/.expanded=%
+ {\number\numexpr\forest@nodewalkstephandler@nargs+1}%
+ {\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}},
+ }%
+ \fi\fi
+ \fi
+ },
+}
+\def\forest@forstepwrapper#1#2{\forest@forthis{\forest@nodewalk{#1}{#2}}}
+\def\forest@util@nargs#1#2#3{% #1 = prefix (#, ##, ...), #2 = n args, #3=start; returns {#start}{#start+1}...{#start+n}
+ \ifnum#2>0 {#1\number\numexpr#3+1}\fi
+ \ifnum#2>1 {#1\number\numexpr#3+2}\fi
+ \ifnum#2>2 {#1\number\numexpr#3+3}\fi
+ \ifnum#2>3 {#1\number\numexpr#3+4}\fi
+ \ifnum#2>4 {#1\number\numexpr#3+5}\fi
+ \ifnum#2>5 {#1\number\numexpr#3+6}\fi
+ \ifnum#2>6 {#1\number\numexpr#3+7}\fi
+ \ifnum#2>7 {#1\number\numexpr#3+8}\fi
+ \ifnum#2>8 {#1\number\numexpr#3+9}\fi
+}
+\def\forest@nodewalk@start@oninvalid@fake#1{}
+\def\forest@nodewalk@start@oninvalid@real#1{}
+\def\forest@nodewalk@start@oninvalid@error#1{\PackageError{forest}{nodewalk step "#1" cannot start at the invalid node}{}}
+\forestset{
+ define long step={current}{autostep}{},
+ define long step={next}{autostep}{\edef\forest@cn{\forestove{@next}}},
+ define long step={previous}{autostep}{\edef\forest@cn{\forestove{@previous}}},
+ define long step={parent}{autostep}{\edef\forest@cn{\forestove{@parent}}},
+ define long step={first}{autostep}{\edef\forest@cn{\forestove{@first}}},
+ define long step={last}{autostep}{\edef\forest@cn{\forestove{@last}}},
+ define long step={sibling}{autostep}{%
+ \edef\forest@cn{%
+ \ifnum\forestove{@previous}=0
+ \forestove{@next}%
+ \else
+ \forestove{@previous}%
+ \fi
+ }%
+ },
+ define long step={next node}{autostep}{\edef\forest@cn{\forest@node@linearnextid}},
+ define long step={previous node}{autostep}{\edef\forest@cn{\forest@node@linearpreviousid}},
+ define long step={first leaf}{autostep}{%
+ \safeloop
+ \edef\forest@cn{\forestove{@first}}%
+ \unless\ifnum\forestove{@first}=0
+ \saferepeat
+ },
+ define long step={first leaf'}{autostep}{%
+ \safeloop
+ \unless\ifnum\forestove{@first}=0
+ \edef\forest@cn{\forestove{@first}}%
+ \saferepeat
+ },
+ define long step={last leaf}{autostep}{%
+ \safeloop
+ \edef\forest@cn{\forestove{@last}}%
+ \unless\ifnum\forestove{@last}=0
+ \saferepeat
+ },
+ define long step={last leaf'}{autostep}{%
+ \safeloop
+ \unless\ifnum\forestove{@last}=0
+ \edef\forest@cn{\forestove{@last}}%
+ \saferepeat
+ },
+ define long step={next leaf}{style,strip fake steps=false}{group={do until={n_children()==0}{next node}}},
+ define long step={previous leaf}{style,strip fake steps=false}{group={do until={n_children()==0}{previous node}}},
+ define long step={next on tier}{autostep}{%
+ \def\forest@temp{#1}%
+ \ifx\forest@temp\pgfkeysnovalue@text
+ \forestoget{tier}\forest@nodewalk@giventier
+ \else
+ \def\forest@nodewalk@giventier{#1}%
+ \fi
+ \edef\forest@cn{\forest@node@linearnextnotdescendantid}%
+ \safeloop
+ \forestoget{tier}\forest@nodewalk@tier
+ \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
+ \edef\forest@cn{\forest@node@linearnextid}%
+ \saferepeat
+ },
+ define long step={previous on tier}{autostep}{%
+ \def\forest@temp{#1}%
+ \ifx\forest@temp\pgfkeysnovalue@text
+ \forestoget{tier}\forest@nodewalk@giventier
+ \else
+ \def\forest@nodewalk@giventier{#1}%
+ \fi
+ \safeloop
+ \edef\forest@cn{\forest@node@linearpreviousid}%
+ \forestoget{tier}\forest@nodewalk@tier
+ \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
+ \saferepeat
+ },
+ %
+ define long step={root}{autostep,must start at valid node=false}{%
+ \edef\forest@cn{\forest@node@rootid}},
+ define long step={root'}{autostep,must start at valid node=false}{%
+ \forestOifdefined{\forest@root}{@parent}{\edef\forest@cn{\forest@root}}{\edef\forest@cn{0}}%
+ },
+ define long step={origin}{autostep,must start at valid node=false}{\edef\forest@cn{\forest@nodewalk@origin}},
+ %
+ define long step={n}{autostep,n args=1}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \edef\forest@cn{\forest@node@nthchildid{\forest@temp@n}}%
+ },
+ define long step={n}{autostep,make for=false,n args=1}{%
+ % Yes, twice. ;-)
+ % n=1 and n(ext)
+ \def\forest@nodewalk@temp{#1}%
+ \ifx\forest@nodewalk@temp\pgfkeysnovalue@text
+ \edef\forest@cn{\forestove{@next}}%
+ \else
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \edef\forest@cn{\forest@node@nthchildid{\forest@temp@n}}%
+ \fi
+ },
+ define long step={n'}{autostep,n args=1}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \edef\forest@cn{\forest@node@nbarthchildid{\forest@temp@n}}%
+ },
+ define long step={to tier}{autostep,n args=1}{%
+ \def\forest@nodewalk@giventier{#1}%
+ \safeloop
+ \forestoget{tier}\forest@nodewalk@tier
+ \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
+ \forestoget{@parent}\forest@cn
+ \saferepeat
+ },
+ %
+ define long step={name}{autostep,n args=1,must start at valid node=false}{%
+ \edef\forest@cn{%
+ \forest@node@Ifnamedefined{#1}{\forest@node@Nametoid{#1}}{0}%
+ }%
+ },
+ define long step={id}{autostep,n args=1,must start at valid node=false}{%
+ \forestOifdefined{#1}{@parent}{\edef\forest@cn{#1}}{\edef\forest@cn{0}}%
+ },
+ define long step={Nodewalk}{n args=3,@bare}{% #1 = config, #2 = nodewalk
+ \def\forest@nodewalk@config@everystep@method{independent}%
+ \def\forest@nodewalk@config@history@method{shared}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \pgfqkeys{/forest/nodewalk@config}{#1}%
+ \forest@Nodewalk{#2}{#3}%
+ }%
+ },
+ define long step={nodewalk}{n args=2,@bare}{% #1 = nodewalk, #2 = every step
+ \forest@nodewalk{#1}{#2}%
+ },
+ define long step={nodewalk'}{n args=1,@bare}{% #1 = nodewalk, #2 = every step
+ \def\forest@nodewalk@config@everystep@method{inherited}%
+ \def\forest@nodewalk@config@history@method{independent}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \forest@Nodewalk{#1}{}%
+ }%
+ },
+ % these must be defined explicitely, as prefix "for" normally introduces the every-step keylist
+ for nodewalk/.code 2 args={%
+ \forest@forthis{\forest@nodewalk{#1}{#2}}},
+ for nodewalk'/.code={%
+ \def\forest@nodewalk@config@everystep@method{inherited}%
+ \def\forest@nodewalk@config@history@method{independent}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \forest@forthis{\forest@Nodewalk{#1}{}}%
+ }%
+ },
+ for Nodewalk/.code n args=3{% #1 = config, #2 = nodewalk, #3 = every-step
+ \def\forest@nodewalk@config@everystep@method{inherited}%
+ \def\forest@nodewalk@config@history@method{independent}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \pgfqkeys{/forest/nodewalk@config}{#1}%
+ \forest@forthis{\forest@Nodewalk{#2}{#3}}%
+ }%
+ },
+ copy command key={/forest/for nodewalk}{/forest/nodewalk/for nodewalk},
+ copy command key={/forest/for nodewalk'}{/forest/nodewalk/for nodewalk'},
+ copy command key={/forest/for Nodewalk}{/forest/nodewalk/for Nodewalk},
+ declare keylist register=every step,
+ every step'={},
+ %%% begin nodewalk config
+ nodewalk@config/.cd,
+ every@step/.is choice,
+ every@step/independent/.code={},
+ every@step/inherited/.code={},
+ every@step/shared/.code={},
+ every step/.store in=\forest@nodewalk@config@everystep@method,
+ every step/.prefix style={every@step=#1},
+ @history/independent/.code={},
+ @history/inherited/.code={},
+ @history/shared/.code={},
+ history/.store in=\forest@nodewalk@config@history@method,
+ history/.prefix style={@history=#1},
+ on@invalid/.is choice,
+ on@invalid/error/.code={},
+ on@invalid/fake/.code={},
+ on@invalid/step/.code={},
+ on@invalid/inherited/.code={},
+ on invalid/.store in=\forest@nodewalk@config@oninvalid,
+ on invalid/.prefix style={on@invalid=#1},
+ %%% end nodewalk config
+}
+\forestset{
+ define long step={branch}{n args=1,@bare,style}{%
+ branch@@build/.style={branch@build={##1}{}},
+ @branch={#1},
+ },
+ define long step={branch'}{n args=1,@bare,style}{%
+ branch@@build/.style/.expanded={branch@build={####1}{\forestregister{every step},}},
+ @branch={#1},
+ },
+ nodewalk/@branch/.style={
+ TeX={\forest@temp@toks{}},
+ split/.process args={r}{#1}{,}{branch@@build},
+ branch@do,
+ },
+ nodewalk/branch@build/.code 2 args={% #1 = nodewalk for this branch, #2 = perhaps every step keylist
+ \ifstrempty{#1}{}{%
+ \expandafter\ifstrempty\expandafter{\the\forest@temp@toks}{%
+ \edef\forest@marshal{%
+ \noexpand\forest@temp@toks{for nodewalk={\unexpanded{#1}}{\forestregister{every step}}}%
+ }\forest@marshal
+ }{%
+ \edef\forest@marshal{%
+ \noexpand\forest@temp@toks{for nodewalk={\unexpanded{#1}}{#2\the\forest@temp@toks}}%
+ }\forest@marshal
+ }%
+ }%
+ },
+ nodewalk/branch@do/.code={%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{fake={\the\forest@temp@toks}}%
+ }\forest@marshal
+ },
+ define long step={group}{autostep}{\forest@go{#1}},
+ nodewalk/fake/.code={%
+ \forest@saveandrestoreifcs{forest@nodewalk@fake}{%
+ \forest@nodewalk@faketrue
+ \pgfkeysalso{#1}%
+ }%
+ },
+ nodewalk/real/.code={%
+ \forest@saveandrestoreifcs{forest@nodewalk@fake}{%
+ \forest@nodewalk@fakefalse
+ \pgfkeysalso{#1}%
+ }%
+ },
+ define long step={filter}{n args=2,@bare,style}{% #1 = nodewalk, #2 = condition
+ nodewalk/.expanded={\unexpanded{#1}}{if={\unexpanded{#2}}{\forestregister{every step}}{}}{}
+ },
+ on@invalid/.is choice,
+ on@invalid/error/.code={},
+ on@invalid/fake/.code={},
+ on@invalid/step/.code={},
+ on invalid/.code 2 args={%
+ \pgfkeysalso{/forest/on@invalid={#1}}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \def\forest@nodewalk@oninvalid{#1}%
+ \pgfkeysalso{#2}%
+ }%
+ },
+ define long step={strip fake steps}{n args=1,@bare}{%
+ \forest@nodewalk@stripfakesteps{\pgfkeysalso{#1}}},
+ define long step={walk back}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \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}%
+ \forest@nodewalk@back@updatehistory
+ },
+ nodewalk/walk back/.default=1,
+ define long step={jump back}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{(#1)+\ifnum\forest@cn=0 0\else1\fi}%
+ \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}%
+ \forest@nodewalk@back@updatehistory
+ },
+ nodewalk/jump back/.default=1,
+ define long step={back}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \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}}%
+ \forest@nodewalk@back@updatehistory
+ },
+ nodewalk/back/.default=1,
+ define long step={walk forward}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \forest@nodewalk@walklist{\forest@nodewalk@historyback}{\forest@nodewalk@historyforward}{0}{\forest@temp@n}{\let\forest@cn\forest@nodewalk@cn\forest@nodewalk@makestep}%
+ \forest@nodewalk@forward@updatehistory
+ },
+ nodewalk/walk forward/.default=1,
+ define long step={jump forward}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \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}%
+ \forest@nodewalk@forward@updatehistory
+ },
+ nodewalk/jump forward/.default=1,
+ define long step={forward}{n args=1,@bare}{%
+ \pgfmathtruncatemacro\forest@temp@n{#1}%
+ \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}}%
+ \forest@nodewalk@forward@updatehistory
+ },
+ nodewalk/forward/.default=1,
+ define long step={last valid'}{@bare}{%
+ \ifnum\forest@cn=0
+ \forest@nodewalk@tolastvalid
+ \forest@nodewalk@makestep
+ \fi
+ },
+ define long step={last valid}{@bare}{%
+ \forest@nodewalk@tolastvalid
+ },
+ define long step={reverse}{n args=1,@bare,make for}{%
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ \global\let\forest@global@tempn\forest@nodewalk@n
+ }}{}%
+ \forest@nodewalk@walklist{}{\forest@global@temp}{0}{\forest@global@tempn}{\let\forest@cn\forest@nodewalk@cn\forest@nodewalk@makestep}%
+ },
+ define long step={walk and reverse}{n args=1,@bare,make for}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \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}%
+ }\forest@marshal
+ },
+ define long step={sort}{n args=1,@bare,make for}{%
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ \global\let\forest@global@tempn\forest@nodewalk@n
+ }}{}%
+ \forest@nodewalk@sortlist{\forest@global@temp}{\forest@global@tempn}\forest@sort@ascending
+ },
+ define long step={sort'}{n args=1,@bare,make for}{%
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ \global\let\forest@global@tempn\forest@nodewalk@n
+ }}{}%
+ \forest@nodewalk@sortlist{\forest@global@temp}{\forest@global@tempn}\forest@sort@descending
+ },
+ define long step={walk and sort}{n args=1,@bare,make for}{% walk as given, then walk sorted
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@sortlist{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}\noexpand\forest@sort@ascending
+ }\forest@marshal
+ },
+ define long step={walk and sort'}{n args=1,@bare,make for}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@sortlist{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}\noexpand\forest@sort@descending
+ }\forest@marshal
+ },
+ sort by/.store in=\forest@nodesort@by,
+ define long step={save}{n args=2,@bare,make for}{% #1 = name, #2 = nodewalk
+ \forest@forthis{%
+ \forest@nodewalk{#2,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ \global\let\forest@global@tempn\forest@nodewalk@n
+ }}{}%
+ }%
+ \forest@nodewalk@walklist{}{\forest@global@temp}{0}{\forest@global@tempn}\relax
+ \csedef{forest@nodewalk@saved@#1}{\forest@nodewalk@walklist@walked}%
+ },
+ define long step={walk and save}{n args=2,@bare,make for}{% #1 = name, #2 = nodewalk
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#2}}%
+ \noexpand\forest@nodewalk@walklist{}{\noexpand\forest@nodewalk@historyback}{0}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}\relax
+ }\forest@marshal
+ \csedef{forest@nodewalk@saved@#1}{\forest@nodewalk@walklist@walked}%
+ },
+ nodewalk/save history/.code 2 args={% #1 = back, forward
+ \csedef{forest@nodewalk@saved@#1}{\forest@nodewalk@historyback}%
+ \csedef{forest@nodewalk@saved@#2}{\forest@nodewalk@historyforward}%
+ },
+ define long step={load}{n args=1,@bare,make for}{%
+ \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}%
+ },
+ if in saved nodewalk/.code n args=4{% is node #1 in nodewalk #2; yes: #3, no: #4
+ \forest@forthis{%
+ \forest@go{#1}%
+ \edef\forest@marshal{%
+ \noexpand\pgfutil@in@{,\forest@cn,}{,\csuse{forest@nodewalk@saved@#2},}%
+ }\forest@marshal
+ }%
+ \ifpgfutil@in@
+ \@escapeif{\pgfkeysalso{#3}}%
+ \else
+ \@escapeif{\pgfkeysalso{#4}}%
+ \fi
+ },
+ where in saved nodewalk/.style n args=4{
+ for tree={if in saved nodewalk={#1}{#2}{#3}{#4}}
+ },
+ nodewalk/options/.code={\forestset{#1}},
+ nodewalk/TeX/.code={#1},
+ nodewalk/TeX'/.code={\appto\forest@externalize@loadimages{#1}#1},
+ nodewalk/TeX''/.code={\appto\forest@externalize@loadimages{#1}},
+ nodewalk/typeout/.style={TeX={\typeout{#1}}},
+ % repeat is taken later from /forest/repeat
+}
+\def\forest@nodewalk@walklist#1#2#3#4#5{%
+ % #1 = list of preceding, #2 = list to walk
+ % #3 = from, #4 = to
+ % #5 = every step code
+ \let\forest@nodewalk@cn\forest@cn
+ \edef\forest@marshal{%
+ \noexpand\forest@nodewalk@walklist@{#1}{#2}{\number\numexpr#3}{\number\numexpr#4}{1}{0}{\unexpanded{#5}}%
+ }\forest@marshal
+}
+\def\forest@nodewalk@walklist@#1#2#3#4#5#6#7{%
+ % #1 = list of walked, #2 = list to walk
+ % #3 = from, #4 = to
+ % #5 = current step n, #6 = steps made
+ % #7 = every step code
+ \def\forest@nodewalk@walklist@walked{#1}%
+ \def\forest@nodewalk@walklist@rest{#2}%
+ \edef\forest@nodewalk@walklist@stepsmade{#6}%
+ \ifnum#4<0
+ \forest@temptrue
+ \else
+ \ifnum#5>#4\relax
+ \forest@tempfalse
+ \else
+ \forest@temptrue
+ \fi
+ \fi
+ \ifforest@temp
+ \edef\forest@nodewalk@cn{\forest@csvlist@getfirst@{#2}}%
+ \ifnum\forest@nodewalk@cn=0
+ #7%
+ \else
+ \ifnum#5>#3\relax
+ #7%
+ \edef\forest@nodewalk@walklist@stepsmade{\number\numexpr#6+1}%
+ \fi
+ \forest@csvlist@getfirstrest@{#2}\forest@nodewalk@cn\forest@nodewalk@walklist@rest
+ \@escapeifif{%
+ \edef\forest@marshal{%
+ \noexpand\forest@nodewalk@walklist@
+ {\forest@nodewalk@cn,#1}{\forest@nodewalk@walklist@rest}{#3}{#4}{\number\numexpr#5+1}{\forest@nodewalk@walklist@stepsmade}{\unexpanded{#7}}%
+ }\forest@marshal
+ }%
+ \fi
+ \fi
+}
+
+\def\forest@nodewalk@back@updatehistory{%
+ \ifnum\forest@cn=0
+ \let\forest@nodewalk@historyback\forest@nodewalk@walklist@rest
+ \let\forest@nodewalk@historyforward\forest@nodewalk@walklist@walked
+ \else
+ \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalk@walklist@walked}\forest@temp\forest@nodewalk@historyforward
+ \edef\forest@nodewalk@historyback{\forest@temp,\forest@nodewalk@walklist@rest}%
+ \fi
+}
+\def\forest@nodewalk@forward@updatehistory{%
+ \let\forest@nodewalk@historyforward\forest@nodewalk@walklist@rest
+ \let\forest@nodewalk@historyback\forest@nodewalk@walklist@walked
+}
+\def\forest@go#1{%
+ \def\forest@nodewalk@config@everystep@method{independent}%
+ \def\forest@nodewalk@config@history@method{inherited}%
+ \def\forest@nodewalk@config@oninvalid{inherited}%
+ \forest@saveandrestoremacro\forest@nodewalk@oninvalid{%
+ \forest@Nodewalk{#1}{}%
+ }%
+}
+\def\forest@csvlist@getfirst@#1{% assuming that the list is nonempty and finishes with a comma
+ \forest@csvlist@getfirst@@#1\forest@csvlist@getfirst@@}
+\def\forest@csvlist@getfirst@@#1,#2\forest@csvlist@getfirst@@{#1}
+\def\forest@csvlist@getrest@#1{% assuming that the list is nonempty and finishes with a comma
+ \forest@csvlist@getrest@@#1\forest@csvlist@getrest@@}
+\def\forest@csvlist@getrest@@#1,#2\forest@csvlist@getrest@@{#2}
+\def\forest@csvlist@getfirstrest@#1#2#3{% assuming that the list is nonempty and finishes with a comma
+ % #1 = list, #2 = cs receiving first, #3 = cs receiving rest
+ \forest@csvlist@getfirstrest@@#1\forest@csvlist@getfirstrest@@{#2}{#3}}
+\def\forest@csvlist@getfirstrest@@#1,#2\forest@csvlist@getfirstrest@@#3#4{%
+ \def#3{#1}%
+ \def#4{#2}%
+}
+\def\forest@nodewalk@stripfakesteps#1{%
+ % go to the last valid node if the walk contained any nodes, otherwise restore the current node
+ \edef\forest@marshal{%
+ \unexpanded{#1}%
+ \noexpand\ifnum\noexpand\forest@nodewalk@n=\forest@nodewalk@n\relax
+ \def\noexpand\forest@cn{\forest@cn}%
+ \noexpand\else
+ \unexpanded{%
+ \edef\forest@cn{%
+ \expandafter\forest@csvlist@getfirst@\expandafter{\forest@nodewalk@historyback}%
+ }%
+ }%
+ \noexpand\fi
+ }\forest@marshal
+}
+\def\forest@nodewalk@tolastvalid{%
+ \ifnum\forest@cn=0
+ \edef\forest@cn{\expandafter\forest@csvlist@getfirst@\expandafter{\forest@nodewalk@historyback}}%
+ \ifnum\forest@cn=0
+ \let\forest@cn\forest@nodewalk@origin
+ \fi
+ \fi
+}
+\def\forest@nodewalk@sortlist#1#2#3{%#1=list,#2=to,#3=asc/desc
+ \edef\forest@nodewalksort@list{#1}%
+ \expandafter\forest@nodewalk@sortlist@\expandafter{\number\numexpr#2}{#3}%
+}
+\def\forest@nodewalk@sortlist@#1#2{%#1=to,#2=asc/desc
+ \safeloop
+ \unless\ifnum\safeloopn>#1\relax
+ \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalksort@list}\forest@nodewalksort@cn\forest@nodewalksort@list
+ \csedef{forest@nodesort@\safeloopn}{\forest@nodewalksort@cn}%
+ \saferepeat
+ \edef\forest@nodesort@sortkey{\forest@nodesort@by}%
+ \forest@sort\forest@nodesort@cmpnodes\forest@nodesort@let#2{1}{#1}%
+ \def\forest@nodewalksort@sorted{}%
+ \safeloop
+ \unless\ifnum\safeloopn>#1\relax
+ \edef\forest@cn{\csname forest@nodesort@\safeloopn\endcsname}%
+ \forest@nodewalk@makestep
+ \saferepeat
+}
+\forestset{
+ define long step={min}{n args=1,@bare,make for}{% the first min in the argument nodewalk
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ }}{}%
+ \forest@nodewalk@minmax{\forest@global@temp}{-1}{<}{\forest@nodewalk@minmax@node,}%
+ },
+ define long step={mins}{n args=1,@bare,make for}{% all mins in the argument nodewalk
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ }}{}%
+ \forest@nodewalk@minmax{\forest@global@temp}{-1}{<}{\forest@nodewalk@minmax@nodes}%
+ },
+ define long step={walk and min}{n args=1,@bare}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{<}{\noexpand\forest@nodewalk@minmax@node,}%%
+ }\forest@marshal
+ },
+ define long step={walk and mins}{n args=1,@bare}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{<}{\noexpand\forest@nodewalk@minmax@nodes}%%
+ }\forest@marshal
+ },
+ define long step={min in nodewalk}{@bare}{% find the first min in the preceding nodewalk, step to it
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{<}{\forest@nodewalk@minmax@node,}%
+ },
+ define long step={mins in nodewalk}{@bare}{% find mins in the preceding nodewalk, step to mins
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{<}{\forest@nodewalk@minmax@nodes}%
+ },
+ define long step={min in nodewalk'}{@bare}{% find the first min in the preceding nodewalk, step to min in history
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{<}{}%
+ },
+ %
+ define long step={max}{n args=1,@bare,make for}{% the first max in the argument nodewalk
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ }}{}%
+ \forest@nodewalk@minmax{\forest@global@temp}{-1}{>}{\forest@nodewalk@minmax@node,}%
+ },
+ define long step={maxs}{n args=1,@bare,make for}{% all maxs in the argument nodewalk
+ \forest@nodewalk{#1,TeX={%
+ \global\let\forest@global@temp\forest@nodewalk@historyback
+ }}{}%
+ \forest@nodewalk@minmax{\forest@global@temp}{-1}{>}{\forest@nodewalk@minmax@nodes}%
+ },
+ define long step={walk and max}{n args=1,@bare}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{>}{\noexpand\forest@nodewalk@minmax@node,}%%
+ }\forest@marshal
+ },
+ define long step={walk and maxs}{n args=1,@bare}{%
+ \edef\forest@marshal{%
+ \noexpand\pgfkeysalso{\unexpanded{#1}}%
+ \noexpand\forest@nodewalk@minmax{\noexpand\forest@nodewalk@historyback}{\noexpand\forest@nodewalk@n-\forest@nodewalk@n}{>}{\noexpand\forest@nodewalk@minmax@nodes}%%
+ }\forest@marshal
+ },
+ define long step={max in nodewalk}{@bare}{% find the first max in the preceding nodewalk, step to it
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{>}{\forest@nodewalk@minmax@node,}%
+ },
+ define long step={maxs in nodewalk}{@bare}{% find maxs in the preceding nodewalk, step to maxs
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{>}{\forest@nodewalk@minmax@nodes}%
+ },
+ define long step={max in nodewalk'}{@bare}{% find the first max in the preceding nodewalk, step to max in history
+ \forest@nodewalk@minmax{\forest@nodewalk@historyback}{-1}{>}{}%
+ },
+}
+
+\def\forest@nodewalk@minmax#1#2#3#4{%
+ % #1 = list of nodes
+ % #2 = max index in list (start with 1)
+ % #3 = min/max = ascending/descending = </>
+ % #4 = how many results? 1 = {\forest@nodewalk@minmax@node,}, all={\forest@nodewalk@minmax@nodes}, walk in history={}
+ \edef\forest@nodesort@sortkey{\forest@nodesort@by}%
+ \edef\forest@nodewalk@minmax@N{\number\numexpr#2}%
+ \edef\forest@nodewalk@minmax@n{}%
+ \edef\forest@nodewalk@minmax@list{#1}%
+ \def\forest@nodewalk@minmax@nodes{}%
+ \def\forest@nodewalk@minmax@node{}%
+ \ifdefempty{\forest@nodewalk@minmax@list}{%
+ }{%
+ \safeloop
+ \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalk@minmax@list}\forest@nodewalk@minmax@cn\forest@nodewalk@minmax@list
+ \ifnum\forest@nodewalk@minmax@cn=0 \else
+ \ifdefempty{\forest@nodewalk@minmax@node}{%
+ \edef\forest@nodewalk@minmax@node{\forest@nodewalk@minmax@cn}%
+ \edef\forest@nodewalk@minmax@nodes{\forest@nodewalk@minmax@cn,}%
+ \edef\forest@nodewalk@minmax@n{\safeloopn}%
+ }{%
+ \csedef{forest@nodesort@1}{\forest@nodewalk@minmax@node}%
+ \csedef{forest@nodesort@2}{\forest@nodewalk@minmax@cn}%
+ \forest@nodesort@cmpnodes{2}{1}%
+ \if=\forest@sort@cmp@result
+ \edef\forest@nodewalk@minmax@node{\forest@nodewalk@minmax@cn}%
+ \epreto\forest@nodewalk@minmax@nodes{\forest@nodewalk@minmax@cn,}%
+ \edef\forest@nodewalk@minmax@n{\safeloopn}%
+ \else
+ \if#3\forest@sort@cmp@result
+ \edef\forest@nodewalk@minmax@node{\forest@nodewalk@minmax@cn}%
+ \edef\forest@nodewalk@minmax@nodes{\forest@nodewalk@minmax@cn,}%
+ \edef\forest@nodewalk@minmax@n{\safeloopn}%
+ \fi
+ \fi
+ }%
+ \fi
+ \ifdefempty{\forest@nodewalk@minmax@list}{\forest@tempfalse}{\forest@temptrue}%
+ \ifnum\safeloopn=\forest@nodewalk@minmax@N\relax\forest@temptrue\fi
+ \ifforest@temp
+ \saferepeat
+ \edef\forest@nodewalk@minmax@list{#4}%
+ \ifdefempty\forest@nodewalk@minmax@list{%
+ \forestset{nodewalk/jump back=\forest@nodewalk@minmax@n-1}% CHECK
+ }{%
+ \safeloop
+ \expandafter\forest@csvlist@getfirstrest@\expandafter{\forest@nodewalk@minmax@list}\forest@cn\forest@nodewalk@minmax@list
+ \forest@nodewalk@makestep
+ \ifdefempty{\forest@nodewalk@minmax@list}{\forest@tempfalse}{\forest@temptrue}%
+ \ifforest@temp
+ \saferepeat
+ }%
+ }%
+}
+\newtoks\forest@nodewalk@shortsteps@resolution
+\newif\ifforest@nodewalk@areshortsteps
+\pgfqkeys{/forest/nodewalk}{
+ .unknown/.code={%
+ \forest@nodewalk@areshortstepsfalse
+ \pgfkeysifdefined{/forest/\pgfkeyscurrentname/@.cmd}{%
+ }{%
+ \ifx\pgfkeyscurrentvalue\pgfkeysnovalue@text % no value, so possibly short steps
+ \forest@nodewalk@shortsteps@resolution{}%
+ \forest@nodewalk@areshortstepstrue
+ \expandafter\forest@nodewalk@shortsteps\pgfkeyscurrentname==========,% "=" and "," cannot be short steps, so they are good as delimiters
+ \fi
+ }%
+ \ifforest@nodewalk@areshortsteps
+ \@escapeif{\expandafter\pgfkeysalso\expandafter{\the\forest@nodewalk@shortsteps@resolution}}%
+ \else
+ \@escapeif{\pgfkeysalso{/forest/\pgfkeyscurrentname={#1}}}%
+ \fi
+ },
+}
+\def\forest@nodewalk@shortsteps{%
+ \futurelet\forest@nodewalk@nexttoken\forest@nodewalk@shortsteps@
+}
+\def\forest@nodewalk@shortsteps@{%
+ \ifx\forest@nodewalk@nexttoken=%
+ \let\forest@nodewalk@nextop\forest@nodewalk@shortsteps@end
+ \else
+ \ifx\forest@nodewalk@nexttoken\bgroup
+ \letcs\forest@nodewalk@nextop{forest@shortstep@group}%
+ \else
+ \let\forest@nodewalk@nextop\forest@nodewalk@shortsteps@@
+ \fi
+ \fi
+ \forest@nodewalk@nextop
+}
+\def\forest@nodewalk@shortsteps@@#1{%
+ \ifcsdef{forest@shortstep@#1}{%
+ \csname forest@shortstep@#1\endcsname
+ }{%
+ \forest@nodewalk@areshortstepsfalse
+ \forest@nodewalk@shortsteps@end
+ }%
+}
+\csdef{forest@nodewalk@defshortstep@0@args}#1#2{%
+ \csdef{forest@shortstep@#1}{%
+ \apptotoks\forest@nodewalk@shortsteps@resolution{,#2}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@1@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1{%
+ \edef\forest@marshal####1{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@2@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2{%
+ \edef\forest@marshal####1####2{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@3@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3{%
+ \edef\forest@marshal####1####2####3{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@4@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4{%
+ \edef\forest@marshal####1####2####3####4{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@5@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4##5{%
+ \edef\forest@marshal####1####2####3####4####5{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@6@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4##5##6{%
+ \edef\forest@marshal####1####2####3####4####5####6{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@7@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4##5##6##7{%
+ \edef\forest@marshal####1####2####3####4####5####6####7{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}{##7}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@8@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4##5##6##7##8{%
+ \edef\forest@marshal####1####2####3####4####5####6####7####8{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}}%
+ \forest@nodewalk@shortsteps}}
+\csdef{forest@nodewalk@defshortstep@9@args}#1#2{%
+ \csdef{forest@shortstep@#1}##1##2##3##4##5##6##7##8##9{%
+ \edef\forest@marshal####1####2####3####4####5####6####7####8####9{#2}%
+ \eapptotoks\forest@nodewalk@shortsteps@resolution{,\forest@marshal{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}{##9}}%
+ \forest@nodewalk@shortsteps}}
+\forestset{
+ define short step/.code n args=3{% #1 = short step, #2 = n args, #3 = long step
+ \csname forest@nodewalk@defshortstep@#2@args\endcsname{#1}{#3}%
+ },
+}
+\def\forest@nodewalk@shortsteps@end#1,{}
+\forestset{
+ define short step={group}{1}{group={#1}}, % {braces} are special
+ define short step={p}{0}{previous},
+ define short step={n}{0}{next},
+ define short step={u}{0}{parent},
+ define short step={s}{0}{sibling},
+ define short step={c}{0}{current},
+ define short step={o}{0}{origin},
+ define short step={r}{0}{root},
+ define short step={R}{0}{root'},
+ define short step={P}{0}{previous leaf},
+ define short step={N}{0}{next leaf},
+ define short step={F}{0}{first leaf},
+ define short step={L}{0}{last leaf},
+ define short step={>}{0}{next on tier},
+ define short step={<}{0}{previous on tier},
+ define short step={1}{0}{n=1},
+ define short step={2}{0}{n=2},
+ define short step={3}{0}{n=3},
+ define short step={4}{0}{n=4},
+ define short step={5}{0}{n=5},
+ define short step={6}{0}{n=6},
+ define short step={7}{0}{n=7},
+ define short step={8}{0}{n=8},
+ define short step={9}{0}{n=9},
+ define short step={l}{0}{last},
+ define short step={b}{0}{back},
+ define short step={f}{0}{forward},
+ define short step={v}{0}{last valid},
+ define short step={*}{2}{repeat={#1}{#2}},
+ for 1/.style={for nodewalk={n=1}{#1}},
+ for 2/.style={for nodewalk={n=2}{#1}},
+ for 3/.style={for nodewalk={n=3}{#1}},
+ for 4/.style={for nodewalk={n=4}{#1}},
+ for 5/.style={for nodewalk={n=5}{#1}},
+ for 6/.style={for nodewalk={n=6}{#1}},
+ for 7/.style={for nodewalk={n=7}{#1}},
+ for 8/.style={for nodewalk={n=8}{#1}},
+ for 9/.style={for nodewalk={n=9}{#1}},
+ for -1/.style={for nodewalk={n'=1}{#1}},
+ for -2/.style={for nodewalk={n'=2}{#1}},
+ for -3/.style={for nodewalk={n'=3}{#1}},
+ for -4/.style={for nodewalk={n'=4}{#1}},
+ for -5/.style={for nodewalk={n'=5}{#1}},
+ for -6/.style={for nodewalk={n'=6}{#1}},
+ for -7/.style={for nodewalk={n'=7}{#1}},
+ for -8/.style={for nodewalk={n'=8}{#1}},
+ for -9/.style={for nodewalk={n'=9}{#1}},
+}
+\forestset{
+ define long step={tree}{}{\forest@node@foreach{\forest@nodewalk@makestep}},
+ define long step={tree reversed}{}{\forest@node@foreach@reversed{\forest@nodewalk@makestep}},
+ define long step={tree children-first}{}{\forest@node@foreach@childrenfirst{\forest@nodewalk@makestep}},
+ define long step={tree children-first reversed}{}{\forest@node@foreach@childrenfirst@reversed{\forest@nodewalk@makestep}},
+ define long step={tree breadth-first}{}{\forest@node@foreach@breadthfirst{-1}{\forest@nodewalk@makestep}},
+ define long step={tree breadth-first reversed}{}{\forest@node@foreach@breadthfirst@reversed{-1}{\forest@nodewalk@makestep}},
+ define long step={descendants}{}{\forest@node@foreachdescendant{\forest@nodewalk@makestep}},
+ define long step={descendants reversed}{}{\forest@node@foreachdescendant@reversed{\forest@nodewalk@makestep}},
+ define long step={descendants children-first}{}{\forest@node@foreachdescendant@childrenfirst{\forest@nodewalk@makestep}},
+ define long step={descendants children-first reversed}{}{\forest@node@foreachdescendant@childrenfirst@reversed{\forest@nodewalk@makestep}},
+ define long step={descendants breadth-first}{}{\forest@node@foreach@breadthfirst{0}{\forest@nodewalk@makestep}},
+ define long step={descendants breadth-first reversed}{}{\forest@node@foreach@breadthfirst@reversed{0}{\forest@nodewalk@makestep}},
+ define long step={level}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{#1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {\forest@temp}%
+ {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={level>}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{#1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {-1}%
+ {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={level<}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)-1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {\forest@temp}%
+ {\noexpand\forest@nodewalk@makestep}%
+ }\forest@marshal
+ },
+ define long step={level reversed}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{#1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {\forest@temp}%
+ {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={level reversed>}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{#1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {-1}%
+ {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={level reversed<}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)-1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {\forest@temp}%
+ {\noexpand\forest@nodewalk@makestep}%
+ }\forest@marshal
+ },
+ %
+ define long step={relative level}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {\forest@temp}%
+ {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={relative level>}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {-1}%
+ {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={relative level<}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}-1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst
+ {\forest@temp}%
+ {\noexpand\forest@nodewalk@makestep}%
+ }\forest@marshal
+ },
+ define long step={relative level reversed}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {\forest@temp}%
+ {\noexpand\ifnum\noexpand\forestove{level}=\forest@temp\relax\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={relative level reversed>}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {-1}%
+ {\noexpand\ifnum\noexpand\forestove{level}<\forest@temp\relax\noexpand\else\noexpand\forest@nodewalk@makestep\noexpand\fi}%
+ }\forest@marshal
+ },
+ define long step={relative level reversed<}{n args=1}{%
+ \pgfmathtruncatemacro\forest@temp{(#1)+\forestove{level}-1}%
+ \edef\forest@marshal{%
+ \noexpand\forest@node@foreach@breadthfirst@reversed
+ {\forest@temp}%
+ {\noexpand\forest@nodewalk@makestep}%
+ }\forest@marshal
+ },
+ define long step={children}{}{\forest@node@foreachchild{\forest@nodewalk@makestep}},
+ define long step={children reversed}{}{\forest@node@foreachchild@reversed{\forest@nodewalk@makestep}},
+ define long step={current and following siblings}{}{\forest@node@@forselfandfollowingsiblings{\forest@nodewalk@makestep}},
+ define long step={following siblings}{style}{if nodewalk valid={next}{fake=next,current and following siblings}{}},
+ define long step={current and preceding siblings}{}{\forest@node@@forselfandprecedingsiblings{\forest@nodewalk@makestep}},
+ define long step={preceding siblings}{style}{if nodewalk valid={previous}{fake=previous,current and preceding siblings}{}},
+ define long step={current and following siblings reversed}{}{\forest@node@@forselfandfollowingsiblings@reversed{\forest@nodewalk@makestep}},
+ define long step={following siblings reversed}{style}{fake=next,current and following siblings reversed},
+ define long step={current and preceding siblings reversed}{}{\forest@node@@forselfandprecedingsiblings@reversed{\forest@nodewalk@makestep}},
+ define long step={preceding siblings reversed}{style}{fake=previous,current and preceding siblings reversed},
+ define long step={siblings}{style}{for nodewalk'={preceding siblings},following siblings},
+ define long step={siblings reversed}{style}{for nodewalk'={following siblings reversed},preceding siblings reversed},
+ define long step={ancestors}{style}{while={}{parent},last valid},
+ define long step={current and ancestors}{style}{current,ancestors},
+ define long step={following nodes}{style}{while={}{next node},last valid},
+ define long step={preceding nodes}{style}{while={}{previous node},last valid},
+ define long step={current and following nodes}{style}{current,following nodes},
+ define long step={current and preceding nodes}{style}{current,preceding nodes},
+}
+\let\forest@nodewalkstephandler@styletrueorfalse\forest@nodewalkstephandler@styletrue
\def\forest@last@node{0}
\def\forest@nodehandleby@name@nodewalk@or@bracket#1{%
\ifx\pgfkeysnovalue#1%
@@ -2129,6 +4104,9 @@
\else
\forest@forthis{%
\forest@nameandgo{#1#2}%
+ \ifnum\forest@cn=0
+ \PackageError{forest}{Cannot use a dynamic key on the invalid node}{}%
+ \fi
\let\forest@last@node\forest@cn
}%
\fi
@@ -2138,16 +4116,47 @@
\forest@last@node=#1\forest@end@create@node
}
\def\forest@create@collectafterthought#1\forest@end@create@node{%
- \forestOletO{\forest@last@node}{delay}{\forest@last@node}{given options}%
- \forestOset{\forest@last@node}{given options}{}%
- \forestOeappto{\forest@last@node}{delay}{,\unexpanded{#1}}%
-}
-\def\forest@create@collectafterthought#1\forest@end@create@node{%
\forest@node@Foreach{\forest@last@node}{%
\forestoleto{delay}{given options}%
\forestoset{given options}{}%
}%
\forestOeappto{\forest@last@node}{delay}{,\unexpanded{#1}}%
+ \forestOset{\forest@last@node}{given options}{delay={}}%
+}
+\def\forest@create@node@and@process@given@options#1{% #1=bracket representation
+ \bracketParse{\forest@createandprocess@collectafterthought}%
+ \forest@last@node=#1\forest@end@create@node
+}
+\def\forest@createandprocess@collectafterthought#1\forest@end@create@node{%
+ \forest@node@Compute@numeric@ts@info{\forest@last@node}%
+ \forest@saveandrestoremacro\forest@root{%
+ \let\forest@root\forest@last@node
+ \forestset{process keylist=given options}%
+ }%
+}
+\def\forest@saveandrestoremacro#1#2{% #1 = the (zero-arg) macro to save before and restore after processing code in #2
+ \edef\forest@marshal{%
+ \unexpanded{#2}%
+ \noexpand\def\noexpand#1{\expandonce{#1}}%
+ }\forest@marshal
+}
+\def\forest@saveandrestoreifcs#1#2{% #1 = the if cs to save before and restore after processing code in #2
+ \edef\forest@marshal{%
+ \unexpanded{#2}%
+ \ifbool{#1}{\noexpand\setbool{#1}{true}}{\noexpand\setbool{#1}{false}}
+ }\forest@marshal
+}
+\def\forest@saveandrestoretoks#1#2{% #1 = the toks to save before and restore after processing code in #2
+ \edef\forest@marshal{%
+ \unexpanded{#2}%
+ \noexpand#1{\the#1}%
+ }\forest@marshal
+}
+\def\forest@saveandrestoreregister#1#2{% #1 = the register to save before and restore after processing code in #2
+ \edef\forest@marshal{%
+ \unexpanded{#2}%
+ \noexpand\forestrset{#1}{\forestregister{#1}}%
+ }\forest@marshal
}
\def\forest@remove@node#1{%
\forest@node@Remove{#1}%
@@ -2168,6 +4177,9 @@
\forest@node@Remove{#2}%
\forest@node@Insertbefore{\forestOve{#1}{@parent}}{#2}{#1}%
}
+\def\forest@set@root#1#2{%
+ \def\forest@root{#2}%
+}
\def\forest@appto@do@dynamics#1#2{%
\forest@nodehandleby@name@nodewalk@or@bracket{#2}%
\ifcase\forest@dynamics@copyhow\relax\or
@@ -2179,14 +4191,20 @@
\forestOepreto{\forest@last@node}{delay}
{for id={\forest@node@Nametoid{forest@last@node}}{alias=forest@last@node},}%
}{}%
- \forest@havedelayedoptionstrue
\edef\forest@marshal{%
\noexpand\apptotoks\noexpand\forest@do@dynamics{%
\noexpand#1{\forest@cn}{\forest@last@node}}%
}\forest@marshal
}
\forestset{%
- create/.code={\forest@create@node{#1}},
+ create/.code={%
+ \forest@create@node{#1}%
+ \forest@fornode{\forest@last@node}{\forest@node@setalias{forest@last@node}}%
+ },
+ create'/.code={%
+ \forest@create@node@and@process@given@options{#1}%
+ \forest@fornode{\forest@last@node}{\forest@node@setalias{forest@last@node}}%
+ },
append/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@append@node{#1}},
prepend/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@prepend@node{#1}},
insert after/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@insertafter@node{#1}},
@@ -2205,16 +4223,29 @@
\expandafter\forest@remove@node\expandafter{\forest@cn}}%
},
set root/.code={%
- \forest@nodehandleby@name@nodewalk@or@bracket{#1}%
- \edef\forest@marshal{%
- \noexpand\apptotoks\noexpand\forest@do@dynamics{%
- \def\noexpand\forest@root{\forest@last@node}%
- }%
- }\forest@marshal
+ \def\forest@dynamics@copyhow{0}%
+ \forest@appto@do@dynamics\forest@set@root{#1}%
},
replace by/.code={\forest@replaceby@code{#1}{insert after}},
replace by'/.code={\forest@replaceby@code{#1}{insert after'}},
replace by''/.code={\forest@replaceby@code{#1}{insert after''}},
+ sort/.code={%
+ \eapptotoks\forest@do@dynamics{%
+ \noexpand\forest@nodesort
+ \noexpand\forest@sort@ascending
+ {\forest@cn}%
+ {\expandonce{\forest@nodesort@by}}%
+ }%
+ },
+ sort'/.code={%
+ \eapptotoks\forest@do@dynamics{%
+ \noexpand\forest@nodesort
+ \noexpand\forest@sort@descending
+ {\forest@cn}%
+ {\expandonce{\forest@nodesort@by}}%
+ }%
+ },
+ sort by/.store in=\forest@nodesort@by,
}
\def\forest@replaceby@code#1#2{%#1=node spec,#2=insert after['][']
\ifnum\forestove{@parent}=0
@@ -2228,8 +4259,70 @@
}%
\fi
}
+\def\forest@nodesort#1#2#3{% #1 = direction, #2 = parent node, #3 = sort key
+ \def\forest@nodesort@sortkey{#3}%
+ \forest@fornode{#2}{\forest@nodesort@#1}%
+}
+\def\forest@nodesort@#1{%
+ % prepare the array of child ids
+ \c@pgf@counta=0
+ \forestoget{@first}\forest@nodesort@id
+ \forest@loop
+ \ifnum\forest@nodesort@id>0
+ \advance\c@pgf@counta 1
+ \csedef{forest@nodesort@\the\c@pgf@counta}{\forest@nodesort@id}%
+ \forestOget{\forest@nodesort@id}{@next}\forest@nodesort@id
+ \forest@repeat
+ % sort
+ \forestoget{n children}\forest@nodesort@n
+ \forest@sort\forest@nodesort@cmpnodes\forest@nodesort@let#1{1}{\forest@nodesort@n}%
+ % remove all children
+ \forestoget{@first}\forest@nodesort@id
+ \forest@loop
+ \ifnum\forest@nodesort@id>0
+ \forest@node@Remove{\forest@nodesort@id}%
+ \forestoget{@first}\forest@nodesort@id
+ \forest@repeat
+ % insert the children in new order
+ \c@pgf@counta=0
+ \forest@loop
+ \ifnum\c@pgf@counta<\forest@nodesort@n\relax
+ \advance\c@pgf@counta 1
+ \edef\temp{\csname forest@nodesort@\the\c@pgf@counta\endcsname}%
+ \forest@node@append{\csname forest@nodesort@\the\c@pgf@counta\endcsname}%
+ \forest@repeat
+}
+\def\forest@nodesort@cmpnodes#1#2{%
+ \global\let\forest@nodesort@cmpresult\forest@sort@cmp@eq
+ \foreach \forest@temp@pgfmath in \forest@nodesort@sortkey {%
+ \forest@fornode{\csname forest@nodesort@#1\endcsname}{%
+ \pgfmathparse{\forest@temp@pgfmath}\global\let\forest@global@tempa\pgfmathresult}%
+ \forest@fornode{\csname forest@nodesort@#2\endcsname}{%
+ \pgfmathparse{\forest@temp@pgfmath}\global\let\forest@global@tempb\pgfmathresult}%
+ \ifdim\forest@global@tempa pt<\forest@global@tempb pt
+ \global\let\forest@nodesort@cmpresult\forest@sort@cmp@lt
+ \breakforeach
+ \else
+ \ifdim\forest@global@tempa pt>\forest@global@tempb pt
+ \global\let\forest@nodesort@cmpresult\forest@sort@cmp@gt
+ \breakforeach
+ \fi
+ \fi
+ }%
+ \forest@nodesort@cmpresult
+}
+\def\forest@nodesort@let#1#2{%
+ \csletcs{forest@nodesort@#1}{forest@nodesort@#2}%
+}
+\def\forest@root{0}
+ %%% begin listing region: stages
\forestset{
stages/.style={
+ for root'={
+ process keylist register=default preamble,
+ process keylist register=preamble
+ },
+ process keylist=given options,
process keylist=before typesetting nodes,
typeset nodes stage,
process keylist=before packing,
@@ -2237,33 +4330,68 @@
process keylist=before computing xy,
compute xy stage,
process keylist=before drawing tree,
- draw tree stage,
+ draw tree stage
},
typeset nodes stage/.style={for root'=typeset nodes},
pack stage/.style={for root'=pack},
compute xy stage/.style={for root'=compute xy},
draw tree stage/.style={for root'=draw tree},
- process keylist/.code={\forest@process@hook@keylist{#1}},
+}
+ %%% end listing region: stages
+\forestset{
+ process keylist/.code={%
+ \forest@process@hook@keylist{#1}{#1 processing order/.try,processing order/.lastretry}},
+ process keylist'/.code 2 args={\forest@process@hook@keylist@nodynamics{#1}{#2}},
+ process keylist''/.code 2 args={\forest@process@hook@keylist@{#1}{#2}},
+ process keylist register/.code={\forest@process@keylist@register{#1}},
+ process delayed/.code={%
+ \forest@havedelayedoptions{@delay}{#1}%
+ \ifforest@havedelayedoptions
+ \forest@process@hook@keylist@nodynamics{@delay}{#1}%
+ \fi
+ },
+ do dynamics/.code={%
+ \the\forest@do@dynamics
+ \forest@do@dynamics{}%
+ \forest@node@Compute@numeric@ts@info{\forest@root}%
+ },
declare keylist={given options}{},
declare keylist={before typesetting nodes}{},
declare keylist={before packing}{},
+ declare keylist={before packing node}{},
+ declare keylist={after packing node}{},
declare keylist={before computing xy}{},
declare keylist={before drawing tree}{},
declare keylist={delay}{},
- delay/.append code={\forest@havedelayedoptionstrue},
delay n/.style 2 args={if={#1==0}{#2}{delay@n={#1}{#2}}},
delay@n/.style 2 args={
if={#1==1}{delay={#2}}{delay={delay@n/.wrap pgfmath arg={{##1}{#2}}{#1-1}}}
},
- if have delayed/.code 2 args={%
- \ifforest@havedelayedoptions\pgfkeysalso{#1}\else\pgfkeysalso{#2}\fi
+ if have delayed/.style 2 args={if have delayed'={processing order}{#1}{#2}},
+ if have delayed'/.code n args=3{%
+ \forest@havedelayedoptionsfalse
+ \forest@forthis{%
+ \forest@nodewalk{#1}{%
+ TeX={%
+ \forestoget{delay}\forest@temp@delayed
+ \ifdefempty\forest@temp@delayed{}{\forest@havedelayedoptionstrue}%
+ }%
+ }%
+ }%
+ \ifforest@havedelayedoptions\pgfkeysalso{#2}\else\pgfkeysalso{#3}\fi
},
typeset nodes/.code={%
\forest@drawtree@preservenodeboxes@false
- \forest@node@foreach{\forest@node@typeset}},
+ \forest@nodewalk
+ {typeset nodes processing order/.try,processing order/.lastretry}%
+ {TeX={\forest@node@typeset}}%
+ },
typeset nodes'/.code={%
\forest@drawtree@preservenodeboxes@true
- \forest@node@foreach{\forest@node@typeset}},
+ \forest@nodewalk
+ {typeset nodes processing order/.try,processing order/.lastretry}%
+ {TeX={\forest@node@typeset}}%
+ },
typeset node/.code={%
\forest@drawtree@preservenodeboxes@false
\forest@node@typeset
@@ -2281,45 +4409,101 @@
\forest@drawtree@preservenodeboxes@true
\forest@node@drawtree
},
+ %%% begin listing region: draw_tree_method
+ draw tree method/.style={
+ for nodewalk={
+ draw tree nodes processing order/.try,
+ draw tree processing order/.retry,
+ processing order/.lastretry
+ }{draw tree node},
+ for nodewalk={
+ draw tree edges processing order/.try,
+ draw tree processing order/.retry,
+ processing order/.lastretry
+ }{draw tree edge},
+ for nodewalk={
+ draw tree tikz processing order/.try,
+ draw tree processing order/.retry,
+ processing order/.lastretry
+ }{draw tree tikz}
+ },
+ %%% end listing region: draw_tree_method
+ draw tree node/.code={\forest@draw@node},
+ draw tree edge/.code={\forest@draw@edge},
+ draw tree tikz/.code={\forest@draw@tikz},
+ for nodewalk={processing order/.style={tree}}{},
+ %given options processing order/.style={processing order},
+ %before typesetting nodes processing order/.style={processing order},
+ %before packing processing order/.style={processing order},
+ %before computing xy processing order/.style={processing order},
+ %before drawing tree processing order/.style={processing order},
}
\newtoks\forest@do@dynamics
\newif\ifforest@havedelayedoptions
-\def\forest@process@hook@keylist#1{%
- \forest@loopa
- \forest@havedelayedoptionsfalse
- \forest@do@dynamics={}%
- \forest@fornode{\forest@root}{\forest@process@hook@keylist@{#1}}%
+\def\forest@process@hook@keylist#1#2{%,#1=keylist,#2=processing order nodewalk
+ \safeloop
+ \forest@fornode{\forest@root}{\forest@process@hook@keylist@{#1}{#2}}%
\expandafter\ifstrempty\expandafter{\the\forest@do@dynamics}{}{%
\the\forest@do@dynamics
+ \forest@do@dynamics={}%
\forest@node@Compute@numeric@ts@info{\forest@root}%
- \forest@havedelayedoptionstrue
}%
+ \forest@fornode{\forest@root}{\forest@havedelayedoptions{#1}{#2}}%
\ifforest@havedelayedoptions
- \forest@node@Foreach{\forest@root}{%
- \forestoget{delay}\forest@temp@delayed
- \forestolet{#1}\forest@temp@delayed
- \forestoset{delay}{}%
+ \saferepeat
+}
+\def\forest@process@hook@keylist@nodynamics#1#2{%#1=keylist,#2=processing order nodewalk
+ % note: this macro works on (nodewalk starting at) the current node
+ \safeloop
+ \forest@forthis{\forest@process@hook@keylist@{#1}{#2}}%
+ \forest@havedelayedoptions{#1}{#2}%
+ \ifforest@havedelayedoptions
+ \saferepeat
+}
+\def\forest@process@hook@keylist@#1#2{%#1=keylist,#2=processing order nodewalk
+ \forest@nodewalk{#2}{%
+ TeX={%
+ \forestoget{#1}\forest@temp@keys
+ \ifdefvoid\forest@temp@keys{}{%
+ \forestoset{#1}{}%
+ \expandafter\forestset\expandafter{\forest@temp@keys}%
+ }%
}%
- \forest@repeata
+ }%
}
-\def\forest@process@hook@keylist@#1{%
- \forest@node@foreach{%
- \forestoget{#1}\forest@temp@keys
- \ifdefvoid\forest@temp@keys{}{%
- \forestoset{#1}{}%
- \expandafter\forestset\expandafter{\forest@temp@keys}%
+\def\forest@process@keylist@register#1{%
+ \edef\forest@marshal{%
+ \noexpand\forestset{\forestregister{#1}}%
+ }\forest@marshal
+}
+\def\forest@havedelayedoptions#1#2{%#1 = keylist, #2=nodewalk
+ \forest@havedelayedoptionsfalse
+ \forest@forthis{%
+ \forest@nodewalk{#2}{%
+ TeX={%
+ \forestoget{delay}\forest@temp@delayed
+ \ifdefempty\forest@temp@delayed{}{\forest@havedelayedoptionstrue}%
+ \forestolet{#1}\forest@temp@delayed
+ \forestoset{delay}{}%
+ }%
}%
}%
}
\def\forest@node@typeset{%
\let\forest@next\forest@node@typeset@
- \forestoifdefined{box}{%
- \ifforest@drawtree@preservenodeboxes@
- \let\forest@next\relax
- \fi
+ \forestoifdefined{@box}{%
+ \forestoget{@box}\forest@temp
+ \ifdefempty\forest@temp{%
+ \locbox\forest@temp@box
+ \forestolet{@box}\forest@temp@box
+ }{%
+ \ifforest@drawtree@preservenodeboxes@
+ \let\forest@next\relax
+ \fi
+ }%
}{%
\locbox\forest@temp@box
- \forestolet{box}\forest@temp@box
+ \forestolet{@box}\forest@temp@box
}%
\def\forest@node@typeset@restore{}%
\ifdefined\ifsa@tikz\forest@standalone@hack\fi
@@ -2339,52 +4523,38 @@
\fi
}
\newbox\forest@box
+\def\forest@pgf@notyetpositioned{not yet positionedPGFINTERNAL}
\def\forest@node@typeset@{%
+ \forestanchortotikzanchor{anchor}\forest@temp
+ \edef\forest@marshal{%
+ \noexpand\forestolet{anchor}\noexpand\forest@temp
+ \noexpand\forest@node@typeset@@
+ \noexpand\forestoset{anchor}{\forestov{anchor}}%
+ }\forest@marshal
+}
+\def\forest@node@typeset@@{%
\forestoget{name}\forest@nodename
\edef\forest@temp@nodeformat{\forestove{node format}}%
\gdef\forest@smuggle{}%
\setbox0=\hbox{%
- \begin{tikzpicture}%
+ \begin{tikzpicture}[%
+ /forest/copy command key={/tikz/anchor}{/tikz/forest@orig@anchor},
+ anchor/.style={%
+ /forest/TeX={\forestanchortotikzanchor{##1}\forest@temp@anchor},
+ forest@orig@anchor/.expand once=\forest@temp@anchor
+ }]
\pgfpositionnodelater{\forest@positionnodelater@save}%
\forest@temp@nodeformat
\pgfinterruptpath
\pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{forestcomputenodeboundary}%
\endpgfinterruptpath
- %\forest@compute@node@boundary\forest@temp
- %\xappto\forest@smuggle{\noexpand\forestoset{boundary}{\expandonce\forest@temp}}%
- \if\relax\forestove{parent anchor}\relax
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{center}%
- \else
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{\forestove{parent anchor}}%
- \fi
- \xappto\forest@smuggle{%
- \noexpand\forestoset{parent@anchor}{%
- \noexpand\noexpand\noexpand\pgf@x=\the\pgf@x\relax
- \noexpand\noexpand\noexpand\pgf@y=\the\pgf@y\relax}}%
- \if\relax\forestove{child anchor}\relax
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{center}%
- \else
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{\forestove{child anchor}}%
- \fi
- \xappto\forest@smuggle{%
- \noexpand\forestoeset{child@anchor}{%
- \noexpand\noexpand\noexpand\pgf@x=\the\pgf@x\relax
- \noexpand\noexpand\noexpand\pgf@y=\the\pgf@y\relax}}%
- \if\relax\forestove{anchor}\relax
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{center}%
- \else
- \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{\forestove{anchor}}%
- \fi
- \xappto\forest@smuggle{%
- \noexpand\forestoeset{@anchor}{%
- \noexpand\noexpand\noexpand\pgf@x=\the\pgf@x\relax
- \noexpand\noexpand\noexpand\pgf@y=\the\pgf@y\relax}}%
\end{tikzpicture}%
}%
- \setbox\forestove{box}=\box\forest@box % smuggle the box
- \forestolet{boundary}\forest@global@boundary
+ \setbox\forestove{@box}=\box\forest@box % smuggle the box
+ \forestolet{@boundary}\forest@global@boundary
\forest@smuggle % ... and the rest
}
+
\forestset{
declare readonly dimen={min x},
declare readonly dimen={min y},
@@ -2417,13 +4587,17 @@
\else
\let\forest@boxorcopy\box
\fi
- \forestoget{box}\forest@temp
+ \forestoget{@box}\forest@temp
\setbox\pgfpositionnodelaterbox=\forest@boxorcopy\forest@temp
\edef\pgfpositionnodelatername{\forestove{later@name}}%
\edef\pgfpositionnodelaterminx{\forestove{min x}}%
\edef\pgfpositionnodelaterminy{\forestove{min y}}%
\edef\pgfpositionnodelatermaxx{\forestove{max x}}%
\edef\pgfpositionnodelatermaxy{\forestove{max y}}%
+ \ifforest@drawtree@preservenodeboxes@
+ \else
+ \forestoset{@box}{}%
+ \fi
}
\def\forest@pack{%
\forest@pack@computetiers
@@ -2432,24 +4606,28 @@
}
\def\forest@@pack{%
\ifnum\forestove{n children}>0
- \ifnum\forestove{uniform growth}>0
+ \ifnum\forestove{uniform growth}>0
\forest@pack@level@uniform
\forest@pack@aligntiers@ofsubtree
\forest@pack@sibling@uniform@recursive
\else
\forest@node@foreachchild{\forest@@pack}%
+ \forest@process@hook@keylist@nodynamics{before packing node}{current}%
\forest@pack@level@nonuniform
\forest@pack@aligntiers
\forest@pack@sibling@uniform@applyreversed
\fi
\fi
+ \forestoget{after packing node}\forest@temp@keys
+ \forest@process@hook@keylist@nodynamics{after packing node}{current}%
}
\def\forest@pack@onlythisnode{%
\ifnum\forestove{n children}>0
\forest@pack@computetiers
- \forest@pack@level@nonuniform
- \forest@pack@aligntiers
- \forest@pack@sibling@uniform@applyreversed
+ \forest@pack@level@nonuniform
+ \forest@pack@aligntiers
+ \forest@node@foreachchild{\forestoset{s}{0pt}}%
+ \forest@pack@sibling@uniform@applyreversed
\fi
}
\def\forest@pack@computegrowthuniformity{%
@@ -2470,7 +4648,13 @@
\fi
\fi
}%
- \forestolet{uniform growth}\forest@pack@cgu@uniformity
+ \forestoget{before packing node}\forest@temp@a
+ \forestoget{after packing node}\forest@temp@b
+ \expandafter\expandafter\expandafter\ifstrempty\expandafter\expandafter\expandafter{\expandafter\forest@temp@a\forest@temp@b}{%
+ \forestolet{uniform growth}\forest@pack@cgu@uniformity
+ }{%
+ \forestoset{uniform growth}{0}%
+ }%
}
\def\forest@pack@level@uniform{%
\let\forest@plu@minchildl\relax
@@ -2571,9 +4755,9 @@
\def\forest@pack@sibling@uniform@applyreversed{%
\ifnum\forestove{n children}>1
\ifnum\forestove{reversed}=0
- \pack@sibling@uniform@main{first}{last}{next}{previous}%
+ \forest@pack@sibling@uniform@main{first}{last}{next}{previous}%
\else
- \pack@sibling@uniform@main{last}{first}{previous}{next}%
+ \forest@pack@sibling@uniform@main{last}{first}{previous}{next}%
\fi
\else
\ifnum\forestove{n children}=1
@@ -2581,28 +4765,28 @@
\fi
\fi
}
-\def\pack@sibling@uniform@main#1#2#3#4{%
+\def\forest@pack@sibling@uniform@main#1#2#3#4{%
\forestoget{@#1}\forest@child
- \edef\forest@temp{%
+ \edef\forest@marshal{%
\noexpand\forest@fornode{\forestove{@#1}}{%
\noexpand\forest@node@getedge
- {positive}
- {\forestove{grow}}
+ {positive}%
+ {\forestove{grow}}%
\noexpand\forest@temp@edge
}%
- }\forest@temp
+ }\forest@marshal
\forest@pack@pgfpoint@childsposition\forest@child
\let\forest@previous@positive@edge\pgfutil@empty
\forest@extendpath\forest@previous@positive@edge\forest@temp@edge{}%
\forestOget{\forest@child}{@#3}\forest@child
\edef\forest@previous@child@s{0pt}%
- \forest@loopb
+ \safeloop
\unless\ifnum\forest@child=0
\edef\forest@temp{%
\noexpand\forest@fornode{\forest@child}{%
\noexpand\forest@node@getedge
- {negative}
- {\forestove{grow}}
+ {negative}%
+ {\forestove{grow}}%
\noexpand\forest@temp@edge
}%
}\forest@temp
@@ -2616,7 +4800,7 @@
\else
\advance\pgfutil@tempdimb-\forest@csdistance\relax
\advance\pgfutil@tempdimb\forestove{s sep}\relax
- \forestOeset{\forest@child}{s}{\the\dimexpr\forestove{s}-\forest@csdistance+\forestove{s sep}}%
+ \forestOeset{\forest@child}{s}{\the\dimexpr\forestOve{\forest@child}{s}-\forest@csdistance+\forestove{s sep}}%
\fi
\ifdim\forestOve{\forest@child}{s}<\forest@previous@child@s\relax
\forestOeset{\forest@child}{s}{\forest@previous@child@s}%
@@ -2626,8 +4810,8 @@
\edef\forest@temp{%
\noexpand\forest@fornode{\forest@child}{%
\noexpand\forest@node@getedge
- {positive}
- {\forestove{grow}}
+ {positive}%
+ {\forestove{grow}}%
\noexpand\forest@temp@edge
}%
}\forest@temp
@@ -2635,7 +4819,7 @@
\forest@extendpath\forest@previous@positive@edge\forest@temp@edge{}%
\forest@getpositivetightedgeofpath\forest@previous@positive@edge\forest@previous@positive@edge
\forestOget{\forest@child}{@#3}\forest@child
- \forest@repeatb
+ \saferepeat
\csname forest@calign@\forestove{calign}\endcsname
}
\def\forest@pack@pgfpoint@childsposition#1{%
@@ -2670,9 +4854,9 @@
\pgftransformrotate{\forestove{grow}}%
\pgfpointtransformed{\pgfqpoint{\forestOve{\forest@temp@child}{l}}{\forestOve{\forest@temp@child}{s}}}%
\pgf@xa=\pgf@x\relax\pgf@ya=\pgf@y\relax
- \forestOve{\forest@temp@child}{child@anchor}%
+ \forest@Pointanchor{\forest@temp@child}{child anchor}%
\advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
- \forestove{parent@anchor}%
+ \forest@pointanchor{parent anchor}%
\advance\pgf@xa-\pgf@x\relax\advance\pgf@ya-\pgf@y\relax
\edef\forest@marshal{%
\noexpand\pgftransformreset
@@ -2697,13 +4881,13 @@
\pgftransformrotate{\forestove{grow}}%
\pgfpointtransformed{\pgfqpoint{\forestOve{\forest@temp@firstchild}{l}}{\forestOve{\forest@temp@firstchild}{s}}}%
\pgf@xa=\pgf@x\relax\pgf@ya=\pgf@y\relax
- \forestOve{\forest@temp@firstchild}{child@anchor}%
+ \forest@Pointanchor{\forest@temp@firstchild}{child anchor}%
\advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
\edef\forest@marshal{%
\noexpand\pgfpointtransformed{\noexpand\pgfqpoint{\forestOve{\forest@temp@secondchild}{l}}{\forestOve{\forest@temp@secondchild}{s}}}%
}\forest@marshal
\advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
- \forestOve{\forest@temp@secondchild}{child@anchor}%
+ \forest@Pointanchor{\forest@temp@secondchild}{child anchor}%
\advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
\divide\pgf@xa2 \divide\pgf@ya2
\edef\forest@marshal{%
@@ -2779,16 +4963,13 @@
\fi
\forestOget{\forest@ca@first@child}{l}\forest@ca@first@l
\forestOget{\forest@ca@second@child}{l}\forest@ca@second@l
- \forestoget{parent@anchor}\forest@ca@parent@anchor
- \forest@ca@parent@anchor
+ \forest@pointanchor{parent anchor}%
\edef\forest@ca@parent@anchor@s{\the\pgf@x}%
\edef\forest@ca@parent@anchor@l{\the\pgf@y}%
- \forestOget{\forest@ca@first@child}{child@anchor}\forest@ca@first@child@anchor
- \forest@ca@first@child@anchor
+ \forest@Pointanchor{\forest@ca@first@child}{child anchor}%
\edef\forest@ca@first@child@anchor@s{\the\pgf@x}%
\edef\forest@ca@first@child@anchor@l{\the\pgf@y}%
- \forestOget{\forest@ca@second@child}{child@anchor}\forest@ca@second@child@anchor
- \forest@ca@second@child@anchor
+ \forest@Pointanchor{\forest@ca@second@child}{child anchor}%
\edef\forest@ca@second@child@anchor@s{\the\pgf@x}%
\edef\forest@ca@second@child@anchor@l{\the\pgf@y}%
\pgfmathsetlengthmacro\forest@ca@desired@second@edge@s{tan(\forestove{calign secondary angle})*%
@@ -2805,8 +4986,7 @@
\ifdim\forest@ca@actual@s@distance=0pt
\forestoget{n children}\forest@temp@n@children
\forest@node@foreachchild{%
- \forestoget{child@anchor}\forest@temp@child@anchor
- \forest@temp@child@anchor
+ \forest@pointanchor{child anchor}%
\edef\forest@temp@child@anchor@s{\the\pgf@x}%
\pgfmathsetlengthmacro\forest@temp{%
\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}%
@@ -2817,8 +4997,7 @@
\pgfmathsetmacro\forest@ca@ratio{%
\forest@ca@desired@s@distance/\forest@ca@actual@s@distance}%
\forest@node@foreachchild{%
- \forestoget{child@anchor}\forest@temp@child@anchor
- \forest@temp@child@anchor
+ \forest@pointanchor{child anchor}%
\edef\forest@temp@child@anchor@s{\the\pgf@x}%
\pgfmathsetlengthmacro\forest@temp{%
\forest@ca@ratio*(%
@@ -2838,8 +5017,7 @@
\pgfmathsetlengthmacro\forest@ca@ratio{%
\forest@ca@actual@s@distance/\forest@ca@desired@s@distance}%
\forest@node@foreachchild{%
- \forestoget{child@anchor}\forest@temp@child@anchor
- \forest@temp@child@anchor
+ \forest@pointanchor{child anchor}%
\edef\forest@temp@child@anchor@l{\the\pgf@y}%
\pgfmathsetlengthmacro\forest@temp{%
\forest@ca@ratio*(%
@@ -2871,7 +5049,7 @@
%{%
\forest@setupgrowline{#1}%
\ifnum\forestove{ignore}=0
- \forestoget{boundary}\forest@node@boundary
+ \forestoget{@boundary}\forest@node@boundary
\else
\def\forest@node@boundary{}%
\fi
@@ -2886,10 +5064,11 @@
\def\get@edges@merge#1#2{%
\ifnum\forestove{n children}>0
\forestoget{#1@edge@#2}\forest@node@edge
- \forestove{parent@anchor}%
+ \forest@pointanchor{parent anchor}%
\edef\forest@getedge@pa@l{\the\pgf@x}%
\edef\forest@getedge@pa@s{\the\pgf@y}%
\eappto\forest@node@edge{\noexpand\pgfsyssoftpath@movetotoken{\forest@getedge@pa@l}{\forest@getedge@pa@s}}%
+ \pgfgettransform\forest@temp@transform
\pgftransformreset
\pgftransformrotate{\forestove{grow}}%
\def\forest@all@edges{}%
@@ -2900,7 +5079,7 @@
\ifnum\forestove{ignore edge}=0
\pgfpointadd
{\pgfpointtransformed{\pgfqpoint{\forestove{l}}{\forestove{s}}}}%
- {\forestove{child@anchor}}%
+ {\forest@pointanchor{child anchor}}%
\pgfgetlastxy{\forest@getedge@ca@l}{\forest@getedge@ca@s}%
\eappto\forest@all@edges{%
\noexpand\pgfsyssoftpath@movetotoken{\forest@getedge@pa@l}{\forest@getedge@pa@s}%
@@ -2916,23 +5095,23 @@
\forest@merge@intersectionloop
\eappto\forest@node@edge{\expandonce{\forest@all@edges}\expandonce{\forest@edgenode@intersections}}%
}%
+ \pgfsettransform\forest@temp@transform
\csname forest@get#1\forestove{fit}edgeofpath\endcsname\forest@node@edge\forest@node@edge
\forestolet{#1@edge@#2}\forest@node@edge
\fi
}
-\newloop\forest@merge@loop
\def\forest@merge@intersectionloop{%
\c@pgf@counta=0
- \forest@merge@loop
+ \forest@loop
\ifnum\c@pgf@counta<\pgfintersectionsolutions\relax
\advance\c@pgf@counta1
\pgfpointintersectionsolution{\the\c@pgf@counta}%
\eappto\forest@edgenode@intersections{\noexpand\pgfsyssoftpath@movetotoken
{\the\pgf@x}{\the\pgf@y}}%
- \forest@merge@repeat
+ \forest@repeat
}
\def\forest@node@getboundingrectangle@ls#1{%
- \forestoget{boundary}\forest@node@boundary
+ \forestoget{@boundary}\forest@node@boundary
\forest@path@getboundingrectangle@ls\forest@node@boundary{#1}%
}
\def\forest@pgfpathtransformed#1{%
@@ -3079,7 +5258,7 @@
\def\forest@pack@tiers@computeprocessingorder{%
\def\forest@tiers@processingorder{}%
\forestoget{tiers}\forest@tiers@cpo@tierstodo
- \forest@loopa
+ \safeloop
\ifdefempty\forest@tiers@cpo@tierstodo{\forest@tempfalse}{\forest@temptrue}%
\ifforest@temp
\def\forest@tiers@cpo@tiersremaining{}%
@@ -3089,7 +5268,7 @@
\PackageError{forest}{Circular tiers!}{}}{}%
\forlistloop\forest@pack@tiers@cpo@forhandlerB\forest@tiers@cpo@tiersremaining
\let\forest@tiers@cpo@tierstodo\forest@tiers@cpo@tiersremaining
- \forest@repeata
+ \saferepeat
}
\def\forest@pack@tiers@cpo@forhandlerA#1{%
\ifcsempty{forest@tiers@higher@#1}{%
@@ -3170,7 +5349,7 @@
'\forestOve{\forestove{@parent}}{content}') was given 'calign=\forestove{calign}', while its
child \forest@cn\space (content: '\forestove{content}') was given 'tier=\forestove{tier}'.
The parent's 'calign' will only work if the child was the lowest node on its tier before the
- alignment.}{}
+ alignment.}%
}
\pgfdeclaregenericanchor{forestcomputenodeboundary}{%
\letcs\forest@temp@boundary@macro{forest@compute@node@boundary@#1}%
@@ -3237,26 +5416,25 @@
\forest@lt{arc end}%
\forest@lt{arc start}%
}
-\newloop\forest@computenodeboundary@loop
\csdef{forest@compute@node@boundary@regular polygon}{%
\forest@mt{corner 1}%
\c@pgf@counta=\sides\relax
- \forest@computenodeboundary@loop
+ \forest@loop
\ifnum\c@pgf@counta>0
\forest@lt{corner \the\c@pgf@counta}%
\advance\c@pgf@counta-1
- \forest@computenodeboundary@repeat
+ \forest@repeat
}%
\def\forest@compute@node@boundary@star{%
\forest@mt{outer point 1}%
\c@pgf@counta=\totalstarpoints\relax
\divide\c@pgf@counta2
- \forest@computenodeboundary@loop
+ \forest@loop
\ifnum\c@pgf@counta>0
\forest@lt{inner point \the\c@pgf@counta}%
\forest@lt{outer point \the\c@pgf@counta}%
\advance\c@pgf@counta-1
- \forest@computenodeboundary@repeat
+ \forest@repeat
}%
\csdef{forest@compute@node@boundary@isosceles triangle}{%
\forest@mt{apex}%
@@ -3300,23 +5478,23 @@
\getradii
\forest@mt{puff 1}%
\c@pgf@counta=\puffs\relax
- \forest@computenodeboundary@loop
+ \forest@loop
\ifnum\c@pgf@counta>0
\forest@lt{puff \the\c@pgf@counta}%
\advance\c@pgf@counta-1
- \forest@computenodeboundary@repeat
+ \forest@repeat
}
\def\forest@compute@node@boundary@starburst{
\calculatestarburstpoints
\forest@mt{outer point 1}%
\c@pgf@counta=\totalpoints\relax
\divide\c@pgf@counta2
- \forest@computenodeboundary@loop
+ \forest@loop
\ifnum\c@pgf@counta>0
\forest@lt{inner point \the\c@pgf@counta}%
\forest@lt{outer point \the\c@pgf@counta}%
\advance\c@pgf@counta-1
- \forest@computenodeboundary@repeat
+ \forest@repeat
}%
\def\forest@compute@node@boundary@signal{%
\forest@mt{east}%
@@ -3459,11 +5637,9 @@
\forest@lt{before south west}%
}%
\def\forest@node@computeabsolutepositions{%
- \forestoset{x}{0pt}%
- \forestoset{y}{0pt}%
\edef\forest@marshal{%
\noexpand\forest@node@foreachchild{%
- \noexpand\forest@node@computeabsolutepositions@{0pt}{0pt}{\forestove{grow}}%
+ \noexpand\forest@node@computeabsolutepositions@{\forestove{x}}{\forestove{y}}{\forestove{grow}}%
}%
}\forest@marshal
}
@@ -3557,7 +5733,7 @@
\fi
}
\def\forest@node@drawtree@{%
- \forest@node@foreach{\forest@draw@node}%
+ \forest@forthis{\forestset{draw tree method}}%
\forest@node@Ifnamedefined{forest@baseline@node}{%
\edef\forest@temp{%
\noexpand\pgfsetbaselinepointlater{%
@@ -3567,8 +5743,6 @@
}%
}\forest@temp
}{}%
- \forest@node@foreachdescendant{\forest@draw@edge}%
- \forest@node@foreach{\forest@draw@tikz}%
}
\def\forest@draw@node{%
\ifnum\forestove{phantom}=0
@@ -3583,70 +5757,18 @@
\fi
}
\def\forest@draw@edge{%
- \ifnum\forestove{phantom}=0
- \ifnum\forestOve{\forestove{@parent}}{phantom}=0
- \edef\forest@temp{\forestove{edge path}}%
- \forest@temp
+ \ifnum\forest@cn=\forest@root\relax\else
+ \ifnum\forestove{phantom}=0
+ \ifnum\forestOve{\forestove{@parent}}{phantom}=0
+ \edef\forest@temp{\forestove{edge path}}%
+ \forest@temp
+ \fi
\fi
\fi
}
\def\forest@draw@tikz{%
\forestove{tikz}%
}
-\def\forest@tikz@parse@node#1(#2){%
- \pgfutil@in@.{#2}%
- \ifpgfutil@in@
- \expandafter\forest@tikz@parse@node@checkiftikzname@withdot
- \else%
- \expandafter\forest@tikz@parse@node@checkiftikzname@withoutdot
- \fi%
- #1(#2)\forest@end
-}
-\def\forest@tikz@parse@node@checkiftikzname@withdot#1(#2.#3)\forest@end{%
- \forest@tikz@parse@node@checkiftikzname#1{#2}{.#3}}
-\def\forest@tikz@parse@node@checkiftikzname@withoutdot#1(#2)\forest@end{%
- \forest@tikz@parse@node@checkiftikzname#1{#2}{}}
-\def\forest@tikz@parse@node@checkiftikzname#1#2#3{%
- \expandafter\ifx\csname pgf@sh@ns@#2\endcsname\relax
- \forest@forthis{%
- \forest@nameandgo{#2}%
- \edef\forest@temp@relativenodename{\forestove{name}}%
- }%
- \else
- \def\forest@temp@relativenodename{#2}%
- \fi
- \expandafter\forest@original@tikz@parse@node\expandafter#1\expandafter(\forest@temp@relativenodename#3)%
-}
-\def\forest@nameandgo#1{%
- \pgfutil@in@!{#1}%
- \ifpgfutil@in@
- \forest@nameandgo@(#1)%
- \else
- \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
- \fi
-}
-\def\forest@nameandgo@(#1!#2){%
- \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
- \forest@go{#2}%
-}
-\pgfdeclaregenericanchor{parent anchor}{%
- \forest@generic@parent@child@anchor{parent }{#1}}
-\pgfdeclaregenericanchor{child anchor}{%
- \forest@generic@parent@child@anchor{child }{#1}}
-\pgfdeclaregenericanchor{anchor}{%
- \forest@generic@parent@child@anchor{}{#1}}
-\def\forest@generic@parent@child@anchor#1#2{%
- \forestOget{\forest@node@Nametoid{\pgfreferencednodename}}{#1anchor}\forest@temp@parent@anchor
- \ifdefempty\forest@temp@parent@anchor{%
- \pgf@sh@reanchor{#2}{center}%
- \xdef\forest@hack@tikzshapeborder{%
- \noexpand\tikz@shapebordertrue
- \def\noexpand\tikz@shapeborder@name{\pgfreferencednodename}%
- }\aftergroup\forest@hack@tikzshapeborder
- }{%
- \pgf@sh@reanchor{#2}{\forest@temp@parent@anchor}%
- }%
-}
\newdimen\forest@xg
\newdimen\forest@yg
\newdimen\forest@xs
@@ -3705,7 +5827,7 @@
\edef\forest@ppi@inputprefix{#1}%
\c@pgf@counta=0
\c@pgf@countb=-1
- \loop
+ \safeloop
\ifnum\c@pgf@counta<\csname#1n\endcsname\relax
\letcs\forest@xo{#1\the\c@pgf@counta xo}%
\letcs\forest@yo{#1\the\c@pgf@counta yo}%
@@ -3741,7 +5863,7 @@
\cslet{#1\the\c@pgf@counta xp}\relax
\cslet{#1\the\c@pgf@counta yp}\relax
\advance\c@pgf@counta 1
- \repeat
+ \saferepeat
\cslet{#1n}\relax
\advance\c@pgf@countb 1
\csedef{#2n}{\the\c@pgf@countb}%
@@ -3814,7 +5936,7 @@
\def\forest@breakpath@step{-1}%
\def\forest@breakpath@test{\forest@temp@count>\forest@i\relax}%
\fi
- \loop
+ \safeloop
\advance\forest@temp@count\forest@breakpath@step\relax
\expandafter\ifnum\forest@breakpath@test
\pgfpointintersectionoflines
@@ -3837,7 +5959,7 @@
\forest@last@x\forest@last@y
{\forest@bp@prefix\the\forest@temp@count @}%
\csedef{\forest@bp@prefix(\the\pgf@x,\the\pgf@y)}{\the\forest@temp@count}%
- \repeat
+ \saferepeat
\fi
\forest@breakpath@op{#1}{#2}%
\def\forest@previous@x{#1}%
@@ -3864,34 +5986,32 @@
\forest@breakpath#1{forest@pi@}\forest@brokenpath
\forest@sort@inner@arrays{forest@pi@}#2%
\forest@pathtodict\forest@brokenpath{forest@pi@}%
- \forest@gettightedgeofpath@getedge
- \pgfsyssoftpath@getcurrentpath\forest@edge
+ \forest@gettightedgeofpath@getedge\forest@edge
\forest@simplifypath\forest@edge#3%
}
\def\forest@getbothtightedgesofpath#1#2#3{%
{%
\forest@get@one@tightedgeofpath#1\forest@sort@ascending\forest@gep@firstedge
\c@pgf@counta=0
- \loop
+ \forest@loop
\ifnum\c@pgf@counta<\forest@pi@n\relax
\forest@ppi@deflet{forest@pi@\the\c@pgf@counta @}%
\forest@reversearray\forest@ppi@let
{0}%
{\csname forest@pi@\the\c@pgf@counta @n\endcsname}%
\advance\c@pgf@counta 1
- \repeat
- \forest@gettightedgeofpath@getedge
- \pgfsyssoftpath@getcurrentpath\forest@edge
+ \forest@repeat
+ \forest@gettightedgeofpath@getedge\forest@edge
\forest@simplifypath\forest@edge\forest@gep@secondedge
- \global\let\forest@gep@global@firstedge\forest@gep@firstedge
- \global\let\forest@gep@global@secondedge\forest@gep@secondedge
- }%
+ \global\let\forest@gep@global@firstedge\forest@gep@firstedge
+ \global\let\forest@gep@global@secondedge\forest@gep@secondedge
+ }%
\let#2\forest@gep@global@firstedge
\let#3\forest@gep@global@secondedge
}
\def\forest@sort@inner@arrays#1#2{%
\c@pgf@counta=0
- \forest@loopa
+ \safeloop
\ifnum\c@pgf@counta<\csname#1n\endcsname
\c@pgf@countb=\csname#1\the\c@pgf@counta @n\endcsname\relax
\ifnum\c@pgf@countb>1
@@ -3901,7 +6021,7 @@
\forest@sort\forest@ppi@cmp\forest@ppi@let#2{0}{\the\c@pgf@countb}%
\fi
\advance\c@pgf@counta 1
- \forest@repeata
+ \saferepeat
}
\def\forest@ppi@deflet#1{%
\edef\forest@ppi@let##1##2{%
@@ -3936,7 +6056,7 @@
\def\forest@pathtodict@from{(#1,#2)-}%
\def\forest@pathtodict@subpathstart{}%
}
-\def\forest@gettightedgeofpath@getedge{%
+\def\forest@gettightedgeofpath@getedge#1{% cs to store the edge into
\pgfsyssoftpath@setcurrentpath\pgfutil@empty
\let\forest@last@x\relax
\let\forest@last@y\relax
@@ -3944,24 +6064,26 @@
\forest@temp@count=\forest@pi@n\relax
\advance\forest@temp@count -1
\edef\forest@nminusone{\the\forest@temp@count}%
- \forest@loopa
+ \safeloop
\ifnum\c@pgf@counta<\forest@nminusone\relax
\forest@gettightedgeofpath@getedge@loopa
- \forest@repeata
+ \saferepeat
\ifnum\forest@nminusone<\forest@n\relax\else
\ifnum\csname forest@pi@\forest@nminusone @n\endcsname>0
\forest@gettightedgeofpath@maybemoveto{\forest@nminusone}{0}%
\fi
\fi
+ \pgfsyssoftpath@getcurrentpath#1%
+ \pgfsyssoftpath@setcurrentpath\pgfutil@empty
}
\def\forest@gettightedgeofpath@getedge@loopa{%
\ifnum\csname forest@pi@\the\c@pgf@counta @n\endcsname>0
\forest@gettightedgeofpath@maybemoveto{\the\c@pgf@counta}{0}%
\c@pgf@countb=0
- \forest@loopb
+ \safeloop
\ifnum\c@pgf@countb<\csname forest@pi@\the\c@pgf@counta @n\endcsname\relax
\forest@gettightedgeofpath@getedge@loopb
- \forest@repeatb
+ \saferepeat
\fi
\advance\c@pgf@counta 1
}
@@ -3970,7 +6092,7 @@
\advance\c@pgf@counta 1
\edef\forest@aplusone{\the\c@pgf@counta}%
\advance\c@pgf@counta -1
- \forest@loopc
+ \safeloop
\ifnum\c@pgf@countc<\csname forest@pi@\forest@aplusone @n\endcsname\relax
\forest@tempfalse
\expandafter\ifx\csname forest@pi@(%
@@ -4001,7 +6123,7 @@
\c@pgf@countb=\csname forest@pi@\the\c@pgf@counta @n\endcsname
\fi
\advance\c@pgf@countc 1
- \forest@repeatc
+ \saferepeat
\advance\c@pgf@countb 1
}
\def\forest@gettightedgeofpath@maybemoveto#1#2{%
@@ -4035,6 +6157,7 @@
\fi
\forest@restore@pgfsyssoftpath@tokendefs
\pgfsyssoftpath@getcurrentpath#2%
+ \pgfsyssoftpath@setcurrentpath\pgfutil@empty
}
\def\forest@simplifypath@moveto#1#2{%
\ifx\forest@last@x\relax\else
@@ -4165,7 +6288,7 @@
% compute the distance
\let\forest@distance\relax
\c@pgf@countc=0
- \loop
+ \forest@loop
\ifnum\c@pgf@countc<\csname forest@PI1@n\endcsname\relax
\ifnum\csname forest@PI1@\the\c@pgf@countc @n\endcsname=0 \else
\ifnum\csname forest@PI2@\the\c@pgf@countc @n\endcsname=0 \else
@@ -4181,7 +6304,7 @@
\fi
\fi
\advance\c@pgf@countc 1
- \repeat
+ \forest@repeat
\let#3\forest@distance
}
% merge projections: we need two projection arrays, both containing
@@ -4274,13 +6397,13 @@
\forest@dbep@mp@iterateone\forest@input@prefix@two\c@pgf@countb\forest@output@prefix@two
}
\def\forest@dbep@mp@iterateone#1#2#3{%
- \loop
+ \forest@loop
\ifnum#2<\csname#1n\endcsname\relax
\forest@dbep@mp@@store@p#1#2%
\forest@dbep@mp@@store@o#1#2#3%
\advance\c@pgf@countc 1
\advance#21
- \repeat
+ \forest@repeat
}
\newif\ifforest@equaltotolerance
\def\forest@equaltotolerance#1#2{{%
@@ -4375,15 +6498,6 @@
\ifdim#2<\pgf@ya\relax\pgf@ya=#2 \fi
\ifdim#2>\pgf@yb\relax\pgf@yb=#2 \fi
}
-\newif\ifforesttikzcshack
-\foresttikzcshacktrue
-\newif\ifforest@install@keys@to@tikz@path@
-\forest@install@keys@to@tikz@path@true
-\forestset{package@options/.cd,
- external/.is if=forest@external@,
- tikzcshack/.is if=foresttikzcshack,
- tikzinstallkeys/.is if=forest@install@keys@to@tikz@path@,
-}
\pgfkeys{/forest/external/.cd,
copy command/.initial={cp "\source" "\target"},
optimize/.is if=forest@external@optimize@,
@@ -4404,12 +6518,17 @@
}{}%
\fi
}
-\newif\ifforest@external@
\newif\ifforest@external@optimize@
\forest@external@optimize@true
-\ProcessPgfPackageOptions{/forest/package@options}
\ifforest@install@keys@to@tikz@path@
- \tikzset{fit to tree/.style={/forest/fit to tree}}
+\tikzset{
+ fit to/.style={
+ /forest/for nodewalk=%
+ {TeX={\def\forest@fitto{}},#1}%
+ {TeX={\eappto\forest@fitto{(\forestove{name})}}},
+ fit/.expanded={\forest@fitto}
+ },
+}
\fi
\ifforest@external@
\ifdefined\tikzexternal@tikz@replacement\else
@@ -4447,13 +6566,23 @@
}%
}%
\fi
-\newenvironment{forest}{\pgfkeysalso{/forest/begin forest}\Collect@Body\forest@env}{}
-\long\def\Forest{\pgfkeysalso{/forest/begin forest}\@ifnextchar*{\forest@nogroup}{\forest@group}}
-\def\forest@group#1{{\forest@env{#1}}}
-\def\forest@nogroup*#1{\forest@env{#1}}
+\NewDocumentEnvironment{forest}{D(){stages}}{%
+ \forest@defstages{#1}%
+ \Collect@Body
+ \forest@env
+}{}
+\NewDocumentCommand{\Forest}{s D(){stages} m}{%
+ \forest@defstages{#2}%
+ \IfBooleanTF{#1}{\let\forest@next\forest@env}{\let\forest@next\forest@group@env}%
+ \forest@next{#3}%
+}
+\def\forest@defstages#1{%
+ \def\forest@stages{#1}%
+}
+\def\forest@group@env#1{{\forest@env{#1}}}
\newif\ifforest@externalize@tree@
\newif\ifforest@was@tikzexternalwasenable
-\long\def\forest@env#1{%
+\newcommand\forest@env[1]{%
\let\forest@external@next\forest@begin
\forest@was@tikzexternalwasenablefalse
\ifdefined\tikzexternal@tikz@replacement
@@ -4465,16 +6594,23 @@
\forest@externalize@tree@false
\ifforest@external@
\ifforest@was@tikzexternalwasenable
- \tikzifexternalizing{%
- \let\forest@external@next\forest@begin@externalizing
- }{%
- \let\forest@external@next\forest@begin@externalize
- }%
+ \forest@env@
\fi
\fi
\forest@standardnode@calibrate
\forest@external@next{#1}%
}
+\def\forest@env@{%
+ \iftikzexternalexportnext
+ \tikzifexternalizing{%
+ \let\forest@external@next\forest@begin@externalizing
+ }{%
+ \let\forest@external@next\forest@begin@externalize
+ }%
+ \else
+ \tikzexternalexportnexttrue
+ \fi
+}
\long\def\forest@begin@externalizing#1{%
\forest@external@setup{#1}%
\let\forest@external@next\forest@begin
@@ -4570,8 +6706,7 @@
}
\def\forest@includeexternal#1{%
\edef\forest@temp{\pgfkeysvalueof{/forest/external/context}}%
- \typeout{forest: Including external picture '#1' for forest context+code:
- '\expandafter\detokenize\expandafter{\forest@externalize@id}'}%
+ %\typeout{forest: Including external picture '#1' for forest context+code: '\expandafter\detokenize\expandafter{\forest@externalize@id}'}%
{%
%\def\pgf@declaredraftimage##1##2{\def\pgf@image{\hbox{}}}%
\tikzsetnextfilename{#1}%
@@ -4599,9 +6734,7 @@
}
\def\forest@do{%
\forest@node@Compute@numeric@ts@info{\forest@root}%
- \forestset{process keylist=given options}%
- \forestset{stages}%
- \pgfkeysalso{/forest/end forest}%
+ \expandafter\forestset\expandafter{\forest@stages}%
\ifforest@was@tikzexternalwasenable
\tikzexternalenable
\fi
@@ -4698,11 +6831,9 @@
}
}
\def\forest@forestcs@resetxy{%
- \ifnum\forest@cn=0
- \else
- \global\pgf@x\forestove{x}%
- \global\pgf@y\forestove{y}%
- \fi
+ \ifnum\forest@cn=0 \forest@cs@invalidnodeerror\fi
+ \global\pgf@x\forestove{x}%
+ \global\pgf@y\forestove{y}%
}
\def\forest@forestcs@ls{%
\ifdefined\forest@forestcs@l
@@ -4725,8 +6856,12 @@
}
\def\forest@forestcs@namegoanchor#1.#2\forest@end{%
\forest@nameandgo{#1}%
+ \ifnum\forest@cn=0 \forest@cs@invalidnodeerror\fi
\forest@forestcs@anchor{#2}%
}
+\def\forest@cs@invalidnodeerror{%
+ \PackageError{forest}{Attempt to refer to the invalid node by "forest cs"}%
+}
\tikzdeclarecoordinatesystem{forest}{%
\forest@forthis{%
\forest@forestcs@resetxy
@@ -4735,6 +6870,321 @@
\pgfqkeys{/forest/@cs}{#1}%
}%
}
+\def\forest@tikz@parse@node#1(#2){%
+ \pgfutil@in@.{#2}%
+ \ifpgfutil@in@
+ \expandafter\forest@tikz@parse@node@checkiftikzname@withdot
+ \else%
+ \expandafter\forest@tikz@parse@node@checkiftikzname@withoutdot
+ \fi%
+ #1(#2)\forest@end
+}
+\def\forest@tikz@parse@node@checkiftikzname@withdot#1(#2.#3)\forest@end{%
+ \forest@tikz@parse@node@checkiftikzname#1{#2}{.#3}}
+\def\forest@tikz@parse@node@checkiftikzname@withoutdot#1(#2)\forest@end{%
+ \forest@tikz@parse@node@checkiftikzname#1{#2}{}}
+\def\forest@tikz@parse@node@checkiftikzname#1#2#3{%
+ \expandafter\ifx\csname pgf@sh@ns@#2\endcsname\relax
+ \forest@forthis{%
+ \forest@nameandgo{#2}%
+ \ifnum\forest@cn=0 \forest@cs@invalidnodeerror\fi
+ \edef\forest@temp@relativenodename{\forestove{name}}%
+ }%
+ \else
+ \def\forest@temp@relativenodename{#2}%
+ \fi
+ \expandafter\forest@original@tikz@parse@node\expandafter#1\expandafter(\forest@temp@relativenodename#3)%
+}
+\def\forest@nameandgo#1{%
+ \pgfutil@in@!{#1}%
+ \ifpgfutil@in@
+ \forest@nameandgo@(#1)%
+ \else
+ \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
+ \fi
+}
+\def\forest@nameandgo@(#1!#2){%
+ \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
+ \forest@go{#2}%
+}
+\forestset{
+ declare count={rotate}{0},
+ autoforward'={rotate}{node options},
+}
+\newif\ifforest@anchor@snapbordertocompass
+\newif\ifforest@anchor@forwardtotikz
+\newif\ifforest@anchor@isborder
+\def\forestanchortotikzanchor#1#2{% #1 = forest anchor, #2 = macro to receive the tikz anchor
+ \forest@anchor@forwardtotikzfalse
+ \forest@anchor@do{}{#1}{\forest@cn}%
+ \let#2\forest@temp@anchor
+}
+\pgfdeclaregenericanchor{child anchor}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{child anchor}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent anchor}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent anchor}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{anchor}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{anchor}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children first}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children first}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{first}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{first}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent first}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent first}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent last}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent last}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{last}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{last}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children last}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children last}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children first'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children first'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{first'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{first'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent first'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent first'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{parent last'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{parent last'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{last'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{last'}{\forest@referencednodeid}%
+}
+\pgfdeclaregenericanchor{children last'}{%
+ \forest@anchor@forwardtotikztrue
+ \forest@anchor@do{#1}{children last'}{\forest@referencednodeid}%
+}
+\def\forest@anchor@do#1#2#3{% #1 = shape name, #2 = (potentially) forest anchor, #3 = node id
+ \forest@fornode{#3}{%
+ \def\forest@temp@anchor{#2}%
+ \forest@anchor@snapbordertocompassfalse
+ \forest@anchor@isborderfalse
+ \forest@anchor@to@tikz@anchor
+ \forest@anchor@border@to@compass
+ \ifforest@anchor@forwardtotikz
+ \forest@anchor@forward{#1}%
+ \else
+ \fi
+ }%
+}
+\def\forest@anchor@to@tikz@anchor{%
+ \ifcsdef{forest@anchor@@\forest@temp@anchor}{%
+ \csuse{forest@anchor@@\forest@temp@anchor}%
+ \forest@anchor@to@tikz@anchor
+ }{}%
+}
+\csdef{forest@anchor@@parent anchor}{%
+ \forestoget{parent anchor}\forest@temp@anchor}
+\csdef{forest@anchor@@child anchor}{%
+ \forestoget{child anchor}\forest@temp@anchor}
+\csdef{forest@anchor@@anchor}{%
+ \forestoget{anchor}\forest@temp@anchor}
+\csdef{forest@anchor@@children'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}}%
+}
+\csdef{forest@anchor@@parent'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}+180}%
+}
+\csdef{forest@anchor@@first'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 -\else+\fi90}%
+}
+\csdef{forest@anchor@@last'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 +\else-\fi90}%
+}
+\csdef{forest@anchor@@parent first'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor@parent{\number\numexpr\forestove{grow}-\forestove{rotate}+180}%
+ \edef\forest@temp@anchor@first{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 -\else+\fi90}%
+ \forest@getaverageangle{\forest@temp@anchor@parent}{\forest@temp@anchor@first}\forest@temp@anchor
+}
+\csdef{forest@anchor@@parent last'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor@parent{\number\numexpr\forestove{grow}-\forestove{rotate}+180}%
+ \edef\forest@temp@anchor@last{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 +\else-\fi90}%
+ \forest@getaverageangle{\forest@temp@anchor@parent}{\forest@temp@anchor@last}\forest@temp@anchor
+}
+\csdef{forest@anchor@@children first'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor@first{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 -\else+\fi90}%
+ \forest@getaverageangle{\forestove{grow}-\forestove{rotate}}{\forest@temp@anchor@first}\forest@temp@anchor
+}
+\csdef{forest@anchor@@children last'}{%
+ \forest@anchor@isbordertrue
+ \edef\forest@temp@anchor@last{\number\numexpr\forestove{grow}-\forestove{rotate}\ifnum\forestove{reversed}=0 +\else-\fi90}%
+ \forest@getaverageangle{\forestove{grow}-\forestove{rotate}}{\forest@temp@anchor@last}\forest@temp@anchor
+}
+\csdef{forest@anchor@@children}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@children'}%
+}
+\csdef{forest@anchor@@parent}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@parent'}%
+}
+\csdef{forest@anchor@@first}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@first'}%
+}
+\csdef{forest@anchor@@last}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@last'}%
+}
+\csdef{forest@anchor@@parent first}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@parent first'}%
+}
+\csdef{forest@anchor@@parent last}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@parent last'}%
+}
+\csdef{forest@anchor@@children first}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@children first'}%
+}
+\csdef{forest@anchor@@children last}{%
+ \forest@anchor@snapbordertocompasstrue
+ \csuse{forest@anchor@@children last'}%
+}
+\def\forest@getaverageangle#1#2#3{%
+ \edef\forest@temp{\number\numexpr #1-#2+540}%
+ \pgfmathMod{\forest@temp}{360}\pgfmathtruncatemacro\pgfmathresult{\pgfmathresult}
+ \edef\forest@temp{360+#2+((\pgfmathresult-180)/2)}%
+ \pgfmathMod{\forest@temp}{360}\pgfmathtruncatemacro#3{\pgfmathresult}%
+}
+\def\forest@anchor@border@to@compass{%
+ \ifforest@anchor@isborder
+ \ifforest@anchor@snapbordertocompass
+ \forest@anchor@snap@border@to@compass
+ \else
+ \pgfmathMod{\forest@temp@anchor}{360}%
+ \pgfmathtruncatemacro\forest@temp@anchor{\pgfmathresult}%
+ \fi
+ \ifforest@anchor@forwardtotikz
+ \ifcsname pgf@anchor%
+ @\csname pgf@sh@ns@\pgfreferencednodename\endcsname
+ @\csname forest@compass@\forest@temp@anchor\endcsname
+ \endcsname
+ \letcs\forest@temp@anchor{forest@compass@\forest@temp@anchor}%
+ \fi
+ \else
+ \ifforest@anchor@snapbordertocompass
+ \letcs\forest@temp@anchor{forest@compass@\forest@temp@anchor}%
+ \fi
+ \fi
+ \fi
+}
+\csdef{forest@compass@0}{east}
+\csdef{forest@compass@45}{north east}
+\csdef{forest@compass@90}{north}
+\csdef{forest@compass@135}{north west}
+\csdef{forest@compass@180}{west}
+\csdef{forest@compass@225}{south west}
+\csdef{forest@compass@270}{south}
+\csdef{forest@compass@315}{south east}
+\csdef{forest@compass@360}{east}
+\def\forest@anchor@snap@border@to@compass{%
+ \pgfmathMod{\forest@temp@anchor}{360}%
+ \pgfmathdivide{\pgfmathresult}{45}%
+ \pgfmathround{\pgfmathresult}%
+ \pgfmathmultiply{\pgfmathresult}{45}%
+ \pgfmathtruncatemacro\forest@temp@anchor{\pgfmathresult}%
+}
+\def\forest@anchor@forward#1{% #1 = shape name
+ \ifdefempty\forest@temp@anchor{%
+ \pgf@sh@reanchor{#1}{center}%
+ \xdef\forest@hack@tikzshapeborder{%
+ \noexpand\tikz@shapebordertrue
+ \def\noexpand\tikz@shapeborder@name{\pgfreferencednodename}%
+ }\aftergroup\forest@hack@tikzshapeborder
+ }{%
+ \pgf@sh@reanchor{#1}{\forest@temp@anchor}%
+ }%
+}
+\def\forest@referencednodeid{\forest@node@Nametoid{\forest@referencednodename}}%
+\def\forest@referencednodename{%
+ \expandafter\expandafter\expandafter\forest@referencednodename@\expandafter\pgfreferencednodename\forest@pgf@notyetpositioned\relax
+}
+\expandafter\def\expandafter\forest@referencednodename@\expandafter#\expandafter1\forest@pgf@notyetpositioned#2\relax{%
+ \if\relax#1\relax\forest@referencednodename@stripafter#2\relax\fi
+ \if\relax#2\relax#1\fi
+}
+\expandafter\def\expandafter\forest@referencednodename@stripafter\expandafter#\expandafter1\forest@pgf@notyetpositioned\relax{#1}
+\def\forest@Pointanchor#1#2{% #1 = node id, #2 = anchor
+ {%
+ \def\forest@pa@temp@name{name}%
+ \forestOifdefined{#1}{@box}{%
+ \forestOget{#1}{@box}\forest@temp
+ \ifdefempty\forest@temp{}{%
+ \def\forest@pa@temp@name{later@name}%
+ }%
+ }{}%
+ \setbox0\hbox{%
+ \begin{pgfpicture}%
+ \if\relax\forestOve{#1}{#2}\relax
+ \pgfpointanchor{\forestOve{#1}{\forest@pa@temp@name}}{center}%
+ \else
+ \pgfpointanchor{\forestOve{#1}{\forest@pa@temp@name}}{\forestOve{#1}{#2}}%
+ \fi
+ \xdef\forest@global@marshal{%
+ \noexpand\global\noexpand\pgf@x=\the\pgf@x\relax
+ \noexpand\global\noexpand\pgf@y=\the\pgf@y
+ }%
+ \end{pgfpicture}%
+ }%
+ }%
+ \forest@global@marshal
+}
+\def\forest@pointanchor#1{% #1 = anchor
+ \forest@Pointanchor{\forest@cn}{#1}%
+}
+\ifdefempty{\forest@compat}{}{%
+ \RequirePackage{forest-compat}
+}
\endinput
%%
%% End of file `forest.sty'.