TEP0214
TEP0214
TEP0214
John C Frain
July 2014
John C Frain
Economics Department
Trinity College Dublin 1
1
This is an early draft of a book. Suggestions, comments are welcome and may be sent to
[email protected]
ii
Preface
LATEX or some other TEX based system is usually the first choice of many mathematicians,
physicists, chemists and other scientists when they come to produce papers and other
technical publications. Such documents often need facilities specific to their subject
which may not be available in other software. A LATEX system is more likely to provides
these facilities. It produces output that looks well in print and on screen. It is not as
well known that documents, which do not require a lot of these special facilities, can also
benefit from the use of LATEX even if they contain little or no mathematics. In addition
such documents require a knowledge of only a small part of a LATEX system.
I have used LATEX for more than twenty years and I have typeset many documents with
it. Many of these documents related to econometric/statistical and other quantitative
analysis in economics. I have benefited greatly from the use of LATEX. Many colleagues
that I have introduced to LATEX are of a similar opinion. The primary target audience
for this book would include economists, social scientists and others who wish to include
some mathematics, graphs, tables etc. in documents which contain a lot of text. I would
also hope that others will also find it useful.
The most common argument against the use of LATEX is that it is not user friendly.
Part of the problem is that TEX and LATEX were introduced when computers were much
less powerful and a mouse and windows style interface were not feasible. Today there
are windows style interfaces to LATEX that allow the user much easier access to the
program.
iii
Often a new user resorts to LATEX when he is trying to typeset some difficult mathematics.
The complexity of the mathematics may be responsible for his problems rather than
the complexities of the LATEX program. Preparing a simple text document with LATEX
requires very little knowledge of LATEX and would provide a better introduction than
setting some complicated mathematical document.
In writing this book I propose to provide (1) an easy introduction to LATEX and (2) an
overview of more advanced features. No prior knowledge of LATEX is assumed. If a modern
LATEX system is already installed on your computer you can start typing a simple LATEX
document in a matter of minutes. If LATEX is not installed I will show you how to install
it. Once you have started you may pick from the many recipes in the book to learn how to
complete various tasks such as typesetting mathematics, setting tables, figures, including
graphs generated in other applications, listing contents and compiling bibliographies and
indices. A beginner need only select those facilities that he needs. The beauty of LATEX
is that you give it your content and then allow it to format the document.
The preparation of a LATEX document is facilitated by the use of one of the modern
Graphical User Interfaces described in chapters 3 and 10. My current recommended
interface is TeXstudio (chapter 3). This system was used in the production of this
book.
LATEX is a large system. Here I cover those parts of LATEX and its extensions that I have
found useful in my own work or that colleagues have asked me about. There may be
better ways to completing some tasks than those I have proposed. If the reader knows of
such improvements or considers that some extensions (packages) that I have not covered
are essential I would be glad to hear from them. Including such suggestions in a future
edition of this volume would add to its usefulness. I would also welcome any other
comments.
This document was produced with LATEX and, if you download and examine it, you will
get some idea of what can be accomplished with LATEX. It probably contains (a) material
that you would never use, (b) some material that might be of use at a future date and
(c) material that meets your current requirements. You can safely ignore the material at
(a), postpone reading (b) and concentrate on (c). If you have little or no mathematical
symbols and figures you need to learn very little.
The final document is in Adobe pdf format. It is set up for two sided printing if you
wish to print it. You may also view it on your screen and take advantage of the coloured
iv
diagrams and display boxes. If your pdf viewer supports it the document contains both
internal hyperlinks and links to the world wide web.
If you like the appearance of the book then perhaps it is time that you gave LATEX a
trial.
v
vi
Contents
1 Introduction 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 What is LATEX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 A Brief History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 Outline Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.5 A Road Map for New Users . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.7 A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Installing LATEX 13
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Installing LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3 MiKTeX Maintenance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.4 Installing TeXLive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.5 Installing LATEX on other Operating systems . . . . . . . . . . . . . . . . . 22
2.5.1 Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.5.2 Apple OS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.5.3 Portable Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.6 A LATEX system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
vii
3.1 TeXstudio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.2.1 MS Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.2.2 Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.2.3 Apple OS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.3 Configuring and Using TeXstudio . . . . . . . . . . . . . . . . . . . . . . . 33
3.4 Synchronizing LATEX input file and pdf output . . . . . . . . . . . . . . . . 35
3.5 Previewing Output as you type . . . . . . . . . . . . . . . . . . . . . . . . 36
3.6 TeXtablet – Entering Math freehand in LATEX . . . . . . . . . . . . . . . . 36
3.7 A simple Example using TeXstudio . . . . . . . . . . . . . . . . . . . . . . 37
viii
4.5.8 Verbatim Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.5.9 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
4.5.10 Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.5.11 Fragile/Robust Commands and the \protect command . . . . . . 69
5 Mathematics in LATEX 73
5.1 In-line Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
5.2 The equation and equation* Environments . . . . . . . . . . . . . . . . . 75
5.3 Components of Mathematical Expressions . . . . . . . . . . . . . . . . . . 78
5.3.1 Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
5.3.2 Text in Display Math . . . . . . . . . . . . . . . . . . . . . . . . . 79
5.3.3 Subscripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5.3.4 Powers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5.3.5 Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.3.6 Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.4 Sums and Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
5.4.1 The overset function . . . . . . . . . . . . . . . . . . . . . . . . . 82
5.4.2 Multiplication Sign . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
5.4.3 Accents in Mathematics . . . . . . . . . . . . . . . . . . . . . . . . 82
5.4.4 Brackets and delimiters . . . . . . . . . . . . . . . . . . . . . . . . 83
5.4.5 Bold fonts in Mathematics . . . . . . . . . . . . . . . . . . . . . . . 84
5.4.6 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.4.7 Function Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
5.5 Other Mathematical Environments . . . . . . . . . . . . . . . . . . . . . . 87
5.5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
5.5.2 The split Environment . . . . . . . . . . . . . . . . . . . . . . . . 87
5.5.3 The multiline and multiline* Environments . . . . . . . . . . . 87
5.5.4 The gather and gather* Environments . . . . . . . . . . . . . . . . 89
5.5.5 The align and align* Environments . . . . . . . . . . . . . . . . 89
5.5.6 The alignat and alignat* Environments . . . . . . . . . . . . . . 91
5.5.7 The flalign and flalign* Environments . . . . . . . . . . . . . . 93
5.5.8 The array Environments and Systems of Equations . . . . . . . . . 93
5.5.9 The cases Construction . . . . . . . . . . . . . . . . . . . . . . . . 96
5.5.10 The \intertext command . . . . . . . . . . . . . . . . . . . . . . 96
6 Tables 99
ix
6.1 Floating Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
6.2 The table and table* Environments . . . . . . . . . . . . . . . . . . . . . 100
6.3 The tabular and tabular* Environments . . . . . . . . . . . . . . . . . . 103
6.4 Footnotes in Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
6.5 Long Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
6.6 Landscape Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
7 Graphics 117
7.1 Graphics Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
7.2 The figure and figure* Environments . . . . . . . . . . . . . . . . . . . 118
7.3 The graphicx package and \includegraphics command . . . . . . . . . . 118
7.4 Producing Images with LATEX . . . . . . . . . . . . . . . . . . . . . . . . . 120
x
8.6.5 caption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
8.6.6 url . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
8.6.7 natbib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
8.7 Enhanced Listing Package . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
8.7.1 paralist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
8.8 Chapter Headings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
8.9 Page Styles and the fancyhdr package . . . . . . . . . . . . . . . . . . . . 135
8.9.1 Page styles in base LATEX . . . . . . . . . . . . . . . . . . . . . . . 135
8.9.2 fancyhdr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
8.10 Packages for Typesetting Pages in Landscape . . . . . . . . . . . . . . . . 141
8.10.1 lscape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
8.10.2 rotating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
8.11 Verbatim Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
8.11.1 fancyverb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
8.11.2 cprotect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
8.12 xcolor package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
8.13 tcolorbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
8.14 hyperref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
xi
10 Other LATEX Editors (TEXworks, TEXMaker etc. ) 161
10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
10.2 Texmaker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
10.3 Texworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
10.4 Emacs/AucTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
10.5 TeXnicCenter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
10.6 WinEdt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
10.7 Winshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
10.8 LyX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
xii
17.2 Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
17.3 Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
xiii
xiv
CHAPTER 1
Introduction
1.1 Introduction
For many years authors have been using LATEX to produce papers, theses, books and other
documents. When LATEX was originally produced it was intended for use in typesetting
scientific/mathematical material. It has since been used, successfully in many other
disciplines to produce documents that look better and are often easier to read than those
produced with standard word processing software.
If you are new to LATEX the instructions in section 1.5 (page 8) of this book set out
the minimum that a new user needs to know and do before producing a first LATEX
document.
Many parts of this document are self-contained. They contain illustrated examples of
the use of LATEX to produce various effects. A new LATEX user or a more experienced user
can extract the LATEX code from these examples and use them in their own documents.
If you have used LATEX some time ago this book can act as a revision course, update
your knowledge and introduce you to the new LATEX user interfaces. I would not expect
the book to be read from start to finish. Often one might use the contents list to find
2 Introduction
LATEX has a reputation that it is difficult to use. To an extent this is true as it is somewhat
different to the usual word processing programs that a new user might have used. LATEX
is a large flexible system. A cursory glance at some LATEX documentation may frighten
the new user. In effect a new user only needs to know a small fraction of LATEX syntax.
He is also helped by using a modern user interface such as TeXstudio which is described
in Chapter 3.
It is often argued that a word processing program is easier to use. Perhaps! This depends
on what you are trying to produce. This book was produced with LATEX. Have a look at
its contents and consider how you would replicate them in your word processing program.
If you have mathematical material in your document, LATEX will produce results that at
least as good as any other program. If you have little or no mathematics you need to
learn less LATEX and still produce excellent documents.
I have been using LATEX for more than 20 years and have introduced many new users
to LATEX. Any one that has put some effort into learning it has found it useful. I must
admit that some persons to whom I recommended LATEX have simply refused to consider
using it on the grounds that they had heard that it was difficult to use. All that I ask is
that you give it a fair trial before you decide. I am confidant that you will find it useful
and that, in using it you will produce better looking documents.
Before the advent of computers, the author of a book or a paper submitted material to a
publisher in typewritten or even manuscript form. The publisher passed the manuscript
to a typesetter who prepared plates containing typeset material. The typesetter would
have set the material into parts, chapters, sections etc. as instructed. He would have
inserted headings, looked after pagination and almost all other aspects of the format of
the final publication. From the typesetter’s plates, proofs would be produced and sent
1.2 What is LATEX? 3
to the author and the publisher for proof reading etc. The author/publisher could then
suggest various amendments which the typesetter could include in an amended version.
The typesetter was responsible for all aspects of appearance of the final document. The
author was responsible for the content.
Typesetting was and is a highly skilled profession. If you have any doubt do a web search
for “typesetting qualification” and have a look at the contents of typesetting courses and
qualifications.
LATEX takes the place of the typesetter. You give it the contents of the document and it
will typeset it for you. You are only responsible for the content. You must, of course,
tell LATEX
• What type of document you are trying to produce i. e. an article, a book, a letter,
slides for a presentation etc. LATEX can produce many variants of these basic
documents.
• Divide your document into parts, chapters, sections, subsections etc. as required.
• Include and specify various special items such as lists, graphs and tables.
• That you need a contents list and/or lists of tables and/or figures.
In this computer age we can use the LATEX mark-up language to provide printer’s in-
structions to the LATEX system.
Given the text and LATEX mark-up LATEX will then typeset the document. As part of
this process LATEX
• will manage the numbering of parts, sections, etc., tables, figures, footnotes, equa-
tions and references to these items within the document.
• will amend these references if the material is amended, new items inserted or some
items moved or removed.
• list of contents,
• list of tables,
• list of figures,
• bibliography,
• indices and
• more
If you wish to amend your content or if you don’t like some of the result of the LATEX
typesetting you can of course amend things and rerun LATEX to produce revised out-
put.
Many publishers have LATEX specifications for their publications. To conform to these
specifications it is often only necessary to add a few instructions to your file. These
instructions will be provided by the publisher. If you wish to switch publishers you only
need to swap one set of instructions for the other.
• the basic LATEX and pdfLATEX typesetting programs. The pdfLATEX program is the
main focus of this book.
LATEX is not only a mark-up language for typesetting but is also a programming lan-
guage. While the LATEX program has basically remained fixed for a long time, the LATEX
programming language has been used to write packages that extend the facilities offered
by LATEX. I shall describe many of these packages as I progress.
Most of my work has been done on Microsoft systems with occasional use of Linux. Most
of this book has been written on a MS Windows 7 system. Part was written on a Linux
PC (Ubuntu 13.10). The LATEX input files produce identical results on Windows and
Linux1 . I do not have access to a PC running an Apple OS but I would be surprised
if it did not produce identical results. My recommended LATEX interface TeXstudio is
available for Windows, various Linux distributions, Mac OS X (experimental), FreeBSD
and as source code for compilation in other systems2
The first edition of Knuth’s The Art of Computer programming was published in 1969
and was typeset using a Mono-type hot metal type set. This process was standard at
the time and produced good results. When a second edition of the book was produced
in 1976 the Mono type hot metal process was no longer available and had been largely
replaced by photographic processes. Knuth was so dissatisfied with the proofs of the
new edition that he decided to set up a high quality digital type setting package known
as TEX. This was then used to good effect to produce revised versions of the book.
Development of the TEX package was continued until 1989 when version 3.0 was issued.
Only minor maintenance versions have been issued since then.
TEX is designed so that it can be readily extended. The set of extensions known as LATEX
was initially issued by Leslie Lamport in 1985 and revised in 1994 (Lamport, 1994). LATEX
1
It is interesting to note that this document can also be compiled on Nexus 7 (2012) and Asus TF100
Android tablets using the TeXPortal app available from the Google Playstore
2
The latest version may not be available at the same time in all operating systems.
3
See http://en.wikipedia.org/wiki/TeX
6 Introduction
is now much more often used than TEX. In particular the facilities available in LATEX
make a TEX system more accessible to beginners.
LATEX or other TEX based systems are almost the de facto standard for the preparation
and publication of books and journal articles in mathematics, computer sciences, Physics,
Chemistry and other Sciences. In economics many of the top journals (AER, Applied
Economics, Canadian Journal of Economics, Econometrica, Economica, International
Economic Review, Journal of Applied Econometrics (JAE), Journal of Political Economy
etc.) and Book Publishers (e.g. Springer, Taylor and Francis, Cambridge University
Press, Elsevier,) have special LATEX styles for books.
This book has been prepared with LATEX. It illustrates many of the things that you can
accomplish with LATEX.
• The current Chapter is an introduction and overview of LATEX. Section 1.7 contains
a simple example of LATEX input that will produce a paper which consists of text
alone. All that is missing is the text of the paper. If your paper consists of text
divided into sections subsections etc. you can cut and past into an editor and
simply add section, subsection etc. statements as required.
• Chapter 4 describes the basic syntax of LATEX. This chapter gives more details of
the structure of a LATEX document and how to specify various textual enhancements
(lists, font sizes, emphasised fonts etc.)
1.4 Outline Contents 7
• Chapter 5 shows how mathematical material is set with LATEX. This is a particular
strength of LATEX. No other program can produce superior mathematical output.
• Chapter 6 shows how to insert tables and similar material in your document.
• Tables, figures, text etc. prepared in other computer packages can be used in LATEX.
Chapter 9 shows
• Chapter 15 shows how to use the “helper” programs, bibtex and jabref, to prepare
and manage your bibliographies.
• Chapter 17 outlines some of the errors that may occur and how to solve such
problems.
8 Introduction
The list in section 1.4 does give the impression that LATEX is a very complicated program.
Any program that does as much as LATEX must be complex. It does, indeed, take a
considerable input of time and energy to acquire a good knowledge of LATEX. However
most beginners do not need that much knowledge. Many of the beginners that I have
introduced to LATEX were able to start on producing quite complicated documents in
a matter of hours. With each new paper, the beginner will add to his LATEX skills.
TeXstudio, as an interface to a LATEX system, is a great help to both beginner and
expert alike. It provides lots of menu items and buttons that give easy access to many
symbols and LATEX commands. These and other facilities in TeXstudio are described in
chapter 3.
1. Read this chapter to get an overview of LATEX. If you consider some parts of this
chapter difficult or not relevant you can probably ignore them on a first read and
return to them later if necessary. The same advice applies to much of this book.
2. First you must have a LATEX system installed on your system. If your IT depart-
ment supports a different LATEX distribution you should use it unless there is some
good reason not to do so. If you do not have a LATEX system installed you must
first install one. For the beginner using MS Windows I recommend proTeXt. In-
stallation details are given in section 2.2. A LATEX system is large and may take
some time to install. Be patient. If you are using Linux you might install the TeX
Live system. Versions of the TeX Live system are available in the repositories of
most Linux distributions. An updated version of TeX Live for any Linux distribu-
tion is available at www.tug.org. MacTex (http://www.tug.org/mactex/) is the
corresponding distribution for Apple Mac. The current version requires OS 10.5
Leopard or higher. Earlier versions which are compatible with earlier versions of
Mac OS can be downloaded from the same website.
3. You should then install TeXstudio to manage your text, insert the necessary mark-
up, and manage your interaction with the LATEX system. If you have installed
proTeXt you may need to update the installed version of TeXstudio. Simply down-
1.6 Notation 9
load the install program for the latest version, run it and follow the instructions on
screen.
4. If your document is mainly text you may be able to typeset most of it using the
simple example in figure 1.1 as a template. A more elaborate template is described
in chapter 11.
5. If required, read the parts of chapters 4 to 7 that cover what you need of text
formatting, mathematical symbols and equations, tables and graphs. You do not
need to learn these in detail as the help files, menu items, buttons and auto-
completion of mark-up can be a great help to both the beginner and the experienced
user.
1.6 Notation
In this paper we shall display LATEX input and output in boxes such as figures 1.1 and
1.2 respectively. In the text LATEX commands will be display in a fixed font as in the
following text.
\begin{equation}
x+y=z
\end{equation}
\input{filename }
you would substitute the actual name of a file for filename . In general you should
substitute the required value of a parameter, option, file-name or similar for material in
an example set in an italic mono-spaced font such as filename .
I have often used boxes to set examples of LATEX code. See, for example, figure 1.1. The
output of this LATEX code is given in the box in figure 1.2.
I also use boxes such as that in example 4.4 on page 52. The top portion of such boxes
contains the LATEX code producing the output in the lower portion of the box.
To access various features of Windows or a GUI based interface to LATEX we use a bold
font as follows.
10 Introduction
This implies that you click on Start, then All Programs, then MiKTeX 2.9. The
standard Open File in the editor would be given as
File ñ Open
Figure 1.1 contains the LATEX mark-up that is necessary to produce the document in
Figure 1.24 . Note the following points about the LATEX listing
• Any line starting with a % sign is ignored by LATEX . If the % sign is in the middle
of the line the % sign and anything after the % sign is ignored5 .
4
See also section 3.7 on page 37 where this example is compiled using the TeXstudio interface
5
If you need a % sign you can learn how to insert it in section 4.4, page 47). As we shall see, several
symbols have special meanings.
1.7 A Simple Example 11
\documentclass[]{article}
\title{A first \LaTeX \ document}
\author{A. N. Other \\ Number 1 University
\thanks{Thanks to those who aided me with this document}}
Contents
1 Introduction 1
2 Development 1
2.1 Early Developments . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.2 Later Developments . . . . . . . . . . . . . . . . . . . . . . . . . 1
3 Conclusions 1
1 Introduction
This is a basic LATEX document, More text.
2 Development
2.1 Early Developments
Text, text, text.
3 Conclusions
Text, text, text.
Installing LATEX
2.1 Introduction
If you already have a LATEX system installed on your PC you can probably skip this
chapter. If your system is old you should consider installing a new LATEX system or
updating your existing system.
I assume that you have full administrative rights on the PC on which you wish to install
your LATEXa system. If so, choose the option to install for all persons. If not, install for
a single user in a directory in which you have read, write and execute rights. If you find
that you can not run the install program there is a portable version of MiKTeX available
14 Installing LATEX
LATEX is a large package. The full LATEX system on the PC that I am currently working on
has 63, 555 files in 7, 027 folders and uses 1.96 GB of disk storage. For comparison the full
Microsoft Office Professional in the Program Files (X86) folder on the same computer
has 4, 524 files in 158 folders and uses 893 M B of disk storage. A full installation may
take over one hour on any but the fastest PC. Be patient!
Before installing LATEX I would recommend that you install ghostscript and gsview.
Ghostscript is an interpreter for the postscript language and PDF. Gsview is a Windows
interface to ghostscript. Gsview/ghostscript can be used to read and manipulate
postscript and pdf files and may be needed at a later stage. Installing them at this stage
will simplify the installation of some later additional programs that require access to
postscript routines.
You may download the latest version of ghostscript from www.ghostscript.com. There
are 32-bit and 64-bit versions of the program. The 64-bit version requires a 64-bit version
of Windows. The 32-bit version will run in both 32 and 64 bit versions of Windows.
Download the relevant installation program and run it. You can accept the defaults.
Once you have installed ghostscript you may download the gsview install program
from http://pages.cs.wisc.edu/~ghost/gsview/index.htm and run it. Again you
can accept the defaults. On some occasions, gsview may be useful as a pdf reader.
There are two comprehensive LATEX1 Windows installation programs – MiKTeX (currently
version 2.9) and TeX Live (A new version of TeX Live is issued annually). MiKTeX is
somewhat more accessible to beginners and easier to use and maintain. TeX Live is more
comprehensive but a little more difficult to install and maintain. I usually use MiKTeX on
Windows and TeX Live on Linux2 . If you have a recent TeX Live installation on your
1
The installation programs described here install complete TEX (or LATEX) systems which include
several variants of TEX (including LATEX), a large number of helper programs and additional packages.
Thus the terminology LATEX installation program is not very exact but we continue to use it to describe
what might be more accurately described as a TEX system.
2
I have recently installed Tex Live on Windows 8.1 and I have encountered no problems.
2.2 Installing LATEX 15
PC there is no reason why you should change to MiKTeX. The main visible difference
between the two systems lies in their management systems.
If you have access to a fast internet connection the easiest way to install LATEX is to
download proTeXt which is a user friendly MiKTeX-based distribution for Windows.
ProTeXt is available as a self-extracting archive (currently ProTeXt-3.1.3-060313.exe)
from https://www.tug.org/protext/. Download the file and save it in an appropri-
ate place. Open Windows Explorer and go to the downloaded file. Double-click on
the file and a protext directory is created. This directory contains the install program
(...\protext\Setup.exe). There is an excellent installation manual protext-install-en.pdf
in the Install subdirectory.
When you run the install program you will be presented with the window in figure 2.1 You
can use the Uninstall button to remove any previous version of MiKTeX. Clicking on the
relevant install button then installs MiKTeX. You will be offered several options
1. Package Set. I would have a certain preference for the installation of the complete
MiKTeX rather than the default base MiKTeX. Choosing the complete MiKTeX
option does make the install and later update process slower. If you do install a less
than complete system MiKTeX can download any missing packages in a document
provided you have access to the internet (see 3 below).
2. Installation Directory. I would recommend that you do not have spaces in your
installation directory. I would specify C:\MiKTeX-2.9\ rather that a subdirectory
16 Installing LATEX
3. Settings Here you specify your default paper size and whether you want to install
missing packages on the fly (If you have missing packages specified in your LATEX
document do you want MiKTeX to install them from the web. The default is to
download after asking for and obtaining confirmation.
You may also download a MiKTeX installer from http://miktex.org/. If you choose
that option the install process is somewhat different. The MiKTeX manual, which covers
this installation, may be downloaded from http://miktex.org/docs.
The first advantage of MiKTeX is that it allows the easy installation of a comprehensive
range of LATEX related programs and packages. A less obvious advantage is that it
provides user friendly facilities for updates, extensions and other maintenance tasks on
your system. If the MiKTeX system is up to date then you can postpone maintenance
until a later date. If this is so, you may skip the remainder of this chapter and return to
it later3 .
Under Start ñ All Programs ñ MiKTeX 2.9 the following facilities are avail-
able
MiKTeX 2.9 ñ Previewer I do not use this item. It calls the yap previewer for .dvi
files
MiKTeX 2.9 ñ TeXworks TeXworks is the standard editor distributed with MiK-
TeX. This editor is more suitable for those with a good knowledge of LATEX.
MiKTeX 2.9 ñ Help ñ FAQ A pointer to some frequently asked questions This is
worth reading.
MiKTeX 2.9 ñ Help ñ Manual This is the MiKTeX manual. This is a compre-
hensive document. It contains detailed installation instructions that are of interest
to all users and a lot of other material that may not be required by ordinary users.
3 A
LT EX packages are maintained by individual agents and updates are available as new versions of
individual packages are completed. The latest version of the MiKTeX install program may not contain
the latest updates. The update procedure does update any packages that have been installed.
2.3 MiKTeX Maintenance 17
MiKTeX 2.9 ñ Maintenance ñ Package Manager This and the next two items
are relevant to maintenance of systems/packages which have been installed by those
without administrator rights. If you have administrator rights (have installed for
all users as recommended) then use the Admin links that follow.
MiKTeX 2.9 ñ Maintenance (Admin) ñ Update (Admin) This is the main up-
date procedure provided by MiKTeX. It provides a way of keeping your MiKTeX
system up to date. I update my system every few months. The longer you wait the
longer the adjustment process takes. I know several persons who have not updated
their system for a considerable time. If you have an out of date system, encounter
problems and seek help from a local expert it is likely that his system may be more
up to date and he may not be able to replicate the problem. My recommendation
would be to keep your system reasonably up to date but not to update when you
are trying to meet a deadline. Probably the best time to update is when you have
finished a project and are about to start a second4 .
Selecting this item brings up the window shown in figure 2.4. Here you select
the mirror site (package repository) from which you wish to obtain your updates.
4
I have never encountered any problems with these updates but it is probably better to be sure than
sorry.
18 Installing LATEX
Generally the first option (Use the nearest package repository) is best. If, for some
reason this fails you may try the third option (Let me choose a remote package
repository) and choose another near repository. The second option (use the package
repository used on previous update) may be used if you have had problems with
the nearest repository. If you are working through a proxy server you will need to
use the Connection Button to enter details specific to that proxy. These details
are site specific and you will need to contact your site administrator for details. If
you have access to a local copy of the package repository you may enter details on
the lower half of this window.
Select Next to bring up the window in figure 2.5. This is a list of the packages that
may be updated. Note that this list may take some time to appear. Be patient!
When the list appears select Next to download the packages. Figure 2.6 shows
the progress of the downloads. Again this download may be a slow process. When
the download is completed MiKTeX may spend some time rebuilding the system.
The actual time taken depends on the speed of your download and of your system.
Again be patient.
Occasionally there is an update to the main MiKTeX binaries. In this case only
the binaries will be ticked for update in figure 2.5. In this case finish the update
process updating only those binaries and when this update is finished rerun the
update system again to update any packages that are out of date.
MiKTeX 2.9 ñ MiKTeX on the Web ñ Give Back This is an invitation to sub-
scribe to the upkeep of MiKTeX
MiKTeX 2.9 ñ MiKTeX on the Web ñ Known Issues This and the next two items
are links to various help available for MiKTeX
• By downloading and running a net install program. This program sets options
and downloads the LATEX system as it installs it https://www.tug.org/texlive/
acquire-netinstall.html
• Downloading a large iso file (currently about 2.6 GB) Writing this to DVD and run-
ning the install program from the DVD. The DVD contains installation and man-
agement instructions. There is an easy to use installation program for windows that
installs a complete system. https://www.tug.org/texlive/acquire-iso.html. This
DVD is updated each year.
• The DVD may be purchased from the TeX Users Group. If you subscribe to the
TeX Users Group you will receive a copy of the DVD each year that you subscribe.
The TeX Live DVD contains several installation programs which allow various levels of
customisation of the install. A TeX Live installation can be updated using the tlmgr
program which will have been installed during the install process.
Full instructions on the installation and maintenance of TeX Live are given in the
texlive-doc directory of the DVD and at https://www.tug.org/texlive/doc.html.
2.5.1 Linux
Most Linux distributions will have a TeX Live package in their package depositories.
You can use the appropriate package management software to install the distribution.
On some occasions this package may be rather old. In these circumstances you can
download the TeX Live installation material described in section 2.4. The DVD con-
tains installation scripts for a variety of operating systems. If you install this TeX Live
distribution you will have access to the tlmgr management and maintenance program.
As far as I know, tlmgr is not available in any of the packages available in the Linux
depositories.
Some persons may be concerned that installing LATEX in this way may cause problems
2.5 Installing LATEX on other Operating systems 23
with their package management system. If you are concerned you can install in a sub-
directory of your home directory (For details see the manual).
TeXstudio packages may also be available in the package depository of your Linux distri-
bution. Alternatively deb and rpm packages for several Linux distributions are available
at texstudio.sourceforge.net. Kile is an alternative KDE based interface to LATEX
which Linux users may prefer to TeXstudio5 . Experienced Linux users may prefer to use
Emacs (and AucTeX) or Vim.
2.5.2 Apple OS
On Apple iOS the TeX Writer app (http://www.texwriterapp.com/) lets you write,
compile and preview TEX documents on an iPad/iPhone, and no internet connection is
required. The app contains a dedicated keyboard. It synchronises with Dropbox allowing
you to share files with PCs and other mobile devices. The app only supports a limited
number of packages but additional packages can be included in the working directory. I
have installed the app on an iPad and successfully compiled several test files.
On Android the apps TeXPortal and TeXpert provide a LATEX system. TeXPortal
provides the LATEX compiler and TeXpert an edit-compile-view interface to the com-
piler. As a test of this system I loaded a near complete version of this book on a Nexus 7
(2012) tablet.and successfully recompiled the document. On the initial run missing pack-
ages were downloaded and installed. While subsequent runs were slower than on a PC
the edit-compile-view system was usable even for a large document such as this.
The TeX Writer app was recently made available for Android. At this stage I have not
used this app on Android.
5
Installing Kile on windows requires the prior installation of a KDE system. see http://
sourceforge.net/apps/mediawiki/kile/index.php?title=KileOnWindows
24 Installing LATEX
The purpose of this section is to explain some of the processes that one can complete using
a few mouse clicks in TeXstudio. Before the advent of GUIs it was necessary to compile
your LATEX files using the DOS console or a Linux terminal process. An understanding
of these processes would be helpful if you have a non-standard LATEX installation and
need to configure the GUI program that you are using.
of this section. First the basic LATEX program (latex.exe) acts on the .tex file to pro-
duce a.dvi file. Note that in the example in the box there is a report “LaTeX Warning:
Label(s) may have changed . Rerun to get cross-references right.”. This is
explained in footnote 6. latex is then run a second time to resolve the unresolved
references.
The .dvi (device independent) file is very similar in purpose to a modern .pdf file in
that it contains all the information necessary to produce the same final output regardless
of the output device used. Most LATEX distributions come with a .dvi viewer and this
was often used to view the .dvi file and check the progress of the work. The dvips.exe
program transforms the .dvi file to postscript format (.ps). ps2pdf.exe then transforms
the .ps file to pdf format.
This book has been produced using the pdflatex.exe process. At first sight one might
ask why one would ever use the “traditional” approach. The choice of approach often
depends on the format of the graphics files inserted in the document. However pdflatex
supports only graphics files in .pdf, .png and .jpg formats. Files in other formats must
be transformed to one of these formats before being included in a LATEX document which
is to be processed by pdflatex.exe.
The right hand side process only includes graphics in .eps or .ps formats. If your
econometric software produces graphics in .eps then this approach may be preferable.
Some advanced users may also embed postscript in their LATEX files. In this case the
second approach should be used. Most economists, social scientists etc. are unlikely to
need these facilities.
MiKTeX contains a utility epstopdf.exe which may be used to convert .eps files to pdf.
There is also a way to arrange that that .eps files are automatically converted before
running the pdflatex.exe program We shall deal with this matter in greater detail in
chapter 7.
c:\Work\IntroLaTeX>pdflatex main
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (MiKTeX 2.9)
entering extended mode
...
lots of deleted output
26 Installing LATEX
...
Output written on main.pdf (191 pages, 3251828 bytes).
Transcript written on main.log.
c:\Work\IntroLaTeX>
2.6 A LATEX system 27
c:\Users\frainj>cd /Work/PhD/Thesis/Temp/
cd /Work/PhD/Thesis/Temp/
c:\Work\PhD\Thesis\Temp>latex thesis_main_5.tex
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
)
(see the transcript file for additional information)
Output written on thesis_main_5.dvi (230 pages, 1239452 bytes).
Transcript written on thesis_main_5.log.
c:\Work\PhD\Thesis\Temp>latex thesis_main_5.tex
c:\Work\PhD\Thesis\Temp>ps2pdf thesis_main_5.ps
c:\Work\PhD\Thesis\Temp>
CHAPTER 3
3.1 TeXstudio
• A way of entering and editing your text. In TeXstudio the standard File, Edit,
Search etc. menu items work in the same way as in a Windows program1
• In the editor LATEX commands are colour highlighted to distinguish them from the
text.
• Auto-completion If you type the first letters of a LATEX command a list of possible
completions appear in a drop-down box. Command completions may be selected
from the drop-down box using the up/down cursor or mouse and the enter key. If
the list is long you can add more letters to the start of the command which will
reduce the list of possible completions.
• If you hover the cursor over certain basic LATEX commands a bubble (tool-tip)
appears and displays summary syntax and help for the command.
• If you right click over a LATEX command the resulting drop down menu contains
an item “open package documentation (LaTeX-document)”. This link brings you
to the material on the command in Berry et al. (2012). Help for LATEX commands
is also available through the help menu item.
• Wizards are available which enable you to construct or insert more complicated
structures (e. g. tables, graphs) using a system of menus and dialogues.
• If If you right click over a command from a LATEX package the resulting drop down
menu contains an item “open package documentation (package name)”.
• You can view the structure (list of chapters, sections, subsections etc. as appro-
priate) of your document in a separate structure window. This structure window
allows you to easily go to chapters, sections, subsection etc. by right-clicking on
the relevant entry in the structure.
• TeXstudio helps with setting up and using internal references in your documents
to sections, figures, pages, footnotes, the bibliography etc.
• A previewer which allows you a live view of sections of your document. For example,
if you are setting a complicated mathematical expression you can set preview on
for that equation and have a live view of the effect of your mark-up as you enter it.
• An integrated pdf viewer that is linked to the original LATEX file. If you successfully
compile your file place the cursor over a word in the LATEX file and |CTRL|+left
mouse button transfers you to the corresponding place in the pdf file or opens
the pdf file at that point. If you are reading the pdf file the corresponding action in
the pdf file returns you to the LATEX file at the selected word. In either file clicking
the right mouse button gives a context menu which allows the same transfer.
3.1 TeXstudio 31
• TeXstudio provides menu items that process the LATEX file and produce the re-
quired output (in pdf format in our case). Many of the more complicated aspects
of this process are handled automatically by TeXstudio. For example, if a biblio-
graphic database has been amended since the last run it will know that it has to
rerun and will rerun the generation of the bibliography.
• There is a row of icons below the menu bar. These icons give quick access to
several features of TeXstudio and LATEX. If you hover the mouse over these icons
their function is displayed. In the default set-up in TeXstudio (TeXstudio 2.7.1
(hg 4491+:c8f436e2da6d+) development version) these icons are set in 7 groups or
tool-bars.
Most users will not require to change any of these tool-bars. They will find that the
existing tool-bars, menu items and character icons provide the required access to LATEX
Item 3(a) (Build and View) is often all that is needed to compile a LATEX document.
As mentioned earlier it is best to install your LATEX system before you install TeXstu-
dio.
TeXstudio is available for and runs in many computer platforms including MS Windows,
Linux and Apple OS. TeXstudio was started in 2009 as a fork of TeXmaker. It is some-
times criticised as being too cluttered. I feel that a lot of this clutter is of considerable
help to a beginner. If you want a more simple interface try TeXworks (see section 10.3)
which is simpler but does not offer the same help to a beginner.
3.2 Installation
3.2.1 MS Windows
3.2.2 Linux
Most Linux package repositories have a TeXstudio package. If the version available
for your distribution is recent then you can use your distribution’s package manager to
install the program. It is possible that a newer version for your distribution is avail-
able on http://texstudio.sourceforge.net/. If all else fails you can compile the
source code. Instructions are available at http://sourceforge.net/apps/mediawiki/
texstudio/index.php?title=CompileTXS.
3.2.3 Apple OS
The main features of TeXstudio are described in that diagram. Across the top is the
usual type of menu system that is familiar to all users of an MS Windows or other GUI
(Graphical User Interface). Below this is a row of icons that give quick access to various
features of TeXstudio. These are described in section 3.1.
• The main edit window on the right where one prepares the document
• The second window displays the structure of the document (i. e. list of chapters,
sections subsections, labels etc.) It is possible to navigate to a particular section
by left clicking on any item in the structure window
The figure shows two sets of icons at the left of the edit window — The Central tool-bar
described in section 3.1.
• The top set contains some text formatting facilities (e. g. bold, italic, underline,
justification). Select the text that you want to format and click on the appropriate
button.
• The second set contains some math formatting icons which we shall describe in
chapter 5.
On the left of the structure window is a set of icons that gives access to about 400
mathematical and other symbols. Clicking on any of these icons replaces the material in
the structure window with symbols. Clicking on any of these symbols enters the LATEX
code for the symbol in the LATEX document being edited.
If you have used the installation procedures described here it is likely that TeXstudio
will be configured properly by the installation program. The menu item Options ñ
Configure TeXstudio allows one to reconfigure the system. For example, suppose that
TeXstudio can not find the program pdflatex.exe. Select commands from that win-
dow. The button on the extreme right enables you to navigate to the pdflatex program.
Press OK and the new location and program will be recorded for future use.
MiKTeX system or some other relevant program you may need to change some of the
program references.
The display of line numbers can be turned on or off using the Advanced Editor config-
uration that can be turned on by ticking the Show advanced options in the Configuring
TeXstudio window.
Synchronizing LATEX and the generated pdf output file is is one of the most useful in-
novations available in a good modern LATEX interface. I would expect that
1. If i make an amendment to my LATEX file and compile the resulting pdf file should
be opened at the corresponding point. (I presume that the cursor in the edit pane
36 Installing and using TeXstudio
TeXstudio uses the syncTeX procedure to synchronise your LATEX file and the pdf out-
put file. When you compile your LATEX file with the option --syncTeX=1 you create a
file filename.synctex.gz. This file contains all the information necessary to navigate
between the LATEX file and the pdf.
1. If you right click at any point in the LATEX file and select Go to PDF in the drop
down menu you will be transferred to the corresponding point in the pdf file.
2. Similarly If you right click at any point in the pdf file and select Go to Source
in the drop down menu you will be transferred to the corresponding point in the
LATEX file.
3. When you run the Build and View process the pdf file will be opened at the
point corresponding to the position of the cursor in the LATEX file.
In figure 3.3, the equation in lines 91 to 94 have been selected. Right clicking on the
selected area and then selecting Preview Selection/Parenthesis (or Alt+P) displays
the output of the selected area below the selected area. You can then edit within the
selected area and watch the effect of your changes as you make them. You turn preview
off by right clicking and selecting Clear Inline Preview.
In Windows TeXstudio can use the textablet program to translate mathematical equa-
tions handwritten on the screen to LATEX input. This uses the Math input Panel available
in Windows 72 . It did not work well for me using a mouse to write some mathematics. I
2
I presume that this also works for Windows 8 but I have not been able to check.
3.7 A simple Example using TeXstudio 37
am sure that this would work better with a touch sensitive screen and a stylus or using
a graphics tablet. Given the greater availability of touch screens and tablets this or a
similar development might become more available and usable.
Figure 3.4 is a copy of figure 1.1. Start TeXstudio and copy the file in figure 3.4 into the
edit window. Save the file in a temporary window. Click on the Load and View icon
and you should get something very similar to figure 1.2. You can now experiment with
this file (e. g. Add your name and affiliation, add simple text).
38 Installing and using TeXstudio
In going from .tex to .pdf files LATEX generates a lot of subsidiary files1 . If your main
LATEX file is called money.tex these subsidiary files are placed in the same directory, have
the same first name but have a variety of extensions (.aux, .bbl, .log, .toc etc.). For
the time being you do not need to worry about these files. If you are concerned about disk
space TeXstudio has facilities to remove them after the .pdf file has been produced. New
versions of these intermediate files, produced by later runs, simply overwrite existing files.
Some of theses intermediate files may be of use if you encounter a problem. In particular
1 A
LT EX processes a file by passing through it from start to finish. On its first run it may encounter
references to equations, tables, figures, pages etc. that have not yet been processed. Such references are
unresolved at the first run. The first run also generates an auxiliary (.aux) file. This file contains all the
material necessary to resolve the unresolved references and compile a table of contents, lists of tables
and figures, etc. A second pass of the LATEX program then reads the .aux file as the \begin{document}
command is processed thus allowing all references to be resolved. In circumstances such as this, TeXstu-
dio knows it must run the LATEX compile process twice. With some other LATEX interfaces the user may
be responsible for running the LATEX programs more than once if required. Other files are generated if
you are generating a table of contents, table of figures, list of tables, indices, bibliographies etc. If you
are using the \longtable package and you find that your tables are not properly aligned you may need
to run your compile program another couple of times.
40 Basic LATEX Syntax
log files will contain a record of any errors or warnings issued by the LATEX compiler
during a run.
Some students will try to put all the files for a course in one directory. The directory
may contain computer scripts, reports, term papers, notes etc. There may eventually be
hundreds of files in such a directory. Eventually an important file will get lost or over-
written. Following Murphy’s lay this will happen on the day before an important exercise
or paper is due. You can avoid these problems if you set up a new separate directory for
each set of exercises, term project, document or paper that you are producing. In the
directory, for a LATEX document, I would include the main .tex file(s) for the document.
If there were a small number of graphics files to be included in the document I might
also include these here. If there were a fair number of such files I would probably include
them in a subdirectory of the LATEX document directory.
Don’t forget to backup your files. After an editing session I usually make a backup copy
of what I have done. It is relatively easy to copy (backup) a project directory to a flash
or external hard drive, to a cloud system such as dropbox, sugarsync, box etc. or to
a college or company server. If each item of work is in a separate directory backup is
easier to manage. The more advanced user should consider some form of version control
(e. g. git). Systems such as this are useful when several persons are collaborating in a
project.
I usually run the Build and View process frequently as I compose my document. If this
process shows errors it is easier to find and cure the error if it is in a recent block that
has been added to the file.
Do not be afraid to experiment. If you make some changes to a document and they cause
problems it is usually easy to reverse the change. If you are concerned that you may
may damage a document, make a copy of the document directory and experiment on the
copy. If you do encounter some problem and there is a local expert ask his help. He was
a beginner at some stage himself.
A preamble which sets out the type of document (article, book, report, presentation,
letter etc.). It may also load various supplementary packages (extensions to LATEX),
sets defaults for the document and optionally gives details of the document title
and author(s).
4.1 Some Preliminaries 41
The text of the document which contains the main content of the document.
A modern LATEX editor such as TeXstudio, or the other interfaces described in Chapter 10,
provides facilities to automate most of the preparation of a LATEX document. There are
several ways to start a LATEX document.
2. When I first used LATEX I copied the preamble of a LATEX document from a col-
league’s document and then proceeded to add my text. At the time, I did not
understand the purpose of many of the \usepackage statements included in the
preamble. I knew that they added extra facilities. In all likelihood, I did not use
many of the extra facilities provided by the packages. While this may have caused
some minor inefficiency it did not interact with my document preparation. If your
document is very simple you could use the preamble to the documents in figure 3.7
or the more realistic examples in Chapter 11 to 13. Alternatively if your organisa-
42 Basic LATEX Syntax
tion has a local LATEX expert he may have a template that satisfy any requirements
of your local organisation (e. g. page layout, formats, corporate logos, trademarks
etc.).
4. You can, of course use a combinations of the relevant LaTeX menu items and typing
to produce your preamble.
5. Your preamble may be based on the sample preambles are given in Chapters 11
to 14
In the next four sections I will give some details of the preamble and main text parts of
the LATEX paper. Mathematical material, table generation and graphics are covered in
chapters 5, 6 and 7 respectively.
The first of these is the most important for the time being. The end of a such a command
is any non-letter. If a command is ended by a space all spaces following that space are
ignored. The impact of this is discussed in subsection 4.4.3
Mandatory Mandatory parameters, if required, are included between braces, ({ and }).
Some commands do not require mandatory parameters If more than one mandatory
parameter is required each parameter is given within a separate set of braces.
4.3 The Preamble 43
Some commands need no parameters, some need only optional parameters, some need
only mandatory parameters and some need both.
Commands are case sensitive. For example the command \gamma produces γ while
\Gamma produces Γ. Extra spaces at the end of a command are ignored.
There are two variation of some LATEX commands, the standard version \command and
a starred version \command* . The two variations will have the same basic functionality
but with important differences which I shall explain as we encounter them.
4.2.2 Comments
Any line starting with a % is regarded as a comment line and is ignored by the LATEX
compiler. If the % sign occurs in the middle of a line that part of the line after the % is
also ignored3 .
The first statement in the preamble is the documentclass command. The basic syntax of
this statement is
\documentclass[options]{class}
2
There is a small trap here. You may encounter the topic of this footnote at some stage. It will make
more sense to study it when you are more familiar with LATEXcommands.
Suppose the text after the command begins with a [. LATEX will mistake this for the start of an optional
parameter and will give an error when compiling. The solution is to enclose the [ within braces, {[}, if
it is not the start of an option for a command.
Many commands have a second version that has an added * . If you are using the version of the
command without an * and the text following the command starts with an * you should include the *
within braces ({*})
3
In the default in TeXstudio lines, which are longer than one screen width are wrapped onto the next
line on the display. In TeXstudio line continuations are marked by a ë symbol in the column to the left
of the edit window. This column contains the line number of the file in the window. Most LATEX user
interfaces and text editors behave or can be configured to wrap long lines in this manner.
44 Basic LATEX Syntax
The standard values for the obligatory parameter class are book, report, article,
letter or slides. As might be expected these are used to produce books, reports,
articles, letters and slides.
The slides class has to all extent been replaced by the beamer class which is provided
by the beamer package4 . This package is likely to be of particular interest to readers and
is covered in detail in Chapter 14.
Many other classes are made available through the package system. A standard LATEX
distribution contains about 250 such packages. There are classes for various journals,
technical papers, publisher’s book specification etc. The beginner can concentrate on the
article, book, beamer and possible the report class.
Changing one’s format to satisfy the requirements of a publisher who specifies a LATEX
class often requires little more than changing the documentclass statement5 . and in-
cluding the relevant usepackage statement.
options is a comma separated list of options. The most important options to the
\documentclass statement are
10pt | 11pt | 12pt sets the default font size for basic text in the document. For the basic
classes the default is 10 point. This book is set in 11 point.
oneside | twoside When class is book this allow one to use separate formats for left and
right hand pages. the default is oneside for the article class.
onecolumn | twocolumn uses single column or double column text. onecolumn is the
default.
leqno sets equation numbers on left hand side of equation if allowed by document class.
4
The powerdot package is an alternative presentation package for LATEX. The interested reader should
consult Voss (Voß) (2012b)
5
A publisher may also specify a special format for the bibliography and his class will usually be
accompanied by an appropriate file that will automate the process. (See chapter 15)
4.3 The Preamble 45
This list of options is not comprehensive. Options set in the preamble are the defaults
for the entire document. Certain options to be used when loading various packages can
also be included here. Some optional packages may change the defaults. The defaults in
such cases are given in the package documentation.
Additional options for some packages may be included in the \documentclass statement
for passing to packages which are loaded later.
Various packages (extensions to basic LATEX) can be loaded in the preamble using
\usepackage[options]{package} statements. In the display box below six packages are
loaded.
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{longtable}
\usepackage[a4paper,left=3.5cm,right=3.5cm,top=5cm,bottom=5cm]{geometry}
\usepackage[breaklinks,pagebackref]{hyperref}
bm Provides bold mathematical symbols. amsmath, amssymb and bm are packages provided
by the American Mathematical Society and should be included in almost all pre-
ambles unless you have some specific reason for excluding them.
longtable Provides facilities for the setting of long tables which stretch over several
pages.
46 Basic LATEX Syntax
geometry The geometry package provides facilities to change margins and other features
on the printed page. The example above specifies a left margin of 3.5 cm., a right
margin of 3.5 cm., a top margin of 5 cm. and a bottom margin of 5 cm. In general
you should try to avoid this facility as the default output from LATEX is usually
very good.
hyperref This package provides facilities for the use of hyperlinks in the document. If
the hyperref package is loaded it should be the last package loaded. If, in text, a
hyperlink will not fit on the current line the breaklinKs option breaks the hyperlink
across lines. The pagebackref adds ‘backlink’ text to the end of each item in the
bibliography as a list of page numbers where the item is cited.
I shall deal with these and a selection of other packages as we discuss various other
features of LATEX. Chapter 8 contains details of a selection of packages that you may
find useful. I would include these packages in all of my documents.
Title and Author details are generally entered in the preamble. The display box below
repeats the title and author details from the listing in figure 1.1.
\title{details} where details is the title of the paper. If you wish to spread the title
over several lines use \\ to show where you want the line to break.
\author{details} where data is the name and affiliation of the author. If you wish to
spread this material over several lines use \\ to show where you want the line to
break. If you have multiple authors you can use the \and statement to specify the
second and subsequent authors
4.4 Document Text 47
\date{date details} If this is omitted the current date is entered below the title and
author details. If it exists date details as in the file is written there. If you do
want something other than a date to follow the author’s details you can also enter
this here
\maketitle in the main text of the article uses this material to generate a title page.
In the preamble a user may make various adjustments to LATEX defaults. These adjust-
ments then hold throughout the entire document. An example of such an adjustment is
the use of the geometry package above. Unless you have a very good reason to make
such an adjustment keep to the defaults6 .
The actual content of your document is set out between \begin{document} and \end{document}
statements as in the box below.
\begin{document}
text of document
\end{document}
6
For example if you are constrained to produce a document of less than 10 pages you might wish to
use smaller fonts and margins to accommodate more text on a page. You might find that if you really
reduce the size of your document it might be easier to read more people might read it.
48 Basic LATEX Syntax
. I will postpone describing math mode until chapter 5 and will concentrate on text
mode in the remainder of this chapter.
In keying the text of your LATEX document you may use any of the characters on your
keyboard. However the ten keys
# $ % & ˜ _ ˆ { } \
have special meanings7 . They should not be used in ordinary text. If you include one in
error and your document compiles you will get some unexpected results from the point
where the special character was included. If the document does not compile you will
get an error message. If you do need one of these characters in your document they can
be produced using the LATEX commands specified in Table 4.1. For example if you wish
to produce a # in your document enter \#. Forgetting about special characters is one
of the most common errors that beginners make. If you copy text from a non LATEX
document into a LATEX document it is possible that the copied material may contain
some of these special characters and you will have to replace them by the substitutes in
Table 4.1.
The space character and the ENTER key have a special meaning in a LATEX file.
• You can separate the words in your document by any number of white spaces
and these will be regarded as one by LATEX. For the purpose of separating words
an individual ENTER key is the same as a space key. Two or more such space
characters are the same as one.
7
We shall learn about these special meanings as we progress
4.4 Document Text 49
Character Produced by
# \#
$ \$
% \%
& \&
~ \textasciitilde
_ \_
^ \textasciicircum
{ \{
} \}
\ \textbackslash
• You end a paragraph with two consecutive ENTER keys. This will leave a blank
line in your input file. Equivalently, one is often instructed to end a paragraph
with a blank line.
Spacing in printed material is sometimes a matter of taste and partly a matter of type-
setting practice. Occasionally LATEX produces spacing that one might think could be
improved. Table 4.2 gives details of the commands that can adjust spacing. In general
one should minimise the use of these commands.
Command Produces
~ Inserts an inter-word space so that the line can not be broken between
the two words.
\, Inserts a very narrow space
\: Inserts a medium space
\␣ Inserts a standard inter-word space. ␣ is a white space character
\! Inserts a negative thin space
\; Inserts a thick space
\@ Inserts an end of sentence space after a full stop which is preceded by a
capital letter.
In any document the words on a line are separated by an inter-word space. In the
traditional approach in English documents sentences are separated by a wider space.
This is the approach used in this document. In some other languages and in modern
English usage sentences are separated by a standard inter-word space.
50 Basic LATEX Syntax
The default in LATEX is the traditional approach. When LATEX encounters a full stop
followed by a white space it assumes that the full stop signifies the end of a sentence and
it inserts extra space. If the full stop is preceded by a capital letter it assumes that the
full stop marks an abbreviation and inserts a standard inter-word space. Usually this
works well but occasionally the rule does not work8 .
In the first line of output in example 4.1 there is to much space after the full stop. Here
LATEX thinks that the sentence ends at the full stop and inserts an inter-sentence space
after the full stop. This is corrected by the insertion of a standard inter-word space after
the abbreviation. Note that there is no space between the abbreviation and the \␣.
In example 4.2 LATEX thinks that the period is attached to the abbreviation and puts a
standard inter-word space after the period. Inserting \@ before the period informs LATEX
that this is the end of a sentence and that one should insert and extra space.
If you wish to use the more modern approach keeping a standard inter-word space at the
end of a sentence, insert
8
The containing box of numbered examples such as example 4.1 is divided into two parts. The upper
part contains LATEX code while the lower part contains the result of compiling that code.
4.4 Document Text 51
\frenchspacing
in the preamble of your document or at the point where you wish to begin the traditional
approach. If you wish to return to the traditional approach insert
\nonfrenchspacing
Example 4.3 illustrates three ways in which compound abbreviations can be treated.
i.e. J.C.Frain \\
i.\,e. J.\,C.\,Frain \\
i.\,e. J. C. Frain
i.e. J.C.Frain
i. e. J. C. Frain
i. e. J. C. Frain
1. In the first line the abbreviations are printed without any spacing between the parts
of each abbreviation. While the i.e. may look OK my name does not. (Note that
as explained above the period after the e is taken as marking the end of a sentence
and a wider space is inserted.)
2. In the second line a thin space is inserted after the i., the J. and the C. This
approach would be followed by the traditional typesetter who allows extra space
after a sentence. Apart from my bibliography this is the approach used in this
book.
3. In the third line full spaces are given after my initials. This is the approach used
by the bibliography style used in this book.
52 Basic LATEX Syntax
In general these commands should be used sparingly. There is one exception. A LATEX
command ends in a space and multiple spaces are regarded as a single space. The com-
mand \LaTeX outputs LATEX. The code \LaTeX document produces “LATEXdocument”
which is missing the space between LATEX and document. To achieve the required result
insert a space command \␣ . (e./,g. \LaTeX\ document produces ) “LATEX document”
which is correct. Note that \LaTeX \ document produces ) also produces the same text
“LATEX document”.
The command \\ ends a line and text continues on the next line. The command \\* is
the same as the ordinary \\ command except that it tells LATEX not to start a new page
until the next line has been output.
Recall that a new paragraph is indicated by a blank line. You can also end a paragraph
with the \par command.
The command \vspace{length} inserts a vertical space of length length. If the command
is given in the middle of a paragraph the space is inserted after the end of the current
line. If it is inserted at the end of a paragraph then the vertical space is inserted before
the next paragraph. Part of the space that would carry beyond a page break is omitted.
If you wish to carry the unused part of the space on to the start of the following page
use the \vspace*{length}. Length can be given in any of the units recognised by LATEX
(See section 16.3).
The command \hspace{length} inserts a horizontal space of length at the point at which
it occurs. That part continuing beyond the end of a line is deleted. The \hspace*{optlen}
continues the space beyond the end of the line onto the next line.
The command \hfill inserts sufficient space so that the following text is right justified.
The boxed example 4.4 illustrates the use of these space-making commands
4.4 Document Text 53
{The command \\ ends a line and text is continued on the next line.\par
\vspace{1cm} %inserts a vertical space of 1 cm.
The command
ends a line and text is continued on the next line.
If your document contains only textual material you are now almost ready to produce it
in LATEX. The proper use of LATEX demands that you structure your document. If you
are writing a book (book class) there is provision to divide your book into
• parts
• chapters
• sections
• subsections
• sub subsections
• paragraphs
• sub paragraphs
Not all books have the complete structure. For example, this book has chapters, sections
and subsections. Many books only have chapters and sections and some only chapters.
For the article class parts and chapters are not available.
54 Basic LATEX Syntax
The structure of a book or thesis can be more complicated than this. The book class
provides three commands \frontmatter, \mainmatter and \backmatter.
After the \mainmatter command one places the main content of the document.
After the \backmatter command one places the appendix (\appendix command), bib-
liography and similar items
If you are writing an article the first thing that you should do is specify the structure
of your document. By structure we mean the division of the paper into sections and
subsections. You may of course insert new or delete existing sections or subsections as
you write. Have a look again at figures 1.1 and 1.2.
where the longer section title (bounded by { and }) will appear in the paper as a heading
on the section. The shorter section title (bounded by [ and ]) will appear in the table of
contents. If you do not specify a Shorter section title the Longer section title is
used in the contents list. Do not number your sections. LATEX will do this for you.
where the optional and mandatory fields are similar to those for the \section com-
mand.
The current chapter, section and subsection headings and their listing in the contents
were inserted by the commands in the following box.
4.4 Document Text 55
% At start of Chapter
\chapter{Basic \LaTeX\ Syntax}
% At start of Section
\section{Document Text}
% At start of Subsection
\subsection{Document Structure}
\tableofcontents
• Various commands are available by clicking on the icons on the button and icon
bars.
document. If you hover the mouse over some LATEX commands a box is displayed
which gives summary help for the command. These facilities are also available
for some environments. If you start to type \begin{it you will be presenIted
with a drop-down which includes the itemize environment. If you select this both
the begin and end statements for the itemize environment will be transferred to
your document leaving you to enter the contents of the environment. There is a
convenient keyboard short-cut for \item (Ctrl+Shift+i). Many other keyboard
short-cuts are available in the default set-up. These are itemised in the drop-down
menus in the menu bar. It is also possible to configure your own short-cut menus.
• TeXstudio Wizards provide a easy way to enter some of the more complex structures
such as tables, arrays, graphics etc.
To illustrate the LATEX help system available in TeXstudio the help for the \section
command is given in the box below.
Sectioning commands provide the means to structure your text into units:
\part
\chapter (report and book class only)
\section
\subsection
\subsubsection
\paragraph
\subparagraph
\chapter[toctitle]{title}
4.4 Document Text 57
In addition to providing the heading title in the main text, the section title can
appear in two other places:
You may not want the same text in these places as in the main text. To handle this,
the sectioning commands have an optional argument toctitle that, when given,
specifies the text for these other places.
Also, all sectioning commands have *-forms that print title as usual, but do not
include a number and do not make an entry in the table of contents. For instance:
\section*{Preamble}
The \appendix command changes the way following sectional units are numbered. The
\appendix command itself generates no text and does not affect the numbering of parts.
The normal use of this command is something like
\chapter{A Chapter}
...
\appendix
\chapter{The First Appendix}
\setcounter{secnumdepth}{level}
suppresses heading numbers at any depth > level, where chapter is level zero.
(See \setcounter.)
Recall that it does not matter how many spaces or lines are used to separate words sen-
tences or paragraphs. Once LATEX has the words, sentences and paragraphs, subsections,
sections etc. contents of environments it will arrange them in your paper in a consistent
manner. You do not need to worry about formatting your document A LATEX expert
might fine tune some aspects but this is often not necessary.
4.4.6 Environments
We use environments to tell LATEX that the material included in the environment is not
plain text. In the box below the environment name is started with the \begin{name}
command and ended with the \end{name} command.
\begin{name}
content
\end{name}
You may wish to emphasise some text or change font sizes or shape. The next section
shows how to achieve such enhancements
If you have a selection of text and you wish to change the size of the font you can simply
insert the command before the text and enclose the text between { and }. Alternatively
select the text with your mouse and us the menu item LaTeX ñ Font Sizes and
TeXstudio will do the work for you.
4.5 Text Enhancements 59
Bold, italic, underlined etc. fonts are easily added in LATEX by means of LATEX commands.
A selection of the most used commands of this type are below.
• \emph{text} writes text in an emphasised font (usually italic). If you use \emph{}
within your emphasised text it produces normal text.
Example –
\emph{this is a \emph{good} example of emphasised text}
produces
this is a good example of emphasised text
produces
4th
These commands can be accessed from TeXstudio in similar ways to the size commands
in section 4.5.2.
Pakin (2009)9 lists some 5913 text or mathematical symbols and the corresponding LATEX
commands that produce them. The usual user will only require a small subset of these
symbols. The following code includes the fontenc and textcomp packages. These pack-
ages are highly recommended as they increase the quality and range of characters avail-
able.
\usepackage[T1]{fontenc}
\usepackage{textcomp}
Figure 4.4 gives examples of various accented text symbols that can be generated by
LATEX. These symbols can be accessed from the “accented letters” and the two “miscel-
laneous text symbols” buttons on the left-hand side of the “structure” pane.
9
This document is available on my MiKTeX system as C:\MiKTeX-2.9\doc\info\symbols\
comprehensive\symbol-a4.pdf
4.5 Text Enhancements 61
4.5.4 e Symbol
I recommend that you load the eurosym package if you need to use the e symbol.
\usepackage[left]{eurosym}
This gives you the \euro command which produces e. The additional command \EUR{amount}
produces a good typeset version of amount. For example \EUR{1,234,567.89} produces
e 1,234,567.89.
Dashes. Dashes of various sizes are produced with one, two or three “-” charac-
ters.
• The double dash (n-dash) “--” can be used to describe a range e. g. 1990--2012
produces 1990–2012 and June--September produces June–September.
• The triple dash (m-dash) “---” may replace commas, semicolons, colons, and par-
entheses. It may also be used to indicate added emphasis, an interruption, or an
abrupt change of thought. In formal writing it is better to use comas, semicolons,
colons or parenthesis.
Dots. The command \ldots makes an ellipsis, i. e. . . . . (this may also be used in math
mode.)
LATEX is very good at line and page breaking. If you have finished your paper and you do
wish to do some fine tuning to the line and page breaks then it does provide the necessary
facilities. You should not attempt to make such adjustments until you are completely
sure that you have the absolutely final version of your paper. If you are composing your
62 Basic LATEX Syntax
thesis from a collection of earlier papers I would recommend that you leave all fine tuning
until the thesis is finalised.
If you wish to keep two or more words on the same line you can join them with ~. e. g.
John~Frain will keep John and Frain on the same line.
The command \\ ends a line within a paragraph and continues on the next line. The
examples in the previous subsections were produced using this command.
The command \newpage terminates the current page and resumes on the next page.
To include material within single quotation marks it is better to open the quotation with
an open quotation mark (below the ESC key on a standard UK English keyboard and
close it with the close quotation mark. If you wish to use double quotation marks open
the quote with two open quotation marks and close it with two close quotation marks.
This is illustrated at 1 and 2 in the box below. This gives a more polished output that
the standard approach which is illustrated at 3 and 4 in the box.
There are two environments for longer quoted material, the quote environment if you
wish to quote a single paragraph and the quotation environment if you wish to quote
several paragraphs. I give an example of the quotation environment in example 4.5
4.5 Text Enhancements 63
below.
\begin{quotation}
The first edition of this book published in 1978, dealt with financial
crises that
were, for the most part, before World War II. Black Monday, October 19
1987,
along with more research on earlier troubles, indicated, at least to me,
a need for a second look. The third edition had its stimulus the Japanese
crash of 1990. That was some time ago.
\dots. \emph{\citet{Kind00}}
\end{quotation}
The first edition of this book published in 1978, dealt with financial crises
that were, for the most part, before World War II. Black Monday, October
19 1987, along with more research on earlier troubles, indicated, at least to
me, a need for a second look. The third edition had its stimulus the Japanese
crash of 1990. That was some time ago.
A fourth edition is perhaps not needed by readers but only as occupational
therapy for the writer. The push comes partly from the Mexican crisis of
1994-95, but more especially from the East Asian difficulties of 1997-98, which
are not far behind us,
. . . . Kindleberger (2000)
As I have emphasised one of the main advantages of LATEX is that it is possible to just
enter your text unformatted and then leave it to LATEX to do the formatting. On occasion
you may wish to enter some text and have LATEX reproduce the text exactly as typed
(e. g. a computer program). This is the purpose of the verbatim environment. Many of
the examples of LATEX input in this note have been produced using an enhanced version
of the verbatim environment. See, for example, Example 4.6 and many of the boxed
sections. I illustrate the environment with an example of a short strata10 program which
I might wish to reproduce a program in a paper.
\begin{verbatim}
insheet using medicare.txt,clear
describe
* CREATE NEW VARIABLES*/
generate AVE_DAYS=tot_d/num_dchg
generate CCPD=cov_chg/num_dchg
generate NUM_DCHG=num_dchg/1000
replace year = 1989+year
tsset state year
save medicare, replace
\end{verbatim}
Note that LATEX commands etc. within the “verbatim” are not interpreted but are pro-
duced “verbatim” i. e. exactly as typed in the verbatim environment. The material in
the “verbatim” environment is set in a new paragraph
10
For the computer programmer there are more elaborate listing packages available
4.5 Text Enhancements 65
\verb+\begin{verbatim}+\\
\verb|abc+def|
\begin{verbatim}
abc+def
While the verbatim environment is sufficient for most requirements, the fancyvrb pack-
age offers several extensions and enhancements to the basic verbatim environment. It
allows one to
• Change fort size and shape. It is probably best to do this for all similar verbatim
environments throughout the document
• etc.
alphabetical list of and links to LATEX packages which is a most useful source of information.
4.5 Text Enhancements 67
4.5.9 Lists
Standard LATEX provides three kinds of lists, bulleted, numbered and labelled lists. Ex-
amples of the the three environments used to produce these lists are given in in Ex-
amples 4.8. 4.9 and 4.10.
The itemize environment produces a bulleted list. The bulleted lists produced by this
environment can be nested to a depth of four. The types of bullets used are defined by
the document class used. For details on how to change the defaults see Mittelbach and
Goossens (2004, page 128).
Similarly the enumerate environment produces a numbered list which can be nested to
depth of four. The default enumerators are 1, 2, . . . for the first level, a, b, . . . for the
second, i, ii, . . . for the third and A, B, . . . for the fourth. These enumerators may be
amended, see for example Mittelbach and Goossens (2004, page 130).
The labels for each item are included in [] in the \item[] at the start of each item.
Usually the labels are given in bold type, are indented and right justified.
\begin{itemize}
\item A bulleted list
\item A numbered list
\item A labelled list
\end{itemize}
• A bulleted list
• A numbered list
• A labelled list
A list environment is also available. This provides flexible lists and is most used in
programming special lists. It is seldom used directly in documents.
The paralist package provides extra list environments and extensions to existing ones.
It is described in subsection 8.7.1.
68 Basic LATEX Syntax
\begin{enumerate}
\item A bulleted list
\item A numbered list
\item A labelled list
\end{enumerate}
1. A bulleted list
2. A numbered list
3. A labelled list
\begin{description}
\item[bulleted] use \texttt{itemize} environment
\item[numbered] use \texttt{enumerate} environment
\item[Labelled] use \texttt{description}
\end{description}
4.5.10 Boxes
The commands \makebox, \mbox, \framebox and fbox are LATEX commands are designed
to make unframed and framed LATEX boxes. A LATEX box is a construct that can not be
split across lines or pages. Other commands often generate such constructs.
I have not used these commands to generate the display material in this book. There
are three types of displays here
1. Longer listings such as those in the box on page 199. These are produced by the
Verbatim environment using a [frame=single] option.
\begin{Verbatim}[fontsize=\relsize{-1},% commandchars=\|\(\),frame=single]
4.5 Text Enhancements 69
2. Boxes such as those in item 1 of this environment are produced by the colorbox
environment provided by the tcolorbox package (see section 8.13) probably sup-
plemented by the Verbatim environment in the fancyverb package (see subsec-
tion 8.11.1).
3. Boxes which contain LATEX code in their upper portion and the output of that code
in the lower. These are produced using the methods described on page 30 of the
tcolorbox manual.
The concept of fragile versus robust LATEX commands is a source of confusion to many
beginners. The problems that arise from fragile LATEX is best explained by an ex-
ample.
\section{Section Heading\footnotemark{}}
\footnotetext{Some text}
It looks very simple but if you insert it into a LATEX document that has no errors several
errors appear. The problem arises from the fact that the code contains movable text.
The title of the section will appear in the section heading, in the table of contents and
possibly in page headings. Recall that LATEX processes a file by reading straight through
it. If, on page 3, it encounters a reference to an equation on a later page it is unable to
resolve that reference on a first run.
Here I am trying to insert a footnote into a chapter heading. . Recall that LATEX processes
a file by reading straight through it. If, on page 3, it encounters a reference to an equation
on a later page it is unable to resolve that reference. The problem here is of a similar
nature. During the first LATEX run the information necessary to resolve these problems,
is written to various helper files. These helper files are then read in conjunction with the
original LATEX file during a subsequent LATEXrun. In this example LATEX is processing
the material before passing it to the helper file and, in the process12 , passing code to
the helper file which generates errors when the helper files are read on the second LATEX
12
Recall that TeXstudio will run LATEXmore than once if there are unresolved references, tables of
contents etc. to be generated.
70 Basic LATEX Syntax
run. LATEX commands which may generate this kind of error are said to be fragile. Other
commands are robust
The commands \footnotemark and \footnotetext are fragile. The command \protect
can be used to delay any processing before the material is written to the helper file. The
next box shows the use of the \protect command to remove the errors in the current
example. It would be good practice in this case to use the optional “Shorter section title”
– see section 4.4.4 on page 53.
\section{Section Heading\protect\footnotemark{}}
\protect{\footnotetext{Some text}}
The following more detailed explanation is taken from the UK List of TEX Frequently
Asked Questions on the Web (http://www.tex.ac.uk/cgi-bin/texfaq2html?label=
protect)
Sometimes LaTeX saves data it will reread later. These data are often the ar-
gument of some command; they are the so-called moving arguments. (“Mov-
ing” because data are moved around.) Candidates are all arguments that
may go into table of contents, list of figures, etc.; namely, data that are writ-
ten to an auxiliary file and read in later. Other places are those data that
might appear in head- or footlines. Section headings and figure captions are
the most prominent examples; there’s a complete list in Lamport’s book (see
TeX-related books).
What’s going on really, behind the scenes? The commands in moving argu-
ments are normally expanded to their internal structure during the process
of saving. Sometimes this expansion results in invalid TeX code, which shows
either during expansion or when the code is processed again. Protecting a
command, using \protect\cmd tells LaTeX to save \cmd as \cmd, without
expanding it at all.
Some fragile commands, such as \cite, have been made robust in later revi-
sions of LATEX. Some commands, such as \end and \nocite, are fragile even
though they have no optional arguments
There is no reason that a package author should not also make robust com-
mands with optional arguments as part of the package. Some robust com-
mands are redefined by certain packages to be fragile (the \cite command
commonly suffers this treatment). Further, simply “hiding” a fragile com-
mand in another command, has no effect on fragility. So, if \fred is fragile,
and you write:
\newcommand{\jim}{\fred}
\DeclareRobustCommand{\jim}{\fred}
\MakeRobustCommand\fred
Where after, \fred is robust. Using the package may be reasonable if you
have lots of fragile commands that you need to use in moving arguments.
72 Basic LATEX Syntax
Mathematics in LATEX
Probably the main reason many of you are reading this is you are writing a paper or
dissertation which will contain some mathematics and you have seen some work done
with LATEX and were impressed. Davidson and MacKinnon (2004) and Hayashi (2000)
are just two examples of the many books on econometrics that acknowledge the use of
LATEX. Varian’s two Microeconomics texts (Varian, 1992, 2010) are further examples of
the use of LATEX in economics.
The production of in-line mathematics is illustrated in the following box which replicates
some material from (Davidson and MacKinnon, 2004, , page 164)1 . At this stage don’t
worry about the LATEX commands included in these examples. In general they can be
inserted using a mouse to select items from drop-down lists or using the auto-completion
facilities available in your editor.
Example 5.1: Material quoted from (Davidson and MacKinnon, 2004, , page 164)
The bootstrap test rejects if $r/B < \alpha$, that is,if $r < B \alpha$.
Under the null the probability that this inequality is satisfied is
the proportion of the $B+1$ possible values of $r$ that satisfy it.
If we denote by $|\alpha B|$ the largest integer that is smaller
than $\alpha B$, it is easy to see that there are exactly $|\alpha
B| + 1 $ such values of $r$, namely $0,1,\dots,|\alpha B|$. Thus the
probability of rejection is $(|\alpha B| + 1 )/(B+1)$
The bootstrap test rejects if r{B ă α, that is,if r ă Bα. Under the null the probability
that this inequality is satisfied is the proportion of the B ` 1 possible values of r that
satisfy it. If we denote by |αB| the largest integer that is smaller than αB, it is easy
to see that there are exactly |αB| ` 1 such values of r, namely 0, 1, . . . , |αB|. Thus the
probability of rejection is p|αB| ` 1q{pB ` 1q
• The math symbols e. g. α can be accessed from the symbols panels in the structure
panel (extreme left hand side of the TeXstudio window). About 400 symbols are
available from this source. As mentioned in 4.5.3 many extra symbols are listed
in Pakin (2009). You can also get a symbol by starting to type the symbol and
selecting the symbol from the drop-down window that is generated.
1
A gentle reminder — Boxes labelled as Example n.m have LATEX code in the upper part and the
output of this code in the lower part
2
In-line math modes can also be separated from text mode by \( \) pairs which is a short cut for
\begin{math}, \end{math} pairs. These latter two versions are not robust and may cause problems. I
mention them only because they may be included in other LATEX documents that you may encounter.
In your own work you should use the $, $ pair. (In the rarely used alltt environment it is better to use
the \( \) pair – see Voss (Voß) (2010a, , page 2))
5.2 The equation and equation* Environments 75
• Many of the facilities available in Display Math can also be used in in-line math.
• Leaving out the closing $ is one of the most common errors that occur in preparing
a LATEX document. Be very careful. As a practical matter I first enter both the
starting $ and finishing $ and then enter the in-line mathematics between the two
$ symbols.
The same mathematical symbols/characters are used in both in-line and display mathem-
atics. If you are using TeXstudio almost all of the commonly used symbols are available
on one of the mathematical symbol icons at the extreme left of the TeXstudio window.
Most other LATEX GUIs have a similar facility. If you can not find the symbol that you
require consult (Pakin, 2009) “The Comprehensive LATEX Symbol List” which contains
5913 symbols and the corresponding LATEX commands that produce them.
The equation and equation* environments are the first two display math environments
that most users encounter. Display math is math that is set apart from text as in
Example 5.2
Example 5.2: Further material quoted from (Davidson and MacKinnon, 2004, , page
164)
αpB ` 1q “ |αB| ` 1.
Since the . . .
Recall that there are various ways in which TeXstudio can facilitate the entry of LATEX
commands. The methods described here can be used in most circumstances.
1. Use the menu item Math ñ Numbered Equation This enters the \begin{equation}
76 Mathematics in LATEX
3. If the first few letters of a command are unique you can type type them and then
the Tab key to complete the command. Thus if you type \Om followed by the tab
key, the command \Omega is completed. This gives the Greek capital Ω.
4. You may copy first \alpha and paste where you need it later
5. You may even type the complete LATEX command. If you make frequent use of
a command and are comfortable with the keyboard you may find the keyboard a
convenient way to enter LATEX commands.
6. You may of course use a combination of these methods. Use whichever you find
most convenient. I suspect that beginners will find the first two methods more
convenient and utilize the other methods as they become more familiar with LATEX.
The equation and equation* environments produce a single equation. The equation
version is numbered and the starred version is not numbered. In this example the equa-
tion is clearly displayed separately from the text on it’s own line. Thus the term “Display
Math”.
\begin{equation}
\label{eq:line}
F(x)=\int_{-\infty}^xf(u)\rd u
\end{equation}
See Equation~\ref{eq:line} \dots
żx
F pxq “ f puqdu (5.1)
´8
• I have defined a label eq:line which I can use to reference the equation with the
LATEX statement equation~\ref{eq:line} which produces “equation 5.1”. If you
insert or delete any numbered equation LATEX will revise the reference numbers
to all other equations as necessary and also correct any existing references to the
equations within the document. In TeXstudio as you type say \ref{eq: you will be
presented with a list of possible completions of the label on the equation. Choose
the correct completion and press enter and TeXstudio will complete the typing of
the reference for you.
• The equation numbers are by default set on the right of the equation. Adding the
option leqno to the initial documentclass statement places equation numbers on
the left hand side.
• The documentclass option fleqn sets equations justified on the left hand side. By
default they are centred as is the practice here
• I have used the example to show how to set out the limits on a definite integral. The
LATEXcommand \int produces the integral ( ) sign. The lower limit is produced
ş
There are a variety of other Display Math environments which cater for instances such
as equations that are too long to fit on one line, aligned systems of equations, matrices
etc. We shall return to these later after looking at some mathematical components which
can be used to build mathematical expressions.
In many of the examples here I give the LATEX code or command required to produce
some effect in your document. If you are using TeXstudio or one of the other modern
LATEX interfaces you do not have to remember this code. In TeXstudio it will be available
either in the operator boxes on the extreme left hand side of your screen or through menus
or using auto-completion. Other systems will offer also provide some similar aids to the
writer. What you see here is the effect of using the relevant gui aids.
5.3.1 Fractions
Fractions are set in math mode using the command \frac{num}{den} command where
num and den are the numerator and denominator, respectively, of the fraction. In in-line
mode it is often better to set the fraction as $(1+x)/(1-x^2)=1/(1-x)$ which gives
p1 ` xqp1 ´ x2 q “ 1{p1 ´ xq rather than \frac{1+x}{1-x^2} = \frac{1}{1-x} which
gives 1`x
1´x2
“ 1
1´x and may disturb normal line spacing in your document. You could
try both and keep the one that you prefer. Example 5.4 is an example of \frac{}{} in
display mode.
\begin{equation}
\frac{1+x}{1-x^2} = \frac{1}{1-x}
\end{equation}
1`x 1
2
“ (5.2)
1´x 1´x
5.3 Components of Mathematical Expressions 79
You will have noticed at this stage that the fonts used in mathematics do not have the
same shape as the text fonts. The spacing in the mathematics environments is also dif-
ferent to what one wants in text. The amsmath package adds the \text{word or words}
function to LATEX and provides a way of entering text in mathematics. This is illustrated
in example 5.5.
\begin{equation}
x_{ij} = \alpha_i +\beta_j \text{, for all }i=1,\dots,n
\text{ and } j=1,\dots,n
\end{equation}
5.3.3 Subscripts
5.3.4 Powers
Powers (exponents, superscripts) are inserted in mathematics using the caret character
i. e. $x^2$ produces x2 . If two or more characters are to be included in the subscript the
characters in the subscript must be included within braces, i. e. $x^{12}$ produces x12 .
To use subscripts and superscripts use the caret for the superscript and an underscore
for the subscript.
The subscripts can be placed before or after the superscripts. Example 5.6.
80 Mathematics in LATEX
The treatment of limits in integrals, sums and products is similar. See example 5.33 .
\begin{equation}
x_{ij}^2 = \alpha_i^2 +2 \alpha_i \beta_j +\beta^2_j
\end{equation}
5.3.5 Roots
5.3.6 Integrals
3
The command \textsuperscript{} produces a superscript in text. For example the code
up\textsuperscript{over} produces upover .
4
In the preamble the statement \newcommand{\rd}{\ensuremath{\mathrm{d}}} defines a new com-
mand \rd. This produces an upright d for the differential sign. Alternatively we could use \mathrm{d}
wherever we required an upright d in our document. See section 5.4.7
5.4 Sums and Products 81
żb
1 px´µq2
P robpa ď x ď bq “ ? e 2σ 2 dx (5.5)
2πσ
a
The box below shows the use of the sum (\sum\limits_{min}^{max}) and product
\prod\limits_{min}^{max} functions. The \limits part may be omitted or replaced
by a
\nolimits part as in the box. In displayed Math if the \limits part is included or omit-
ted the limits are set on top of the sum or product sign. If the \nolimits part is included
the limits are set to the right of the signs. In most cases the simpler version without the
\limits is sufficient. Advanced users may use the options on the \usepackage{amsmath}
to change the default.
82 Mathematics in LATEX
\begin{equation*}
\bar{x}=\sum\limits_1^n{x_i}=\sum_1^n{x_i}
\text{ (arithmetic mean)}
\end{equation*}
\begin{equation*}
\bar{x}=\sqrt[n]{\prod\limits_1^n{x_i}}=\sqrt[n]{\prod_1^n{x_i}}
\text{ (geometric mean)}
\end{equation*}
n
ÿ n
ÿ
x̄ “ xi “ xi (arithmetic mean)
1 1
g g
fn fn
fź fź
x̄ “ e
n
xi “ n
e xi (geometric mean)
1 1
Table 5.1 lists many of the the accents used in math mode in LATEX. Many of these
accents are available on the “Accented” letters drop-down menu on the extreme right
hand side of the TeXStudio screen. Additional accents are listed in Pakin (2009).
5.4 Sums and Products 83
Table 5.1: Accents in Mathematics from TeXstudio Version 2.7 drop-down menu
Mathematical expressions may involve brackets and delimiters of various sizes. The easi-
est way to manage such problems is to use the put \left before the left bracket and
\right before the right bracket. The \left and \right must be used in pairs and can
be nested. This is illustrated in the following box. In equation 5.7 I use only standard
brackets. Obviously the square brackets are not the correct size. In equation 5.8 I use
\left and \right commands before the square bracket and the correct size bracket are
now printed. As a farther illustration I have nested a further two \left and \right com-
mands before a pair of round brackets. Again LATEX produces the correct size brackets.
84 Mathematics in LATEX
\begin{equation}
\label{eq:bracket1}
I(\bm{\theta)}=-E[\frac{\partial^2{\log L(\theta)}}
{\partial \tilde{\bm{\theta}} \partial \tilde{\bm{\theta}'}}]
\end{equation}
\begin{equation}
\label{eq:bracket2}
I(\bm{\theta)}=-E\left[\frac{\partial^2{\log L\left(\theta\right)}}
{\partial \tilde{\bm{\theta}} \partial \tilde{\bm{\theta}'}}\right]
\end{equation}
\begin{equation}
\label{eq:bracket3}
\prod_{i=1}^n\left\{K+\frac{1}{\sqrt{2 \pi \frac{\sigma^2}{1-\phi^2}}}
\times \exp \left[\frac{\left( y_0 - \frac{c}{1-\phi}\right)^2}
{2 \frac{\sigma^2}{1-\phi^2}} \right] \right\}
\end{equation}
B 2 log Lpθq
Ipθq “ ´Er s (5.7)
B θ̃B θ̃ 1
„ 2
B log L pθq
Ipθq “ ´E (5.8)
B θ̃B θ̃ 1
$ »´ ¯2 fi,
c
— y0 ´ 1´φ ffi
n ’ /
ź & 1 .
K`b ˆ exp – σ2 fl (5.9)
’
i“1 %
σ2
2π 1´φ 2
2 1´φ 2
/
-
Equation 5.9 is a more complicated example of the use of the \left and \right com-
mands. Note that the curly bracket (brace) requires a \ and that the curly bracket pair
is produced by \left\{ content \right\}. These brackets can be accessed on the icon
line below the menu items in TeXstudio.
To include bold mathematical fonts I load the bm package in the preamble. This adds
the bm command which allows one to set mathematics in bold font
5.4 Sums and Products 85
\usepackage{bm}
The mathematics to be included in bold font is simply included between the { and }
signs. This is illustrated in the following box.
\begin{equation}
\hat{\bm{\beta}}=\left(\bm{X}'\bm{X}\right)^{-1}\bm{X}'\bm{y}
\end{equation}
˘´1 1
(5.10)
`
β̂ “ X 1 X Xy
5.4.6 Matrices
The amsmath package adds six environments which provide facilities to typeset matrices
with different delimiters. The five environments pmatric, bmatrix, Bmatrix, vmatrix
and Vmatrix have (respectively) ( ), [ ], { }, | |, and ‖‖delimiters built in. The matrix
environment has no delimiters. These are illustrated below.
¨ ˛ » fi $ ,
˚x11 x12 ‹ —x11 x12 ffi &x11 x12 /
’ .
$pmatrix ˝ ‚ \bmatrix – fl \Bmatrix
’ /
x21 x22 x21 x22 %x
21 x22
-
x11 x12
x11 x12
x11 x12
\vmatrix \Vmatrix
\matrix
x21 x22
x21 x22
x21 x22
The matrix is set row by row. Within a row elements are separated by & and each row is
separated by \\. This is illustrated in the following box. Note the use of \cdots, \vdots
and \ddots commands.
86 Mathematics in LATEX
\begin{equation}
\bm{X}=
\begin{pmatrix}
x_{11} & x_{12} & \cdots & x_{1N} \\
x_{21} & x_{22} & \cdots & x_{2N} \\
\vdots & \vdots & \ddots & \vdots \\
x_{T1} & x_{T2} & \cdots & x_{TN}
\end{pmatrix}
\end{equation}
¨ ˛
x11 x12 ¨¨¨ x1N
˚ x21 x22 x2N ‹
˚ ‹
¨¨¨
˚ ..
X“˚ .. .. .. ‹ (5.11)
˝ . . . . ‚
‹
xT 1 xT 2 ¨¨¨ xT N
Standard practice is to set mathematical variables in a slanted font and LATEX does
so. Function names, however should be set in an upright font. For a variety of math-
ematical functions LATEX provides commands which set such functions properly. Thus
the logarithm of x is set by $\log x$ which gives log x or by $\ln x$ which gives
ln x. The following are available in the “Operator Symbols” drop-down box in TeXstudio
$\arccos, \arcsin, \arctan, \arg, \cos, \cosh, \cot, \coth, \csc, \deg, \det, \dim,
\exp, \gcd, \hom, \inf, \ker, \lg, \lim, \liminf, \limsup, \ln, \log, \max, \min, \Pr,
\projlim, \sec, \sin, \sinh, \sup, \tan, \tanh, \varlimsup, \varliminf, \varinjlim,
\varprojlim
%\DeclareMathOperator{util}{util} in preamble
\begin{equation}
\util(q_1,q_2)=A q_1^{\alpha} q_2^{1-\alpha}
\end{equation}
5.5.1 Introduction
The split environment is part of the amsmath package. It is used within another display
environment. It produces only one equation number for the content of the split envir-
onment. The split environment sets the lines of the equation in columns. The columns
are separated by a & and the rows by \\. In example 5.13 the split environment is
used to similar effect to the align environment in example /refex:align. Note that it is
possible to number the individual lines in the align environment while only one number
can be used in the split environment. The split environment can be used within an
align environment — I would think that this facility is not widely used.
The multiline environment is very suitable for setting long equations. The first line of a
long equation is left justified, the last right justified and middle lines, if any, are centred.
88 Mathematics in LATEX
\begin{equation}
\begin{split}
\bm{b}-\bm{\beta}
&= (\bm{X}'\bm{X})^{-1} \bm{X}'\bm{y} - \bm{\beta} \notag \\
&= (\bm{X}'\bm{X})^{-1}
\bm{X}'(\bm{X}\bm{\beta}+\bm{\varepsilon})
- \bm{\beta} \notag \\
&= (\bm{X}'\bm{X})^{-1} \bm{X}'\bm{X}\bm{\beta} +
(\bm{X}'\bm{X})^{-1} \bm{X}'\bm{\varepsilon}-- \bm{\beta} \notag
\\
&= \bm{\beta}+ (\bm{X}'\bm{X})^{-1} \bm{X}'\bm{\varepsilon}-
\bm{\beta} \notag \\
&= (\bm{X}'\bm{X})^{-1} \bm{X}'\bm{\varepsilon}
\end{split}
\end{equation}
b ´ β “ pX 1 Xq´1 X 1 y ´ β
“ pX 1 Xq´1 X 1 pXβ ` εq ´ β
“ pX 1 Xq´1 X 1 Xβ ` pX 1 Xq´1 X 1 ε ´ ´β
“ β ` pX 1 Xq´1 X 1 ε ´ β
“ pX 1 Xq´1 X 1 ε
left
centred
centred
right (5.13)
You indicate where the lines are to be broken with a \\. Equation 5.14 is an adapted
version of equation 1.7.4’ in Hayashi (2000) and uses a multiline environment. The
starred version of this environment multiline* produces an unnumbered version of the
equation.
5.5 Other Mathematical Environments 89
\begin{multline}
\label{eq:multiline}
\log \left( \frac{TC_i}{Q_i}\right) = \beta_1 +
(\beta_2 - 1) \log(Q_i) \\
+\beta_3\log(p_{i1}) + \beta_4\log(p_{i2}) +
\beta_5\log(p_{i3}) +\varepsilon_i,\quad i=1,\dots,T
\end{multline}
ˆ ˙
T Ci
log “ β1 ` pβ2 ´ 1q logpQi q
Qi
` β3 logppi1 q ` β4 logppi2 q ` β5 logppi3 q ` εi , i “ 1, . . . , T (5.14)
The gather environment is similar to the multiline except that all lines are centred as
illustrated below.
line 1 (5.15)
line 2 (5.16)
line 3 (5.17)
line 4 (5.18)
The box below illustrates the use of the gather environment to reset the same equation
as used to illustrate the multiline environment.
The align environment is used when we want to set a system of equations aligned in a
manner to be specified.
The simplest use is where only one horizontal alignment is required. Usually the align-
ment is at an equal or other relationship symbol. The alignment mark is a & which is
90 Mathematics in LATEX
\begin{gather}
\label{eq:gather}
\log \left( \frac{TC_i}{Q_i}\right) = \beta_1 +
(\beta_2 - 1) \log(Q_i) \\
+\beta_3\log(p_{i1}) + \beta_4\log(p_{i2}) +
\beta_5\log(p_{i3}) +\varepsilon_i,\quad i=1,\dots,T
\end{gather}
ˆ ˙
T Ci
log “ β1 ` pβ2 ´ 1q logpQi q (5.19)
Qi
`β3 logppi1 q ` β4 logppi2 q ` β5 logppi3 q ` εi , i “ 1, . . . , T (5.20)
inserted before the relevant symbol. the end of each line is indicated by a \\. The next
box is an example of this use of the align environment.
\begin{align}
\bm{b}-\bm{\beta}
&= (\bm{X}'\bm{X})^{-1} \bm{X}'\bm{y} - \bm{\beta} \notag \\
&= (\bm{X}'\bm{X})^{-1} \bm{X}'(\bm{X}\bm{\beta}+\bm{\varepsilon})
- \bm{\beta} \notag \\
&= (\bm{X}'\bm{X})^{-1} \bm{X}'\bm{X}\bm{\beta} +
(\bm{X}'\bm{X})^{-1} \bm{X}'\bm{\varepsilon}-- \bm{\beta} \notag \\
&= \bm{\beta}+ (\bm{X}'\bm{X})^{-1} \bm{X}'\bm{\varepsilon}-
\bm{\beta} \notag \\
&= (\bm{X}'\bm{X})^{-1} \bm{X}'\bm{\varepsilon}
\end{align}
b ´ β “ pX 1 Xq´1 X 1 y ´ β
“ pX 1 Xq´1 X 1 pXβ ` εq ´ β
“ pX 1 Xq´1 X 1 Xβ ` pX 1 Xq´1 X 1 ε ´ ´β
“ β ` pX 1 Xq´1 X 1 ε ´ β
“ pX 1 Xq´1 X 1 ε (5.21)
5.5 Other Mathematical Environments 91
An align environment can have several alignment points in each line. This is illustrated
in the box below. This example states the condition for equality of two 3 ˆ 3 matrices.
There are three columns of equations. Within each equation the alignment & is at the =
character. (There are three such characters) A & sign also separates the columns. (There
are two such signs). there are five such signs on each line of the equation system. In
general if you have n equations on each line there must be 2n ´ 1 alignment signs. Each
line of the system is ended by \\. In the example the output from each line contains
a reference number. You can suppress the reference numbers for a particular line by
adding a \notag or \nonumber immediately before the \\ marking the end of the line.
The align* environment produces similar output but the equations are not numbered.
\begin{align} \label{eq:align}
a_{11} &= b_{11} & a_{12} &= b_{12} & a_{13} &= b_{13} \notag \\
a_{21} &= b_{21} & a_{22} &= b_{22} & a_{23} &= b_{23} \notag \\
a_{31} &= b_{31} & a_{32} &= b_{32} & a_{33} &= b_{33}
\end{align}
One may use \text command within an align environment to produce line by line
annotations of a system of equations. Example 5.18 is adapted from American Mathem-
atical Society (2002).
The alignat environment is an extension of the align environment that allows one to
set the spacing between columns. The format of the environment is
92 Mathematics in LATEX
\begin{align*}
x& = y_1-y_2+y_3-y_5+y_8-\dots && \text{by \eqref{eq:line}}\\
& = y'\circ y^* && \text{by \eqref{eq:gather}}\\
& = y(0) y' && \text {by Axiom 1.}
\end{align*}
x “ y1 ´ y2 ` y3 ´ y5 ` y8 ´ . . . by (5.1)
1
“y ˝y ˚
by (5.19)
“ yp0qy 1
by Axiom 1.
\begin{alignat}{ncols}
content
\end{alignat}
If we repeat the process in Example 5.17 replacing the align environment with an
alignat environment we get example 5.19
\begin{alignat*}{3}
a_{11} &= b_{11} & a_{12} &= b_{12} & a_{13} &= b_{13} \\
a_{21} &= b_{21} & a_{22} &= b_{22} & a_{23} &= b_{23} \\
a_{31} &= b_{31} & a_{32} &= b_{32} & a_{33} &= b_{33}
\end{alignat*}
In the align environment LATEX fixes the separation between the equations as in ex-
ample 5.16. The alignat environment allows us to specify how the equations are to be
5.5 Other Mathematical Environments 93
separated. Here we have not specified any space between the equations and we have not
got the desired result. In the next box we have added ,\quad to each equation and we
get an appropriate version of the equations. It is perhaps a matter of taste whether you
think which of Examples 5.17 or 5.20 is best in any particular circumstance.
\begin{alignat}{3}
a_{11} &= b_{11},\quad & a_{12} &= b_{12},\quad
& a_{13} &= b_{13},\notag \\
a_{21} &= b_{21},\quad & a_{22} &= b_{22},\quad
& a_{23} &= b_{23},\notag \\
a_{31} &= b_{31},\quad & a_{32} &= b_{32},\quad
& a_{33} &= b_{33}.
\end{alignat}
The flalign and flalign* environments spread the equations over the entire line. The
left most equation is left justified and the right right justified. See the box below.
The array environment is the mathematical equivalent of the text environment tabular.
While the default content of the tabular environment is text the default content of the
array environment is mathematics. The format of the array environment is
94 Mathematics in LATEX
\begin{flalign} \label{eq:falign}
a_{11} &= b_{11} & a_{12} &= b_{12} & a_{13} &= b_{13} \notag \\
a_{21} &= b_{21} & a_{22} &= b_{22} & a_{23} &= b_{23} \notag \\
a_{31} &= b_{31} & a_{32} &= b_{32} & a_{33} &= b_{33}
\end{flalign}
\begin{array}[position]{column justification}
column 1 & column 2 & column 3 \\
column 1 & column 2 & column 3 \\
................ \\
column 1 & column 2 & column 3
\end{array}
where the optional parameter position is a combination of htb with the same meaning
as in the table environment and the obligatory column justification is a single letter
specifying the justification of each column of the array.
c for centred
Column entries are separated by an &. Column entries may include other LaTeX com-
mands. Each row of the array must be terminated with the string \\.
The use of the array statement is illustrated in example 5.25. This equation relates to
the inversion of lag polynomials and is taken from page 373 of Hayashi (2000). Note the
alignment of the ψ’s and φ’s.
5.5 Other Mathematical Environments 95
\begin{equation} \label{ex:array2}
\begin{array}{rllllllr}
\text{constant} &\quad \psi_0& &
& & & &=1, \\
L^{1}: &\quad \psi_{1} &-\phi_{0} &
& & & &=0, \\
L^{2}: &\quad \psi_{2} &-\phi_1\psi_1 & -\phi_2\psi_0
& & & &=0, \\
\cdots & & &
&\cdots & & &=0,\\
L^{p-1}:&\quad \psi_{p-1} &-\phi_1\psi_{p-2} &-\phi_2\psi_{p-3}
&-\cdots &-\phi_{p-1}\psi_{0} & &=0,\\
L^{p} :&\quad \psi_{p} &-\phi_1\psi_{p-1} &-\phi_2\psi_{p-2}
&-\cdots &-\phi_{p-1}\psi_{1} &-\phi_{p}\psi_{0} &=0,\\
L^{p+1}:&\quad \psi_{p+1} &-\phi_1\psi_{p} &-\phi_2\psi_{p-1}
&-\cdots &-\phi_{p-1}\psi_{2} &-\phi_{p}\psi_{1} &=0,\\
L^{p+2}:&\quad \psi_{p+2} &-\phi_1\psi_{p+1} &-\phi_2\psi_{p}
&-\cdots &-\phi_{p-1}\psi_{3} &-\phi_{p}\psi_{2} &=0, \\
\multicolumn{4}{r}{\cdots} & \multicolumn{4}{r}{,}\\
\end{array}
\end{equation}
constant ψ0 “ 1,
L1 : ψ1 ´φ0 “ 0,
L2 : ψ2 ´φ1 ψ1 ´φ2 ψ0 “ 0,
¨¨¨ ¨¨¨ “ 0,
Lp´1 : ψp´1 ´φ1 ψp´2 ´φ2 ψp´3 ´¨¨¨ ´φp´1 ψ0 “ 0, (5.25)
Lp : ψp ´φ1 ψp´1 ´φ2 ψp´2 ´¨¨¨ ´φp´1 ψ1 ´φp ψ0 “ 0,
Lp`1 : ψp`1 ´φ1 ψp ´φ2 ψp´1 ´¨¨¨ ´φp´1 ψ2 ´φp ψ1 “ 0,
Lp`2 : ψp`2 ´φ1 ψp`1 ´φ2 ψp ´¨¨¨ ´φp´1 ψ3 ´φp ψ2 “ 0,
¨¨¨ ,
96 Mathematics in LATEX
The cases environment is used to set a system such as the definition of of an elementary
Tobit model. (see Hayashi, 2000, page 518) and is reproduced in example 5.23 which
also gives the LATEX input required to produce this output.
\begin{align}
y_t^*& =\bm{x'}_t \bm{\beta}_0 +\varepsilon_t,\quad t=1,2,\dots,n, \\
y_t & = \begin{cases}
y_t^* & \text{ if $y_t^* > c $ } \\
0 & \text{ if $y_t^* \le c $ }.
\end{cases}
\end{align}
The \intertext command is used to insert a line of text in a system of equations. The
\intertext command is issued immediately after a \\command. Note the position of
the text in the output.
5.5 Other Mathematical Environments 97
\begin{align}
A_1&=N_0(\lambda;\Omega)-\phi(\lambda;\Omega),\\
A_2&=\phi(\lambda;\Omega)-\phi(\lambda;\Omega),\\
\intertext{and}
A_3&=\mathcal{N}(\lambda;\Omega).
\end{align}
and
Tables
LATEX is very good at deciding where it can break a sentence or paragraph and go to a
new page. There are, however, certain blocks of material such as graphs, other figures
and tables that, in general, should not be broken across pages. Such items are known in
LATEX as floats. Sometimes they can be placed where they occur, other times times they
may be placed at the top or bottom of the existing page or even at the top or bottom of a
following page. Sometimes an author may wish to specify that all floats should be placed
at the end of a document. LATEX allows us to specify which of these options we prefer.
Once one has specified what material is to be included in floats and our preferences about
the positioning of the floats we can usually leave the rest to LATEX.
LATEX had two main environments or classes for floating material. Every float belongs
to one class. There are two default classes.
• figure for graphs, pictures and similar material. I shall deal with the figure
environment in more detail in chapter 7.
100 Tables
In this book I use a floating environment for setting various examples (e. g. example 6.1
on page 104). This environment is generated using the tcolorbox package (see section
8.13).
The basic code for a table environment is given in the box below
\begin{table}[preferences ]
table material e. g. tabular environment
\caption{Table Title }
\label{key }
\end{table}
where
h : Here - at the position in the text where the table environment appears.
If only h is given then it is amended to ht as there may not be sufficient space left
on the current page to put the table.
If you include a ! before the preferences LATEX will expand the space available on
the page and thus try harder to place the table there.
In the article and book classes the default is tbp. Remember LATEX decides which
of these three is appropriate and places the table there. If you do not have a lot of
tables (and other floats) then this will generally lead to a satisfactory result. Other
document classes may have different defaults.
Generally LATEX makes a good job of placing your tables. If you have a lot of
tables and figures you may not be happy with what it does. If LATEX has build up
a number of floats which it has been unable to place the command
\clearpage
ends the current page and causes all figures and tables that have so far appeared in
the input to be printed. For those who require more there is an extended account
on how to manage the placement of tables and other floats at the following link
LATEX Stack Exchange Link
Some Journals ask you to include tables at the end of the paper. The package
endfloat allows the placement of all floats at the end of the paper.
• If the caption is to be placed under the table you now insert the content of your
table before the caption and label statements. If the caption is to be inserted on
top of the table you place the \caption and \label statements before the table
content.
• The Table Title is the title of the table that will be printed under the table and in
the list of tables if required.
• The key is a label that can be used to refer to the table elsewhere in the document
using the LATEX command \ref{key}
LATEX looks after the numbering of your tables. If you insert an extra table early in
102 Tables
your document LATEX will renumber all subsequent tables and revise all references1 to
the renumbered tables in your documents.
The LATEX command \listoftables produces a list of the tables in the document.
In two column mode the table* environment produces tables that are spread across both
columns. In double column mode the unstarred table environment restricts the table to
a single column. Otherwise the two environments are the same.
• The purpose of your table is to convey, to the reader, information that can not be
given in running text.
• Only include, in your table, material that is relevant. Extra or irrelevant material
will deflect attention from the important items and may confuse the reader.
• Try to make your headings and the stub of your table as complete as possible. A
reader should be able to understand your table by simply looking at the table. He
should not have to search through text for explanations of what could be obvious
if the material in the table were set out properly.
• Minimise the number of vertical lines in your table. In fact typesetting experts
often claim that there should be no vertical lines in a table.
• In most cases an unedited version of the basic regression output from many eco-
nometric or statistical packages is not suitable for inclusion in a paper2 . Some
such software has facilities for outputting an enhanced version of the tables. I will
describe some of these facilities in chapter 9.
LATEX offers extensive facilities for typesetting tables. Voss (Voß) (2010b) is a full length
book devoted entirely to the typesetting of tables in LATEX. Next, I move to various ways
of producing the actual tables that go into the table float.
1
These references must have used the key parameter specified on the \label command
2
Heiberger and Holland (2004, Appendix E) claims that students who submit to them class papers
with an inappropriate use of computer output may have their papers returned marked unread.
6.3 The tabular and tabular* Environments 103
The tabular environment is the basic environment for producing tables with LATEX. If
you need to use this environment TeXstudio has a wizard that makes it a little easier
to use. Some econometric/statistical packages can output code for LATEX tables. These
are described in chapter 9. They use the tabular environment. Some of these short-
cut methods require some knowledge of the tabular environment. A knowledge of the
environment will also permit fine tuning of the results, if required.
The basic code for a tabular environment is given in the box below
\begin{tabular}{columns }
table contents
\end{tabular}
where
• the parameter columns describes the formatting of the columns of the table. There
is one entry for each column in the table.
{ColSeparator} :
• Cells within the line are separated by &. Column entries may include other LaTeX
commands.
• You may insert a horizontal line in a table with the \hline command. This com-
mand is issued immediately after the \\which ends the previous row.
• You may insert a horizontal line under a range of columns with the \cline{i-j}
command which inserts a line under columns i to j, inclusive.
• The table structure has four columns – the first left justified, the second centred,
the third right justified and the fourth is 2 cm in length.
• I have inserted a horizontal line before and after the next line which contains two
items, each of which is 2 columns in length. In
• The first three columns of the table contain some simple entries. The fourth column
may need a little more explanation. The entry fixed length of two cm shows
how entries are wrapped in a column of fixed length. The entry fixed \newline length
shows how to break a cell entry using \newline to specify where you want to break
the line.
\begin{tabular}{|l|c|r|p{2cm}|}
\hline
\multicolumn{2}{|c|}{heading1}&\multicolumn{2}{c|}{heading2}\\ \hline
item1 &item 2 &item3 & item 4 \\ \hline
a &b &c &fixed length \\
aa &bb &cc &fixed length of two cm \\
\cline{2-3}
aaa &bbb &ccc &fixed \newline length \\
Total & Total & Total & Total \\ \hline
\end{tabular}
heading1 heading2
item1 item 2 item3 item 4
a b c fixed length
aa bb cc fixed length
of two cm
aaa bbb ccc fixed
length
Total Total Total Total
There is no provision for footnotes in tables in basic LATEX. The can to some extent be
accommodated by a succession of complete row \multicolumn statements at the end of
the table. Perhaps a better way is by loading the threeparttable package. The use of
this is illustrated in example 6.2
tabular footnote.
• The command \tnote{} indicates what is to be footnoted. The same footnote may
be repeated several times.
\begin{threeparttable}[b]
\caption{Sample Table with Footnotes}
\begin{tabular}{p{2cm} p{1.5cm} p{1.5cm}}
\hline
item &\hfill value&\hfill t-stat \\
\hline
money\tnote{a} &\hfill .54 &\hfill 2.53 \\
inflation\tnote{b} & \hfill1.54 & \hfill.26 \\
constant\tnote{a} &\hfill 10.21 &\hfill 4.71\\
\hline
\end{tabular}
\begin{tablenotes}
\item[a] The first note
\item[b] The second note
\end{tablenotes}
\end{threeparttable}
Floating tables (and figures) are constrained to a single page. Usually this is not a con-
straint as most tables are smaller than a page. Occasionally one has a large table which
must be continued on to a second or third or more pages. The longtable environment
6.5 Long Tables 107
can be used in such circumstances. The following LATEXcode is and example of the use
this environment to produce a long table. The table gives monthly averages for the
exchange rates of the , ¥and £with the e. The code is followed by the table that it
produces. The following points should be noted.
• The format of the longtable environment is very similar to the tabular environ-
ment. There is an extra option ([c] here) which refers to the positioning of the
table. Here c is used to centre the table between the left and right sides of the
page. Other possible values are l and r which put the table against the left and
right margins respectively.
\firsthead : giving the text that appears at the top of the first page of the table.
\endfoot : giving the text at the bottom of every page except the last.
• The proper alignment of tables using the longtable environment may require up
to four LATEX runs if the table has been changed. This only applies to the next
processing cycle after the table has been edited.
\endlastfoot
January 2005 & 1.3119 & 135.63 & 0.69867 \\
February 2005 & 1.3014 & 136.55 & 0.68968\\
March 2005 & 1.3201 & 138.83 & 0.69233 \\
April 2005 & 1.2938 & 138.84 & 0.68293 \\
May 2005 & 1.2694 & 135.37 & 0.68399 \\
June 2005 & 1.2165 & 132.22 & 0.66895 \\
July 2005 & 1.2037 & 134.75 & 0.68756 \\
August 2005 & 1.2292 & 135.98 & 0.68527 \\
September 2005 & 1.2256 & 136.06 & 0.67760 \\
October 2005 & 1.2015 & 138.05 & 0.68137 \\
November 2005 & 1.1786 & 139.59 & 0.67933 \\
December 2005 & 1.1856 & 140.58 & 0.67922 \\
January 2006 & 1.2103 & 139.82 & 0.68598 \\
February 2006 & 1.1938 & 140.77 & 0.68297 \\
March 2006 & 1.2020 & 140.96 & 0.68935 \\
April 2006 & 1.2279 & 143.72 & 0.69435 \\
May 2006 & 1.2770 & 142.70 & 0.68330 \\
June 2006 & 1.2650 & 145.11 & 0.68666 \\
July 2006 & 1.2684 & 146.70 & 0.68782 \\
August 2006 & 1.2811 & 148.53 & 0.67669 \\
September 2006 & 1.2727 & 148.99 & 0.67511 \\
October 2006 & 1.2611 & 149.65 & 0.67254 \\
November 2006 & 1.2881 & 151.11 & 0.67397 \\
December 2006 & 1.3213 & 154.82 & 0.67286 \\
January 2007 & 1.2999 & 156.56 & 0.66341 \\
February 2007 & 1.3074 & 157.60 & 0.66800 \\
March 2007 & 1.3242 & 155.24 & 0.68021 \\
April 2007 & 1.3516 & 160.68 & 0.67934 \\
May 2007 & 1.3511 & 163.22 & 0.68136 \\
June 2007 & 1.3419 & 164.55 & 0.67562 \\
July 2007 & 1.3716 & 166.76 & 0.67440 \\
August 2007 & 1.3622 & 159.05 & 0.67766 \\
September 2007 & 1.3896 & 159.82 & 0.68887 \\
October 2007 & 1.4227 & 164.95 & 0.69614 \\
November 2007 & 1.4684 & 162.89 & 0.70896 \\
December 2007 & 1.4570 & 163.55 & 0.72064 \\
January 2008 & 1.4718 & 158.68 & 0.74725 \\
February 2008 & 1.4748 & 157.97 & 0.75094 \\
March 2008 & 1.5527 & 156.59 & 0.77494 \\
April 2008 & 1.5751 & 161.56 & 0.79487 \\
May 2008 & 1.5557 & 162.31 & 0.79209 \\
June 2008 & 1.5553 & 166.26 & 0.79152 \\
July 2008 & 1.5770 & 168.45 & 0.79308 \\
6.5 Long Tables 109
Table 6.2: Monthly Average USD, JPY and GBP exchange rates with Euro
Occasionally one will have a table that is to wide to fit on a portrait page but would
fit on a landscape page. The rotating package allows one to rotate floats. The manual
on my recommended default is at C:\MiKTeX-2.9\doc\latex\rotating\rotating.pdf.
Table 6.3 is taken from the file examples.tex in the same directory as the manual.
The code to produce the table is given below. I have reproduced the input code in land-
scape mode using the package lscape which introduces the landscape environment. The
landscape environment allows one to change some text in a portrait format document to
landscape. The lscape package may be used in conjunction with the longtable package
to produce wide tables that extend over more than one page.
114
\begin{sidewaystable}
\centering
\begin{tabular}{|llllllllp{1in}lp{1in}|}
\hline
Context &Length &Breadth/ &Depth &Profile &Pottery &Flint &Animal &Stone &Other &C14 Dates \\
& &Diameter & & & & &
Bones&&&\\
\hline
&&&&&&&&&&\\
\multicolumn{10}{|l}{\bf Grooved Ware}&\\
784 &--- &0.9m &0.18m &Sloping U &P1 &$\times$46 & $\times$8 && $\times$2 bone
& 2150$\pm$ 100 BC\\
785
&--- &1.00m &0.12 &Sloping U &P2--4 &$\times$23 & $\times$21 & Hammerstone &---&---\\
962 &--- &1.37m &0.20m &Sloping U &P5--6 &$\times$48 & $\times$57* & ---& ---
&1990 $\pm$ 80 BC (Layer 4) 1870 $\pm$90 BC (Layer 1)\\
983 &0.83m &0.73m &0.25m &Stepped U &--- &$\times$18 & $\times$8 & ---& Fired clay&---\\
&&&&&&&&&&\\
\multicolumn{10}{|l}{\bf Beaker}&\\
552 &--- &0.68m &0.12m &Saucer &P7--14 &--- & --- & --- &--- &---\\
790 &--- &0.60m &0.25m &U &P15 &$\times$12 & --- & Quartzite-lump&--- &---\\
794 &2.89m &0.75m &0.25m &Irreg. &P16 &$\times$3 & --- & --- &--- &---\\
\hline
\end{tabular}
\caption{Example of table in Landscape mode}
\end{sidewaystable}
Tables
Context Length Breadth/ Depth Profile Pottery Flint Animal Stone Other C14 Dates
Diameter Bones
6.6 Landscape Tables
Grooved Ware
784 — 0.9m 0.18m Sloping U P1 ˆ46 ˆ8 ˆ2 bone 2150˘ 100 BC
785 — 1.00m 0.12 Sloping U P2–4 ˆ23 ˆ21 Hammerstone — —
962 — 1.37m 0.20m Sloping U P5–6 ˆ48 ˆ57* — — 1990 ˘ 80 BC
(Layer 4) 1870
˘90 BC (Layer
1)
983 0.83m 0.73m 0.25m Stepped U — ˆ18 ˆ8 — Fired clay —
Beaker
552 — 0.68m 0.12m Saucer P7–14 — — — — —
790 — 0.60m 0.25m U P15 ˆ12 — Quartzite- — —
lump
794 2.89m 0.75m 0.25m Irreg. P16 ˆ3 — — — —
Graphics
This chapter deals with the incorporation of graphic material (e. g. graphs, diagrams,
photos) in LATEX documents In chapter 9 I shall give some details on using statistical/e-
conometric and other software to produce these graphics.
First a word about graphics formats. Basically these are of two kinds
Bit-mapped Graphics Bit-mapped graphics are a collection of dots with each dot having
a colour code attached. This is the format used on your computer screen and in
digital photographs. These files can be very large. Your software will produce a
bit-mapped image at a particular resolution. Thus a resolution of 300ˆ450 pixels
means that the image consists of a grid of 300ˆ450 colour coded pixels. If you wish
to reproduce this at another resolution pixels need to be added or taken away and
118 Graphics
there may be a loss of quality in the image. If the picture is magnified this may cause
considerable roughness at the edges of various shapes in the image. Bit mapped
images are more suitable for photographs or screen dumps. Vector images are more
suitable for the types of data graphs that are produced by statistical/econometric
analysis.
Most figures are included in a figure floating environment which I describe in the next
section. In section 7.3 I use the \includegraphics command to include the image in
this environment.
The figure environment is the second of the floating environment considered in subsec-
tion 6.1. It is used to set figures.
The basic code for a figure environment is similar to that for the table, and is given
in the box below.
The placement preferences are the same as those set out in subsectiom6.1 for the table
environment.
\usepackage{graphicx}
7.3 The graphicx package and \includegraphics command 119
The graphicx package supports the importation of the following file formats
Adobe Portable Document Format (pdf). This is the most common format used
for producing scientific papers and much other material. In this case the pdf file
contains only the image to be inserted in the document.
Joint Photographic Experts Group (jpg). This is the standard format used by di-
gital cameras to produce photographs. It is possible to edit such images using soft-
ware such as Adobe Photoshop (www.adobe.com), Gimp (http://www.gimp.org/)
and a variety of other packages. jpg files can be highly compressed and and some
information will be lost during compression. Often this loss of data is achieved
without any appreciable loss of quality. Use if you wish to include digital photo-
graphs or screen dumps in your text.
If one is using the direct pdfLaTeX approach (see section 2.6) the first three of these
formats are available. If you are using the dvi approach you can only use eps format
files. If you wish to use pdflatex and your analysis software produces images in eps
format then the images must be converted to pdf before being used. There are several
ways to do this.
epstopdf gfilename.eps
2. The process can also be achieved by loading the epstopdf package after the graphicx
package.
...
\usepackage{graphicx}
\usepackage{epstopdf}
...
If the epstopdf package is loaded and LATEX finds a .eps and no corresponding
.pdf it generates the required .pdf file. If both files exist it just imports the
.pdf file. If you insert an amended version of the .eps file you must
remember to manually delete the older .pdf file. Otherwise the pdf file
will not be updated. Links to a manual for this package are available at http:
//www.ctan.org/tex-archive/macros/latex/contrib/oberdiek
Sometimes you may find that a pdf image contains large large white borders. There
are many ways to remove these borders. The bris program available from http://
sourceforge.net/projects/briss/ is one such program.
2. Load the pdf file to be trimmed. The image is displayed with a proposed trimming
area.
3. You may change the proposed trim by moving the top left and bottom right corners
of the trim area. You may move the trimmed area by dragging any other part of
the trim area.
of extra work and might be left till one has mastered other aspects of LATEX. The LATEX
Graphics Companion (Goossens et al., 2008) contains considerable details on “native”
LATEX graphics as well as a good coverage on importing graphics material generated by
other software. Voss (Voß) (2011) is a 900 page book on Graphics and Postscript for
TEX and LATEX. Van Dongen (2012) contains an introduction to these methods.
CHAPTER 8
8.1 Introduction
This chapter gives a brief account of the purpose and use of the LATEX packages that I
have found useful. In a document of this size one must be very selective. The LATEX
Companion (Mittelbach and Goossens, 2004) covers a much larger selection of packages
in its 1090 pages. The arrangement of packages below id by function.
8.2 Languages
8.2.1 babel
The default language for LATEX is American English. The babel package provides facil-
ities for the use of LATEX to set documents in other languages. Loading babel with the
british option allows on to change the default to UK English. Many other languages
can be accommodated with an appropriate option. See table 11.1.
Several languages may be specified in the options on the babel statement. The last such
124 Other Useful Packages
language specified is the default for the document. It is possible to switch to one of
the other languages specified for a portion of the document. See the babel manual and
http://www.ctan.org/pkg/babel.
8.2.2 inputenc
Most modern keyboards are language specific. With a suitable editor and keyboard
characters specific to a language can be entered into LATEX from the keyboard. This
will not lead to any problem unless one is collaborating with a second author whoo uses
another keyboard. In such the inputenc package provides a solution to the problem. The
option
\usepackage[latin1]{inputenc}
can be used to facilitate collaboration between researchers using keyboards for most
European languages.
8.2.3 fontenc
In early TEX systems accented characters such as ö were produced by overprinting the o
with ¨. The fontenc package with the T1 option adds the accented character and many
other characters to LATEX.
\usepackage[T1]{fontenc}
8.2.4 textcomp
\usepackage{textcomp}
8.2 Languages 125
8.2.5 mathabx
mathabx provides some additional mathematical symbols. For lists and usage see the
manual http://.../CTAN/tex/fonts/mathabx/mathtest.pdf.
\usepackage{mathabx}
8.2.6 pifont
\usepackage{pifont}
8.2.7 eurosym
The eurosym package provides access to various forms of the Euro symbol. For details
see http://www.theiling.de/eurosym.html
\usepackage[left]{eurosym}
8.2.8 upquote
The upquote package sets proper quote characters in verbatim style environments. This
is important if your document includes computer listings which have quote characters.
\usepackage{upquote}
126 Other Useful Packages
8.3.1 graphicx
\usepackage{graphicx}
8.3.2 wrapfig
The package wrapfig allows text to wrap around a figure (See figure in first paragraph
of subsection 2.6 on page 24).
\usepackage{wrapfig}
8.4.1 setspace
The setspace package is an easy way to change line spacing in a document. It defines
three new commands which set line spacing as follows -
Line spacing is best set in the preamble where it will hold for the entire document. To
set line spacing at one-and-a-half spacing for the document include
8.5 American Mathematical Society - AMS - Packages 127
\usepackage{setspace}
\onehalfspacing
8.4.2 geometry
The geometry package allows one to change page margins. See http://www.ctan.org/
pkg/geometry. The package allows one to set various details of the page layout. The
following test specifies left and right margins of 3.5 cm. and top and bottom margins of
5 cm. for a one-sided document.
\usepackage[a4paper,left=3.5cm,right=3.5cm,top=5cm,bottom=5cm]{geometry}
For two-sided output one can use ‘inner’ and ‘outer’ margins rather than left and right.
To cater for binding the inner margin might be larger than the outer. Thus we might
specify –
\usepackage[a4paper,inner=4.5cm,outer=3.5cm,top=5cm,bottom=5cm]{geometry}
The amsmath package is distributed together with some small auxiliary packages:
amsmath Primary package, provides various features for displayed equations and other
mathematical constructs.
amstext Provides a \text command for typesetting a fragment of text inside a display
equation.
128 Other Useful Packages
amsopn Provides \DeclareMathOperator for defining new ‘operator names’ like sin and
lim.
amsbsy For backward compatibility this package continues to exist but use of the newer
bm package that comes with LATEX is recommended instead.
amscd Provides a CD environment for simple commutative diagrams (no support for
diagonal arrows).
amsxtra Provides certain odds and ends such as \fracwithdelims and \accentedsymbol,
for compatibility with documents created using version 1.1.
The amsmath package incorporates amstext, amsopn, and amsbsy. The features of amscd
and amsxtra, however, are available only by invoking those packages separately. These
later two packages will not be needed by the majority of readers of this book. I would also
recommend including the package amssymb which provides extra mathematical symbols.
(see ftp://ftp.ams.org/pub/tex/doc/amsmath/short-math-guide.pdf)
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bm}
1
After a recent update to MiKTeX 2.9 LATEX runs started to report that amsmath.sty was not found
and MiKTeX did not try to install the missing package. The problem was, apparently, due to a repack-
aging of the AMS packages which the MiKTeX package management system could not handle. The work-
around is to re-install the amsmath (and ams-latex) packages using the MiKTeX package management
system. Once the packages are re-installed use |repositories|synchronize| to synchronise the MiKTeX
package management system on the PC with the package repository. After this you may find that a
LATEX run reports a missing etex.sty. You can fix this by installing the package miktex-etex-base-2.9
and again synchronize with the repositories. See http://tex.stackexchange.com/questions/96778/
a-miktex-update-removed-amsmath-as-obsolete-can-i-use-another-package-or-get-i
8.6 Table Formatting Packages 129
8.6.1 longtable
The longtable package allows long tables that stretch over more than one page. Some
details of this package have been given in section 6.5
8.6.2 threeparttable
The threeparttable package provides extra facilities for the setting of titles and foot-
notes in tables. Its use in setting footnotes is described in section 6.4.
8.6.3 dcolumn
The dcolumn package defines a system for columns of entries in an array or tabular which
are to be aligned on a ‘decimal point’. In particular it provides a new column specifier
for the tabular and array environments. The format of this new specifier is
where
\begin{tabular}{|D{.}{\cdot}{-1}|D{.}{\cdot}{2}|D{.}{\cdot}{1}|D{.}{\cdot}{0}|}
1.2& 1.2& 1.2& 1.2\\
1.23& 1.23& 12.5& 300.2\\
1121.2& 1121.2& 861.20& 674.29\\
184& 184& 10& 69\\
.4& .4& &.4\\
& &.4& \\
\end{tabular}
Note that the first column, which had a negative (decimal places) argument is wider than
the second column, so that the decimal point appears in the middle of the column. In
the second column the specification sets out the exact number required. The last two
columns show what can happen when the number of decimals specified is less than the
number in the input.
8.6.4 array
The array package provides extensions to the tabular and array environments. Table 8.1
gives details of the column formatting options that are provided by the package.
Unchanged options
l Left adjusted column.
c Centred adjusted column.
r Right adjusted column.
p{width} Equivalent to parbox[t]{width}.
Suppresses inter-column space and inserts decl. in-
@{decl.}
stead.
New options
Defines a column of width width. Every entry will
m{width\} be centred in proportion to the rest of the line. It is
somewhat like \parbox{width}=.
b{width\} Coincides with \parbox[b]{width}=.
Can be used before an l, r, c, p, m or a b option.
>\{decl.\} It inserts decl. directly in front of the entry of the
column.
Can be used after an l, r, c, p{..}, m{..} or a b{..}
<{decl.\} option. It inserts decl. right after the entry of the
column.
Inserts a vertical line. The distance between two
| columns will be enlarged by the width of the line in
contrast to the original definition of LATEX.
Can be used anywhere and corresponds with the | op-
tion. The difference is that decl. is inserted instead
+!{decl.}+ of a vertical line, so this option doesn’t suppress the
normally inserted space between columns in contrast
to =@...=.
8.6.5 caption
The caption package allow one to format the caption to a float. I use
\usepackage[format=hang]{caption}
to produce captions such as the caption for the ghost table 8.2.
The package also allows many other ways of formatting tables. See the manual.
132 Other Useful Packages
Table 8.2: This an Example of a table with a long title which is set over more than one
line and uses the format=hang option in the caption package. The table is
omitted. only the caption is set
8.6.6 url
The url package provides a convenient way of setting email addresses, hypertext links,
directories paths, and file names in some operating systems. MS Windows file names
are better set with a combination of the \texttt and \textbackslash commands as in
example 8.22 .
The url provides two two new commands \url and urldef (If hyperref is not loaded
- see subsection 8.14). By default the url ignores spaces in any email address, url, file
name etc. that it type sets. This can be overridden by using the obeyspaces option as
in the box below.
\usepackage[obeyspaces]{url}
8.6.7 natbib
The natbib package provides enhanced facilities for citations and the bibliography. It is
described in subsection 15.1.2.
2
The hyperref breaks the \urldef command in the url package.
8.7 Enhanced Listing Package 133
8.7.1 paralist
The paralist environment extends the three LaTeX listing environments, (enumerate,
itemize and description). It provides for listing within paragraphs, changes in the
spacing and labelling of lists. The package also allows individual items in a list to be
referenced. Examples 8.3, 8.4 and 8.5 are taken from the paralist manual.
\begin{asparaenum}
\item Every \verb|\item| is basically set as a separate paragraph. The
second line is not indented (this is a feature, not a bug).
\item The next \verb|\item| looks like this and is labelled \label{pl1}
\end{asparaenum}
1. Every \item is basically set as a separate paragraph. The second line is not indented
(this is a feature, not a bug).
2. The next \item looks like this and is labelled
The compactenum environment is just a compact version of the standard LATEX enumerate
environment. In the default the space between items is set to zero but it is adjustable
the LATEX itemize environment except that symbols are used instead of numbers in the
lists. You may specify the symbols to be used.
There are also similar extensions to the LATEX description package, asparadesc inparaitem
and inparaitem environments.
The fncychap package provides alternative ways of setting Chapter headings in the book
class. Look at the manual. The chapter headings in this book was produced by including
\usepackage[Sonny]{fncychap}
in the preamble to the document. The fncychap application provides facilities for chan-
ging LATEX default chapter headings and gives several new pre-set heading formats.
8.9 Page Styles and the fancyhdr package 135
A good reference for the material in this section is section 16.7 of Wiki Colaboration
(2013)
The LATEX defaults for headers and footers depend on the document class in use. They
will be satisfactory for most users. If you are preparing material for publication it is
possible that the publishers style file contains specific instruction for headers and footers.
If so the publisher’s instructions should contain the necessary instructions to reproduce
these details with LATEX. If you are writing a book or long document you may wish
to change the content of your headers and footers to aid the reader in negotiating the
136 Other Useful Packages
document. The remaining material in this section is only relevant if you wish to change
the defaults.
A short explanation of the defaults and some terminology is necessary before we consider
how to change them. A page in a publication consists of three parts –
1. a header,
2. the text and
3. a footer
In the front matter in this book (preface, table of contents) the page number is placed in
the centre of the footer and the headers are empty. In the main matter there are different
headers on the even and odd numbered pages. On the even numbered pages the page
number is on the outside and the chapter title on the inside edge. On the odd numbered
pages the page number is on the outside and the section number and title are on the
inside. The book is set up for two-sided printing. With the book open flat the even and
odd numbered pages are on the left and right respectively. This layout is intended to aid
the reader in navigating the book.
In one-sided printing the specified style for the odd-numbered pages is used.
In standard LATEX two commands that are commonly used to change the way in which
headers and footers are used.
1. \pagestyle{option }
2. \thispagestyle{option }
The command \pagestyle{} applies to the current and subsequent pages. The command
\thispagestyle{} applies to the current page only. In the front matter the command
\pagestyle{plain} is used to put a page number in the centre of the footer and nothing
in the header. after a \pagestyle{myheaders} command the command
8.9 Page Styles and the fancyhdr package 137
can be used to set the headers in the (in the standard book, report and article)
classes and
can be used to set headers and footers. A left header is generated by the last \markboth
command before the end of the page, while a right header is generated by the first
\markboth or \markright that comes on the page if there is one, otherwise by the last
one before the page.
as headers on the left and right hand pages. (The page numbers are inserted by LATEX
in the appropriate place)
In the header generation commands you can insert special commands which extract
details of the current page in the document
8.9.2 fancyhdr
While it is possible to define new styles for headers and footers in base LATEX this is
not easy. If you do need to do so, I would recommend using the fancyhdr3 package.
This package introduces a new option fancy to the \pagestyle{option } command.
This option can be defined to to customize various aspects of the layout of the page –
headers, footers marginal notes, placement of floats etc. As illustrated in the box below,
for headers and footers, there are eight items that can be specified when the fancy style
is in operation.
page body
These eight items include the contents at the left (L), centre (C) and right (R) of the
header and of the footer and the decorative lines dividing the header or footer from the
main text in the body of the page. We can also have separate definitions for the odd-
(O) and even-numbered (E)pages.
The commands
\fancyhead[positions ]{content }
or
\fancyfoot[positions ]{content }
are used to define the content of the headers and footers. where positions is a position
or a list of positions using the abbreviations in the previous paragraph. For example, OL
3
At the time of writing the latest version of the documentation for this package is in (Mittelbach and
Goossens, 2004, pages 224-232) There is also a good account of the package in Wiki Colaboration (2013)
8.9 Page Styles and the fancyhdr package 139
means the Left header on an Odd-numbered page and ER the Right header on an Even
Page.
I used the following code to produce the headers and footers in this book.
\usepackage{fancyhdr}
\frontmatter
\pagestyle{plain}
% Front matter - Abstract etc. - inserted here
\mainmatter
\pagestyle{fancy}
\fancyheadoffset[LE,RO]{0.3\marginparwidth}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{}
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers
\renewcommand{\headrulewidth}{0pt} % and the line
}
In the front material (abstract, contents table etc.) I do not want any material in the
headers or footers other than the basic Roman numeral page number in the footer. The
\pagestyle{plain} command in the frontmatter achieves this effect.
In the main part of the document the header on the odd numbered pages contains (a) The
section number and section title on the left hand side (OR) and (b) the page number on
the right hand side (OL) of the header.
The header on the even numbered pages contains (a) the page number on the left hand
140 Other Useful Packages
side (EL)of the header and (b) the chapter title on the right hand side (ER). The page
number the headers contain (a) page numbers (b) chapter title or (c) section number
and section title.
I also have a decorative line under the header. This line is extended to the left on the
even numbered pages and to the right on the odd numbered pages. The footer is empty.
Next I explain how the commands in the box above achieve these effects
1. The command \pagestylefancy sets the default headers and footers for the fancyhdr
package. These are revised in what follows.
8. The remaining lines redefine the plain style to remove the material in the headers
and the line separating the header from the text.
8.10 Packages for Typesetting Pages in Landscape 141
The fancyhdr package is much more flexible than one might conclude reading this section.
It is more complex than other details of the LATEX system and, if possible the beginner
might avoid using it until he is more familiar with LATEX.
8.10.1 lscape
The lscape package provides an environment landscape which allows on to switch from
portrait to landscape format. The environment works by starting a new page and setting
the remainder of the material in the environment in landscape mode. At the end of the
environment a new page is started and typesetting is returned to portrait mode. This
environment is compatible with the longtable package.
8.10.2 rotating
8.11.1 fancyverb
The Verbatim environment has a variety of options which provide considerable flexibility
in the formatting of the verbatim test. The main options/facilities are
(a) The use of verbatim commands and environments (the standard LATEX and fancyvrb
ones) in footnotes. This is possible after a \VerbatimFootnotes statement in the
document.
(b) Allow comments in verbatim environments.
Example 8.6: Example of a comment in a verbatim statement
(c) Suppress initial characters of listing - useful if you wish to reproduce a computer
listing or similar which is indented in its source and this indentation not needed in
your output.
(d) The formatcom option allows one to issue a command before the Verbatim listing.
In example 8.7 this process is used to change the colour of the verbatim text to red.
Example 8.7: Example of the use of the formatcom option
to use in the verbatim text. The font families tt (default), courier and helvetica
are predefined. Example 8.8 shows how to change the font used in verbatim test to
helvetica.
Example 8.8: Example of change of font family in a Verbatim environment
(g) Change font size – The fontsize option allows you to change the font size in the
verbatim text. If you also use the relsize package you can specify a change of font
relative to the current font. Example 8.9 reduces the font size in the verbatim text
by two steps. This process is most useful if some lines in your verbatim test overflow
the page when the current font size is used.
Example 8.9: Example of change of font size in a Verbatim environment
\begin{Verbatim}
first Verbatim line
second Verbatim line
\end{Verbatim}
\begin{Verbatim}[fontsize=\relsize{-2}]
first Verbatim line
second Verbatim line
\end{Verbatim}
Further details of these and other facilities are given in the fancyvrb manual.
8.11.2 cprotect
The cprotect package is an alternative way to to put verbatim text in footnotes, section
titles, etc.
The xcolor package provides facilities for typesetting in colour. For details see the
xcolor manual.
8.13 tcolorbox
The tcolorbox package provides an environment for coloured and framed text boxes
with a heading line. Optionally, such a box can be split in an upper and a lower part.
In this book I use this package to set the examples 8.6 to 8.9 above. The LATEX source
code in the upper and the corresponding output in the lower. This environment is used
to set many of the coloured boxes in this paper.
8.14 hyperref
The hyperref package extends the functionality of all the LATEX cross-referencing com-
mands - including those relevant to the table of contents, bibliographies etc. - to produce
internal commands which can be turned into hypertext links. It also provides new com-
mands to allow the user to write hypertext links, including those to external documents
and URLs. As the package amends many LATEX commands it should be the last pack-
age loaded in the preamble. In this document the package is the last one loaded in the
preamble as follows.
\usepackage[breaklinks,pagebackref]{hyperref}
8.14 hyperref 145
The breaklinks option allows long hyper-references to be spread over two lines, the part
on each line acting as a link. The pagebackref adds pages numbers to the bibliography.
These page numbers are hyperlinks to the page containing the citations.
146 Other Useful Packages
CHAPTER 9
9.1 Introduction
Many users prepare graphs and tables in a spreadsheet or word processor. They use
statistical/econometric packages to analyse their data. The purpose of this chapter is
to give an outline as to how material generated in this way can be transferred to LATEX
without having to re-key tables and re-generate graphs. While the facilities described
here relates only to packages that I have used, the general methodology may also apply
to other software.
1. How to transfer to LATEX tables, regression and other results from statistical/e-
conometric and other software.
2. How to use, in LATEX graphs produced in such software. These instructions assume
an understanding of the material in Chapter 7.
The basic output produced by many packages is designed for viewing on screen. Students,
sometimes, simply cut and paste this output into into a word processing program and
148 Using Output from External Programs with LATEX
then reproduce it proportional font such as Times Roman. If they use a fixed font the
material may be wrapped over a second line. In either case the output will be difficult
to read and will not do justice to what, otherwise, may be excellent work.
The better analysis programs produce publication quality tables and graphs and provide
a means of transferring them to a report generating package. Many others only provide
a partial solution. Any package that requires the transfer of data by hand should be
avoided. Many of the facilities outlined in this chapter may also be useful to users of the
analysis programs who are using word processors to produce their reports.
Over the years I have used three spreadsheet programs (in alphabetical order, Calc
(LibreOffice or OpenOffice), Excel and Gnumeric).
Many economists prepare tables for reports with Excel. An Excel add-In (excel2latex)
is available which outputs Excel tables in LATEX format. Text formatting (bold, italic),
alignment (left, right, centred), and rotation of cell contents is retained. Cells spanning
multiple columns and/or rows are also supported. Border lines can be retained at the
level of individual cells, or replaced with the style of formatting recommended by the
booktabs package. The LATEX code can be copied to the clipboard or saved as a LATEX file,
which then can be included in an existing LaTeX document using the input command
or pasted into a LATEX document. You can also specify which ranges of your Excel
workbook you want to convert into LATEX, and convert the ranges as individual LATEX files.
For more information see http://www.ctan.org/tex-archive/support/excel2latex/.
Installation instructions are in the Readme file in that directory.
LibreOffice and OpenOffice are two very similar free open source “Office” products.
In 2010 development of OpenOffice ceased and many of the volunteer programmers
working on OpenOffice transferred their allegiance to the new LibreOffice1 . In 2011
work on OpenOffice resumed under the Apache Software Foundation. The spreadsheet
package in both is known as Calc. Currently both versions of Calc are similar and I have
1
LibreOffice can be downloaded from http://www.libreoffice.org/download/ and OpenOffice from
http://www.openoffice.org/download/.
9.2 Spreadsheets and LATEX 149
used the methods described here in both versions. While I now use the LibreOffice
version feel free to use the other particularly if you have local support. In my own work
I use Calc in preference to Excel.
Calc has some very flexible delimited file output facilities which I have long used to
transfer data between programs. Calc can use or import data in Excel, xls, xlsx, csv
and many other formats. I have used it to import, to LATEX and other packages, data
from other programs, the web, and various data-bases. The procedure that I use with
Calc may be summarised as follows2 .
3. Edit, Delete or insert data as required. You may need to format some columns to
give the required number of decimal places.
4. In the menu |File|Save as| in the drop-down box select “Text CSV (.csv)(*.csv)”
and ensure that the box “Edit filter settings is ticked.
5. Enter a file name and select “Save”. Confirm csv format when prompted.
6. In the “Enter Text File” dialogue (see figure 9.1) that appears enter & as “Field”
delimiter and delete any “Text delimiter”. Selecting “OK” will now save the file in
a format that can be included within a tabular environment.
7. Each line in the generated file will now end with &\\. Open the file in a text editor3
and use a global find and replace to replace each &\\in the file with \\. This gives
a file that can be incorporated in a tabular, longtable or similar environment.
Gnumeric is a free spreadsheet program that provides many of the facilities of Excel and
Calc. If you are using a spreadsheet for statistical analyses then Gnumeric is the best
choice.4
2
I am using Calc to set up the tabular structures described in chapter 6. You might need to refer to
some of the material in that chapter.
3
As a text editor. I recommend notepad++ (http://notepad-plus-plus.org/) or Scite (http:
//www.scintilla.org/SciTE.html)
4
For farther elaboration see McCullough and Heiser (2008) from which the following quote is taken –
Excel 2007, like its predecessors, fails a standard set of intermediate-level accuracy tests
in three areas: statistical distributions, random number generation, and estimation. Ad-
ditional errors in specific Excel procedures are discussed. Microsoft’s continuing inability
150 Using Output from External Programs with LATEX
If you have tables in Gnumeric they can be saved directly in LATEX format. This gives
results similar to those obtained using the procedure described above for Calc. The
delimited file export facilities in Gnumeric are also very flexible and it is possible to
follow a scheme similar to that described above for Calc.
I often find that graphs produced in Excel are often a bit clumsy or unwieldy. They
look better in powerpoint presentations than in printed material. Perhaps this is an
indication of my lack of knowledge of Excel and a more experienced Excel user might
make better use of the spreadsheet graphics facilities than me. I do find it easier to
produce publication quality graphics in other software. I think that Excel graphs are
aimed at business/marketing users5 .
The most convenient way to transfer Excel graphs to LATEX is to save the graph as a
pdf file and use an \includegraphics instruction to include the graphics file in your
document. I accomplish this in one of two ways.
1. Right-Click on the image and |File|Save as| and select Save as Type pdf.
2. If you have a pdf print driver such as PDFCreator 6 . This adds a virtual printer
to correctly fix errors is discussed. No statistical procedure in Excel should be used until
Microsoft documents that the procedure is correct; it is not safe to assume that Microsoft
Excel’s statistical procedures give the correct answer. Persons who wish to conduct statist-
ical analyses should use some other package.
5
Perhaps Excel graphics facilities are not targeted at my kind of work.
6
PDFCreator can be downloaded from http://www.pdfforge.org/pdfcreator.
9.3 Word Processors and LATEX 151
to your list of printers and allows you to generate pdf files by printing the item
(graph) to a pdf file on the virtual printer.
Calc can export graphs as pdf from the File menu. Gnumeric can save the graph (Save
as image) in pdf and other formats that may be of interest to a LATEX user (e. g. svg,
ps, eps etc. )
If you use LATEX you may encounter some problems in working with a journal or with
colleagues who do not use LATEX. There is a summary of solutions at http://tug.org/
utilities/texconv/textopc.html. All of these solutions work in some cases but none
are 100% satisfactory in all cases. The best way to proceed probably depends on the
relative amount of text, mathematics, and graphics in your document.
One can generally transfer a short document (e. g. journal article size) from LATEX to
Word relatively easily without resort to any of these utilities. In such a case I would
proceed as follows
1. The text of the article can be transferred by cut and paste from the LATEX or pdf
document to the word processor.
2. Mathematics can be entered using the word processor’s equation editor or the
special symbols in the word processor.
3. You may be asked to supply diagrams as separate files. Often the editor of his staff
may be more flexible that the journal’s regulations. Check how flexible they are
and act accordingly.
4. If you have a few tables consider resetting them in your word processor. Alternat-
ively you can transfer them as follows.
(b) paste to your spreadsheet, (in Excel 2010 use |Home|Paste|Text Import
Wizard|),
5. You can also copy, paste and edit the bibliography from the LATEX pdf document
to your Word processor.
Given the relatively short length of academic papers this process should not be too
onerous and can be completed in a few hours.
I have used simple copy and paste to to move large segments from word processing
documents to LATEX. I would then enter remaining material directly in my LATEX editor.
Again for short documents the transfer should not be to onerous and completed in a few
hours.
I have found that direct translation from word processors to LATEX generates some very
complicated LATEX code. Any editing of these files may be very complicated. In general
I would avoid such translations if possible.
Abiword and LibreOffice can import documents in MS Word formats and Save as or
Export the document in LATEX format. This will attempt to maintain the format and
pagination of the original word processing documents. To obtain the advantages of LATEX
will, in most cases require further editing.
Graphs generated by Eviews can be saved as eps and transformed to pdf using epstopdf.
9.4 Some Statistical/Econometric Packages and LATEX 153
Introduction
gretl is an open-source statistical package, mainly for econometrics. The name is an ac-
ronym for Gnu Regression, Econometrics and Time-series Library. It can be downloaded
from http://gretl.sourceforge.net/. It has a graphical user interface (GUI) and can
be used together with X-12-ARIMA, TRAMO/SEATS, R, Octave, Jmulti and Ox. As
a complement to the GUI it also has a command line interface (CLI). Work done in the
GUI can be recorded in the CLI. These recorded commands can be saved, retrieved and
edited if necessary and rerun with amendments as necessary.
It can import plain text files (comma-separated or “CSV” being the most common type),
Spreadsheet files (MS Excel, Gnumeric and Open Document (ODS)), Stata data files
(.dta), SPSS data files (.sav), SAS “xport” files (.xpt), Eviews workfiles (.wf1), JMulTi
data files. It can import data from various databases (e. g. Rats 4, PCGive) and offers
ODBC connectivity.
It can export to GNU Octave, R, Comma Separated Values, JMulTi, and PcGive file
formats. It is very easy to use, supports most current econometric routines and new or
advanced procedures can be scripted in the CLI.
For our purposes model estimation results and other tabular material can be formatted
and output as LATEX code for incorporation in a LATEX document.
Gretl uses gnuplot to produce graphs. These graphs can be saved in pdf and a variety
of other formats. The interface to gnuplot itself is through the command line but gretl
provides a GUI to gnuplot which allows one to amend various aspects of a chart (e. g.
axis labels, legends, scales etc.).
IN summary gretl not only provides good facilities for econometric analysis but also
one of the best interfaces between an econometric package and LATEX. Adkins (2013)
contains further material on gretl. The latest version of that document may be down-
loaded from http://www.learneconometrics.com/gretl/index.html. Chapter 35 of
the gretl user’s manual (Cottrell and Lucchetti (2014)) contains details of the interface
between gretl and LATEX.
154 Using Output from External Programs with LATEX
The Matlab publish functions allow one to produce formatted reports in a variety of
formats including LATEX. the easiest way to access these functions is through the Matlab
graphical user interface. The interface produces LATEX code which should be processed
by a LATEX program. Details are available in the Matlab Help files.
MATLAB/Octave Graphics
MATLAB generates a great variety of excellent graphics. You may save these in pdf
format using the |File|Save as| and specify Save as type pdf. or using the command
in your script. Both Matlab and Octave offer extensive and flexible facilities that can be
used to produce publication quality graphics for inclusion in LATEX documents.
MATweave
The original file contains active Matlab/octave code and LATEX code as Matlab/octave
block comments7 . This file is first processed by Matlab or octave which analyses the
data and produces the required results for inclusion in the report. The second trick
is to include the verbatim package in the preamble and define new Matlab/Octave
7
Block comments are available in Matlab version R14 and later and Octave from version 3.2
9.4 Some Statistical/Econometric Packages and LATEX 155
environments based on \comment and \verbatim. allowing you to treat the octave
input as comments. A LATEX sequence will then produce the required output.
R has more LATEX functionality than the other programs considered here. If you are
already using R you are probably familiar with at least some of this functionality. I will
restrict myself to just listing a few of the facilities. If your work or research involves heavy
statistical analysis R is recommended. The task views on http://cran.r-project.org/
give an introduction to the use of R in a variety of disciplines. An economist might
consult Kleiber and Zeileis (2008), Pfaff (2008) or Vinod (2008) which deal with the use
of R in applied econometrics.
• texreg – produces regression output in LATEX form) are available for typesetting R
estimation results as LATEX tables.
The graphics facilities in R are comprehensive and output may be saved as pdf, eps or
in a variety of other formats.
The knitr8 R package allows one to embed R code in a LATEX document. This is some-
what similar to but much more powerful than the MATweave system for Matlab/octave
discussed in the previous section. knitr is described on http://yihui.name/knitr/ and
in Xie (2014). Gandrud (2014) deals more generally with doing reproducible research
with R, RStudio, knitr and other tools. A knitr empowered script is basically a LATEX
document with embedded chunks of R code. These chunks of R code can be reproduced
or not reproduced, can do calculations, can fetch data and produce output in the form of
data, formatted tables graphs etc. In effect they can do anything that R can do.
The RStudio GUI for R eases the production of “knitr” documents and automates their
processing.
The knitr package can create dynamic reports, which can be updated automatically
if data or analysis change. Instead of inserting a prefabricated graph or table into the
report, the master document contains the R code necessary to obtain it. Each time we
run the document through R, all data analysis output (tables, graphs, etc.) is created
on the fly and inserted into a final LATEX document. The report can be automatically
updated if data or analysis change, which allows for truly reproducible research.
Rats has a report command that is used to produce reports. These reports are similar
to spreadsheets. They can contain the results of a wide variety of analyses. They can
also be formatted (number of significant figures or decimals, row and column names,
justification of column and row contents etc.). When the reports have been generated
they can be exported to file or to the clipboard in LATEX format. This material can be
incorporated in your LATEX document. There are examples in the Rats users’ guide and
reference manuals.
The Rats package contains excellent graphics facilities. I would generally save Rats
graphs in eps format and use epstopdf to convert to pdf.
Below is a list of user contributed modules that aid the transfer of Stata output to LATEX.
Some of these commands may also be useful in preparing a report using a word processor.
These are not part of a standard Stata distribution. If you have administrative rights on
your PC you can install these using the Stata findit command.
dotex Execute commands from a do-file, creating the log file in LATEX format. This can
then be copied directly to your LATEX source file. See http://ideas.repec.org/
9.4 Some Statistical/Econometric Packages and LATEX 157
c/boc/bocode/s420001.html
esttab The stata command estout produces summary tables of estimated regression
models. esttab can export these tables in various formats including LATEX. Note
that it is possible to exercise considerable control over the content, format, number
of decimal places etc. in such tables. See http://repec.org/bocode/e/estout/
esttab.html
graph2tex Generates LATEX statements and and a eps file to include in your LATEXfile.
See http://www.ats.ucla.edu/stat/stata/latex/graph_stata_latex.htm. In
the pdflatex scheme it will be necessary to convert this eps file to pdf. It may be
easier to generate the graph, save your image as pdf and use the TeXstudio wizard
to generate the code.
latab Produce LATEX output from the stata command tabulate. See http://ideas.
repec.org/c/boc/bocode/s430001.html
latabstat The stata command tabstat produces a table giving various summary stat-
istics.
latabstat produces corresponding results in LATEX code. See http://www.ats.
ucla.edu/stat/stata/latex/tabstat_stata.htm.
listtex List a variable list to a file or to the log for inclusion in a LATEX, HTML, or word
processor table. See http://ideas.repec.org/c/boc/bocode/s423201.html
maketex Creates a LATEX file from the using file. See http://econpapers.repec.org/
software/bocbocode/s424301.htm
outreg Write formatted regression output to a text file. Should work after any estimation
command. See http://www.kellogg.northwestern.edu/rc/stata-outreg.htm
outtex Generates LATEX code for results tables after any estimation command. See
http://www.ats.ucla.edu/stat/stata/latex/estimates.htm
sutex generates LATEX code for summary statistics tables (stata summarize command).
See http://www.ats.ucla.edu/stat/stata/latex/list_variables.htm
158 Using Output from External Programs with LATEX
9.5.1 GIMP
GIMP is a free open source image manipulation program which has a lot of the functionality
of the commercial PhotoShop. I sometimes use the Windows snipping tool to produce
screen images (jpg) for inclusion in LATEX documents. If I need to add text annotations
to the image I have found it easy to open the jpg fine in GIMP, use the text tool to add
the annotations and then export the file as jpg9 .
GIMP is a bit of a monster for a relatively minor task such as this but it does work
well.
9.5.2 gnuplot
gnuplot is a free open source graphics package designed for the presentation and graphing
of scientific data and the production of publication quality graphics. Many other packages
use gnuplot to generate graphics In particular the graphics produced by gretl and
octave10 are generated by gnuplot. In effect gretl provides a user friendly access to
most of the facilities of gnuplot that many might need. In effect, to use gnuplot through
gretl one does not have to know anything about gnuplot.
If you are familiar with gnuplot and gretl the gmuplot script generated by gretl can
be saved and refined in gnuplot.
Both packages have good manuals. Two recent books about gnuplot are Philips (2012)
and Janert (2010)
To quote from their website Graphviz is free open source graph visualization software.
Graph visualization is a way of representing structural information as diagrams of ab-
stract graphs and networks. It has important applications in networking, bioinformatics,
software engineering, database and web design, machine learning, and in visual interfaces
9
GIMP can open jpg file but can not save them with the usual |File|Save| menu. You can however use
the |File|Export to| menu to save as jpg.
10
octave can also use other graphics engines
9.5 Other Software and LATEX 159
for other technical domains. GVedit is a graphical user interface to the system. The dia-
gram in section 2.6. was generated using this software. The Graphwiz script used to
generate that diagram is given below.
digraph G {
"file.tex" [shape=box];
"file.pdf"[shape=box];
"file.tex" -> "file.dvi" [label="latex.exe"] ;
"file.dvi" -> "file.ps" [label="dvips.exe"] ;
"file.ps" -> "file.pdf" [label="ps2pdf.exe"] ;
"file.tex" -> "file.pdf" [label="pdflatex.exe "] ;
}
There are some further examples in the dot users guide which, after a standard install,
is available at
C:\Program Files (x86)\Graphviz 2.28\share\graphviz\doc\pdf\dotguide.pdf
CHAPTER 10
10.1 Introduction
• An editor to compose revise and edit the document. The editor might have
– The usual type of menu bar for various file, editing etc. commands.
– Icons giving access to a good selection of the mathematical and other symbols
available in LATEX.
162 Other LATEX Editors (TEXworks, TEXMaker etc. )
– Code completion for various LATEX commands. For example, one should be
able to type the first few letters of a LATEX command and then the IDE should
be able to complete the command.
• The ability
If you do a web search on “best LATEX IDE” you will get a confusing variety of recom-
mendations. Some users will have already used an IDE or editor for writing programs
(e. g. Eclipse, Notepad++) and they have a good knowledge of it. There may be an
extension to their existing system that allows them to prepare and process LATEX docu-
ments. Their knowledge of the particular editor means that this may be an appropriate
10.2 Texmaker 163
choice for them. Others have started with a particular IDE because a colleague or other
user recommended it. They spent time learning it and now are happy to recommend it
to other users. In effect there are many LATEX IDEs that produce good results. None
are perfect. All have good points and all have bad points. The aim of TeXstudio is
to incorporate the better points of other IDEs. In my opinion it does this well. The
installation and use of TeXstudio has been covered in Chapter 3.
If you have access to a LATEX guru who supports and recommends another IDE or another
IDE is widely used in your organisation then you might consider using that alternative.
This book has been written using TeXstudio. From time to time I have compiled the
document with other GUIs. I now give some details of those alternative IDEs that I have
used over the years.
10.2 Texmaker
In 2009 Texstudio forked from the original TeXmaker. Both programs still have many
features in common. If I was using postscript files and using the tex ñdviñpsñpdf
methodology I might prefer Texmaker to TeXstudio. Texmaker is available from http:
//www.xm1math.net/texmaker/.
10.3 Texworks
Texworks is the IDE distributed with TEX Live. If you consider that TeXstudio is a little
cluttered 1 then you should consider Texworks. Texworks is inspired by the TeXShop
LATEX IDE for Mac OS X. There is set of short-cuts available for LATEX commands,
environments and characters. This works well if you are familiar with LATEX , but I think
that it might be a little confusing for a beginner. I have the experimental TeXworks
development build for Windows v0.5r1010 loaded on my PC. It also allows the more
standard command completion methods. (i. e. if I type \begin{eq and press the Tab
key it cycles through the available choices)
Sometimes the manuals for various LATEX packages and other documents are available
on the web or on your PC in both pdf and LATEX formats. If these are downloaded to
the same directory loading the LATEX file into Texworks also loads the pdf file into the
1
I don’t but I have heard others say so.
164 Other LATEX Editors (TEXworks, TEXMaker etc. )
TeXworks pdf reader. If there is an effect in the pdf that I admire and would like to use
in my own document it is then easy to see exactly how the effect was achieved.
10.4 Emacs/AucTeX
The first operational version of Emacs was available in 19762 . The current version of
the program (24.3) is basically a text editor with various add-ons that set up “modes”
which allow it to work as an IDE for various programs. (e. g. AucTeX for LATEX, ESS for
statistical packages, Octave mode for Octave etc.). The power and flexibility of Emacs
should not be underestimated. However this power and flexibility do not come free. Emacs
is difficult. Unless you already use it for some other purpose I would not recommend
that you adopt it. A specially augmented installation Windows/Mac Emacs installation
program can be downloaded from http://vgoulet.act.ulaval.ca/en/emacs/.
10.5 TeXnicCenter
TeXnicCenter is popular in various circles. I have only briefly looked at it and have
never really used it to any great extent. If the other LATEX users in your Department
use it and they are willing to provide help and assistance if you run into trouble then
consider using it.
10.6 WinEdt
WinEdt is shareware. You can download it for a trial period of 31 days. After this
period you are required to purchase a license. WinEdt can be downloaded from http:
//www.winedt.com/.
I was a regular user of WinEdt 5 for many years. When WinEdt 5 was updated to version
6 I decided to look at some alternatives and changed to Winshell which was my main
editor for some years.
2
see http://en.wikipedia.org/wiki/Emacs#History
10.7 Winshell 165
10.7 Winshell
Winshell has a simpler interface to LATEX that some people might welcome. It is available
from http://www.winshell.de/.
10.8 LyX
LyX documents may be exported to LATEX in formats suitable for direct processing by
LATEX pdfLATEX or other TEX processing systems. LyX can also import LATEX documents.
(Complex documents may cause some problems) The beamer package3 has special facil-
ities for preparing presentations with LyX.
I find LyX a little difficult to use. I think that the approach used by many of the other
LATEX editors is more flexible and quicker to use. It may be that when I looked at the
program in detail some time ago standard PCs were not powerful enough to readily run
it in MS Windows. It does, however have some devoted proponents who advocate its
use.
It might be mentioned that the preview system in TeXstudio has been taken from LyX
and allows one to mimic one of the main features of LyX.
3
beamer is a package for the preparation of presentations See chapter 14 of this document
CHAPTER 11
The box below contains a skeleton LATEX script for a paper. Each package that is loaded
in the preamble contains a brief explanation of its purpose. If you substitute your details
in the title and author sections and then enter the required text in the main body of
the document you will produce a well formatted document.
Many of the packages used are described in chapter 8 of this book. Manuals for many of
the packages are available in your LATEX distribution in C:\...\doc\latex\. Manuals for
these packages may also be found on the web. For example the manual for the hyperref
package may be downloaded from http://www.ctan.org/pkg/hyperref. Manuals for
the other packages may be downloaded from a similar link by substituting the name of
the package for hyperref in that link. http://www.ctan.org/pkg/ contains an index of
all packages available in CTAN, including many that are not mentioned in this note.
In using the skeleton script you may comment the usepackage instruction for any pack-
ages you do not require. You may also vary the options as required.
%
% skeleton file for a document of the article class.
%
\documentclass[11pt,a4paper]{article}
168 Writing a paper with LATEX
%
% The default language for LATEX is American English.
% The babel package provides facilities for the use of LATEX
% in other languages. Loading babel with the british option allows on to
% change the default to UK English
% Language Packages
\usepackage[british]{babel}
% Most modern keyboards are language specific. With a suitable editor characters
% specific to a language can be entered into LATEX from the keyboard
% This will not lead to any problem unless one is collaborating with a second
% author whoo uses another keyboard. In such the inputenc package provides a
% solution to the problem. The option
\usepackage[latin1]{inputenc}
% can represent most European languages. You may not need this package
\usepackage[T1]{fontenc}
\usepackage{textcomp}
% The eurosym package provides access to various forms of the Euro symbol.
% For details see \url{http://www.theiling.de/eurosym.html}
\usepackage[left]{eurosym}
\usepackage{upquote}
% Graphics Packages
\usepackage{graphicx}
\usepackage{wrapfig}
%\usepackage[format=hang]{caption}
% Activate next line to begin paragraph with an empty line rather than an
% indent
%
% \usepackage[parfill]{parskip}
170 Writing a paper with LATEX
% AMS Packages
% Load the longtable package if you have long tables that stretch over more
% one page.
\usepackage{longtable}
% URL Package
\usepackage{paralist}
% Verbatim Packages
% Paper Title
% Define the title and author variables. The \\ is a new line instruction.
% the \thanks inserts a footnote in the title page.
\title{Introduction to \LaTeX \\ for Economists \\ Social Scientists \\and Others \\ }
\author{John C Frain \\
Economics Department \\
Trinity College Dublin
\thanks{Comments to \url{[email protected]}}}
% Text of Document
\begin{document}
% the \maketitle instruction inserts the title using the `title' and `author'
% variables defined in the preamble.
173
\maketitle
\newpage
% Add abstract
\begin{abstract}
content of abstract to be added
\end{abstract}
\newpage
\section{Introduction}
text of introduction
\section{Title of section 2}
text of section 2
\section{Title of section 3}
text of section 3
\section{Title of section 4}
text of section 4
\bibliographystyle{chicago}
\bibliography{bibtex data bases }
\end{document}
Language Option(s)
Afrikaans afrikaans
Bahasa bahasa, indonesian, indon, bahasai, bahasam,
malay, meyalu
Basque basque
Breton breton
Bulgarian bulgarian
Catalan catalan
Croatian croatian
Czech czech
Continued on next page
174 Writing a paper with LATEX
If your university has an official LATEX package for a thesis then use it. If your university
has not got an official LATEX thesis package the perhaps some lecturer or other student has
an unofficial one. Failing this, a lecturer or another student is willing to give you a copy
of the preamble they used in similar circumstances that should be a good starting point.
You might also find that a LATEX package designed for another university might satisfy
your university’s requirements. In this chapter I set out what is currently required for a
thesis in Trinity College Dublin and give a preamble that meets the current requirements.
A student should always check the current requirements at his own university as they
may change from time to time. The preamble here duplicates a lot of what is in the
LATEX paper preamble in the previous chapter. Chapter 8 contains more details of some
of these packages and manuals for the packages are available on the web.
The Trinity College Dublin current thesis regulations contain the following provisions
–
spacing must be at one and a half or double spacing between lines. The
gutter margin of both text and diagrams must not be less than 35 mm and
that on the other three sides not less than 20 mm. The two copies of the
thesis for examination should be soft-bound and printed on one side of the
page only. It is expected that the hard-bound copy of a thesis will be printed
on both sides of the page on paper of a weight of at least 90 gsm. A copy
of the hard-bound thesis will be lodged in the Library following approval by
Council. Colour photocopies and scanned images may be used in the copy of
the thesis deposited in the Library.
1.32.8 Declaration. The thesis must contain immediately after the title page
a signed declaration that
a) it has not been submitted as an exercise for a degree at this or any other
University,
b) it is entirely the candidate’s own work (in the case of a thesis for which
the work has been carried out jointly; there must be a statement that it
includes the unpublished and/or published work of others, duly acknow-
ledged in the text wherever included) and
c) the candidate agrees that the Library may lend or copy the thesis upon
request. This permission covers only single copies made for study pur-
poses, subject to normal conditions of acknowledgement. (See below for
withheld access (a “stay”) for such permission).
1.32.9 Summary. A succinct summary of the methods used and the major
findings of the thesis must be bound into each copy of the thesis following
the declaration page. It must not exceed two pages of typescript.
paper, must be submitted loose with each copy of the soft-bound thesis. The
abstract must contain the title of the thesis and the author’s full names as
a heading and may be single spaced. Two copies of an abstract must be
submitted loose with the final hard-bound copy.
1.32.13 Submission. Two copies of the thesis, which may not be returned,
and which for the first submission must be soft-bound and printed on one
side of the page only, should be presented at the Graduate Studies Office,
accompanied by two loose copies of the abstract.
My basic aim is to augment the LATEX article skeleton in chapter 11 to satisfy these
requirements. It should be easy to accommodate the requirements of other universities or
to adapt the skeleton to produce a book. In the listing below there is a brief description
of the purpose of each package included. More details of the packages are given in
Chapter 8 and in the manuals for the packages. The main options that you should
consider are —
For presentation purposes I have divided the thesis file into two parts
1. The preamble
2. the document contents
The contents of each part can be cut from the listings and pasted into a file in TeXstu-
dio.
180 Writing your Thesis with LATEX
%
% Skeleton file for a Thesis fulfilling TCD requirements 2012/13
%
% There are two `documentclass' statements - The first gives one-sided output for
% initial submission, the second two-sided for the final submission.
%
%\documentclass[12pt,a4paper,fleqn,oneside]{book}
\documentclass[12pt,a4paper,fleqn,twoside]{book}
%
%
% The default language for LATEX is American English.
% The babel package provides facilities for the use of LATEX
% in other languages. Loading babel with the british option allows on to
% change the default to UK English
% Language Packages
% Many other languages can be accommodated with an appropriate option. See
% table 11.1.
\usepackage[british]{babel}
% The eurosym package provides access to various forms of the Euro symbol.
181
% The upquote package gives appropriate quotation marks in verbatim style environments.
% This is useful if you have computer listings in your document.
\usepackage{upquote}
% Graphics Packages
% Load the graphicx package. See Section 7.
\usepackage{graphicx}
%Load the longtable package if you have long tables that stretch over more
% than one page.
\usepackage{longtable}
% The `caption' package allow one to format the caption to a float. I use
\usepackage[format=hang]{caption}
% URL Package
% Allow the typing of email addresses, hypertext links, directories/paths, etc.
% The obeyspaces option keeps spaces in the url. Without this option they are ignored.
\usepackage[obeyspaces]{url}
\usepackage{natbib}
% The parskip package with the parfill option inserts a blank line between paragraphs.
% Comment the next \usepackage statement if you do not like this effect.
\usepackage[parfill]{parskip}
% Chapter Headings
% The `fncychap' package provides alternative ways of setting Chapter headings
% in the book classs. Look at the manual. Try
\usepackage[Sonny]{fncychap}
% Page Layout
% The `fancyhdr' package allows one to set various features of the page layout,
% including headers, footers, etc.
\usepackage{fancyhdr}
% Verbatim Packages
% The `fancyvrb' environment provides enhancements to the `verbatim' environment.
% It provides the `Verbatim' environment which has one extra argument compared to
% the standard `verbatim' environment. This example of a LATEX preamble %
% has been produced using a `Verbatim' environment with options for fontsize,
% substitution of command characters /, { and } and inclusion of the typeset %
% environment in a frame
\usepackage{fancyvrb}
\usepackage{relsize}
% The `cprotect' package attempts to do something that is not possible allows you
% to put verbatim in footnotes, section titles, in a straightforward way. See section
% 4 of this note and the `cprotect' manual
\usepackage{cprotect}
% The `tcolorbox' package provides an environment for coloured and framed text boxes
% with a heading line. Optionally, such a box can be split in an upper and a lower part
%Thus the package may be used for the setting of LATEX examples where
% one part of the box displays the source code and the other part shows the output.
% This environment is used to set many of the coloured boxed examples in this paper
% e. g. figure 1.1, 1.2 etc. The \tcbuselibrary{listings} command is setting the
% listings option for the tcolorbox package.
\usepackage{tcolorbox}
\tcbuselibrary{listings}
%
% Text of Document follows
%
\begin{document}
\frontmatter
% The \maketitle instruction inserts the title using the `title' , `author' and `date'
% variables defined in the preamble.
\maketitle
% The declaration on a single page
\pagestyle{plain}
%\thispagestyle{empty}
\begin{center}
\section*{Declaration}
\end{center}
I declare that this thesis submitted to the University of Dublin, Trinity College,
for the degree of Doctor of Philosophy,
\renewcommand\theenumi{\alph{enumi}}
\begin{enumerate}
\item has not been submitted as an exercise for a degree at this or any other
University;
\item is entirely my own work; and
\item I agree that the Library may lend or copy the thesis upon request. This
permission covers only single copies for study purposes, subject to
186 Writing your Thesis with LATEX
% The Summary
\pagestyle{plain}
%\thispagestyle{empty}
\begin{center}
\section*{Summary}
\end{center}
Type the summary of the paper here
\newpage
%Acknowledgements (1.32.10)
\begin{center}
\section*{Acknowledgements}
\end{center}
Type your acknowledgements here
\newpage
\tableofcontents
\listoftables
\listoffigures
\mainmatter
\normalsize
\pagestyle{fancy}
\fancyhead{}
\fancyhead[LE,RO]{Section \thesection}
\chapter{Introduction}
\section{Preview}
This is just a simple example of the layout for a thesis which has been typeset with
LaTeX. You should consult your University regulations and amend as necessary. If your
university has an approved LaTeX style you should, of course use that.
\section{Postscript}
I hope that this introduction has helped you to produce a well formatted thesis.
\chapter{Results from an earlier seminar\protect \footnotemark}
\footnotetext{This Chapter is based on a paper (\cite{Frai07}) presented at:
\begin{itemize}
187
\section{Introduction}
Your introduction
\section{The Model}
Your theory and the consequent model, In order to populate a bibliography I cite at
random from my own bibliographic database.
\citet{Blat71,Bouc00,Cham76,Cont01,Nola07,Pano95,Paol01,Voit05,Barn01}.
\section{Econometric Estimates}
My econometric results are shown in table~\ref{tab:sample1}.
Figure~\ref{fig:samplegraph} compares the actual and fitted data.
\begin{table}
\begin{center}
\caption[Sample OLS results]{ OLS, using observations 1958--1972 ($T$ = 15)\\
Dependent variable: log(Y)}
\label{tab:sample1}
\begin{tabular}{lrrrr}
\multicolumn{1}{c}{ } &
\multicolumn{1}{c}{Coefficient} &
\multicolumn{1}{c}{Std.\ Error} &
\multicolumn{1}{c}{$t$-ratio} &
\multicolumn{1}{c}{p-value} \\
const & $-3.34$ & 2.45 & $-1.36$ & .2 \\
l\_X2 & $1.50$ & 0.54 & $2.78$ & 0.0 \\
l\_X3 & $0.49$ & 0.10 & $4.80$ & 0.0 \\
\end{tabular}
\end{center}
\end{table}
\begin{table}
\begin{center}
\begin{tabular}{lrlr}
Mean dependent var & 10.09653 & S.D. dependent var & 0.207914 \\
Sum squared resid & 0.067158 & S.E. of regression & 0.074810 \\
$R^2$ & 0.889030 & Adjusted $R^2$ & 0.870535 \\
$F(2, 12)$ & 48.06885 & P-value($F$) & 1.87\textrm{e--06} \\
Log-likelihood & 19.28156 & Akaike criterion & $-$32.56312 \\
Schwarz criterion & $-$30.43897 & Hannan--Quinn & $-$32.58575 \\
$\hat{\rho}$ & 0.365748 & Durbin--Watson & 0.891083 \\
\end{tabular}
\end{center}
\end{table}
188 Writing your Thesis with LATEX
1, & t>0. \\
\end{array}%
\right.
\end{equation}
\chapter{Computer Programs}
\fancyhead[LE,RO]{Section \thesection}
\section{Packages}
\newpage
\section{Special Routines}
\backmatter
\bibliographystyle{plainnat}
\fancyhead{}
\fancyhead[RO,LE]{Bibliography}
\bibliography{C:/Home/bibliographies/stable}
\end{document}
CHAPTER 13
The file exam.cls provides the exam document class, which attempts to make it easy for
even a LATEX novice to prepare exams. This class is provided by the exam package. If this
package is missing from your system it may be installed using either the MiKTeX or Tex
Live package management systems. A user guide is available at http://www-math.mit.
edu/~psh/exam/examdoc.pdf. The following description of the package is taken from
the introduction to this manual. The references in the quoted material are to sections of
the manual.
Specifically, exam.cls sets the page layout so that there are one inch
margins all around (no matter what size paper you’re using) and provides
commands that make it easy to format questions, create flexible headers and
footers, change the margins, and create grading tables. In more detail:
• The class will automatically format and number the questions, parts of
questions, sub-parts of parts, and sub-sub-parts of sub-parts (see sections
4.1 and 4.2).
• You can include the point value of each question (or part, or sub-part,
or sub-sub-part), with your choice of having the point values printed at
the beginning of the text of the question, opposite that in the left margin,
192 Setting Exercises and Examination Papers with LATEX
opposite that in the right margin, or in the right margin opposite the end
of the question (see section 4.3).
• The class will add up the total points for each question (and all of its
parts, sub-parts,and sub-sub-parts) and the total points on each page, and
make those totals available in macros (see sections 4.3.9, 9.5 and 9.6).
• You can have the class print a grading table, indexed either by question
number or by page number (see section 9.1).
• You specify the header in three parts: One part to be left justified, one
part to be centred, and one part to be right justified, and one or all of
these can be omitted (see section 11.2).
• The footer is also specified in three parts: Left justified, centred, and
right justified (see section 11.3).
• The header and footer for the first page can be different from the ones
used on other pages (see sections 11.2.1, 11.2.2, 11.3.1, and 11.3.2).
• Both headers and footers can contain more than one line. To accommod-
ate headers and footers with several lines, simple commands are provided
to enlarge the part of the page devoted to the header and/or footer, and
these commands can give one amount of space on the first page and a
different amount of space on all other pages (see section 11.4).
• Macros are defined to enable you to state the total number of pages in
the exam (see section 11.6) and to change the header and/or footer that
appears on the last page of the exam (see section 11.7).
• Macros are defined so that the headers and footers can vary depending on
whether the current page begins a new question or continues a question
that started on an earlier page (and, if one continues onto the current
page, to say what the number of that question is). Macros are also
defined so that the headers and footers can vary depending on whether
a question is complete on the current page or continues on to the next
page (and, if one continues, to say what the number of that question is)
(see section 11.9).
• You can have a horizontal rule at the base of the header and/or at the
top of the footer (see section 11.5).
• The exam can begin with one or more cover pages, which are numbered
separately from the main pages of the exam and which can have headers
and footers different from the ones in the main pages of the exam (see
section 12).
193
• You can include solutions in your LATEX file and have these solutions
either printed or ignored (or replaced automatically by space in which the
students can write their answers) depending on a single command (see
section 8, section 5.5, and section 7.6). The latest version of exam.cls
(possibly a beta test version) should always be available at http: //
www-math. mit. edu/ ~psh/ .
The exam class is very flexible. Like most flexible systems it can be hard to learn.
Chapter 2 of the manual gives instructions for a basic exam and is relatively simple.
You could start with Chapter 2 and then extract facilities from the remainder of the
manual as required. Often you may not even need to go beyond Section 2. You can,
of course use, as required, in your exam scripts, other standard LATEX mathematics and
text facilities.
CHAPTER 14
LATEX in combination with the beamer package can be used to produce professional qual-
ity transparencies and slides, with much less effort than the market leader. Figure 14.1
is an example of such a slide which has been produced using a supplied theme and the
default set up. You can of course use other themes and colours.
• The black and blue band across the top gives hyperlinks to various parts of the
document. A beamer document should be structured into sections and subsections
like any LATEX article. These sections and subsections can be based on the structure
of your paper or draft paper. By clicking on one of the section links in the black
area a list of subsections is displayed in the blue area. By clicking on one of the
subsection links one opens the (first) slide in that sub-section.
• In beamer technology the basic slide is known as a frame. At the top of the frame
there is a frame title.
196 Using Beamer for Presentations
• This frame contains two blocks. Each block has a title. In this case each block
contains an itemize environment. Many blocks will contain some kind of list
environment.
• If you have external hyper-links in your presentation and have internet access during
your seminar you can access the links during your presentation.
– Prepare handouts and lecture notes containing reduced copies of the slides.
• At many talks I have been not been amused (?) by slides consisting of an A4
portrait page of tightly packed tabular data, in a 10 point font, reduced to fit on
a landscape slide. This is usually accompanied by an apology that the slide is
probably unreadable by any member of the audience but .̇. Why does one go to
the bother of producing a slide that is not readable? Beamer produces slides that
contain fonts that are large enough to be read by all the audience. The usual font
commands can be used to some extent to reduce the size of the fonts in a beamer
presentation this is to be avoided if possible. In any case the effect of such font
change is not as extreme. If your audience needs access to such condensed material
printed copies should be made available.
• There is a very good manual1 for beamer. As well as the usual technical material
in such manuals there is good general advice on how to prepare for a presentation,
illustrative examples and templates for various types of seminar. There is some
introductory material on beamer in Goossens et al. (2008) and Van Dongen (2012).
Voss (Voß) (2012b) is devoted to presentations in LATEX.
• Perhaps I am a little unfair to the market leading presentation program as I have not
used it for many years. In my opinion beamer a far superior presentation product
in an academic context. The ease of preparing presentations and the quality of the
product are added advantages of learning LATEX.
If you have installed the full version of TEX Live or MiKTEX beamer is already installed.
If you installed a minimum version of TEX you need to check that the three packages
1
References to the beamer user guide are to that for version 3,20.(Tantau et al., 2012)
198 Using Beamer for Presentations
beamer, pgf and xcolor are installed. Install them if they are not installed. For TEX
Live use the TEX Live Manager (tlmgr) to install these packages. For MiKTEX use the
MiKTEX Package Manager (Admin). (For further details see the beamer manual and
subsection 2.3 of this note).
Beamer is called by setting the documentclass to beamer as in the box below. This is
followed by the usetheme command which specifies the entire layout of the presentation.
The themes are named after cities. Sections 15.2 to 15.6 of the beamer user guide
describe 29 such themes. The theme used to produce figure 14.1 was Warsaw. It is
possible to reconfigure these themes or to compose one’s own theme but for the beginner
it is probably better to stick with one of the provided themes.
\documentclass{beamer}
or
\documentclass[options ]{beamer}
%
\usetheme{Warsaw}
I usually use the first specification as options are not often required.
The preamble is then continued by loading whatever packages are required. beamer auto-
matically loads a variety of packages (e. g. amsthm, color, enumerate, hyperref,xcolor.
beamer sets its own options, etc. for these packages. Usually this causes no problem
unless you wish to override one of these options. Section 2.6 of the user guide contains
material on possible conflicts. My recommendation would be to minimise the number of
packages loaded when using beamer. I should add that, following this advice, I have not
encountered any such conflicts.
The following box contains a sample set of slides for a presentation. The slides are
reproduced on pages 205 to 208. The references to Mackay (1852) results from the fact
that I was reading this book as I was writing the first draft of this chapter. The content
of the sample presentation is not to be taken seriously. It should act as a template for
your presentations. You should be able to cut and copy from the box and compile and
get something similar to the slides on pages 205 to 208. Notes on the presentation follow
14.3 The Presentation 199
the box.
\documentclass{beamer} % Note 1
%
\usetheme{Warsaw} % Note 2
%
% Languages Options
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[left]{eurosym}
%
\usepackage{graphicx}
%
\usepackage{amsmath}
\usepackage{amsthm}
% Note 3
\newcommand{\rd}{\ensuremath{\mathrm{d}}} % Provides an upright derivative sign
%
\title{Extraordinary Popular Delusions and the Madness of Crowds}
\author{Charles Mackay \\
Illustrated London News
\thanks{Comments by mail to Illustrated London News}
}
\date{1\textsuperscript{st} ed. (1841), 2\textsuperscript{nd} ed. (1852)}
\begin{document}
\begin{frame} % Note 4
\frametitle{Summary} % Note 5
\maketitle
\end{frame}
\section{introduction} % Note 6
\begin{frame} % Note 4
\frametitle{Summary} % Note 5
\tableofcontents % Note 7
\end{frame}
%
\section{Bubbles} % Note 6
\subsection{Mississippi Scheme} % Note 8
\begin{frame} % Note 4
\frametitle{John Law} % Note 5
\begin{block}{1671-1715} % Note 9
\begin{itemize} % Note 10
\item Banking Family
200 Using Beamer for Presentations
\item Gambling
\item Duelling
\end{itemize}
\end{block}
\pause % Note 11
\begin{block}{Mississippi Company} % Note 9
\begin{enumerate} % Note 10
\item Louisiana Trading Company
\pause % Note 11
\item Banque General
\pause % Note 11
\item Bubble and Collapse
\end{enumerate}
\end{block}
\end{frame}
\subsection{South-Sea Bubble} % Note 8
\begin{frame} % Note 4
\frametitle{South-Sea Bubble} % Note 5
Material for Slide
\end{frame}
\subsection{Tulipmania} % Note 8
\begin{frame} % Note 4
\frametitle{Tulipmania} % Note 5
Material for Slide
\end{frame}
\section{Analysis} % Note 6
\subsection{Tulips} % Note 8
\begin{frame} % Note 4
\begin{figure} % Note 12
\begin{center}
\includegraphics{tulips_mixed}
\end{center}
\caption{Tulips}
\end{figure}
\end{frame}
\end{equation}
Integrating
\begin{align}
x(t) &= \int_t^\infty \exp \left(-\frac{\tau-t}{\alpha} \right)\frac{f(\tau)}{\alpha}%
\rd \tau \notag \\
&+ \lim_{T\to \infty}\exp \left(-\frac{\tau-t}{\alpha} \right) x(T) \notag \\
& \equiv F(t) + B(t)
\end{align}
\end{frame}
\end{document}
1. The LATEX code preamble is a reduced version of the preamble that might be used
in a paper, thesis or other similar document. Packages that are not relevant to a
presentation are simply removed. Possible conflicts are documented in section 2.6
of the beamer user manual.
2. The theme here is Warsaw. Try one of the alternative themes from section 16 of
the manual and choose another if you prefer it.
202 Using Beamer for Presentations
4. The basic environment for a beamer presentation is the frame. It is probably best
at this stage to think of the frame as a slide for the presentation. In the first frame
I use the LATEX command \maketitle to extract from the preamble the details of
author, affiliation, etc. and and make a title slide for the presentation.
5. The command \frametitle adds a title to the frame. It is recommended that you
add a title to each frame.
• Introduction
• Bubbles
• Analysis
9. The block environment allows one to highlight parts of a frame. See top slide on
page 206 which contains two blocks.
10. Many frames and blocks will contain list environments (e. g. itemize, enumerate
as used in this example) to be displayed
11. The pause command is used to display parts of a frame in sequence. The first
pause command will cause the material in the frame as far as that pause to be
displayed. Thus when you are presenting your material the slide will display only
the first block. The next slide will contain the first block and the material in the
second block as far as the next pause command. The process is repeated until the
you reach the end of the frame
12. You can insert graphs and figures in exactly the same way as you insert them in
your basic document.
13. In this slide we enter an equation, some text and an equation structure. Again this
is done in a similar way as in an ordinary document.
14.3 The Presentation 203
14. In this slide we put the equation and the structure in two separate blocks with a
pause separating the two blocks.
15. The slides on pages 205 to 208 do not show the effects of the \pause commands.
16. If you wish to include verbatim text in a frame you must use the fragile option
to the frame environment e. g.
\begin{frame}[fragile]
\frametitle{verbatim text}
\begin{verbatim}
Material in a verbatim environment is included in
the final document exactly as typed in that environment.
Even special characters which have special meanings in
LATEX, such as #, $, %, &, ~, _, ^, {, }, \,
are produced as is. Verbatim is an extended version of the
verbatim environment.
\end{verbatim}
\end{frame}
17. The material in this example is a simple introduction to the facilities of the beamer
class and does not cover many advanced facilities. For example it is possible for a
department wishes to set up a departmental theme with departmental logos and
colour schemes. For further details see the manual or Voss (Voß) (2012b)
204 Using Beamer for Presentations
The slides on pages 205 to 208 are one form of handout that might be given out
at a presentation. They were produced by replacing the part of the script before
%Language Options by
\documentclass[handout]{beamer}
%
\usetheme{Warsaw}
%
\usepackage{pgfpages}
\pgfpagesuselayout{2 on 1}[a4paper]
\mode<handout>{\setbeamercolor{background canvas}{bg=black!4}}
%
Note
• In this illustration I have used the theme Warsaw. In producing these pages I was
trying to illustrate both the production of slides and of handouts. For the handout
it would be better to use a plainer theme such as the default (delete or comment
out the \usetheme) or the Montpelier, Singapore or Szeged.
• The pgfpages package is used to assemble several pages into a single page. It is
part of the Tik & PGF graphics package.
introduction
Bubbles
Analysis
Charles Mackay
Illustrated London News 1
1
Comments by mail to Illustrated London News
Charles Mackay Illustrated London News Extraordinary Popular Delusions and the Madness of Crowds
introduction
Bubbles
Analysis
Summary
1 introduction
2 Bubbles
Mississippy Scheme
South-Sea Bubble
Tulipmania
3 Analysis
Tulips
The Model
Alternative Display of Model
Charles Mackay Illustrated London News Extraordinary Popular Delusions and the Madness of Crowds
206 Using Beamer for Presentations
John Law
1671-1715
Banking Family
Gambling
Dueling
Mississipy Company
1 Lousiana Trading Company
2 Banque General
3 Bubble and Collapse
Charles Mackay Illustrated London News Extraordinary Popular Delusions and the Madness of Crowds
South-Sea Bubble
Charles Mackay Illustrated London News Extraordinary Popular Delusions and the Madness of Crowds
14.4 Handouts etc. 207
Tulipmania
Charles Mackay Illustrated London News Extraordinary Popular Delusions and the Madness of Crowds
introduction Tulips
Bubbles The Model
Analysis Alternative Display of Model
Figure : Tulips
Charles Mackay Illustrated London News Extraordinary Popular Delusions and the Madness of Crowds
208 Using Beamer for Presentations
introduction Tulips
Bubbles The Model
Analysis Alternative Display of Model
Bubble Model
dx(t)
x(t) = f (t) + α (1)
dt
Integrating
Z ∞
τ − t f (τ )
x(t) = exp − dτ
t α α
τ −t
+ lim exp − x(T )
T →∞ α
≡ F (t) + B(t) (2)
Charles Mackay Illustrated London News Extraordinary Popular Delusions and the Madness of Crowds
introduction Tulips
Bubbles The Model
Analysis Alternative Display of Model
System
dx(t)
x(t) = f (t) + α (3)
dt
Integrating
Z ∞
τ − t f (τ )
x(t) = exp − dτ
t α α
τ −t
+ lim exp − x(T )
T →∞ α
≡ F (t) + B(t) (4)
Charles Mackay Illustrated London News Extraordinary Popular Delusions and the Madness of Crowds
CHAPTER 15
15.1 Introduction
There are four ways to manage your citations and bibliography in LATEX.
1. Record your bibliography data in a BibTEX compatible data base and use the
bibtex program to extract your citations and material for your bibliography. This
is the method that we will concentrate on here. Your data base can be added to and
reused in your next paper. This method ensures that the format of your citations
and bibliography are consistent throughout the document.
2. Use a BibTEX compatible data base, the biblatex package and the biber or bibtex
program. This is a more modern approach but it is unlikely that the extra facilities
will be required by a new user.
3. Use the thebibliography environment. This allows you to enter your bibliographic
material in a special format in the document. It is only satisfactory when the
bibliography is very short and I would not recommend it.
4. You could just enter your bibliography using text and LATEX commands. I would
210 Managing your References
The first step in using bibtex is the compilation of a BibTeX bibliography data base.
The Jabref program greatly simplifies this process. For example the data base entry for
the book Hayashi (2000) is
@BOOK{Haya00,
title = {Econometrics},
publisher = {Princeton University Press},
year = {2000},
author = {Fumio Hayashi}
}
The initial @BOOK that starts the entry indicates that this is a reference for a book.
Alternatives entry types provided by Jabref include ARTICLE, BOOKLET, CONFERENCE,
ELECTRONOC, INBOOK, INCOLLECTION, INPROCEEDINGS, MANUAL, MASTERTHESIS, MISC,
OTHER, PATENT, PERIODICAL, PHDTHESIS, PROCEEDINGS, STANDARD, TECHREPORT,
UNPUBLISHED. When you use Jabref to enter a new item in your data base you will be
asked to choose one of these types. Depending on your choice you will be asked for
material to enter in the data base.
The bibliographic information is included between the braces ({ and }) that follow the
item description. The first item Haya00 is the code that is used to cite the book. You can
15.1 Introduction 211
choose this code yourself. I use the first four letters of the first author’s surname followed
by the last two digits of the year of publication. If this method leads to duplication of
codes I add letters a, b etc. You are free to choose your own code for each publication.
Choose a coding system that you will find easy to remember. The remaining items
(title, publisher, year and author) are self explanatory. For an entry of BOOK
these four items are obligatory. Each one of the entry types has its own set of obligatory
items. You do not have to recall these as the Jabref will show you which items are
obligatory for each type. There are also many optional items that may also be entered.
Figure 15.1 shows how the Hayashi (2000) entry was entered into the data base. You can
add a new entry to a BibTEX database using the menu item |BibTeX|New Entry| (or
Cnrl + n). You will then be presented with a dialogue asking you to specify the entry
type. In this case Book is selected. and we may make the appropriate entries as shown
in the figure.
In making your entry there are a few rules that should be followed. The general idea
is that capitalization and punctuation in your citations and bibliography are best left
to LATEX and BibTEX. The capitalisation of the title depends on the bibliographic style
in use. Usually Book titles are capitalised while article titles are not. Unless you are
required to follow a “house” style in such matters it is probably more important that your
style is consistent.
Sometimes the style may not do what you require or expect. For example if a biblio-
graphic journal item contains “Microsoft Excel” you may wish to retain the upper case
“M” and “E”. In McCullough and Heiser (2008) I required capital letters on “Microsoft
Excel” and specified the title as
Enclosing any text (here the M and the E) in braces ({ and }) ensures that the case
is preserved. Thus, it is good practice to enclose the first letter of a proper name or
abbreviations such as IMF in braces to ensure that they are not changed to lower case.
If you have any of the LATEX special characters in the title they must be dealt with in
the same way as in the body of the document.
The author field needs some more explanation. If there is a single author his name is
entered as
or
Thus author={John C. Frain} and author={Frain, John C.} are equivalent. If there
is no comma in the author field the last name is regarded as the surname. If there is a
comma or commas then what precedes the final comma is regarded as the surname. If
the author has a double surname the comma form must be used and the double surname
15.1 Introduction 213
given before the comma. Note that I have used an initial “C. ” in the author field and
that I must follow this with a space.
If you have joint authors use either of the two formats to enter their names in the author
field and separate the authors by and e. g.
Note that the K in MacKinlay is between braces. This ensures that the capitalisation is
maintained if it is to be listed. In general anything included in the author field that you
do not wish LATEX (BibTEX) to convert to the specified style must be included in braces
e. g.
or
Jabref presents you with a tabbed set of forms to enter the details of the item. The first
tab contains the obligatory items. The last form gives the generated BibTEX entry for
the database. CTRL+s saves the entry. CTRL+e edits an existing item. In general
Jabref works like any Windows program.
Alternatively you can extract bibliographic information from Google Books or JStore or
similar and past it directly into the BibTEX source tab. Jabref also has a web search fa-
cility which allows one to search (|Search|Web Search|) which allows one to search
various data bases (Inspire, JStore, Spires, JPLP, DBLP, ArXiv.org, Medline,
CiteSeer) for bibliographic information in BibTEX format. You probable need to spe-
cify your searches tightly as, otherwise you will probably get a lot of candidate entries.
You can of course edit these items using the earlier tabs. In particular you may wish to
edit the BibTEX key. Bibliographic information in BiBTEX format is also available from
Google http://books.google.com/.
214 Managing your References
15.1.2 Citations using the natbib package and the BibTEX data base.
The citations and references in this paper were produced by the natbib package.
\usepackage{natbib}
The natbib package extends the citation and bibliography facilities available in
LATEX. A reference sheet for natbib is available on my MiKTeX installation at
C:\MiKTeX-2.9\doc\latex\natbib\natnotes.pdf and a complete manual at
C:\MiKTeX-2.9\doc\latex\natbib\natbib.pdf
2. natbib replaces the basic \cite command in LATEX with \citet for textual and
citep for citations in brackets. Variants of these commands are shown below.
Various extensions to these facilities are set out in the natbib documentation.
3. Having cited various references in the course of the document we now need to
generate the bibliography. The first thing to be done is to specify a style for the
bibliography. This is done using the \bibliographystylestyle command. The
style used here is chicago which produces the type of author date bibliography
used by many journals and working paper series in economics and the social sci-
ences.
15.1 Introduction 215
\bibliographystyle{chicago}
Many journals have their own bibliography style. To use such a style it may be
just a simple matter of replacing natbib in the following command by the specified
journal style.
4. All that remains is to specify the files containing the BibTEX data bases. If you are
starting you may have only one database file. In my case I have a collections of bib-
liography files each of which is restricted to one area of my work. The specification
is done with the bibliography command1
\bibliography{c:/home/bibliographies/statistics,%
c:/home/bibliographies/bubble,%
c:/home/bibliographies/computing,%
c:/home/bibliographies/econometric_books,%
c:/home/bibliographies/finance,%
c:/home/bibliographies/stable,%
c:/home/bibliographies/historical,%
c:/home/bibliographies/stochastics,%
c:/home/bibliographies/economics}
Figure 15.2 shows how easy it is to switch to the style specified by the American Eco-
nomic Review. Simply delete the reference to the natbib in the preamble, and change
the \bibliographystyle{chicago} to \bibliographystyle{aer}. Use |Tools|Clean
Auxiliary Files| to delete current bibliography files. Then run pdfLATEX and BibTEX
as necessary (see subsection15.1.3). You might compare the results here with those in
the bibliography at the end of this document.
1
If there are one or more bibliography files these must be specified in a comma separated list containing
no spaces. Including a comment sign (%) immediately after the last character at the end of a line enables
on to continue input on the next line. (It comments out the end of line marker which would otherwise
be regarded as a white space)
216 Managing your References
LATEX Input
Citations \\
See \cite{Camp97} \\
See \cite{Mccu08}\\
See \cite{Kind00}\\
\bibliographystyle{aer}
\bibliographyl{List of BibTeX data base files as before}
LATEX Output
Citations
See Campbell et al. (1997)
See McCullough and Heiser (2008)
See Kindleberger (2000)
References
Campbell, John Y., Andrew W. Lo, and A. Craig MacKinlay, The Econometrics
of Financial Markets, Princeton University Press, 1997.
Kindleberger, Charles P., Manias, Panics and Crashes A History of Financial Criises,
Palgrave, 2000.
McCullough, B.D. and David A. Heiser, “On the accuracy of statistical procedures
in Microsoft Excel 2007,” Computational Statistics and Data Analysis, 2008, 52, 4570–
4578.
Figure 15.2: Changing Bibliography style to that of the American Economic Review
(AER)
If you are using TEXStudio, the program looks after the generation of citations and the
bibliography. If during the pdflatex run TeXstudio detects that
then TeXstudio will automatically rerun the BibTEX program to regenerate the citations
and bibliography and then re-run pdflatex at least twice to include the updated material
in the document.
If required you may generate the revised citations and bibliography yourself. Some LATEX
interfaces require you to do this. The process may be summarised as follows.
1. Your LATEXfile has been amended or your BibTEX bibliography files have been
amended. Re-run pdflatex . This will write an updated version of the list of
citations and style in use to the .aux file.
2. You then run the BibTEXprogram which reads details from this amended .aux file,
.bib bibliographic files and .bst bibliography style files and produces a .bbl file
which contains the material necessary to produce the bibliography.
3. A pdflatex run then uses this .bbl file to revise the .aux file
4. A final pdflatex run then produces the final version of the paper containing the
citations and bibliography.
This process may sound a little complicated. The process may be summarised as follows.
When you have updated your citations or your bibliography data files
2. Run BibTEX
3. Runpdflatex
If you are reading this document on a computer using a pdf reader you may have noticed
that the citations are hyper-linked to the bibliography. If you right click on a citation
you are transferred to the corresponding entry in the bibliography. At the end of the
item in the bibliography you will see a list of numbers in red boxes. These are reverse
hyper-links back to the citations allowing you to return, directly,to the page you were
reading before you consulted the bibliography.
218 Managing your References
This facility is provided by the hyperlink package which for this document is loaded as
follows.
\usepackage[breaklinks,pagebackref]{hyperref}
The hyperref package needs to extend some of the facilities available in other packages.
To do so, it is necessary to load the hyperref package after these other packages. It is
recommended that the hyperref package be the last package to be loaded.
The hyperlinks package also adds the \url command which allows one to include ex-
ternal hyperlinks in your document. If the hyperlink will not fit on a line the breaklinks
allows it to be split over two lines if it will not fit on one line or on the remainder of the
line where it has been inserted.
The biblatex package and biber program is a reimplementation of the BibTEX system.
While the new system is more flexible. I have found that natbib and BibTEX have been
sufficient for my needs. The biblatex manuals are on my system at
C:\MiKTeX-2.9\doc\latex\\biblatex\biblatex.pdf
If you do wish to use biblatex you will probably find the examples in the examples
subdirectory useful. Biblatex was used for the management of the bibliography in
Van Dongen (2012). There is explained in the book on pages 25–29.
It is possible to avoid using a BibTEX data base and enter the bibliography in the actual
document. To do this we have the thebibliography environment. The thebibliography
2
To enable the required functionality the hyperref package must overwrite parts of some other
packages. If those packages are loaded after the hyperref package the amendments will not be made
15.1 Introduction 219
\begin{thebibliography}{widest-label}
\bibitem[short(year)long]{key}
details
\bibitem ...
details
...
\end{thebibliography}
To illustrate this, in figure 15.3 I duplicate three of the entries in my bibliography using
these methods. The preamble to the LATEX segment in that figure includes
\usepackage{natbib}
The format of the \bibitem requires some explanation. Consider the first item in the
list.
\bibitem[Campbell et~al(1997)]{Camp97}
Campbell, J.~Y., A.~W. Lo, and A.~C. Mac{K}inlay (1997).
\newblock {\em The Econometrics of Financial Markets}.
\newblock Princeton University Press.
For a natbib author-year citation the option within square brackets is obligatory. The
material within these square brackets is used to cite the document. The first entry in the
square brackets is the text of the short citation. This is followed within round brackets by
the year of publication. This can be followed by an optional full citation. The text within
braces is the code used to refer to the document in the cite command. The remainder
220 Managing your References
of the text is the material to be included in the bibliography. The command is defined
in the class or in an added package and effects the formatting of the part of the part
of the bibliography included between the following braces. If you get a undefined try
something like
LATEX Input
Citations \\
See \cite{Camp97} \\
See \cite{Mccu08}\\
See \cite{Kind00}
\bibliographystyle{chicago}
\begin{thebibliography}{99}
\bibitem[Campbell et~al(1997)]{Camp97}
Campbell, J.~Y., A.~W. Lo, and A.~C. Mac{K}inlay (1997).
\newblock {\em The Econometrics of Financial Markets}.
\newblock Princeton University Press.
\bibitem[Kindleberger(2000)]{Kind00}
Kindleberger, C.~P. (2000).
\newblock {\em Manias, Panics and Crashes A History of Financial Criises}.
\newblock Palgrave.
LATEX Output
Citations
See Campbell et al (1997)
See McCullough and Heiser (2008)
See Kindleberger (2000)
References
Campbell, J. Y., A. W. Lo, and A. C. MacKinlay (1997). The Econometrics of Financial
Markets. Princeton University Press.
1
Figure 15.3: Bibliography without BibTEX
CHAPTER 16
16.1 Introduction
If you have done some programming before you may find the approach here somewhat
simple. LATEX is a form of mark-up language. This LATEX (and TEX ) language can also
be regarded as a programming language which can be used to write extend LATEX. This
is the source of the added packages that are available.
In theory, any user could write such extension packages. In practice, most users will not
need to. The simplest use of user defined functions is to replace a repeated sequence of
LATEX instructions and/or text with a simpler shorter user defined function. Most of the
examples given here can be placed anywhere in a document but most are best placed in
the preamble.
Suppose that we have a piece of text “©International Monetary Fund” that one might
want to repeat many times in the course of a document we can use the LATEX command
224 Some Simple User Defined Functions
\newcommand as follows
LATEX Input
\newcommand{\IMF}{\textcopyright International Monetary Fund}
\IMF
LATEX Output
©International Monetary Fund
\newcommand{newcmd }[def ]
where newcmd is the new command to be defined (in this case \IMF) and def is the
text to be substituted wherever \IMF is found in the document. This has several advant-
ages
• It ensures that the section of text is the same where ever it is included in the
document.
• If we discover at a later stage that the text should have been “©World Bank” we
can simply change the definition of \IMF to
\newcommand{\IMF}{\textcopyright World Bank}
and reproduce the document.
If the new command being defined already exists you will get and error. If you do wish
to change the command you should use the \renewcommand command which has syntax
similar to the newcommand command. Suppose that in the first portion of the document
we wished to refer to the International Monetary Fund while in the second World Bank
then we would proceed as in the example below.
16.2 Simple Function with no Arguments 225
LATEX Input
\textbf{\LaTeX\ Output}
Some text
More Text
LATEX Output
©International Monetary Fund
Some text
©World Bank
More Text
LATEX Input
%\newcommand{\rd}{\ensuremath{\mathrm{d}}}
\begin{equation} \label{eq:rd03}
\frac{d^2y}{dx^2}+ux\frac{dy}{dx}+vx=fx
\end{equation}
\begin{equation} \label{eq:rd04}
\frac{\rd^2y}{\rd x^2}+ux\frac{\rd y}{\rd x}+vx=fx
\end{equation}
LATEX Output
d2 y dy
2
` upxq ` vpxq “ f pxq (16.1)
dx dx
d2 y dy
2
` upxq ` vpxq “ f pxq (16.2)
dx dx
\renewcommand{cmd}[args][default]{def}
where
cmd is the new command being defined. The name should begin with a \.
args is the number (1 to 9) of substitutable arguments that are to be used in the defin-
ition of the new command. The arguments are labelled #1, #2,. . . ,#9 and these
symbols are used in the definition of the function.
def This is the material that is to be substituted for every call of the function. The nth
parameter is substituted for #n in the definition.
LATEX Input
\newcommand{\cpr}[2]{\textcopyright #1, #2}
\cpr{Jones}{2012} \\
\cpr{Murphy}{2011}
LATEX Output
©Jones, 2012
©Murphy, 2011
Here a new command \cpr is defined. It has two parameters. and the function definition
is \textcopyright #1, #2. In the first call of the function the first parameter (#1) is
{Jones} and the second {2012}. If more parameters (subject to a maximum of 9) they
are included in extra pair(s) of braces When we substitute for \cpr and the parameters
#1 and #2 in \cpr{Jones}{2012} we get ©Jones, 2012. Similarly for v̇erb+©Murphy,
2011+ produces ©Murphy, 2011.
In the next example we define a similar function which has a default for the first parameter
and show how to over-ride the default.
LATEX Input
\renewcommand{\cpr}[2][Frain]{\textcopyright #1, #2}
\cpr{2012} \\
\cpr{Murphy}{2011}
LATEX Output
©Frain, 2012
©Murphy, 2011
The \newcommand command fails if the command already exists. The \renewcommand
command replaces or amends an existing command. It fails is the command does not
exist. I use the \renewcommand command to change the \cpr command to provide
a default for the first parameter. The new addition [Frain] is the default value for
#1. The parameter #2 is then then 2012 If I wish to change the default I include the
replacement value Murphy.
228 Some Simple User Defined Functions
16.3 Lengths
cm Centimetres
em 1 em is the width of an M in the current font
ex 1 ex is the width of an x in the current font
in Inches
pc Picas (1 pc = 12 pt)
pt Points (1 in = 72.27pt)
mm Millimetres
These lengths are used in many places in LATEX. For example if you wish to insert a
graph with a width of ten centimetres in our document we can write
\includegraphics[width=10cm]{graphfile}
To separate the text from boxes such as these I use the instruction
\vspace{1ex}
Then if I use a larger font the size of the space is increased proportionally. It is generally
better to use “flexible” units such as em or ex when making either horizontal or vertical
spaces. Likewise when I am inserting a graph I use a unit such as \textwidth which is
the width of the text on the page. Thus if I want the width of the graph to be 80% of
the text width I use
\includegraphics[width=0.8\textwidth]{graphfile}
Most graphs in this book have been published in this manner. If a later stage you change
your page size or margin widths the graph keeps the original proportion of the text width
even though the text width has changed.
CHAPTER 17
17.1 Introduction
Errors in LATEX are of two kinds. The first type involves typographic errors, misspelling,
errors in formulae etc. which LATEX blindly ignores and sets as entered. You can use a
spell checker to find many of the spelling errors but the remaining errors of this type can
only be found by careful proof-reading. This problem has to be solved regardless of the
program that you are using to set your document.
The second type of error arises from mistakes in entering your LATEX commands and
environments. On occasion the code may compile but produce unintended output. This
kind of error can only be caught during proof-reading. On other occasions LATEX will
produce no output or only part of the output. On such occasions error messages will be
produced during the LATEX run. These error messages can take one of four formats
• Error messages beginning with ! Error:. These are errors that the underlying
TEX program detects
• Error messages beginning with ! LaTeX Error:. These are errors that the LATEX
system detects
230 Errors and Warnings
17.2 Errors
Below I give a commentary on few examples of errors that occur. Appendix C of Kopka
and Daly (2004) and Chapter 12 of Kottwitz (2011) contain an extended introduction to
resolving problems in LATEX. Appendix B of Mittelbach and Goossens (2004) contains
a more comprehensive but advanced treatment. A colleague with LATEX experience is a
very valuable resource if you run into problems.
TeXstudio is a good environment for resolving issues in LATEX. When you run LATEX the
bottom of the screen displays a tabbed window1 . At this stage the three tabs Messages,
Log File and Errors are of interest. To Illustrate some sample errors, I have inserted in
the file an incorrect command e. g. \LateX instead of the correct \LaTeX. After running
LATEX the contents of the Messages Tab is displayed in figure 17.1. This shows that the
process ended with error. The Errors tab is reproduced in figure 17.2. In this case only
one error is displayed. If there are multiple errors they are listed in this tab. By clicking
on a line in this tab the cursor is moved to the error in the edit window. Clicking on an
item in the error window and opening the log tab displays the log file at the point that
the error was discovered. This is displayed in figure 17.3 This gives some extra details of
the problem. In the traditional approach to error checking, when LATEX found an error it
stopped processing the document and asked the author for input that might correct the
error. The instruction type I and the correct spelling ... is intended for working
in this manner. The default in TeXstudio, when it finds an error is to attempt a form of
1
If this window is not displayed then |View|Messages/Log File| will restore it
17.2 Errors 231
correction and continue to the end of the file if possible or at least beyond the first error.
Thus if you are working with TeXstudio you should ignore such instructions. When
LATEX has finished processing your document you should then try to correct the errors
in the editor.
The Next LaTeX Error and Previous LaTeX Error commands allow to get to the errors
detected during compilation. In the edit pane lines with errors, warnings, bad boxes will
be highlighted with red, yellow or blue background and you can jump between them using
Ctrl+Up/Down. (Ctrl+Shift for errors only, Ctrl+Alt for warnings only, Alt+Shift for
bad boxes only). A tool tip will show more details of the mistake if you jump to a line
232 Errors and Warnings
(it is also shown if you move the mouse over the mark left from the line numbers).
Character
included Error Message
in error
# ! You can’t use ‘macro parameter character #’ in vertical mode.
l.9
#
$ ! Missing $ inserted.
<inserted text>
$
& ! Misplaced alignment tab character &.
l.18 &
In most of these cases the information in the message makes it easy to find and
correct the problem. In some cases LATEXmay run but will not produce the required
17.2 Errors 233
2. Another possible problem is to open an environment and not close it. A sample
log file, resulting from such and error, is illustrated in figure 17.4. TeXstudio has
no way of determining where the environment should end. In this case it points
to the end of the document. The first line of the log message does point to where
the unclosed environment was started. This information can be used to fix the
problem.
3. I have illustrated, in figures 17.1 to 16.1, what happens if you misspell a LATEX
command. This again should be easy to identify and fix.
Many word processing programs have an automatic save after a specified interval. If you
are using TeXstudio you should consider processing the file frequently. This has several
advantages.
• If you encounter an error it is almost certainly in the material that you have typed
since the previous time that you processed and saved the file.
• It gives you the opportunity to preview the most recent material that you have
typeset.
In typesetting complicated mathematics you should consider setting it in parts and com-
piling after each part.
Sometimes the first error in your document will cause a lot of “spurious” errors later in
the document. It may be worthwhile re-compiling you document after fixing the first
error to see if that clears up some or all of the later errors.
Some times you may be able to work out that the error comes from a particular part of
the document but can not work out what is wrong. In such circumstances I comment
out the entire area and re-compile the document. Hopefully this re-compile completes
without error. Then uncomment the commented area bit by bit until the actual source
of the error is revealed.
17.3 Warnings
Warnings are not as serious as errors. A warning message generally means that the output
has compiled but LATEX thinks that it does not look as well as it should. Probably a line
of text or a graph has overflowed into the margins or a page is short or long. In an ideal
world one might fix all warnings. For a beginner if the problem is minor leave it go for the
time being. I will discuss below some of the ways of solving such problems id they have
a significant effect on our document. Often it is better to fix warnings during the final
proof reading as amendments made elsewhere may cause the problem to go away
A warning such as
overfull \hbox (48.90923pt too wide) in paragraph at lines 716--717
simply indicates that the LATEX code at lines 716-717 has caused the text to over flow
the margins by about 2/3 of an inch (72.27 points = 1 inch – see section 16.3). The
cause of this problem was the use of in-line verbatim text. In-line verbatim text can not
be broken across a line so LATEXmust decide to include it on the current line which will
then be to long or to move it to the next line leaving excess space on the current line. It
is leaving the solution up to us. We can then either
1. Add a \\ before the verbatim text to force the verbatim text to the next line leaving
some space at the end of the current line.
2. Perhaps redraft the sentence in such a way to prevent the text overflowing
3. Perhaps break the verbatim statement into two in such a way that the first part
fits onto the line without overflowing
17.3 Warnings 235
If the error message arises from a figure that is to wide then include a width parameter
in the \includegraphics statement. There is a similar underfull \vbox message when
the line is short and space is very stretched to ensure justification. You will also find
overfull \vbox and underfull \vbox messages when a page is to long or to short
respectively. You should not fix any of these line or page breaking problems
until you have the absolutely final version of your document.
LATEX will also give warnings about missing or wrong citations, labels, references, mul-
tiple defined labels etc. The cause of the warning is usually fairly obvious and easily
fixed.
CHAPTER 18
Further Reading
18.1 Introduction
In this chapter I give some brief comments on the LATEX literature. I shall deal first
with the commercial literature and then survey some of the non-commercial literature.
Most of this literature should not be read from cover to cover like a novel. Read the
introduction, contents and extract what you need as you need it. Do not be afraid to
experiment.
The next three books can be regarded as a set describing available LATEX add-on packages.
They are thus a complement to Lamport (1994).
Goossens and Rahtz (1999), The LaTeX Web companion: integrating TEX,
HTML, and XML. Addison Wesley, Longman.
This book deals with the relationship between LATEXand the web
A series of 5 books on LATEX by Herbert Voß1 , translated from German originals have
recently been published.
Voss (Voß) (2010b), Typesetting Tables with Latex. UIT Cambridge Ltd.
A comprehensive account of setting tables in LATEX. There is a full review of this book
at http://www.tug.org/TUGboat/tb32-1/tb100reviews.pdf
Voss (Voß) (2011), PSTricks: Graphics and PostScript for TEXand LATEX.
UIT Cambridge Ltd.
This is a book of more than 900 pages which is of relevance to those using the PSTricks
package to produce very high quality Postscript graphics.
Voss (Voß) (2012b), Presentations with LATEX: Which Package, which Com-
mand, which Syntax? Lehmanns Media GmbH.
This contains a good account of the beamer package
There is a lot of good free material on LATEX available on the web. Much of this is also
available in a standard MiKTeX or TeX Live installation. The following four items are
recommended.
This is a reference manual for base LATEX. It can be accessed in pdf or html format
from the TeXstudio help menu. It is also available for download in various formats from
http://home.gna.org/latexrefman.
Oetiker et al. (2010), The Not So Short Introduction to LATEX 2ε , Oetiker and
Contributors.
This is a highly recommended introduction to LATEX. It is available on my MiKTeX
installation at C:\MiKTeX-2.9\doc\guides\lshort-english The latest version of this
document is available from CTAN (http://tug.ctan.org/tex-archive/info/lshort/).
Package manuals are generally included in a standard MiKTeX or TeX Live installation.
On my MiKTeX installation package documentation is in C:\MiKTeX-2.9\doc\latex. If
you can not find the documentation for a package there try the site http://www.ctan.
org/pkg/ which contains an alphabetical list of links to packages.
a package command in the editor window and selecting “open package documentation
(package name)” from the dropdown menu. The relevant package documentation is then
displayed in the pdf viewer.
Bibliography
Adkins, L. C. (2013). Using gretl for Principles of Econometrics, (4th ed.). Oklahoma
State University. 153
American Mathematical Society (2002). User’s Guide for the amsmath Package (Ver-
sion 2.0). American Mathematical Society. 1999-12-13 (revised 2002-02-25). 91
Berry, K., S. Gilmore, and T. Martinsen (2012). LATEX: Structured documents for TEX
– unofficial LATEX reference manual. Available for download from http://home.gna.
org/latexrefman/. 30
Gandrud, C. (2014). Reproducible Research with R and RStudio. CRC Press. 155
244 BIBLIOGRAPHY
Goossens, M., F. Mittelbach, S. Rahtz, D. Roegel, and H. Voss (2008). The LaTeX
Graphics Companion. Addison-Wesley series on tools and techniques for computer
typesetting. Addison-Wesley. 120, 121, 197, 238
Goossens, M. and S. Rahtz (1999). The LaTex Web companion: integrating TeX, HTML,
and XML. Addison-Wesley series on tools and techniques for computer typesetting.
Addison Wesley Longman. 239
Hayashi, F. (2000). Econometrics. Princeton University Press. 73, 88, 94, 96, 210, 212
Heiberger, R. M. and B. Holland (2004). Statistical Analysis And Data Display: An In-
termediate Course With Examples In S-Plus, R, And SAS. Springer Texts in Statistics.
Springer. 102
Kopka, H. and P. Daly (2004). Guide to LATEX. Addison-Wesley series on tools and
techniques for computer typesetting. Addison-Wesley. 230, 238
Lamport, L. (1994). LATEX: a document preparation system : user’s guide and reference
manual. Addison-Wesley Pub. Co. 5, 238
Oetiker, T., H. Partl, I. Hyna, and E. Schlegl (2010). The Not So Short Introduction to
LATEX 2ε . OETIKER+PARTNER AG. 240
Pakin, S. (2009). The Comprehensive LATEX Symbol List. CTAN. 60, 74, 75, 82
Pfaff, B. (2008). Analysis of Integrated and Cointegrated Time Series with R (Second
ed.). Springer. 155
Tantau, T., J. Wright, and V. Mileti1́c (2012, September). The BEAMER class User
Guide for version 3.22. 197
Van Dongen, M. (2012). LaTeX and Friends. X. media. publishing Series. Springer. 121,
197, 218, 237
Voss (Voß), H. (2010a). Typesetting Mathematics with LaTeX. UIT Cambridge Ltd. 74,
239
Voss (Voß), H. (2010b). Typesetting Tables with Latex. UIT Cambridge Ltd. 102, 239
Voss (Voß), H. (2011). PSTricks: Graphics and PostScript for TeX and LaTeX. UIT
Cambridge Ltd. 121, 239
Voss (Voß), H. (2012a). Latex Quick Reference. UIT Cambridge Ltd. 239
Voss (Voß), H. (2012b). Presentations with LaTeX: Which Package, which Command,
which Syntax? Lehmanns Media GmbH. 44, 197, 203, 239
Xie, Y. (2014). Dynamic Documents with R and knitr. CRC Press. 155