summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/forest/forest-compat.sty
blob: c69220844c3f11e8c066d7edf6f26acb6668a97e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
% \CheckSum{12884}
% \iffalse meta-comment
% forest-index.dtx
%% `forest-compat' defines a compatibility layer of package `forest'.
%%
%% Copyright (c) 2012-2017 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}[2016/12/31]

\def\forest@deprecated#1{%
  \PackageWarning{forest}{Compatibility mode for #1}%
}
\forestset{@@deprecated/.code={\forest@deprecated{#1}}}
\def\forestcompat#1{\pgfqkeys{/forest/@compat}{#1}}
\def\forestcompat@patchfailed{%
  \pgfkeys@split@path
  \PackageError{forest}{Patching in compat=\pgfkeyscurrentname\space failed}{}%
}
\forestcompat{
  silent/.code={\def\forest@deprecated##1{}},
  %%% begin listing region: compat_keys
  most/.style={1.0-most},
  all/.style={1.0-all},
  none/.style={},
  1.0-harmless/.style={
    1.0-triangle,1.0-linear,1.0-nodewalk,1.0-ancestors,
    1.0-fittotree,1.0-for,1.0-forall,
  },
  1.0-most/.style={1.0-harmless,2.0.2-most},
  1.0-all/.style={1.0-harmless,
    1.0-forstep,1.0-rotate,1.0-stages,1.0-name,
    2.0.2-all,
  },
  2.0.2-most/.style={2.0-most},
  2.0.2-all/.style={
    2.0.2-delayn,2.0.2-wrapnpgfmathargs,
    2.0-all,
  },
  2.0-edges/.style={2.0-anchors,2.0-forkededge,2.0-folder},
  2.0-most/.style={2.1.1-most},
  2.0-all/.style={
    2.0-delayn,
    2.0-edges,
    2.1.1-all,
  },
  2.1.1-most/.style={},
  2.1.1-all/.style={2.1.1-loops},
  %%% end listing region: compat_keys
  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-forstep/.code={%
    \def\forest@forstepwrapper##1##2{%
      \forest@forthis{%
        \forest@configured@nodewalk{independent}{independent}{compatfake}{##1}{##2}%
      }%
    }%
    \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}%
      }%
    }%
  },
  2.0.2-delayn/.style={
    /forest/delay@n/.style 2 args={
      @@deprecated={propagator "delay n" (it introduces two levels of hash doubling reevaluates the first argument (the desired number of cycles) at every cycle)},
      if={##1==1}{delay={##2}}{delay={delay@n/.wrap pgfmath arg={{####1}{##2}}{##1-1}}}
    },
    2.0-delayn/.style={}, % this key would patch the same thing!
  },
  2.0.2-wrapnpgfmathargs/.code={%
    \def\forest@wrap@pgfmath@args@@@wrapandpasson{%
      \forest@deprecated{handler "wrap n pgfmath args" (it introduces two levels of hash doubling)}%
      \expandafter\expandafter\expandafter\def
          \expandafter\expandafter\expandafter\forest@wrapped
          \expandafter\expandafter\expandafter{%
            \expandafter\forest@wrap@code\forest@wrap@args}%
      \expandafter\pgfkeysalso\expandafter{\expandafter\pgfkeyscurrentpath\expandafter=\expandafter{\forest@wrapped}}%
    }%
  },
  2.0-delayn/.style={
    /forest/delay n/.style 2 args={
      @@deprecated={propagator "delay n" (it reevaluates the first argument (the desired number of cycles) at every cycle)},
      if={##1==0}{##2}{delay@n={##1}{##2}}
    },
    /forest/delay@n/.style 2 args={
      if={##1==1}{delay={##2}}{delay={delay@n/.process={P}{##1-1}{##2}}}
    },    
  },
  2.0-anchors/.code={%
    \csdef{forest@anchor@@parent'}{%
      \forest@anchor@isbordertrue
      \edef\forest@temp@anchor{\number\numexpr\forestove{grow}-\forestove{rotate}+180}%
    }
    \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
    }
  },
  2.0-forkededge/.code={%
    \forest@iflibraryloaded{edges}{%
      \forestset{
        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}
        },
      }%
    }{%
      \appto\forest@compat@libraries@edges{\forestcompat{2.0-forkededge}}%
    }%
  },
  2.0-folder/.code={%
    \forest@iflibraryloaded{edges}{%
      \expandafter\patchcmd\csname pgfk@/forest/folder/.@cmd\endcsname
        {parent anchor=-children last}
        {parent anchor=parent last}
        {}{\forestcompat@patchfailed}%
      \expandafter\patchcmd\csname pgfk@/forest/folder/.@cmd\endcsname
        {edge={rotate/.option=!parent.grow},}
        {edge={rotate/.pgfmath=grow()}}
        {}{\forestcompat@patchfailed}%
    }{%
      \appto\forest@compat@libraries@edges{\forestcompat{2.0-folder}}%
    }%
  },
  2.1.1-loops/.code={%
    \patchcmd\newsafeRKloop % pre-{##1}
      {\forest@temp@toks}%
      {%
        \forest@deprecated{hash-doubling loops from pre-2.1.2}%
        \def\forest@temp
      }%
      {}{\forestcompat@patchfailed}%
    \patchcmd\newsafeRKloop % post-{##1}
      {\csedef}%
      {\forest@temp@toks\expandafter{\forest@temp}\csedef}%
      {}{\forestcompat@patchfailed}%
  },
}
\expandafter\forestcompat\expandafter{\forest@compat}