%---------- trees.sty --------------------
% Peter Vanroose, 18 april 1990.
\newcount\branchwidth\newcount\xcoord\newcount\ycoord\newcount\coordstep
\def\branchlabels#1#2#3{\edef\labela{#1}\edef\labelb{#2}\edef\labelc{#3}}
\branchlabels012
%
\def\root(#1,#2) #3.{\catcode32=9       % ignore spaces
              %  #3 is the node label of the root
 \expandafter\xdef\csname nodex#3\endcsname{#1}
 \expandafter\xdef\csname nodey#3\endcsname{#2}
 \put(#1,#2){
  \put(0,0){\line(-1,0)6}\put(-6,0){\line(0,-1)3}\put(-9,-3){\line(1,0)6}}}
%
\def\branch#1#2#3:#4,#5.{ \branchwidth=#1
 \xcoord=\expandafter\number\csname nodex#3\endcsname
 \ycoord=\expandafter\number\csname nodey#3\endcsname
 \edef\coord{(\number\xcoord,\number\ycoord)}
 \advance\xcoord by 12      %  #4,#5 are the labels of the childs
 \expandafter\xdef\csname nodex#4\endcsname{\number\xcoord}
 \expandafter\xdef\csname nodex#5\endcsname{\number\xcoord}
 \ifcase\branchwidth
  \advance\ycoord by 24\coordstep=-48 \or % case 0
  \advance\ycoord by 12\coordstep=-24 \or % case 1
  \advance\ycoord by  6\coordstep=-12 \or % case 2
  \advance\ycoord by  3\coordstep=- 6 \fi % case 3
 \expandafter\xdef\csname nodey#4\endcsname{\number\ycoord}
 \advance\ycoord by \coordstep
 \expandafter\xdef\csname nodey#5\endcsname{\number\ycoord}
 \expandafter\put\coord{
  \put(0,0){\circle*1}\put(0,1.5){\makebox(0,0){\scriptsize #2}}
  \ifcase\branchwidth
   \put(0,0){\line(1,2){12}}\put(0,0){\line(1,-2){12}}
   \put(5,12){\tiny$\labela$}\put(5,-12){\tiny$\labelb$} \or % case 0
   \put(0,0){\line(1,1){12}}\put(0,0){\line(1,-1){12}}
   \put(6,7){\tiny$\labela$}\put(6,-8){\tiny$\labelb$}   \or % case 1
   \put(0,0){\line(2,1){12}}\put(0,0){\line(2,-1){12}}
   \put(6,3.6){\tiny$\labela$}\put(6,-5){\tiny$\labelb$} \or % case 2
   \put(0,0){\line(4,1){12}}\put(0,0){\line(4,-1){12}}
   \put(6,2){\tiny$\labela$}\put(6,-3){\tiny$\labelb$}   \fi % case 3
}}
%
\def\tbranch#1#2#3:#4,#5,#6.{
 \branchwidth=#1
 \xcoord=\expandafter\number\csname nodex#3\endcsname
 \ycoord=\expandafter\number\csname nodey#3\endcsname
 \edef\coord{(\number\xcoord,\number\ycoord)}
 \advance\xcoord by 12
 \expandafter\xdef\csname nodex#4\endcsname{\number\xcoord}
 \expandafter\xdef\csname nodex#5\endcsname{\number\xcoord}
 \expandafter\xdef\csname nodex#6\endcsname{\number\xcoord}
 \ifcase\branchwidth
  \advance\ycoord by 24\coordstep=-24 \or % case 0
  \advance\ycoord by 12\coordstep=-12 \or % case 1
  \advance\ycoord by  6\coordstep= -6 \or % case 2
  \advance\ycoord by  3\coordstep= -3 \fi % case 3
 \expandafter\xdef\csname nodey#4\endcsname{\number\ycoord}
 \advance\ycoord by \coordstep
 \expandafter\xdef\csname nodey#5\endcsname{\number\ycoord}
 \advance\ycoord by \coordstep
 \expandafter\xdef\csname nodey#6\endcsname{\number\ycoord}
 \expandafter\put\coord{
  \put(0,0){\circle*1}\put(0,1.5){\makebox(0,0){\scriptsize #2}}
  \ifcase\branchwidth
   \put(0,0){\line(1,2){12}}\put(0,0){\line(1,0){12}}\put(0,0){\line(1,-2){12}}
   \put(5,12){\tiny$\labela$}\put(5,0.6){\tiny$\labelb$}\put
     (5,-12){\tiny$\labelc$} \or % case 0
   \put(0,0){\line(1,1){12}}\put(0,0){\line(1,0){12}}\put(0,0){\line(1,-1){12}}
   \put(6,7){\tiny$\labela$}\put(6,0.5){\tiny$\labelb$}\put
     (6,-8){\tiny$\labelc$}  \or % case 1
   \put(0,0){\line(2,1){12}}\put(0,0){\line(1,0){12}}\put(0,0){\line(2,-1){12}}
   \put(6,3.6){\tiny$\labela$}\put(6,0.5){\tiny$\labelb$}\put
     (6,-5){\tiny$\labelc$}  \or % case 2
   \put(0,0){\line(4,1){12}}\put(0,0){\line(1,0){12}}\put(0,0){\line(4,-1){12}}
   \put(6,2){\tiny$\labela$}\put(6,0.25){\tiny$\labelb$}\put
     (6,-3){\tiny$\labelc$}    \fi % case 3
}}
%
\def\leaf#1#2#3.{
 \xcoord=\expandafter\number\csname nodex#3\endcsname
 \ycoord=\expandafter\number\csname nodey#3\endcsname
 \edef\coord{(\number\xcoord,\number\ycoord)}
 \expandafter\put\coord{
  \put(0,0){\circle*1}\put(0,1.5){\makebox(0,0){\scriptsize #1}}
  \put(2,-0.6){\makebox(0,0)[l]{#2}}}}
%
%-------- end of trees.sty -------------
