summaryrefslogtreecommitdiff
path: root/macros/generic/misc/emtrees.tex
blob: 3c9c5e1a3fb04ecf7936de34e64cdd15bc4afe83 (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
%From: hwb@texnix.stgt.sub.org (Harald Boegeholz)
%Newsgroups: comp.text.tex
%Date: 14 Jan 91 13:44:29 GMT
%
%Hi!
%
%Some time ago I wrote some TeX-macros to typeset trees. Since
%two people asked recently, here they are (quite short, so I thought
%I might post). Be aware, though, of two possible problems:
%  1. The macros use the \specials defined by emTeX. If your DVI-driver
%     doesn't support these, you won't see any lines.
%  2. The semantic nest size required is considerable (too many boxes
%     inside of boxes inside of boxes...), so you'll possibly need
%     a TeX which is "large" in this respect for typesetting complex trees.
%
%Hope this helps
%Harald
%------------------ cut here with a sharp knife ------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% tree macros by Harald Boegeholz
% This file uses the \specials defined by emTeX to draw the lines!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcount\pointnumber \pointnumber=0
\newcount\father
\font\nodefont=cmr7
\def\nextpoint{\global\advance\pointnumber by 1\relax}
\def\endsubtrees{\endsubtrees}
\def\tn#1{\vbox{%
  \vskip.5mm
  \hbox{\nodefont\hskip1ex\relax #1\hskip1ex}
  \vskip.5mm
  }%
}
\def\tree#1#2{%
  \vtop{%
    \nextpoint
    \father=\pointnumber
    \halign{\hfil##\hfil\cr
      #1\cr
      \special{em:point \number\father}\cr
      \noalign{\vskip5mm}
      \hbox{\subtrees#2\endsubtrees}\cr
    }%
  }%
}%
\def\subtrees#1{\ifx#1\endsubtrees\let\next\relax\else
  \vbox{\halign{\hfil##\hfil\cr
    \nextpoint
    \special{em:point \number\pointnumber}%
    \special{em:line \number\pointnumber h,\number\father h}\cr
    #1\cr
  }}%
  \let\next\subtrees\fi
  \next
}
\def\labeledtree#1#2{\vbox{\offinterlineskip\halign{\hfil##\hfil\cr
  #1\cr
  \noalign{\vskip3pt}%
  $\scriptstyle#2$\cr
}}}

\parindent0pt
\raggedbottom

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% macros end here ... sample follows:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput

{\labeledtree{% 
  {\tree{\tn{1}}{% 
    {\tree{\tn{2}}{% 
      {\tn{3}}% 
      {\tn{4}}% 
      }}% 
    {\tree{\tn{5}}{% 
      {\tn{6}}% 
      }}% 
    }}% 
}{[1,2,2,1,5]}}% 

\bye
------------------ cut here with a sharp knife ------------------------
--
Harald Boegeholz |Home:       hwb@texnix.stgt.sub.org (read daily)
                 |University: boegehol@az3.informatik.uni-stuttgart.de
                 |            ^ please use the latter for large (>100k) mails