Writing Finance Papers Using L TEX: Stanton@haas - Berkeley.edu

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

AT X Writing Finance Papers Using L E Richard Stanton June 19, 2012, 15:24

RS: Notes like this appear throughout the document and are created using the todonotes package (see Section 5.6).

Abstract This document provides some recommendations for eciently writing nance paA pers using L TEX and related tools, based on techniques that have made me more A productive over the years. It also contains the necessary L TEX style les and BibTEX format les (along with sample paper outlines) for making your paper and bibliography match the formats required by the Journal of Finance, Journal of Financial Economics, and Review of Financial Studies. The source le, texintro.tex, and various additional included les are important parts of this document.

RS: Including the current time helps to locate the latest printout in that huge pile on your desk when you create many versions of a paper during the day (see datetime package, Section 5.7).

Comments and suggestions on this document are welcome. I am grateful to Jennifer Carpenter and Johan Walden for valuable input (even if some of it was inadvertent). I am also grateful to Tobias Oetiker for writing the example environment, which I use liberally in this document. INCLUDES NOTES. Haas School of Business, U.C. Berkeley, 545 Student Services Building #1900, Berkeley, CA 94720-1900, phone: 510-642-7382, fax: 510-643-1412, e-mail: [email protected].

RS: I like to have this on the front page to reduce the likelihood that the paper will go back to the journal complete with all my insulting comments about the referee.

Contents
1 Introduction
A 2 Installing L TEX

3 4 8 8 8 9 9 9 9 10 10 11 12 12 12 13 13 13 13 14 16 16 17 19 19 20 21 22 22 23 24 26 27 28 29 29

RS: Every entry in the table of contents is a clickable hyperlink (see hyperref package, Section 5.10)

3 Entering Text 3.1 Spaces and line breaks . 3.2 Sections and subsections 3.3 Emphasizing text . . . . 3.4 Tables . . . . . . . . . . 3.5 Figures . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

4 Entering Mathematical Expressions 4.1 Inline versus displayed expressions (unnumbered) 4.2 Numbered equations . . . . . . . . . . . . . . . . 4.3 Spacing in mathematical expressions . . . . . . . 4.4 Long equations . . . . . . . . . . . . . . . . . . . 4.5 Text inside mathematical expressions . . . . . . . 4.6 Brackets . . . . . . . . . . . . . . . . . . . . . . . 4.7 Arrays . . . . . . . . . . . . . . . . . . . . . . . . 4.8 Dening new operators . . . . . . . . . . . . . . . 4.9 Theorems, etc. . . . . . . . . . . . . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

A 5 Useful L TEX Packages 5.1 Installing packages . . . . . . . . . . . . . . . . . . . 5.2 Changing line spacing: setspace . . . . . . . . . . . 5.3 Including gures: graphicx . . . . . . . . . . . . . . 5.4 Mathematical typesetting: amsmath . . . . . . . . . . 5.5 Setting page margins: geometry . . . . . . . . . . . . 5.6 Inserting notes: todonotes . . . . . . . . . . . . . . . 5.7 Printing date and time: datetime . . . . . . . . . . . 5.8 Multiple versions from one le: versionPO . . . . . . 5.9 List formatting: enumitem . . . . . . . . . . . . . . . 5.10 URLs and hyperlinks: hyperref . . . . . . . . . . . . 5.11 Landscape and subgures: rotating and subfigure 5.12 Other useful packages . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

6 Citations and Bibliographies 6.1 BibTEX . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 The BibTEX database . . . . . . . . . . . . . . . . . . 6.3 Telling BibTEX where to nd the database . . . . . . . 6.4 Formatting the bibliography: natbib and custom-bib

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

7 Journal-Specic Document Formatting 7.1 Formatting the bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Formatting the text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Working with Others: Version Control Systems 8.1 Public hosting of DVCS repositories . . . . . . . . . . . . . . . . . . . . . . . 8.2 This projects Bitbucket repository . . . . . . . . . . . . . . . . . . . . . . .

30 31 31 32 34 34

Introduction
A RS: By default, L TEX sets huge margins. Customize them easily using the geometry package (see Section 5.5).

A L TEX is a document typesetting system, based on Knuths program TEX (see Knuth, 1984), which makes it relatively simple to produce papers with high-quality equations and errorfree cross-references to equations, tables, and gures, and to handle creation and formatting of bibliographies and citations.1 This document explains the basics of installing and using A L TEX to produce high-quality papers,2 and presents a number of suggestions for tools and techniques that make me more productive when I write papers, along with instructions and sample les for formatting your papers to match the requirements of the Journal of Finance, Journal of Financial Economics, and Review of Financial Studies. A This document is not intended to be a comprehensive overview of L TEX. If youre starting from scratch, one very popular reference, free to download, is the Not So Short Introduction A to L TEX 2 (Oetiker, Partl, Hyna, and Schlegl, 2011). There are also some excellent books A on L TEX. Standard references include Lamport (1994), written by the original author of A L TEX; Kopka and Daly (2003), a more recent, popular introductory text; and Mittelbach, A Goossens, Braams, Carlisle, and Rowley (2004), an excellent reference on both L TEX itself A and many of the additional packages that have been created since L TEX was created (the 3 A authors of this book are some of the main developers of L TEX). A Creation of a document using L TEX is a two-step process: A 1. Create a L TEX source le, usually with the extension .tex, containing your text plus A commands that tell L TEX how to format your document.4 2. Process the .tex le to create the nal PDF le.5

RS: Section 6 deals with creating citations and bibliographies using BibTEX.

Plenty of people use word processors for writing papers instead. This makes no sense to me, but rather than engage in a debate, Ill just note that if you use Word this document is probably not going to be very useful to you. 2 Im talking about the quality of the typesetting here. The intellectual quality is up to you. 3 A I own and refer to all of these books, especially Mittelbach et al. (2004), and I originally learned L TEX from Lamport (1994). You can also nd other references at http://www.ctan.org/starter.html. However, I nd that nowadays I use Google more than any other reference. 4 A For example, the source for this document is called texintro.tex. Unlike word-processor les, L TEX les are plain text, with no special control codes. This makes them easily portable from one machine (or architecture or OS) to another, easy to view using any plain-text le viewer, and also means that you stand a decent chance of being able to rescue a lot of your material if the le accidentally gets corrupted, say by a misbehaving word processor or a disk failure. Not that les get corrupted all that often, of course, but just in case, its nice to know. This also makes it easy to keep track of your work using a Version Control System (see Section 8). 5 Before PDF became standard, it was usual for the .tex le to be processed to a .dvi (Device Independent) le, which was then further processed to a printable format using a printer-specic executable (e.g., dvips for Postscript or dvilj for an HP Laserjet). To create a PDF le, you would 1) run latex to create a .dvi le, 2) run dvips to convert the .dvi le into a Postscript le, and 3) run Adobe Distiller (or Ghostscript) to convert the PS le to PDF. Nowadays this is usually done in one step (using the pdflatex program behind the scenes). Yes, I know you still insist on using dvips, Johan, though I have no idea why. . . .

A RS: By default, L TEX inserts more space between list items than this (see enumitem package, Section 5.9).

A For example, here is an extremely simple L TEX le (the text after % on each line is just A a comment; it is ignored by L TEX):

\documentclass{article} \begin{document} This is my first paper. \end{document}

% % % %

Tell LaTeX to use the "article" style Document starts here Text Document ends here

A If you process this le using L TEX, it produces the following PDF le:6

This is my rst paper.

A While simple, this document shows the structure of every L TEX source le. The part of the document before \begin{document} is called the preamble. In this case, it contains just the single line

\documentclass{article}

% Tell LaTeX to use the "article" style

A More generally, this part of the le contains commands to tell L TEX how to format the documentspacing, font size and shape, justication, etc. The second part of the document, the document body, is everything between \begin{document} . . . \end{document}. This is where you type the words and equations that make up your paper. A The rest of this document starts from here and tries to get you writing papers with L TEX A as quickly and eciently as possible. Section 2 describes how to download and install L TEX. Section 3 discusses how to enter text in your document, and Section 4 discusses how to enter mathematical expressions. Section 5 gives an overview of some particularly useful add-on packages, Section 6 explains how to handle citations and bibliographies in your document, and Section 7 discusses formatting your paper for each of the three top Finance journals, the Journal of Finance, Journal of Financial Economics, and Review of Financial Studies. Finally, Section 8 explains why I recommend using a Version Control System like Mercurial A to manage your L TEX les (as well as your program les).

2
6

A Installing L TEX
1

A In principle, writing papers using L TEX requires three separate pieces of software:

Theres also a page number at the bottom of the page, which Ive omitted to save space.

1. A text editor to edit the .tex source le. A 2. TEX/L TEX software to process your source le and create the nal PDF le. 3. A PDF viewer so you can see the output.
A While you can install three separate pieces of software, it is much simpler to use a L TEX installation that comes with a front-end program, which seamlessly integrates all of these pieces into one so you never have to think about the dierent steps involved.7 The standard A L TEX installations for Windows and OS X both come with a good front-end program:

OS Installation Name Front end URL Windows MikTeX TeXworks http://miktex.org OS X MacTeX TeXShop http://www.tug.org/mactex. To install one of these on your system, go to the URL listed above (you can click on the link) and follow the installation instructions.8 Creating a document with either TeXworks or TeXShop involves loading the .tex le, editing it until youre happy with it, then pressing a button to create the PDF le, which will also be displayed on the screen. Figure 1 shows how the TeXworks environment looks when editing the test le from above. Figure 2 shows the same for TeXShop. In both cases:
7

Dierent syntactical elements are highlighted in dierent colors. Processing the .tex le to a PDF le entails just pressing a single button.9 When there are errors, you can automatically be taken to the right place in the text. You can easily see which bit of the PDF le corresponds to which bit of the .tex le, making editing easier.

There is nothing to stop you switching to separate programs later, if you want. For example, I use Emacs (see http://www.gnu.org/software/emacs/) for editing .tex les (and for almost everything else in my life), and either SumatraPDF (Windowssee http://blog.kowalczyk.info/software/sumatrapdf) or Skim (OS Xsee http://skim-app.sourceforge.net/) to view the resulting PDF les. 8 There seems to be a bug in the MikTeX installation, which causes MikTeX to be installed with a default A4 paper size regardless of what you ask for during the installation. This in turn causes pages to be oset vertically by about an inch. You can get around this by setting fake margins in your document to compensate (yes, I mean you, Johan. . . ), but this will annoy coauthors who dont suer from this bug. Instead, change the default paper size manually after installing MikTeX: From the Windows program menu, select MikTeX 2.09 Maintenance (Admin) Settings (Admin). Under Paper select Letter (letterSize), then press Update formats and press OK (see Figure 3). To do this manually from a command prompt, you typically have to run a series of commands, especially if youre using BibTEX to handle your citations (see Section 6): pdflatex test bibtex test pdflatex test pdflatex test
9

6 Figure 1: Simple document with TeXworks. Shows syntax highlighting and simultaneous view of text and PDF les
RS: To insert graphics, use the \includegraphics command (see graphicx package, Section 5.3). To create a landscape gure, use the sidewaysfigure environment (see rotating package, Section 5.11).

7 Figure 2: Simple document with TeXShop. Shows syntax highlighting and simultaneous view of text and PDF les.

3
3.1

Entering Text
Spaces and line breaks

A Entering text in a L TEX document is pretty straightforwardjust type it. A couple of things to note if youre used to a word processor (i.e., if you are between 3 and 90 years old): A i. L TEX doesnt care if you use one or several spaces or how often you insert a line break, A and ii. a completely blank line tells L TEX to start a new paragraph.

Lots of doesnt care.

spaces and but \LaTeX\


A Lots of spaces and some line breaks, but L TEX doesnt care. A A blank line tells L TEX to start a new para-

some line breaks,

A blank line tells \LaTeX\ to start a new paragraph.

graph.

A L TEX automatically adds extra space at the end of a sentence. However, it gets confused when a word in the middle of a sentence ends with a period. In this case, you can use A \ (backslash then space) to force L TEX to insert a regular intra-sentence space. For example,

I ran into Dr. Smith, who was walking extremely rapidly. \\ I ran into Dr.\ Smith, who was walking extremely rapidly.

I ran into Dr. tremely rapidly.

Smith, who was walking ex-

I ran into Dr. Smith, who was walking extremely rapidly.

Another special space, ~, is used when we want to prevent a line break between two words, such as between Section, Equation, etc., and the number that follows. For example,
Its difficult to read this when we allow Section 3 to have a line break in the middle.\\ Its difficult to read this when we allow Section~3 to have a line break in the middle. Its dicult to read this when we allow Section 3 to have a line break in the middle. Its dicult to read this when we allow Section 3 to have a line break in the middle.

3.2

Sections and subsections

Start a new section or subsection using the commands \section and \subsection. E.g.,

1
\section{Section Title} \subsection{Subsection title} Some very uninteresting text\ldots

Section Title
Subsection title

1.1

Some very uninteresting text. . .

If you need them, there are also subsubsections, paragraphs, and subparagraphs:

\subsubsection{Subsubsection title} \paragraph{Paragraph title} This is a paragraph. \subparagraph{Subparagraph title} Yet more uninteresting text\ldots

1.1.1

Subsubsection title

Paragraph title This is a paragraph. Subparagraph title Yet more uninteresting text. . .

If you want any of these not to be numbered, add an asterisk after the command name, e.g., \section*{An Untitled Section}. A Note that these instructions tell L TEX about the logical structure of the document (e.g., I want to start a new section here) but not about the formatting that goes along with it A (e.g., Format this left-justied in Times-Roman 12 point), which L TEX takes care of by A itself. This is a general feature of L TEX, which means that you spend most of your time thinking about what youre writing rather than about how to format your paper.

3.3 3.4 3.5

Emphasizing text Tables Figures

Entering Mathematical Expressions

A L TEX excels at typesetting mathematical expressions. You can do most things using just A the capabilities built in to basic L TEX, but there are some very useful additional features provided by the amsmath package (see Section 5.4), which I recommend loading into every document by including the line

\includepackage{amsmath} 9

in the preamble. This document mentions some of the additional capabilities provided by the amsmath package, but for full details you should see the package documentation, available at http://www.tug.org/texlive/Contents/live/texmf-dist/doc/latex/amsmath/ amsldoc.pdf.

4.1

Inline versus displayed expressions (unnumbered)

A There are two dierent ways to display mathematical expressions in L TEX:

1. Inline: The expression appears as part of the paragraph if surrounded by (single) dollar signs, $ . . . $, or (equivalently) \( . . . \). For example,
Of course, $e^{i\pi} + 1 = $ \( \lim_{x \rightarrow 0} \frac{\sin(x)}{x} - 1 = 0 \). Of course, ei + 1 = limx0
sin(x) x

1 = 0.

2. Display: The expression appears on a separate line, with more generous vertical spacing, if surrounded by $$ . . . $$ or (equivalently) \[ . . . \]. For example,
Here is a displayed equation: Here is a displayed equation: $$ E = \frac{mv^2}{2}. $$ E= mv 2 . 2

Here is another: \[ \left[\int_0^\frac{\pi}{2} \frac{\cos(x)}{2} \, dx\right]^3 = \frac{1}{8}. \]

Here is another:
2

cos(x) dx 2

1 = . 8

4.2

Numbered equations

A L TEX also has several environments that create numbered equations. For example,

A numbered equation: \begin{equation} E = mc^2. \label{eq:Einstein} \end{equation} E = mc2 . (1) A numbered equation:

10

Aligned, numbered equations: \begin{align} \sum_{i=1}^n i &= \frac{n(n+1)}{2}; \\ \sum_{i=1}^n i^2 &= \frac{n(n+1)(2n+1)}{6}. \end{align}

Aligned, numbered equations:


n

i=
i=1 n

n(n + 1) ; 2 n(n + 1)(2n + 1) . 6

(2) (3)

i2 =
i=1

To refer to equations in the text, use either \ref or \eqref:10


Eq.~\eqref{eq:Einstein} \ldots \\ Eq.~(\ref{eq:Einstein}) \ldots Eq. (1) . . . Eq. (1) . . .

4.3

Spacing in mathematical expressions

A We saw above (Section 3.1) that L TEX doesnt care much about how much whitespace you A have in your text; one space is the same as one hundred. L TEX cares even less about whitespace in equationsit ignores spaces completely (something thats easy to forget). For example, suppose you wanted to typeset the equation

dS = m dt + s dZ. S To create a space between, say, the m and the dt, the obvious thing to try is to insert a space in the text le, but this looks a lot better in the .tex source than it does in the nal document. . . :
\[ \frac{dS}{S} = m dt + s dZ. \] dS = mdt + sdZ. S

A L TEX completely ignores those spaces, making the right hand side very hard to interpret. A You have to tell L TEX explicitly when you want to insert some space in an equation, in this case using the thinspace command, \,:

\[ \frac{dS}{S} = m\,dt + s\,dZ. \]


10

dS = m dt + s dZ. S

The \eqref command and align environment require the amsmath package (see Section 5.4).

11

4.4

Long equations

Sometimes an equation or expression is too long to t onto a single line. The amsmath package (see Section 5.4) provides several options to deal with this, notably the multline and split environments. For example,
\begin{multline} a+b+c+d+e+f+g+ \\ h+i+j+k+l+m+n \end{multline} a + b + c + d + e + f + g+ h + i + j + k + l + m + n (4)

\begin{align} y & = mx + c. \\ \begin{split} a & = b+c+d+e+f+g\\ & \quad -h+i+j+k+l \end{split} \end{align} a=b+c+d+e+f +g h+i+j+k+l (6) y = mx + c. (5)

4.5

Text inside mathematical expressions

If you want to put text inside a mathematical expression, enclose it in either \mbox{} or \text{}. These are very similar, though the latter requires the amsmath package to be loaded. One advantage of \text{}, however, is that it knows how to adjust the font size when used as part of a subscript. For example,
\begin{align*} A_{\mbox{font too big}} &= 1 \mbox{ in most cases.} \\ A_{\text{font OK}} &= 1 \text{ in most cases.} \end{align*} Afont too big = 1 in most cases. Afont OK = 1 in most cases.

4.6

Brackets

It is often necessary to put brackets around mathematical expressions. For small expressions, this can be done (almost) the obvious way, using ( . . . ), [ . . . ], or \{ . . . \} (but note that you need a backslash before { or }). For example, 12

\[ (a+b)+[c+d]+\{e+f\}. \] (a + b) + [c + d] + {e + f }.

However, this doesnt work so well if the expressions inside the brackets are taller than a single character. For example, the following expression really needs larger brackets:
\[ (\frac{a}{b})+ \{\frac{c^{[d+\frac{e^2}{2}]}}{f}\} \]
A L TEX has various commands for manually setting a larger bracket size, but in the vast A majority of cases you can just let L TEX set the bracket size automatically by using \left(, \right), etc. For example,

a c[d+ 2 ] ( )+{ } b f

e2

\[ \left(\frac{a}{b}\right)+ \left\{\frac{c^{\left[d+\frac{e^2}{2} \right]}}{f}\right\} \] a + b c


d+ e2
2

4.7 4.8 4.9

Arrays Dening new operators Theorems, etc.


A Useful L TEX Packages

A The standard L TEX distribution comes with a large number of extra packages. These are A les with the extension .sty, which allow you to customize the behavior of L TEX, either by adding additional functionality or by changing the behavior of functions already dened. Many of these packages are extremely useful. For example, if you want to include graphics in your paper, you load the graphicx package (dened in the le graphicx.sty). To use a package installed on your system, you use the command \usepackage. For example, to load the graphicx package, youd include the command

\usepackage{graphicx} in the preamble to your document. Near the top of this le youll nd the lines 13

\usepackage{setspace,graphicx,epstopdf,amsmath,versionPO} \usepackage{marginnote,datetime,url,enumitem,subfigure,rotating} These lines load some packages that I nd particularly useful, and include in almost every document I write. You can nd full documentation on the Web, but heres a brief description of why each of these packages is so useful, with some brief examples illustrating their use. A Before that, however, a discussion of how to install them so L TEX knows where to nd them.

5.1

Installing packages

Its easy to use a package once its installed on your system, but what do you have to do to install a package you havent used before? The usual answer is nothing. Nearly all of the packages youll ever want (including nearly all the packages described in this document) are A installed as part of the L TEX distribution.11 5.1.1 Installing Non-Standard Packages

A From time to time, you may want to use a package that is not part of the standard L TEX distribution. One of the packages I use on a regular basis, versionPO, falls into this category, and so do my customized journal-specic les, jf.sty, jfe.sty, and rfs.sty. One way to use packages like this is just to copy them into the directory containing your projects .tex le, and they will automatically be found when you process it. However, this is not a great solution, as you have to do it for every new project, and if you ever need to edit one of these les, its very easy to lose track of the most recent version when you have dozens of copies at various places on your disk. A A much better method is to install these les (once) somewhere L TEX will always know where to nd them. This does require a bit of work, but it only has to be done once. Lets illustrate this with the versionPO package included with this document.

1. The rst thing you need to decide is where to put your extra .sty le(s). You could put them in the same directory structure as the standard packages, but dont do this!12 Instead, set up your own local directory tree. For example, on my Windows system, I store extra packages in subdirectories under c:\RHS\texmf-local\tex\latex, and on my Mac I use /Users/stanton/Library/texmf/tex/latex.13
In some cases (e.g., MikTeX) you can choose not to install all packages, but to have the package manager install new packages for you whenever you ask to use them for the rst time. 12 When you next upgrade your installation, youll have to remember to copy them elsewhere (which also means remembering which packages they were) to avoid losing them. 13 This may seem complicated, but it follows the recommended TEX directory structure. You can pick
11

14

A 2. After creating the relevant directory, tell your L TEX installation where to nd it.

MikTeX 2.09: From the Windows program menu, select MikTeX 2.09 Maintenance (Admin) Settings (Admin). Click on the Roots tab, click Add, and select the appropriate directory structure (in my case, this is c:\RHS\texmf-local).14 TeX Live (MacTeX): If you chose the same directory as I did (~/Library/texmf/tex/latex, where A ~ denotes your own home directory, e.g., /Users/stanton), L TEX will automatically look for les there and in all subdirectories, so you dont need to do anything else here.
A Note: Both of these steps only need to be done once for a given L TEX installation. The next steps need to be performed for every non-standard package you install.

3. Copy any new .sty les into the directory structure you just created. For example, c:\RHS\texmf-local\tex\latex\misc\versionPO.sty.
A Now run L TEX on a le that uses the package versionPO. Wait! It fails with the error message

RS: Should work OK with the Mac; verify.

! LaTeX Error: File versionPO.sty not found.


A What the. . . ?! L TEX knows where you want to keep your extra les and youve put the A le right where L TEX expects to nd it. This is a very frustrating error, which can cause people to get quite annoyed with the idiot coauthor who told them to install a non-standard package on their system (or so Ive heard. . . ). The reason for the error (which is easy to A forget even for experienced L TEX users, leading to potential frustration every time you install A a new non-standard package) is that when you run L TEX, it doesnt actually search in every relevant directory to nd all the les it needs to load; this would make it unbearably slow. Instead, it consults a database that tells it where to nd each le. Each time you install a new le, theres therefore one additional step: A 4. Update the L TEX le name database.

MikTeX 2.09:
anywhere you like for the root of this directory structure (c:\RHS\texmf-local, for example), but everything underneath this directory should follow the standard structure. For additional information on the standard TEX directory structure (TDS), see http://www.tex.ac.uk/tex-archive/tds/tds.html). 14 A This will allow L TEX to nd les anywhere under this directory.

15

From the Windows program menu, select MikTeX 2.09 Maintenance (Admin) Settings (Admin). Click on Refresh FNDB (File name database). TeXLive (MacTeX): Run the command texhash or mktexlsr.
RS: Shouldnt need to do this if we chose the default location.

5.2

Changing line spacing: setspace

Journals often want submissions to be double-spaced, while for most purposes I use 1.5 spacing. setspace is a convenient way to set or change the line spacing of the document, or parts of the document. For example, near the top of this le is the command \onehalfspacing This sets the overall document spacing to one and a half. You can also single-space part of the text (the abstract, say) by enclosing it in a singlespace environment:
\begin{singlespace} This is single spaced. Once this environment is finished, the document will revert to its previous spacing. \end{singlespace} This is single spaced. Once this environment is nished, the document will revert to its previous spacing.

5.3

Including gures: graphicx

Use this package to include gures in your document. For example, heres a picture of the MikTeX settings page described in footnote 8 on page 5.

\begin{figure}[H] \centering \includegraphics% [width=1in]{figures/MikTeX_Options} \caption{MikTeX main options page} \label{fig:MikOptions} \end{figure}

Figure 3: MikTeX main options page

Notes 16

Dont include the extension in the le name. The package knows about several standard graphics types (in this example, I provided a PNG le). In particular, if you tell A it to look for le then if you process the le straight to PDF using pdfL TEX, it will automatically look for le.pdf (pdflatex cant handle EPS les) and if youre processing it to a DVI le (and then to a PS le) using the latex command, it will automatically look for le.eps (latex cant handle PDF les). If the pdflatex command cannot handle EPS les, what do you do if you dont want to convert your source le to .dvi, but only have EPS graphic les?15 The answer is to include the epstopdf package, which automatically converts all EPS graphics les to PDF les on the y when you process the source using pdflatex. A There are various options for telling L TEX where to put a gure on the page. In this A case I wanted to force L TEX to put the gure exactly where I dened it, so I used the [H] option, dened in the float package.

5.4

Mathematical typesetting: amsmath

Contains lots of useful extra mathematical features. Some of the most useful: 5.4.1 \eqref

This puts parentheses around equation numbers for you instead of your doing it manually with \ref. For example,16
Equation~(\ref{eq:Emc2}) versus \\ Equation~\eqref{eq:Emc2}. Equation (12) versus Equation (12).

5.4.2

\begin{align} . . . \end{align}

Use this instead of eqnarray for aligning multiple equations. Compare the spacing of the following equations:
\begin{equation} E = mc^2. \end{equation}
For example, Matlab is much better at generating EPS les than PDF les. Yes, I realize both versions have the same number of characters, but for my two-ngered typing style its quicker to type an extra eq than the two parentheses.
16 15

E = mc2 .

(7)

17

\begin{align} E &= mc^2. \\ A &= \pi r^2. \end{align} E = mc2 . A = r2 . (8) (9)

\begin{eqnarray} E &=& mc^2. \\ A &=& \pi r^2. \end{eqnarray} E = mc2 . A = r2 . (10) (11)

Note: Oetiker et al. (2011) recommend using IEEEeqnarray (part of the IEEEtrantools package) instead of align (see Moser, 2012, for details on this environment and lots of useful discussion of how to typeset mathematical equations). It does seem to overcome some drawbacks of the align package, and maybe Ill try it out one day. . . . For now, heres the same example as above:17
\begin{IEEEeqnarray}{rCl} E &=& mc^2. \label{eq:Emc2} \\ A &=& \pi r^2. \end{IEEEeqnarray} E = mc2 . A = r2 . (12) (13)

5.4.3

\begin{cases} . . . \end{cases}

Useful when an equations right-hand side can take several forms. For example,
\begin{equation} C(S) = \begin{cases} 0 C (S ) = S K if S K, otherwise. (14) 0 & \text{if $S \leq K$}, \\ S - K & \text{otherwise}. \end{cases} \end{equation}
17 One negative: IEEEtrantools is not part of the MiKTeX distribution, so youll have to install it manually. All of my coauthors already hate me for making them learn how to install non-standard packages. . . (see Section 5.1.1). In addition, IEEEtrantools interacts badly with enumitem unless you load it with the command \usepackage[retainorgcmds]{IEEEtrantools}.

18

5.5

Setting page margins: geometry

A convenient way to set the page layout, margins, etc.18 For example, to set one-inch margins on all sides, you simply type \usepackage[margin=1in]{geometry} This can all be done manually instead, but it takes a lot more work.

5.6

Inserting notes: todonotes


RS: (Sample note) Dear author, this is gibberish. Note that this note appears both here and in the global To Do list on page 19. Note also that I used the caption to create a shorter entry for the To Do list.

An extremely useful package for adding notes.19 These can either be in the text or in the margin, can be colored as you desire, can appear in a global To Do list or not, can easily be switched o whenever you need to print a neat version of the paper, etc. I usually use marginal notes, and set the margins and paper size so that the layout doesnt change (much) when you turn notes on or o (see also Section 5.8).20 This package has lots of dierent options. I dene my default note command, \rhs, as follows: \newcommand{\smalltodo}[2][] {\todo[caption={#2}, size=\scriptsize,% fancyline, #1]{\begin{spacing}{.5}#2\end{spacing}}} \newcommand{\rhs}[2][]{\smalltodo[color=green!30,#1]{{\bf RS:} #2}} The command \rhs produces (by default) a green margin note with a small font and tight interline spacing (to allow me to get more text into a cramped space), and inserts a nice arrow pointing to the relevant point in the text.21 The note is also listed by default in the global To Do list, if there is one. This list, which summarizes the notes in the entire paper, can be inserted anywhere in your text (usually at the top) with the command \listoftodos:

RS: Like this one, inserted with the command \rhs{Like this one, inserted with the command \rhs{Like this one, inserted...

Richards To Do List
\listoftodos[Richards To Do List] o RS: Dear author, this is gibberish. . . o RS: A red note . . . . . . . . . . . . . 19 20

This is useful for keeping track of large numbers of notes, but I often dont include it as it changes the layout of the paper (and the notes are pretty easy to see in the text anyway).
A For some reason, the default L TEX margins are huge. For full details, see the package documentation at http://www.ctan.org/tex-archive/macros/latex/ contrib/todonotes/todonotes.pdf. 20 You also need to include the marginnote package if you want to generate notes in footnotes. 21 A You need to run L TEX several times to get the note and arrow correctly placed. 19 18

19

You can easily modify the denition of or add additional options to the \rhs command to create dierent results. For example, its easy to change the color or to make an inline note. \rhs[inline,nolist]{Heres an inline note. I dont use these much as the papers spacing changes when you turn them off, but theyre useful if you have a really long note. This note does not appear in the To Do list because I used the \texttt{nolist} option.}
RS: Heres an inline note. I dont use these much as the papers spacing changes when you turn them o, but theyre better if you have a really long note. This note does not appear in the To Do list because I used the nolist option.

RS: A red note, inserted with the command \rhs[color=red!30]{A red note, inserted with the command ...

Note: By default, todo notes do not work inside footnotes or oats (gures and tables). A If you try, L TEX produces an incomprehensible error message and no note. A work-around for this problem is to redene the command \marginpar using the command22 \renewcommand{\marginpar}{\marginnote} This allows notes to be created inside footnotes, but you will now nd that notes on your page overlap if you create two notes close together in the text. To prevent this, my current work-around is not to include the command above, but instead to dene a new note command \rhsnfn, to be used only in footnotes and oats, which performs this redenition temporarily. This is done by the following lines at the top of this document: \let\oldmarginpar\marginpar % Save original definition of \marginpar \newcommand{\rhsfn}[2][]{% To be used in footnotes and floats \renewcommand{\marginpar}{\marginnote}% \smalltodo[color=green!30,#1]{{\bf RS:} #2}% \renewcommand{\marginpar}{\oldmarginpar}}

5.7

Printing date and time: datetime

Allows various choices of formatting dates, as well as referring to the current time (via \currenttime). This is useful for mammoth editing sessions where youve created printouts of several dierent versions of a document during the same day.
22

This requires you to load the marginnote package.

20

5.8

Multiple versions from one le: versionPO

This package allows you to include text in your paper conditionally, so you can generate multiple dierent versions of a document from a single source le by changing just one or two statements.23 here are many, many uses for this package, including Creating working papers and journal submissions from a single source le. Optionally including responses to referees. Adding notes to yourself that you can switch on or o at will. Writing an exam and having the option to add extra space for students to write their answers, or having the option to include solutions, again all in a single le.

Heres a simple example. See what happens to the output below when you change the command \includeversion{notes} to \excludeversion{notes} at the top of the le.
Notes \ifnotes{\emph{are}}% {are \emph{not}} shown in this file. Notes are shown in this le.

A slightly more interesting example is the following, from the top of this le: \ifnotes{% \usepackage[margin=1in,paperwidth=10in,right=2.5in]{geometry}% \usepackage[textwidth=1.4in,shadow,colorinlistoftodos]{todonotes}% }{% \usepackage[margin=1in]{geometry}% \usepackage[disable]{todonotes}% } If the command \includeversion{notes} appears at the top of this le, then this command loads todonotes with various options, and then loads geometry with some slightly strange paper size and margin denitions that allow both the text and the margin notes to be printed on a standard piece of paper without changing the text layout. If the command \excludeversion{notes} appears instead, notes are disabled and standard one-inch margins are used, producing a version of the document ready for distribution. One environment dened by default (and excluded) is comment, so you can comment out text by
A One drawback of versionPO.sty is that its not included as part of the standard L TEX installation. Ive therefore included it with this document, and it needs to be installed as described in Section 5.1.1. versionPO.sty was written by Piet van Oostrum in about 1991 and originally named version.sty. I renamed it versionPO.sty to avoid any possible conicts with a dierent le, also called version.sty, that is in the standard distribution.There are several standard packages that do similar things to this one, including version, versions, optional, and comment. You should feel free to use one of them instead, but I am used to using versionPO and dont like change. 23

RS: To maximize how much I can say, I use a small font and the widest margin notes I can get my printer to generate.

21

either surrounding it with \ifcomment{...} or (useful for larger blocks) putting it inside \begin{comment} . . . \end{comment}. This is useful for temporarily removing text that you might want to put back later. For example,
This is the first sentence. \begin{comment} The second sentence is commented out. \end{comment} This is the third sentence. This is the rst sentence. This is the third sentence.

Here are some more examples from the top of this document. Try changing their settings to see what happens when you reprocess the document. \includeversion{notes} \includeversion{links} \excludeversion{submit} \includeversion{toc} % % % % Include notes? Turn hyperlinks on? Format for conference submission? Include table of contents?

5.9

List formatting: enumitem

enumitem enables easy control over many aspects of numbering and spacing in enumerate, itemize, and description lists. For example, at the top of this le youll see the command \setlist{noitemsep} This removes all extra vertical space between list items, which I prefer to the default spacing A (by default, L TEX puts extra vertical space between list items). You can also use this package to change the indentation of a list. For example,
Here is an unindented itemized list: \begin{itemize}[leftmargin=*] \item Item 1. \item Item 2. \end{itemize} Here is an unindented itemized list: Item 1. Item 2.

5.10

URLs and hyperlinks: hyperref

This package allows you to include clickable hyperlinks in your paper for URLs, citations, equations, references, etc. For example,

22

\cite{Stanton:95} \\ \url{http://www.ctan.org/} \\ \href{http://www.ctan.org/}% {CTAN Web site} \\ Equation~\eqref{eq:Emc2} \\ Section~\ref{sec:todo}

Stanton (1995) http://www.ctan.org/ CTAN Web site Equation (12) Section 5.6

You can customize how (and if) these are displayed in your text (colored text, boxes, etc.). There are also unlinked versions of some commands, e.g.,
\nolinkurl{http://www.ctan.org/} http://www.ctan.org/

If you dont want any hyperlinks in your document, you can turn them all o with the command \hypersetup{draft=true}.24 You can try this out by changing the command \includeversion{links} to \excludeversion{links} at the top of this document.

5.11

Landscape and subgures: rotating and subfigure

The rotating package allows the creation of tables and gures in landscape mode using \begin{sidewaystable} . . . \end{sidewaystable} for tables and \begin{sidewaysfigure} . . . \end{sidewaysfigure} for gures.25 The subfigure package allows creation of a single gure with multiple subgures. Figure 4 illustrates the use of both rotating and subfigure, created using the command \begin{sidewaysfigure} \centering \subfigure[A somewhat familiar figure]{ \includegraphics[width=3.5in]{figures/MikTeX_Options} \label{fig:sub1} } \subfigure[That was fun. Lets plot it again!]{ \includegraphics[width=3.5in]{figures/MikTeX_Options} \label{fig:sub2} } \caption{This completely gratuitous figure plots the same graphic
An alternative is to use the url package, but it is less exible than hyperref. Note that these are placed on separate pages. This is usually what you want, as youre rotating the gure or table because its too large to be set in portrait mode. However, there is also the sideways environment, which allows you to have rotated text/gures on the same page as non-rotated material.
25 24

23

we saw earlier, but does so twice and in landscape mode. How exciting! } \label{fig:fig_subfig} \end{sidewaysfigure} Note that you can also refer to the whole gure or to individual subgures in the text, e.g.,
Figure~\ref{fig:fig_subfig}. \\ Figure~\ref{fig:sub2}. Figure 4. Figure 4(b).

5.12

Other useful packages

Though I dont use these in every document, here are a few other packages I sometimes nd useful: bibunits: Allows you to create multiple bibliographies in a single document. For example, you might be teaching a class and want a single document with a section on each of a number of topics and a separate bibliography per section. You can optionally also have a single global bibliography. Each bibliography can have a dierent format. tocvsec2: Allows you to control which level of section appears in the table of contents, and you can change this section by section. For example, you might want to list subsections from the main body of the paper, but only sections from the Appendix. lastpage: Allows you to refer to the number of the last page of the document. tikz: Very powerful environment for creating diagrams. For example, heres an interest rate tree: 9.00% 7.80% 5.00% 3.00% 2.00% This was created using the commands 24 5.00%

25
(a) A somewhat familiar gure (b) That was fun. Lets plot it again!

Figure 4: This completely gratuitous gure plots the same graphic we saw earlier, but does so twice and in landscape mode. How exciting!

\begin{center} \begin{tikzpicture}[>=stealth,sloped] \matrix (tree) [matrix of nodes, minimum size=.3cm, column sep=2.5cm, row sep=.7cm, nodes={anchor=east}] { & & 9.00\% \\ & 7.80\% & \\ 5.00\% & & 5.00\% \\ & 3.00\% & \\ & & 2.00\% \\ }; \draw[->] (tree-3-1) -- (tree-2-2) ; \draw[->] (tree-3-1) -- (tree-4-2) ; \draw[->] (tree-2-2) -- (tree-1-3) ; \draw[->] (tree-2-2) -- (tree-3-3) ; \draw[->] (tree-4-2) -- (tree-3-3) ; \draw[->] (tree-4-2) -- (tree-5-3) ; \end{tikzpicture} \end{center} indentfirst: Indents the rst line of a new section (JF asks for this). caption: Gives you easy control over the format of gure and table captions. Useful for satisfying journal requirements. xr: Allows you to refer in one document to labels in another document. Useful, for example, for creating an Internet Appendix for the Journal of Finance where you want to be able to refer to equation numbers in the main paper.26 amsthm: Allows good control over theorem-like environments. booktabs: Allows good control over table layout and spacing. longtable: Allows a single table to span more than one page, keeping the same column headings, etc.

Citations and Bibliographies

A L TEX makes it very easy to create and format citations and bibliographies. The most basic method is to insert the bibliography manually into your paper using the thebibliography

This could alternatively be done by putting everything in a single le and using bibunits to generate the two (separate) bibliographies, but then youd need to split the resulting PDF le in half. Its your choice.

26

26

environment and one \bibitem command for each entry. E.g., \begin{thebibliography}{99} \bibitem{Stanton:95} Stanton, Richard, 1995, Rational prepayment and the value of mortgage-backed securities, {\em Review of Financial Studies\/} 8, 677--708. \end{thebibliography} This entry would be cited in the text using the command \cite{Stanton:95}. This is how bibliography creation is described in Lamport (1994) and Oetiker et al. (2011) (though the latter does mention using BibTEX), but dont do it this way! Major drawbacks of this manual method include: 1. If you remove a citation from your text, you need to remove that paper from the bibliography manually (after, of course, checking to make sure youre not still citing it somewhere else). 2. To match a journals bibliography style, you have to edit every entry by hand. 3. Since theres no central database of references, you typically end up having to retype (after re-Googling) the same citations over and over again in dierent papers. This is both time-consuming and error-prone. A 4. By default, L TEX produces numerical citations, whereas most nance journals want author-year citations, e.g., Stanton (1995).

6.1

BibTEX

The solution to the problems above is to create bibliographies using BibTEX, a separate A program installed as part of any standard L TEX installation.27 Compared with the manual method, 1. BibTEX automatically inserts only references you actually cite (or that you tell it to insert even though you dont actually cite them, using the \nocite command). If you delete all citations to a particular paper, it will automatically be removed from your bibliography. 2. Reformatting a bibliography usually requires editing just a single command in your paper (see Section 6.4.2).
One day, it will probably be even better to use the biblatex package instead. This has some more features than BibTEX (for example, you can have citations appear in footnotes, and can refer to the title of a reference within your text), and it is in principle easier to customize, but it is currently easier to generate journal-specic bibliography formats using BibTEX with custom-bib.
27

27

3. You keep all references in a central database. As a result, (a) You only need to type or look each reference up once. (b) Theres no doubt about where to nd the latest version of any reference. (c) Once youve corrected any errors in a reference, they remain corrected forever. 4. Its easy to generate citations in any format you desire using the standard \cite command (see Section 6.4.1).

6.2

The BibTEX database

When using BibTEX, you store all your references in one or more .bib les, taking the following format: @ARTICLE{Stanton:95, author = {Richard Stanton}, title = {Rational Prepayment and the Value of Mortgage-Backed Securities}, journal = {Review of Financial Studies}, year = {1995}, volume = {8}, pages = {677--708}, number = {3} } Note that this entry contains all of the logical information about the reference (author, title, etc.), but says nothing about formatting, which is handled separately. Once youve entered A a reference in your .bib le and told L TEX and BibTEX where to nd it (see below), when you use the \cite command, BibTEX will automatically nd the right reference, add it to your bibliography, and insert the appropriate citation in the text, e.g.,
\cite{Stanton:95} Stanton (1995)

Just like a .tex le, a .bib le is a plain-text le and can be edited with the same editor you use to edit your .tex les. However, there are also some BibTEX-specic editors, including JabRef (available on multiple platforms from http://jabref.sourceforge.net) and BibDesk (OS X only, installed as part of the MacTeX distribution).

28

6.3

Telling BibTEX where to nd the database

You tell BibTEX to look for references in the le master.bib by putting the following line in your TeX le: \bibliography{master} Note: BibTEX will always nd the le master.bib if it is in the current directory, but you dont want to have lots of dierent versions of this le sitting in every dierent project directory. A better approach is to set the environment variable BIBINPUTS to point to the directory in which youve stored your Bib le, and then BibTEX will nd it no matter where you run it from. On my Windows machine, BIBINPUTS is set to c:/RHS/texmf-local/bibtex/bib//, which will look for Bib les in the current directory and then, failing that, in directory c:\RHS\texmf-local\bibtex\bib and in all subdirectories.28 To set an environment variable in Windows, go to Control Panel and select System Advanced Environment Variables. Then under System Variables, click New, enter the variable name (BIBINPUTS) and the variable value (c:/RHS/texmf-local/bibtex/bib//, and click OK a few times. On my Mac, BIBINPUTS is set to ./:/Users/stanton/tex/texmf-local/bibtex/bib//, which will look for Bib les in the current directory and, failing that, in the directory c:\RHS\texmf-local\bibtex\bib and in all its subdirectories. To set an environment variable in OS X, edit le ~/.profile and add the line29 export BIBINPUTS=./:~/tex/texmf-local/bibtex/bib//

6.4
6.4.1

Formatting the bibliography: natbib and custom-bib


natbib

A This package provides ner control than basic L TEX over citation formatting. For example,

Searches in Windows almost always look in the current directory rst, so this doesnt need specifying. A Strictly speaking, this only has an eect if youre running L TEX from a command shell. If run from within a GUI application, this may not work. If this is a problem for you, set the environment variable instead using the command launchctl setenv BIBINPUTS ./:~/tex/texmf-local/bibtex/bib//.
29

28

29

\cite{Stanton:95} \\ \citep[see, for example,]% [p. 3]{Stanton:95} \\ \citet[Equation~1]{Stanton:95} \\ \citealt[Equation~1]{Stanton:95} \\ \citealp[Equation~1]{Stanton:95} \\ \citeauthor{Stanton:95} \\ \citeyear{Stanton:95}

Stanton (1995) (see, for example, Stanton, 1995, p. 3) Stanton (1995, Equation 1) Stanton 1995, Equation 1 Stanton, 1995, Equation 1 Stanton 1995

By loading the extra package bibentry, you can also print the full reference. For example,
Stanton, Richard, 1995, Rational prepayment \bibentry{Stanton:95} and the value of mortgage-backed securities, Review of Financial Studies 8, 677708

6.4.2

Customizing the bibliography format: custom-bib

This package allows you to dene a new bibliography style ( a .bst le), matching the format of your bibliography to that of the journal you are submitting to.30 To create a new bibliography style called, say, jf.bst for the Journal of Finance, run the command latex makebst and then answer various questions about the name of the output le and how you want your bibliography formatted. It then creates a customized .bst le, jf.bst. To use the format dened in this le, you insert the command \bibliographystyle{jf}
A in your document. This tells L TEX/BibTEX to format the bibliography using information in the le jf.bst.

Journal-Specic Document Formatting

Journals typically have their own requirements for section numbers, gure captions, etc., as well as for the format of the bibliography. Meeting these requirements requires you to modify some of the default denitions.
You can alternatively create or edit the appropriate .bst le by hand. However, before you even think A of doing this, take a look at one of the .bst les in your L TEX installation. These use a mysterious syntax that is most denitely not fun to edit. . .
30

30

7.1

Formatting the bibliography

Ive used custom-bib to create bibliography styles for Journal of Finance (jf.bst), Journal of Financial Economics (jfe.bst), Review of Financial Studies (rfs.bst). These les are included with this document. Change the command \bibliographystyle{jf} below to \bibliographystyle{jfe} or \bibliographystyle{rfs}, reprocess the document (by running LaTeX, BibTeX, and LaTeX again), and see how the bibliography format changes.31 Note: Youll typically nd one or two minor journal bibliography conventions that custom-bib cant quite handle.32 You now have two choices. One is to spend hours manually editing the .bst le to do what you want. The other (which I recommend) is to wait until the bibliography is really nal, then just copy the contents of the .bbl le into the body of the text (removing the \bibliographystyle and \bibliography commands), and edit it manually to make these last few changes.33

7.2

Formatting the text

In addition to the bibliography format les mentioned above, I have also have written style les to help make your paper match the submission requirements of either the Journal of Finance (jf.sty), Journal of Financial Economics (jfe.sty), or Review of Financial Studies (rfs.sty). I have also included a sample paper for each journal, which you can use as the basis for preparing your own documents. They include similar packages to this document, but each also includes the journal-specic style le and bibliography format le, and also has some journal-specic formatting commands in the text. The specic les included for each journal are: 1. Journal of Finance: jf.sty: Formatting commands for papers. jfIA.sty: Formatting commands for Internet Appendices. jf.bst: Bibliography format.
The bibliography contains references to published papers (Stanton, 1995), books (Hull, 2011), and working papers (Carpenter, Stanton, and Wallace, 2012), so you can see how various entry types are formatted. 32 For example, you may have page numbers listed in your BibTEX database as 10231045, while the journal insists on 102345. 33 Save even more time by doing this after the copy-editor has taken a look and pointed out where you need to make changes.
31

31

jfsample.tex: Sample paper (TEX le). PDF le. jfIAsample.tex: Sample Internet Appendix (TEX le). PDF le. 2. Journal of Financial Economics: jfe.sty: Formatting commands for papers. jfe.bst: Bibliography format. jfesample.tex: Sample paper (TEX le). PDF le. 3. Review of Financial Studies: rfs.sty: Formatting commands for papers. rfs.bst: Bibliography format. rfssample.tex: Sample paper (TEX le). PDF le.

Working with Others: Version Control Systems

When working on a paper with other people, you have to be careful to keep track of who is working on what version of each le associated with the paper (both .tex and program les, e.g., Matlab code). One common way to do this is to edit the les in turn, making sure that each person only starts editing a le once the prior person in line has emailed them a version containing all of their changes. This works most of the time, so it isnt an absolutely terrible idea, but it has some signicant drawbacks. For example, It involves a lot of emailing. With multiple les, its easy to forget whos supposed to be editing which le. What happens when your coauthor accidentally edits the version of the le you sent her 4 days ago instead of the version containing all your latest edits? What happens when you remember there was a section (or a Matlab function) in the version you presented at the WFA meetings 6 months ago thats now gone from the le, but which youd like to retrieve? What happens when youve spent a week editing your program, and realize the direction you were going in just doesnt work, so you want to go back to the version right before you started these edits? 32

What happens when you realize that at some (unknown) time during the last month, one of your coauthors accidentally deleted a section of the paper you really liked? What happens when you realize that your code now produces dierent results than it did a year ago, but shouldnt? How do you track down what changes to the code during the last year caused the change in behavior? A good back-up system (e.g., Time Machine) will help by allowing you to retrieve old versions of your les.34 Using Dropbox or some similar le-sharing software is also very helpful in solving the constant-emailing problem, and it also means that everyone knows that the latest version of the le is always stored in the shared Dropbox directory (at least as long as whoever edited it last has remembered to copy it from their working directory to the Dropbox directory. . . ). For these and many other reasons I strongly recommend that everyone back up their important les on a regular basis. I also love Dropbox. However, Suppose you forget that its not your turn to edit a le (or you come up with an algorithm or way of expressing a thought thats so brilliant you cant possibly wait to commit it to paperor a .tex le). So now both you and your coauthor are editing the le at the same time. Now suppose you save your edits on Dropbox rst and then your coauthor saves her edits. Your edits have now disappeared from the latest version of the le (which is quite a shame, given how brilliant they were). More generally, wouldnt it be nice not to have to worry about editing the le sequentially, so any of the coauthors could edit it whenever they had time or a good idea (or both), without worrying about losing track of the current version of the le or of their or anyone elses edits? And wouldnt it be nice if you could at any time easily go back to any prior version of any le? A Version Control System (VCS) solves all of the problems we discussed above. Among many advantages, It makes it easy to merge simultaneous edits by dierent coauthors, so you dont have to worry any more about editing les sequentially. Edit whatever le you want whenever you want.
But how do you remember which version from about 6 months ago you actually need? This problem is commonly solved by saving lots of versions of your paper and code with clever descriptive names like program WFA2011.m program remember this as I might want to go back to this version.m program XXX.m However, after a while there are so many les that you cant nd the one you want in the crowd, and youll eventually forget what those names, which seemed so clear when you rst came up with them, mean.
34

33

It allows you to keep track of every revision of every le thats ever existed, along with a log of what changed from one revision to the next. If you want to go back to a prior version, or see whats changed since a version 2 years ago, its almost trivial. The second advantage makes using a VCS a good idea even when theres only one author, but its particularly valuable when there is more than one.35 An in-depth discussion of VCS is beyond the scope of this document. Some excellent introductions, which explain way better than I could what version control is, why its important, and how to use it, are Sink (2011), Spolsky (2012), and OSullivan (2009).36 There are numerous VCS to choose from, but my personal recommendation if youre starting from scratch is to use one of the three most popular DVCS, Mercurial (see http://mercurial. selenic.com), Git (see http://git-scm.com), or Bazaar (see http://bazaar.canonical. com).37 With these systems, each author edits and keeps track of his or her changes locally, and periodically pushes those changes to a shared central repository.

8.1

Public hosting of DVCS repositories

At this point, many of you are probably starting to sweat, worried that your coauthors will ask you to be the person who manages and hosts the shared repository.38 Fortunately, there are public hosting services that make it extremely simple to host your central repository, as well as giving you the ability to keep track of bugs, access your les from anywhere theres a Web connection, etc. Examples include GitHub (https://github.com/: Git), BitBucket (https://bitbucket.org/: Mercurial and Git), and Launchpad (https: //launchpad.net/: Bazaar). You can host either public (open to everyone) or private (accessible only to those you explicitly designate) repositories on these sites.

8.2

This projects Bitbucket repository

The central (Mercurial) repository for this project is publicly available on Bitbucket at https://bitbucket.org/rhstanton/texintro. Feel free to clone this repository and exIve been using a VCS to keep track of every .tex le I care about for over 20 years, starting with RCS (a rst generation VCS), then switching to CVS (a second generation, centralized VCS, or CVCS), and more recently Mercurial (a third generation, distributed VCS, or DVCS). 36 Sink (2011) covers several dierent VCS, including Subversion, Mercurial, and Git. OSullivan (2009) and Spolsky (2012) focus exclusively on Mercurial. 37 While there are loud arguments on the Web about which of these is the best, the similarities are way more striking than the dierences. I chose Mercurial because Git and Mercurial seem to have more users than Bazaar and because Mercurial and Bazaar play slightly nicer with the standard Emacs version-control packages than Git (a factor that probably wont play much of a role in your decision). 38 Can you remind me again how to set up a password-protected Apache Web server on my Mac. . . ?
35

34

periment with it (and Mercurial).39 Note: I know you probably wont all start using a VCS tomorrow. Ive been extolling their virtues for years, and so far Ive managed to get one coauthor to admitgrudgingly that they might think about using one in about 150 years and the rest of them no longer return my calls or emails. Using a VCS is still a good idea. Really. . . !

References
Carpenter, Jennifer, Richard Stanton, and Nancy Wallace, 2012, Estimation of employee stock option exercise rates and rm cost, Working paper, U.C. Berkeley. Hull, John C., 2011, Options, Futures, and Other Derivatives , 8th edition (Prentice Hall, New York). Knuth, Donald E., 1984, The TEXbook (Addison-Wesley, Reading, MA).
A Kopka, Helmut, and Patrick W. Daly, 2003, Guide to L TEX , fourth edition (Addison-Wesley, Reading, MA). A Lamport, Leslie, 1994, L TEX: A Document Preparation System , second edition (AddisonWesley, Reading, MA).

Maddox, Sarah, 2012, bitbucket 101, https://confluence.atlassian.com/display/ BITBUCKET/bitbucket+101. Mittelbach, Frank, Michel Goossens, Johannes Braams, David Carlisle, and Chris Rowley, A 2004, The L TEX Companion , second edition (Addison-Wesley, Reading, MA).
A Moser, Stefan M., 2012, How to typeset equations in L TEX, v. 3.7 (http://moser.cm.nctu. edu.tw/docs/typeset_equations.pdf).

Oetiker, Tobias, Hubert Partl, Irene Hyna, and Elisabeth Schlegl, 2011, The not so short A introduction to L TEX 2 , v. 5.01 (http://www.ctan.org/tex-archive/info/lshort/ english). OSullivan, Bryan, 2009, Mercurial: The Denitive Guide (OReilly Media, Inc., Sebastopol, CA), http://hgbook.red-bean.com/.
For details of how to set up an account at Bitbucket and how to interact with Bitbucket repositories, see Maddox (2012).
39

35

Sink, Eric, 2011, Version Control by Example (Pyrenean Gold Press, Champaign, IL), http: //www.ericsink.com/vcbe/. Spolsky, Joel, 2012, Hg Init: A Mercurial tutorial, http://hginit.com/. Stanton, Richard, 1995, Rational prepayment and the value of mortgage-backed securities, Review of Financial Studies 8, 677708.

36

You might also like