Elements of the LATEX System for the Development of Large Publications Esben Sloth Andersen Dept. of Business Studies, Aalborg University
[email protected], www.business.aau.dk/evolution/esa/
Version: 2006-09-17, 17:52 This document presents gives a quick overview over the LATEX system from the viewpoint of the production of books and complex papers. Thereby it provides the starting point for the author’s selection of a set of LATEX packages and the development of related commands. This LATEX ‘metapackage’ is described in Andersen (2006b) and Andersen (2006c).
5.2 5.3 5.4 5.5 5.6 5.7
Contents 1
Introduction
2
2
The LATEX system 2.1 The evolution of LATEX . . 2.2 Integrated LATEX systems . 2.2.1 Files used by the LATEX system . . . 2.2.2 The integration problem . . . . . . 2.2.3 Files produced . . 2.3 A concrete LATEX system .
3 3 4 6 4 4 5 6
3
Quotes . . . . . . . . . Lists . . . . . . . . . . Tabulated text . . . . . Notes . . . . . . . . . Cross references . . . . Further aspects of text .
. . . . . .
. . . . . .
13 14 14 15 16 16
Mathematics 6.1 A math example . . . . . . 6.2 Forms of math typesetting 6.3 Automatic typesetting decisions . . . . . . . . . . . 6.4 Complex equations . . . . 6.5 Definitions, theorems, etc. 6.6 More on math typing . . .
17 17 18
Organisation of documents 7 3.1 The basic template . . . . 7 3.2 Explaining the template . . 8 7 Graphics, tables, and boxes 3.3 Decomposing large docu7.1 Graphics . . . . . . . . . ments . . . . . . . . . . . 9 7.1.1 Simple graphics . 3.4 Working with large docu7.1.2 Figures . . . . . ments . . . . . . . . . . . 10 7.1.3 LATEX drawings . 4 Layout of documents 11 7.2 Tables . . . . . . . . . . 4.1 Changing the size of pages 12 7.2.1 An example . . . 4.2 Fancy headers . . . . . . . 12 7.2.2 Special tools . . 7.3 Text boxes . . . . . . . . 5 Text structures 13 7.4 Problems of floating . . . 5.1 Paragraphs . . . . . . . . . 13 1
18 19 19 20
21 . 21 . 21 . 21 . 22 . 23 . 23 . 24 . 25 . 25
2
1
Introduction
8
Bibliography and Index 8.1 Bibliography generation . 8.1.1 The bibliographic database . . . . . . 8.1.2 Citing of references 8.1.3 Formatting the bibliography . . . 8.2 Index generation . . . . .
26 26
26 10 Printing and distribution 27 10.1 Output files and hyperref 10.2 Getting LATEX packages, etc. 28 28 11 Conclusions
31
Customising LATEX
29
31
9
9.1 9.2
New and modified commands . . . . . . . . . . . 29 Making your own packages 29
References
30 30 30
1. Introduction If you produce a book or a large set of notes and papers, you need an advanced system for document creation and typesetting. If you include a lot of mathematics and graphics, you should consider LATEX (if you have not done so yet). Even outside the core areas for LATEX use—mathematics, computer science, physics, theoretical microeconomics, etc.—it can be of major importance. LATEX emphasises document structure and the logical mark up of text in contrast to a WYSIWYG1 system consisting of, for instance, MS Word, Equation Editor, and EndNote. In the latter system layout details that tend to pester document development and the consistent change of equations and figures is very difficult. The author experienced these problem when writing Andersen (1994)—and decided to turn to LATEX (Andersen, 1997). Presently, the development of several large book projects motivates an update of the applied LATEX system. This version of the system is used for the formatting of the present article that, however, has an introductory purpose. Therefore, it is not describing Andersen’s esameta.sty package for the LATEX system. This package and many other issues are covered by Andersen (2006b). What makes a LATEX system different from WYSIWYG systems is that it encourages the decomposition of complex tasks2 and that all information (including equations and citations) are contained in easily modifiable text files. Therefore, you need an advanced editing program. This program modifies the “source files” without a continuous look at a graphical display of the document in its final form but it also quickly presents the “output file”. Since the output is often a pdf file, the editor must integrate well with Adobe Reader. Thereby you may very frequently inspect the part of the document that you are developing. Actually, it is rather easy to learn how to mark up text in LATEX. If you have made the HTML code for a web page, you will have the feeling about what is going on. But the LATEX system as a whole is pretty complex. Thus this article can only give some impressions of the scale and scope of the LATEX system. The starting point for the learning process might be some example source files as well as the classic book by Lamport (1994) and the standard introduction by Kopka and Daly (2004)—but you may also try to find part of this information on the Internet in e.g. Oetiker et al. (2006) (available at people.ee.ethz.ch/˜oetiker/lshort/lshort.pdf) or Wiki Books (2006) (available at en.wikibooks.org/wiki/LaTeX). A real understanding of many details covered in the present article presupposes that you continue with The LATEX Companion by Mittelbach and Goossens 1 WYSIWYG 2 See
= What You See Is What You Get. Mittelbach and Goossens (2004, 18–20) and Grätzer (1996, 48–50).
2
3
The LATEX system
TEX LATEX Figure 1: The TEX and LATEX logos (2004)3 and, perhaps, Grätzer (1996). The LATEX Companion is especially needed if you also want to inspect Andersen (2006a) and Andersen (2006c).
2. The LATEX system 2.1. The evolution of LATEX Although the letters in TEX appear ordinary, they are really Greek. They stand for Tau, Epsilon, and Chi; and they are part of the Greek word techne (τεχνε) that is known from the word ‘technology’. The Greek meaning of techne is ‘art’ as well as ‘craft’. Both TEX and LATEX are dedicated to the art and craft of typesetting complex documents—but there is a difference between the two computer programs. TEX especially serves a bottom-up approach that can be illustrated by the TEX logo (see Figure 1). This logo is produced by TEX commands that define the horizontal and vertical placement of the printed letters in an artful arrangement. Such typesetting, with special emphasis on the handling of mathematics, forms the foundation of the work in TEX: From words and equations we turn to sentences, paragraphs, sections, chapters, etc. LATEX builds on TEX but it suggests a top-down approach: We start from the definition of books, reports, and articles. Then we turn to chapters, sections, and paragraphs. Finally, we consider the commands that can control the formatting of paragraphs and their components. The starting point for the evolution of TEX—and later LATEX—was the production of a series of large books by the computer scientist Donald Knuth—now a professor emeritus at Stanford University.4 These books on The Art of Computer Programming (Knuth, 1997) represent extremely complex typesetting problems. To make sure that such problems could be solved more easily in the future, Knuth (1990) developed the TEX typesetting language and a related type of fonts (Computer Modern). The system is mostly known for having extensive capabilities to typeset mathematics, but it also has many other facilities. However, the TEX system required the writer to enter into the details of document creation, so Lamport (1994) designed LATEX is an extension of TEX. Here he emphasised document structure and the logical mark-up of texts. At the same time LATEX focus on automatic numbering and cross-referencing. AMS-LATEX (cf. Grätzer, 1996) is based on the fact that the American Mathematical Society has for a long time been central to the TEX and LATEX community through its publishing mathematical journals and books. Its package adds a lot of features related to mathematical typesetting. TEX, LATEX and AMS-LATEX are in themselves just a small part of a complexly evolved system for mathematically oriented typesetting. This system is the result of the work of thousands of contributors and thereby it has become a very complex system for producing LATEX-based documents. This system—in more or less the same form—is available for most computer operating systems. The most solid description of the overall system is made by Mittelbach and Goossens (2004), but Kopka and Daly (2004) have provided a more readable book that serves as an introduction to the LATEX system. These and other authors demonstrate that the overall system has evolved in so many directions that it has become very relevant even to many groups of researchers that do not use mathematics in their texts. 3 This
is really a completely new book although it is called the second edition of Goossens et al. (1994). history of TEX and LATEX is summarised by Grätzer (1996, 379–382) and Mittelbach and Goossens (2004, 1–6). 4 The
2
4
The LATEX system
User’s source file (tex) BibTeX and MakeIndex (bbl,ind)
LaTeX engine Working files (aux, idx, toc, lof, lot)
System source files (cls, sty, fmt, tfm, fd)
Output file (pdf or ps or dvi)
System feedback (lis, log)
Figure 2: File types for the LATEX system
2.2. Integrated LATEX systems 2.2.1. Files used by the LATEX system The complexity of the LATEX system is easily demonstrated by the large number of different types of text file that are used or produced when LATEX documents are produced. However, each of these files have a standardised 3-digit suffix. Among these files are:5 bib: the user-defined bibliographic database that is used when creating the bibliography bst: the definition of a bibliographic style cls: a LATEX 2ε document class file—like article, book and slides def: a LATEX 2ε definition file fd: a font definition file ist: the definition of a style for making indexes sty: the definition of a package of commands that adds to the predefined LATEX styles tex: the document source file that we produce with an editor application Although is not necessary to know all these (and many other) types of file, the listing of them gives an impression of the complexity if the LATEX system that uses and/or produces these files (see Figure 2). 2.2.2. The integration problem The described system includes many programs, and several program solutions to the problem of handling the complex LATEX system have developed. These programs are often Integrated Development Environments (IDEs) that serve as user interfaces to many other programs and huge databases. In this way, the user is provided with access to at least the following programs and files: LATEX editors: Seen from the viewpoint of the user, the starting point is a text editor in which the LATEX source file (the tex file) is produced. Since the LATEX language includes hundreds of commands (and can easily be extended with thousands of additional commands), such text editors provide menus and icons that unburden the user from memorising these commands. Spelling checker: The user’s production of text and LATEX mark-up is supported by a spell checker that is designed to handle LATEX documents 5 Further
types of file are listed by Mittelbach and Goossens (2004, 8–9).
2
The LATEX system
5
Graphics: Simple graphics can be produced with LATEX commands, but we need an independent application that produces complex graphics and saves it in the correct format (e.g. pdf or encapsulated postscript). This application is not integrated in the Integrated Development Environment. BIBTEX: This is application for generating LATEX bibliographies (see Mittelbach and Goossens, 2004, Ch. 12). MakeIndex: MakeIndex The application for creating a sorted index (see Mittelbach and Goossens, 2004, Ch. 11). Distributions of LATEX files: There are systems that provides a—more or less—full set of files with LATEX code in a system that is accessible to the user’s Integrated Development Environment. The best distribution systems provide automatic upgrades and automatic download of packages and styles that the user applies for the first time. Output production: The user simply requests the Integrated Development Environment to compile the document source file. Then the IDE calls the necessary files and programs. The user may need to give the request 2–3 times before the final output is produced. Most users are most accustomed to pdf output, but other formats are available (PostScript and the special dvi format provided by TEX). METAFONT: Behind the scenes, we use an application that produces new sizes and styles of fonts when needed. This is an implementation of Donald Knuth’s METAFONT application and other font related tools. Debugging: The production of LATEX output will normally require the correction of errors of different types. Therefore, the Integrated Development Environment includes a window that provides information about the many steps that it performs—and about the errors that occur in some of these steps. The errors are located to numbered lines in the processed files, and there may also be easy ways of moving to the lines with errors. WYSIWYG?: Since the user very frequently compiles the tex file, the output viewer (e.g. Acrobat Reader) has to be well integrated. Then it is easy to detect layout issues and what LATEX or the user considers to be errors. 2.2.3. Files produced by the LATEX system As we have already seen, the basic input to the LATEX system is the source file MYDOCUMENT.tex. tex: the document source file that we produce with an editor application Although the ultimate outcome of LATEX is a single document—e.g. a pdf file—a lot of different types of file are produced during the processing of the tex file. Depending on the facilities we have chosen, we will see different types of file. Here is a list of some of these file types, ordered according to suffix:6 aux: an auxiliary file created and maintained by LATEX to support the creation of crossreferences, bibliography, table of contents bbl: a file created by BIBTEX that contains the bibliography to be placed near the end of the document—at the place where the \bibliography command is given dvi: the device independent output of LATEX which can be shown on screen or send to a printer ent: a file generated by LATEX if the endnotes package is loaded idx: a file generated by LATEX and used by MakeIndex 6 These files—but of course not the tex file—can be deleted after the output has been printed. However, most of the files include information that is used the next time the document is printed. If they are deleted, it is necessary to run LATEX two or three times instead of making a single run. Furthermore, the user must secure that the IDE runs BIBTEX and MakeIndex in between.
2
6
The LATEX system
Figure 3: The TEXnicCenter program ind: a file created by MakeIndex that contains the index to be placed at the end of the document—if the \makeindex command is given in the beginning of the document log: a log file that includes all the information on errors, etc. that LATEX produces during its processing of e.g. a tex file. pdf: a pdf file for printing ps: a postscript file for printing toc: the table of contents produced by LATEX–at the place where the \tableofcontents command is given
2.3. A concrete LATEX system We shall concentrate on LATEX systems that are freely distributed (normally under the GNU Public License).7 Since Unix/Linux systems normally are delivered with a fully functioning LATEX system of this type, we shall presently study the setting up of systems for other types of computer boxes. On a Macintosh OS X, we could use a combination of the simple IDE called TEXShop and the TEX distribution system called TEXLive–teTEX (which are actually standard distributions for Unix machines). However, our chosen example is a system for MS Windows computers. This system includes: MikTEX: This is a basic LATEX distribution for Windows, with full support for the installation and configuration of LATEX and related systems. You simply start by installing a small or large version of the LATEX distribution. Later, you can update your installation manually, but you can also allow that MikTEX from the net automatically installs needed components. You simply write the names of new packages or styles in your tex files, and then MikTEX finds out that they should be downloaded. MikTEX can be downloaded from www.miktex.org. Actually, you should install it before installing the following program. 7 Mittelbach and Goossens (2004) include a CD with a near-full LAT X distribution as well as related E application programs for Unix/Linux, MS Windows, and Macintosh OS X—but the present article presents other applications.
3
Organisation of documents
7
TEXnicCenter: This is a graphical front-end for MikTEX that provides an Integrated Development Environment.8 TEXnicCenter (see Figure 3) might appear a bit complicated because of its many features, especially because of its support of project orientated development of LATEX documents. To begin with, you can consider it as an editor for the production of tex files that allows simple insertion of LATEX constructs by menu or toolbar. To see the intermediary results, you should often request TEXnicCenter to show you the output (in pdf, ps, or dvi format). Later, you can appreciate the simple jumping to errors, warnings and bad boxes, the support for document templates, the customisable menu and toolbars, and the project management facilities. TEXnicCenter can be downloaded from www.texniccenter.org. JabRef: This is a program for managing the bibliographic database. It is described at the end of Section 8.1.1. Setting up the system: Create a directory for your first LATEX project, start the newly installed TEXnicCenter, select File/New Project, write the name of the project (which will become the name of the tex file), and save. If you are writing a paper, use something like the template described in Section 3.1. If you are working with a thesis or a book, then create a subdirectory for each chapter, name an empty tex file in a simple way, and use the template of Section 3.3 in the main tex file of the project. During the development of your project, you will recreate the output file innumerable times. Therefore, you should consider which output viewer you want. If you choose the option LaTeX => DVI, the viewer will be the Yap DVI Viewer, which is well integrated into the LATEX system. However, many will prefer the option LaTeX => PDF, but here you probably have to modify the strange preferences for using Acrobat Reader (found in Build/Define Output Profiles).Presently, information on this issue is found at en.wikipedia.org/wiki/TeXnicCenter. Working with the system: The basic rule for successful production of LATEX documents is that they have to be developed incrementally. The reason is that LATEX has a huge number of available commands and the misspelling of a single of them can hinder the system in producing any output. Therefore, it is a hopeless strategy to produce a document with a large number of commands before trying out the output. Instead, you should very frequently hit the key F7 when working in TEXnicCenter. This will save your file and build (but not show) the output. During the process, a lot of information is shown in the bottom window. If no output is produced, select the menu Build/Next Error, figure our what you made wrong, rewrite, and press F7. Repeat this process until output is produced. Now you at the bottom window will see a final message. This message might still include errors and warnings: LaTeX-Result: 3 Errors, 4 Warnings, ... If this message is like this, select the menu Build/Next Error, and repeat the process. Then select Build/Next Warning, and check whether it is important. In contrast, you might ignore massages about “Bad Boxes” since LATEX has unrealistic requirements about the quality of its layout of paragraphs, etc. You might even end up accepting unimportant “error messages”. Then you inspect the output file by pressing F5 (actually, you may combine building and viewing by Ctrl+F5).
3. Organisation of documents 3.1. The basic template As mentioned above (see Section 2.1) a core purpose of design of LATEX by Lamport (1994) is to focus the writer’s attention on the document structure and the logical mark up of texts. This 8 An alternative is the WinEdt program that can be downloaded for trial from www.winedt.com. This program is in some respects more advanced than TEXnicCenter—but it is also more complex.
3
Organisation of documents
8
starts by considering the overall structure of a LATEX document as a rather simple template that should just be filled out. In the following example covers major parts of such a template for an article like the present one. The lines are numbered9 to allow for easy referencing: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
\documentclass[a4paper]{article} \usepackage{amsmath,amssymb} \usepackage{graphicx,epsf} \usepackage{natbib} \usepackage[danish,british]{babel} \begin{document} \title{\textbf{TITLE}} \author{AUTHOR% \thanks{INTRODUCTORY FOOTNOTE.}\\ {\normalsize INSTITUTION}\\ {\small AUTHOR'S EMAIL, WEBSITE} } \date{DATE} \maketitle \begin{abstract} ABSTRACT \end{abstract} \tableofcontents \section{NAME OF FIRST SECTION} \label{sec:FIRSTLABEL} TEXT OF FIRST SECTION \section{NAME OF SECOND SECTION} \label{sec:SECONDLABEL} \subsection{A SUBSECTION} \label{ssec:SUBSECTIONLABEL} TEXT OF A SUBSECTION \renewcommand{\bibindent}{0.0} \small \bibliography{MYBIBLIOGRAPHY} \bibliographystyle{apa} \end{document}
3.2. Explaining the template In the above example we—as always—start by declaring the type of LATEX document that we are dealing with (line 1). In the present case we have an article as defined the basic LATEX file that defines how articles are to be typeset.10 We specify an option—a4paper—because the article should be set on European A4 paper.11 We could also have added other options like [a4paper,twocolumns] to have the article set in two columns as the present article. 9 The numbering is created by the listing environment defined by the moreverb package which modifies the verbatim environment. 10 The style of the article can be modified by additional definitions in a specialised package like MYPACKAGE.sty. 11 The margins of the text, however, have been set so that the output should be printable on American paper.
3
Organisation of documents
9
The file consists of four main parts: the preamble (lines 1–5), the front matter (lines 9–20), the main matter (lines 22–29) and end matter (lines 31–34): Preamble: before we come to the document we make a series of definitions which influences the available commands, the typesetting of the document, etc. • If we want special mathematical symbols and an ability to split formulas over several lines, we call (line 3) parts of the AMS-LATEX package like amsmath and amssymbol. • If we want a special handling of graphics, we may call (line 4) graphicx and epsf. • If we want citations as they are normally made in the social sciences (and in this article), we e.g. call the natbib package (line 5) and the apa bibliographic style (line 34). • We call the package babel (line 5) to handle hyphenation and other language issues (see Section 5.7). The last language in the babel call is the primary one. • We may—according to special needs—apply further packages. The present article e.g. uses verbatim, moreverb and curves. Front matter: When we have called the basic LATEX packages, we can start our document. The first task is to give the title of the article, name, institution, email and the date of the present version of the article (lines 10–15). Furthermore, we can make an initial note with e.g. acknowledgements (line 12). Finally, the front matter ends with an abstract of the article (lines 18–20) and a table of contents (line 21). Main matter: Then we come to the main contents of the article (lines 23–30). This is divided into sections (starting at lines 23 and 26) and subsections (our example starts at line 28) that will automatically be numbered. For each section you can make a label line the sec:FIRSTLABEL in line 24. This label can later be used for e.g. referencing the number of the section: \section{NAME OF SECTION 1} \label{sec:LABEL1} In Section~\ref{sec:LABEL1} we see ... End matter: At the end of the document we place the bibliography (see line 34) and—perhaps— the index (see Section 8).
3.3. Decomposing large documents When we develop a complex document, it is helpful to focus on one part at a time. This divideand-conquer strategy can be promoted by defining the document as a master document that consists of subdocuments which in turn may consist of subsubdocuments, and so on. We can then focus on an individual part of the document. This does not mean that the whole document consists of independent parts: all subdocuments depend on the declarations in the beginning of the master document and individual sections may include cross-references and citations. This means that we have to be careful when working with parts of a document. The simplest form of decomposition is to split the document into a set of files that each contains a chapter, section, or subsection. Let us think of a book document placed in a directory with an empty version of Chapter 1 placed in a subdirectory as MyBook/Chapter1/Chapter1.tex. When we have made all the components, we can create the master file MyBook/MyBook.tex: 1 2 3 4
\documentclass{book} \include{MyDefinitions} \makeindex \begin{document}
3
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Organisation of documents
10
\frontmatter \author{AUTHOR} \title{TITLE} \date{DATE} \maketitle \tableofcontents \include{Preface/Preface} \mainmatter \include{Chapter1/Chapter1} \include{Chapter2/Chapter2} ... \appendix \include{Appendix1/Appendix1} ... \backmatter \bibliographystyle{apa} \bibliography{MYBIBLIOGRAPHY} \printindex \end{document}
Preamble: We start in lines 1–2 by declaring the document as a book (calling book.cls) and by calling the file with all our definitions (MyDefinitions.tex, e.g. including the LATEX lines 3–6 of Section 3.1). In line 3 we ask LATEX to compile an index (cf. Section 8.2). Front matter: The starting elements in lines 6–9 are author, title and date. In line 10 we ask for a table of contents. Then we in lines import the document files one by one from their subdirectories. We start with the preface. All front matter has its own pagination (normally with Roman numbers). Main matter: In lines 13–14, we import Chapters 1–2. appendices: In line 16 we mark with the \appendix command that the appendices will start. In line 17 we import Appendix 1. Back matter: At the end of the document we place the bibliography (lines 20–21) and the index (line 22).
3.4. Working with large documents Given this master document, LATEX Integrated Development Environments like TEXnicCenter make editing very easy. The tool is the Navigation Bar that visualises the total structure of the document (see Figure 4) and helps with several operations. To navigate to a particular section, figure, or equation in your document, start by locating this item. Then double-click. TEXnicCenter now displays this item in the text window. This even works for files that has not yet been opened! The Navigation Bar also facilitates cross referencing (see Section 5.6). For instance, you write Section~, locates the section you want to refer to, right-click this section, and select Insert Reference. Then the result will look like Section~\ref{sssec:cros} (of course assuming that you have labelled your sections). The Navigation Bar also provides specialised supports for cross reference. Thus, there are listings of figures, tables, equations, etc., and from here you can insert references in the same way as for sections. Similarly, there is a bibliographical list (if you have provided a BIBTEX database). From this list you can insert citations (see Section 8.1.2). The master document allows the printing of individual parts. When you have made changes in e.g. Chapter 2, you can print this chapter by adding the command \includeonly{Chapter2} before line 4 in the master file and then run LATEX on the master file. Then you get a partial manuscript which includes title, table of contents, Chapter 2, bibliography and index. Except for
4
Layout of documents
11
Figure 4: Using structure view in TEXnicCenter the changes caused by changes in Chapter 2, the table of contents, bibliography and index uses information from previous runs of the whole document. To focus the printed output further on Chapter 2, you can exclude the table of contents, bibliography and index by adding a percent sign before these items (e.g. %\printindex). You can also (if you use the moreverb package) “comment out” large sections of Chapter 2 by defining them as comments which are not to be printed: \begin{comment} Excluded part of Chapter 2. \end{comment} When you once more want to work with the whole document, you have to remember to remove all the % and all the comment environments.
4. Layout of documents The above listings of an article document and a book document are complete! You can simply let your LATEX interface (e.g. TEXnicCenter) run them, and the result with be two skeletons (templates). If you do so (after creating in your project folder an empty file called MYBIBLIOGRAPHY.bib, you will immediately recognise that LATEX makes a large number of decisions about the document layout. Although these decisions will do for many purposes, you may need to improve the design. For this purpose, you can find many pre-defined templates (for e.g. an article, a book, or a thesis) on the Internet. However, it is relevant to have some knowledge about the possibilities of improving the designs of the LATEX document classes. The LATEX distribution includes the classes article.cls, book.cls, and thesis.cls. It is one of these classes that you normally call by a command like \documentclass{book}. This class defines an large number of layout issues—like the types of sectioning (chapters, sections, appendices), the numbering of these sections, the layout of the page, the running header on the pages, the design of table of contents, etc. The auxiliary programs BIBTEX and MakeIndex use styles that further determine the formatting of the bibliography and the index. Many of these decisions can be changed by the setting of different options, and you might even (probably with much difficulty) redefine the document classes and styles. However, you will normally apply packages that do much of this work for you. In the following, we shall illustrate the redesign issues by a couple examples.
4
12
Layout of documents
4.1. Changing the size of pages The predefined settings are made according to the experience of the publishing business, but sometimes academics want more text on each page. In the present article, this problem is solved by redefining the margins of the text on the page. The solution is to place something like the following commands in the preamble of your tex file: \textwidth \textheigth \oddsidemargin \evensidemargin
= = = =
6.25 9.00 0.00 0.00
in in in in
It is not easy to understand these commands (see Mittelbach and Goossens, 2004, 193–97), so the best probably is to process by trial and error. A more specialised issue concerns two-column text. This is provided as an option to the class call, like \documentclass[twocolumn,a4paper]{article} where we also ask for printing in the European A4 format. The remaining issue is that for the purposes of the present article, the spacing between the columns is too small. Therefore, the preamble also includes \setlength{\columnsep}{0.3 in}
4.2. Fancy headers The predefined headers in the LATEX classes are pretty boring. Therefore, you might want to introduce more fancy headers. This is helped by the package fancyhdr (cf. Oostrum, 2004). Let us see how. The starting point is to load this package and to reset the definition of headers (and footers). This is done by putting the following commands in the preamble: \usepackage{fancyhdr} \pagestyle{fancy} \fancyhead{} \fancyfoot{} Now both the header and the footer are empty. The present article has then defined the following cryptic command. \lhead{\sffamily\nouppercase{\leftmark}% \hfill \bfseries\thepage} This command sets the text of the header in sans serif font, suppresses capitalisation of the header text (the name of the section), and puts the section title to the left and the page number to the right (in bold type). A remaining issue concerns the length of the section title. If you use a very long title you will need a shorter version for the header (and for the table of contents). For each section, this is done in the following way: \section[Short title]{Long title} For a book, the syntax is more complicated. Here we e.g. would like the title of the book on right pages and the title of chapters on left pages. This is obtained by adding to the preamble the following: \lhead[\sffamily{\bfseries\thepage}% \hfill BOOK TITLE]{} \rhead[]{\sffamily\nouppercase{\leftmark}% \hfill {\bfseries\thepage}}
5
Text structures
13
5. Text structures Now we begin the treatment of the standard topics of the reference web sites and the manuals.12 . The reason why these manuals are needed is that a huge number commands are available (see e.g. www.giss.nasa.gov/tools/latex/ltx-2.html). You should consider using the menus of your LATEX editor to check out different commands. This approach will also help you avoiding the misspellings that can hinder the production of any output.
Figure 5: One of many menu bars in TEXnicCenter The number of constructs available from the Insert and Math menus of TEXnicCenter are huge, but to illustrate the procedure we shall use the simple menu bar depicted in Figure 5) as example. Here the third item is a numbered list. By clicking this item we obtain \begin{enumerate} \item \end{enumerate} The functioning of this “environment” is described in Section 5.3.
5.1. Paragraphs Text is basically divided into paragraphs that are produced by inserting a blank like into the source file. Special paragraphs are defined through so-called environments like the comment environment in Section 3.3. We demarcate a particular type of environment by a \begin{environment}...\end{environment}, where environment is the type of text structure we are working with. One of the effects of defining a paragraph is that the next paragraph will start with an indentation. However, you will sometimes want the text to continue without indent after an environment. You can obtain this effect by starting the next paragraph with the command \noindent. The same effect—important in mathematical texts (see Section 6)—can be obtained text if you do not insert a blank line but only a single line shift after the environment. The alignment of one or more paragraphs can be altered by a \begin{xxx} ... \end{xxx} parenthesis with the argument center, flushright, or flushleft.
5.2. Quotes Ordinary quotation marks are asymmetric. The left mark is made by ' or '' and the right mark by ' or ''. Thus, `the idea of ``simplicity''.' produces ‘the idea of “simplicity”.’ Larger quotes are displayed. If, for instance, a paragraph occurs within a quote environment, it is printed with both left and right indentation. Thus we can write13 12 Start
e.g. with the classic by Lamport (1994) or with Kopka and Daly (2004). align the author to the right of the text, we actually break the line, place an empty mbox, use the flush right command (\hfill), and write \hfill\emph{Ada Augusta}, 1842. 13 To
5
Text structures
14
\begin{quote} The engine can ... accordingly. \\\mbox{}\hfill\emph{Ada Augusta, 1842} \end{quote} We get the following result: The [computational] engine can arrange and combine its numerical quantities exactly as if they were letters or any other general symbols; and in fact it might bring out its results in algebraic notation, were provisions made accordingly. Ada Augusta, 1842
5.3. Lists Text can also be organised in more complex structures or templates, like lists, programs and tables. For instance, we make a numbered list with the following template: \begin{enumerate} \item THEFIRSTITEM \item THESECONDITEM \end{enumerate} If we fill out the template, we may e.g. get the following result about the three kinds of list that are available in LATEX. 1. Numbered lists are produced within an enumerate environment. If you add an item, the list is automatically renumbered. 2. Bulleted lists are produced by an itemize environment. 3. Captioned lists are defined by a description environment; they consists of words and their definitions (like \item[WORD] DEFINITION). Like other lists they can also be placed as sublists. Thus we can repeat within a description environment:14 enumerate: defines numbered lists itemize: defines bulleted lists description: defines definition lists
5.4. Tabulated text When you use a traditional typewriter, we create table by means of the spacebar or—better—the tabulator with preset tab stops. In LATEX all tabs and all extra spaces are normally ignored, so we have to define environments in which spaces and/or tabs are taken literally. These environments are verbatim, tabbing, tabular and array. Let us start with a simple task, to write a program in which the lines are indented to emphasise the program structure. Here we apply a verbatimtab environment (from the moreverb package) to allow for tabs and to have the program set in a typewriter font. In the source file > represents the tab character: \begin{verbatimtab}[3] Exchange := proc(gA,fA,gB,fB) ... > X_rate := Rate(gA,fA,gB,fB); > X_quantity := > > > Quantity(gA,fA,gB,fB,X_rate); ... \end{verbatimtab} 14 The
typesetting of the defined words in bold may seem too dominant in the text. They can also be set in other fonts like typewriter font by \item[\texttt{...}]. In the present article I use the bold type to demarcate clearly the defined words from their definitions.
5
Text structures
15
Since we have given the argument [3] to the verbatimtab environment, a tab means an indent of three characters. As a result we get: Exchange := proc(gA,fA,gB,fB) local X_quantity, X_rate; X_rate := Rate(gA,fA,gB,fB); X_quantity := Quantity(gA,fA,gB,fB,X_rate); if X_quantity > 0 then Contract(gA,fA,gB,fB, X_rate,X_quantity); fi; end; Tables are specialised tabbing environments that furthermore have numbers and captions. We shall consider them together with graphics (see Section 7.2).
5.5. Notes There are four main types of note—all of which are used in the present article: • Footnotes are placed at the bottom of the page and they may be marked by special footnote marks (like ∗, †).15 • Endnotes are placed at the end of the document or after each chapter. • Table notes are placed after the table and marked with small letters. • Marginal notes placed in the right or the left margin (see the NB! in the margin of the text). Footnotes are inserted by means of the \footnote command. Here is an example: Minimise the number of footnotes.\footnote{Certain types of text---like historical studies---cannot avoid to use a large number of footnotes.} This source text produces the following result: Minimise the number of footnotes.16 In the social sciences we often use endnotes, but they are not included in the standard LATEX styles. Instead they are produced with the special package endnotes (see Mittelbach and Goossens, 2004, 125–26). When this package is loaded, we may simply use \endnote instead of \footnote. We determine where to place the endnotes by the command \theendnotes.17 During the preparation of a document it is often helpful to print the endnotes as footnotes. That is easy. Early in our source file we just write the following command: \renewcommand{\endnote}{\footnote} 15 The different marking systems can be attributed to different types of note. To get the special footnote marks for footnotes we write: \renewcommand{\thefootnote}{\fnsymbol{footnote}} 16 Certain types of text—like historical studies—cannot avoid to use a large number of footnotes. 17 The package does not produce a finely tuned output. To improve the typeset document, we may write: \begingroup \renewcommand{\footnotesize}{\small} \setlength{\parindent}{0pt} \setlength{\parskip}{1ex} \theendnotes \endgroup
NB!
5
16
Text structures
The consequence is that both footnotes and endnotes are printed at the bottom of the page—but they can be distinguished since each type of note has its own numbering system. Marginal notes are often used in the process of document creation. Here we use the command \marginpar{Text in the margin}. In a document printed in two columns there is not much room for marginal notes. We might, however, write short notes or key works (like \marginpar{$\backslash endnote$}.
5.6. Cross references To reference to an item or a page in the document, we start by inserting a label like \label{LABELNAME}. This label can be inserted everywhere, and it can be used for referring to the page in question by the command \pageref{LABELNAME}. For instance, if we have inserted a label in the introduction to the present article, we can later write Page~\pageref{introwysiwyg} (here the tilde is used so that page and page number is not split across lines). For instance, we may write “WYSIWYG was discussed on Page 2”. References are normally made to items like section numbers, figure numbers, or equation numbers. Here we need to place the label immediately after defining a section or within the environment that defines a figure or numbered equation. For instance, we can have labelled the introductory section secintro and can refer to it with see Section~\ref{secintro} (see Section 1). Similarly, we can refer to one of the equations of Section 6.4 by Equation~\eqref{align2} and Page~\pageref{align2} and write “in Equation (3) on Page 19, we shall see . . . ”.
5.7. Further aspects of text LATEX makes available a large number of further facilities for defining text elements in a document.18 They include: Style: the style can be changed to e.g. italics, bold, SMALL CAPS, sans serif and typewriter font: \emph{...}, \textbf{...}, \textsc, \textsf and \texttt. Size:
for changing the
size
is a set of declarations ; these declarations are \tiny{...}, \scriptsize{...}, \footnotesize, \small, \normalsize, \large, \Large, \LARGE, \huge and \Huge.
there
Special signs: •, –, —, \, |, &, %, and $ can be made with \textbullet, --, ---, \textbackslash, \textbar, \&, \%, and \$. Frames: can e.g. be made with fbox ; the command is \fbox{YOURTEXT}. Hyphenation: is normally made automatically by LATEX; the reason is that in complex documents like the present article there can be extreme and ugly differences in the spacing of different lines. If LATEX cannot determine an appropriate hyphenation, then the text will sometimes extend to the right of the normal margin. In that case, you can add an optional hyphen to the word (for instance, aaaa\-aaaaaaa). European hyphenation: is provided by the babel package (see Mittelbach and Goossens, 2004, Ch. 9); the present article is mainly hyphenated according to the British style but in the following text we switch to dkhyphen.tex by means of the environment \begin{otherlanguage}{danish}:
18 Text elements cannot normally be used in math environments. Here you need special commands—see Section 6.6.
6
17
Mathematics
Figure 6: The extensive math menu bars in the WinEdt editor
Figure 7: One of the simple math menu bars in TEXnicCenter På Akerlofs citronmarked for biler var kvaliteten specificeret via fabrikskvaliteten— som blev opdaget af sælgerne. Men hvad hvis kvaliteten bestemmes endogent i vo-
res model af markedet? Dette svære spørgsmål diskuteres hos Varian gennem et dubiøst eksempel, nemlig paraplymarkedet.
Non-standard symbols: like ä, æ, Æ, ø, and Å can be written as \"{a}, \ae, \AE, \o and \AA. Alternatively, you should declare the language in the babel package (see above) and then in the preamble to your document insert \usepackage[T1]{fontenc} \usepackage[latin1]{inputenc} Dates: Within babel, the setting of dates with the command \today is made according to your chosen language: british gives 17th September 2006 while german gives 17. September 2006, french gives 17 septembre 2006, and danish gives 17. september 2006.
6. Mathematics When turning to mathematical typesetting, the complexity becomes even more overwhelming than before. The solution, however, is the same as before: incremental learning and decomposition of tasks. Furthermore, there are excellent textbooks at the levels of beginners and advanced users. Thus a sequence of books might be Lamport (1994), Kopka and Daly (2004), Mittelbach and Goossens (2004), and Grätzer (1996). You might also inspect the information and resources provided by the American Mathematical Society (available at www.ams.org/tex/) The number of commands for mathematical typesetting in LATEX is huge so the advice given in the beginning of Section 5 now becomes imperative: use the specialised menus of your editor program! Some of these programs (like WinEdt, see Figure 6) have an extensive system of graphical menus that help to find select among the commands. But the are not really necessary. If you are thinking of the command for the non-equal symbol in TEXnicCenter, look it up in the menu Math/Comparison or use the menu bar depicted by Figure 7. If you click the seventh item on this bar, \neq is inserted and the result is 6= (within a maths environment).
6.1. A math example All books on the LATEX system cover the typesetting of mathematics that can be rather complicated, but it might be relevant to emphasise the basic issues. Let us, for instance, assume that
6
18
Mathematics
you want to write a simple equation that says that the total quantity of an industry at time t is equal to the sum of the outputs of the firms which for each firm j is its capital coefficient times its capital stock. In LATEX this is written in as Q_{t} = \sum_{j=1}^{n}A_{jt}K_{jt}. The marked-up formula has two special elements. First we see that subscripts and subscripts are defined by _{...} and ^{...}. Second, we see a more complex specification of a sum, namely \sum_{...}^{...}..., where the subscript and superscript have to be placed in relation to the large operator ∑. The production of a marked-up equation takes some time. But as soon as it is made, you have several advantages that we shall consider in the following.
6.2. Forms of math typesetting One advantage is that the equation can be typeset in several ways. If you enclose the equation in dollar signs ($...$), it will be printed in-line in compresses form like Qt = ∑nj=1 A jt K jt . If you enclose the equation in double dollar signs ($$...$$), it will be displayed on its own line as n
Qt =
∑ A jt K jt .
j=1
Finally, if you enclose the equation like \begin{equation} Q_{t} = \sum_{j=1}^{n}A_{jt}K_{jt} \label{eq:Qt} \end{equation} the equation will be displayed with a number which you can refer to elsewhere: n
Qt =
∑ A jt K jt .
(1)
j=1
With this specification you can refer to Equation (1) by Equation~\eqref{eq:Qt}. More importantly, you do not have to go through your system of references to equation numbers each time you add or delete an equation. If you added an equation before the numbered equation, then the reference would automatically be changed to “Equation (2)”.
6.3. Automatic typesetting decisions If you consider the different versions of the equation in comparison with the marked-up equation, it becomes obvious that the LATEX system makes a lot of decisions for you. These decisions include • centring of displayed equations with equation number to the right and an addition vertical space before and after the equation line, • condensed form of inline equations, • printing of variables in italics with adequate horizontal space between them, • for subscripts and superscripts the use of a smaller font size, • etc. The good thing with the LATEX system is not only that these practical and aesthetic decisions have been made with great care, but also that they can be changed fairly easily by your publisher or yourself. The definitions are found in text files that can be changed or—better—overwritten be commands in your own document system.
6
19
Mathematics
6.4. Complex equations One of the problems in mathematical typesetting is to align equations correctly. Here the AMSLATEX gives a lot of flexibility (see Grätzer, 1996). Take for instance Equations (2)–(4): r 2 = s2 + t 2
(2)
α
(3)
2u + 1 = v + w y+z x= √ s + 2u
(4)
These equations are coded by \begin{align} r^{2} &= s^{2} + t^{2} \label{eq:align1}\\ 2u + 1 &= v + w^{\alpha} \label{eq:align3}\\ x &= \frac{y + z}{\sqrt{s + 2u}} \label{eq:align3} \end{align} which we can refer to individually (e.g. to Eqn (3) by \eqref{eq:align2}) or collectively as Equations (2)–(4). Another typesetting problem emerges when we want to show how a function works in different cases. Here we use the cases environment within the display or equation environment. For instance we write \begin{equation} f(x)= \begin{cases} -x^{2}, &\text{if $x < 0$;}\\ \alpha + x, &\text{if $0 \leq x \leq 1$;}\\ x^{2}, &\text{otherwise.} \end{cases} \begin{equation} and the result is 2 −x , if x < 0; f (x) = α + x, if 0 ≤ x ≤ 1; 2 x , otherwise.
(5)
6.5. Definitions, theorems, etc. In formal analysis there is a tradition of numbering definitions, theorems, etc. for later referencing. To use this facility, we should in the preamble of the source file declare the types of theorem-like structures we want to use: \newtheorem{definition}{Definition} \newtheorem{theorem}{Theorem} Now we can make use the facilities. For instance we may in game theory discuss refinements of the Nash equilibrium. In this context, we in definition 1 specify how in a population of strategies an incumbent strategy S∗ can be evolutionary stable against small minorities of any 0 0 other strategy S . This is decided by comparing the conditional payoffs for S∗ against S (i.e. 0 ∗ U(S , S )), etc.
6
20
Mathematics
0
Definition 1 A strategy S∗ is an evolutionary stable strategy if for everyhother strategy S there i 0 0 exists a small frequency ε¯ of S such that for all ε ∈ [0, ε¯ ] we have that U S∗ , εS + (1 − ε)S∗ > h 0 0 i U S , εS + (1 − ε)S∗ . This numbered definition is produced by the definition environment \begin{definition} ... \end{definition} Similarly, we have a theorem environment with its own numbering scheme. Take, for instance, the following result for 2 × 2 games: Theorem 1 Consider a context of pairwise contests and a two-dimensional pay-off matrix A ≡ (ai j ). Assume aii 6= ai j (i = 1, 2, j 6= i). Then an evolutionary stable strategy exists.
6.6. More on math typing LATEX and AMS-LATEX include a very large number of facilities for typesetting of mathematics. LATEX-oriented editors (like the MS Windows programs TEXnicCenter and WinEdt) have interfaces which helps to find the facilities. They include: Math styles: we sometimes need to specify the math styles like italics (\mathit{...}), boldface (\mathbf{...}), etc.—but remember that normally LATEX immediately recognises that a variable like Q should be typeset in italics and that ln should be typeset in roman Text style: to place ordinary text within a mathematical environment, we write \text{...} (as demonstrated by Equation (5)) Accents: to obtain a, ˙ a¯ and a, ˆ we write \dot{a}, \bar{a} and \hat{a} Greek: within mathematical environments α, β and Γ is obtained by writing \alpha, \beta and \Gamma Some symbols: we get ℜ, ∂, ∃ and ∞ by writing \Re, \partial, \exists and \infty Some functions: exp, ln, max and lim are obtained by \exp, \ln, \max and \lim Relations: to obtain e.g. ≤, ≡ and ⊆, we write \leq, \equiv and \subseteq Large operators: like the formula for a sum (see Section 6.1), we have a number of other temR plates to fill out, e.g. for integrals like ac (by \int_{...}^{...}...) and products ∏ (by \prod). √ Templates: for fractions a/b and ba (by a/b and \frac{a}{b}), roots n a (by \sqrt[n]{a}), etc. Large delimitators: are used in complex expressions like (a + b) + c (by \big[ (a+b) + c \big]) ab Matrices: while simple inline matrices like are obtained by e.g. cd \left( {a\atop c} {b\atop d} \right), full control over matrix structures requires an environment like array. Environments: we have already encountered the math environments math ($...$), displaymath ($$...$$) and equation (begin{equation} ... end{equation}); other environments are eqnarray and array; here new rows are inserted by \\ while the elements of the rows are split by &; of course, there has to be the same number of elements in each row. The above list is just meant to give an quick impression of some of the many math facilities of LATEX (and TEX). A more extensive treatment is given by Grätzer (1996).
7
Graphics, tables, and boxes
21
7. Graphics, tables, and boxes 7.1. Graphics This topic is covered by Lamport (1994, Ch. 7) and Mittelbach and Goossens (2004, Ch. 10). There has even come out a whole book about the subject (Goossens et al., 1997). The complexity of the subject suggests a gradual movement away from the simplest possible solutions. However, a preview of more advanced topics seems relevant. It should be noted that graphics are not a part of the LATEX source file (.tex). Instead each picture is imported from a specialised graphics file. It is best to use graphics files in the eps/EPSF format or pdf format. 7.1.1. Simple graphics The graphics file can be referred to through an \includegraphics command. This command allows the scaling of the graphic. For instance, we want it to have the height of 4 cm (and a corresponding horizontal scaling). If we have the file program.pdf in the same folder as our tex file, we can give the following command: \begin{center} \includegraphics[height=4cm]{program.pdf} \end{center} The result is:
The approach to graphics that underlies the placement of the above figure has many similarities with the simple display of mathematical equations that was discussed in Section 1. There is no numbering and the graph is printed exactly where it is described in the source file. The former feature makes referencing difficult and the latter feature will often disturb the flow of the text by creating extra vertical spacing between the paragraphs. 7.1.2. Figures An alternative approach is to define a special environment for displaying graphics files, namely the figure environment. In the new environment the figure is able to float to find a—more or less—nice place in the printed document. Furthermore, the figure is numbered automatically and can easily be referred to in the surrounding text—without any need for renumbering. Thus the following marked-up text can either be placed precisely where the command is placed in the source code (h = here) or at the top of the page (t):19 \begin{figure}[t] \capstart\centering 19 The
use of the ‘startcaption’ command presupposes the loading of hypcap.sty.
7
22
Graphics, tables, and boxes
G Firm 5 5 Firm 1 4 Firm 2 Firm 6
3 Firm 3 2 Firm 6 20
Firm 4 40
60
80
100
Figure 8: Example of simulation results \includegraphics[width=0.5\textwidth]{firms.pdf} \caption{Example of simulation results} \label{fig:exam} \end{figure} The result is a figure (number 8) that is not necessarily placed after this sentence. Alternatively, it will be placed at the top of a page. Now Figure 8 can be referred to by \ref{fig:exam} and the references will automatically be changed if the figure changes its number. 7.1.3. LATEX drawings In the LATEX system, there are several packages for drawing figures. Here we shall apply the curves package that extend the ordinary LATEX commands for the picture environment (see Mittelbach and Goossens, 2004, 611–12). We shall consider a relatively complex example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
\setlength{\unitlength}{1mm} \begin{figure}[t] \capstart\centering \begin{picture}(55,55) \put(0,0){\vector(0,1){50}} \put(0,51){\makebox(0,0)[b]{y}} \put(0,0){\vector(1,0){50}} \put(52,0){\makebox(0,0)[c]{x}} \thicklines \curve(5,48, 20,20, 48,5) \put(10,40){curve} \put(20,20){\circle*{1.5}} \put(23,20){\makebox(0,0)[b]{A}} \curve(0,40, 40,0) \put(10,8){straight line} \end{picture} \caption{Example of a picture} \label{fig:pict} \end{figure} The above listing (which produces Figure 9) defines the following steps:
7
23
Graphics, tables, and boxes
y 6
... ... ... ... ... curve .... .... .... ..... .... .. .... .. .... ... .... .. .... ... ....... ........ ....... ....... .... .....sA ...... ...... ............ ............ .... ........ .... ......... . . straight line .......... ............................ ............... .... .... .... .... .. -
x
Figure 9: Example of picture (by curves.sty) unit length: line 1 sets the unit length to 1 mm to make calculations easy; a scaling of the picture can be obtained by changing the unit length figure: line 2 defines a figure environment and line 3 centres the graphics picture: line 4 defines a picture of 5.5 × 5.5 cm coordinate system: lines 5–8 draw a coordinate system and put labels on the axes curve: lines 9–11 define a thickly drawn curve that goes from point (5,48) through point (20,20) to point (48,5). point and line: lines 12–15 define and label a straight line from point (0,40) to point (40,0), and we indicate the tangency point with the curve by a dot and a label, A = (20,20). caption and label: lines 17–18 define a caption and a label for references
7.2. Tables 7.2.1. An example Tables20 are—like figures—numbered and floating elements of LATEX documents. Tables have also some similarities with tabbing environments (see Section 5.4) but they are much more specialised. They can most easily be described through an example. 1 2 3 4 5 6 7 8 9 10 11 12 13
\begin{table}[t] \capstart\centering \begin{tabular}{||l|c|c||} \hline \hline Statement & \multicolumn{2}{c||}{Conditions}\\ \hline S1 & B1 & B2 \\ \hline S2 & B3 & B4 \\ \hline \hline \end{tabular} \caption{This is the first table} 20 The
topic of tables is covered by Mittelbach and Goossens (2004, Ch. 5).
7
24
Graphics, tables, and boxes
Statement S1 S2
Conditions B1 B2 B3 B4
Table 1: This is the first table Statement S1 S2
Conditions B1 B1 B3 B4
Table 2: This is the second table 14 15
\label{tbl:first} \end{table} The above listing (which produces Table 1) has the following characteristics: table: lines 1–2 define a centred table as a floating element that should either be placed here, at top or at bottom of the page columns: line 3 defines a tabular environment with three columns; one column should be left aligned (l) while the other columns are centred (c, c); at the outside of the table there should be double lines (||) while single bars should be used within the table (|) horizontal lines: lines 4 and 11 ask for double horizontal lines above an beneath the table; lines 7 and 9 ask for single lines between the internal rows row headings: lines 5–6 specify the first row; its cells are divided by & and the row is finished by \\; the first heading is Statement; the second heading (Conditions) spans two columns cell contents: lines 8 and 10 define the contents of the individual cells (demarcated by &) caption and label: lines 13–14 define the caption and the label for referencing
Table 1 applies too many demarcation lines. This is corrected in Table 2, which shows a simpler and nicer layout. 7.2.2. Special tools Specialised “styles” are useful. For instance, Osborne (2005) has developed sgame.sty for game theorists. Given the basic information about a game of strategy, his style formats the matrix of payoffs as the table-like Figure 10.21 The underlying LATEX code is: 1 2 3 4 5
\begin{game}{2}{3}[Player~1][Player~2] &$L$ &$M$& $R$\\ $T$&$2,2$&$2,0$&$0,3$\\ $B$&$3,0$&$0,9$&$1,1$ \end{game}
The encoding of the game information starts in line 1 by defining the number of rows (2) and columns (3) as well as the names of the players. Line 2 gives the labels of the columns—where & denotes a new column and e.g. $L$ secures mathematical typesetting. Lines 3–4 give both the labels and the contents of the rows. 21 As
usual, you need to browse the manual (Osborne, 2005). In the case of sgame.sty, you also need to give the command \usepackage{color}).
7
25
Graphics, tables, and boxes
Player 1
T B
L 2, 2 3, 0
Player 2 M R 2, 0 0, 3 0, 9 1, 1
Figure 10: A strategic game. Box 7.1: Using text boxes Floating text boxes can be used for several purposes. You may want to present an economic model in condensed form, to present an algorithm, or to include background materials . . . .
7.3. Text boxes Mittelbach and Goossens (2004, 291–95) describes the facilities for defining text boxes provided by the float package. To use it, we may define the following in the preamble: \usepackage{float} \floatstyle{ruled} \newfloat{Box}{htb}{lob} The command \newfloat defines an environment for writing boxes Here is an example, where extra vertical space is added to improve the design. \begin{Box} \caption{Using text boxes} \label{usingboxes} Floating text boxes ... \vspace{2mm} \end{Box} The result of these commands is shown by Box 7.1.22
7.4. Problems of floating Figures, tables, and text boxes represent major layout problems for LATEX documents. If they remain at their natural place in the text (as in Section 7.1.1), the layout is easily disturbed. Therefore, they normally are defined as “floating” items. Thus, when they do not fit the current page, the normal solution is to place them at the top of the next page. However, there might not even be room on that page, and then the predefined LATEX styles place the non-fitting “floats” at the end of the document. This predefined behaviour is not necessarily what you want. For instance, some publishers require that all figures and tables are placed at the end of your manuscript. In contrast, the documents that you yourself prepare for printing need a more careful placement. The solutions are to indicate where to place the floats (if possible) and to increase the part of the page that can be used for floats. The first of the solutions has already been applied in several of the above examples, like Box 7.1. Here the optional specification of possible placements was made in the beginning of the float, like \begin{Box}[htb] (where h = here, t = top, b = bottom, and p = separate page at the end of the document). The sequence in which these specifications are given is their priority. The default is [tbp]. 22 However,
the float package has been slightly redefined, see Andersen (2006b).
8
Bibliography and Index
26
The placement of floats normally obeys a set of rules of their nice appearance. These rules can be changed in two ways. If we add an exclamation mark (like [htp!]), then the rules are suspended. We can also modify the rules explicitly. In the following we set 90% of the page for top floats, non-floats, and bottom floats, while the text only needs to cover 10% of the page: \renewcommand{\floatpagefraction}{.9} \renewcommand{\topfraction}{.9} \renewcommand{\bottomfraction}{.9} \renewcommand{\textfraction}{.1}
8. Bibliography and Index According to the jargon of the publishing business (see Section 3.2) end matter consists of appendices, bibliography, index, etc. We shall only deal with bibliography and index. At the same time we shall consider how they are produced.
8.1. Bibliography generation In Section 3.2 we have already seen how the natbib package and the apa style was included into the LATEX source file. This means that we have prepared ourselves for including a bibliography at the end of the document. But the bibliographical database has to be developed before it can be used (cf. Mittelbach and Goossens, 2004, Ch.12). 8.1.1. The bibliographic database References to different types of publication contain different information. A reference to a journal article might include the volume and number of the journal, which is usually not meaningful for a book. Therefore, database entries of different types have different fields. For instance, we create an entry for a book like AUTHOR Mittelbach, Frank Goossens, Michel YEAR 2004 TITLE The {\LaTeX} Companion CITY Reading, Mass. PUBLISHER Addison-Wesley LABEL Mittelbach2004 In this entry the only special things is that we put the LATEX code for the LaTeX logo in braces and that we have added an identification key (Mittelbach2004). The problem is now to transfer this entry to a format that can be used by the LATEX system. BIBTEX requires us to transform this basic information into the following format: @book{Mittelbach2004, Author = {Mittelbach, F. and Goossens, M.}, Title = {The {\LaTeX} Companion}, Publisher = {Addison-Wesley},
8
27
Bibliography and Index
Figure 11: The JabRef program Address = {Reading, Mass.}, Keywords = {latex}, Year = {2004} } In this bibliographic entry is pretty straightforward except for the first line. Here we define the reference label (Mittelbach2004) and the type of the reference (book). BIBTEX recognises several types, and the types need somewhat different information (see Lamport, 1994, 161– 162). Some confusion may arise in a few cases. An edited book is called book but includes Editor, Title, and BookTitle (where the title is repeated!). A paper in an edited book is called incollection and it includes Year and Pages but no information on the book in which it is contained; this information is found through the Crossref (the label of the edited book). A working paper is called a techreport and needs Institution and Type (e.g. Working Papers). Since a single unmatched brace will cause BIBTEX to stop, you would not like to write such entries by hand. Instead you may use a program like JabRef (see Figure 11). JabRef runs on all platforms and requires Java 1.4 or newer. It can be downloaded from jabref.sourceforge.net/. You will recognise that JabRef is not only an advanced BIBTEX editor. It also includes several useful search functions, the classification of entries, import and export of various formats (including Refer/EndNote), and access to databases on the Internet. However, it works on the basic BIBTEX database that you can also modify by hand or through TEXnicCenter. 8.1.2. Citing of references When we have produced a bibliographic database and called it in the tex document, we can insert simple citations easily. As partly shown in Figure 12, the basic method in TEXnicCenter is: (1) place the insertion point correctly in the text, (2) click the Reference icon in the Navigation Bar, (3) locate the relevant entry, and (4) right-click this reference and select Insert Reference in the small pop-up menu. Thereby we e.g. obtain \cite{Mittelbach2004} that produces Mittelbach and Goossens (2004). The formating of the citation is determined by the fact that we have already called the natbib package that supports the author–year citation style (also called the Harvard style). This system is a pretty fixed standard in make areas of the social sciences—although it can be argued that is clutters the text with additional information and encourages the passive voice and vague writing. However, instead of turning to the numbering system as emphasised in reference number [12] (i.e. the book by Mittelbach and Goossens), we use the facilities of natbib to increase the use of active voice in scientific writing. So we add \usepackage{natbib} to the preamble of our tex document. When TEXnicCenter produces a citation it has the format \cite{Mittelbach2004}. When using natbib, we may modify this form of citation. Some of the possibilities are illustrated by the following example:
8
Bibliography and Index
28
Figure 12: Inserting citations in TEXnicCenter It should be noticed that \citet[Ch.~12]{Mittelbach2004} ... correct \citep[Fig.~12.1]{Mittelbach2004}. ... \citeauthor{Mittelbach2004} ... \citep[see][700--11]{Mittelbach2004}... Here p means that the whole citation should be put in parenthesis while t puts the author in the main text. Furthermore, a single [postinfo] puts postinfo after the citation while a double [preinfo][postinfo] puts preinfo before the citation and postinfo after it. For a correctly installed system, the typeset result is: It should be noticed that Mittelbach and Goossens (2004, Ch. 12) treat BIBTEX systematically. It is especially important to remark the way BIBTEX uses the aux file that is the outcome of an initial run of LATEX. Then you have to run LATEX twice to get the citations correct (Mittelbach and Goossens, 2004, Fig. 12.1). The exposition of Mittelbach and Goossens is also covering several related tools. Thus they cover the natbib package for author–year citations (see Mittelbach and Goossens, 2004, 700–11). If you detect a minor formatting problem that is due to your bib database, you do no not have to switch to JabRef. Instead you locate the reference in TEXnicCenter (as in Figure 11), right click, select Go To, and make the correction when seeing the database entry. Then save the database and compile to see the result (after moving back to your tex file). 8.1.3. Formatting the bibliography There are hundreds of different bibliographical styles for the formatting of the bibliography, and many of them are available for LATEX systems (with the extension bst. These styles are used by BIBTEX, but not all will function together with natbib. Obviously, the bundled styles will work, but they are not optimal. As a starting point, we may instead use the present version of apa.bst from the TEX archives. If you before the end of your document include \bibliographystyle{apa}, you obtain references in the following format: • Goossens, M., Mittelbach, F., and Samarin, A. (1994). The LATEX Companion. Addison– Wesley, Reading, Mass.
8.2. Index generation To make an index23 we first give the \makeindex command and indicate where the index is to be placed with \printindex (see Section 3.3). Then we go through the document and 23 See
Lamport (1994, App. A) and Mittelbach and Goossens (2004, Ch. 11).
9
Customising LATEX
29
place \index{...} commands where it is relevant. For instance, we may want to make an entry telling that the present section is about indexing. We may write \index{indexing}, but we can also make a hierarchical index by writing \index{indexing!entries}. Normally we can also include special characters in index commands. For instance, we may write \index{indexing!\textbackslash index}. The specialised programs that support indexing will not be covered in the present article. It might, however, be relevant to mention the indexing provided by the natbib package. To obtain an index of citations like in the present article (the first part of the Index), simply write \citeindextrue before starting the main matter of your document. (If you do not want the back matter included, write \citeindexfalse before that part.) Furthermore, like in the present article (see page ??), you can in the bibliography obtain links to the places in which the individual items are cited by giving an argument to natbib in the preamble of your document (\usepackage[pagebackref]{natbib}).
9. Customising LATEX 9.1. New and modified commands In LATEX it is easy to define commands (see Grätzer, 1996, Ch. 9). A command must be defined before it is used, but it does not matter whether the definition is made in a LATEX package, in the preamble of the document or in the main matter of the document. To define a command we just write \newcommand{\NAME}{ACTION}. Whenever the command is invoked by \NAME, the ACTION is performed. This facility can be used in several ways: Shorthand: the ACTION part of the definition may be the expansion of an abbreviation; if the definition is \newcommand{\nw}{Nelson \&\ Winter}, \nw is substituted by Nelson \&\ Winter and is thus printed as Nelson & Winter Consistency: if we change ACTION, we are sure that it is done consistently throughout the document; for instance we can change from “&” to “and” in Nelson and Winter Index entries: if we want all occurrences of \nw to be recorded in the index, we can expand the ACTION part of the definition; for instance we can write \newcommand{\nw}{Nelson \&\ Winter. Renewed commands: if we try to define a command that has been defined before—e.g. in a LATEX package—we will get an error message. Often we are committing a real error, but we may also try to redefine a command. In this case we should write \renewcommand{\NAME}{ACTION}. For instance, there is a set of LATEX commands that define the names of different document components. This system allows us to redefine name of the section References to Bibliography by \renewcommand{\refname}{Bibliography}.24
9.2. Making your own packages As the stock of customised commands accumulates, it is helpful to distinguish between specialised and generic commands. The former type belongs to the individual documents while generic commands should be placed in one or more packages which are saved in the directory TeX-inputs and are loaded by the preamble command \usepackage{MYPACKAGE.sty} 24 Another example of renewed commands is found in the listing in Section 3.1. Here we in line 31 remove the indent of the bibliography—to make the style fit for two-column printing.
10
Printing and distribution
30
10. Printing and distribution 10.1. Output files and hyperref There are many ways of distributing your LATEX output (see Goossens et al., 1997; Goossens and Rahtz, 1999). tex: the source file gives the full information about your document but it is dependent on styles, bibliographies, etc., which may be idiosyncratic to your LATEX system; therefore, you have to consider carefully the simplest possible set of files that can be handled by friends or publishers with their own LATEX systems and formatting preferences dvi and ps: the first is well-suited for receivers who have a viewer included in their own LATEX systems; the latter is for printing and viewing by all technically oriented users pdf: the pdf file is most adequate for web publishing since it can be inspected before printing by nearly all receivers (by means of Acrobat Reader) Since the pdf format has a diverse set of users that largely perform at least a preliminary inspection on their computer screen, the precise functioning of the document is worth quite some considerations. The attempts of improving the web document are rather well supported by the hyperref package. This package is described in Goossens and Rahtz (1999) and at www.tug.org/applications/hyperref/manual.html. When you insert a call of hyperref in the preamble of your tex document, many of its items are immediately made into internal links. This covers the table of contents, figures and tables, citations of the bibliography, and footnotes. Thereby, the user can jump between the different parts of the text (like in the present article).25 Furthermore, you can easily ad both internal and external links. Like LATEX cross references, the internal hypertext links consist of a label and one or more references. The label is created by placing the command \hypertarget{REFNAME}{ATEXT}; links to this target has the format \hyperlink{REFNAME}{BTEXT}. Thus, ATEXT is the target linked to by BTEXT. In the case of external links, the label is an address on the Internet. If you want the user to see the full URL, the link text is identical to the link and your can use the form \url{http://www.tug.org/} (http://www.tug.org/). Otherwise, you can write \href{http://www.tug.org/}{TUG website} (TUG website). The formatting of links are determined by a large number of options. Since the default settings look strange for many users, the present article has (among other hyperref options) defined the following in the preamble: \usepackage{hyperref} \hypersetup{colorlinks=true, pdfpagemode=UseOutlines, pdfstartview=FitH, linkcolor=blue} \usepackage{url} \usepackage{hypcap}
10.2. Getting LATEX packages, etc. Many of the facilities described in this article presupposes that different LATEX packages are available in the correct directory. This placing is easy if you use automatically updating LATEX distributions like the one described in Section 2.3. However, you might also want to inspect the documentation and download the needed files from the Comprehensive TeX Archive Network (CTAN)—which is a set of fully-mirrored ftp sites providing the most complete, up-to-date TEXrelated software possible. 25 The
hyperref package does not support the use of endnotes—so there are no links to the endnotes.
References
31
The problem of getting LATEX packages is covered by Grätzer (1996, App. G) and Mittelbach and Goossens (2004, App. C). A Danish mirror of CTAN is found at Dotsrc.org (formerly SunSITE.dk) at Aalborg University. The web address is ftp.sunsite.dk/pub/tex/ctan/. A searchable version of CTAN is found at tug.ctan.org/search.html. However, it is easier to access a CTAN database through MikTEX (see Section 2.3). If you are looking for a template for a particular document type (e.g. curriculum vitae), open MikTEX Package Manager in MS Windows (Start/All Programs/MikTeX/MikTeX Package Manager), write “curriculum” in one of the search fields, and inspect the results. If a + is given, it means that the package/template is not already installed. Doubleclick the file and find a location that is recognised by TEXnicCenter.26
11. Conclusions This article has shown some of the possibilities of LATEX systems. It is obvious that we are facing a very strong type of typesetting system which has evolved through the voluntary effort of a large number of members of the LATEX community. Still, many researchers are quite reluctant to move from the apparent ease of the WYSIWYG systems. There are some merits to their arguments. Unless you really master the LATEX system—and that might for some researchers take several months, it can be pretty frustrating. A single error in a source file or a single missing element in the large and complex LATEX system can hinder any output. The full potential of the system can only be exploited in a local LATEX community.
References Andersen, E. S. (1994), Evolutionary Economics: Post-Schumpeterian Contributions, Pinter, London. 2 Andersen, E. S. (1997), Elements of LATEX systems, Working Paper, Department of Business Studies, Aalborg University. 2 Andersen, E. S. (2006a), Elements of the LATEX system for the development of large publications, Working Paper, Department of Business Studies, Aalborg University. www.business.aau.dk/evolution/esapapers/esa06/MyLaTeX.pdf 3 Andersen, E. S. (2006b), The evolution and use of a personal LATEX metapackage, Working Paper, Department of Business Studies, Aalborg University. www.business.aau.dk/evolution/esapapers/esa06/esameta.pdf 1, 2, 25 Andersen, E. S. (2006c), The evolution and use of a personal LATEX metapackage: Appendix on postscript graphics, Working Paper, Department of Business Studies, Aalborg University. www.business.aau.dk/evolution/esapapers/esa06/esametagraph.pdf 1, 3 Goossens, M., Mittelbach, F. and Samarin, A. (1994), The LATEX Companion, Addison–Wesley, Reading, Mass. 3 Goossens, M. and Rahtz, S. (1999), The LATEX Web Companion: Integrating TEX, HTML, and XML, Addison–Wesley, Reading, Mass. 30 Goossens, M., Rahtz, S. and Mittelbach, F. (1997), The LATEX Graphics Companion: Illustrating Documents with TEX and PostScript, Addison–Wesley, Reading, Mass. 21, 30 Grätzer, G. (1996), Math into LATEX: An Introduction to LATEX and AMS -LATEX, Birkhäuser, Boston. 2, 3, 17, 19, 20, 29, 31 Knuth, D. E. (1990), The TEX Book, Computers and Typesetting, Vol A, 2nd edn, Addison– Wesley, Reading, Mass. 3 Knuth, D. E. (1997), The Art of Computer Programming, 3 vols, 2nd–3rd edn, Addison–Wesley, Reading, Mass. 3 Kopka, H. and Daly, P. W. (2004), Guide to LATEX, 4th edn, Addison–Wesley, Boston, Mass. 2, 3, 13, 17 26 In
TEXnicCenter, templates are placed in ...\TeXnicCenter\Template\Projects.
References
32
Lamport, L. (1994), LATEX: A Document Preparation System, 2nd edn, Addison–Wesley, Reading, Mass. 2, 3, 7, 13, 17, 21, 27, 28 Mittelbach, F. and Goossens, M. (2004), The LATEX Companion, 2nd edn, Addison–Wesley, Boston, Mass. 2, 3, 4, 5, 6, 12, 15, 16, 17, 21, 22, 23, 25, 26, 27, 28, 31 Oetiker, T., Partl, H., Hyna, I. and Schlegl, E. (2006), The Not So Short Introduction to LATEX 2ε , 4.20 edn, Web document. 2 Oostrum, P. v. (2004), Page layout in LATEX, Web Document, Utrecht University. 12 Osborne, M. J. (2005), Manual for sgame.sty and sgamevar.sty, University of Toronto, Web document, Version 2.13. www.ctan.org/tex-archive/macros/latex/contrib/sgame/ 24 Wiki Books (2006), LaTeX, Wikibooks, the open-content textbooks collection, Web documents. http://en.wikibooks.org/wiki/LaTeX 2