Debian Codegraph @

texmf-dist/doc/latex/qtree/qtreenotes.tex

raw
1 % Demo and documentation for qtree.sty, the front end to the
2 % Qobitree tree-drawing package
3
4 % (LaTeX)
5
6 \documentclass[11pt,a4paper]{ltxdoc}
7
8 % You can safely comment this out if you don't have hyperref
9 \usepackage[bookmarks]{hyperref}
10
11 % We stick with the text width set by ltxdoc.cls
12
13 % Fairly-balanced A4 margins:
14 \topmargin=-0.25in
15 \textheight=9in
16
17 \parskip=4pt
18 \parindent=0pt
19 \raggedbottom
20
21 \DeleteShortVerb{\|}
22 \AtBeginDocument{\OnlyDescription} % There's no code, anyway
23
24 % Like \DescribeMacro, but arbitrary text
25 \def\marginpost#1{\leavevmode \marginpar{~\hfill\texttt{#1}}\ignorespaces}
26
27 % The name of the package, capitalized or not.
28 \def\QT{\textsf{\emph{Qtree}}}
29 \def\Qt{\textsf{\emph{qtree}}}
30
31 \def\pstyle#1{\textsf{#1}} % style filenames
32
33 \def\argplain#1{\textit{$\langle$#1$\rangle$}} % Like \marg, but without { }
34
35
36 \usepackage{qtree}
37
38 % Break page unless requested amount of space remains
39 % Must be used BETWEEN paragraphs
40 %
41 \makeatletter
42 \def\vneed#1{\par \penalty-100 \begingroup % preserve \dimen@, \dimen@i
43 \ifdim\prevdepth>\maxdepth \dimen@i\maxdepth \else \dimen@i\prevdepth\fi
44 \kern-\dimen@i
45 \dimen@\pagegoal \advance\dimen@-\pagetotal % space left
46 \ifdim #1>\dimen@ \vfil \eject \fi
47 \kern\dimen@i
48 \endgroup}
49 \makeatother
50
51
52 \begin{document}
53
54 \begin{center}
55 \Large {\bf Qtree, a \LaTeX\ tree-drawing package}\footnote{
56 Thanks to Jeff Siskind for permission to distribute the QobiTree code.
57 Please direct comments to Alexis Dimitriadis
58 (\emph{[email protected]}).}
59 \large
60 \\[8pt] Jeffrey Mark Siskind (tree drawing and core package)\\[4pt]
61 Alexis Dimitriadis (parser and extensions) \\[8pt]
62 Version \qTreeVersion, 12 December 2008
63 \\[8pt] \Large % For the paragraph spacing
64 \end{center}
65
66 \section{Overview}
67
68 The \QT\ package consists of QobiTree, a package of tree-drawing
69 macros written by Jeff Siskind, and a front end that allows trees to be
70 specified in bracket notation, using whitespace to separate tokens. Tree
71 nodes can have labels of any size or complexity, and are automatically
72 arranged on the page, usually with quite good results. Provisions exist for
73 fine-tuning the default layout. The front end also centers trees (by default)
74 and provides some other nice features.
75
76 A simple tree may look like this,
77 \begin{verbatim}
78 \Tree [.S This [.VP [.V is ] \qroof{a simple tree}.NP ] ]
79 \end{verbatim}
80 which produces:
81 \par
82 \Tree [.S This [.VP [.V is ] \qroof{a simple tree}.NP ] ]
83 \bigskip
84
85 The node labels in trees may be quite complicated; they may contain font
86 changes and math-mode text, line breaks introduced with \verb|\\| (which
87 produce centered lines), etc. The trees produced are constrained to a
88 maximum depth of 20 levels, with a maximum of five branches at any one node.
89 \QT\ automatically adjusts for the
90 width and height of tree labels, and is pretty good at arranging nodes on
91 the page.
92
93 Trees are defined using a version of the bracket notation familiar to
94 linguists. Tree elements are delimited by white space; braces can be
95 used to enclose multi-word labels. \QT\ does not rely on
96 \verb|\catcode| changes for its operation, allowing trees to be
97 included in footnotes and other moving environments without problems. (But
98 see the discussion of \verb|\automath| below).
99
100 Thanks to recent improvements in \LaTeX's support for PDF, \Qt\ can now
101 produce good-looking graphics for both DVI/PostScript and PDF output. By default, \Qt\ will load the package \pstyle{pict2e.sty}, which improves the native picture-drawing facilities of \LaTeX\ and transparently supports both
102 PostScript and PDF output.\footnote{%
103 Earlier versions of \Qt\ loaded \pstyle{eepic.sty}, which does not work with PDF. You can still use \Qt\ with \pstyle{eepic} if you wish; see section \ref{s:options}.
104 }
105 This version of Qtree also provides hooks for customization, and
106 contains many small enhancements and corrections of minor glitches.
107
108 Many of the new features were inspired by questions or requests from \Qt\
109 users. Thank you all for your contributions to \Qt, and keep them coming!
110
111
112 \subsection{New features}
113
114 \begin{enumerate}
115 \item Full PDF and PostScript support using
116 \pstyle{pict2e.sty}. This package, which extends the limited capabilities
117 of the standard \verb|picture| environment, was planned long ago by the
118 \LaTeX\ developers but has only recently been released. It provides
119 enhanced drawing quality for both DVI and PDF output.
120
121 \item Customization hooks allow easy adjustments to the default style of
122 leaf and branch labels, and to a number of other aspects of tree
123 appearance.
124
125 \item Extraneous whitespace around trees has been removed.
126
127 \item Reorganized and rewritten code is easier to customize (with a moderate
128 amount of \LaTeX\ hacking skills).
129
130 \item The documentation has been extended and reorganized. An FAQ section
131 has been added with explanations of various frequently requested
132 tasks.
133
134 \item Several functions have been added, including a ``balancing'' command
135 that will produce trees with more evenly sized branches.
136
137 \item \QT\ is now (finally) available on CTAN.
138
139 \end{enumerate}
140
141
142 \subsection{Home page}
143
144 The \Qt\ home page is at:
145
146 \begin{center}
147 http://www.ling.upenn.edu/advice/latex/qtree/.
148 \end{center}
149
150
151
152
153
154 \newpage
155 \tableofcontents
156 \newpage
157
158 \section{Invocation}
159
160 \pstyle{Qtree.sty} is a \LaTeX\ package. It should be installed in a
161 directory of style files, and included with the \LaTeXe\ command
162 \verb|\usepackage{qtree}|.
163
164 \subsection{Package options}
165 \label{s:options}
166
167 \DescribeMacro{[center]} Horizontally center trees on the line. This is the
168 default behavior. (See also the commands \verb|\qtreecentertrue| and
169 \verb|\qtreecenterfalse|, below). %in section \ref{s:params}).
170
171 \DescribeMacro{[nocenter]} Do not center trees. Trees are positioned on the
172 page like ordinary text, and can be manually aligned to the left or right
173 (or centered).
174
175 \DescribeMacro{[noload]} Suppress automatic loading of the graphics
176 extensions library \pstyle{pict2e.sty}. \pstyle{Pict2e} supports both
177 PostScript and PDF graphics, but automatic loading can be inhibited if it
178 causes problems, or if you want to pass your own options to \pstyle{pict2e}.
179
180 Earlier versions of \Qt\ used \pstyle{eepic.sty} as the graphics enhancement library; if you want to use it instead of \pstyle{pict2e}, invoke \Qt\ with the package option \texttt{[noload]} and load \pstyle{eepic.sty} manually (using \verb|\usepackage{eepic}|).
181
182
183 \subsection{Customization parameters}
184 \label{s:params}
185
186 \DescribeMacro{\qtreecentertrue}
187 \DescribeMacro{\qtreecenterfalse}
188 Trees are horizontally centered on the line by default, but you can turn
189 centering on and off at any point with these commands. They obey the usual
190 scoping rules; if used inside an \verb|enumerate| environment, for example,
191 their effect will only last until the end of that environment. (See also the
192 \texttt{[(no)center]} package options).
193
194 \paragraph{Length parameters}
195 The following macros can be redefined to customize various aspects of tree
196 construction. (Note that they are all \emph{macros,} not counters).
197
198 \DescribeMacro{\qtreepadding} The amount of whitespace inserted around
199 labels and leaf nodes as the tree is built. The default is the value of the
200 \LaTeX\ parameter \cmd{\tabcolsep} (usually set to \texttt{6pt}). It is safe
201 to change the value of this macro for different trees, but modifying it in
202 the middle of a tree could lead to somewhat strange behaviour.
203
204 \DescribeMacro{\qroofpadding}
205 The amount of whitespace inserted around text placed under a
206 roof; that is, the width of the ``eaves'' of the roof that extend beyond the
207 text. The default is \texttt{0.4em.}
208
209 \DescribeMacro{\qtreeunaryht}
210 The height of the line connecting the labels of non-branching
211 nodes to their leaves. The default is \texttt{2ex}.
212
213 \paragraph{Customization hooks}
214 The following macros are empty by default, but they can be defined to
215 customize the appearance of labels and leaves. They can safely change font
216 styles etc., since they are invoked inside another environment.
217
218 \DescribeMacro{\qtreeinithook} Called at the beginning
219 of each tree, before processing begins. It can be used for definitions or
220 modifications of commands that should only be in effect during tree
221 construction. (For example, to use the \verb|\small| font size for all trees).
222
223 \DescribeMacro{\qtreefinalhook} Called after the completed tree has been
224 printed out; it might be used, for example, to end an environment opened
225 with \verb|\qtreeinithook|.
226
227 \DescribeMacro{\qleafhook}
228 \DescribeMacro{\qlabelhook}
229 \verb|\qleafhook| is called for each leaf node, and \verb|\qlabelhook| for
230 each non-terminal label.
231 They can be used to define default fonts, etc., for
232 text in these places. Their use is explained in section \ref{s:ftune}.
233
234 \vneed{2in}
235 \section{Basic usage}
236
237 \subsection{Tree syntax}
238
239 \DescribeMacro{\Tree}
240 The front end of \Qt\ reads a tree description
241 written in the familiar (to linguists) bracket notation. Tree labels are
242 delimited by whitespace. To make a multi-word node label, enclose it in
243 braces. Note also that
244 \TeX\ discards the spaces immediately after {\it control
245 sequences\/} (commands whose name consists of a backslash followed by
246 letters); hence if a node label ends with a control sequence, like
247 \verb|\ldots| in the following example, you need to enclose it in braces
248 too.
249
250 \Tree [.CP [.{\sc Spec}(CP) {which car} ] {\ldots} ]
251 \begin{verbatim}
252 \Tree [.CP [.{\sc Spec}(CP) {which car} ] {\ldots} ]
253 \end{verbatim}
254
255 \subsection{Label matching}
256 For convenience, a label for a non-terminal node can be written either after
257 the left bracket or after the right bracket corresponding to that node. Thus
258 the following are equivalent:
259 \begin{verbatim}
260 \Tree [.S when [.NP the cat ] sleeps ]
261 \Tree [.S when [ the cat ].NP sleeps ]
262 \end{verbatim}
263 To help keep braces matched when editing large trees, the front end allows
264 the option of writing a label after both the left and the right bracket of
265 the same node, as shown for the node NP below. In this case the two labels
266 provided must be identical, token for token.
267 \begin{verbatim}
268 \Tree [.S when [.NP the cat ].NP sleeps ]
269 \end{verbatim}
270
271 \vneed {2cm}
272 \subsection{Roofs}
273 \DescribeMacro{\qroof}
274 \DescribeMacro{\qroofx}
275 \DescribeMacro{\qroofy}
276 The command \verb|\qroof| draws a triangular ``roof'' above a phrase that is
277 treated as a unit. It can appear anywhere a {\it leaf\/} can appear. The slope
278 of the roof is equal to the ratio \verb|\qroofy / \qroofx| (these counters may
279 be reset to any pair of integers between zero and six; the default is 1/3).
280
281 To create a roof
282 labeled {\it NP\/} over the phrase {\it the book,} write
283 \begin{flushleft}
284 \begin{verbatim}
285 \qroof{the book}.NP
286 \end{verbatim}
287
288 \vspace{-0.75cm}
289 \hfil\hfil \leaf{\qroof{the book}.NP } \qobitree
290 \end{flushleft}
291
292 If the phrase contains line breaks introduced with \verb|\\|, the resulting
293 lines are flush left, not centered. Again, it is possible for the ``phrase''
294 to be a construction of arbitrary complexity; but the syntax of
295 \verb|\qroof| does not allow further branches of the tree to appear under
296 the roof, since a roof is meant to cover material that is not
297 analyzed.\footnote{%
298 \QT\ internally implements a roof as a large leaf.
299 } % END FOOTNOTE
300 See also the discussion of roofs in the following section.
301
302 % Although the parsing messes up, it IS possible to work qroof into a
303 % non-terminal label:
304 % \Tree [.A this [.{\qroof{Cheat}.ME } x [ below ] ]]
305
306 \vneed{3cm}
307 \subsection{Branching without labels}
308
309 Sometimes we want to draw an abbreviated tree without a label on some or all
310 intermediate nodes. \QT\ will handle such trees correctly:
311
312 % \medskip
313 % \Tree [ [.np Eve ] [ [.(np$\backslash$s)/np ate ] [ [.np/n the ] [.n apple ]
314 % ]]]
315
316 \medskip
317 \Tree [.CP Spec(CP) [ C^0 [.IP I^0 Comp(IP) ] ] ]
318 \begin{verbatim}
319 \Tree [.CP Spec(CP) [ C^0 [.IP I^0 Comp(IP) ] ] ]
320 \end{verbatim}
321
322 Starting with qtree version 3.1b, a roof without a label will be attached to the tree branches above it. Note that the period between the roof text and the label does need to be given. If you use this option, you will probably want to adjust the roof angles so that they match the slope of the branch above it. For binary branching, the correct values are \verb|\qroofx=2|, \verb|\qroofy=1|.
323
324 \begin{verbatim}
325 \qroofx=2
326 \qroofy=1
327 \Tree [.S This [ [.V is ] \qroof{a simple tree}. ] ]
328 \end{verbatim}
329
330 \qroofx=2
331 \qroofy=1
332 \Tree [ [.NP This ] [ [.V is ] \qroof{an unlabeled tree}. ] ]
333
334
335
336
337
338
339 \subsection{Subscripts, superscripts and primes}
340 \label{s:super}
341
342 \QT\ defines the following formatting commands in such a way that they are
343 only in effect during tree construction. They have their regular meaning (or
344 none) in the rest of the document.
345
346 \DescribeMacro{\automath}
347 \DescribeMacro{\noautomath}
348 Trees are constructed in a special environment in which things like
349 \verb|NP_i|, \verb|N^0|, automatically format their subscripts or
350 superscripts in math mode, giving NP$_i$ and N$^0$, respectively. The
351 command that arranges this is called \verb|\automath|, and can also be enabled outside the tree environment, if desired. (It is turned off with
352 \verb|\noautomath|).
353
354 Because this feature relies on
355 \verb|\catcode| changes for its operation, \cmd{\automath} has no
356 effect when called inside footnotes or floats; in such trees, all sub- or
357 superscripts should be explicitly placed in math mode, as you would ordinarily do. Alternately, you can turn on \cmd{\automath} before entering the footnote or float.
358
359
360 \vneed{1in}
361 \marginpost{\cmd{\0},\cmd{\1},\cmd{\2}}
362 {\makeatletter \qtreeprimes@internal
363 As a further convenience, constructions like \verb|X$'$|, producing X\1, can
364 be abbreviated \verb|X\1|. (If you simply type \verb|X'| you get X', with an
365 apostrophe rather than a prime). There is also \verb|X\2|, producing X\2, and
366 \verb|X\0|, producing X\0. These commands also arrange for subtle
367 improvements in the centering of labels that use them, by using \cmd{\rlap}
368 to set the superscript.}
369
370 \DescribeMacro{\qtreeprimes}
371 \qtreeprimes
372 If you want to use commands like \cmd{\1} in your text (outside of trees),
373 you can cause all three to be defined by putting the command
374 \cmd{\qtreeprimes} in your preamble. The version defined in this way does
375 not use \cmd{\rlap} around the superscripts, since this is inappropriate for
376 running text. Thus you get X\1, X\2, and X\0. (Notice the position of the
377 punctuation compared to the previous paragraph). The versions that use
378 \cmd{\rlap} will still be used inside trees.
379
380 \bigskip
381 \vneed{2in}
382 Here is an example using some of these features:
383
384 \label{roof}
385 \Tree
386 [.IP [ Roses ].NP_i [.I\1 [ are ].I\0
387 [.VP t_i [ [ going ].V\0 \qroof{out of style}.PP ].V\1 ].VP
388 ].I\1 ]
389 \begin{verbatim}
390 \Tree
391 [.IP [ Roses ].NP_i [.I\1 [ are ].I\0
392 [.VP t_i [ [ going ].V\0 \qroof{out of style}.PP ].V\1 ].VP
393 ].I\1 ]
394 \end{verbatim}
395 Granted, by the time the examples get this big, the bracketed format isn't
396 all that readable; but it's certainly no worse than any other tree format,
397 and you can add white space to make it a little better.
398
399 \subsection{Customizing text appearance}
400 \label{s:ftune}
401
402 \DescribeMacro{\qleafhook}
403 \DescribeMacro{\qlabelhook}
404 The macros \cmd{\qleafhook} and \cmd{\qlabelhook} don't do anything by default,
405 but they can be defined to control the appearance of the text in
406 leaves and in branch labels, respectively. The macros can be defined
407 either with or without an argument; the following examples illustrate both options.
408 \begin{verbatim}
409 \newcommand{\qlabelhook}{\bf}
410 \newcommand{\qleafhook}[1]{\emph{#1}}
411 \newcommand{\qlabelhook}{\framebox}
412 \end{verbatim}
413
414 \paragraph{Details:} For some effects it is important to know that
415 the argument of
416 the hook is not just the text of the leaf or label, but a small
417 \texttt{tabular} environment (which inserts whitespace controlled by
418 \cmd{\qtreepadding}). In simplified form, the code that uses the hooks looks
419 like this (where \verb|#1| is the text of the branch label).
420
421 \begin{verbatim}
422 ... \qlabelhook {\begin{tabular}[t]{c} #1 \end{tabular}}
423 \end{verbatim}
424
425 This arrangement makes it possible for leaves and labels to contain line
426 breaks (\verb|\\|). But one consequence is that the hooks cannot
427 put their argument in math mode, since a table cannot appear inside math
428 mode. Fortunately, there is a simple work-around: We get the same effect by
429 making
430 \Qt\ use the \verb|array| environment in place of \verb|tabular|.\footnote{%
431 This works because \texttt{tabular} and \texttt{array} are internally
432 implemented identically, except for switching on math mode in \texttt{array}.
433 } % END FOOTNOTE
434 To put only
435 branch labels (not leaves) in math mode, define the following hook:
436 \begin{verbatim}
437 \def\qlabelhook{\let\tabular=\array \let\endtabular=\endarray}
438 \end{verbatim}
439
440
441
442 \subsection{Escaping the parser}
443
444 \marginpost{!-escapes}
445 For fine control of the tree-building process, we must sneak certain
446 directives past the front end. If a
447 word begins with an exclamation mark, the entire word (i.e., up to the next
448 space) will be passed through unchanged, except for stripping off the ``!''.
449 Braces can be used to pass through larger groups. This is most often used
450 for the manual width-adjustment commands
451 \verb|\faketreewidth| and \verb|\qsetw| (see below), but can also be
452 used to override various \Qt\ settings for part of the tree. Note that
453 \verb|\qroof| is part of the tree syntax, and should {\it not\/} be
454 preceded by an exclamation mark.
455
456 \subsection{Adjusting inter-node spacing}
457
458 \DescribeMacro{\qsetw}
459 The command \cmd{\qsetw}\marg{length} (where \argplain{length} might be
460 \verb|0.5in|, \verb|36pt|, etc.) tells \Qt\ to override its default
461 calculation of the width of the {\it just-finished\/} node (that's the leaf
462 or branch ending just to the {\it left\/} of where the directive was
463 issued), and instead consider that width to be \argplain{length}.
464
465 \DescribeMacro{\faketreewidth}
466 Similarly,
467 \cmd{\faketreewidth}\marg{text} sets the width of the last node to be
468 equal to
469 the width of \argplain{text} (which again can contain `\verb|\\|' commands
470 etc.) \argplain{text} is not actually typeset but is used just to compute the
471 fake width of the most recently completed leaf or subtree.
472
473 % For example, the default placement rules produce the tree labeled (2b) above.
474 % By setting the width of the subtree headed by T to 1cm, we get the following:
475 %
476 % b. \Tree[ A [.T {B\\ \em note} cc ].T !\qsetw{1cm} D ].S
477
478 For example, the default placement rules would
479 produce tree (a) below. By setting the width of the subtree headed by B to
480 \texttt{1cm}, we get tree (b).
481
482 \begin{center}
483 \qtreecenterfalse
484 \leavevmode\llap{a. }\Tree [.A [ a b c d ].B C ]
485 \hfil
486 \llap{b. }\Tree [.A [ a b c d ].B !\qsetw{1cm} C ]
487
488 \end{center}
489 \begin{verbatim}
490 \Tree [.A [ a b c d ].B !\qsetw{1cm} C ]
491 \end{verbatim}
492 When you use \verb|\qsetw| or \verb|\faketreewidth| you are on your own. They
493 can either shrink or enlarge the space taken by the node and may result in
494 trees with overlapping labels.
495
496
497 \subsection{``Balanced'' trees}
498
499 \DescribeMacro{\qbalance}
500 Regular binary-branching trees often end up
501 with smaller and smaller branches as you descend into the tree; you can see
502 an example below. If you don't like this look, you can get
503 ``balanced'' trees by adjusting the width of the last leaf node. For a
504 balanced tree, this should be exactly \emph{three} times as wide as the leaves on
505 its left;\footnote{%
506 The geometrical justification for this is left as an exercise to the reader.
507 } % END FOOTNOTE
508 For binary-branching trees, the command \verb|\qbalance| can be used. It sets the width of the node just before it to be three times
509 the width of the \emph{previous} node. If it does not do what you need,
510 you'll need to set the correct width manually. In the example below, the
511 width of the leaf \emph{``last''} is set to be three times the width of
512 \emph{leaf$_3$.}
513
514 \begin{center}\small
515 \qtreecenterfalse
516 a. \Tree [.X leaf_1 [.Y leaf_2 [.Z leaf_3 last ] ] ]
517 \hfil
518 b. \Tree [.X leaf_1 [.Y leaf_2 [.Z leaf_3 last !{\qbalance} ] ] ]
519 \end{center}
520 \begin{verbatim}
521 \Tree [.X leaf_1 [.Y leaf_2 [.Z leaf_3 last !{\qbalance} ] ] ]
522 \end{verbatim}
523
524
525
526
527
528 \vneed{1.5in}
529 \section{Using qtree}
530 \subsection{How to convert a tree to brackets}
531
532 Reading or writing a complex tree in bracket notation is not terribly easy for
533 humans; it helps to have an editor that can show matching braces as they are
534 typed in. The procedure described here should allow you to easily convert a
535 tree to bracket notation. If you don't have any difficulty with this, just
536 skip this section and do it any way you want!
537
538 \begin{enumerate}
539 \item Draw the tree you want to enter on a piece of paper, so you can look at
540 it.
541
542 \item Imagine that the tree is a large peninsula, and your pencil is a boat
543 sailing around it. Starting just to the left of the root node, move
544 downwards, following the outline of the tree until you come back to the root
545 node (on the right side, having moved counterclockwise around the tree),
546 without crossing any of the tree's lines.
547
548 \item \begin{enumerate}
549 \item
550 Every time you are at the left side of a non-terminal node, type a left
551 bracket, and the label for that node.
552 \item Every time you are
553 at a leaf node, type in the contents of that node.
554 \item
555 Finally, every time you are on the right of a non-terminal node, type a right
556 bracket (and the node name again, if you want to help keep them straight).
557 \end{enumerate}
558
559 \end{enumerate}
560
561 To see this in practice, consider the following tree; in the variant on the
562 right, the numbered subscripts show the order in which the brackets and
563 labels are written.
564
565 \bigskip
566 \Tree [.A [.B [.C one ] [.D two ] ].B [.E three ] ].A
567 %
568 \Tree [.{[_1 A ]_{13}}
569 [.{[_2 B ]_9} [.{[_3 C ]_5} one_4 ] [.{[_6 D ]_8} two_7 ] ]
570 [.{[_{10} E ]_{12}} three_{11} ] ]
571 \par
572 \medskip
573 Accordingly, we would generate the tree by typing the following:
574
575 {\center
576 \verb|\Tree [.A [.B [.C one ] [.D two ] ].B [.E three ] ].A| \par}
577
578
579 \subsection{Placing trees on the page}
580
581 \paragraph*{Numbered examples etc.}
582 A tree generated with \Qt\ can be placed in a numbered example environment,
583 in footnotes or \verb|\parbox|es, inside math formulas, tables, pictures,
584 etc. The tree nodes can themselves contain arbitrarily complex
585 material---although, unfortunately, it is not possible to embed a recursive
586 call to \Qt. If you need to do this, save the intermediate tree
587 in a \verb|\box|. An example is shown in section \ref{s:embed}.
588
589 Trees are centered horizontally on the line by default, but this feature can
590 be turned off with \verb|\qtreecenterfalse| (see section \ref{s:params}).
591 If you are not satisfied with the horizontal placement of the
592 tree, you can adjust it by judicial use of \verb|\hskip|.\footnote{%
593 Earlier versions of \Qt\ inserted stray spaces in front of trees,
594 requiring frequent use of \texttt{\bslash hskip}. This problem has now been
595 fixed.
596 } % END FOOTNOTE
597
598 \QT\ attempts to align the topmost label of the tree with the baseline of
599 the text, similarly to the effect of the [t] option for \verb|\parbox|
600 alignment. To center trees vertically on the baseline, enclose the entire
601 tree in a \texttt{tabular} environment.
602 %% \footnote{%
603 %% You may also want to suppress the padding that \texttt{tabular} normally
604 %% inserts, as follows:
605
606 %% \centerline{...} (Covered in the FAQ section)
607 %% } % END FOOTNOTE
608
609 % Here is an example
610 % using the {\tt enumerate} environment, and the code to generate it.
611
612 % \begin{enumerate} \item[(1)] a. \hskip-0.75in
613 % \Tree[.C [.Tns [.Neg [.Ind V [.Ind Ind Agr$_1$ ]] Neg ].Neg
614 % [.Tns Agr$_2$ Tns ] ].Tns [.C C Agr$_3$ ] ]
615 % \end{enumerate}
616 % \begin{verbatim}
617 % \begin{enumerate} \item[(1)] a. \hskip-0.75in
618 % \Tree[.C [.Tns [.Neg [.Ind V [.Ind Ind Agr_1 ]] Neg ].Neg
619 % [.Tns Agr_2 Tns ] ].Tns [.C C Agr_3 ] ]
620 % \end{enumerate}
621 % \end{verbatim}
622
623
624 \paragraph*{Side by side trees}
625 Multiple trees, or text and trees, can be arranged side by side. This can
626 generally be done by just arranging commands one after another; it usually
627 helps to turn off tree centering. If necessary the positioning can be
628 adjusted with \verb|\hskip|.
629 \begin{enumerate}
630 \qtreecenterfalse
631 \item[(2)] a. \Tree [.S [.NP \'el\\he ]
632 [.VP [.V hizo\\made ] [.V decir\\say ]
633 [.NP lo\\it ] [.NP a-mi\\me ] ].VP ]
634 \hskip 0.3in
635 b. \Tree[ A [.T {B\\ \em note} cc ].T D ].S
636 \end{enumerate}
637 \label{2b}
638 \begin{verbatim}
639 \begin{enumerate}
640 \qtreecenterfalse
641 \item[(2)] a. \Tree [.S [.NP \'el\\he ]
642 [.VP [.V hizo\\made ] [.V decir\\say ]
643 [.NP lo\\it ] [.NP a-mi\\me ] ].VP ]
644 \hskip 0.3in
645 b. \Tree[ A [.T {B\\ \em note} cc ].T D ].S
646 \end{enumerate}
647 \end{verbatim}
648
649
650
651 % \paragraph*{\it Trivia note:\/}
652 % If you insist on placing trees in a \verb|\parbox|, here is how to do it.
653 % Note the \verb|~|, called a {\it tie,\/} before \verb|\Tree| inside the
654 % parbox; it keeps \LaTeX\ from breaking the line and placing the tree one
655 % line too low.
656 % \begin{enumerate}
657 % \item \parbox[t]{2.4in}{ (a)~\Tree
658 % [.VP [.NP (mud) ] [.V\1 [.V (get) ] [.PP {(on wall)} ]]] }
659 % %
660 % \parbox[t]{2in}{ (b)~\Tree
661 % [.VP [.NP (screen) ] \qroof{V\qquad AP\\ \hfil(clear)~}.V\1 ] }
662 % \end{enumerate}
663
664 % \begin{verbatim}
665 % \begin{enumerate}
666 % \item \parbox[t]{2.4in}{ (a)~\Tree
667 % [.VP [.NP (mud) ] [.V\1 [.V (get) ] [.PP {(on wall)} ]]] }
668 % \parbox[t]{2in}{ (b)~\Tree
669 % [.VP [.NP (screen) ] \qroof{V\qquad AP\\ \hfil(clear)~}.V\1 ] }
670 % \end{enumerate}
671 % \end{verbatim}
672
673 \section{Advanced features}
674
675
676
677 \subsection{Putting a frame around part of a tree}
678
679 \DescribeMacro{\qframesubtree}
680 The command \verb|\qframesubtree| will put a rectangular box
681 (``frame'') around part of a tree. It should be placed just \emph{after} the
682 closing bracket of the subtree that should be boxed.
683
684 \Tree [.IP [.NP Roses ] [ [.I^0 are ]
685 [.VP t [ [.V^0 turning ] [.NP pink ] ] ].VP !{\qframesubtree} ]]
686 \begin{verbatim}
687 \Tree [.IP [.NP Roses ] [ [.I^0 are ]
688 [.VP t [ [.V^0 turning ] [.NP pink ] ] ].VP !{\qframesubtree} ]]
689 \end{verbatim}
690
691 Only complete subtrees can be framed with this method. To enclose a single
692 label node in a box, use a frame command directly. To box all
693 labels or leaves, you can use the format customization hooks. For example,
694 the following will put a box around every label:
695 \begin{verbatim}
696 \renewcommand{\qlabelhook}[1]{\framebox{#1}}
697 \end{verbatim}
698
699 \subsection{Embedding one tree in another}
700 \label{s:embed}
701
702 The internal implementation of \Qt\ only supports one tree being built at
703 one time; hence it does not allow a complete tree to be recursively embedded
704 as part of another one. This is not actually needed very often (trees are
705 already recursive, after all); for most constructions that seem to require
706 it, there's a simpler way to get the same effect. But it might be
707 necessary, for example, if you need to put a subtree under a roof.
708
709 Fortunately it's straightforward to embed one tree in another using \TeX's
710 facilities, without ever calling \Qt\ recursively. We can do this by saving
711 the first tree in a named box, and then using it as part of the larger tree.
712 Here's how:
713
714 \vneed{6cm}
715 \begin{flushleft}
716 \footnotesize
717 \begin{verbatim}
718 \newsavebox{\partbox} % Declare this only once, in your preamble!
719
720 %% Build the subtree and save it in the box
721 \setbox\partbox=\hbox{\Tree [.DP my pony ] }
722
723 %% Use the subtree in the containing tree
724 \Tree [ how
725 \qroof{about \usebox{\partbox} ...}.PP
726 ].S
727 \end{verbatim}
728
729 \vspace{-3.1cm}
730 \newsavebox{\partbox} % Declare this only once, in your preamble!
731
732 %% Build the subtree and save it in the box
733 \setbox\partbox=\hbox{\Tree [.DP my pony ] }
734
735 \hfill
736 %% Use the subtree in the containing tree
737 \Tree [ how
738 \qroof{about \usebox{\partbox} ...}.PP
739 ].S
740 \end{flushleft}
741
742
743 \subsection{Overriding branch drawing}
744 \label{s:bdraw}
745
746 \QT\ is designed to produce nice trees automatically; it is not designed for
747 fine control over their appearance. Nevertheless, technically inclined users
748 could use the \verb|!| escape mechanism to temporarily redefine the
749 branch-drawing routine and draw the branches any way they want, specifying
750 wavy or dotted lines between selected nodes, arrows at line tips, etc.
751
752 \DescribeMacro{\qdraw@branches}
753 The code that draws the lines from a tree node to its daughters
754 is encapsulated in the macro \cmd{\qdraw@branches}.
755 It takes one argument, the number of branches, and
756 uses graphics commands to draw a picture containing the branched
757 lines. The default drawing is very simple; the actual width of the picture
758 is controlled through the value of the
759 parameter \cmd{\unitlength} (see the documentation of the standard \LaTeX\
760 environment \verb|{picture}|), which will be set to \emph{half} the
761 required distance between the branch tips before \cmd{\qdraw@branches} is
762 called.
763
764 In the following simple example we override the macro (and later restore it),
765 to shorten the line that connects ``b'' to its parent and add an arrow at its
766 end (with \verb|\vector|). Since the custom macro will only be used once, it supports ternary
767 branching only and ignores its argument.
768 \begin{flushleft}
769 \makeatletter
770 \newcommand{\myLines}[1]{% Three-way only
771 \begin{picture}(4,1)
772 \put(0,0){\line(2,1){2}}
773 \put(2,0){\vector(0,1){0.7}}
774 \put(4,0){\line(-2,1){2}}
775 \end{picture}}
776 \let\qdrawReal=\qdraw@branches
777 \newcommand\brOverride{\let\qdraw@branches=\myLines}
778 \newcommand\brRestore{\let\qdraw@branches=\qdrawReal}
779 \small
780
781 \hfill \Tree [.Top X [.Hub a b [.c left right ]
782 !{\brOverride} ].Hub !{\brRestore} ].Top
783
784 \vspace{-3.8cm}
785 \begin{verbatim}
786 \makeatletter
787 \newcommand{\myLines}[1]{% Three-way only
788 \begin{picture}(4,1)
789 \put(0,0){\line(2,1){2}}
790 \put(2,0){\vector(0,1){0.7}}
791 \put(4,0){\line(-2,1){2}}
792 \end{picture}}
793 \let\qdrawReal=\qdraw@branches
794 \newcommand\brOverride{\let\qdraw@branches=\myLines}
795 \newcommand\brRestore{\let\qdraw@branches=\qdrawReal}
796 \makeatother
797
798 \Tree [.Top X [.Hub a b [.c left right ]
799 !{\brOverride} ].Hub !{\brRestore} ].Top
800 \end{verbatim}
801 \end{flushleft}
802
803 The branch-drawing code above is a simple modification of the commands
804 found in the style file, but it could be replaced with commands using a
805 drawing environment of your choice, and inserting arbitrary graphic elements.
806 Note, however, that the horizontal placement of child nodes on the page is
807 not affected by what the drawing routine does; drawing wider or narrower
808 branch lines will not cause the text to move with them.
809
810
811 \subsection{Visualising tree construction}
812
813 If you're curious about how \Qt\ assembles leaves and labels into a tree,
814 you can try the command \verb|\qtreeshowframes|. It causes trees to
815 be drawn with boxes around their leaf nodes and labels; in the example
816 below we also add a frame around the entire tree, to show \TeX's idea of its
817 bounding box:
818
819 \bigskip
820 \vneed{4cm}
821 \begin{flushleft}
822 \small
823 \begin{verbatim}
824 { \qtreeshowframes
825 \frame{\Tree [.S This
826 [.VP [.V is ]
827 [.NP [.D a ] [ simple tree ] ]
828 ]] }}
829 \end{verbatim}
830
831 \vspace{-2.5cm}
832 \leavevmode\hfill { \qtreeshowframes
833 \frame{\Tree [.S This
834 [.VP [.V is ]
835 [.NP [.D a ] [ simple tree ] ]
836 ]] }}
837 \hspace{\tabcolsep}\strut
838 \end{flushleft}
839
840
841 \subsection{The low-level interface}
842 The guts of \Qt\ are the tree macros written by Jeff Siskind, named
843 \emph{QobiTree.} Using the original interface (which is still accessible
844 with this package) the example tree shown on page \pageref{2b} would be
845 written like this:
846
847 \begin{center}
848 \leaf{A}
849 \leaf{B\\ \em note} \leaf{cc}
850 \branch{2}{T}
851 \leaf{D}
852 \branch{3}{S}
853 \hskip 3in \qobitree
854 \end{center}
855 \vspace*{-1.5in}
856 \begin{verbatim}
857 \begin{center}
858 \leaf{A}
859 \leaf{B\\ \em note} \leaf{cc}
860 \branch{2}{T}
861 \leaf{D}
862 \branch{3}{S}
863 \qobitree
864 \end{center}
865 \end{verbatim}
866
867 These macros operate like a stack machine. You push \TeX\ boxes onto the
868 stack of tree nodes, then you pop them off to make branching nodes which
869 get pushed back on the stack. The \Qt\ front end internally generates these
870 commands to build trees.
871
872 The command\verb|\branch| requires you to specify the number of stack elements that will be made into children of the new node. The front end uses an internal counter, \verb|\nbranches|, to keep track of how many children a node has.
873
874 It is possible, and in some cases even useful, to write your own commands that
875 add bits of tree structure to the qtree stack. The command \verb|\mylex| in the following example formats a singleton branch label in bold above lexical items (in italics), while leaving other branch labels in the default roman font.
876
877 {\small
878 \begin{verbatim}
879 \newcommand\mylex[2]{\advance\nbranches by1
880 \leaf{\emph{#2}}\branch{1}{\bf #1}}
881
882 \Tree [.S !\mylex{N}{John}
883 [.VP !\mylex{V}{saw} !\mylex{N}{Jane} ]]
884 \end{verbatim}}
885 \vspace*{-2.7cm}\hfill
886 \newcommand\mylex[2]{\advance\nbranches by1 \leaf{\emph{#2}}\branch{1}{\bf #1}}
887 \Tree [.S !\mylex{N}{John} [.VP !\mylex{V}{saw} !\mylex{N}{Jane} ] ]
888
889 \medskip
890
891 We use \verb|!| to bypass the front end, in order to manipulate the tree stack directly. The macro pushes a leaf onto the stack and then includes it under a singleton branch with a bold label. It also increments the counter \verb|\nbranches| to let the front end know that the resulting node has been added to the stack. With some understanding of how qtree works, much more complicated commands are possible. (In extreme cases, you might consider bypassing the front end altogether and relying exclusively on the stack interface).
892
893
894 \section{How do I \ldots? (The qtree FAQ)}
895
896 \paragraph{Make my tree fit in the page?} Try one or more of the following:
897 reduce the font size with \verb|\small| or another size command,
898 \emph{before} you begin the tree; reduce the amount of space between subtrees
899 with \verb|\qsetw| or \verb|\faketreewidth|; abbreviate unimportant parts of
900 your tree with \verb|\qroof|; consider placing your tree sideways in the page,
901 using one of the packages that provide rotation commands.
902
903 \paragraph{Draw movement arrows from one node of a tree to another?}
904 Use Emma Pease's \pstyle{tree-dvips.sty}, or some other package for drawing
905 lines between locations on the page. Despite its name, \pstyle{tree-dvips}
906 is not narrowly tailored to creating trees; its many line- and arrow-drawing
907 commands can be used to decorate trees drawn with \Qt.
908
909 \paragraph{Use \Qt\ with \textsl{pdflatex}?}
910 Earlier versions of \Qt\ did not have good pdflatex support. The current
911 version supports it through the package \pstyle{pict2e.sty.} If it is not
912 already available on your system, it is highly recommended that you install
913 it. See section 2 for details.
914
915 \paragraph{Place a tree in a footnote, figure, or macro argument?} \QT\ does work in floats, but the \verb|\automath| feature is not available in such environments. If you're having problems, you're probably using sub- or superscripts without switching to math mode. See section~\ref{s:super}.
916
917 \paragraph{Center my trees vertically on the baseline?}
918 Put them inside a trivial
919 \texttt{tabular} environment. (This can be automated with the hooks
920 \verb|\qtreeinithook|, \verb|\qtreefinalhook|). To avoid extra whitespace
921 around the tree, use the following column specification (see the documentation of \verb|{tabular}| for an explanation):
922
923 \verb|\begin{tabular}[c]{@{}l@{}} \Tree ...|
924
925 \paragraph{Line up the text from all the leaf nodes on one horizontal line?}
926 As far as I can tell, \Qt's design is incompatible with this style of
927 tree. I'd love it if there was an easy way to give \Qt\ this
928 capability, but if there is, I haven't figured it out.
929
930 \paragraph{Draw dashed or dotted branches between certain nodes?}
931 This requires a bit of \LaTeX\ hacking skills, but it can be done. See
932 section \ref{s:bdraw} for details.
933
934 \paragraph{Automatically select a particular font for branch or leaf labels?}
935 Redefine \verb|\qlabelhook| and/or \verb|\qleafhook|. See section
936 \ref{s:ftune}.
937
938 \paragraph{Embed one call to \Qt\ inside another?} \QT\ cannot be called
939 recursively. If you do need to embed one tree in another (it's very rarely
940 necessary), save the smaller tree in a \verb|\savebox| and insert it into
941 the bigger one. See section \ref{s:embed} for the details.
942
943
944 \section{Troubleshooting}
945
946 \paragraph*{Disclaimer:}
947 I welcome any comments, feature requests, or reports of other problems.
948 But as usual, no guarantees, promises, etc.\ can be made about the present or
949 future state of this code.
950
951 \paragraph{The placement of trees on the page has changed} Version 3 of \Qt\
952 has fixed some bugs in horizontal spacing (most visibly, extra spaces used
953 to be inserted before trees), and made countless small adjustments in
954 spacing. Trees are now centered exactly on the line, and they generate
955 \emph{no} white space around them.\footnote{%
956 If you put a tight box around a tree (using \texttt{\bslash frame}), it will
957 just touch the sides of the tree.
958 } % END FOOTNOTE
959 They are thus easy to position and integrate with other visual objects.
960
961 Unfortunately, this creates a compatibility problem, as it was not practical
962 to provide a ``backwardly compatible'' spacing option. If you have used a
963 lot of \verb|\hspace| commands to adjust the placement of your trees, they
964 will no longer work properly. On the positive side, it should now be very
965 easy to arrange trees the way you want them. If you need to process files that have a lot of old trees with spacing adjustments, you can install the package
966 \pstyle{qtree221.sty}, which contains version 2.21 of qtree. The new commands
967 and formatting options of \Qt\ version 3 are not available in
968 \pstyle{qtree221.sty}.\footnote{\pstyle{qtree221.sty} is not available on CTAN. It can be downloaded from the Qtree home page, http://www.ling.upenn.edu/advice/latex/qtree/.}
969
970 The change-over is a one-time incompatibility. Future revisions will
971 retain the spacing of version 3.
972
973 \paragraph{LaTeX says that pict2e.sty ``will not be written soon''}
974 \pstyle{Pict2e.sty} \emph{has} finally been written. You need to update your \TeX\ distribution or just download the package. If you cannot do that for any reason, load \Qt\ with \verb|\usepackage[noload]{qtree}| to suppress loading of \pstyle{pict2e.sty}.
975
976 \paragraph{Some very short lines are not drawn}
977 This problem is caused by the limited inventory of line shapes in
978 the original \LaTeX\ picture environment. For example, the tree fragment
979 \verb|[.X a b ]| will produce invisible branch lines from \verb|X| to
980 \verb|a| and~\verb|b|,
981 but the lines will reappear if the labels are made wider. If you use
982 \pstyle{pict2e}, the problem should go away.
983
984 \paragraph{Some not-so-short lines are not drawn} My dvi previewer (yap)
985 sometimes fails to display some lines; but the lines are really there,
986 and can be seen at higher magnifications, or when the file is printed or
987 converted to PostScript. So it's only a problem with the previewer;
988 if it gets in your way, suppress loading of
989 \pstyle{pict2e} with the package option \texttt{[noload]}.
990
991 \paragraph{\TeX\ is running out of registers} \QT\ is a real pig for
992 counter registers: it uses more than 60 of them. In combination with other
993 packages that use a lot (e.g., the \pstyle{memoir} class), this can go over
994 the limits of the original \TeX\
995 engine. Fortunately most distributions have now quietly switched to using
996 e\TeX\ internally, which makes many more registers available (you still
997 invoke it simply as \verb|latex|, so you probably don't even know you're
998 using it). But you need to tell e\TeX\ that the extra
999 registers are there. If you run out of registers, try including the
1000 package \pstyle{etex.sty} and see if it fixes the problem.\footnote{%
1001 If you include \pstyle{etex.sty} and strange things
1002 start happening, you probably aren't running the e\TeX\ engine; in that case,
1003 \emph{don't} load \pstyle{etex.sty.} You'll have to install a newer \TeX\
1004 distribution first.
1005 } % END FOOTNOTE
1006
1007 \paragraph{There's too much space below my trees, but only when I use pdflatex}
1008 Qtree should produce identical output for dvi and pdf. The problem is caused by a bug in older versions of \pstyle{color.sty}, which is loaded internally by many pdf-aware packages.\footnote{The bug is in the redefinition of \texttt{$\backslash$ usebox} in the file \pstyle{pdftex.def}.}
1009 Update the package \pstyle{color} from CTAN (the entire directory) and the problem will go away.
1010
1011
1012 \paragraph{\QT\ will not work with journal style X}
1013
1014 Any number of things could be going wrong, of course, but start by checking if
1015 the journal's style redefines the {\tt tabular\/} environment. \QT\
1016 makes internal calls to {\tt tabular\/}, so this is a frequent source of
1017 problems. Usually the style's writer has saved the original definition of
1018 \verb|\tabular| under a different name, so all you need to do is arrange for
1019 the original definition to be restored during the calls to \verb|\Tree|.
1020
1021 You can define
1022 \verb|\qtreeinithook| to carry out the necessary redefinitions. It is
1023 called at the beginning of each call to \verb|\Tree|, with
1024 local scope (so that any redefinitions it makes are automatically canceled
1025 at the end of the call to \verb|\Tree|). For example, the JNLE style
1026 (\pstyle{nle.sty}) saves the standard commands to begin and end a table as
1027 \verb|\oldtabular| and \verb|\endoldtabular|, respectively, and the
1028 replacement macros result in {\it ~r e a l l y ~ w i d e~\/} trees. The
1029 following will restore the original definitions for calls to \verb|\Tree|
1030 only.
1031 \begin{verbatim}
1032 \def\qtreeinithook{\let\tabular=\oldtabular
1033 \let\endtabular=\endoldtabular}
1034 \end{verbatim}
1035
1036 Kluwer's house style saves the original definitions as \verb|\klu@tabular| and \verb|\klu@endtabular|; they can be restored in the same way. (You'll need to use \verb|\makeatletter| since these names contain an \texttt{@}-sign).
1037
1038 \end{document}
1039
1040 % possibilities for the documentation:
1041 % - expand tree-dvips discussion?
1042 % - incorporate how-to-draw picture?
1043
1044
1045 % I guess we don't need this in the printed manual anymore...
1046
1047 \section{Inspiration}
1048 Here is a last demo, illustrating some of the things you {\it can\/} do with
1049 \Qt.
1050 (This example, and parts of the above exposition, were adapted from the
1051 original documentation for \texttt{QobiTree}).
1052
1053 \def\CUP{{\bf cup}}
1054 \def\Nspec{N$_{\mbox{\sc spec}}$}
1055 \Tree [.{{\em The cup slid from John to Mary.}\\
1056 {GO(\CUP, $[_{\rm Path}$ FROM({\bf John}), TO({\bf Mary})])}\\IP}
1057 [.\fbox{Fracture}
1058 %
1059 [.{{\em The cup}\\\CUP\\NP}
1060 [ {{\em The}\\$\bot$\\\Nspec} {{\em cup}\\\CUP\\N} ].\fbox{Fracture}
1061 ]
1062 [.{{\em slid from John to Mary}\\
1063 {GO({\it x}, $[_{\rm Path}$ FROM({\bf John}), TO({\bf Mary})])}\\IP}
1064 [ $\vdots$ $\vdots$ !\faketreewidth{WWW} ].\fbox{Fracture}
1065 ]
1066 ].\fbox{Fracture} % repeated label
1067 ]
1068
1069 {\small
1070 \begin{verbatim}
1071 \def\CUP{{\bf cup}}
1072 \def\Nspec{N$_{\mbox{\sc spec}}$}
1073 \Tree [.{{\em The cup slid from John to Mary.}\\
1074 {GO(\CUP, $[_{\rm Path}$ FROM({\bf John}), TO({\bf Mary})])}\\IP}
1075 [.\fbox{Fracture}
1076 %
1077 [.{{\em The cup}\\\CUP\\NP}
1078 [ {{\em The}\\$\bot$\\\Nspec} {{\em cup}\\\CUP\\N} ].\fbox{Fracture}
1079 ]
1080 [.{{\em slid from John to Mary}\\
1081 {GO({\it x}, $[_{\rm Path}$ FROM({\bf John}), TO({\bf Mary})])}\\IP}
1082 [ $\vdots$ $\vdots$ !\faketreewidth{WWW} ].\fbox{Fracture}
1083 ]
1084 ].\fbox{Fracture} % repeated label
1085 ]
1086 \end{verbatim}} % end \small
1087
1088
1089 \end{document}