%*****************************************************************************
%*****************************************************************************
%
%   impltree.sty
%
%   a LaTeX style for painting implication trees
%
%   A
%   �����ĿB
%   �     �����ĿC
%   �           ������ĿD
%   ����ĿE            �������ĿC
%        �������F      �       ��������ĿG
%                      ���������K       �������H
%                      ���������L       �������Z
%                                       �������I
%   Frantisek Hakl, January 1996        �������J
%   E-mail: hakl@uivt.cas.cz
%
%
%*****************************************************************************
%*****************************************************************************
%
\newcounter{cycl}
%
% counters  \ygap\roman{implylevel}  are constructed dynamically
%
\newcounter{implylevel}                 \newcounter{deepestlevel}
\newcounter{ygapi}                      \newcounter{xgapi}
\newcounter{firstinimply}               \newcounter{treeysize}
\newcounter{dummyyposition}             \newcounter{dummyxposition}
\newcounter{dummylenght}                \newcounter{propx}
\newcounter{propxstep}                  \newcounter{propy}
\newcounter{propystep}                  \newcounter{imtreeradius}
\newcounter{dummycounter}
%
\def\imtreestyle{sharp}
\def\ovalstring{oval}                   \def\brokenstring{broken}
\def\sharpstring{sharp}                 % use plain for nothing
%
\def\imarrowstyle{usearrow}
\def\noarrowstring{noarrow}             \def\usearrowstring{usearrow}
%
\setcounter{implylevel}{1}
\setcounter{deepestlevel}{1} % for alloc of ygap??? only
\setcounter{imtreeradius}{10}
\setcounter{propxstep}{60}              \setcounter{propystep}{20}
%
%
\newenvironment{impltree}[2]%
{\setcounter{treeysize}{#2}
 \setcounter{firstinimply}{0}
 \setcounter{propy}{0}
 \setcounter{propx}{0}
 \setcounter{xgapi}{0}
 \begin{picture}(#1,#2)}%
{\typeout{Tree height: \arabic{propy}}\end{picture}}
%
\def\impltreestyle#1{
   \def\imtreestyle{#1} % sharp, oval, broken
   \typeout{Imply tree style : \imtreestyle,
            radius=\arabic{imtreeradius}}
}
%
\def\implarrowstyle#1{
   \def\imarrowstyle{#1} % noarrow, usearrow
   \typeout{Arrow tree style : \imarrowstyle}
}
%
\def\PaintSharpBranch{
       \put(\value{dummyxposition},\value{dummyyposition})
           {\line(0,1){\value{ygap\roman{implylevel}}}}
       \ifx\imarrowstyle\usearrowstring
          \put(\value{dummyxposition},\value{dummyyposition})
              {\vector(1,0){\value{propxstep}}}
       \else
          \put(\value{dummyxposition},\value{dummyyposition})
              {\line(1,0){\value{propxstep}}}
       \fi
}
\def\PaintOvalBranch{
       \addtocounter{dummyyposition}{\arabic{imtreeradius}}
       \setcounter{dummycounter}{\arabic{ygap\roman{implylevel}}}
       \addtocounter{dummycounter}{-\arabic{imtreeradius}}
       \put(\value{dummyxposition},\value{dummyyposition})
           {\line(0,1){\value{dummycounter}}}
       \addtocounter{dummyxposition}{\arabic{imtreeradius}}
       \setcounter{dummycounter}{\arabic{imtreeradius}}
       \addtocounter{dummycounter}{\arabic{imtreeradius}}
       \put(\value{dummyxposition},\value{dummyyposition})
           {\oval(\value{dummycounter},\value{dummycounter})[bl]}
       \addtocounter{dummyyposition}{-\arabic{imtreeradius}}
       \setcounter{dummycounter}{\arabic{propxstep}}
       \addtocounter{dummycounter}{-\arabic{imtreeradius}}
       \ifx\imarrowstyle\usearrowstring
          \put(\value{dummyxposition},\value{dummyyposition})
              {\vector(1,0){\value{dummycounter}}}
       \else
          \put(\value{dummyxposition},\value{dummyyposition})
              {\line(1,0){\value{dummycounter}}}
       \fi
}
\def\PaintBrokenBranch{
       \addtocounter{dummyyposition}{\arabic{imtreeradius}}
       \setcounter{dummycounter}{\arabic{ygap\roman{implylevel}}}
       \addtocounter{dummycounter}{-\arabic{imtreeradius}}
       \put(\value{dummyxposition},\value{dummyyposition})
           {\line(0,1){\value{dummycounter}}}
       \put(\value{dummyxposition},\value{dummyyposition})
           {\line(1,-1){\value{imtreeradius}}}
       \addtocounter{dummyyposition}{-\arabic{imtreeradius}}
       \addtocounter{dummyxposition}{\arabic{imtreeradius}}
       \setcounter{dummycounter}{\arabic{propxstep}}
       \addtocounter{dummycounter}{-\arabic{imtreeradius}}
       \ifx\imarrowstyle\usearrowstring
          \put(\value{dummyxposition},\value{dummyyposition})
              {\vector(1,0){\value{dummycounter}}}
       \else
          \put(\value{dummyxposition},\value{dummyyposition})
              {\line(1,0){\value{dummycounter}}}
       \fi
}
%
\def\imply#1{
   \addtocounter{implylevel}{1}
   \ifnum \value{deepestlevel} < \value{implylevel}
       \setcounter{deepestlevel}{\arabic{implylevel}}  % alloc new counter
       \newcounter{ygap\roman{implylevel}}
       \newcounter{xgap\roman{implylevel}}
   \fi
   \setcounter{ygap\roman{implylevel}}{0}
   \setcounter{firstinimply}{0}
   #1
   \addtocounter{implylevel}{-1}
   \setcounter{xgap\roman{implylevel}}{\arabic{propxstep}}
} % end imply
%
%
%
\def\prop#1{
    %
    \setcounter{propx}{0}
    \setcounter{cycl}{1}
    \ifnum \arabic{firstinimply} = 0                % for first prop in imply
       \setcounter{xgap\roman{implylevel}}{\arabic{propxstep}}
    \fi
    \loop
       \addtocounter{ygap\roman{cycl}}{\arabic{propystep}}
       \addtocounter{propx}{\arabic{xgap\roman{cycl}}}
       \ifnum \arabic{cycl} < \arabic{implylevel}
       \addtocounter{cycl}{1}
    \repeat
    %
    \addtocounter{propy}{\arabic{propystep}}
    \setcounter{dummyyposition}{\arabic{treeysize}}
    \addtocounter{dummyyposition}{-\arabic{propy}}
    %
    \addtocounter{propx}{-\arabic{xgap\roman{implylevel}}}
    \addtocounter{propx}{\arabic{propxstep}}
    \setcounter{dummyxposition}{\arabic{propx}}
    \addtocounter{dummyxposition}{-\arabic{xgap\roman{implylevel}}}
    \put(\value{propx},\value{dummyyposition}){#1}
    \ifnum \value{implylevel} = 1                        % no path for root
    \else
          \ifx\imtreestyle\ovalstring
                \PaintOvalBranch
          \else \ifx\imtreestyle\brokenstring
                      \PaintBrokenBranch
                \else \ifx\imtreestyle\sharpstring
                           \PaintSharpBranch
    \fi   \fi   \fi   \fi
    \ifnum \arabic{firstinimply} = 0                % for first prop in imply
       \setcounter{firstinimply}{1}
    \fi
} % end prop
%
%
%*****************************************************************************
%*****************************************************************************


