Using ShareLaeX to make rees Alan Munn September 2016 1 Introduction he ShareLaeX site http://sharelatex.com/ is a cloud-based LaeX system. LaeX is a complete typesetting system which converts a plain text document with embedded commands (called a source file) into a fully formatted PF document. he ShareLaeX site can be used to create complete documents using LaeX, but in se notes I will simply explain how to use it to produce PF (or or format) images that can be easily placed into or documents such as MSWord or Powerpoint. he advantage of this is that it can be used to quickly draw nice trees to include in Word or Powerpoint or Inesign documents without having to actually learn LaeX fully or install it on your own computer. In this guide I will explain how to use ShareLaeX to make nice trees. 1.1 Using ShareLaeX ShareLaeX is a free cloud-based document sharing system, very similar to Google ocs: you can create documents, save m in cloud and share m with ors and sync m with your ropbox folder, if you use ropbox. You sign up with your email address and n access site through any web browser, just like Google ocs. When you first open an ShareLaeX window, you should see something like following: ShareLaeX and rees 1
here are three main parts to this display: on lefthand side will be list of files/projects/- folders that you have created. he middle part is called source window, and this is where you enter actual code to generate your tree. he righthand part is preview window, and this shows output of compiled code. he first time you login to ShareLaeX it displays a sample source document, so your preview may look slightly different from image above. I have created a basic template document that you can use on ShareLaeX. Click on following link and it will lead you to document: LI 434 ree emplate. ow you are ready to input a simple tree into system. Copy code from template document and paste it into a new file source window, completely replacing any or text that might already be re. Listing 1: A simple document \documentclass[12pt,border=5pt,varwidth=true{standalone} \usepackage[1{fontenc} \usepackage[utf8{inputenc} \usepackage[{forest} \forestset{.style={for tree= {parent anchor=south, child anchor=north,align=center,inner sep=2pt}}} \begin{document} \begin{forest} [P [P [\\ [ [\\man [' [\\will [ [\\eat [P [\\a [ [\\burger \end{document} ow click on Recompile button, and you should see following: P P man ShareLaeX and rees 2 will eat a P burger
If all has gone well, you have successfully created your first tree. You can now download that tree as a PF file by clicking on ownload PF icon located beside Compile button and insert it as an image into your Word document. (See Appendix at end for how to do this.) ow that you ve created a simple tree, I ll explain a bit more how LaeX and forest notation works. 2 Some basic things to understand about LaeX For people who are used to using a word processor like Microsoft Word, idea that your source document is separate from your formatted document is a bit odd at first. he basic thing to understand about a LaeX document is following: Formatting is separated from content! Formatting should be associated with a semantics! In reality what does this mean? Well basically, if you want LaeX to format something a particular way, you should tell it what kind of thing it is (give it a semantics) and n associate formatting with kind rar than actual thing. Every LaeX document begins with a statement of what kind of document it is. his is \documentclass command. In example above, \documentclass has been set to standalone, which is a special class designed to make standalone images rar than full documents. his is best document class for purpose of making single images to be inserted into Word documents. he main font size of a document is set by document class itself, and is set by putting it in square brackets before {class-name} part of command. So first line in our sample document means Use standalone class with font size 12 pt. Although re are many basic things that LaeX can do, many useful things are implemented as separate packages. Each package is loaded separately in what is called preamble of document. Extra packages are loaded using \usepackage{} command. In sample document above, we are loading a few packages. he commands \usepackage[1{fontenc} and \usepackage[utf8{inputenc} load packages that are used to allow use of accented characters in your document, and you should generally always use m. ext we load forest packages. his is package that is needed to draw trees in LaeX. We n define a style within forest to make trees that look nice for linguistics. You should add all of se lines to every tree document you create. 3 ree notation he forest package allows you to enter a labelled bracketing of a tree and output a tree. he rules for forest bracketing are simple: (1) Bracketing Rules a. Every tree begins with \begin{forest} and ends with b. labels are suffixed to brackets; you can t have a space between a bracket and a label c. all brackets must be balanced, i.e., every left bracket needs a closing right bracket ShareLaeX and rees 3
Here, refore, is code for a simple tree, which produces output in (2b). (2) a. \begin{forest} [P [ [ [ [ [man b. P man One thing to notice in this tree is that re are branches between terminal nodes and ir labels. If you don t want this (and I generally don t, since labels are labels of words) you can include terminal as part of label by connecting two with a linebreak, which in LaeX is \\. ree (2) could n be coded as (3a) and appear as (3b). (3) a. \begin{forest} [P [\\ [ [\\man b. P man If you cut and paste this tree into your document (replacing everything between \begin{document}...\end{document}), and click on compile button, you should see following: If your display doesn t look exactly like one in picture because image in preview window is too small or too large, you can change size of preview to fit window eir by ShareLaeX and rees 4
height or by width. he buttons to do this are contextual and will appear if you move your cursor to top left corner of preview as shown below: 3.1 How to convert a tree to brackets It s helpful to understand how to convert a tree into a bracketed structure. he basic idea is that every node in tree gets a pair of brackets, and label for node is label for left bracket of pair. So you should draw your tree by hand and n starting from top, create brackets around beginning and ends of nodes. For sample tree shown above, we could do following. In this tree, I ve shown bracketing in red as well as tree. [ P P [ [ [ P P [ man [ will [ [ eat [ [ P P [ a [ [P [ burger [P [\\ [ [\\man [ [\\will [ [\\eat [P [\\a [ [\\burger 3.2 More forest commands he forest package can also make closed triangles for grouping nodes under a single node. For this you need to use add triangle command. Here is an example. he text you want to be under triangle is enclosed inside {...} as node label. his is n followed by a comma (which is important) and triangle command. (4) a. \begin{forest} [P [P [{ man with hat},triangle [ [\\will [ [{go to store tomorrow},triangle ShareLaeX and rees 5
b. P P man with hat will go to store tomorrow 4 Some useful latex commands In order to format text in a tree, it is necessary to be able to use a few LaeX commands. Almost all LaeX commands begin with a backslash (\) character. If a command takes an argument, argument is enclosed in braces ({}). Here are some basic commands that are useful for tree drawing. (5) Some useful LaeX commands a. subscripts, e.g. t i use t$_i$ b. superscripts e.g. t i use t$ˆi$ c. to start a new line in a label, use \\ d. to keep words toger as a group, enclose m 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$$) (o do this a lot, see Section 6 below for a better solution.) (6) Formatting commands a. to make font sans serif put \sffamily at beginning of 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 color to red precede it with \color{red} ShareLaeX and rees 6
5 Some examples Here are some examples of more trees. For large trees it s helpful to write out bracketed structure on separate lines with indenting to show partial structure. his will allow you to find mismatched brackets more easily (and you will mismatch brackets ) (7) a. \begin{forest} [P [P [\\ [ [\\man [ [\\might [ [\\expect [P [P [{ woman},triangle [ [\\to [ [ [\\leave [P [\\{\o} [ [\\town [PP [P\\after [P [\\ [ [\\party b. \begin{forest} [P [AdvP [Adv\\usually [P [P [\\{\O} [\\John [ [\\\emph{prese} [ [ [\\goes [PP [P\\to [P [\\ [\\park [PP [P\\on [P [\\{\O} [\\uesdays ShareLaeX and rees 7
c. \begin{forest} [P [P [\\Hanako [\\ga [ [ [CP [P [P [\\Yoshi [\\ga [ [ [P [\\Yuki [\\-o [\\mi [\\ta [C\\to [\\it [\\ta (8) a. P P might man expect P P woman to PP leave ø P town P after P party ShareLaeX and rees 8
b. P AdvP P Adv usually P Ø John PRESE PP goes PP P on P P to P Ø uesdays park c. P P Hanako ga ta CP it P C to P Yoshi ga Yuki P -o mi ta 6 Really advanced stuff LaeX can do all sorts of really amazing things, and is especially good for representing mamatics. We can use this facility to make even fancier trees, and also make shorthands for m. For example, as noted above, using square brackets in LaeX is complicated since square bracket is used for or things within LaeX itself. However, we can create a command which automatically puts ShareLaeX and rees 9
something in square brackets (useful for annotating nodes with features.) It requires amsmath package to be added to included packages. (9) 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 If you put this command in first line of your LaeX source, you can n add features to trees using \SB command, as in following example: (10) a. \newcommand{\sb}[1{$[\text{#1}$} \begin{forest} [P [P\SB{om} [\\ [ [\\man [ [\\will\\\sb{case:om} [ [\\left b. P P[om man will [Case:om left If we want to put a bunch of features in a list, we can use array command, and automatically expandable square brackets using \left[ and \right commands. Here is an example: (11) Feature bundle using an array a. $\left[\begin{array}{c} \text{ense}\\ \text{om}\\ \text{3psg}\\ \end{array}\right$ b. Output ense om 3PSg ShareLaeX and rees 10
7 More information hese are just some examples of what can be done with LaeX. hey are not intended to be a complete introduction to all of its power. here are plenty of good introductions to be found on web. For a very minimal introduction aimed at Mac users by me, see A Beginner s Guide to LaeX (on Mac). Anor more extensive guide also for linguistics is by Adam Liter and can be found here: LaeX workshop (for linguists). More general online books by icola albot can be found here: LaeX Books from ickinmaw Books. A very good printed book such as Marc van ongen s LaeX and Friends (Springer, 2012) might also be useful. Appendix How to insert PF images into MSWord documents Once you ve created your tree, you can easily insert it into a Microsoft Word document. On a Mac you can simply drag PF file onto your document or choose Insert Picture from File. On a PC you can choose Insert Object and n select Adobe Acrobat ocument and choose file. ShareLaeX and rees 11