0% found this document useful (0 votes)
119 views23 pages

Latex Workshop

Introduction to LaTeX (pronounced lah-tek), a new platform for source-code manipulation of text documents. Alternative to Microsoft Word and other word processing software.

Uploaded by

dponton
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views23 pages

Latex Workshop

Introduction to LaTeX (pronounced lah-tek), a new platform for source-code manipulation of text documents. Alternative to Microsoft Word and other word processing software.

Uploaded by

dponton
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

AT X Introduction to L E Dave Armstrong University of Wisconsin - Milwaukee Department of Political Science e: armstrod@uwm.

edu

Contents
1 Introduction and What A 1.1 Distribution of L TEX 1.2 Text Editor . . . . . 1.3 Ancillary Stu . . . .
A 2 The L TEX Document A 3 Typing in L TEX 3.1 Common and Useful Environments 3.1.1 itemize . . . . . . . . . . . . 3.1.2 enumerate . . . . . . . . . . 3.1.3 description . . . . . . . . . . 3.2 Text Size and Spacing . . . . . . .

You . . . . . . . . .

Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3 3 3 3 4

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

5 5 6 6 7 7 8 9 10 11 11 11 12 14 14 14 15 16 18

4 Tables and Tabular Material 4.1 Single-tables in the table environment . . . . . . 4.2 Using the subtable command for multiple tables 4.3 Making Tables More Easily . . . . . . . . . . . . 4.3.1 LaTable . . . . . . . . . . . . . . . . . . . A 4.3.2 Models from R into L TEX . . . . . . . . . A 4.3.3 Models from Stata into L TEX . . . . . . .

5 Figures and Graphics 5.1 The Figure Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Single Graphic Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Including Multiple Figures with subfigure . . . . . . . . . . . . . . . . . . . 6 Equations 7 BibTeX and Citations

8 Troubleshooting 9 Things We Didnt Cover

19 23

List of Tables
1 2 3 4 5 6 Percentage of ICPSR students using various statistical software packages session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Percentage of ICPSR students using various statistical software packages session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ICPSR Participants in 2001 and 2006 . . . . . . . . . . . . . . . . . . . . Table from LaTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Example tables from R . . . . . . . . . . . . . . . . . . . . . . . . . . . . Example tables from Stata . . . . . . . . . . . . . . . . . . . . . . . . . . by . . by . . . . . . . . . . 9 10 11 11 12 13

List of Figures
1 2 Normal Density over [-4,4], =0, =1 with more words to make the caption really long . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Three Normal Densities over [-4,4], =0, = a)1, b)5, c)10 . . . . . . . . . . 15 16

1
1.1

Introduction and What You Need


A Distribution of L TEX

For Windows, you could use: MiKTeX http://miktex.org/2.9/setup or proTeXt, which is a MiKTeX-based distribution that guides you through the installation process. TeXLive http://www.tug.org/texlive/ For Mac, you could use: MacTeX http://www.tug.org/mactex/, which is a TeXLive version for Mac. XeTeX http://www.tug.org/xetex/, which has additional font support. For Linux, you could use: TeXLive http://www.tug.org/texlive/
A In general, you can look here for advice on getting started with L TEX: http://www. tug.org/interest.html

1.2

Text Editor

A While you could use any text editor (including Notepad) for L TEX, there are many options A that come with built-in and easily customizable L TEX functionality. The Packages and programs section of this link: http://www.tug.org/interest.html#packages gives a number of free options. I also have had good luck with WinEdt on Windows (http://www.winedt. com/, $40 educational, $30 student) and TextMate (http://macromates.com/, $50, edA ucational). Many, though certainly not all, of the free L TEX editors provide environments A specic to L TEX. However, WinEdt, Textmate, TextWrangler/BBEdit, Emacs and others provide support for many environments (including R, Stata, Sweave, etc...). I would suggest TeXStudio (http://sourceforge.net/projects/texstudio/) for the beginners because it oers good syntax highlighting and some nice interactivity with citations. It is also quite customizable.

1.3

Ancillary Stu

Windows users would do well to install Ghostscript and Ghostview which are programs that facilitate working with postscript documents. These can be downloaded from here: Ghostscript: http://www.ghostscript.com/download/gsdnld.html Ghostview: http://pages.cs.wisc.edu/~ghost/gsview/get50.htm

Mac users will likely already have facility to work with these les. Youll also need a PDF viewer, like Acrobat, Foxit, Skim or Prview. Though you probably A already have one of these. It is worth installing L TEX, the postscript software and the pdf viewer before installing your text editor. Most of them will query the le system to nd where all of the necessary software is installed.

A The L TEX Document

A The L TEX document has two main parts - the Preamble and the Body. The Preamble sets up the document by including any packages that you might use, though you dont have to use all of the packages that you load. It also allows you to dene new commands and set properties of the document (like author, title, margins, header style, etc...).

\documentclass[12pt]{article} \usepackage{amsfonts, amsmath, amssymb, bm} %Math fonts and symbols \usepackage{dcolumn, multirow} % decimal-aligned columns, multi-row cells \usepackage{graphicx, subfigure, float} % graphics commands \usepackage[margin=1in]{geometry} % sets page layout \usepackage{setspace}% allows toggling of double/single-spacing \usepackage{verbatim}% defines environment for un-evaluated code \usepackage{natbib}% defines citation commands and environments. \usepackage{url}% allows including urls with \url{} field. \singlespace % set document spacing to single \bibpunct[, ]{(}{)}{,}{a}{}{,} % sets the punctuation of the bibliography entires. \newcolumntype{d}[1]{D{.}{.}{#1}} % defines a decimal-aligned column \title{Introduction to \LaTeX{}} % set the title of the document \author{Dave Armstrong \\ University of Wisconsin - Milwaukee \\ Department of Political Science} % set the author information use \and to include other authors

The Preamble is everything the between \documentclass[]{} and \begin{document}. The Body of the document is where all of the text and code that will be compiled by A L TEX goes. With few exceptions, the things you write in the preamble wont show up A in the document (except for the title commands). As you will see, L TEX is a language that treats text dierently depending on the environment. Environments are basically conA tainers for text that dene dierent ways of dealing with that text. In L TEX, dierent environments can be invoked with \begin{environment-name} and can be stopped with \end{environment-name}. These environments can be nested to produce specic output. In fact, all of the text were typing here is in the document environment, that we invoked with \begin{document} and will close after all of our writing is done with \end{document}.

A Typing in L TEX

Before we go extensively into some of the other material, there are a few hints that will A reduce some of the initial frustration of working with L TEX. First, if youre making pdf or picture (jpg, bmp, png) gures, youll want to typeset your document with pdflatex (this should be an option in whatever editor youre using). This typesets your document as a pdf. The other option, using latex, will produce a dvi le that will have to be converted either to ps or pdf (through ps). This option also requires ps or eps gures as input. When I say A L TEXthe document, generally I mean run pdflatex. \\ and \newline - both move whatever follows them to a new line. However, if there is no line to end, then you will get complaints about this. \newpage will put everything below starting on a new page. is the open double-quote symbol and '' is the closed double-quote symbol.

\section, \subsection and \subsubsection - all generate sequentially nested numbered sections. \section{Section 1 } \subsection{Subsection 1} \subsubsection{Subsubsection 1} will produce:

1
1.1
1.1.1

Section 1
Subsection 1
Subsubsection 1

Paragraph 1 \footnote{} puts a footnote with the text between the curly braces at the bottom of the page. You can use the package endnotes.sty to convert from footnotes to endnotes. See http://help-csli.stanford.edu/tex/latex-footnotes.shtml for more details.

3.1

Common and Useful Environments

A There are a number of useful L TEX environments that you will likely nd yourself using quite frequently.

verbatim is an environment that allows you to print commands that would otherwise be interpreted. This is useful for including statistical output in your document. This has its own environment for long segments of verbatim text: \begin{verbatim} and \end{verbatim}. It also has a command for verbatim text that ts on a single line: 5

\verb"" some text mod <- lm(y ~ x, data=dat) some more text mod <- lm(y ~ x, data=dat) Enumerate, Itemize and Description - all are items that give sequential bullet-like points. enumerate uses numbers and letters, itemize uses dierent character symbols, and description uses words to oset dierent items. 3.1.1 itemize

\begin{itemize} \item First bullet point. \end{itemize} First bullet point. 3.1.2 enumerate

\begin{enumerate} \item First bullet point. \end{enumerate} 1. First bullet point. You can also next enumerate environments, which would produce the following: \begin{enumerate} \item First item \begin{enumerate} \item First sub-item \begin{enumerate} \item First sub-sub-item \begin{enumerate} \item First sub-sub-sub-item. \end{enumerate} \end{enumerate} \end{enumerate} \end{enumerate} 1. First item (a) First sub-item i. First sub-sub-item A. First sub-sub-sub-item. 6

3.1.3

description

\begin{description} \item[First bullet] point. \end{description} First bullet point. You can also change the itemize symbol by putting the symbol you want it [ ] after the \item statement. \item[$\circ$] \item[$\bullet$] \item[$\star$] \item[$\blacklozenge$] \item[$\blacksquare$]

\item[\tiny{$\blacktriangleright$} ]

3.2

Text Size and Spacing

A Generally, it is not as easy to change font point sizes in L TEXas it is in Word or other word processing programs. However, there are a number of font sizes from which you can choose.

{\tiny tiny}

tiny

{\scriptsize scriptsize}

scriptsize

{\footnotesize footnotesize} footnotesize {\small small} small {\normalsize normalsize} normalsize {\large large} large {\Large Large} {\LARGE LARGE} {\huge huge}

Large

LARGE

huge {\Huge Huge} Huge


7

These can also dene environments (as in \begin{tiny} and \end{tiny}, with everything in between those two statements being printed in tiny text. Those of you who want to re-dene the pt. sizes of these various declarations, have a look here: http://xpt.sourceforge. net/techdocs/language/latex/latex32-LaTeXAndFonts/ar01s14.html. With the setspace package, you can use either \singlespace or \doublespace in your preamble to set the default for the document and then you can use either tag in the document to set spacing for a certain section. In general, if you set the default to \doublespace and use the \singlespace tag in the document, text will be single-spaced until the next \doublespace command is used. \doublespace Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-eld of that war. We have come to dedicate a portion of that eld, as a nal resting place for those who here gave their lives that that nation might live. It is altogether tting and proper that we should do this. \singlespace Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-eld of that war. We have come to dedicate a portion of that eld, as a nal resting place for those who here gave their lives that that nation might live. It is altogether tting and proper that we should do this.

Tables and Tabular Material

Tables and tabular material also go in their own environments. The tabular environment allows you to add tabular material. As you will see in the examples below, the ampersand (& ) separates the contents of each cell and every line has to be ended with \\. You will also notice in the tabular environment that you have to declare a justication for each column. For example, lets say we wanted a table with three columns, with the rst one left-justied and the other two aligned on the decimal point, you would invoke the tabular environment as follows: \begin{tabular}{ld{2}d{2}} A couple of things to note here. First, to use the decimal-aligned columns, you should put the following lines in your preamble:

\usepackage{dcolumn} \newcolumntype{d}[1]{D{.}{.}{#1}} the rst line loads the dcolumn package and the second creates a new column type, so rather than specifying D{.}{.}{2} for a decimal-aligned column with two decimal places, you can simply put d{2}. Another thing to note is that you dont necessarily need two decimal places A in each entry, this just tells L TEXto leave enough room for two decimal places. The table environment usually envelopes the tabular environment. The table environment adds a caption to tables and allows them to be referenced elsewhere in the text with labels. More on this later.

4.1

Single-tables in the table environment

\begin{table}[H] \caption{Percentage of ICPSR students using various statistical software packages by session}\label{tab:pack1} \centering \begin{tabular}{ld{2}d{2}d{2}d{2}} \hline & \multicolumn{4}{c}{Packages}\\ \hline & \multicolumn{1}{c}{R} & \multicolumn{1}{c}{SPSS} & \multicolumn{1}{c}{STATA} & \multicolumn{1}{c}{SAS} \\ \hline\hline Session 1 & 40.25 & 30.15 & 20.1 & 10.5 \\ Session 2 & 20.5 & 30.1 & 40.25 & 10.15 \\ \hline\hline \end{tabular} \end{table}

Table 1: Percentage of ICPSR students using various statistical software packages by session Packages R SPSS STATA SAS Session 1 40.25 30.15 20.1 10.5 Session 2 20.5 30.1 40.25 10.15 \begin{table}[H] \caption{Percentage of ICPSR students using various statistical software packages by session}\label{tab:pack2} \centering \begin{tabular}{l|d{2}d{2}d{2}d{2}} \hline 9

& \multicolumn{4}{c}{Packages}\\ \hline & \multicolumn{1}{c}{R} & \multicolumn{1}{c}{SPSS} & \multicolumn{1}{c}{STATA} & \multicolumn{1}{c}{SAS} \\ \hline\hline Session 1 & 40.25 & 30.15 & 20.1 & 10.5 \\ Session 2 & 20.5 & 30.1 & 40.25 & 10.15 \\ \hline\hline \end{tabular} \end{table} Table 2: Percentage of ICPSR students using various statistical software packages by session Packages R SPSS STATA SAS Session 1 40.25 30.15 20.1 10.5 30.1 40.25 10.15 Session 2 20.5 Typing Table~\ref{tab:pack1} will reference Table ??, and Table~\ref{tab:pack2} will reference Table ??.

4.2

Using the subtable command for multiple tables

\begin{table}[h!] \caption{ICPSR Participants in 2001 and 2006}\label{tab:subtab} \centerline{\hbox{ \subtable[2001]{ \begin{tabular}{lcc} & Men & Women\\ \hline Session 1 & 200 & 150 \\ Session 2 & 150 & 125 \\ \hline \end{tabular}\label{tab:subtab1}} \quad \quad \subtable[2006]{ \begin{tabular}{lcc} & Men & Women\\ \hline Session 1 & 250 & 200 \\ Session 2 & 175 & 150 \\ \hline \end{tabular}\label{tab:subtab1}}}} \end{table} 10

Table 3: ICPSR Participants in 2001 and 2006


(a) 2001 (b) 2006

Men Women Session 1 200 150 Session 2 150 125

Men Women Session 1 250 200 Session 2 175 150

To reference a subtable, simply put the \label{} inside the \subtable{} command, as above. Then, typing Table~\ref{tab:subtab1} will produce Table ??. Using \subref{} instead of \ref{} will print only the letter, rather than the letter and the number. For more advice on and example code for making tables, see: http://www.tug.org/ pracjourn/2007-1/mori/mori.pdf and http://mirrors.ibiblio.org/pub/mirrors/CTAN/ macros/latex/contrib/booktabs/booktabs.pdf.

4.3
4.3.1

Making Tables More Easily


LaTable

LaTable (http://zigzag00.blogspot.com/2010/08/latable-easy-way-to-write-tables-in. A html) is a stand-alone package that generates table code for L TEX. Tables are not hard to make, but sometimes can get cumbersome. LaTable is a WYSIWIG-like table editor that A produces L TEX code.

Table 4: Table from LaTable Model 1 Model 2 Intercept 1 2 X1 1 X2 -1 R2 .4 .4 Model 3 0 2 -2 .5

4.3.2

A Models from R into L TEX

In R, you could do the following: 11

> > > > > >

library(car) library(apsrtable) mod1 <- lm(prestige ~ income + type, data = Duncan) mod2 <- lm(prestige ~ income + education, data = Duncan) mod3 <- lm(prestige ~ income + education + type, data = Duncan) NA

> apsrtable(mod1, mod2, mod3) > NA

Table 5: Example tables from R Model 1 Model 2 Model 3 (Intercept) 6.70 6.06 0.19 (3.22) (4.27) (3.71) income 0.68 0.60 0.60 (0.09) (0.12) (0.09) typeprof 33.16 16.66 (4.83) (6.99) typewc 4.28 14.66 (5.55) (6.11) education 0.55 0.35 (0.10) (0.11) N 45 45 45 R2 0.89 0.83 0.91 2 adj. R 0.89 0.82 0.90 Resid. sd 10.68 13.37 9.74
Standard errors in parentheses indicates signicance at p < 0.05
A You can just cut-and-paste the output from R into L TEX. There are other options for tables of objects (not necessarily model output) such as xtable in the package of the same name and mtable in the memisc package.

4.3.3

A Models from Stata into L TEX

In Stata, do the following: use xi: est reg est xi: est "/Users/armstrod/Desktop/Duncan.dta" reg prestige income i.type store mod1 prestige income education store mod2 reg prestige income i.type education store mod3 12

Table 6: Example tables from Stata Model 1 Model 2 Model 3 Income Professional White Collar Education Constant 0.676 (7.21) 33.156 (6.86) 4.277 (0.77) 0.598 (6.69) 16.658 (2.38) 14.661 (2.40) 0.546 0.345 (5.56) (3.04) 6.704 6.065 0.185 (2.08) (1.42) (0.05) 0.599 (5.00)

Then, issue the following command: estout mod1 mod2 mod3 using "~/Desktop/latexumd/statamods.tex", style(tex) cells(b(star fmt(3)) t(par fmt(2))) starlevels(* .05) replace label collabels(, none) varlabels(_cons Constant income Income _Itype_2 Professional _Itype_3 "White Collar" education Education) posthead("") prefoot("") postfoot("") varwidth(16) mlabels("" "" "") This will put your table in the le statamods.tex and will print it to the screen (from which A you could just copy and paste into your L TEX le), or you could do the following: \begin{table} \caption{Example tables from Stata}\label{tab:Statatab} \centering \begin{tabular}{ld{3}d{3}d{3}} & \multicolumn{1}{c}{Model 1} & \multicolumn{1}{c}{Model 2} & \multicolumn{1}{c}{Model 3}\\ \hline \input{statamods.tex} \hline \end{tabular} \end{table}

13

Figures and Graphics

The graphicx package allows for the inclusion of many types of graphics including .ps, .eps, .pdf, .bmp, .jpg, .wmf, and doubtless others as well through the \includegraphics command.

5.1

The Figure Syntax

The figure environment allows graphics to be included, titled with a caption and automatically numbered. Graphics can be included without putting them in the figure environment, but cannot then be titled with automatically numbered captions. The command for including a graphic is \includegraphics[options]{filename} (note the s, not x). Some useful arguments or options for \includegraphics are: width, height scale the width and height to the values (e.g., [height=2in, width=1in]) scale scales the image by the given amount. keepaspectratio preserves the aspect ratio of the original gure angle angle of gure rotation (degrees counterclockwise). It is easiest to put graphs in the directory where your document is. That is where A L TEX is going to look for them by default. However, there is a command you can put in the preamble: \graphicspath{{dir1}{dir2}{dir3}...}. However, 1. dir1 must be a Unix-style path C:/graphs/ not C:\graphs\
A 2. L TEX doesnt like spaces in the directory names, so the directories may not have spaces in them.

5.2

Single Graphic Figures

\begin{figure}[h!] \caption{Normal Density over [-4,4], $\mu$=0, $\sigma$=1 with more words to make the caption really long}\label{fig:onefig} \centerline{\includegraphics[width=2.5in]{norm1.ps}} \end{figure}

Now, without the figure environment:

14

Figure 1: Normal Density over [-4,4], =0, =1 with more words to make the caption really long
0.4 0.0 4 0.1 0.2 0.3

0.0 4

0.1

0.2

0.3

0.4

I can reference Figure ?? with Figure~\ref{fig:onefig}.

5.3

Including Multiple Figures with subfigure

\begin{figure}[h!] \caption{Three Normal Densities over [-4,4], $\mu$=0, $\sigma$= a)1, b)5, c)10}

\centerline{\subfigure[$\sigma$=1]{\includegraphics[width=.3\textwidth]{norm1.pdf}} \quad \subfigure[$\sigma$=5]{\includegraphics[width=.3\textwidth]{norm2.pdf}}} \centerline{\subfigure[$\sigma$=10]{\includegraphics[width=.3\textwidth]{norm3.pdf}}} \end{figure} 15

Figure 2: Three Normal Densities over [-4,4], =0, = a)1, b)5, c)10
0.080 4 2 0 2 4 0.060 0.0 4 0.065 0.070 0.075 0.4 0.1 0.2 0.3

(a) =1

(b) =5

0.0370 4

0.0380

0.0390

0.0400

(c) =10

See ?, Chapter 6 for more information on controlling and customizing the appearance of oats.

Equations

A To me, the big advantage of L TEX is that you can type equations, rather than hunting and pecking through some pull-down menus. Youll notice that once youve become familiar with the symbols you need (and there are relatively few of them), it is much faster to type than peck through menus. If you want a list of common symbols and how to make them, look here: http://web.ift.uib.no/Teori/KURS/WRK/TeX/symALL.html I have prepared some example equations below, so you can see how things work. There are two environments that may be useful here. The equation environment allows you to type single equations and the align environment allows you to type multi-line equations where you can control the center-point of each line. Lets start with something relatively simple:

\begin{equation} y_{i} = b_{0} + b_{1}x_{i} + \varepsilon_{i}\label{eq:linreg} \end{equation} 16

yi = b0 + b1 xi + i Typing equation~\ref{eq:linreg} will refer to equation ?? Using the equation* environment will suppress the equation number \begin{equation*} \hat{\beta} = \left(\mathbf{X^{\prime}X}\right)^{-1}\mathbf{X^{\prime}Y} \end{equation*} = (X X)1 X Y, but so would doing the following: \begin{equation} \hat{\beta} = \left(\mathbf{X^{\prime}X}\right)^{-1}\mathbf{X^{\prime}Y}\nonumber \end{equation} = (X X)1 X Y,

(1)

To ensure that parentheses and other delimiters are big enough to accommodate fractions and sums, you can use the \left( and \right) which will make the parentheses big enough to completely cover the expression inside them. \begin{equation} \bar{X} = \left(\frac{1}{n}\right)\sum X \end{equation} 1 n

= X

(2)

In general, \left\{, \left(, and \left[, will produce curly braces, parentheses, and square brackets that are the appropriate size for the expression. They are oset by their \right\}, \right) and \right] counterparts. The align environment lines multi-line equations up wherever you put the ampersand on each line. For example, \begin{align} x + 11 &= 3\\ x &= 3-11\\ x &=-8 \end{align} 17

will produce x + 11 = 3 x = 3 11 x = 8 (3) (4) (5)

Note that to align the equations on the equal sign, you can simply place the ampersand before the equal sign in each equation. Also note that you need the \\ and the end of each line. Using \nonumber (before the \\) will shut the equation number o for that particular line, but will leave other equation numbers intact. You can include math symbols in in-line text by using $ $ as follows: The matrix algebra generating regression coecients is (X X)1 X Y, which was obtained as follows: $\left(\bm{X}^{\prime}\bm{X}\right)^{-1}\bm{X}^{\prime}\bm{Y}$.

BibTeX and Citations

A To use BibTeX, you will need to make an appropriate bibliography le and then tell L TEX how you want those citations to show up in the document. I use the natbib package, but others (like harvard) exist as well. In fact, the le necessary for making APSR-style bibliographies is in the harvard package, so having the harvard package around is not such a bad idea. The .bib le is where you store all of your references. I would suggest that you have one master .bib le where all of your references are stored and BibTeX will simply take out the ones it needs each time. The particulars for doing this are dierent depending on your operating system.

On the mac, you can simply place your bibliography le in the following folder: ~/Library/texmf/bibtex/bib/ and or usr/local/texlive/2012/texmf-dist/bibtex/bib| regardless of where your document is, it will look in this folder for your bibliography le. Otherwise, it will look in the directory where your document lives. On the PC, using MikTeX, you can put your bibliography le in: C:\Program Files\Miktex 2.9\bibtex\bib\, C:\Program Files\texlive\2012\texmf-dist\bibtex\bibitem (or use the appropriate path to where MikTeX lives). Otherwise (generally if you dont have write permission to that drive), use the following to guide you through the process of setting up a local tex directory structure and putting your bibliography le there: http://docs.miktex.org/manual/localadditions.html. On a Linux machine, I suspect, though dont know for sure, that the solution is quite similar to the mac. This .bib le is a at text le that has a series of lines for each entry of the following type.1
1

See ?, Chap. 13 for more details on Bibliography generation.

18

olatex

I just compiled my .bib le by typing my references in a le in this format. However, there are some BibTeX front-ends that make it easier to manage bibliographies. One of the most popular is a java-based program called Jabref (http://jabref.sourceforge.net/). There are other options, like Papers (if you dont mind spending $80 for a polished piece of software) or Bibdesk if youre on the Mac. If youre just getting started, this a good way to begin. If youre using natbib, the documentation is quite useful, but here are a few example citations: \citet{MG2004} produces ? \citep{MG2004} produces (?) \citep[See][251]{MG2004} produces (See ?, 251) \citeyearp{MG2004} produces (?)
A A A Remember the sequence: L TEX, BibTeX, L TEX, L TEX, you have to do this to get the references to appear. In fact, there are lots of times you have to typeset the document more than once because it takes a couple of times for references to resolve and get printed back into the document. So, if something doesnt show up the rst time, just try typesetting the document again. I wont have time to go into this, but there is a utility called latexmk which is a highly-congurable piece of software that automatically typesets your document, including running BibTeX (and other ancillary programs) enough times to resolve all crossreferences. If youre using TexStudio or TextMate (and presumably some others, too), you can specify that you want the entire chain of commands to be run that will resolve all (cross)references. In TextMate, go into the Preferences panel in the LaTeX bundle and check the use latexmk.pl check box. In TeXStudio, go to Preferences (on the Mac) or Options Congure TeXStudio (on Windows). Click the check box for Show Advanced Options. Then, click on the Build link in the left-hand panel. By Build & View, click the down arrow in the text box and choose |txs:///pdf-chain. Then, when you click the Build & View button, it will do everything needed to typeset the pdf. Then, just type \bibliography{bibname} where bibname is the name of your bibliography (.bib) le without the .bib extension. For example, I used \bibliography{latex} for this document because I stored the references above in a le called latex.bib.

Troubleshooting

When you are typesetting a document, generally some sort of console window will appear that will show you the progress of the typesetting endeavor. When you encounter an error, the WinEDT console (though this diers across software) will ask for user input with ?. If A you type r at the question mark, then L TEXwill try to recover from the error and produce 19

something. It may produce something that looks ne and it may not. If you type q at the A question mark, L TEXwill quit and allow you to x the error. A One of the most common ways to generate an error is to not close a delimiter (that L TEXis expecting to be closed). This doesnt so much matter for parentheses or other delimiters that you might use in prose, but matters a lot for things like environments and delimiters within mathematical expressions (though not always). Another common mistake is excluding a le A that L TEXthought it should nd. A few examples should clarify:

20

Here, I forgot to close the \begin{itemize} with \end{itemize}. Notice that the error is actually quite informative, it suggests where the error occurs (1.10 means that it encountered the error on line 10 of the document), but the error indicates that the problem started with the tag on line 5 not being closed.

Here, I forgot to close a math delimiter. I forgot to put a closing dollar sign. Notice A that the error suggests the problem and identies that L TEXwill try to solve it by inserting the dollar sign.

21

A Here, I forgot to include a gure that L TEXexpected to be in the same directory as A A my le. Notice that LTEXtells me that the le is missing. Typing r will allow L TEXto continue with a stand-in for the missing gure.

Here, I used a bib le that didnt exist. Look at the <<filename>>.blg to diagnose problems with the BibTEXrun.

22

Here, I used a citation that didnt exist in a le that does exist. Again, the <<filename>>.blg helps diagnose the problem.

Things We Didnt Cover

There are a number of things we didnt cover that I would be happy to talk with people about in smaller groups or individually as there is interest: Sweave (http://www.stat.uni-muenchen.de/~leisch/Sweave/), which is a method A for integrating R into your L TEXdocument to ensure perfect reproducibility of your results and to keep your statistics code and writing in the same place.
A Presentations in L TEX. There are a number of tools for making high-quality presenA tations in LTEX. The one I use is called Beamer (https://bitbucket.org/rivanvx/ beamer/wiki/Home)

Games (normal and extensive form) can be made with Martin Osbornes egameps.sty le. You can get information about those here: http://ctan.org/tex-archive/ macros/latex/contrib/egameps/ or http://www.drewdimmery.com/extensive-form-game-trees

23

You might also like