From 0a913026039e7c9ab353dbc13d77074411ba616a Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Fri, 4 Mar 2016 22:52:55 +0000
Subject: forest (4mar16)

git-svn-id: svn://tug.org/texlive/trunk@39937 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/forest/forest.sty | 114 +++++++++++++++++++-------
 1 file changed, 84 insertions(+), 30 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/forest/forest.sty')

diff --git a/Master/texmf-dist/tex/latex/forest/forest.sty b/Master/texmf-dist/tex/latex/forest/forest.sty
index 9b7800e7c82..a1746c66751 100644
--- a/Master/texmf-dist/tex/latex/forest/forest.sty
+++ b/Master/texmf-dist/tex/latex/forest/forest.sty
@@ -44,7 +44,7 @@
 %% - LICENCE
 %% To use the package, only the files marked with + need to be installed.
 %%
-\ProvidesPackage{forest}[2016/02/20 v2.0.1 Drawing (linguistic) trees]
+\ProvidesPackage{forest}[2016/03/04 v2.0.2 Drawing (linguistic) trees]
 
 \RequirePackage{tikz}[2013/12/13]
 \usetikzlibrary{shapes}
@@ -84,11 +84,12 @@
 \foresttikzcshacktrue
 \def\forest@loadlibrarieslater{}
 \AtEndOfPackage{\forest@loadlibrarieslater}
-\NewDocumentCommand\useforestlibrary{s m}{%
-  \forcsvlist\useforestlibrary@{#2}%
-  \IfBooleanT{#1}{\forestapplylibrarydefaults{#2}}%
+\NewDocumentCommand\useforestlibrary{s O{} m}{%
+  \def\useforestlibrary@@##1{\useforestlibrary@{#2}{##1}}%
+  \forcsvlist\useforestlibrary@@{#3}%
+  \IfBooleanT{#1}{\forestapplylibrarydefaults{#3}}%
 }
-\def\useforestlibrary@#1{\RequirePackage{forest-lib-#1}}
+\def\useforestlibrary@#1#2{\RequirePackage[#1]{forest-lib-#2}}
 \def\forestapplylibrarydefaults#1{\forcsvlist\forestapplylibrarydefaults@{#1}}
 \def\forestapplylibrarydefaults@#1{\forestset{libraries/#1/defaults/.try}}
 \NewDocumentCommand\ProvidesForestLibrary{m O{}}{\ProvidesPackage{forest-lib-#1}[#2]}
@@ -2219,21 +2220,27 @@
 \forestset{
   declare toks register/.code={%
     \forest@declareregisterhandler\forest@declaretoksregister@handler{#1}%
+    \forestset{#1={}}%
   },
   declare autowrapped toks register/.code={%
     \forest@declareregisterhandler\forest@declareautowrappedtoksregister@handler{#1}%
+    \forestset{#1={}}%
   },
   declare keylist register/.code={%
     \forest@declareregisterhandler\forest@declarekeylistregister@handler{#1}%
+    \forestset{#1'={}}%
   },
   declare dimen register/.code={%
     \forest@declareregisterhandler\forest@declaredimenregister@handler{#1}%
+    \forestset{#1'=0pt}%
   },
   declare count register/.code={%
     \forest@declareregisterhandler\forest@declarecountregister@handler{#1}%
+    \forestset{#1'=0}%
   },
   declare boolean register/.code={%
     \forest@declareregisterhandler\forest@declarebooleanregister@handler{#1}%
+    \forestset{#1=0}%
   },
 }
 \forestset{
@@ -3185,6 +3192,11 @@
     \fi
   },
 }
+\pgfqkeys{/handlers}{
+  .nodewalk style/.code={\forest@handlers@savecurrentpath\pgfkeysalso{%
+      \forest@currentpath/nodewalk/\forest@currentname/.style={#1}%
+    }},
+}
 \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
@@ -4102,6 +4114,7 @@
 }
 \let\forest@nodewalkstephandler@styletrueorfalse\forest@nodewalkstephandler@styletrue
 \def\forest@last@node{0}
+\csdef{forest@nodewalk@saved@dynamic nodes}{}
 \def\forest@nodehandleby@name@nodewalk@or@bracket#1{%
   \ifx\pgfkeysnovalue#1%
     \edef\forest@last@node{\forest@node@Nametoid{forest@last@node}}%
@@ -4112,6 +4125,7 @@
 \def\forest@nodehandleby@nnb@checkfirst#1#2\forest@END{%
   \ifx[#1%]
     \forest@create@node{#1#2}%
+    \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@last@node,}%
   \else
     \forest@forthis{%
       \forest@nameandgo{#1#2}%
@@ -4210,11 +4224,17 @@
 \forestset{%
   create/.code={%
     \forest@create@node{#1}%
-    \forest@fornode{\forest@last@node}{\forest@node@setalias{forest@last@node}}%
+    \forest@fornode{\forest@last@node}{%
+      \forest@node@setalias{forest@last@node}%
+      \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@last@node,}%
+    }%
   },
   create'/.code={%
     \forest@create@node@and@process@given@options{#1}%
-    \forest@fornode{\forest@last@node}{\forest@node@setalias{forest@last@node}}%
+    \forest@fornode{\forest@last@node}{%
+      \forest@node@setalias{forest@last@node}%
+      \cseappto{forest@nodewalk@saved@dynamic nodes}{\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}},
@@ -4230,6 +4250,7 @@
   insert before''/.code={\def\forest@dynamics@copyhow{2}\forest@appto@do@dynamics\forest@insertbefore@node{#1}},
   remove/.code={%
     \pgfkeysalso{alias=forest@last@node}%
+    \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@cn,}%
     \expandafter\apptotoks\expandafter\forest@do@dynamics\expandafter{%
       \expandafter\forest@remove@node\expandafter{\forest@cn}}%
   },
@@ -4260,8 +4281,10 @@
 }
 \def\forest@replaceby@code#1#2{%#1=node spec,#2=insert after['][']
   \ifnum\forestove{@parent}=0
-    \pgfkeysalso{set root={#1}}%
+    \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@cn,}%
+    \pgfkeysalso{alias=forest@last@node,set root={#1}}%
   \else
+    \cseappto{forest@nodewalk@saved@dynamic nodes}{\forest@cn,}%
     \pgfkeysalso{alias=forest@last@node,#2={#1}}%
     \eapptotoks\forest@do@dynamics{%
       \noexpand\ifnum\noexpand\forestOve{\forest@cn}{@parent}=\forestove{@parent}
@@ -4325,6 +4348,11 @@
 \def\forest@nodesort@let#1#2{%
   \csletcs{forest@nodesort@#1}{forest@nodesort@#2}%
 }
+\forestset{
+  define long step={last dynamic node}{style,must start at valid node=false}{%
+    name=forest@last@node
+  }
+}
 \def\forest@root{0}
   %%% begin listing region: stages
 \forestset{
@@ -4442,7 +4470,10 @@
   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}}{},
+  draw tree node'/.code={\forest@draw@node@},
+  draw tree edge'/.code={\forest@draw@edge@},
+  draw tree tikz'/.code={\forest@draw@tikz@},
+  processing order/.nodewalk style={tree},
   %given options processing order/.style={processing order},
   %before typesetting nodes processing order/.style={processing order},
   %before packing processing order/.style={processing order},
@@ -4611,13 +4642,15 @@
   \fi
 }
 \def\forest@pack{%
+  \pgfsyssoftpath@getcurrentpath\forest@pack@original@path
   \forest@pack@computetiers
   \forest@pack@computegrowthuniformity
   \forest@@pack
+  \pgfsyssoftpath@setcurrentpath\forest@pack@original@path
 }
 \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
@@ -5745,8 +5778,14 @@
     \fi
   \fi
 }
+\def\forest@drawtree@root{0}
 \def\forest@node@drawtree@{%
-  \forest@forthis{\forestset{draw tree method}}%
+  \forest@forthis{%
+    \forest@saveandrestoremacro\forest@drawtree@root{%
+      \edef\forest@drawtree@root{\forest@cn}%
+      \forestset{draw tree method}%
+    }%
+  }%
   \forest@node@Ifnamedefined{forest@baseline@node}{%
     \edef\forest@temp{%
       \noexpand\pgfsetbaselinepointlater{%
@@ -5759,27 +5798,37 @@
 }
 \def\forest@draw@node{%
   \ifnum\forestove{phantom}=0
-    \forest@node@forest@positionnodelater@restore
-    \ifforest@drawtree@preservenodeboxes@
-      \pgfnodealias{forest@temp}{\forestove{later@name}}%
-    \fi
-    \pgfpositionnodenow{\pgfqpoint{\forestove{x}}{\forestove{y}}}%
-    \ifforest@drawtree@preservenodeboxes@
-      \pgfnodealias{\forestove{later@name}}{forest@temp}%
-    \fi
+    \forest@draw@node@
+  \fi
+}
+\def\forest@draw@node@{%
+  \forest@node@forest@positionnodelater@restore
+  \ifforest@drawtree@preservenodeboxes@
+    \pgfnodealias{forest@temp}{\forestove{later@name}}%
+  \fi
+  \pgfpositionnodenow{\pgfqpoint{\forestove{x}}{\forestove{y}}}%
+  \ifforest@drawtree@preservenodeboxes@
+    \pgfnodealias{\forestove{later@name}}{forest@temp}%
   \fi
 }
 \def\forest@draw@edge{%
-  \ifnum\forest@cn=\forest@root\relax\else
+  \ifnum\forest@cn=\forest@drawtree@root\relax\else
     \ifnum\forestove{phantom}=0
       \ifnum\forestOve{\forestove{@parent}}{phantom}=0
-        \edef\forest@temp{\forestove{edge path}}%
-        \forest@temp
+        \forest@draw@edge@
       \fi
     \fi
   \fi
 }
+\def\forest@draw@edge@{%
+  \edef\forest@temp{\forestove{edge path}}\forest@temp
+}
 \def\forest@draw@tikz{%
+  \ifnum\forestove{phantom}=0
+    \forest@draw@tikz@
+  \fi
+}
+\def\forest@draw@tikz@{%
   \forestove{tikz}%
 }
 \newdimen\forest@xg
@@ -6579,18 +6628,23 @@
     }%
   }%
 \fi
-\NewDocumentEnvironment{forest}{D(){stages}}{%
-  \forest@defstages{#1}%
+\NewDocumentEnvironment{forest}{D(){}}{%
+  \forest@config{#1}%
   \Collect@Body
   \forest@env
 }{}
-\NewDocumentCommand{\Forest}{s D(){stages} m}{%
-  \forest@defstages{#2}%
+\NewDocumentCommand{\Forest}{s D(){} m}{%
+  \forest@config{#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@config#1{%
+  \def\forest@stages{stages}%
+  \forestset{@config/.cd,#1}%
+}
+\forestset{@config/.cd,
+  stages/.store in=\forest@stages,
+  .unknown/.code={\PackageError{forest}{Unknown config option for forest environment/command.}{In Forest v2.0.0 and v2.0.1, this (parenthesized) argument accepted the definition of style stages for the current forest environment/macro. Since v2.0.2, you should write "\string\begin{forest}(stages={...})...\string\end{forest}", or "\string\Forest(stages={...}){...}" instead.}}
 }
 \def\forest@group@env#1{{\forest@env{#1}}}
 \newif\ifforest@externalize@tree@
@@ -6756,7 +6810,7 @@
   \advance\forest@node@maxid1
   \forest@fornode{\the\forest@node@maxid}{%
     \forest@node@init
-    \forest@node@setname{standard node}%
+    \forest@node@setname@silent{standard node}%
   }%
 }
 \def\forest@standardnode@calibrate{%
@@ -6873,7 +6927,7 @@
   \forest@forestcs@anchor{#2}%
 }
 \def\forest@cs@invalidnodeerror{%
-  \PackageError{forest}{Attempt to refer to the invalid node by "forest cs"}%
+  \PackageError{forest}{Attempt to refer to the invalid node by "forest cs"}{}%
 }
 \tikzdeclarecoordinatesystem{forest}{%
   \forest@forthis{%
-- 
cgit v1.2.3

