Writing Papers in LATEX Pomona Ling/CogSci February 13, 2016

1 Introduction The purpose of this document is to give you a brief introduction to LATEX in a way that is hopefully accessible. On my website there is a large variety of links to relevant resources, but many of those can be intimidating because they offer too much information at once. This introduction is meant to give step-by-step instructions to people that don’t know anything about LATEX, and particularly written for people who may be somewhat intimidated by the prospect of learning new computer-related things. The short story is that this is accessible and achievable for all our LGCS students, and hopefully these instructions will help you take the leap if you want to start using LATEX. It does require some patience as you learn, but this is wholly within reach. Roadmap:

Section 2 Section 3.2 Section 5 Section 6 Section 7 Section 8 Section 9 Section 10 Section 11

Where and how to access LATEX Using packages: The preamble Numbered examples and glossed examples Using cross-references Using IPA fonts Inserting footnotes Miscellanea Drawing trees Citations with BibTeX

2 Where and how to access LATEX In many ways LATEX is like familiar word processors (like Microsoft Word) because it is a typesetting program that takes input via a keyboard and produces a document that can be printed on paper. There are important differences, though. In LATEX you directly annotate your writing to tell the computer how to format it, so if you want to write something in italics you write something that includes curly brackets and backslashes: \textit{italics}, and if you want something bolded you write \textbf{bolded}. LATEX then converts that ‘code’ into what looks like italics and bold. Another difference is that LATEX is more similar to the code that makes Microsoft Word run, rather than Word itself. LATEX doesn’t come with a user interface, and instead people have created many different sorts of apps to access and use LATEX. Some ways to work in LATEX: • The online LATEX previewer is restricted in what it can do, but if you are just drawing some basic trees or equations it is a quick-start way to start working with LATEX. The previewer allows you to preview what you wrote and download the images (or screenshot them), which can be inserted into a document you are working on in Microsoft Word (or a similar app). There are other similar things (often referred to as equation editors) that are available online or downloadable for Mac/PC. Access the LATEX previewer at http://www.tlhiv.org/ltxpreview/. 1

• Overleaf (https://www.overleaf.com) is a cloud-based LATEX editor that makes it quicker and easier to start writing in LATEX. It has limitations and full access requires a subscription, but the free accounts at present are probably sufficient for a lot of student work. • If you want to install TEX on your own computer, you can download the distribution for Windows here (http://miktex.org) and for Mac here (http://www.tug.org/mactex/). • I believe that both of the TEX distributions come with editors (i.e. apps to do your writing in) for creating LATEXdocuments. There are a wide variety available online for free, however. I know people who have used TeXShop, TeXstudio (which I’m currently using), Emacs, Overleaf, and Latexian, but there are a wide variety of others for you to explore if you want to. • Installing TEX on your own machine comes with benefits and challenges. I recommend using Overleaf at first, at least, if you find tracking down the software intimidating.

3 Core structure of a document 3.1 Compiling and printing While you don’t need to understand many technical details about LATEX in order to use it, you DO need to understand some broad conceptual things. First, what you write in LATEX looks like computer code (or maybe more like HTML) in the sense that your text is marked up with commands (that usually start with a backslash \). These commands tell LATEX to format your document in a specific sort of way. The document you write in is basically a text file consisting of simple text and coding, which gets saved as a .tex file. The .tex file is what you edit when you write. What you type into a LATEX editor then needs to be compiled, or processed, by LATEX itself to turn it into a formatted document. Different editors have different buttons/keystrokes that start this compiling process, and they usually then produce a preview of your formatted document, which you can then download or convert to a PDF document.1 It is recommended that you compile your document frequently, so that if you made an error in your coding you don’t have too much to look back through to find your error. Some editors (like Overleaf) will do this automatically for you, but you can do it yourself in any LATEX editor. So bolded or italic fonts are written via the commands \textbf{bolded} and textit{italic}, and when a document is compiled it converts the code with backslashes and brackets into the relevant visual images. This handout has been distributed in both .tex and .pdf files, so you can compare those two to see how this document itself was written in LATEX.

3.2 Using packages: The preamble At the top of every single LATEX document is what is called a preamble, where you tell LATEX how to format what you write in your document. First you declare what the class of your document is (for assignments for Pomona LGCS this will be an article, as shown in the example below). 1 In fact, when you compile a .tex file the LAT X editor usually auto-generates a collection of files on your computer that are saved E alongside the .tex file (if you are working on your machine and not on an online cloud service like Overleaf). Depending on how your LATEX editor is set to compile, it may generate a .pdf file, a .ps file, a .dvi file, a .aux file, and a .log file. Until you know more about LATEX you won’t need to do anything with these other files. For now you need to know that you edit the .tex file and the .pdf file is your formatted document.

2

(1)

\documentclass{article} \usepackage{gb4e} \usepackage{times}

Notice in (1) that there are two packages declared as well: gb4e (which allows you to format numbered examples, like the one above) and times, which puts the document in times font. This is a central feature of how LATEX works. The basic software itself can do many things, but not everything, so people have created add-ons, sort of like plug-ins or browser extensions, which allow LATEX to do the extra things they want LATEX to be able to do. These add-ons are called packages. The preamble for the LATEX document that created this handout includes the commands shown in (1) in the preamble, but also includes additional packages (some of which we discuss below).

3.3 Necessary commands The rest of this document outline some of the major kinds of packages and commands that will be useful for you to write Pomona LGCS papers. Every single package that exists for LATEX comes with documentation online that lays out what the package does, and how to use it. You can find most of these by googling “latex [package name]”, or by searching through LATEX sites like CTAN, TUG, or stackexchange. Every LATEX document you will write must have a preamble at the beginning where you declare the document class, declare any packages you will use, and most likely give the title/author/date. Then the document has a main body, which is demarcated with the commands \begin{document} at the beginning, and \end{document} at the end. In the example below I’ve shown a portion of the preamble and first section of this handout. (2) Example of preamble and core structure of a document \documentclass{article} \usepackage[top=1in]{geometry} \usepackage{gb4e} \usepackage{times} \usepackage{hyperref} \title{Writing Papers in \LaTeX} \author{Pomona Ling/CogSci} \date{\today} \begin{document} \maketitle \section{Introduction} ... lots of code follows here that makes up the handout... \end{document}

LATEX for some reason (probably a great one that I just don’t know) has you declare the title, author, and date in the preamble, and then at the beginning of the document you tell LATEX to create the title with 3

the command \maketitle, which comes in the document immediately after the \begin{document} command. Of course, in this document many sections and subsections come after Section 1, the Introduction. The sections of the handout that follow talk about some basic tools you need to construct a document for Pomona LGCS. See MJKD’s TEX site for some sample .tex documents that you can play around with to see how preambles are structured and documents are structured.

4 Sections and subsections 4.1 These 4.1.1 are 4.1.2 levels of

4.2 subsections In the course of writing a paper you will need to demarcate sections via headers. This is accomplished with a few straightforward commands: \section{}, \subsection{}, and \subsubsection{}. (3) The code that generated the section headers in this section. \section{Sections and subsections} \subsection{These} \subsubsection{are} \subsubsection{levels of} \subsection{subsections} LATEX auto-numbers sections for you, so when you add sections or take away sections LATEX will renumber the sections appropriately when you compile the document. You may find yourself wanting to refer to section numbers in your text (like I will right now) - section 6 describes how to do this.

5 Numbered Examples and Glossed Examples Linguistics papers of various sorts refer to data, figures, and charts via numbered examples. (4) This is a numbered example. (5)

a. This is a numbered example with a tree. b. TP VP

NP this example

V is

NP a tree

4

Numbered examples are handy for organizing figures and data for readers, and especially handy for crossreferencing as you go along. I recommend the package gb4e for examples in your papers - to use it, be sure to include the package in the preamble with the command \usepackage{gb4e}. To create a numbered example, then, you open the example environment with the command \begin{exe}, and when the example or examples are completed, you close the example enviroment with the command \end{exe}. Each numbered example is introduced with the command \ex. The example below is the code that creates examples (4) and (5) above, with the actual code for the tree omitted for now. (6) \begin{exe} \ex This is a numbered example. \ex \begin{xlist} \ex This is a numbered example with a tree. \ex \end{xlist} \end{exe} As you can see above, multiple (lettered) examples within a single numbered example are created using an xlist environment inside an example created with the command \ex. The gb4e package is also useful for non-English examples, allowing for examples that include inter-linear glosses and translations like the Lubukusu sentence in (7): (7) Peter se-a-la-ba a-kula sitabu ta. Peter NEG-SA-TNS-be SA-buy book NEG ‘Peter will not be buying a book.’

Lubukusu

The example in (7) is generated with the code that is given in (8) (with some non-essential formatting details removed to simplify things visually for you). Crucially, the language and glossing lines are introduced with the \gll command, with a line break \\ to separate them. gb4e uses whitespace to align words, so put one space between each word in the language line, and one space between each word in the gloss line, and LATEX will auto-align the glosses for you. (8) \begin{exe} \ex \gll Peter se-a-la-ba a-kula sitabu ta. \\ Peter NEG-SA-TNS-be SA-buy book NEG \\ \glt ‘Peter will not be buying a book.’ \end{exe} The translation line is introduced with the command \glt, with no line break at the end of the translation.

6 Using cross-references It is very useful to be able to refer in text to numbered examples or section numbers: for example, I may want to tell you that examples (4) and (5) are built using gb4e. There are two components of a cross-reference in 5

text. First, you must label a particular section or example that you intend to refer to, and second, you must then code the cross-reference itself. So, the code for the header of this section is what is shown in (9), where a label is declared using the command \label{label.name.here} (where you choose what you want to name the label). (9) \section{Using cross-references} \label{crossreferences} Sometimes you may want to refer to a section in your writing, for example, by saying that we are currently in Section 6. This cross-reference is produced with the \ref{label.name.here} command. The example below shows how the underlined portion of the previous sentence was coded. (10) we are currently in Section \ref{crossreferences}. Notably, you can only use the \ref{} command with labels that are already established - attempting to build a cross-reference to a label that is not already declared will not stop your document from compiling, but it will result in question marks where the cross-reference out to be, like this: (??). Labeling for numbered examples works in exactly the same way as for section headers. So, with an example like (11), the example in (11a) is generated via the code in (11b): (11)

a. A numbered example with a label b. A numbered example with a label \label{labelsample}

Having labeled the numbered example in (11a), then, we can refer to it easily with the command \ref{labelsample} put into parentheses. So, the underlined portion of the preceding sentence was coded: (12) the numbered example in (\ref{labelsample}) These kinds of cross-references are auto-generated as references to example numbers and section numbers every time you compile your document. You will never have to renumber examples in your document again.

7 Using IPA fonts with tipa • There are a variety of ways to incorporate IPA symbols into your .tex document. Some typesetting engines associated with TEX allow inserting unicode IPA fonts directly into .tex files, but this complicates matters a bit, so for now we suggest using the package tipa to insert IPA symbols. • To use tipa, first be sure to include the command \usepackage{tipa} in your preamble, so that LATEX knows to use the tipa package when compiling your document. The tipa package tells LATEX to take a short command that you type and turn it into an IPA symbol in your formatted document. So, when I type \textipa{B} it appears in text as B. likewise, typing \textipa{J} yields J, and \textipa{\!o} yields ò. • The tipa documentation provides a full explanation of how tipa works, and MJKD’s website links to a straightforward chart detailing the commands for most IPA characters.

6

8 Inserting footnotes It is relatively straightforward to add footnotes to your text using the \footnote{footnote.text.here} command. So this sentence now comes with a footnote. 2 The underlined sentence+footnote was coded like this: (13) So this sentence now comes with a footnote.\footnote{This is a footnote.} And as you can see, the footnote is auto-generated at the bottom of the page when the document compiles.

9 Miscellanea 9.1 Comments If you are familiar with computer code then you are familiar with commenting, which is when you introduce lines of text or code in your .tex file that does not have any effect: for LATEX this means that commented material does not show up in the .pdf file when the .tex file is compiled. So what is not evident in this .pdf, for example is that between this paragraph and the subsection header is the text that is in the example below: (14) %I can write whatever I want here %and it won’t show up in the formatted document %when it compiles, because it is commented out. It does not show up, however, because the % at the beginning of each line signals that that line won’t appear when the .tex document is compiled. So you can use comments to leave yourself notes in your .tex file, or remove parts of your paper without deleting it, or whatever.

9.2 Potentially useful symbols One minor downside to using LATEX is that some basic formatting and symbols that you are used to having a convenient button for in Microsoft Word (like, say, underlining or italics) can take a moment to figure out how to code in LATEX. This subsection has a few major sorts of formatting that you might want to use. MJKD’s TEXpage on his website can point you to some additional resources that you might find useful. 2 This

is a footnote.

7

(15) Name

Example

Code

Null Theta Phi Hash Trace Ellipsis Subscript Superscript Bold Italic Small Caps Degree symbol Bar-level node

∅ θ φ # t ... NPi NPi bold italic

$\emptyset$ $\theta$ $phi$ \# $t$ \dots NP_i NPˆi \textbf{bold} \textit{italic} \textsc{small caps} X$ˆ{\circ}$ X\1

SMALL CAPS

X◦ X′

Most of these can be used in all places in LATEX. Some of are restricted to a \Tree environment (that is, when drawing trees in qtree, e.g. the bar-level node for X′-syntax).

9.3 ulem for underlining/emphasis Details coming later. The brief note is to say that for some forms of underlining/emphasis you need an additional package. I have been using ulem with relative success, so I recommend it at present.

9.4 Some final notes Note that some symbols that you might want to type–like %, #, &, and $–all mean something in LATEX coding, so if you type them directly into your text you will get an error. Adding a backslash before such a symbol is often the trick to getting it to appear in the text. So in the previous sentence I wrote these as \%, \#, \&, and \&, and LATEX formatted them to the form that you see in that first sentence.

10 Drawing trees For first-level LATEX users, we recommend using the package qtree to draw trees, and the package tree-dvips to draw arrows and other kinds of annotations on trees. In this handout we don’t spend time explaining how to draw trees, because this is laid out in multiple other handouts that we have developed for Pomona LGCS and are accessible on MJKD’s website.

11 Citations with BibTeX Details coming later.

8