summaryrefslogtreecommitdiff
path: root/graphics/dratex/wotree.sty
blob: 78ec73999d53b1264e51fb097656071797273539 (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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% wotree.sty                           2000-06-29-20:18 %
% Copyright (C) 2000            Eitan M. Gurari         %
%                                                       %
% This program can redistributed and/or modified under  %
% the terms of the LaTeX Project Public License         %
% Distributed from CTAN archives in directory           %
% macros/latex/base/lppl.txt; either version 1 of the   %
% License, or (at your option) any later version.       %
%                                                       %
% However, you are allowed to modify this program       %
% without changing its name, if you modify its          %
% signature. Changes to the signature can be introduced %
% with a directive of the form                          %
%            \message{signature}                        %
%                                                       %
%                             gurari@cse.ohio-state.edu %
%                 http://www.cse.ohio-state.edu/~gurari %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\immediate\write-1{version 2000-06-29-20:18}

\expandafter\edef\csname wo:recall\endcsname{\catcode`:=\the\catcode`:}
\catcode`\:=11

\Define\WO:GetY(2){\Vb=#2;}

\Define\WOEdge(2){
  \CSeg\WO:GetY(#2,EdgeGuide)
  \IF \GtDec(\Vb,0)
            \MoveToNode(#2,0,-1)
  \ELSE
            \MoveToNode(#2,0,1)
  \FI
  \MarkLoc(*1)   \Move(10,0)  \MarkLoc(*2)
  \MoveToLoc(EdgeGuide) \Move(0,10)  \MarkLoc(*3)
  \MoveToLL(*1,*2)(EdgeGuide,*3) \MarkLoc(*3)
  \MoveToNode(#1,1,0) \Move(5,0) \LineToLoc(EdgeGuide)
  \LineToLoc(*3)    \CSeg[2]\Line(*1,#2)
}
\def\WOTree#1{%
   \let\WO:tree=\empty
   \def\:queue{\init:count#1,,//}\put:queue
   \TreeSpec()()(\WOEdge)
   \TreeAlign(H,-1,0)(0,0,0)%
   \WO:TreeSpace
   \def\wo:temp{\Tree()(}%
   \expandafter\wo:temp\expandafter{\WO:tree})
    }

\def\put:queue{%
   \let\put:woitem=\empty
   \ifx \WO:tree\empty \else
       \expandafter\def\expandafter\WO:tree\expandafter{\WO:tree//}%
    \fi
   \ifx \:queue\empty  \def\wo:temp##1{}\else
   \let\wo:temp=\:queue \let\:queue=\empty \fi
   \wo:temp\put:queue }

\def\init:count#1,{%
   \def\WO:root{#1}\I=0;\WO:count}

\edef\wo:temp{\catcode`\noexpand\&=\the\catcode`\&}
\catcode`\&=13

\def\WO:count#1,{%
   \def\wo:temp{#1}\ifx \wo:temp\empty
       \expandafter\checkWO:root\WO:root//%
       \edef\wo:temp{\put:woitem\Val\I,\beforeWO:root}%
       \def\put:woitem{\noexpand&}%
       \expandafter\expandafter\expandafter\def
       \expandafter\expandafter\expandafter\WO:root
       \expandafter\expandafter\expandafter
          {\expandafter\wo:temp\WO:root}%
       \expandafter\expandafter\expandafter\def
       \expandafter\expandafter\expandafter\WO:tree
       \expandafter\expandafter\expandafter
          {\expandafter\WO:tree \WO:root}%
       \def\WO:root##1//{}\expandafter\WO:root
   \else
      \expandafter\def\expandafter\:queue
          \expandafter{\:queue\init:count#1,,//}%
      \I+1;\expandafter\WO:count
   \fi }

\wo:temp

\def\checkWO:root{\futurelet\wo:temp\ckWO:root}
\def\ckWO:root#1//{\edef\beforeWO:root{\ifx \wo:temp\WO \else
    \ifx \WO:tree\empty\else
         \noexpand\noexpand\noexpand\WO{}\fi\fi}}

\def\WO#1{\csname :WO:#1\endcsname}
\def\defWO#1#2{\expandafter\def\csname :WO:#1\endcsname{#2}}

\defWO{}{\llap{$\triangleright$ }}
\defWO{not}{\hrulefill~~\WO{}}
\defWO{or}{~$\bigoplus$}
\defWO{plus}{~$+$}
\defWO{xor}{~$\bigotimes$}

\Define\WOSpace(2){\def\WO:TreeSpace{\TreeSpace(C,#1,#2)}}
\WOSpace(10,20)

\wo:recall
\endinput