Drawing Trees Using the LaTeX Previewer

176 downloads 206 Views 439KB Size Report
which produces images from LaTeX code. It creates pdf ... as the underlying engine, it can do everything LaTeX can do. ..... LaTeX and Friends (Springer, 2012).
Using LaTeX Previewer to make Trees Alan Munn February 2011

1

Introduction

Troy Henderson’s LaTeX previewer http://www.tlhiv.org/ltxpreview/ is a web page which produces images from LaTeX code. It creates pdf (or other format) images that can be easily placed into other documents such as MSWord or Powerpoint. Since it uses LaTeX as the underlying engine, it can do everything LaTeX can do. This means that it can be used to quickly draw nice trees to include in Word or Powerpoint or InDesign documents without having to actually learn LaTeX fully or install it on your own computer. In this guide I will explain how to use the previewer to make nice trees.

1.1

Using the previewer

When you connect to the previewer, you first see a web page looking like this:

Click on the Packages button, and you will see a list of available packages. Choose the qtree package, and click on the arrow button to copy it from the Available list to the Included list. Then choose the fontenc[T1] package. If you want to use colors, then choose the colortbl package. When you are done, your screen should look like the following:

LaTeX Previewer and Trees

1

Now you are ready to input a simple tree into the previewer. To do this you need to learn a bit about how to construct trees using the qtree notation.

2

Qtree notation

The way trees are input is using the LaTeX package qtree, created by Alexis Dimitriadis. Qtree allows one to enter a labelled bracketing of a tree and output a tree. The rules for qtree bracketing are simple: (1) Bracketing Rules a. Every tree begins with \Tree b. labels are suffixed to brackets with a “.” character. c. all brackets must be separated by spaces d. all brackets must be balanced 1 Here, therefore, is the code for a simple tree, which produces the output in (2c). Notice that node labels can be either on the opening brackets (2a) or the closing brackets (2b) (or in fact, both). 1 For Macs, AutoPairs http://www.jwwalker.com/pages/autopairs.html is a very nice bracket balancer that works with any appliction. I don’t know if there’s an equivalent program for Windows or Linux.

LaTeX Previewer and Trees

2

(2)

a. \Tree [.DP [.D the ] [.NP [.N man ] ] ] b. \Tree [ [ the ].D [ [ man ].N ].NP ].DP c. DP D

NP

the

N man

One thing to notice in this tree is that there are branches between the terminal nodes and their labels. If you don’t want this (and I generally don’t, since the labels are labels of the words) you can include the terminal as part of the label by connecting the two with a linebreak, which in LaTeX is \\. Tree (2) could then be coded as (3a) and appear as (3b). (3)

a. \Tree [.DP [.D\\the ] [.NP [.N\\man ] ] ] b. DP D the

NP N man

If you cut and paste this tree into the Preview window, and click on the Preview button, you should see the following:

You can then click on the Download pulldown menu at the far right of the preview window to save your tree to a file. The best format to save it in is EPS. The file will show up in your LaTeX Previewer and Trees

3

usual downloads place with the filename preview.eps. If you want to save the LaTeX code too, you can, by choosing to save the LaTeX source. This file will be named preview.tex. Be sure to rename the files to something more informative before you do another tree.

2.1

More qtree commands

A few other things are built into qtree also. Bar-levels can be made with the commands X\0 X\1 X\2 which yield X0 , X0 and X00 respectively. Qtree can also make closed triangles for grouping nodes under a single node. For this you need to use the \qroof command. Here is an example. Notice that the node label here must be suffixed to the closing brace of the command. As you can also see, the input code can be split over more than one line. (4)

a. \Tree [.TP \qroof{the man with the hat}.DP [.T\1 [.T\\will ] \qroof{go to the store tomorrow}.VP ] ]

b.

TP

T0

DP the man with the hat

T will

VP go to the store tomorrow

3

Low-level qtree commands

Trees in qtree often get smaller as they get deeper. This can be fixed with the !{\qbalance} command. This command tries to balance the width of the previous nodes. Here is an example, with and without !{\qbalance}. (5)

a. \Tree [.DP the [.NP big [.NP tall [.NP man ] ] ] ] b. \Tree [.DP the [.NP big [.NP tall [.NP man ] !{\qbalance} ] ] ]

LaTeX Previewer and Trees

4

c.

DP the

d. NP

big

DP the

NP tall

NP big

NP

NP tall

NP

man man If you want even finer control of the tree branch width, you can set the width of the most recently completed node with the command !\qsetw{length}. This command takes a length such as 1in or 2cm in the curly brackets (e.g. !\qsetw{1in}). See the examples below for an example of this use.

4

Some useful latex commands

In order to format the text in a tree, it is necessary to be able to use a few LaTeX commands. Almost all LaTeX commands begin with a backslash (\) character. If a command takes an argument, the argument is enclosed in braces ({}). Here are some basic commands that are useful for tree drawing. (6) Some useful LaTeX commands a. subscripts, e.g. ti use t_i b. superscripts e.g. ti use tˆi c. to start a new line in a label, use \\ d. to keep words together as a group, enclose them in braces {} e. to display a curly bracket, precede it with a \(e.g. to produce {some text} you need to type \{some text\}) f. to display a square bracket, enclose it in $$ (e.g. to produce [some text] you need to type $[$some text$]$) (To do this a lot, see Section 6 below for a better solution.) (7) Formatting commands a. to make the font sans serif put \sffamily at the beginning of the document b. to make something italics enclose it in \textit{} c. to make something bold enclose it in \textbf{} d. to make something small caps enclose it in \textsc{} e. to change the color to red precede it with \color{red}

LaTeX Previewer and Trees

5

5

Some examples

Here are some examples of more trees. Trees (8c/d) are identical except for the use of the qsetw command to change the length of the first branches of the tree. For large trees, it’s helpful to indent the levels of the tree so that you can see the structure better. Here I’ve inde: (8)

a. \Tree [.TP [.DP [.D\\the ] [.NP [.N\\man ] ] ] [.T\1 [.T\\might ] [.VP [.V\\expect ] [.TP \qroof{the woman}.DP [.T\1 [.T\\to ] [.VP [.VP [.V\\leave ] [.DP [.D\\{\o} ] [.NP [.N\\town ] ] ] ] [.PP [.P\\after ] [.DP [.D\\the ] [.NP [.N\\party ] ]!{\qbalance} ] ] ]] ] ] ] ]

b. \Tree[.TP [.AdvP [.Adv\\usually ] ] [.TP [.DP [.D\\{\O} ] [.NP\\John ] ] [.T\1 [.T\\\emph{PRESENT} ] [.VP [.VP [.V\\goes ] [.PP [.P\\to ] [.DP [.D\\the ] [.NP\\park ] ] ] ] [.PP [.P\\on ] [.DP [.D\\{\O} ] [.NP\\Tuesdays ] ] ] ] ] ] ]

LaTeX Previewer and Trees

6

c. \Tree[.TP [.DP [.NP\\Hanako ] [.D\\ga ] ] [.T\1 [.VP [.CP [.TP [.DP [.NP\\Yoshi ] [.D\\ga ] ] [.T\1 [.VP [.DP [.NP\\Yuki ] [.D\\-o [.V\\mi ] ] [.T\\ta ] ] ] [.C\\to ] ] [.V\\it ] ] [.T\\ta ] ] !\qsetw{2.5in}

]

]

]

d. \Tree[.TP [.DP [.NP\\Hanako ] [.D\\ga ] ] [.T\1 [.VP [.CP [.TP [.DP [.NP\\Yoshi ] [.D\\ga ] ] [.T\1 [.VP [.DP [.NP\\Yuki ] [.D\\-o ] [.V\\mi ] ] [.T\\ta ] ] ] [.C\\to ] ] [.V\\it ] ] [.T\\ta ] ]

]

]

LaTeX Previewer and Trees

7

(9)

a.

TP T0

DP D the

NP N man

T might

VP

V expect

TP T0

DP the woman T to

VP

PP

VP V leave

b.

DP D ø

NP

P after

DP D the

N town

NP N party

TP

AdvP

TP

Adv usually

T0

DP D Ø

NP John

T PRESENT

VP

VP V goes

P on

PP P to

LaTeX Previewer and Trees

PP

DP D the

DP D Ø

NP Tuesdays

NP park 8

TP

T0

DP NP Hanako

D ga

VP CP

c.

V it

TP

C to

Using !\qsetw{2.5in} to make the root branches smaller.

T0

DP NP Yoshi

T ta

D ga

VP DP NP Yuki

LaTeX Previewer and Trees

D -o

V mi

T ta

9

d.

TP

T0

DP NP Hanako

D ga

T ta

VP V it

CP

TP

C to T0

DP NP Yoshi

D ga

VP DP NP Yuki

D -o

V mi

T ta

Without using !\qsetw.

6

Really advanced stuff

LaTeX can do all sorts of really amazing things, and is especially good for representing mathematics. We can use this facility to make even fancier trees, and also make shorthands for them. For example, as noted above, using square brackets in LaTeX is complicated since the square bracket is used for other things within LaTeX itself. However, we can create a command which automatically puts something in square brackets (useful for annotating nodes with features.) It requires the amsmath package to be added to the included packages. (10) Command to enclose something in square brackets a. Command definition: \newcommand{\SB}[1]{$[\text{#1}]$}

b. Command usage: \SB{some text}

c. Output: [some text]

LaTeX Previewer and Trees

10

If you put this command in the first line of your LaTeX source, you can then add features to trees using the \SB command, as in the following example: (11)

a. \newcommand{\SB}[1]{$[\text{#1}]$} \Tree [.TP [.DP\SB{Nom} [.D\\the ] [.NP [.N\\man ] ] ] [.T\1 [.T\\will\\\SB{Case:Nom} ] [.VP [.V\\left ] ] ] ]

b.

TP DP[Nom] D the

NP N man

T0 T will [Case:Nom]

VP V left

If we want to put a bunch of features in a list, we can use the array command, and automatically expandable square brackets using the \left[ and \right] commands. Here is an example: (12) Feature bundle using an array a. $\left[\begin{array}{c} \text{Tense}\\ \text{Nom}\\ \text{3PSg}\\ \end{array}\right]$

b. Output   Tense  Nom  3PSg These are just some examples of what can be done with LaTeX. They are not intended to be a complete introduction to all of its power. There are plenty of good introductions to be found on the web. If you really want to start using it more seriously (i.e. for more than just trees with the Previewer) you should probably get a good book such as Marc van Dongen’s LaTeX and Friends (Springer, 2012).

LaTeX Previewer and Trees

11