% \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}
