% % chomsky.sty by Michael Barr.  From TeXhax 1989, issue 54.
% % See below, after \endinput, for documentation.
% \documentstyle{article}
% \textwidth=6.5in \leftmargin=0in
% \begin{document}
\unitlength=.001em

\newcount\xa \newcount\xb \newcount\xc
\newcount\ya \newcount\yb \newcount\yc \newcount\ym
\newcount\Xa \newcount\Xb \newcount\Xc
\newcount\Ya \newcount\Yb \newcount\Yc
\newcount\hsep \newcount\vsep
\newcount\tempa \newcount\tempb \newcount\tempc
\newbox\boxa \newbox\boxb \newbox\boxc
\newcount\offset \newcount\offseta \newcount\offsetb \newcount\offsetc
\newcount \hsep \newcount \vsep
\hsep=3000
\newcount \wide \newcount \high
\newcount\correction
\newdimen\tempdimen
\tempdimen=3.3333333pt
\divide\tempdimen by \unitlength
\correction=\tempdimen

\def\chomsky{\bgroup\catcode`\/=\active \catcode`\[=1 \catcode`\]=2}
\def\endchomsky{\egroup}

\chomsky

\gdef/#1;#2,#3/{{%
\setbox\boxa=\hbox{${\rm#1}$}
\offset=0 \setbox\boxb=\hbox{\strut#2}\offsetb=\offset
\offset=0 \setbox\boxc=\hbox{\strut#3}\offsetc=\offset
\xa=\wd\boxa \divide \xa by \unitlength
\ya=\ht\boxa \divide \ya by \unitlength
\xb=\wd\boxb \divide \xb by \unitlength
\yb=\ht\boxb \divide \yb by \unitlength
\xc=\wd\boxc \divide \xc by \unitlength
\yc=\ht\boxc \divide \yc by \unitlength
\ifnum\offsetb=0 \offsetb=\xb \divide \offsetb by 2 \fi
\ifnum\offsetc=0 \offsetc=\xc \divide \offsetc by 2 \fi
\ifnum\xc=0 \onebox \else \twobox \fi}}

\gdef\onebox{{%
\Xa=\offsetb
\vsep=2000
\Ya=\yb \advance \Ya by \vsep
\wide=\xb
\high=\yb \advance \high by \vsep {\divide \ya by 2 \global\advance
     \high by \ya}
\advance\wide by -\correction
\begin{picture}(\wide,\high)
\put(\Xa,\Ya){\makebox(0,0){\usebox{\boxa}}}
\put(0,0){\usebox{\boxb}}
\global\offset=\Xa
\advance \Ya by -\ya \advance \Ya by -100
\advance \vsep by -\ya \advance \vsep by -400
\put(\Xa,\Ya){\line(0,-1){\vsep}}
\end{picture}
}}

\gdef\twobox{{%
\ifnum\yb<\yc \ym=\yc \else \ym=\yb \fi
\Yb=\ym \advance \Yb by -\yb
\Yc=\ym \advance \Yc by -\yc
\Xc=\xb \advance \Xc by \hsep
\vsep=\xb \advance \vsep by -\offsetb \advance \vsep by \offsetc
   \advance \vsep by \hsep \divide \vsep by 2
\Xa=\offsetb \advance \Xa by \vsep \advance\Xa by \correction
\Ya=\ym \advance \Ya by \vsep
\wide=\xb \advance \wide by \xc \advance \wide by \hsep
\advance\wide by -\correction
\high=\Ya {\divide \ya by 2 \global\advance \high by \ya}
\begin{picture}(\wide,\high)(\correction,0)
\put(\Xa,\Ya){\makebox(0,0){\usebox{\boxa}}}
\put(0,\Yb){\usebox{\boxb}}
\put(\Xc,\Yc){\usebox{\boxc}}
\global\offset=\Xa
\advance \Ya by -\ya \advance \Ya by -200
\advance \vsep by -\ya \advance \vsep by -500
{\advance\Xa by -\ya \advance\Xa by -200
\put(\Xa,\Ya){\line(-1,-1){\vsep}}}
\advance\Xa by \ya \advance \Xa by 200
\put(\Xa,\Ya){\line(1,-1){\vsep}}
\end{picture}
}}

\endchomsky
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput
% \end{document}
% \gdef/#1;#2,#3/{\lbrack$_{\rm#1}\,$#2 #3\rbrack$_{\rm#1}\,$}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Usage: \chomsky [/;,/] \endchomsky.
        Can recurse.
 E.g.,

 \chomsky
 [/S;[/NP;[/Det;The,/],[/N;man,/]/],%
 [/VP;[/V_t;bit,/],[/NP;[/Det;a,/],[/N;dog,/]/]/]/]
 \endchomsky

 Gives:
                 S
                / \
              /     \
            /         \
          /             \
        /                 \
       NP                 VP
     /    \              /  \
   /        \          /      \
 Det         N       /          \
  |          |      Vt           NP
 The        man     |           /   \
                   bit        Det    N
                               |     |
                               a    dog


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Date: Mon, 22 May 89 22:49:14 EDT
From: INHB000 <INHB%MCGILLC.BITNET@UWAVM.ACS.WASHINGTON.EDU>
Subject: Macro to help display parsing trees
Keywords: macros, parsing trees

Paul Krause wanted some macros to help him display parsing trees.  The
enclosed is not the best possible solution, but it is a start.  It can
be improved in various ways.  The most important is to reduce the number
3000 that \hsep defaults to.  It is that large only so that very short
two word phrases will still have their parse lines; with a smaller value
you come up to a shorter distance than latex can draw a slant line.  The
best thing is to use a smaller value, 1500 looks good, and increase it
if the resultant line is too short.  Then the positioning is not
perfect.  This appears to be the result of the boxes produced by the
\picture environment being too wide by 3.333333pt.  It might be better
if the lines lower in the tree had steeper slope.  This would introduce
all sorts of complications.

Some might object to the syntax.  It was chosen to make the rather ugly
recursive structure as readable as possible and, not coincidentally,
come as close as possible to the alternate notation used in Chomsky's
``Aspects of Syntax''.  In fact, a different definition that reproduces
that alternate notation appears at the end.  I would have preferred the
syntax without the slashes, but I could not figure out how to implement
that.  A couple of caveats.  Since I have changed their \catcode's, [,]
and / cannot be used inside the trees.  Since I have never seen them so
used, this seems safe.  Of course, the brackets can all be replaced by
braces and the opening slashes changed to \tree or something.

The only sane way to use this macro is to define a key in your editor
that produces the string [/;,/] and four backspaces with a single
keystroke and leaves you in insert mode.  This will help enormously in
getting the syntax correct.

Michael Barr
