TEP0214

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

Applied LATEX for Economists,

Social Scientists and Others

John C Frain

TEP Working Paper No. 0214

July 2014

Trinity Economics Papers


Department of Economics
Trinity College Dublin
Applied LATEX
for Economists,
Social Scientists
and Others

John C Frain
Economics Department
Trinity College Dublin 1

16th June 2014

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

3 Installing and using TeXstudio 29

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

4 Basic LATEX Syntax 39


4.1 Some Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.2 LATEX commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.2.1 Format of a LATEX command . . . . . . . . . . . . . . . . . . . . . 42
4.2.2 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.3 The Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.3.1 \documentclass Command . . . . . . . . . . . . . . . . . . . . . . 43
4.3.2 \usepackage statement . . . . . . . . . . . . . . . . . . . . . . . . 45
4.3.3 Title and Author Details . . . . . . . . . . . . . . . . . . . . . . . . 46
4.3.4 Changing Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.4 Document Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.4.1 \begin{document} and \end{document} commands . . . . . . . . 47
4.4.2 Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.4.3 Spaces Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.4.4 Document Structure . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.4.5 LATEX Help system in TeXstudio . . . . . . . . . . . . . . . . . . . 55
4.4.6 Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.5 Text Enhancements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.5.1 Font sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.5.2 Bold, italic, underlined etc. fonts . . . . . . . . . . . . . . . . . . . 59
4.5.3 Additional Text Symbols . . . . . . . . . . . . . . . . . . . . . . . . 60
4.5.4 e Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4.5.5 Dashes and Dots . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4.5.6 Line and Page Breaking . . . . . . . . . . . . . . . . . . . . . . . . 61
4.5.7 Quotation Marks and Quoted Text . . . . . . . . . . . . . . . . . . 62

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

8 Other Useful Packages 123


8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
8.2 Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
8.2.1 babel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
8.2.2 inputenc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
8.2.3 fontenc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
8.2.4 textcomp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
8.2.5 mathabx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
8.2.6 pifont . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
8.2.7 eurosym . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
8.2.8 upquote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
8.3 Graphics Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
8.3.1 graphicx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
8.3.2 wrapfig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
8.4 Page Layout and Format Packages . . . . . . . . . . . . . . . . . . . . . . 126
8.4.1 setspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
8.4.2 geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
8.5 American Mathematical Society - AMS - Packages . . . . . . . . . . . . . 127
8.6 Table Formatting Packages . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.6.1 longtable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.6.2 threeparttable . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.6.3 dcolumn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.6.4 array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

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

9 Using Output from External Programs with LATEX 147


9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
9.2 Spreadsheets and LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
9.2.1 Spreadsheet Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
9.2.2 Spreadsheet Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . 150
9.3 Word Processors and LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . 151
9.4 Some Statistical/Econometric Packages and LATEX . . . . . . . . . . . . . 152
9.4.1 Eviews and LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
9.4.2 Gretl and LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
9.4.3 MATLAB and Octave . . . . . . . . . . . . . . . . . . . . . . . . . 154
9.4.4 R and LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
9.4.5 Rats and LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
9.4.6 Stata and LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
9.5 Other Software and LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
9.5.1 GIMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
9.5.2 gnuplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
9.5.3 GVEdit and Graphviz . . . . . . . . . . . . . . . . . . . . . . . . . 158

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

11 Writing a paper with LATEX 167

12 Writing your Thesis with LATEX 177

13 Setting Exercises and Examination Papers with LATEX 191

14 Using Beamer for Presentations 195


14.1 Introduction to Beamer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
14.2 Installing beamer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
14.3 The Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
14.4 Handouts etc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204

15 Managing your References 209


15.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
15.1.1 Compiling your BibTEX data base using Jabref . . . . . . . . . . . 210
15.1.2 Citations using the natbib package and the BibTEX data base. . . . 214
15.1.3 Running BibTEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
15.1.4 Hyper-references in your bibliography . . . . . . . . . . . . . . . . 217
15.1.5 The biblatex package. . . . . . . . . . . . . . . . . . . . . . . . . 218
15.1.6 Bibliographies without a BibTEX data base. . . . . . . . . . . . . . . 218

16 Some Simple User Defined Functions 223


16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
16.2 Simple Function with no Arguments . . . . . . . . . . . . . . . . . . . . . 223
16.3 Lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228

17 Errors and Warnings 229


17.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

xii
17.2 Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
17.3 Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234

18 Further Reading 237


18.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
18.2 Commercial Publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
18.3 Free Publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

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

relevant material and concentrate on that.

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.

1.2 What is LATEX?

LATEX is a typesetting program. LATEX is not a word-processing program. While LATEX


and word-processing programs such as MS Word, LibreOffice Writer, Abiword etc. can
produce similar outputs the capabilities of LATEX are more extensive than those of the
word-processing programs. Perhaps LATEX is most useful when you need some of these
capabilities but I have found it useful even when I am not using these capabilities.

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.

Word-processing programs appear to transfer many of the functions of the typesetter


to the author. The author is then responsible for both content and final appearance.
Usually the results are not as good as they should be. This is not surprising as the
author will not, in general, have any training in typesetting and graphic design.

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.

• Include mathematical symbols, other symbols, equations and other mathematical


structures.

• That you need a contents list and/or lists of tables and/or figures.

• To include citations and a bibliography and

• To compile and include an index.

The rest is up to LATEX.

In pre-computer days communication between author and typesetter was achieved by


adding handwritten annotations in the form of conventional symbolic printer’s instruc-
tions in the margins and text of a paper manuscript or printed proof. This procedure
was known as mark-up
4 Introduction

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 place tables and figures in appropriate places in the document

• will typeset mathematical material

• 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.

and include, if instructed,

• 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.

A TEX system will contain a variety of files including

• the basic TEX typesetting program,


1.3 A Brief History 5

• the basic LATEX and pdfLATEX typesetting programs. The pdfLATEX program is the
main focus of this book.

• other TEX based typesetting programs

• various helper programs

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

1.3 A Brief History3

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.

1.4 Outline Contents

This book has been prepared with LATEX. It illustrates many of the things that you can
accomplish with LATEX.

The general layout of the book is as follows

• 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 2 contains instructions on the installation and maintenance of LATEX. The


MS Windows beginner should pay particular attention to section 2.2 which deals
with the installation of Protext, an easy to install LATEX distribution for MS Win-
dows. Section 2.6 gives some information on the purpose of the more important
programs included with a LATEX distribution.

• Chapter 3 contains instructions on the installation and use of TeXstudio. TeXstudio


is a user interface to the LATEX system. It allows one to prepare, specify and manage
content using the type of graphical user interface familiar to Windows, Linux or
Mac users.

• 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.

• Chapter 7 deals with figures, graphs etc.

• As already mentioned, LATEX is also a programming language. This facility has


been used to program various extensions to LATEX. These are provided as add-on
packages. Chapter 8 describes a small selection of these packages that I have found
useful.

• Tables, figures, text etc. prepared in other computer packages can be used in LATEX.
Chapter 9 shows

– how to transfer material to or from various word-processing programs and


spreadsheets to LATEX,

– how to prepare material in various econometric/statistical packages for use as


LATEX tables and figures.

– how to use various graphical programs to prepare material for LATEX.

• For completeness chapter 10 provides a brief introduction to alternative LATEX


interfaces and “editors”. I am recommending TeXstudio (see chapter 3) but there
may be institutional constraints which force a user to use an alternative “editor”.

• Chapters 11 to 14 cover four typical LATEX applications.

– preparation of a paper (chapter 11).

– preparation of a thesis (chapter 12).

– preparation of an examination papers/exercises and solutions (chapter 13).

– using beamer to prepare slides for presentations (chapter 14).

• Chapter 15 shows how to use the “helper” programs, bibtex and jabref, to prepare
and manage your bibliographies.

• Chapter 16 introduces some of the programming features of LATEX.

• Chapter 17 outlines some of the errors that may occur and how to solve such
problems.
8 Introduction

• Chapter 18 contains a brief review of the LATEX literature.

1.5 A Road Map for New Users

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.

The beginner might proceed as follows.

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}

In the following command

\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

Start ñ All Programs ñ MiKTeX 2.9

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

1.7 A Simple Example

% Anything after a % on a line is a comment


% Preamble
\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 of document
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
This is a basic \LaTeX \ document, More text.
\section{Development}
\subsection{Early Developments}
Text, text, text.
\subsection{Later Developments}
Text, text, text
\section{Conclusions}
Text, text, text.
\end{document}

Figure 1.1: Simple LATEX program

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

• Mark-up is achieved by LATEX commands. All LATEX commands start with a \.

• The script is divided into two parts.

a preamble which in this case consists of the three statements

\documentclass[]{article}
\title{A first \LaTeX \ document}
\author{A. N. Other \\ Number 1 University
\thanks{Thanks to those who aided me with this document}}

All LATEX documents must start with a \documentclass[]{} command. I


shall discuss this command in greater detail in subsection 4.3.1. The \title{}
command simply contains the title of the article. The \author{} command
sets out the name and address of the author. If this is to be spread out over
several lines each individual line should be terminated by \\. The \thanks{}
command is part of the \author{} command and puts a footnote to the
authors name on the title page of the article. Have a look at figure 1.2 to see
what is produced by these commands.

the main text then follows between \begin{document} and \end{document}


commands. All you need to do is enter the text of your article divided into
sections, subsections etc. as required. You should not be concerned about
formatting the data. LATEX will look after this for you and it will do a very
good job. In effect if your paper consists of text only you could just insert sec-
tion/subsection headings and the unformatted text of the sections/subsections
and LATEX will produce a good looking paper.
12 Introduction

A first LATEX document


A. N. Other

Number 1 University
March 17, 2012

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.

2.2 Later Developments


Text, text, text

3 Conclusions
Text, text, text.

∗ Thanks to those who aided me with this document

Figure 1.2: Output of LATEX code in table


CHAPTER 2

Installing LATEX

2.1 Introduction

The emphasis in this chapter is on installing a LATEX system in MS Windows. This is


the operating system that most economists, social scientists and practitioners in similar
disciplines use. Perhaps a few use Mac OS. Most Linux users, that I know, are in
disciplines such as computing, science, engineering, mathematics or similar. Most of
these already have a good knowledge of computing and are well capable of installing a
LATEX system. In Section 2.5 I have included some basic information on installing LATEX
in operating systems other than MS Windows.

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

from http://www.miktex.org/portable/about. This version of LATEX may be installed


on and run from a USB stick. (Windows 7 may ask if the program installed properly.
You may confirm that it has.)

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.

2.2 Installing LATEX

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.

Figure 2.1: ProTeXt Start-up Window

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

of c:\Program Files\ as instillation directory on my PCs.

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.

2.3 MiKTeX Maintenance

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 ñ Settings

MiKTeX 2.9 ñ Maintenance ñ Update

MiKTeX 2.9 ñ Maintenance (Admin) ñ Package Manager (Admin) This opens


a window similar to that in figure 2.2. Package Manager is described in Chapter 5
of the MiKTeX manual. It is a relatively easy way to install extra packages. Simply
select the packages and press the ` button.

MiKTeX 2.9 ñ Maintenance (Admin) ñ Settings (Admin) This opens a win-


dow similar to that in figure 2.3. On the general tab you can set default paper
size and the procedure to be followed if you try to use a missing package. (Perhaps
a colleague has given you a LATEX file that needs a package not installed on your
system). If you are connected to the internet you may ask that MiKTeX will down-
load and install the missing package for you. This is simpler than the procedure in
the previous heading. The other tabs allow one to set some more advanced features
of the system. These are for a more advanced user and are covered in the MiKTeX
manual.

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

MiKTeX 2.9 ñ MiKTeX on the Web ñ MiKTeX Project Page

MiKTeX 2.9 ñ MiKTeX on the Web ñ Support


2.3 MiKTeX Maintenance 19

Figure 2.2: Package Manager

Figure 2.3: MiKTeX Settings


20 Installing LATEX

Figure 2.4: First Step in Update Process

Figure 2.5: Second Step in Update Process


2.3 MiKTeX Maintenance 21

Figure 2.6: Third Step in Update Process


22 Installing LATEX

2.4 Installing TeXLive

Tex-Live may be installed

• 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 Installing LATEX on other Operating systems

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

The MacTeX-2012 distribution is available for download from www.tug.org/mactex.


This page also contains a lot of links to material specific the use of LATEX on Apple
OS. The distribution contains a user interface designed for Mac. A version of TeXstudio
is also available for Mac OS.

2.5.3 Portable Devices

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

2.6 A LATEX system

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.

You will have noticed by now that your LATEX


distribution contains a large number of pro-
file.tex grams. The diagram on the left illustrates two
ways in which these programs can be used to
produce a pdf (.pdf) file from a LATEX (.tex)
latex.exe file. The graphical user interface in TeXstudio,
which is described in chapter 3, can be used to
operate these programs by means of a series of
file.dvi
menus and mouse clicks.

In the diagram the file file.tex contains our


pdflatex.exe dvips.exe
LATEX input. On the left-hand side of the dia-
gram the program pdflatex acts on the .tex
file.ps file and directly produces the .pdf file. This is
the method used by a majority in recent times.
The first box at the end of this section shows
ps2pdf.exe this process operating in a command window
in Windows. This box illustrates the use of the
pdflatex program in compiling a file main.pdf
file.pdf
from a LATEX file Most of the program output
has been suppressed6 .

The process set out on the right is the “tradi-


tional” approach and is more complex. This is illustrated in the second box at the end
6
It is often necessary to run the pdflatex more than once. LATEX processes the file in a single pass
through the document. On the first run of the program forward references to tables, figures, equations
etc. can not be resolved as LATEX has not encountered the item. All referenced tables, figures, equations
etc. are also written to an auxiliary file. On a second run of the pdflatex program this auxiliary file is
read in conjunction with the .tex file and the references are resolved. TeXstudio recognises the existence
of unresolved references and will automatically run the pdflatex program more than once if required.
Other GUIs may require the user to rerun the pdflatex when this is required .
2.6 A LATEX system 25

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.

Microsoft Windows [Version 6.1.7601]


Copyright (c) 2009 Microsoft Corporation. All rights reserved.

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

Microsoft Windows [Version 6.1.7601]


Copyright (c) 2009 Microsoft Corporation. All rights reserved.

c:\Users\frainj>cd /Work/PhD/Thesis/Temp/
cd /Work/PhD/Thesis/Temp/

c:\Work\PhD\Thesis\Temp>latex thesis_main_5.tex

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (MiKTeX 2.9)


entering extended mode
(c:\Work\PhD\Thesis\Temp\thesis_main_5.tex
LaTeX2e <2011/06/27>

Lots of output removed

Underfull \hbox (badness 10000) in paragraph at lines 760--760


\T1/hlh/m/n/12 ([]$\T1/hlst/m/n/12 www . riskmetrics . com / pdf / working / RM
2006 _ introduction . pdf$[][]\T1/hlh/m/n/12 ).
) [214] (c:\Work\PhD\Thesis\Temp\thesis_main_5.aux)

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

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (MiKTeX 2.9)


entering extended mode
(c:\Work\PhD\Thesis\Temp\thesis_main_5.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for English, Afrikaans, ancientgreek

lots more output deleted

2006 _ introduction . pdf$[][]\T1/hlh/m/n/12 ).


) [214] (c:\Work\PhD\Thesis\Temp\thesis_main_5.aux) )
(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.
28 Installing LATEX

c:\Work\PhD\Thesis\Temp>dvips -P pdf thesis_main_5


dvips -P pdf thesis_main_5
This is dvips(k) 5.992 Copyright 2012 Radical Eye Software (www.radicaleye.com)
' TeX output 2013.01.29:1404' -> thesis_main_5.ps

Even more output deleted

[209] [210] [211] [212] [213] [214]

c:\Work\PhD\Thesis\Temp>ps2pdf thesis_main_5.ps

c:\Work\PhD\Thesis\Temp>
CHAPTER 3

Installing and using TeXstudio

3.1 TeXstudio

The latest version of TeXstudio may be downloaded from http://texstudio.sourceforge.


net/. TeXstudio is a graphical user interface to the LATEX system that simplifies the
preparation of a LATEX document. It is important to remember that programs such as
TeXstudio and the other programs mentioned in chapter 10 are simply interfaces to a
TEX/LATEX system. A separate TEX/LATEX system must be installed before the program
can be used. The main features of TeXstudio include —

• 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

• Menus and/or buttons provide access to most LATEX commands (mark-up).

• In the editor LATEX commands are colour highlighted to distinguish them from the
text.

• Inserted brackets are automatically closed.


1
Where I mention “Windows program” I do so for convenience only. Similar facilities are available in
Linux and Apple OS software.
30 Installing and using TeXstudio

• 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.

• Access to a spell checker in a variety of languages.

• 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.

• TeXstudio provides help to locate and navigate to errors if these occur.

• 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.

1. File management (New, Open, Save and Close).


2. Edit (Undo, Redo, Copy, Cut, Past)
3. LATEX Tools
(a) Build and View (This item runs the pdflatex, bibtex etc programs as
required and by default opens a view of the document in the internal
TeXstudio pdf viewer. This may be configured as required but the default
is probably sufficient for the beginner.
(b) Compile, By default, runs pdflatex.
(c) Stop Compile. Use if the compile has taken too long.
(d) View, Opens the internal pdf viewer at the point corresponding to the
position of the cursor in the LATEX source.
4. Access to some LATEXcommands (Math)
5. Access to some table editing features of TeXstudio (Format)
6. File comparison features (Diff )
7. There is also a set of icons to aid negotiating a document in the internal pdf
document (Viewer).
8. The Central tool-bar should appear between the edit and structure windows.
If it does not right-click on any of the tool-bars. A drop-down list of tool-bars
should appear. To make the central tool-bar appear put a tick in the box
opposite Central in the drop-down box. If you wish you can remove any of
the tool-bars by removing the tick opposite the tool-bar in the drop-down box.
9. There is also a Custom tool-box that you can populate with any LATEX com-
mands that you wish. By default it is empty by default.
32 Installing and using TeXstudio

The default functionality of these tool-bars is satisfactory for a beginner. It is


useful to know that, if needed, they can be re-configured using the menu item
Options ñ Configure Texstudio. Select toolbars in the left-hand column. In
the drop-down box on the top of the second column select the tool-bar that you
wish to edit. In the second column select an item that you wish to remove and press
the arrow to move it from the tool-bar. In the third column select a command and
press the arrow to move it to the tool-bar. For example I have used a typewriter
font in many places and I found it convenient to have a \texttt command in the
central menu. The order of a command in a tool-bar may be changed by dragging
it with the mouse to the required place in the list in the second column.

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

Download the Windows installation program from http://texstudio.sourceforge.


net/, save on your computer and double click on the saved program and follow the
instructions. Unless you have some particular requirements’ you can accept the installa-
tion defaults.
3.3 Configuring and Using TeXstudio 33

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

Installation packages and instructions are available at http://texstudio.sourceforge.


net/.

3.3 Configuring and Using TeXstudio

The opening window in TeXstudio is shown in figure 3.1.

Figure 3.1: TeXstudio Start up Window


34 Installing and using TeXstudio

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.

There are two main windows

• 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.

By default a UK English dictionary was installed on my PC. German, Spanish, French,


Hungarian, Italian, and Dutch dictionaries were also installed. The default dictionary can
be changed using the general options. TeXstudio uses standard open office dictionaries
which can be downloaded from the link provided on the general tab. Figure 3.2 shows
the default configuration as derived from the commands options. If you update your
3.4 Synchronizing LATEX input file and pdf output 35

Figure 3.2: Configuring TeXstudio

MiKTeX system or some other relevant program you may need to change some of the
program references.

Configuring line numbers

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.

3.4 Synchronizing LATEX input file and pdf output

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

has been left at the amendment)


2. One can go from a point in the LATEX file to the corresponding place in the LATEX
file.
3. Similarly one can go from a point in the pdf to the corresponding place in the
LATEX file.

This process is known as synchronization.

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.

3.5 Previewing Output as you type

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.

3.6 TeXtablet – Entering Math freehand in LATEX

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

Figure 3.3: TeXstudio Preview

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.

3.7 A simple Example using TeXstudio

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

% Anything after a % on a line is a comment


% Preamble
\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 of document
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
This is a basic \LaTeX \ document, More text.
\section{Development}
\subsection{Early Developments}
Text, text, text.
\subsection{Later Developments}
Text, text, text
\section{Conclusions}
Text, text, text.
\end{document}

Figure 3.4: Simple LATEX program (Copy of that in figure 1.1)


CHAPTER 4

Basic LATEX Syntax

4.1 Some Preliminaries

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 LATEX document is a simple text document. It consists of two parts.

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.

Figure 4.1: Begin LATEX Wizard

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.

1. Possibly expand on the simple example given in section 3.7.

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.).

3. TeXstudio provides a quick start wizard (Wizards ñ Quick Start) which is


illustrated in figure 4.1. The defaults on this wizard are a suitable starting point
for a paper. You may, at a later stage, add extra templates to this wizard. This
could, of course, include a template to satisfy the requirements of your organisation.

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.

4.2 LATEX commands

4.2.1 Format of a LATEX command

A LATEX command consists of

• a \ followed by a string of letters.

• a single special character #, $, &, ˜, _ and ˆ (See section 4.4.2),

• a single \ followed by a single non-letter (e. g. \@).

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

A LATEX command may contain two kinds of parameters (options).

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

Optional Optional parameters are included between square brackets, ([ and ]2 ).

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 .

4.3 The Preamble

4.3.1 \documentclass Command

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.

portrait |landscape Print in portrait or landscape mode. Default is portrait mode.

a4paper |a5paper |b5paper |letterpaper |legalpaper |executivepaper Specify paper


size.
Check default on your system which may be letter paper. I usually include a4paper
this in my options.

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

flqno left aligns all equations

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.

4.3.2 \usepackage statement

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}

amsmath This package provides various enhancements in setting mathematical equa-


tions. I would include this package in all my documents.

amssymb Provides extra mathematical symbols.

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.

4.3.3 Title and Author Details

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{A first \LaTeX \ document}


\author{A. N. Other \\ Number 1 University
\thanks{Thanks to those who aided me with this document}}

In defining the title we make use of three commands

\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

\author {John Murphy \\ University One \\


\and Pat Smith \\ University Two}

The command \thanks{details} puts a footnote containing details on the title


page of the document. A separate \thanks{details} may be entered for each
author.

\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.

4.3.4 Changing Defaults

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 .

4.4 Document Text

4.4.1 \begin{document} and \end{document} commands

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

This content can be in one of two modes

text mode where we enter ordinary text and

math mode where we enter our mathematics.

. I will postpone describing math mode until chapter 5 and will concentrate on text
mode in the remainder of this chapter.

4.4.2 Special Characters

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.

4.4.3 Spaces Characters

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

Table 4.1: Special Characters

• 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.

Table 4.2: Space Generating Commands

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 .

Example 4.1: Space after abbreviation

He bought pen, paper etc. for his report.\\


He bought pen, paper etc.\ for his report.

He bought pen, paper etc. for his report.


He bought pen, paper etc. for his report.

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.

Example 4.2: Space after full stop

The code for Ireland is IE. Then \dots \\


The code for Ireland is IE\@. Then \dots \\

The code for Ireland is IE. Then . . .


The code for Ireland is IE. Then . . .

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

where you wish to return to the traditional approach.

Example 4.3 illustrates three ways in which compound abbreviations can be treated.

Example 4.3: Space between Abbreviations

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

Note the following —

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

Example 4.4: Horizontal and vertical Spaces

{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 \hspace{1in} inserts a 1 inch horizontal gap.

\hfill moves this text to the end of the line.


}

The command
ends a line and text is continued on the next line.

The command inserts a 1 inch horizontal gap.


moves this text to the end of the line.

4.4.4 Document Structure

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 command \frontmatter one places a preface, acknowledgements, contents,


lists of figures, lists of tables etc. as required. We can use the starred versions of the
sectioning commands in the front-matter.

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.

At the start of a section you enter something like

\section[Shorter section title]{Longer section title}

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.

Within each section you may specify subsections.

\subsection[Shorter section title]{Longer section title}

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}

If you want a table of contents simply place the command

\tableofcontents

where you want the contents table to appear.

4.4.5 LATEX Help system in TeXstudio

TeXstudio provides a lot of help to those learning or using LATEX.

• A summary of LATEXcommands is given in the LATEX Reference in the TeXstudio


Help menu. Other LATEX graphical interfaces also have a LATEX help system.

• Various commands are available by clicking on the icons on the button and icon
bars.

• The LaTeX item in the menu provides access to many commands.

• TeXstudio provides auto-completion of many commands. For example the LATEX


command to produce a copyright sign © is \textcopyright. In TeXstudio you get
this by clicking on the appropriate button in the list of miscellaneous text symbols.
But if you type \textc you will be presented with a drop-down window displaying
all LATEX commands that start with\textc and there are many. To restrict the
choice continue typing \textco and the drop-down window will look like that in
figure 4.2. Use the cursor keys or mouse to select \textcopyright and press enter
or double click on it and it will be transferred to your document. The box also
contains an template for the options for the command which also transfer to the
56 Basic LATEX Syntax

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.

Figure 4.2: Auto-Completion in TeXstudio

• 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

All sectioning commands take the same general form, e.g.,

\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:

The table of contents.


The running head at the top of the page.

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}

The secnumdepth counter controls printing of section 0 numbers. The setting

\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

An important concept in LATEX is that of an environment. There are separate environ-


ments for items such as lists, mathematical equations, verbatim text, tables, figures etc.
58 Basic LATEX Syntax

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

4.5 Text Enhancements

4.5.1 Font sizes

The default text size in a LATEX is specified in the \documentclass[]{} statement.


LATEXwill increase the font size for section headings and similar and provide reduced size
fonts for footnotes, subscripts and superscripts. In general it does a good job but you
can change font sizes if you have a need for some special effects. There is a selection
of LATEX commands to change font sizes relative to the default. These commands are
illustrated in figure 4.5.1.

\tiny{} Text \large{} Text


\scriptsize{} Text \Large{} Text
\footnotesize{} Text \LARGE{} Text
\small{} Text \huge{} Text
\normalsize{} Text \Huge{} Text
Table 4.3: LATEX functions to change font sizes

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

4.5.2 Bold, italic, underlined etc. fonts

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.

• \textbf{text} writes text in bold font.


Example –
\textbf{this is a good example of bold text}
produces
this is a good example of bold text

• \textit{text} writes text in italic font.


Example –
\textit{this is a good example of italic text}
produces
this is a good example of italic text

• \underline{text} writes text in underlined.produces


Example–
\underline{this is a good example of underlined text}
produces
this is a good example of underlined text

• \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

• \texttt{text} writes text in a typewriter font (fixed size).


Example –
\texttt{this is a good example of typewriter font}
produces
this is a good example of typewriter font

• \textsuperscript{arg} makes arg a text superscript


Example –
4\textsuperscript{th}
60 Basic LATEX Syntax

code gives code gives code gives


Accents
\'{o} ó \`{o} ò \^{o} ô
\"{o} ö \~{o} õ \={o} ō
\.{o} ȯ \u{o} ŏ \v{o} ǒ
\H{o} ő \t{oo} o \c{o} o̧
\d{o} o. \b{o} o
¯
Some Non-English Symbols
\ss ß \aa å \ae æ
Symbols Used in both Text and Mathematics
\dag † \ddag ‡ \copyright ©
\S S \P ¶

Table 4.4: Some LATEX Text Symbols

produces
4th

These commands can be accessed from TeXstudio in similar ways to the size commands
in section 4.5.2.

4.5.3 Additional Text Symbols

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.

4.5.5 Dashes and Dots

Dashes. Dashes of various sizes are produced with one, two or three “-” charac-
ters.

• The single “-” is the standard hyphen. e. g. last-resort produces last-resort.

• 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.)

4.5.6 Line and Page Breaking

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.

4.5.7 Quotation Marks and Quoted Text

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.

1. `material within quotation marks'


producing
‘material within quotation marks’
2. ``material within quotation marks''
producing
“material within quotation marks”
3. 'material within quotation marks'
producing
’material within quotation marks’
4. "material within quotation marks"
producing
"material within quotation marks"

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.

Example 4.5: Example of quoted text

\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.

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,

\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)

There is also a verse environment to quote poetry.


64 Basic LATEX Syntax

4.5.8 Verbatim Text

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.

Example 4.6: Example of verbatim environment

\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}

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

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

Sometimes it may be necessary to produce some “verbatim material within a paragraph


of normal LATEX input. This is achieved by the \verb+text+ command which produces
the material between the two + signs in an in-line “verbatim format. The + character
which marks the start and end of the “verbatim” text may be replaced by any other
character. The choice of character is dependent on the content of the “verbatim” text.
This is illustrated in example 4.7. The first line uses a + character to delineate the
verbatim text. The Verbatim text in the second line contains a + and an other character
| is used for this purpose.

Example 4.7: Example of \verb command

\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

• Include verbatim sections in footnotes.

• Include comments in verbatim environments.

• Suppress leading characters in a environment.

• Customise various aspects of the formatting of an verbatim environment.

• Include frames around an verbatim environment.

• Include colours in an verbatim environment.

• etc.

These facilities are described in full in the fancyvrb manual11 .


11
This manual is available in my MiKTeX 2.9 installation at C:\MiKTeX-2.9\doc\latex\fancyvrb\
fancyvrb.pdf. You can also get information on this package at http://www.ctan.org/pkg/fancyvrb.
The site http://www.ctan.org/pkg which is part of Jim Hefferon’s AZ web views of CTAN provides an
66 Basic LATEX Syntax

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.

Example 4.8: bulleted list using itemize environment

\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

Example 4.9: Numbered list using enumerate environment

\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

Example 4.10: Labelled list using description environment

\begin{description}
\item[bulleted] use \texttt{itemize} environment
\item[numbered] use \texttt{enumerate} environment
\item[Labelled] use \texttt{description}
\end{description}

bulleted use itemize environment

numbered use enumerate environment

Labelled use 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.

4.5.11 Fragile/Robust Commands and the \protect command

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.

Consider the LATEX code in the following box.

\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.

So, what is a “fragile command”. It is a command that expands into illegal


TeX code during the save process.

What is a robust command? It is a command that expands into legal TeX


code during the save process.
4.5 Text Enhancements 71

Lamport’s book says in its description of every LaTeX command whether


it is “robust” or “fragile”; it also says that every command with an optional
argument is fragile. The list is not reliable, and neither is the assertion about
optional arguments; the statements may have been true in early versions of
LaTeX2e but are not any longer necessarily so:

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

The “user’s way” of creating a command with an optional argument (us-


ing \newcommand or \newcommand*) now always creates a robust command
(though macros without optional arguments may still be fragile if they do
things that are themselves fragile).

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}

then \jim is fragile too. There is the \newcommand-replacement \DeclareRobustCommand,


which always creates a robust command (whether or not it has optional ar-
guments). The syntax of \DeclareRobustCommand is substantially identical
to that of \newcommand, and if you do the wrapping trick above as:

\DeclareRobustCommand{\jim}{\fred}

then \jim is robust.

Finally the makerobust package defines \MakeRobustCommand to convert a


command to be robust. With the package, the “wrapping” above can simply
be replaced by:

\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

In short, the situation is confusing. No-one believes this is satisfactory; the


LATEX team have removed the need for protection of some things, but the
techniques available in current LaTeX mean that this is an expensive exercise.
It remains a long-term aim of the team to remove all need for \protection.
CHAPTER 5

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.

LATEX has two methods of setting mathematical material

• In-line Mathematics i. e. mathematics embedded within text. For example, we


might write px ` yq2 “ x2 ` 2xy ` y 2 where the equation appears to be part of the
text, or

• Display Mathematics i. e. Equations or other mathematics set on a separate line.


For example,
px ` yq2 “ x2 ` 2xy ` y 2

and the equation is set or displayed on a separate line.


74 Mathematics in LATEX

5.1 In-line Mathematics

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

Note in particular that

• In-line mathematics is started and ended by a $ characters2 .

• 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.

5.2 The equation and equation* Environments

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)

If we equate the probability to $\alpha$


\begin{equation*}
\alpha(B+1)=|\alpha B| + 1.
\end{equation*}
Since the \dots

If we equate the probability to α

α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

and \end{equation} statements for the environment. Add an * to the \begin{equation}


statement. In TeXstudio it will automatically be added to the \end{equation}
statement. On the extreme left hand side of your screen click on the box contain-
ing a λ — Greek letters – and click on α. The remainder of the equation, apart
from the second α can be entered from the keyboard.

2. Type \begin{e. Select \begin{equation*} from the drop-down box. TeXstudio


will the insert the \begin and \end statements. To insert an α type \al and select
\alpha from the drop-down box.

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”.

Example 5.3 is an example of the numbered equation environment.


5.2 The equation and equation* Environments 77

Example 5.3: Equation environment

\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

See Equation 5.1 . . .

Note the following

• 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
ş

by the underscore in _{-\infty}. The upper limit is produced by the ^ in ^x.


If there is more than one character in the upper or lower limits one must enclose
the characters in braces ({ }). With a single character in the limits a brace is not
necessary. Open and close braces define a kind of block on which the command
before the opening brace operates.
şx
• In in-line mode $F(x)=\int_{-\infty}^xf(u)du$ produces F pxq “ ´8 f puqdu.
78 Mathematics in LATEX

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 Components of Mathematical Expressions

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.

Example 5.4: Fractions

\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

5.3.2 Text in Display Math

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.

Example 5.5: Text in Display Math

\begin{equation}
x_{ij} = \alpha_i +\beta_j \text{, for all }i=1,\dots,n
\text{ and } j=1,\dots,n
\end{equation}

xij “ αi ` βj , for all i “ 1, . . . , n and j “ 1, . . . , n (5.3)

Note the use of spaces in the text

5.3.3 Subscripts

A single subscript is produced by the underscore character i. e. $x_i$ produces xi . 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_{ij}$ produces xij .

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 .

Example 5.6: Sub/superscripts

\begin{equation}
x_{ij}^2 = \alpha_i^2 +2 \alpha_i \beta_j +\beta^2_j
\end{equation}

x2ij “ αi2 ` 2αi βj ` βj2 (5.4)

5.3.5 Roots

The function \sqrt{arg} produces a square root. Thus \sqrt{x^2+y^2}* produces


a a
x2 ` y 2 . To produce the nth rood use \sqrt[n]{x^2+y^2} which gives n x2 ` y 2 .

5.3.6 Integrals

Integrals are set in LATEX using the syntax $\int_{min}^{max}f(x)\rd x$ command


şmax
which produces min f pxqdx. Its use in display math is illustrated in the box below4

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

Example 5.7: Integrals

% with the limits above and below the integral sign


\begin{equation} \label{eq:rd02}
Prob(a \le x \le b) = \frac{1}{\sqrt{2 \pi} \sigma}
\int\limits_{a}^{b} e^{\frac{(x-\mu)^2}{2\sigma^2}}\rd x
\end{equation}
or with the limits to the right of the integral sign
\begin{equation}
Prob(a \le x \le b) = \frac{1}{\sqrt{2 \pi} \sigma}
\int_{a}^{b} e^{\frac{(x-\mu)^2}{2\sigma^2}}\rd x
\end{equation}

żb
1 px´µq2
P robpa ď x ď bq “ ? e 2σ 2 dx (5.5)
2πσ
a

or with the limits to the right of the integral sign


żb
1 px´µq2
P robpa ď x ď bq “ ? e 2σ 2 dx (5.6)
2πσ a

5.4 Sums and Products

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

Example 5.8: Sums and products

\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

5.4.1 The overset function

The overset function \overset{superscript}{argument} is a function that I have


found useful to produce some special effects. For example
dist
$\overset{prob}{\longrightarrow}$// produces ÝÑ which may be used to indicate
convergence in distribution. You may find it useful in various circumstances.

5.4.2 Multiplication Sign

A multiplication sign is generated by \times. Thus $a \times b$ produces a ˆ b.

5.4.3 Accents in Mathematics

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

LATEX Input Output LATEX Input Output


\acute{a} á \grave{a} à
\check{a} ǎ \hat{a} â
\tilde{a} ã \bar{a} ā
\vec{a} ~a \breve{a} ă
\dot{a} a9 \ddot{a} a
:
\dddot{a} a
; \ddddot{a} a
<
\mathring{a} å \widetilde{abc} abc
Ă
ÐÝ
\widehat{abc} abc
x \overleftarrow{abc} abc
ÝÑ
\overrightarrow{abc} abc line\overline{abc} abc
hkkikkj
\underline{abc} abc \overbrace{abc} abc
ÐÑ
\underbrace{abc} looabc
moon \overleftrightarrow{abc} abc
\underleftrightarrow{abc} abc
ÐÑ \underleftarrow{abc} abc
ÐÝ
abc
\underrightarrow{abc} abc
ÝÑ \xleftarrow{abc} ÐÝÝ
abc above
\xrightarrow{abc} ÝÝÑ \stackrel{above}{under} under
f' f1 f'' f2

Table 5.1: Accents in Mathematics from TeXstudio Version 2.7 drop-down menu

5.4.4 Brackets and delimiters

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

Example 5.9: Brackets

\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.

5.4.5 Bold fonts in Mathematics

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.

Example 5.10: Brackets

\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

Example 5.11: Matrix

\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

5.4.7 Function Names

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

You can define more functions by including a DeclareMathOperator{command}{symbol}.


An economist might be interested in using a utility function, say \util(), in his equations
. In the box below I show how this might be set up and used in an equation.
5.5 Other Mathematical Environments 87

Example 5.12: Function Names

%\DeclareMathOperator{util}{util} in preamble
\begin{equation}
\util(q_1,q_2)=A q_1^{\alpha} q_2^{1-\alpha}
\end{equation}

utilpq1 , q2 q “ Aq1α q21´α (5.12)

5.5 Other Mathematical Environments

5.5.1 Introduction

In this section I show how

1. Long equations may be split over several lines and

2. Systems of equations may be set.

5.5.2 The split Environment

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.

5.5.3 The multiline and multiline* Environments

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

Example 5.13: split environment

\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 ε

This is illustrated below.

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

Example 5.14: Multiline

\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)

5.5.4 The gather and gather* Environments

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.

5.5.5 The align and align* Environments

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

Example 5.15: Gather environment

\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.

Example 5.16: 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.

Example 5.17: Multiple Align points

\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}

a11 “ b11 a12 “ b12 a13 “ b13


a21 “ b21 a22 “ b22 a23 “ b23
a31 “ b31 a32 “ b32 a33 “ b33 (5.22)

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).

5.5.6 The alignat and alignat* Environments

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

Example 5.18: Further Align

\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

Example 5.19: Alignat

\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*}

a11 “ b11 a12 “ b12 a13 “ b13


a21 “ b21 a22 “ b22 a23 “ b23
a31 “ b31 a32 “ b32 a33 “ b33

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.

Example 5.20: More alignat

\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}

a11 “ b11 , a12 “ b12 , a13 “ b13 ,


a21 “ b21 , a22 “ b22 , a23 “ b23 ,
a31 “ b31 , a32 “ b32 , a33 “ b33 . (5.23)

5.5.7 The flalign and flalign* Environments

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.

5.5.8 The array Environments and Systems of Equations

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

Example 5.21: Brackets

\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}

a11 “ b11 a12 “ b12 a13 “ b13


a21 “ b21 a22 “ b22 a23 “ b23
a31 “ b31 a32 “ b32 a33 “ b33 (5.24)

\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

l for flush left

r for flush right

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

Example 5.22: Array environment

\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

5.5.9 The cases Construction

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.

Example 5.23: Cases

\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}

yt˚ “ x1t β0 ` εt , t “ 1, 2, . . . , n, (5.26)


$
&y ˚ if y ˚ ą c
t t
yt “ (5.27)
%0 if yt˚ ď c .

5.5.10 The \intertext command

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

Example 5.24: intertext Command

\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}

A1 “ N0 pλ; Ωq ´ φpλ; Ωq, (5.28)


A2 “ φpλ; Ωq ´ φpλ; Ωq, (5.29)

and

A3 “ N pλ; Ωq. (5.30)


CHAPTER 6

Tables

6.1 Floating Environments

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.

• table for tables and related material.

• 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).

6.2 The table and table* Environments

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

• preferences can be any combination of ! h, t, b and p where

! : Relax some restrictions — I will return to this below

h : Here - at the position in the text where the table environment appears.

t : Top - at the top of a text page.

b : Bottom - at the bottom of a text page.

p : Page of floats - on a separate float page, which is a page containing no text,


only floats.

The exact meaning of these parameters is often a source of confusion to beginners.


For example specifying [bt] means that LATEX should place the table at the top
or the bottom of a page. The order of the preferences does not matter. Thus [bt]
and [tb] both mean the same. LATEX will place the table at the top or bottom
of the page, whichever it considers best. It will not place it at the position in the
text at which the table environment is entered unless this is at the chosen top or
bottom of a page.
6.2 The table and table* Environments 101

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.

In setting tables a writer should remember the following points.

• 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.

• Horizontal lines of different widths enhance your 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

6.3 The tabular and tabular* Environments

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.

c : for a centred entry. The width of a column with columns parameter c, l or r


is determined by the widest entry in the column.

l : for left aligned

r : for right aligned

p{length } : Gives a column of fixed length determined by the parameter length.


Cells in a column with this specification can be spread over several lines. You
may specify a new line with a \newline command.

{ColSeparator} :

If two columns parameters are separated by a | or by || then a single or double


line is drawn between the two columns.

• The table is entered row by row. Rows are separated by \\.


104 Tables

• Cells within the line are separated by &. Column entries may include other LaTeX
commands.

• You may use the \multicolumn{cols}{pos}{text} to make a table entry that is


spread over several columns. cols is the number of columns included in the entry,
pos is the format of the cell using the c, l or r and | parameters and text is the
content of the multicolumn cell.

• 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.

Example 6.1 illustrates these points.

• 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.

• The instruction cline{1-3} inserts a partial line in columns 2 and 3.


6.4 Footnotes in Tables 105

Example 6.1: Tabular environment

\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

6.4 Footnotes in Tables

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

Note the following points.

• Usually the threeparttable environment is an addition to the table environment.


The LATEX input part of the example has three commented statements. Removing
the comment characters from these lines is an indication of how to use it in this
way.

• Note the use of the tablenotes environment. This is similar to a description


environment. The entry in square brackets is the symbol to be attached to each
106 Tables

tabular footnote.

• The command \tnote{} indicates what is to be footnoted. The same footnote may
be repeated several times.

Example 6.2: Threeparttable environment

\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}

Table 6.1: Sample Table with Foot-


notes

item value t-stat


moneya .54 2.53
inflationb 1.54 .26
constanta 10.21 4.71
a
The first note
b
The second note

6.5 Long Tables

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.

• We then have a series of 4 sections of code which end respectively with

\firsthead : giving the text that appears at the top of the first page of the table.

\endhead : giving the text at the top of all subsequent pages.

\endfoot : giving the text at the bottom of every page except the last.

\endlastfoot : giving the text at the bottom of the last page

• 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.

• The manual for the longtable package is available at C:/MiKTeX-2.9/doc/latex/


tools/longtable.pdf if you are using my recommended MiKTeX directory struc-
ture on Windows.
\begin{longtable}[c]{|l|r|r|r|}
\caption[Sample Longtable] {Monthly Average USD, JPY %
and GBP exchange rates with Euro}\\ \hline
& USD & JPY & GBP \\ \hline
\endfirsthead
\multicolumn{4}{p{7cm}} {Monthly Average USD, JPY %
and GBP exchange rates with Euro, (\emph{continued})}\\ \hline
& USD & JPY & GBP \\ \hline
\endhead
\hline
\multicolumn{4}{r} {\emph{Continued on next page}}\\
\endfoot
\hline
\multicolumn{4}{r} {\emph{End of Table}}\\
108 Tables

\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

August 2008 & 1.4975 & 163.63 & 0.79279 \\


September 2008 & 1.4370 & 153.20 & 0.79924 \\
October 2008 & 1.3322 & 133.53 & 0.78668 \\
November 2008 & 1.2732 & 123.28 & 0.83063 \\
December 2008 & 1.3449 & 122.51 & 0.90448 \\
January 2009 & 1.3239 & 119.73 & 0.91819 \\
February 2009 & 1.2785 & 118.30 & 0.88691 \\
March 2009 & 1.3050 & 127.65 & 0.91966 \\
April 2009 & 1.3190 & 130.25 & 0.89756 \\
May 2009 & 1.3650 & 131.85 & 0.88445 \\
June 2009 & 1.4016 & 135.39 & 0.85670 \\
July 2009 & 1.4088 & 133.09 & 0.86092 \\
August 2009 & 1.4268 & 135.31 & 0.86265 \\
September 2009 & 1.4562 & 133.14 & 0.89135 \\
October 2009 & 1.4816 & 133.91 & 0.91557 \\
November 2009 & 1.4914 & 132.97 & 0.89892 \\
December 2009 & 1.4614 & 131.21 & 0.89972 \\
January 2010 & 1.4272 & 130.34 & 0.88305 \\
February 2010 & 1.3686 & 123.46 & 0.87604 \\
March 2010 & 1.3569 & 123.03 & 0.90160 \\
April 2010 & 1.3406 & 125.33 & 0.87456 \\
May 2010 & 1.2565 & 115.83 & 0.85714 \\
June 2010 & 1.2209 & 110.99 & 0.82771 \\
July 2010 & 1.2770 & 111.73 & 0.83566 \\
August 2010 & 1.2894 & 110.04 & 0.82363 \\
September 2010 & 1.3067 & 110.26 & 0.83987 \\
October 2010 & 1.3898 & 113.67 & 0.87638 \\
November 2010 & 1.3661 & 112.69 & 0.85510 \\
December 2010 & 1.3220 & 110.11 & 0.84813 \\
January 2011 & 1.3360 & 110.38 & 0.84712 \\
February 2011 & 1.3649 & 112.77 & 0.84676 \\
March 2011 & 1.3999 & 114.40 & 0.86653 \\
April 2011 & 1.4442 & 120.42 & 0.88291 \\
May 2011 & 1.4349 & 116.47 & 0.87788 \\
June 2011 & 1.4388 & 115.75 & 0.88745 \\
July 2011 & 1.4264 & 113.26 & 0.88476 \\
August 2011 & 1.4343 & 110.43 & 0.87668 \\
September 2011 & 1.3770 & 105.75 & 0.87172 \\
October 2011 & 1.3706 & 105.06 & 0.87036 \\
November 2011 & 1.3556 & 105.02 & 0.85740 \\
December 2011 & 1.3179 & 102.55 & 0.84405 \\
January 2012 & 1.2905 & 99.33 & 0.83210 \\
February 2012 & 1.3224 & 103.77 & 0.83696 \\
March 2012 & 1.3201 & 108.88 & 0.83448 \\
110 Tables

April 2012 & 1.3162 & 107.00 & 0.82188 \\


May 2012 & 1.2789 & 101.97 & 0.80371 \\
\end{longtable}

The output of this code is given in table 6.23

Table 6.2: Monthly Average USD, JPY and GBP exchange rates with Euro

USD JPY GBP


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
Continued on next page
3
Data for this table were extracted from an excel file downloaded from http://www.centralbank.
ie/polstats/stats/exrates/Pages/default.aspx and processed as described on page 149.
6.5 Long Tables 111

Monthly Average USD, JPY and GBP ex-


change rates with Euro, (continued )
USD JPY GBP
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
August 2008 1.4975 163.63 0.79279
September 2008 1.4370 153.20 0.79924
October 2008 1.3322 133.53 0.78668
November 2008 1.2732 123.28 0.83063
December 2008 1.3449 122.51 0.90448
January 2009 1.3239 119.73 0.91819
February 2009 1.2785 118.30 0.88691
March 2009 1.3050 127.65 0.91966
April 2009 1.3190 130.25 0.89756
May 2009 1.3650 131.85 0.88445
June 2009 1.4016 135.39 0.85670
July 2009 1.4088 133.09 0.86092
August 2009 1.4268 135.31 0.86265
September 2009 1.4562 133.14 0.89135
October 2009 1.4816 133.91 0.91557
Continued on next page
112 Tables

Monthly Average USD, JPY and GBP ex-


change rates with Euro, (continued )
USD JPY GBP
November 2009 1.4914 132.97 0.89892
December 2009 1.4614 131.21 0.89972
January 2010 1.4272 130.34 0.88305
February 2010 1.3686 123.46 0.87604
March 2010 1.3569 123.03 0.90160
April 2010 1.3406 125.33 0.87456
May 2010 1.2565 115.83 0.85714
June 2010 1.2209 110.99 0.82771
July 2010 1.2770 111.73 0.83566
August 2010 1.2894 110.04 0.82363
September 2010 1.3067 110.26 0.83987
October 2010 1.3898 113.67 0.87638
November 2010 1.3661 112.69 0.85510
December 2010 1.3220 110.11 0.84813
January 2011 1.3360 110.38 0.84712
February 2011 1.3649 112.77 0.84676
March 2011 1.3999 114.40 0.86653
April 2011 1.4442 120.42 0.88291
May 2011 1.4349 116.47 0.87788
June 2011 1.4388 115.75 0.88745
July 2011 1.4264 113.26 0.88476
August 2011 1.4343 110.43 0.87668
September 2011 1.3770 105.75 0.87172
October 2011 1.3706 105.06 0.87036
November 2011 1.3556 105.02 0.85740
December 2011 1.3179 102.55 0.84405
January 2012 1.2905 99.33 0.83210
February 2012 1.3224 103.77 0.83696
March 2012 1.3201 108.88 0.83448
April 2012 1.3162 107.00 0.82188
May 2012 1.2789 101.97 0.80371
End of Table
6.6 Landscape Tables 113

6.6 Landscape Tables

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 — — — —

Table 6.3: Example of table in Landscape mode


115
CHAPTER 7

Graphics

7.1 Graphics Formats

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

Vector Graphics A file in vector graphics format consists of a series of instruction to


draw the lines, curves etc. The main advantages of vector graphics is that a file
containing a diagram or graph will scale well scale well i./,e. there will be no loss
of quality when the graph is enlarged or reduced in size.

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.

7.2 The figure and figure* Environments

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.

\begin{figure }[placement preferences ]


actual figure, includegraphics command and options
\caption{Figure Title }
\label{key }
\end{figure }

The placement preferences are the same as those set out in subsectiom6.1 for the table
environment.

7.3 The graphicx package and \includegraphics command

The graphicx package is loaded in the preamble.

\usepackage{graphicx}
7.3 The graphicx package and \includegraphics command 119

It adds the command \usegraphicx[{options }] {filename} which specifies the graph-


ics file to be included and allows several options to be specified for the image.

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.

Portable Network Graphics (png). This is another bit-mapped format. It uses a


form of lossless compression and files can be much larger than jpg files. I have
used it in this paper to reproduce screen dumps.

Encapsulated PostScript (eps) is a postScript document format with additional re-


strictions which is intended to be usable as a graphics file format. The format was
designed to hold a graphics file which might be included in a postscript file.

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.

1. My preferred way to do this conversion is to use the program epstopdf to convert


each eps file to a pdf format. epstopdf calls the ghostscript program to do the
conversion. The program epstopdf is run in a command window

epstopdf gfilename.eps

where gfilename.eps is the name of the .eps graphics file to be converted. By


default this produces a .pdf file (gfilename.pdf ) with the same name and the
120 Graphics

file extension replaced by .pdf. Further details are available at http://www.ctan.


org/tex-archive/support/epstopdf

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

3. Appendix A of Goossens et al. (2008) contains additional material on producing


pdf output.

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.

1. Start the bris program. A narrow strip is displayed.

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.

7.4 Producing Images with LATEX

Alternatively it is possible to produce a wide variety of publication quality graphics


using LATEX and various LATEX packages. However this methodology does involve a lot
7.4 Producing Images with LATEX 121

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

Other Useful Packages

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

textcomp adds various text symbols to LATEX.

\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

This package provides symbol fonts. For a manual see http://../CTAN/tex/macros/


latex/required/psnfss/psnfss2e.pdf.

\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 Graphics Packages

8.3.1 graphicx

The graphicx package is covered in chapter 7.

\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 Page Layout and Format Packages

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 -

\singlespacing The default - single spacing

\onehalfspacing One-and-a-half spacing

\doublespacing Double spacing

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

in the document preamble.

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}

8.5 American Mathematical Society - AMS - Packages

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)

To summarise, in all my documents I include three packages as follows1 .

\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 Table Formatting Packages

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

D{input decimal symbol }{output decimal symbol }{no decimals }

where

• input decimal symbol is the decimal symbol used in input, usually . or ,.


• output decimal symbol is the decimal symbol used in output. In example 8.1 a ¨ is
specified
• no decimals is the maximum number of decimals to be allowed in setting the table.
130 Other Useful Packages

Example 8.1: Example of use of dcolumn

\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}

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

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.

For more details see the manual.


8.6 Table Formatting Packages 131

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 =@...=.

Table 8.1: Column Format Options.

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 .

Example 8.2: Setting MS File Names

The windows \texttt{.exe} file is \texttt{C:\textbackslash Program Files


(x86)\textbackslash gretl\textbackslash gretlw32.exe}

The windows .exe file is C:\Program Files (x86)\gretl\gretlw32.exe

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 Enhanced Listing Package

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.

The asparaenum environment is a variation of the enumerate environment in which the


individual items are set as paragraphs. This is illustrated in example 8.3

Example 8.3: Example of use of inparaenum environment

\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 code \ref{pl1} produces 2

Example 8.4 is an example of the use of the inparaenum environment to produce a


listing within a paragraph. Note the option [a] in the \begin{inparaenum} command.
This produces the (a), (b), (c) . . . in the listing. Alternative tokens A. I, i, and 1to
produce corresponding lists with upper case letters, upper case Roman numerals, lower
case Roman numerals, and Arabic numerals respectively in the listings. This extension
also works with the standard LATEX enumerate environment when the paralist package
is loaded.

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 asparaitem, inparaitem and compactitem environments offer similar extensions to


134 Other Useful Packages

Example 8.4: Example of use of inparaenum environment

In a posting to \texttt{comp.text.tex} in May 1998, someone asked about


the possibility of an enumerated environment that
\begin{inparaenum}[(a)]
\item can be used within paragraphs,
\item takes care of enumeration and
\item has items that can be referenced. \label{pl2}
\end{inparaenum}
Another posting mentioned ...

In a posting to comp.text.tex in May 1998, someone asked about the possibility of


an enumerated environment that (a) can be used within paragraphs, (b) takes care of
enumeration and (c) has items that can be referenced. Another posting mentioned ...

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.

8.8 Chapter Headings

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

Example 8.5: Example of use of compactenum environment

The standard \texttt{enumerate} environment produces


\begin{enumerate}
\item The first item
\item The second item
\item The third item
\end{enumerate}
The \texttt{compactenum} environment produces
\begin{compactenum}
\item The first item
\item The second item
\item The third item
\end{compactenum}

The standard enumerate environment produces

1. The first item

2. The second item

3. The third item

The compactenum environment produces


1. The first item
2. The second item
3. The third item

8.9 Page Styles and the fancyhdr package

8.9.1 Page styles in base LATEX

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 }

where option takes one of the following values

plain - just a plain page number.


empty - produces empty headers and footers - no page numbers.
headings - puts running headings on each page. The document style specifies what goes
in the headings.
myheadings - you specify what is to go in the heading with the \markboth or the
\markright commands.

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

\markright{left head}{right head}

can be used to set the headers in the (in the standard book, report and article)
classes and

\markboth{left head}{right head}

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.

\markboth{\hfill even number\hfill left page}{right page\hfill odd number\hfill}

16 even number left page


right page odd number 17

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

• \thepage the number of the current page


• \leftmark current chapter name printed like "CHAPTER 3. THIS IS THE CHAPTER
TITLE"
• \rightmark current section name printed like "1.6. THIS IS THE SECTION
TITLE"
• \chaptername the word chapter in the current language. If this is English, it will
display "Chapter"
• \thechapter current chapter number
• \thesection current section number
138 Other Useful Packages

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.

LeftHeader CenteredHeader RightHeader

page body

LeftFooter CenteredFooter RightFooter

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}

in the preamble and

\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 text of the document.

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.

2. In the command \fancyheadoffset[LE,RO]{0.3\marginparwidth} L and R refer


to the left and right hand side of a page page respectively. E and O refer to even
and odd pages. The command extends the header by 0.3\marginparwidth on left
side of the even numbered pages and the right side of the odd numbered pages.
This practice is in accordance with good typesetting practice.

3. The default \chaptermark variable contains three parts

• \thechapter which gives the chapter number,


• \chaptername The word Chapter in the English language or its equivalent in
other languages, and
• \chaptermark which contains the title of the chapter.

\renewcommand{\chaptermark}[1]{\markboth{#1}{}} redefines the \chaptermark


so that \leftmark contains the chapter title (or its short version if given)

4. \fancyhead[RE]{\bfseries\leftmark} inserts the chapter title in the Right hand


side of the header on even pages.

5. \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}} amounts to


redefining the \rightmark so that it contains the section number and title

6. \fancyhead[LO]{\bfseries\rightmark} then inserts this on the left of the odd


pages.

7. \fancyhead[LE,RO]{\bfseries\thepage} inserts the page number on the left of


even numbered pages and on the right of odd numbered pages

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 Packages for Typesetting Pages in Landscape

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

The rotating package provides sidewaystable and sidewaysfigure environments which


produce rotated floats. By default the floats are turned so that the bottom of the float
is nearest to the outside of the page. The options counterclockwise and clockwise ro-
tate the figure counter-clockwise and clockwise as expected. If you are using a two sided
option and wish to have the figures rotated in the same direction use the figuresright
or figuresleft option. The package also provides a sideways environment which, when
used within a table or figure environment rotates the contents of the sideways envir-
onment but not the caption (presumed outside the sideways environment). For further
details see the manual

8.11 Verbatim Packages

8.11.1 fancyverb

The fancyvrb environment provides enhancements to the verbatim4 environment. Sev-


eral new verbatim environments are provided of which the Verbatim is described here.
4
The verbatim environment is covered in subsection 4.5.8 on page 64
142 Other Useful Packages

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

source : \app{fancyvrb} manual


\begin{Verbatim}[commentchar=!]
% ordinary comment in code
Verbatim Line
! A comment that will not print
\end{Verbatim}

source : fancyvrb manual

% ordinary comment in code


Verbatim Line

(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

source : \app{fancyvrb} manual


\begin{Verbatim}[formatcom=\color{red}]
first Verbatim line
second Verbatim line
\end{Verbatim}

source : fancyvrb manual

first Verbatim line


second Verbatim line

(e) Change individual line formatting.


(f) Change font family – the fontfamily option allows one to change the font family
8.11 Verbatim Packages 143

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

source : \app{fancyvrb} manual


\begin{Verbatim}[fontfamily=helvetica]
first Verbatim line
second Verbatim line
\end{Verbatim}

source : fancyvrb manual

first Verbatim line


second Verbatim line

(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}

first Verbatim line


second Verbatim line
first Verbatim line
second Verbatim line

(h) Number lines,


(i) Change line spacing
(j) Frame text,
(k) Include text in boxes,
144 Other Useful Packages

(l) Conditionally process text.

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.

8.12 xcolor package

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

Using Output from External Programs with LATEX

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.

I shall look at two questions —

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.

9.2 Spreadsheets and LATEX

Over the years I have used three spreadsheet programs (in alphabetical order, Calc
(LibreOffice or OpenOffice), Excel and Gnumeric).

9.2.1 Spreadsheet Tables

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 .

1. Import the data in columns from the data source.

2. Add a column of \\’s to each row of the data.

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.

The data for table 6.2 was generated in this way.

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

Figure 9.1: Enter Text File Dialogue

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.

9.2.2 Spreadsheet Graphs

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. )

9.3 Word Processors and LATEX

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.

(a) copy from the LATEX generated pdf,

(b) paste to your spreadsheet, (in Excel 2010 use |Home|Paste|Text Import
Wizard|),

(c) possibly refine the table in the spreadsheet and

(d) finally transfer to your word-processor.


152 Using Output from External Programs with LATEX

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.

The web site http://tug.org/utilities/texconv/pctotex.html is devoted to the task


of transferring documents from a word processor to LATEX.

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.

9.4 Some Statistical/Econometric Packages and LATEX

9.4.1 Eviews and LATEX

An EViews to LATEX add-in is available at http://www.eviews.com/Addins/addins.


shtml. This is intended to convert regression output and other tables generated by
EViews to a LATEX format. Such output will require editing to produce acceptable versions
of the tables. At least one does not have to re-key the numbers.

Graphs generated by Eviews can be saved as eps and transformed to pdf using epstopdf.
9.4 Some Statistical/Econometric Packages and LATEX 153

9.4.2 Gretl and LATEX

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

9.4.3 MATLAB and Octave

MATLAB publish function

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

print "filename.pdf" -dpdf

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

An alternative approach ((MATweave)) has been proposed by Neil Lawrence (http://


staffwww.dcs.shef.ac.uk/people/N.Lawrence/matweave.html). He proposes to use
the comment system available in Matlab/octave and LATEX. The idea is that one embeds
Matlab/Octave code in your LATEX document. This LATEX code is used to read data, do
calculations, report results, generate graphs and tables which can be included in the
LATEX document. This approach is very useful if you may need to reproduce the analysis
with a revised data set. It also allows the analysis to be easily replicated.

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.

9.4.4 R and LATEX

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.

Several R packages can be used to format output e. g.

• apsrtable – produces well-formatted LATEX tables of multiple models side-by-side,

• xtable – production of formatted tables,

• texreg – produces regression output in LATEX form) are available for typesetting R
estimation results as LATEX tables.

• Hmisc also contains some useful functions.

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 compilation of a “knitr” document involves three steps


8
knitr is more flexible than the description here would imply. Its design allows any input languages
(e.g. R, Python and awk) and any output markup languages (e.g. LATEX, HTML, Markdown, AsciiDoc, and
reStructuredText)
156 Using Output from External Programs with LATEX

1. Separating the chunks of R code from the LATEX code

2. Compiling the chunks of R code.

3. Producing the final LATEX source for the document.

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.

9.4.5 Rats and LATEX

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.

9.4.6 Stata and LATEX

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

outtable Output a matrix to a LATEX table. See http://econpapers.repec.org/


software/bocbocode/s419501.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 Other Software and 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)

9.5.3 GVEdit and Graphviz

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

Other LATEX Editors (TEXworks, TEXMaker etc. )

10.1 Introduction

This chapter is an annotated list of LATEX editors or IDEs (Integrated Development


Environments). What is an IDE? An IDE is usually associated with a programming
language or group of programming languages. It is intended to ease the composition of
programs by providing an editor to compose the program and providing a way to test,
find errors, correct errors and run the program and view the output. A LATEX IDE is
an environment or set of tools to aid the the production of a LATEX document. It can
contain the following features

• 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.

– A set of keyboard short-cuts for important functions.

– Access to help for LATEX commands.

– Icons giving access to a good selection of the mathematical and other symbols
available in LATEX.
162 Other LATEX Editors (TEXworks, TEXMaker etc. )

– Icons/menu items giving access to various LATEX functions and environments.

– Help with source-code formatting.

– Keyword emphasis or colouring.

– Assistance with parentheses etc.

– Automatic closing of LATEX environments.

– 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.

– Ability to display labels and BiBTEX references.

• The capability to manage a LATEX project spread over several files.

• Easy navigation through a file or between files.

• Access to individual LATEX commands and/or Build combinations of such com-


mands through menus and/or icons.

• The ability

– to view and navigate the finished or partially completed document,

– to move from a point in the LATEX document to the corresponding point in


the finished or partially completed document and

– to move from a point in the finished or partially completed document to the


corresponding point in the LATEX document

A comprehensive list of LATEX editors is given at http://en.wikipedia.org/wiki/


Comparison_of_TeX_editors. I have used all of the editors mentioned below at some
stage or another. At the moment most of my LATEX editing is done in TeXstudio. I also
currently use Texworks and Emacs/AucTeX.

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.

TeXnicCenter is available from http://www.texniccenter.org/

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 is a document processing system which can be downloaded from http://www.lyx.


org/. Lyx uses a LATEX system to process your documents. If you have not already
installed such a system it will be installed during the LyX install. The LyX screen looks
somewhat like a web page. Your document is fit to the LyX window. that you enter
are displayed in a proper mathematical format. Equations, citations, graphs etc. are
displayed on the screen as they will appear in the final document.

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

Writing a paper with LATEX

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}

% 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 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.

% 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

% In early TEX systems accented characters such as ö were produced by


% overprinting the 0 with ¨. The contenc package
% with the T1 option adds the accented character and many other characters to LATEX.

\usepackage[T1]{fontenc}

% textcomp adds various text symbols to LATEX.

\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}

% The upquote package gives appropriate quotation marks in verbatim environments


169

\usepackage{upquote}

% Graphics Packages

% Load the graphicx package. See Section 7.3.

\usepackage{graphicx}

% The package wrapfig allows text to wrap around a figure.

\usepackage{wrapfig}

%\usepackage[format=hang]{caption}

% Page Layout Packages

% 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 -
% \singlespacing single default
% \onehalfspacing one-and-a-half spacing
% \doublespacing double spacing
% I use one-and-a-half spacing for this document.
\usepackage{setspace}
\onehalfspacing

% Allow fancy formatting of headers and footers


%\usepackage{fancyhdr}

% 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 commented option below sets the
% left, right, top, and bottom margins. Many other options are set out
% in the manual
\usepackage{geometry}
%\usepackage[a4paper,left=3.5cm,right=3.5cm,top=5cm,bottom=5cm]{geometry}

% 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 amsmath package which extends maths facilities


% amsmath also loads amsbsy amsopn amstext ansgen
\usepackage{amsmath}
\usepackage{amsthm}

% Produce bold math symbols


\usepackage{bm}

% Additional Math symbols


\usepackage{mathabx}
\usepackage{pifont}

% Simple arithmetic in LATEX commands


\usepackage{calc}

% Table Generation Packages

% Load the longtable package if you have long tables that stretch over more
% one page.
\usepackage{longtable}

% Facilities for footnotes in tables


\usepackage{threeparttable}

% The package `dcolumn' aligns the columns of a table on a decimal point.


% For details see the manual
\usepackage{dcolumn}

% The 'array' package provides extensions to the `tabular environment.


% For more details see the manual.
\usepackage{array} % format table columns see page 244 of LaTeX Companion

% URL Package

% Allow the typing of email addresses, hypertext links, directories/paths, etc.


\usepackage{url}

% Enhanced Listing Package

% The paralist environment extends the listing environments in LATEX.


% It provides for listing within paragraphs, changes in the spacing
% and labelling of lists.
171

\usepackage{paralist}

% Packages for Typesetting Pages in Landscape

% The lscape package provides an environment landscape which allows on to


% switch from a portrait to a 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 environment.
\usepackage{lscape}

% The rotating package provides sidewaystable and sidewaysfigure


% environment which produce rotated floats. By default the floats
% are turned so that the bottom of the float is nearest to the
% outside of the page. The options `counterclockwise' and `clockwise'
% rotate the figure counterclockwise and clockwise as expected. If
% are using a two sided option and wish to have the figures
% rotated the same direction use the `figuresright' or `figuresleft'
% option. The package also provides a `sideways' environment which,
% when used within a `table' or `figure' environment rotates the
% contents of the sideways environment but not the caption [presumed
% outside the `sideways' environment]. For further details see the
% manual
\usepackage{rotating} % produces rotated floats

% 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}

% Colour etc. Packages


172 Writing a paper with LATEX

% The `xcolor' package provides facilities for typesetting in colour.


\usepackage{xcolor}

% 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.
\usepackage{tcolorbox}

% Package for Hyper-references

% The `hyperref' package extends the functionality of all the LATEX


% cross-referencing commands, including the table of contents,
% bibliographies etc., to produce \special commands which a driver
% can turn into hypertext links; it also provides new commands to allow
% the user to write ad hoc hypertext links, including those to external
% documents and URLs.
\usepackage[breaklinks,pagebackref]{hyperref}
% 1. The package should be the last package loaded.
% 2. The `breaklinks' option allows long links to be spread over two lines,
% the part on each line acting as a link.
% 3. The ``pagebackref' adds pages numbers to the bibliography which are
% hyperlinks to the page containing the citations.

% 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

% Add table of contents.


\tableofcontents

\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}

Table 11.1: babel language options

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

babel language options (continued )


Language Option(s)
Danish danish
Dutch dutch
English english, USenglish, american, UKenglish, brit-
ish, canadian, australian, newzealand
Esperanto esperanto
Estonian estonian
Finnish finnish
French french, francais, canadien, acadian
Galician galician
German austrian, german, germanb, ngerman, naustrian
Greek greek, polutonikogreek
Hebrew hebrew
Hungarian magyar, hungarian
Icelandic icelandic
Interlingua interlingua
Irish Gaelic irish
Italian italian
Latin latin
Lower Sorbian lowersorbian
North Sami samin
Norwegian norsk, nynorsk
Polish polish
Portuguese portuges, portuguese, brazilian, brazil
Romanian romanian
Russian russian
Scottish Gaelic scottish
Spanish spanish
Slovakian slovak
Slovenian slovene
Swedish swedish
Serbian serbian
Turkish turkish
Ukrainian ukrainian
Continued on next page
175

babel language options (continued )


Language Option(s)
Upper Sorbian uppersorbian
Welsh welsh
End of Table
CHAPTER 12

Writing your Thesis 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

1.32.5 Typescript and illustrations. The thesis must be printed on good


quality, A4 p297 ˆ 210mmq white paper. The type must be fully formed as
in the output of a laser or ink jet printer. The output of dot matrix printers
is not acceptable. The type must be black and not less than 10 point. Line-
178 Writing your Thesis with LATEX

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.

1.32.10 Acknowledgements. A formal statement of acknowledgements


must be included in the thesis.

1.32.11 References. Systematic and complete reference to sources used and


a classified list of all sources used must be included in the thesis. The titles of
journals preferably should not be abbreviated; if they are, abbreviations must
comply with an internationally recognised system (the format may vary ac-
cording to the precedents and customs of the subject area; graduate students
should consult with their Supervisor as to appropriate presentation).

1.32.12 Abstract. One copy of an abstract, printed on a single sheet of A4


179

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 —

1. In the \documentclass{} one-sided output is suggested for the initial submission


and two-sided for the final submission. A 12 point font is suggested but you may
wish to change this to 11 or 10.
2. You may wish to work in a language other than UK English which is proposed
here.
3. The setspace allows you to adjust line spacing. Check what is required.
4. The geometry package allows you to set page margins. Note you may require
different settings for one-sided and two-sided output.

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 preamble for a thesis

%
% 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}

% Several languages may be specified in the options on the babel statement.


% The last such 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.
%
% 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.

% In early TeX systems accented characters such as ö were produced by


% overprinting the 0 with ¨. The fontenc package
% with the T1 option adds the accented character and many other characters to LATEX.
\usepackage[T1]{fontenc}

% textcomp adds various text symbols to LATEX.


\usepackage{textcomp}

% The eurosym package provides access to various forms of the Euro symbol.
181

% For details see \url{http://www.theiling.de/eurosym.html}


\usepackage[left]{eurosym}

% 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}

% The package wrapfig allows text to wrap around a figure.


\usepackage{wrapfig}

% Page Layout Packages


% 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 -
% \singlespacing default - single spacing
% \onehalfspacing one-and-a-half spacing
% \doublespacing double spacing
% I use one-and-a-half spacing for this document. Thus
\usepackage{setspace}
\onehalfspacing
% To satisfy the regulations above us one of the following
% TCD PhD requirements are one-and-a-half or double spacing
% Use the `\onehalfspacing' or `\doublespacing' command for both
% first and final submission. Uncomment as required.
%\usepackage{setspace}
%\onehalfspacing
%\doublespacing

% 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. For the initial submission the regulations
% specify that the 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. For the one-sided
% submission I specify left and right margins of 3.5 cm. and top and bottom margins
% of 5 cm.
%\usepackage{geometry}
\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 just larger
% than the outer. Thus we might use
\usepackage[a4paper,left=3.5cm,right=3.5cm,top=5cm,bottom=5cm]{geometry}
182 Writing your Thesis with LATEX

% American Mathematical Society - AMS - Packages


% Load amsmath package which extends maths facilities
% amsmath also loads amsbsy amsopn amstext ansgen
\usepackage{amsmath}
\usepackage{amsthm}
% Produce bold math symbols
\usepackage{bm}

% the mathabx provides additional mathematical symbols/characters For lists of symbols


% provided see http://.../CTAN/tex/fonts/mathabx/mathtest.pdf. If you require the
% symbols uncomment the next \usepackage statement
%\usepackage{mathabx}

% This package provides symbol fonts. For a manual see


% http://../CTAN/tex/macros/latex/required/psnfss/psnfss2e.pdf. Uncomment if needed.
%\usepackage{pifont}

% Table Generation Packages

%Load the longtable package if you have long tables that stretch over more
% than one page.
\usepackage{longtable}

% Facilities for footnotes in tables


\usepackage{threeparttable}

% The package `dcolumn' aligns columns of a table on a decimal point.


% For details see the manual
\usepackage{dcolumn}

% The 'array' package provides extensions to the `tabular environment.


% For more details see the manual.
\usepackage{array} % format table columns see page 244 of LaTeX Companion

% 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}

% Bibliography management facilities


183

\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}

% Enhanced Listing Package


% The paralist environment extends the listing environments in LATEX.
% It provides for listing within paragraphs and changes in the spacing and labelling
% of lists.
\usepackage{paralist}

% 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}

% Packages for Typesetting Pages in Landscape


% The lscape package provides an environment landscape which allows on to switch from
% a portrait to a 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
% environment.
\usepackage{lscape}

% The rotating package provides sidewaystable and sidewaysfigure environment


% which produce rotated floats. By default the floats are turned so that the bottom
% of the float is nearest to the outside of the page. The options `counterclockwise'
% and `clockwise rotate the figure counterclockwise and clockwise as expected. If
% you are using a two sided option and wish to have the figures rotated in the same
% direction use the `figuresright' or `figuresleft' option. The package also provides
% a `sideways' environment which, when used within a `table' or `figure' environment
% rotates the contents of the sidways environment but not the caption [presumed
% outside the `sideways' environment]. For further details see the manual
\usepackage{rotating} % produces rotated floats
184 Writing your Thesis with LATEX

% 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}

% Colour etc. Packages


% The `xcolor' package provides facilities for typesetting in colour.
\usepackage{xcolor}

% 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}

% Package for Hyper-references


% The `hyperref' package extends the functionality of all the LATEX cross-referencing
% commands - including the table of contents, bibliographies etc. - to produce
% \special commands which a driver can turn into hypertext links; it also provides
% new commands to allow the user to write ad hoc hypertext links, including those
% to external documents and URLs.
\usepackage[breaklinks,pagebackref]{hyperref}
% 1. The package should be the last package loaded.
% 2. The `breaklinks' option allows long links to be spread over two lines,
% the part on each line acting as a link.
% 3. The ``pagebackref' adds pages numbers to the bibliography which are
% hyperlinks to the page containing the citations.

% PhD Title etc.


% Define the title and author variables. The \\ is a new line instruction.
185

% the \thanks inserts a footnote in the title page.


%
\title{Studies on the Application of the $\alpha$-stable Distribution in Economics }
\author{}
\date{ \normalsize{by} \\
\vspace{0.8cm} \large John C. Frain \\
\vspace{0.8cm} Submitted to the Department of Economics \\
in fulfilment of the requirements for the degree of \\
\vspace{0.8cm}Doctor of Philosophy \\
\vspace{0.8cm} at the \\
\vspace{0.8cm} University of Dublin \\
\vspace{0.8cm} 2009
}
%
% Text of Document follows in next box

Skeleton document part of a thesis

%
% 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

normal conditions of acknowledgement.


\end{enumerate}
\renewcommand\theenumi{\arabic{enumi}}
\vspace{2cm}
John C. Frain
\vspace{1cm}
\newpage

% 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

\item TCD Graduate Seminar, December 2006.


\item IEA Annual Conference April 2007.
\end{itemize}}

\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

\section{Conclusions and Policy Recommendations}


Your conclusions and policy recommendations
\section{Summary}
A summary of this chapter.
\chapter{Title of section 3}

An example of a \texttt{pdf} graph is given in figure~\ref{fig:samplegraph}


\begin{figure}[!ht]
\begin{center}
\caption{Sample Graph}
\label{fig:samplegraph}
\includegraphics{samplegraph}
\end{center}
\end{figure}
\chapter{Title of section 4}
text of section 4
\fancyhead{}
\fancyhead[RO,LE]{Appendix \thesection}
\appendix
\chapter{Some Hard Maths}
\label{app:hardmaths}
\fancyhead[LE,RO]{Appendix \thechapter}
The characteristic function of an $\alpha$-stable distribution can be deduced from the
stability property and is given by
\begin{align}\label{s:eq:st03}
\phi(t) &= E[e^{itx}] \notag \\
&= \int{e^{itx}}dS(x) \notag \\
&=\left\{%
\begin{array}{ll}
\exp(-\gamma^\alpha |t|^\alpha[1-i \beta (\tan\frac{\pi\alpha}{2})\text{ sign }t]\;+i
\delta t),&\text{if }\alpha\neq 1 \ \hbox{;} \\
\exp(-\gamma\, |t|\, [1+i \beta \frac{2}{\pi}(\text{ sign }t)\;\log(|t|)]+i \delta t),
&\text{if }\alpha = 1 \hbox{.} \\\end{array}%
\right.
\end{align}
(see \cite{Zolo86} or \cite{Samo94}). $E$ is the expectation function, $S(x)$ is the
$\alpha$-stable distribution function and $i=\sqrt{-1}$. The $\text{ sign }t$
function is defined as
\begin{equation}\label{s:eq:st04}
\text{ sign }t=\left\{%
\begin{array}{ll}
-1, & t<0; \\
0, & t=0; \\
189

1, & t>0. \\
\end{array}%
\right.
\end{equation}

\chapter{Data Definitions and Sources}


\label{ap:data}

\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

Setting Exercises and Examination Papers with LATEX

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

Using Beamer for Presentations

14.1 Introduction to Beamer

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.

Note the following features –

• 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

Figure 14.1: Sample slide produced by beamer

• 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.

• Tabular environments, graphs, equations and other mathematical expressions may


be included in frames or in blocks.

• Much of this material may be copied from your LATEXdocument.

• If you have external hyper-links in your presentation and have internet access during
your seminar you can access the links during your presentation.

• You can do a lot more with beamer.

– Uncover parts of a frame or list piecewise.

– Highlight the current item in a list.


14.2 Installing beamer 197

– Uncover equations bit-by-bit.

– Uncover a table column-wise.

– Uncover a table row-wise.

– Add notes for yourself.

– Prepare handouts and lecture notes containing reduced copies of the slides.

– Use features of beamer in preparing papers

• 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.

14.2 Installing beamer

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).

14.3 The Presentation

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}

\subsection{The Model} % Note 8


\begin{frame} % Note 4
\frametitle{Bubble Model} % Note 5
\begin{equation} % Note 13
x(t)=f(t)+\alpha \frac{\rd x(t)}{\rd t}
14.3 The Presentation 201

\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}

\subsection{Alternative Display of Model} % Note 14


\begin{frame}
\frametitle{Bubble Model in Blocks}
\begin{block}{System}
\begin{equation}
x(t)=f(t)+\alpha \frac{\rd x(t)}{\rd t}
\end{equation}
\end{block}
\pause
\begin{block}{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{block}
\end{frame}

\end{document}

Notes to LATEX Code in box above

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

3. See sections 5.3.6 and 5.4.7

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.

6. I have three sections in this presentation

• Introduction

• Bubbles

• Analysis

7. The \tableofcontents Produces a list of sections and subsections that serve as


an initial summary of the talk. Choose your section and subsection titles well and
you will get a summary that will grab the attention of your audience.

8. Note the use of the subsection

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

14.4 Handouts etc.

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

• The use of the handout option can be used to produce a handout.

• 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.

• \pgfpagesuselayout{2 on 1} command is provided by the pgfpages command.


The
{2 on 1} option specifies that two original pages are to be transferred onto one.
Instead of {2 on 1} you could use {4 on 1} and add landscape to the options.
The a4paper specifies that the handout is to be on A4 paper.

• The \mode<handout>{\setbeamercolor{background canvas}{bg=black!4}} com-


mand puts a faint grey background on the slides in the handout. Omit this is you
feel that it does not add to your handout.
14.4 Handouts etc. 205

introduction
Bubbles
Analysis

Extraordinary Popular Delusions and the Madness


of Crowds

Charles Mackay
Illustrated London News 1

1st ed. (1841), 2nd ed. (1852)

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

introduction Mississippy Scheme


Bubbles South-Sea Bubble
Analysis Tulipmania

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

introduction Mississippy Scheme


Bubbles South-Sea Bubble
Analysis Tulipmania

South-Sea Bubble

Material for Slide

Charles Mackay Illustrated London News Extraordinary Popular Delusions and the Madness of Crowds
14.4 Handouts etc. 207

introduction Mississippy Scheme


Bubbles South-Sea Bubble
Analysis Tulipmania

Tulipmania

Material for Slide

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

Bubble Model in Blocks

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

Managing your References

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

not recommend that you do this.

I will cover the following in this section

1. Compiling your BibTEX data base using Jabref.

2. Making citations using the data base.

3. Bibliographies using the BibTEX database.

4. The biblatex package.

5. Compiling your Bibliography without using the BibTEX database.

15.1.1 Compiling your BibTEX data base using Jabref

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: Example of Jabref entry

The Jabref program is available from http://jabref.sourceforge.net/. Installation


instructions for Windows and several other operating systems are given in the document-
ation tab on that site (http://jabref.sourceforge.net/documentation.php). Jabref
is a java program and if a java runtime is not already installed on your PC you will have to
download and install one. The Jabref documentation also explains how to do this.
212 Managing your References

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

title = {On the accuracy of statistical procedures in {M}icrosoft {E}xcel 2007},

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 Publisher and year fields do not need any explanation.

The author field needs some more explanation. If there is a single author his name is
entered as

author={first names surname}

or

author={surname, first names}

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.

author={John Y. Campbell and Andrew W. Lo and A. Craig Mac{K}inlay}

is how I have entered the authors of Campbell et al. (1997) in my database.

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.

author={{Guinness and Co.}}

or

author={Guinness {and} Co.}

will retain Guinness and Co. in its original form.

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.

1. In the preamble I load 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.

\citet{Camp97} ñ Campbell et al. (1997)


\citet[chap.~2]{Camp97} ñ Campbell et al. (1997, chap. 2)
\citep{Camp97} ñ (Campbell et al., 1997)
\citep[chap.~2]{Camp97} ñ (Campbell et al., 1997, chap. 2)
\citep[see][]{Camp97} ñ (see Campbell et al., 1997)
\citep[see][chap.~2]{Camp97} ñ (see Campbell et al., 1997, chap. 2)
\citet*{Camp97} ñ Campbell, Lo, and MacKinlay (1997)
\citep*{Camp97} ñ Campbell, Lo, and MacKinlay (1997)

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)

15.1.3 Running BibTEX

If you are using TEXStudio, the program looks after the generation of citations and the
bibliography. If during the pdflatex run TeXstudio detects that

• the citations in the document have been amended, or

• new citations have been added to the document, or


1
• a bibliography data .bib file has been amended
15.1 Introduction 217

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

1. Run pdflatex (twice)

2. Run BibTEX

3. Runpdflatex

4. Run pdflatex again

15.1.4 Hyper-references in your bibliography

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 pagebackref option inserts the reverse links in the bibliography.

This package should be the last package to be loaded2 .

15.1.5 The biblatex package.

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.

15.1.6 Bibliographies without a BibTEX data base.

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

environment is similar to a listing environment such as the itemize environment. Each


entry in the thebibliography environment is started by a \bibitem command rather
than a \item command. To produce the kind of author-year bibliography at the end of
this document continue to load the natbib package The \bibitem entry has the following
format for this bibliography.

\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

\def\newblock{\hskip .11em plus .33em minus .07em}


15.1 Introduction 221

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.

\bibitem[McCullough and Heiser(2008)]{Mccu08}


McCullough, B. and D.~A. Heiser (2008).
\newblock On the accuracy of statistical procedures in {M}icrosoft {E}xcel 2007.
\newblock {\em Computational Statistics and Data Analysis\/}~{\em 52}, 4570--4578.
\end{thebibliography}

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.

Kindleberger, C. P. (2000). Manias, Panics and Crashes A History of Financial Criises.


Palgrave.

McCullough, B. and D. A. Heiser (2008). On the accuracy of statistical procedures in


Microsoft Excel 2007. Computational Statistics and Data Analysis 52, 4570–4578.

1
Figure 15.3: Bibliography without BibTEX
CHAPTER 16

Some Simple User Defined Functions

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.

16.2 Simple Function with no Arguments

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

The general form of the \newcommand command as used here is

\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 reduces the amount of typing required.

• 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}

\newcommand{\IMF}{\textcopyright International Monetary Fund}


\IMF

Some text

\renewcommand*{\IMF}{\textcopyright World Bank}


\IMF

More Text
LATEX Output
©International Monetary Fund
Some text
©World Bank
More Text

As mentioned on page 81 standard practice in typing a derivative is to use an upright


d rather than the slanted d that is produced as standard in math mode in LATEX. I
have done this in this book by defining a new command \rd as in the following example.
The \ensuremath{} part of the definition ensures that the command can be used in
both text mode and math mode. (If use in text mode \ensuremath{} adds $’s to the
front and back of the expression. If used in math mode the $’s are not required and are
not inserted. The command \mathrm{} converts whatever is between the braces to an
upright (Roman) font.
226 Some Simple User Defined Functions

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

In subsubsection 5.4.7 (page 86) we have already described using \DeclareMathOperator


to specify an upright font for function names in math mode.

An alternative version of the \newcommand which allows substitutable parameters is

\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.

default If this optional parameter is present it is a default value for #1.

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.

The following example illustrates these points


16.2 Simple Function with no Arguments 227

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

Lengths in LATEX may be measured in the following units.

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

Errors and Warnings

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

• Error messages beginning with ! LaTeX <package> Error:. where <package> is


the name of the package which detects the error. If a solution is not obvious you
should consult the package documentation.

• Warning messages. 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 if 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.

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

Figure 17.1: Example of messages window after an error

Figure 17.2: Example of Errors Tab after an Error

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

Figure 17.3: Extract from Log File Showing Error

(it is also shown if you move the mouse over the mark left from the line numbers).

Some common errors are listed below

1. If you use one of the special characters, #, $, %, &, ,̃ _, ,̂ {, }, or \ in your text


you will get an error message. Typical of such messages are

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

output. Proof reading should identify the problem in such cases.

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.

• Each time you process the file it is saved.

• 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.

Figure 17.4: Extract from Log File an environment not completed


234 Errors and Warnings

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.

18.2 Commercial Publications

First I list the more elementary books

Van Dongen (2012), LATEXand Friends. Springer


Computer competent. some advanced topics A full review of this book is available on
http://www.tug.org/books/reviews/tb102reviews-ltxfriends.html.

Grätzer (2007), More math into LaTeX. Springer.


238 Further Reading

This book is an excellent account of the typesetting of mathematical material in LATEX


without neglecting other aspects. Part 1 (Short Course) and Appendix B (Math Symbol
tables) taken from this book can be downloaded from http://www.ctan.org/tex-archive/
info/examples/Math_into_LaTeX-4/

Kopka and Daly (2004), Guide to LATEX. Addison-Wesley.


This is a very comprehensive introduction to LATEX. It covers a lot of material. It is
probably a better book for the person who has some basic knowledge of LATEX than for
an absolute beginner. A full review of this book is available at http://www.tug.org/
TUGboat/tb24-2/tb77waud-kopka.pdf

Kottwitz (2011), LATEXBeginner’s Guide. PACKT Publishing.


A modern approach to LATEX which is suitable for the beginner. I think that the e-
book version looks better than the printed version. This book is based on TeX Live
and Texworks. A full review of this book is available at http://www.tug.org/books/
reviews/kottwitz-beginners.html.

The original LATEX manual


Lamport (1994), LATEX: a document preparation system : user’s guide and
reference manual. Addison-Wesley
is still very useful. It covers base LATEX very well but does not cover any of the extensions
available in add-on packages. I have found it useful.

The next three books can be regarded as a set describing available LATEX add-on packages.
They are thus a complement to Lamport (1994).

Mittelbach and Goossens (2004), The LATEXcompanion.


This 1090 page book provides an overview of LATEX packages not covered in the following
two books. If I have a problem and need to research a package to solve my problem
this book would be my first port of call. Given its age it is advisable that one check the
documentation for any package that you are about to use. It is an essential reference
work for intermediate to advanced users.

Goossens et al. (2008), The LaTeX Graphics Companion. Addison-Wesley.


As Mittelbach and Goossens (2004) but covers material related to graphics. This book
also has a good section on the beamer package. It also contains sections on setting music
scores, chess games and diagrams, the use of colour in LATEX and producing material in
PDF format.
18.3 Free Publications 239

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ß) (2010a), Typesetting Mathematics with LATEX. UIT Cambridge


Ltd.
This is an in depth account of typesetting mathematics in LATEX.

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ß) (2012a), LaTeX Quick Reference. UIT Cambridge Ltd.


This is a condensed account of the syntax of base LATEX and a selection of important
packages. It is useful as a quick reference volume.

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

18.3 Free Publications

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.

Berry, K., S. Gilmore, and T. Martinsen (2012). LATEX: Structured documents


for TEX – unofficial LATEXreference manual
1
On those published by UIT the author’s sirname is given as Voss. The volume published by lehmanns
media give Voß as sirname
240 Further Reading

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.

Flynn (2011), Formatting information: An introduction to typesetting with


LATEX. Silmaril Consultants.
This book is available in pdf format or as html from http://latex.silmaril.ie/. as
the title sets out it is more about typesetting than setting mathematics.

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/).

Wiki Colaboration (2013), LATEX Wikibooks.org. This publication gathers ma-


terial from various other free sources. The project is being actively developed and I
would recommend that you download the latest version from http://en.wikibooks.
org/wiki/LaTeX.

Most LATEXpackages are accompanied by good documentation. Some documentation


starts with an overview of the package and then gives the code for the package. This
code is intended for the more expert user and the beginner should concentrate on the
first part. I use Mittelbach and Goossens (2004) to determine what packages are likely to
solve my problem. If the explanations and examples in Mittelbach and Goossens (2004)
are not sufficient, more information is generally available in the manuals.

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.

For example if I select the link to beamer I am directed to http://www.ctan.org/pkg/


beamer. This gives details of the beamer material on CTAN including links to document-
ation, the maintainers of the package and a link to beamer’s CTAN directory. Here you
can find the code for the package and examples of the use of the package. The beamer
manual is worth examining if you are preparing a presentation with LATEX.

In recent versions of TeXstudio Package manuals can be accessed by right clicking on


18.3 Free Publications 241

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

Campbell, J. Y., A. W. Lo, and A. C. MacKinlay (1997). The Econometrics of Financial


Markets. Princeton University Press. 213, 214

Cottrell, A. and R. J. Lucchetti (2014, January). Gretl Users Guide. Department of


Economics, Wake Forest University and Department of Economics, Wake Forest Uni-
versity. 153

Davidson, R. and J. G. MacKinnon (2004). Econometric Theory and Methods. Oxford


University Press. 73, 74, 75

Flynn, P. (2011). Formatting information: An introduction to typesetting with LATEX.


Silmaril Consultants. 240

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

Grätzer, G. (2007). More math into LaTeX. Springer. 237

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

Janert, P. K. (2010). Gnuplot in Action. Manning. 158

Kindleberger, C. P. (2000). Manias, Panics and Crashes A History of Financial Criises.


Palgrave. 63

Kleiber, C. and A. Zeileis (2008). Applied Econometrics with R. Springer. 155

Kopka, H. and P. Daly (2004). Guide to LATEX. Addison-Wesley series on tools and
techniques for computer typesetting. Addison-Wesley. 230, 238

Kottwitz, S. (2011). LaTeX Beginner’s Guide. Packt Publishing. 230, 238

Lamport, L. (1994). LATEX: a document preparation system : user’s guide and reference
manual. Addison-Wesley Pub. Co. 5, 238

Mackay, C. (1852). Memoirs of Extraordinary Delusions and the Madness of Crowds.


Wordsworth Editions Ltd (Jun 1995). 198

McCullough, B. and D. A. Heiser (2008). On the accuracy of statistical procedures in


Microsoft Excel 2007. Computational Statistics and Data Analysis 52, 4570–4578. 149,
212

Mittelbach, F. and M. Goossens (2004). The LaTeX companion. Addison-Wesley series


on tools and techniques for computer typesetting. Addison-Wesley. 67, 123, 138, 230,
238, 240
BIBLIOGRAPHY 245

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

Philips, L. (2012). gnuplot Cookbook. Packt Publishing Ltd. 158

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

Varian, H. R. (1992). Microeconomic Analysis. Norton. 73

Varian, H. R. (2010). Intermediate Microeconomics: A Modern Approach. Norton. 73

Vinod, H. D. (2008). Hands-on Intermediate Econometrics Using R. World Scientific.


155

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

Wiki Colaboration (Ed.) (2013). LATEX. Wikibooks.org. 135, 138, 240

Xie, Y. (2014). Dynamic Documents with R and knitr. CRC Press. 155

You might also like