\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{color}
\pagecolor[gray]{1}

\makeatletter
\makeatother
\newcommand{\com}[1]{ \texttt{\%\#tree: #1}\nopagebreak[4] }
\newcommand{\SynTeX}{\ensuremath{\mathrm{SY^{N}}}\TeX\ }

\begin{document}

\SynTeX

\SynTeX was written by Matt Chisholm \texttt{<matt (at) theory.org>}. It is available at \texttt{http://www.theory.org/}\verb|~|\texttt{adric/syntex/}. It is licensed under the GNU GPL ( \texttt{http://www.gnu.org/copyleft/gpl.txt} ). It requires \LaTeX\ and Perl 5 to run. It should run under *nix without much modification; it should also run under other operating systems if they have \LaTeX\ and Perl support.

\SynTeX is a \LaTeX\ preprocessor that draws syntactic trees. The preprocessor reads the comments in a \LaTeX\ file and draws the tree based on commands that it finds there. The program looks for lines that begin with the string \texttt{\%\#tree:}. The program expects to find a line which is a list of options, specifying things like type style, type size, and layout algorithm, followed by a line which specifies the content of the tree. 

For example, these two lines together:\\
\\
\com{-f4}\\
\com{S(NP(D(the), N'(N(farmer))), VP(V(killed), NP(D(the), N'(N(pig)), PP(P(with), NP(D(a) N'(N(pitchfork)) ) ) ) ) )\\}
\\
will draw this tree:\\ 
\\
%#tree: -f4
%#tree: S(NP(D(the), N'(N(farmer))), VP(V(killed), NP(D(the), N'(N(pig)), PP(P(with), NP(D(a) N'(N(pitchfork)) ) ) ) ) )

Tree Content

The line that specifies the tree content is a list of nodes. For example, a single node, called XP, which has one child node, called X, is drawn by inserting this text in your document: \\
\\
\com{}\\
\com{XP(X)}\\

%#tree: -f4
%#tree: XP(X)

Nodes can contain any characters except ``('', ``)'', ``|'', or ``,'' (they also can't contain newline or tab characters), and they cannot begin or end with a space. The ``('' and ``)'' characters begin and end a node's list of children. The ``|'' character is explained in the Options section.

The comma character is usually not needed, but I find it useful to use anyway. The only place where the comma character is needed is to mark the boundaries between nodes that do not have any children. Notice that the first two examples are trees where S has three children: in the third example, S has one child with three words. 
\begin{flushleft}
\begin{tabular}{ccc}
\scriptsize\com{S(resistance, is, futile)}
&
\scriptsize\com{S(resistance() is() futile())}
&
\scriptsize\com{S(resistance is futile)}
\\
%#tree: -f4
%#tree: S(resistance, is, futile)
&
%#tree: -f4
%#tree: S(resistance() is() futile())
&
%#tree: -f4 -T
%#tree: S(resistance is futile)
\end{tabular}
\end{flushleft}

Options

Type style can be changed by the \verb|-style=??,??,??| option. Arguments are \verb|tt|, \verb|bf|, \verb|it|, and \verb|sf|, corresponding to \LaTeX 's 
\verb|\texttt|, 
\verb|\texttt|, 
\verb|\textbf|, 
\verb|\textit|, 
\verb|\textsf| 
commands.\\
\\
\com{-style=bf,it,tt}\\
\com{S(NP(D(the), N'(N(farmer))), VP(V'(V(killed), NP(D(the), N'(pig)) )  PP(P'(P(with), NP(D(a), N'(N(pitchfork))) ) ) ) )\\}

%#tree: -style=bf,it,tt
%#tree: S(NP(D(the), N'(N(farmer))), VP(V'(V(killed), NP(D(the), N'(pig)) )  PP(P'(P(with), NP(D(a), N'(N(pitchfork))) ) ) ) )

Font size is changed with the \verb|-f?| command. ``?'' must be a number from 1 to 10, corresponding to the 10 \LaTeX \ type sizes. The default type size is 5, \verb|\large|.\\
\\
\com{-f2}\\ 
\com{S(NP(D(the), N'(N(farmer))), VP(V'(V(killed), NP(D(the), N'(pig)) )  PP(P'(P(with), NP(D(a), N'(N(pitchfork))) ) ) ) )\\}

%#tree: -f2 
%#tree: S(NP(D(the), N'(N(farmer))), VP(V'(V(killed), NP(D(the), N'(pig)) )  PP(P'(P(with), NP(D(a), N'(N(pitchfork))) ) ) ) )

The \verb|-x=prime| or \verb|-x=bar| options specify how you want X' to be drawn; either with a $'$ or with a bar over the top of the letter. The default is to draw a bar.\\
\\
\com{-x=prime}\\
\com{S(NP(D(the), N'(N(farmer))), VP(V'(V(killed), NP(D(the), N'(pig)) ) PP(P'(P(with), NP(D(a), N'(N(pitchfork))) ) ) ) )\\}

%#tree: -x=prime
%#tree: S(NP(D(the), N'(N(farmer))), VP(V'(V(killed), NP(D(the), N'(pig)) ) PP(P'(P(with), NP(D(a), N'(N(pitchfork))) ) ) ) )

The -h and -H options turn ``head balancing'' on and off. ``Head balancing'' means that a projection is aligned directly above it's head. Head balancing is on by default. 

Items in brackets are interpreted as ``features'' and placed into subscripts. A node can be given multiple ``features'' by separating individual features with a \verb|\| character. \\
\\
\com{-h}\\
\com{TP(NP(D(the), N'(N(farmer))), T'(T[+past](0), VP(V'(killed), NP(D(the), N'(N(pig)), PP(P'(P(with), NP(D(a), N'(N(pitchfork))) ) ) ) ) ) )\\}

%#tree: -h
%#tree: TP(NP(D(the), N'(N(farmer))), T'(T[+past](0), VP(V'(killed), NP(D(the), N'(N(pig)), PP(P'(P(with), NP(D(a), N'(N(pitchfork))) ) ) ) ) ) )

The -t and -T options turn ``triangles'' on and off. If triangles are on, a terminal node that contains more than one word will have a triangle above it, instead of a single line. Triangles are on by default. Coreferent noun phrases indicated by subscripts are made by typing ``NPi,'' ``NPj'' or ``NPk.''\\
\\
\com{-t}\\
\com{S( NPi(the farmer), VP(V'(V(killed), NPi(himself)), PP(P'(P(with), NP(a pitchfork) )) ) )\\}

%#tree: -t
%#tree: S( NPi(the farmer), VP(V'(V(killed), NPi(himself)), PP(P'(P(with), NP(a pitchfork) )) ) )

Terminal nodes can be aligned against the bottom of the graph with the -a option. Vertical lines are drawn whenever the program encounters a ``|'' in the input string.\\
\\
\com{-a} \\
\com{S(NP(D(the), N(N'(farmer))),| VP(V(killed), | NP(D(the), N'(N(pig)), PP(P(with), NP(D(a) N'(N(pitchfork)) ) ) ) ) ) \\}

%#tree: -a 
%#tree: S(NP(D(the), N(N'(farmer))),| VP(V(killed), | NP(D(the), N'(N(pig)), PP(P(with), NP(D(a) N'(N(pitchfork)) ) ) ) ) )

The \verb|-line=?| option specifies what type of line to draw between nodes. The options are \verb|line, convex, concave, curly, square,| and \verb|mondrian.| The \verb|line| option is default; the \verb|square| option is nice for genealogical trees. The others are mostly for fun. \\
\\
\com{-line=square -T -f2}\\
\com{Hans+ValborgBjerrum( Vera+MaxChisholm( Elizabeth+Delphey(John, Chris), Derelle+JimGartland(Mark+Claudia(Gabe, Isabel), Ron, Dave+Carrie), Charlie+LindaKramer(Matt, Alex) ))}

%#tree: -line=square -T -f2
%#tree: Hans+ValborgBjerrum( Vera+MaxChisholm( Elizabeth+Delphey(John, Chris), Derelle+JimGartland(Mark+Claudia(Gabe, Isabel), Ron, Dave+Carrie), Charlie+LindaKramer(Matt, Alex) ))

Logicial structures can be represented as well. There is something of a shorthand to express $\wedge$(\verb|^|), $\vee$(\verb|`|), $\to$(\verb|->|), and $\neg$(\verb|!|).

\begin{flushleft}
\com{-paren=[] -f4 -H}\\
\verb|%#tree:  (p^q)->!(p`q)[p^q[p, q], !(p\`q)[p\`q[p, q]]]|
\end{flushleft}

%#tree: -paren=[] -f4 -H
%#tree: (p^q)->!(p`q)[p^q[p, q], !(p`q)[p`q[p, q]]]


% Hans+ValborgBjerrum( Vera+MaxChisholm( Elizabeth+Delphey(John, Chris), Derelle+JimGartland(Mark+Claudia(Gabe, Isabel), Ron, Dave+Carrie), Charlie+LindaKramer(Matt, Alex) ), Elizabeth+WeldonPollard(Tom+Carol(Mark, Jason), Gail, Judy+SpencerStrellis(Annie+Bradley(Oscar),Paisley)), AnnaMarie )

%\clearpage

%tree: -f5 -i -b
%tree: S(NP(D(the), N'(N(farmer))), VP(V'(killed), NP(D(the), N'(pig)), PP(P'(P(with), NP(D(a), N'(N(pitchfork))) ) ) ) )


%tree: -f5 -b
%tree: S(NP(D(the), N'(N(farmer))), VP(V'(killed), NP(D(the), N'(pig)), PP(P'(P(with), NP(D(a), N'(N(pitchfork))) ) ) ) )

\end{document}
