Newfaq
Newfaq
N OTE
This document is an updated and extended version of the FAQ article that was
published as the December 1994 and 1995, and March 1999 editions of the UK TUG
magazine Baskerville (which weren’t formatted like this).
The article is also available via the World Wide Web.
Contents
Introduction 10
Licence of the FAQ 10
Finding the Files 10
A The Background 11
1 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2 What is TeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3 What’s “writing in TeX”? . . . . . . . . . . . . . . . . . . . . . . . 12
4 How should I pronounce “TeX”? . . . . . . . . . . . . . . . . . . . 12
5 What is Metafont? . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
6 What is Metapost? . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7 Things with “TeX” in the name . . . . . . . . . . . . . . . . . . . . 13
8 What is CTAN? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
9 The (CTAN) catalogue . . . . . . . . . . . . . . . . . . . . . . . . . 15
10 How can I be sure it’s really TeX? . . . . . . . . . . . . . . . . . . . 15
11 What is e-TeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
12 What is PDFTeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
13 What is LaTeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
14 What is LaTeX2e? . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
15 How should I pronounce “LaTeX(2e)”? . . . . . . . . . . . . . . . . . 17
16 Should I use Plain TeX or LaTeX? . . . . . . . . . . . . . . . . . . . 17
17 How does LaTeX relate to Plain TeX? . . . . . . . . . . . . . . . . . 17
18 What is ConTeXt? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
19 What are the AMS packages (AMSTeX, etc.)? . . . . . . . . . . . . 18
20 What is Eplain? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
21 What is Texinfo? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
22 Lollipop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
23 If TeX is so good, how come it’s free? . . . . . . . . . . . . . . . . 19
24 What is the future of TeX? . . . . . . . . . . . . . . . . . . . . . . . 19
25 Reading (La)TeX files . . . . . . . . . . . . . . . . . . . . . . . . . 19
26 Why is TeX not a WYSIWYG system? . . . . . . . . . . . . . . . . . 20
27 TeX User Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
B Documentation and Help 21
28 Books relevant to TeX and friends . . . . . . . . . . . . . . . . . . . . 21
29 Books on TeX, Plain TeX and relations . . . . . . . . . . . . . . . . . 21
30 Books on LaTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
31 Books on other TeX-related matters . . . . . . . . . . . . . . . . . . 23
32 Books on Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
33 Where to find FAQs . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1
34 Getting help online . . . . . . . . . . . . . . . . . . . . . . . . . . 24
35 Specialist mailing lists . . . . . . . . . . . . . . . . . . . . . . . . . 25
36 How to ask a question . . . . . . . . . . . . . . . . . . . . . . . . . 25
37 How to make a “minimum example” . . . . . . . . . . . . . . . . . 26
38 Tutorials, etc., for TeX-based systems . . . . . . . . . . . . . . . . . . 27
39 Online introductions: Plain TeX . . . . . . . . . . . . . . . . . . . . . 27
40 Online introductions: LaTeX . . . . . . . . . . . . . . . . . . . . . . 27
41 (La)TeX tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
42 Reference documents . . . . . . . . . . . . . . . . . . . . . . . . . 29
43 WIKI books for TeX and friends . . . . . . . . . . . . . . . . . . . 29
44 Typography tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . 29
45 Freely available (La)TeX books . . . . . . . . . . . . . . . . . . . . 30
46 Documentation of packages . . . . . . . . . . . . . . . . . . . . . . 30
47 Learning to write LaTeX classes and packages . . . . . . . . . . . . . 31
48 LaTeX3 programming . . . . . . . . . . . . . . . . . . . . . . . . . . 31
49 Metafont and Metapost Tutorials . . . . . . . . . . . . . . . . . . . 32
50 BibTeX Documentation . . . . . . . . . . . . . . . . . . . . . . . . 32
51 Where can I find the symbol for . . . . . . . . . . . . . . . . . . . . . 32
52 The PiCTeX manual . . . . . . . . . . . . . . . . . . . . . . . . . . 33
C Bits and pieces of (La)TeX 33
53 What is a DVI file? . . . . . . . . . . . . . . . . . . . . . . . . . . 33
54 What is a DVI driver? . . . . . . . . . . . . . . . . . . . . . . . . . 33
55 What are PK files? . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
56 What are TFM files? . . . . . . . . . . . . . . . . . . . . . . . . . . 34
57 What are virtual fonts? . . . . . . . . . . . . . . . . . . . . . . . . . 34
58 What are (TeX) macros . . . . . . . . . . . . . . . . . . . . . . . . 35
59 \special commands . . . . . . . . . . . . . . . . . . . . . . . . . 35
60 Writing (text) files from TeX . . . . . . . . . . . . . . . . . . . . . 36
61 Spawning programs from (La)TeX: \write18 . . . . . . . . . . . . 36
62 How does hyphenation work in TeX? . . . . . . . . . . . . . . . . . . 37
63 What are LaTeX classes and packages? . . . . . . . . . . . . . . . . . 37
64 What are LaTeX “environments” . . . . . . . . . . . . . . . . . . . 38
65 Documented LaTeX sources (.dtx files) . . . . . . . . . . . . . . . 38
66 What are encodings? . . . . . . . . . . . . . . . . . . . . . . . . . . 39
67 What are the EC fonts? . . . . . . . . . . . . . . . . . . . . . . . . 40
68 Unicode and TeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
69 What is the TDS? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
70 What is “Encapsulated PostScript” (“EPS”)? . . . . . . . . . . . . . . 41
71 Adobe font formats . . . . . . . . . . . . . . . . . . . . . . . . . . 42
72 What are “resolutions”? . . . . . . . . . . . . . . . . . . . . . . . . 42
73 What is the “Berry naming scheme”? . . . . . . . . . . . . . . . . . 43
D Acquiring the Software 43
74 Repositories of TeX material . . . . . . . . . . . . . . . . . . . . . 43
75 Ready-built installation files on the archive . . . . . . . . . . . . . . 44
76 What was the CTAN nonfree tree? . . . . . . . . . . . . . . . . . . 44
77 Contributing a file to the archives . . . . . . . . . . . . . . . . . . . 44
78 Finding (La)TeX files . . . . . . . . . . . . . . . . . . . . . . . . . 45
79 Finding new fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
80 The TeX collection . . . . . . . . . . . . . . . . . . . . . . . . . . 46
E TeX Systems 47
81 (La)TeX for different machines . . . . . . . . . . . . . . . . . . . . . 47
82 Unix and GNU Linux systems . . . . . . . . . . . . . . . . . . . . . . 47
83 (Modern) Windows systems . . . . . . . . . . . . . . . . . . . . . . . 47
84 Macintosh systems . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
85 Other systems’ TeX availability . . . . . . . . . . . . . . . . . . . . 48
86 TeX-friendly editors and shells . . . . . . . . . . . . . . . . . . . . 49
87 Commercial TeX implementations . . . . . . . . . . . . . . . . . . 50
2
F DVI Drivers and Previewers 51
88 DVI to PostScript conversion programs . . . . . . . . . . . . . . . . . 51
89 DVI drivers for HP LaserJet . . . . . . . . . . . . . . . . . . . . . . . 51
90 Output to “other” printers . . . . . . . . . . . . . . . . . . . . . . . . 51
91 DVI previewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
92 Generating bitmaps from DVI . . . . . . . . . . . . . . . . . . . . . . 51
G Support Packages for TeX 52
93 (La)TeX-friendly drawing packages . . . . . . . . . . . . . . . . . . 52
94 TeXCAD, a drawing package for LaTeX . . . . . . . . . . . . . . . 52
95 Spelling checkers for work with TeX . . . . . . . . . . . . . . . . . 52
96 How many words have you written? . . . . . . . . . . . . . . . . . . 53
H Literate programming 54
97 What is Literate Programming? . . . . . . . . . . . . . . . . . . . . 54
98 WEB systems for various languages . . . . . . . . . . . . . . . . . 54
I Format conversions 54
99 Conversion from (La)TeX to plain text . . . . . . . . . . . . . . . . 54
100 Conversion from SGML or HTML to TeX . . . . . . . . . . . . . . 55
101 Conversion from (La)TeX to HTML . . . . . . . . . . . . . . . . . 55
102 Other conversions to and from (La)TeX . . . . . . . . . . . . . . . . 56
103 Using TeX to read SGML or XML directly . . . . . . . . . . . . . . . 57
104 Retrieving (La)TeX from DVI, etc. . . . . . . . . . . . . . . . . . . 58
105 Translating LaTeX to Plain TeX . . . . . . . . . . . . . . . . . . . . 58
J Installing (La)TeX files 58
106 Installing things on a (La)TeX system . . . . . . . . . . . . . . . . . 58
107 Finding packages to install . . . . . . . . . . . . . . . . . . . . . . 59
108 Unpacking LaTeX packages . . . . . . . . . . . . . . . . . . . . . . 59
109 Generating package documentation . . . . . . . . . . . . . . . . . . 59
110 Installing files “where (La)TeX can find them” . . . . . . . . . . . . 60
111 Which tree to use . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
112 Where to install packages . . . . . . . . . . . . . . . . . . . . . . . . 61
113 Tidying up after installation . . . . . . . . . . . . . . . . . . . . . . . 61
114 Shortcuts to installing files . . . . . . . . . . . . . . . . . . . . . . . 62
115 Installation using MiKTeX package manager . . . . . . . . . . . . . 62
116 Installation using TeX Live manager . . . . . . . . . . . . . . . . . 62
117 Installing using ready-built ZIP files . . . . . . . . . . . . . . . . . 62
118 “Temporary” installation of (La)TeX files . . . . . . . . . . . . . . . 63
119 “Private” installations of files . . . . . . . . . . . . . . . . . . . . . 63
120 Installing a new font . . . . . . . . . . . . . . . . . . . . . . . . . . 64
121 Installing a font provided as Metafont source . . . . . . . . . . . . . 64
122 ‘Installing’ a PostScript printer built-in font . . . . . . . . . . . . . 65
123 Preparing a Type 1 font . . . . . . . . . . . . . . . . . . . . . . . . 65
124 Installing a Type 1 font . . . . . . . . . . . . . . . . . . . . . . . . 66
125 Installing the Type 1 versions of the CM fonts . . . . . . . . . . . . 66
K Fonts 67
K.1 Adobe Type 1 (“PostScript”) fonts 67
126 Using Adobe Type 1 fonts with TeX . . . . . . . . . . . . . . . . . . 67
127 Previewing files using Type 1 fonts . . . . . . . . . . . . . . . . . . . 67
128 TeX font metric files for Type 1 fonts . . . . . . . . . . . . . . . . . . 67
129 Deploying Type 1 fonts . . . . . . . . . . . . . . . . . . . . . . . . 68
130 Choice of Type 1 fonts for typesetting Maths . . . . . . . . . . . . . 68
131 Unicode Maths using OpenType fonts . . . . . . . . . . . . . . . . . 74
132 Weird characters in dvips output . . . . . . . . . . . . . . . . . . . . 74
K.2 Macros for using fonts 74
133 Using non-standard fonts in Plain TeX . . . . . . . . . . . . . . . . 74
K.3 Particular font families 75
134 Using the “Concrete” fonts . . . . . . . . . . . . . . . . . . . . . . 75
135 Using the Latin Modern fonts . . . . . . . . . . . . . . . . . . . . . 76
136 Getting ‘free’ fonts not in your distribution . . . . . . . . . . . . . . . 77
3
K.4 Metafont fonts 77
137 Getting Metafont to do what you want . . . . . . . . . . . . . . . . . 77
138 Which font files should be kept . . . . . . . . . . . . . . . . . . . . 78
139 Acquiring bitmap fonts . . . . . . . . . . . . . . . . . . . . . . . . 78
L Hypertext and PDF 79
140 Making PDF documents from (La)TeX . . . . . . . . . . . . . . . . 79
141 Making hypertext documents from TeX . . . . . . . . . . . . . . . . 80
142 The hyperTeX project . . . . . . . . . . . . . . . . . . . . . . . . . 80
143 Quality of PDF from PostScript . . . . . . . . . . . . . . . . . . . . 80
144 The wrong type of fonts in PDF . . . . . . . . . . . . . . . . . . . . . 81
145 Fuzzy fonts because Ghostscript too old . . . . . . . . . . . . . . . . 81
146 Fonts go fuzzy when you switch to T1 . . . . . . . . . . . . . . . . . 81
147 Characters missing from PDF output . . . . . . . . . . . . . . . . . 82
148 Finding ‘8-bit’ Type 1 fonts . . . . . . . . . . . . . . . . . . . . . . 82
149 Replacing Type 3 fonts in PostScript . . . . . . . . . . . . . . . . . 83
150 Hyperref and repeated page numbers . . . . . . . . . . . . . . . . . 83
151 Copy-paste-able/searchable PDF files . . . . . . . . . . . . . . . . . 84
M Graphics 84
152 Importing graphics into (La)TeX documents . . . . . . . . . . . . . 84
153 Imported graphics in dvips . . . . . . . . . . . . . . . . . . . . . . . 85
154 Imported graphics in PDFLaTeX . . . . . . . . . . . . . . . . . . . 86
155 Imported graphics in dvipdfm . . . . . . . . . . . . . . . . . . . . . . 87
156 “Modern” graphics file names . . . . . . . . . . . . . . . . . . . . . . 87
157 Importing graphics from “somewhere else” . . . . . . . . . . . . . . 88
158 Portable imported graphics . . . . . . . . . . . . . . . . . . . . . . 88
159 Repeated graphics in a document . . . . . . . . . . . . . . . . . . . 89
160 Limit the width of imported graphics . . . . . . . . . . . . . . . . . 89
161 Top-aligning imported graphics . . . . . . . . . . . . . . . . . . . . 89
162 Displaying Metapost output in ghostscript . . . . . . . . . . . . . . 90
163 Drawing with TeX . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
164 In-line source for graphics applications . . . . . . . . . . . . . . . . 92
165 Drawing Feynman diagrams in LaTeX . . . . . . . . . . . . . . . . 92
166 Labelling graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
N Bibliographies and citations 94
N.1 Creating bibliographies 94
167 Creating a BibTeX bibliography file . . . . . . . . . . . . . . . . . . 94
168 Creating a bibliography style . . . . . . . . . . . . . . . . . . . . . 95
169 Capitalisation in BibTeX . . . . . . . . . . . . . . . . . . . . . . . 95
170 Accents in bibliographies . . . . . . . . . . . . . . . . . . . . . . . 95
171 ‘String too long’ in BibTeX . . . . . . . . . . . . . . . . . . . . . . 96
172 BibTeX doesn’t understand lists of names . . . . . . . . . . . . . . 96
173 URLs in BibTeX bibliographies . . . . . . . . . . . . . . . . . . . . 96
174 Using BibTeX with Plain TeX . . . . . . . . . . . . . . . . . . . . . . 97
175 Reconstructing .bib files . . . . . . . . . . . . . . . . . . . . . . . . 97
176 BibTeX sorting and name prefixes . . . . . . . . . . . . . . . . . . . . 97
177 ‘Multi-letter’ initials in BibTeX . . . . . . . . . . . . . . . . . . . . 98
N.2 Creating citations 99
178 “Normal” use of BibTeX from LaTeX . . . . . . . . . . . . . . . . 99
179 Choosing a bibliography style . . . . . . . . . . . . . . . . . . . . . 99
180 Separate bibliographies per chapter? . . . . . . . . . . . . . . . . . 100
181 Multiple bibliographies? . . . . . . . . . . . . . . . . . . . . . . . . 100
182 Putting bibliography entries in text . . . . . . . . . . . . . . . . . . . 101
183 Sorting and compressing citations . . . . . . . . . . . . . . . . . . . 102
184 Multiple citations . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
185 References from the bibliography to the citation . . . . . . . . . . . 103
186 Sorting lists of citations . . . . . . . . . . . . . . . . . . . . . . . . 103
187 Reducing spacing in the bibliography . . . . . . . . . . . . . . . . . 103
188 Table of contents rearranges “unsrt” ordering . . . . . . . . . . . . . 104
189 Non-english bibliographies . . . . . . . . . . . . . . . . . . . . . . 104
190 Format of numbers in the bibliography . . . . . . . . . . . . . . . . 105
4
N.3 Manipulating whole bibliographies 105
191 Listing all your BibTeX entries . . . . . . . . . . . . . . . . . . . . 105
192 Making HTML of your Bibliography . . . . . . . . . . . . . . . . . 105
O Adjusting the typesetting 105
O.1 Alternative document classes 105
193 Replacing the standard classes . . . . . . . . . . . . . . . . . . . . . 105
194 Producing presentations (including slides) . . . . . . . . . . . . . . 106
195 Creating posters with LaTeX . . . . . . . . . . . . . . . . . . . . . . 107
196 Formatting a thesis in LaTeX . . . . . . . . . . . . . . . . . . . . . 108
197 Setting papers for journals . . . . . . . . . . . . . . . . . . . . . . . 108
198 A ‘report’ from lots of ‘article’s . . . . . . . . . . . . . . . . . . . . 108
199 Curriculum Vitae (Résumé) . . . . . . . . . . . . . . . . . . . . . . 110
200 Letters and the like . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
201 Other “document font” sizes? . . . . . . . . . . . . . . . . . . . . . . 111
O.2 Document structure 111
202 The style of document titles . . . . . . . . . . . . . . . . . . . . . . . 111
203 The style of section headings . . . . . . . . . . . . . . . . . . . . . 112
204 Appendixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
205 Indent after section headings . . . . . . . . . . . . . . . . . . . . . 113
206 How to create a \subsubsubsection . . . . . . . . . . . . . . . . . 113
207 The style of captions . . . . . . . . . . . . . . . . . . . . . . . . . . 114
208 Alternative head- and footlines in LaTeX . . . . . . . . . . . . . . . 114
209 Wide figures in two-column documents . . . . . . . . . . . . . . . . 115
210 1-column abstract in 2-column document . . . . . . . . . . . . . . . 115
211 Really blank pages between chapters . . . . . . . . . . . . . . . . . 115
212 Balancing columns at the end of a document . . . . . . . . . . . . . 116
213 My section title is too wide for the page header . . . . . . . . . . . . 116
214 Page numbering “hni of hmi” . . . . . . . . . . . . . . . . . . . . . . 117
215 Page numbering by chapter . . . . . . . . . . . . . . . . . . . . . . 118
O.3 Page layout 118
216 The size of printed output . . . . . . . . . . . . . . . . . . . . . . . 118
217 Adobe Reader messing with print size . . . . . . . . . . . . . . . . 118
218 Getting the right paper geometry from (La)TeX . . . . . . . . . . . 118
219 Changing the margins in LaTeX . . . . . . . . . . . . . . . . . . . . 119
220 Packages to set up page designs . . . . . . . . . . . . . . . . . . . . 120
221 How to set up page layout “by hand” . . . . . . . . . . . . . . . . . 120
222 Changing margins “on the fly” . . . . . . . . . . . . . . . . . . . . . 121
223 How to get rid of page numbers . . . . . . . . . . . . . . . . . . . . . 121
224 How to create crop marks . . . . . . . . . . . . . . . . . . . . . . . 122
225 ‘Watermarks’ on every page . . . . . . . . . . . . . . . . . . . . . . 122
226 Typesetting things in landscape orientation . . . . . . . . . . . . . . 123
227 Putting things at fixed positions on the page . . . . . . . . . . . . . 124
228 Preventing page breaks between lines . . . . . . . . . . . . . . . . . 124
229 Parallel setting of text . . . . . . . . . . . . . . . . . . . . . . . . . 125
230 Typesetting epigraphs . . . . . . . . . . . . . . . . . . . . . . . . . 126
O.4 Spacing of characters and lines 127
231 Double-spaced documents in LaTeX . . . . . . . . . . . . . . . . . . 127
232 Changing the space between letters . . . . . . . . . . . . . . . . . . . 127
233 Setting text ragged right . . . . . . . . . . . . . . . . . . . . . . . . . 127
234 Cancelling \ragged commands . . . . . . . . . . . . . . . . . . . . 128
O.5 Typesetting specialities 128
235 Including a file verbatim in LaTeX . . . . . . . . . . . . . . . . . . 128
236 Including line numbers in typeset output . . . . . . . . . . . . . . . 129
237 Code listings in LaTeX . . . . . . . . . . . . . . . . . . . . . . . . 129
238 Typesetting pseudocode in LaTeX . . . . . . . . . . . . . . . . . . . 130
239 Generating an index in (La)TeX . . . . . . . . . . . . . . . . . . . . . 131
240 Typesetting URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
241 Typesetting music in TeX . . . . . . . . . . . . . . . . . . . . . . . 132
242 Zero paragraph indent . . . . . . . . . . . . . . . . . . . . . . . . . 133
243 Big letters at the start of a paragraph . . . . . . . . . . . . . . . . . 134
244 The comma as a decimal separator . . . . . . . . . . . . . . . . . . 134
5
245 Breaking boxes of text . . . . . . . . . . . . . . . . . . . . . . . . . 134
246 Overstriking characters . . . . . . . . . . . . . . . . . . . . . . . . 135
247 Realistic quotes for verbatim listings . . . . . . . . . . . . . . . . . 135
248 Printing the time . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
249 Redefining counters’ \the-commands . . . . . . . . . . . . . . . . 136
O.6 Tables of contents and indexes 136
250 The format of the Table of Contents, etc. . . . . . . . . . . . . . . . 136
251 Unnumbered sections in the Table of Contents . . . . . . . . . . . . 136
252 Bibliography, index, etc., in TOC . . . . . . . . . . . . . . . . . . . . 137
253 Table of contents, etc., per chapter . . . . . . . . . . . . . . . . . . . 137
254 Multiple indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
O.7 Labels and references 139
255 Referring to things by their name . . . . . . . . . . . . . . . . . . . 139
256 Referring to labels in other documents . . . . . . . . . . . . . . . . 140
P How do I do. . . ? 140
P.1 Mathematics 140
257 Proof environment . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
258 Theorem bodies printed in a roman font . . . . . . . . . . . . . . . . . 141
259 Defining a new log-like function in LaTeX . . . . . . . . . . . . . . . 141
260 Set specifications and Dirac brackets . . . . . . . . . . . . . . . . . . 141
261 Cancelling terms in maths expressions . . . . . . . . . . . . . . . . 142
262 Adjusting maths font sizes . . . . . . . . . . . . . . . . . . . . . . . 142
263 Ellipses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
264 Sub- and superscript positioning for operators . . . . . . . . . . . . 143
265 Text inside maths . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
266 Re-using an equation . . . . . . . . . . . . . . . . . . . . . . . . . 144
267 Line-breaking in in-line maths . . . . . . . . . . . . . . . . . . . . . 144
268 Numbers for referenced equations only . . . . . . . . . . . . . . . . 145
269 Even subscript height . . . . . . . . . . . . . . . . . . . . . . . . . 145
P.2 Lists 145
270 Fancy enumeration lists . . . . . . . . . . . . . . . . . . . . . . . . 145
271 How to adjust list spacing . . . . . . . . . . . . . . . . . . . . . . . 146
272 Interrupting enumerated lists . . . . . . . . . . . . . . . . . . . . . . 147
P.3 Tables, figures and diagrams 148
273 The design of tables . . . . . . . . . . . . . . . . . . . . . . . . . . 148
274 Fixed-width tables . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
275 Variable-width columns in tables . . . . . . . . . . . . . . . . . . . 149
276 Spacing lines in tables . . . . . . . . . . . . . . . . . . . . . . . . . 150
277 Tables longer than a single page . . . . . . . . . . . . . . . . . . . . . 151
278 How to alter the alignment of tabular cells . . . . . . . . . . . . . . 152
279 The thickness of rules in LaTeX tables . . . . . . . . . . . . . . . . 152
280 Flowing text around figures . . . . . . . . . . . . . . . . . . . . . . 153
281 Diagonal separation in corner cells of tables . . . . . . . . . . . . . 154
282 How to change a whole row of a table . . . . . . . . . . . . . . . . . 154
283 Merging cells in a column of a table . . . . . . . . . . . . . . . . . 154
P.4 Floating tables, figures, etc. 155
284 Floats on their own on float pages . . . . . . . . . . . . . . . . . . . 155
285 Centring a very wide figure or table . . . . . . . . . . . . . . . . . . 155
286 Placing two-column floats at bottom of page . . . . . . . . . . . . . 156
287 Floats in multicolumn setting . . . . . . . . . . . . . . . . . . . . . 156
288 Facing floats on 2-page spread . . . . . . . . . . . . . . . . . . . . 156
289 Vertical layout of float pages . . . . . . . . . . . . . . . . . . . . . . 157
290 Figure (or table) exactly where I want it . . . . . . . . . . . . . . . . . 157
P.5 Footnotes 158
291 Footnotes in tables . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
292 Footnotes in LaTeX section headings . . . . . . . . . . . . . . . . . 159
293 Footnotes in captions . . . . . . . . . . . . . . . . . . . . . . . . . 159
294 Footnotes whose texts are identical . . . . . . . . . . . . . . . . . . 160
295 More than one sequence of footnotes . . . . . . . . . . . . . . . . . 160
296 Footnotes numbered “per page” . . . . . . . . . . . . . . . . . . . . . 161
297 Not resetting footnote numbers per chapter . . . . . . . . . . . . . . . 161
6
P.6 Document management 161
298 What’s the name of this file . . . . . . . . . . . . . . . . . . . . . . . 161
299 All the files used by this document . . . . . . . . . . . . . . . . . . 162
300 Marking changed parts of your document . . . . . . . . . . . . . . . 162
301 Conditional compilation and “comments” . . . . . . . . . . . . . . . 163
302 Bits of document from other directories . . . . . . . . . . . . . . . . 165
303 Version control using RCS, CVS or the like . . . . . . . . . . . . . . 166
304 Makefiles for LaTeX documents . . . . . . . . . . . . . . . . . . . . . 167
305 How many pages are there in my document? . . . . . . . . . . . . . . 167
306 Including Plain TeX files in LaTeX . . . . . . . . . . . . . . . . . . 168
P.7 Hyphenation 168
307 My words aren’t being hyphenated . . . . . . . . . . . . . . . . . . 168
308 Weird hyphenation of words . . . . . . . . . . . . . . . . . . . . . . 169
309 (Merely) peculiar hyphenation . . . . . . . . . . . . . . . . . . . . 169
310 Accented words aren’t hyphenated . . . . . . . . . . . . . . . . . . 169
311 Using a new language with Babel . . . . . . . . . . . . . . . . . . . 169
312 Stopping all hyphenation . . . . . . . . . . . . . . . . . . . . . . . 170
313 Preventing hyphenation of a particular word . . . . . . . . . . . . . . 171
314 Hyphenation exceptions . . . . . . . . . . . . . . . . . . . . . . . . 172
P.8 Odds and ends 172
315 Typesetting all those TeX-related logos . . . . . . . . . . . . . . . . 172
316 How to do bold-tt or bold-sc . . . . . . . . . . . . . . . . . . . . . . 173
317 Automatic sizing of minipage . . . . . . . . . . . . . . . . . . . . 173
Q Symbols, etc. 174
318 Using symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
319 Symbols for the number sets . . . . . . . . . . . . . . . . . . . . . . 174
320 Better script fonts for maths . . . . . . . . . . . . . . . . . . . . . . 175
321 Setting bold Greek letters in LaTeX maths . . . . . . . . . . . . . . 176
322 The Principal Value Integral symbol . . . . . . . . . . . . . . . . . . 177
323 How to typeset an underscore character . . . . . . . . . . . . . . . . . 177
324 How to type an ‘@’ sign? . . . . . . . . . . . . . . . . . . . . . . . . 177
325 Typesetting the Euro sign . . . . . . . . . . . . . . . . . . . . . . . . 177
326 How to get copyright, trademark, etc. . . . . . . . . . . . . . . . . . 178
327 Using “old-style” figures . . . . . . . . . . . . . . . . . . . . . . . 179
R Macro programming 179
R.1 “Generic” macros and techniques 179
328 Non-letters in macro names . . . . . . . . . . . . . . . . . . . . . . 179
329 Repeating a command n times . . . . . . . . . . . . . . . . . . . . . 180
330 Repeating something for each ‘thing’ in a set . . . . . . . . . . . . . 182
331 Finding the width of a letter, word, or phrase . . . . . . . . . . . . . 182
332 Patching existing commands . . . . . . . . . . . . . . . . . . . . . 182
333 Comparing the “job name” . . . . . . . . . . . . . . . . . . . . . . 184
334 Is the argument a number? . . . . . . . . . . . . . . . . . . . . . . . 184
335 Defining macros within macros . . . . . . . . . . . . . . . . . . . . 185
336 Spaces in macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
337 How to break the 9-argument limit . . . . . . . . . . . . . . . . . . . 187
338 Key-value input for macros and package options . . . . . . . . . . . . 187
339 Defining characters as macros . . . . . . . . . . . . . . . . . . . . . 189
340 Active characters in command arguments . . . . . . . . . . . . . . . 190
341 Defining a macro from an argument . . . . . . . . . . . . . . . . . . . 191
342 Transcribing LaTeX command definitions . . . . . . . . . . . . . . . 191
343 Detecting that something is empty . . . . . . . . . . . . . . . . . . 192
344 Am I using PDFTeX, XeTeX or LuaTeX? . . . . . . . . . . . . . . 192
345 Subverting a token register . . . . . . . . . . . . . . . . . . . . . . 193
346 Is this command defined? . . . . . . . . . . . . . . . . . . . . . . . 193
7
R.2 LaTeX macro tools and techniques 194
347 Using Plain or primitive commands in LaTeX . . . . . . . . . . . . 194
348 \@ and @ in macro names . . . . . . . . . . . . . . . . . . . . . . . 195
349 What’s the reason for ‘protection’? . . . . . . . . . . . . . . . . . . 195
350 \edef does not work with \protect . . . . . . . . . . . . . . . . . 196
351 The definitions of LaTeX commands . . . . . . . . . . . . . . . . . 196
352 Optional arguments like \section . . . . . . . . . . . . . . . . . . 198
353 More than one optional argument . . . . . . . . . . . . . . . . . . . 198
354 Commands defined with * options . . . . . . . . . . . . . . . . . . 199
355 LaTeX internal “abbreviations”, etc. . . . . . . . . . . . . . . . . . 200
356 Defining LaTeX commands within other commands . . . . . . . . . 200
357 How to print contents of variables? . . . . . . . . . . . . . . . . . . . 201
358 Using labels as counter values . . . . . . . . . . . . . . . . . . . . . . 201
R.3 LaTeX macro programming 201
359 How to change LaTeX’s “fixed names” . . . . . . . . . . . . . . . . . 201
360 Changing the words babel uses . . . . . . . . . . . . . . . . . . . . 202
361 Running equation, figure and table numbering . . . . . . . . . . . . 202
362 Making labels from a counter . . . . . . . . . . . . . . . . . . . . . 203
363 Finding if you’re on an odd or an even page . . . . . . . . . . . . . 203
364 How to change the format of labels . . . . . . . . . . . . . . . . . . 204
365 Adjusting the presentation of section numbers . . . . . . . . . . . . 205
366 There’s a space added after my environment . . . . . . . . . . . . . 205
367 Finding if a label is undefined . . . . . . . . . . . . . . . . . . . . . 205
368 Master and slave counters . . . . . . . . . . . . . . . . . . . . . . . 206
369 Fonts at arbitrary sizes . . . . . . . . . . . . . . . . . . . . . . . . . 206
370 The quality of your LaTeX . . . . . . . . . . . . . . . . . . . . . . . 207
371 Process a CSV file in LaTeX . . . . . . . . . . . . . . . . . . . . . . 207
S Things are Going Wrong. . . 208
S.1 Getting things to fit 208
372 Enlarging TeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
373 Why can’t I load PiCTeX? . . . . . . . . . . . . . . . . . . . . . . . 208
S.2 Making things stay where you want them 209
374 Moving tables and figures in LaTeX . . . . . . . . . . . . . . . . . . 209
375 Underlined text won’t break . . . . . . . . . . . . . . . . . . . . . . 210
376 Controlling widows and orphans . . . . . . . . . . . . . . . . . . . 210
S.3 Things have “gone away” 211
377 Old LaTeX font references such as \tenrm . . . . . . . . . . . . . . . 211
378 Missing symbol commands . . . . . . . . . . . . . . . . . . . . . . . 211
379 Where are the msx and msy fonts? . . . . . . . . . . . . . . . . . . . . 211
380 Where are the am fonts? . . . . . . . . . . . . . . . . . . . . . . . . . 211
381 What’s happened to initex? . . . . . . . . . . . . . . . . . . . . . . 212
T Why does it do that? 212
T.1 Common errors 212
382 LaTeX gets cross-references wrong . . . . . . . . . . . . . . . . . . 212
383 Start of line goes awry . . . . . . . . . . . . . . . . . . . . . . . . . 213
384 Why doesn’t verbatim work within . . . ? . . . . . . . . . . . . . . . . 213
385 “No line here to end” . . . . . . . . . . . . . . . . . . . . . . . . . 215
386 Extra vertical space in floats . . . . . . . . . . . . . . . . . . . . . . 216
387 Why is my table/figure/. . . not centred? . . . . . . . . . . . . . . . . 216
388 Two-column float numbers out of order . . . . . . . . . . . . . . . . . 217
389 Accents misbehave in tabbing . . . . . . . . . . . . . . . . . . . . . 217
390 Package reports “command already defined” . . . . . . . . . . . . . . 217
391 Why are my sections numbered 0.1 . . . ? . . . . . . . . . . . . . . . 218
392 Link text doesn’t break at end line . . . . . . . . . . . . . . . . . . . 218
393 Page number is wrong at start of page . . . . . . . . . . . . . . . . . 218
394 My brackets don’t match . . . . . . . . . . . . . . . . . . . . . . . 219
395 Characters disappear from figures in PDFTeX . . . . . . . . . . . . 219
396 I asked for “empty”, but the page is numbered . . . . . . . . . . . . 220
8
T.2 Common misunderstandings 220
397 What’s going on in my \include commands? . . . . . . . . . . . . 220
398 Why does it ignore paragraph parameters? . . . . . . . . . . . . . . 220
399 Case-changing oddities . . . . . . . . . . . . . . . . . . . . . . . . . 221
400 Why does LaTeX split footnotes across pages? . . . . . . . . . . . . . 221
401 Getting \marginpar on the right side . . . . . . . . . . . . . . . . . 222
402 Where have my characters gone? . . . . . . . . . . . . . . . . . . . 222
403 “Rerun” messages won’t go away . . . . . . . . . . . . . . . . . . . 222
404 Commands gobble following space . . . . . . . . . . . . . . . . . . 223
405 (La)TeX makes overfull lines . . . . . . . . . . . . . . . . . . . . . 223
406 Maths symbols don’t scale up . . . . . . . . . . . . . . . . . . . . . 225
407 Why doesn’t \linespread work? . . . . . . . . . . . . . . . . . . 225
408 Only one \baselineskip per paragraph . . . . . . . . . . . . . . . 225
409 Numbers too large in table of contents, etc. . . . . . . . . . . . . . . 226
410 Why is the inside margin so narrow? . . . . . . . . . . . . . . . . . 226
T.3 Why shouldn’t I? 227
411 Why use fontenc rather than t1enc? . . . . . . . . . . . . . . . . . . . 227
412 Why bother with inputenc and fontenc? . . . . . . . . . . . . . . . . . 227
413 Why not use eqnarray? . . . . . . . . . . . . . . . . . . . . . . . . . 227
414 Why use \[ . . . \] in place of $$ . . . $$? . . . . . . . . . . . . . . . . 228
415 What’s wrong with \bf, \it, etc.? . . . . . . . . . . . . . . . . . . 228
416 What’s wrong with \newfont? . . . . . . . . . . . . . . . . . . . . 229
U The joy of TeX errors 229
417 How to approach errors . . . . . . . . . . . . . . . . . . . . . . . . 229
418 The structure of TeX error messages . . . . . . . . . . . . . . . . . 230
419 An extra ‘}’?? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
420 Capacity exceeded [semantic nest . . . ] . . . . . . . . . . . . . . . . . 231
421 No room for a new ‘thing’ . . . . . . . . . . . . . . . . . . . . . . . 232
422 epsf gives up after a bit . . . . . . . . . . . . . . . . . . . . . . . . 232
423 Improper \hyphenation will be flushed . . . . . . . . . . . . . . . 233
424 Option clash for package . . . . . . . . . . . . . . . . . . . . . . . 233
425 Option clash for package . . . . . . . . . . . . . . . . . . . . . . . 234
426 “Too many unprocessed floats” . . . . . . . . . . . . . . . . . . . . 235
427 \spacefactor complaints . . . . . . . . . . . . . . . . . . . . . . 235
428 \end occurred inside a group . . . . . . . . . . . . . . . . . . . . . 235
429 “Missing number, treated as zero” . . . . . . . . . . . . . . . . . . . 236
430 “Please type a command or say \end” . . . . . . . . . . . . . . . . 236
431 “Unknown graphics extension” . . . . . . . . . . . . . . . . . . . . . 237
432 “Missing $ inserted” . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
433 Warning: “Font shape . . . not available” . . . . . . . . . . . . . . . 238
434 Unable to read an entire line . . . . . . . . . . . . . . . . . . . . . . 238
435 “Fatal format file error; I’m stymied” . . . . . . . . . . . . . . . . . 239
436 Non-PDF special ignored! . . . . . . . . . . . . . . . . . . . . . . . 239
437 Mismatched mode ljfour and resolution 8000 . . . . . . . . . . . . . 239
438 “Too deeply nested” . . . . . . . . . . . . . . . . . . . . . . . . . . 240
439 Capacity exceeded — input levels . . . . . . . . . . . . . . . . . . . 240
440 PDFTeX destination . . . ignored . . . . . . . . . . . . . . . . . . . . 240
441 Alignment tab changed to \cr . . . . . . . . . . . . . . . . . . . . . . 241
442 Graphics division by zero . . . . . . . . . . . . . . . . . . . . . . . . 241
443 Missing \begin{document} . . . . . . . . . . . . . . . . . . . . . 242
444 \normalsize not defined . . . . . . . . . . . . . . . . . . . . . . . 242
445 Too many math alphabets . . . . . . . . . . . . . . . . . . . . . . . 243
446 Not in outer par mode . . . . . . . . . . . . . . . . . . . . . . . . . 243
447 Perhaps a missing \item? . . . . . . . . . . . . . . . . . . . . . . . 243
448 Illegal parameter number in definition . . . . . . . . . . . . . . . . 244
449 Float(s) lost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
450 Not in outer par mode . . . . . . . . . . . . . . . . . . . . . . . . . 245
451 Token not allowed in PDFDocEncoded string . . . . . . . . . . . . . 245
452 Checksum mismatch in font . . . . . . . . . . . . . . . . . . . . . . 246
453 Entering compatibility mode . . . . . . . . . . . . . . . . . . . . . 246
454 LaTeX won’t include from other directories . . . . . . . . . . . . . 246
9
455 Support package expl3 too old . . . . . . . . . . . . . . . . . . . . . . 247
V Current TeX-related projects 247
456 The LaTeX project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
457 Future WWW technologies and (La)TeX . . . . . . . . . . . . . . . 248
458 Making outline fonts from Metafont . . . . . . . . . . . . . . . . . 249
459 The TeX document preparation environment . . . . . . . . . . . . . 249
460 Omega and Aleph . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
461 XeTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
462 PDFTeX and LuaTeX . . . . . . . . . . . . . . . . . . . . . . . . . . 251
463 The ANT typesetting system . . . . . . . . . . . . . . . . . . . . . 252
464 The ExTeX project . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
465 Replacing the BibTeX–LaTeX mechanism . . . . . . . . . . . . . . 252
W You’re still stuck? 253
466 You don’t understand the answer . . . . . . . . . . . . . . . . . . . 253
467 Submitting new material for the FAQ . . . . . . . . . . . . . . . . . 253
468 What to do if you find a bug . . . . . . . . . . . . . . . . . . . . . . 254
469 Reporting a LaTeX bug . . . . . . . . . . . . . . . . . . . . . . . . 254
§ § § § § § § § § § § § § § § § § §
Alan Hoenig’s ‘TeX Unbound ’ includes The Alphabet and Elements of Lettering
some discussion and examples of using by Frederick Goudy (Dover, 1963,
Metafont. ISBN-10 0-486-20792-7)
A book covering a wide range of topics Anatomy of a Typeface by Alexander
(including installation and maintenance) is: Lawson (David R. Godine, 1990,
ISBN-10 0-87923-338-8)
Making TeX Work by Norman Walsh
(O’Reilly and Associates, Inc, 1994, A Tally of Types by Stanley Morison
ISBN-10 1-56592-051-1) (David R. Godine, 1999, ISBN-10 1-
56792-004-7)
The book is decidedly dated, and is now Counterpunch by Fred Smeijers (Hyphen,
out of print, but a copy is available via 1996, ISBN-10 0-907259-06-5)
sourceforge and on CTAN, and we list it
under “online books”. Treasury of Alphabets and Lettering by
Jan Tschichold (W. W. Norton, 1992,
32 Books on Type ISBN-10 0-393-70197-2)
The following is a partial listing of books A Short History of the Printed Word
on typography in general. Of these, by Warren Chappell and Robert
Bringhurst seems to be the one most of- Bringhurst (Hartley & Marks, 1999,
ten recommended. ISBN-10 0-88179-154-7)
23
The above lists are limited to books French FAQ:
published in English. Typographic styles help/LaTeX-FAQ-francaise
are somewhat language-dependent, and Sources of this FAQ: help/uk-tex-faq
similarly the ‘interesting’ fonts depend on
the particular writing system involved. Obsolete comp.text.tex FAQ:
obsolete/help/TeX,_LaTeX,
33 Where to find FAQs _etc.:_Frequently_Asked_
Questions_with_Answers
Bobby Bodenheimer’s article, from which
this FAQ was developed, used to be posted The visual FAQ:
(nominally monthly) to newsgroup comp. info/visualFAQ/visualFAQ.pdf
text.tex. The (long obsolete) last posted 34 Getting help online
copy of that article is kept on CTAN for
We assume, here, that you have looked
auld lang syne.
at all relevant FAQ answers you can find,
A version of the present FAQ may be
you’ve looked in any books you have, and
browsed via the World-Wide Web, and its
scanned relevant tutorials. . . and still you
sources are available from CTAN.
don’t know what to do.
This FAQ and others are regularly men- There are two more steps you can take
tioned, on comp.text.tex and elsewhere, before formulating a question to the TeX
in a “pointer FAQ” which is also saved at world at large.
http://tug.org/tex-ptr-faq
First, (if you are seeking a particular
A 2006 innovation from Scott Pakin is package or program), start by looking on
the “visual” LaTeX FAQ. This is a docu- your own system: you might already have
ment with (mostly rubbish) text formatted what you seek — the better TeX distribu-
so as to highlight things we discuss here, tions provide a wide range of supporting
and providing Acrobat hyper-links to the material. The CTAN Catalogue can also
relevant answers in this FAQ on the Web. identify packages that might help: you can
The visual FAQ is provided in PDF format, search it, or you can browse it “by topic”.
on CTAN; it works best using Adobe Ac- Each catalogue entry has a brief descrip-
robat Reader 7 (or later); some features are tion of the package, and links to known
missing with other readers, or with earlier documentation on the net. In fact, a large
versions of Acrobat Reader proportion of CTAN package directories
Another excellent information source, now include documentation, so it’s often
available in English, is the (La)TeX navi- worth looking at the catalogue entry for a
gator. package you’re considering using (where
Both the Francophone TeX user group possible, each package link in the main
Gutenberg and the Czech/Slovak user body of these FAQs has a link to the rele-
group CS-TUG have published translations vant catalogue entry).
of this FAQ, with extensions appropriate Failing that, look to see if anyone has
to their languages. solved the problem before; places where
The Open Directory Project (ODP) people ask are:
maintains a list of sources of (La)TeX
help, including FAQs. View the TeX 1. newsgroup comp.text.tex, whose
area at http://dmoz.org/Computers/ “historical posts” are accessible via
Software/Typesetting/TeX/ Google groups, and
Other non-English FAQs are available 2. the mailing list texhax via its archive,
(off-CTAN): or via the ‘Gmane’ newsgroup gmane.
comp.tex.texhax, which holds a
German Posted regularly to de.comp. very long history of the list. A long
tex, and archived on CTAN; the FAQ shot would be to search the archives
also appears at http://www.dante. of the mailing list’s ancient posts on
de/faq/de-tex-faq/ CTAN, which go back to the days
when it was a digest: in those days,
French A FAQ used to be posted regu- a question asked in one issue would
larly to fr.comp.text.tex, and is only ever be answered in the next one.
archived on CTAN — sadly, that effort
seems to have fallen by the wayside. If the “back question” searches fail, you
must ask the world at large.
Czech See http://www.fi.muni.cz/
So, how do you like to ask questions? —
cstug/csfaq/
the three available mechanisms are:
Resources available on CTAN are: 1. Mailing lists: there are various spe-
Dante FAQ: help/de-tex-faq cialist mailing lists, but the place
24
for ‘general’ (La)TeX queries is the ens.fr: subscribe to it by sending a mes-
texhax mailing list. Mail to texhax@ sage
tug.org to ask a question, but it’s
probably better to subscribe to the subscribe metafont
list (via http://tug.org/mailman/
to [email protected]
listinfo/texhax) first — not every-
one will answer to you as well as to (Note that there’s also a Metapost-
the list. specific mailing list available via the TUG
2. Newsgroup: to ask a question list server; in fact there’s little danger of be-
on comp.text.tex, you can use coming confused by subscribing to both.)
your own news client (if you have Announcements of TeX-related in-
one), or use the “+ new post” stallations on the CTAN archives are
button on http://groups.google. sent to the mailing list ctan-ann. Sub-
com/group/comp.text.tex. scribe to the list via its MailMan web-site
3. Web forum: alternatives are: the “La- https://lists.dante.de/mailman/
TeX community” site, which offers listinfo/ctan-ann; list archives are
a variety of ‘categories’ to place your available at the same address. The list
query, and the TeX, LaTeX and friends archives may also be browsed via http:
Q&A site (“StackExchange”). //www.mail-archive.com/ctan-ann@
StackExchange has a scheme for vot- dante.de/, and an RSS feed is also avail-
ing on the quality of answers (and able: http://www.mail-archive.com/
hence of those who offer support). [email protected]/maillist.xml
This arrangement is supposed to en- 36 How to ask a question
able you to rank any answers that are
posted. You want help from the community at
StackExchange offers hints about large; you’ve decided where you’re go-
“good behaviour”, which any user ing to ask your question, but how do you
should at least scan before asking for phrase it?
help there. (The hints’ principal aim Excellent “general” advice (how to ask
is to maximise the chance that you get questions of anyone) is contained in Eric
useful advice from the first answer; for Raymond’s article on the topic. Eric’s an
example, it suggests that you supply extremely self-confident person, and this
a minimal example of your problem, comes through in his advice; but his guide-
just as these FAQs do. There are peo- lines are very good, even for us in the un-
ple on the site who can be abrasive self-confident majority. It’s important to
to those asking questions, who seem remember that you don’t have a right to
not to be following the guidelines for advice from the world, but that if you ex-
good behaviour) press yourself well, you will usually find
someone who will be pleased to help.
Do not try mailing the LaTeX project team, So how do you express yourself in the
the maintainers of the TeX Live or MiK- (La)TeX world? There aren’t any compre-
TeX distributions or the maintainers of hensive rules, but a few guidelines may
these FAQs for help; while all these ad- help in the application of your own com-
dresses reach experienced (La)TeX users, mon sense.
no small group can possibly have expertise
in every area of usage so that the “big” lists • Make sure you’re asking the right peo-
and forums are a far better bet. ple. Don’t ask in a TeX forum about
printer device drivers for the Foobar
texhax ‘back copies’: digests/texhax
operating system. Yes, TeX users need
printers, but no, TeX users will typ-
35 Specialist mailing lists
ically not be Foobar systems man-
The previous question, “getting help”, agers.
talked of the two major forums in which Similarly, avoid posing a question in
(La)TeX, Metafont and Metapost are dis- a language that the majority of the
cussed; however, these aren’t the only ones group don’t use: post in Ruritanian
available. to de.comp.text.tex and you may
The TUG web site offers many mailing have a long wait before a German- and
lists other than just texhax via its mail list Ruritanian-speaking TeX expert no-
management page. tices your question.
The French national TeX user group, • If your question is (or may be) TeX-
Gutenberg, offers a Metafont (and, de system-specific, report what system
facto, Metapost) mailing list, metafont@ you’re using, or intend to use: “I
25
can’t install TeX” is as good as use- The “building up” process starts with a
less, whereas “I’m trying to install basic document structure (for LaTeX, this
the mumbleTeX distribution on the would have \documentclass, \begin
Grobble operating system” gives all {document}, \end{document}) and adds
the context a potential respondent things. First to add is a paragraph or so
might need. Another common situ- around the actual point where the problem
ation where this information is impor- occurs. (It may prove difficult to find the
tant is when you’re having trouble in- actual line that’s provoking the problem. If
stalling something new in your system: the original problem is an error, reviewing
“I want to add the glugtheory package “the structure of TeX errors” may help.)
to my mumbleTeX v12.0 distribution Note that there are things that can go
on the Grobble 2024 operating sys- wrong in one part of the document as a
tem”. result of something in another part: the
• If you need to know how to do some- commonest is problems in the table of con-
thing, make clear what your environ- tents (from something in a section title, or
ment is: “I want to do x in Plain TeX”, whatever), or the list of hsomethingi (from
or “I want to do y in LaTeX running something in a \caption). In such a case,
the boggle class”. If you thought you include the section title or caption (the cap-
knew how, but your attempts are fail- tion probably needs the figure or table
ing, tell us what you’ve tried: “I’ve environment around it, but it doesn’t need
already tried installing the elephant the figure or table itself).
in the minicar directory, and it didn’t If this file you’ve built up shows the
work, even after refreshing the file- problem already, then you’re done. Oth-
name database”. erwise, try adding packages; the optimum
• If something’s going wrong within is a file with only one package in it, but
(La)TeX, pretend you’re submitting a you may find that the guilty package won’t
LaTeX bug report, and try to generate even load properly unless another package
a minimum failing example. If your has been loaded. (Another common case
example needs your local xyzthesis is that package A only fails when package
class, or some other resource not gen- B has been loaded.)
erally available, be sure to include a The “hacking down” route starts with
pointer to how the resource can be ob- your entire document, and removes bits
tained. until the file no longer fails (and then of
• Figures are special, of course. Some- course restores the last thing removed).
times the figure itself is really needed, Don’t forget to hack out any unneces-
but most problems may be demon- sary packages, but mostly, the difficulty
strated with a “figure substitute” in the is choosing what to hack out of the body
form of a \rule{width}{height} of the document; this is the mirror of the
command, for some value of hwidthi problem above, in the “building up” route.
and hheighti. If the (real) figure is
If you’ve added a package (or more
needed, don’t try posting it: far better
than one), add \listfiles to the pream-
to put it on the web somewhere.
ble too: that way, LaTeX will produce a
• Be as succinct as possible. Your
list of the packages you’ve used and their
helpers don’t usually need to know
version numbers. This information may be
why you’re doing something, just what
useful evidence for people trying to help
you’re doing and where the problem
you.
is.
The process of ‘building up’, and to
some extent that of ‘hacking down’, can be
37 How to make a “minimum
helped by stuff available on CTAN:
example”
Our advice on asking questions suggests • the minimal class (part of the LaTeX
that you prepare a “minimum example” distribution) does what its name says:
(also commonly known as a “minimal ex- it provides nothing more than what is
ample”) of failing behaviour, as a sample needed to get LaTeX code going, and
to post with your question. If you have a • the mwe bundle provides a number of
problem in a two hundred page document, images in formats that (La)TeX doc-
it may be unclear how to proceed from uments can use, and a small package
this problem to a succinct demonstration mwe which loads other useful pack-
of your problem. ages (such as blindtext and lipsum,
There are two valid approaches to this both capable of producing dummy text
task: building up, and hacking down. in a document).
26
What if none of of these cut-down Next comes a selection of “specialised”
derivatives of your document will show (La)TeX tutorials, each of which concen-
your error? Whatever you do, don’t post trates on a single LaTeX topic.
the whole of the document: if you can, it A small selection of reference docu-
may be useful to make a copy available on ments (it would be good to have more) are
the web somewhere: people will probably listed in an answer of their own.
understand if it’s impossible . . . or inadvis- Next comes the (somewhat newer)
able, in the case of something confidential. field of TeX-related WIKIs.
If the whole document is indeed nec- A rather short list gives us a Typogra-
essary, it could be that your error is an phy style tutorial.
overflow of some sort; the best you can do
is to post the code “around” the error, and 39 Online introductions: Plain TeX
(of course) the full text of the error. Michael Doob’s splendid ‘Gentle Introduc-
It may seem that all this work is tion’ to Plain TeX (available on CTAN) has
rather excessive for preparing a simple been stable for a very long time.
post. There are two responses to that, both Another recommendable document is
based on the relative inefficiency of asking D. R. Wilkins’ ‘Getting started with TeX’,
a question on the internet. available on the web at http://www.ntg.
First, preparing a minimum document nl/doc/wilkins/pllong.pdf
very often leads you to the answer, with- Gentle Introduction:
out all the fuss of posting and looking for info/gentle/gentle.pdf
responses.
Second, your prime aim is to get an 40 Online introductions: LaTeX
answer as quickly as possible; a well- A pleasing little document, “Getting some-
prepared example stands a good chance thing out of LaTeX” is designed to give
of attracting an answer “in a single pass”: a feel of LaTeX to someone who’s never
if the person replying to your post finds she used it at all. It’s not a tutorial, merely
needs more information, you have to find helps the user to decide whether to go on
that request, post again, and wait for your to a tutorial, and thence to ‘real’ use of
benefactor to produce a second response. LaTeX.
All things considered, a good example Tobias Oetiker’s ‘(Not so) Short Intro-
file can save you a day, for perhaps half an duction to LaTeX2e’, is regularly updated,
hour’s effort invested. as people suggest better ways of explaining
Much of the above advice, differ- things, etc. The introduction is available
ently phrased, may also be read on the on CTAN, together with translations into a
web at http://www.minimalbeispiel. rather large set of languages.
de/mini-en.html; source of that ar- Peter Flynn’s “Beginner’s LaTeX”
ticle may be found at http://www. (which started life as course material) is
minimalbeispiel.de/, in both German a pleasing read. A complete copy may
and English. be found on CTAN, but it may also be
blindtext.sty : macros/latex/ browsed over the web (http://mirrors.
contrib/blindtext ctan.org/info/beginlatex/html/).
Harvey Greenberg’s ‘Simplified Intro-
lipsum.sty : duction to LaTeX’ was written for a lecture
macros/latex/contrib/lipsum course, and is also available on CTAN (in
minimal.cls: Distributed as part of PostScript only, unfortunately).
macros/latex/base The fourth edition of George Grätzer’s
book “Math into LaTeX” contains a “short
mwe.sty : macros/latex/contrib/mwe course” in LaTeX itself, and that course
has been made publicly available on
38 Tutorials, etc., for TeX-based
CTAN.
systems
Philip Hirschhorn’s “Getting up and
From a situation where every (La)TeX user running with AMSLaTeX” has a brief in-
had to buy a book if she was not to find troduction to LaTeX itself, followed by a
herself groping blindly along, we now have substantial introduction to the use of the
what almost amounts to an embarrassment AMS classes and the amsmath package and
of riches of online documentation. The fol- other things that are potentially of inter-
lowing answers attempt to create lists of est to those writing documents containing
sources “by topic”. mathematics.
First we have introductory manuals, for Edith Hodgen’s LaTeX, a Braindump
Plain TeX and LaTeX. starts you from the ground up — giving a
27
basic tutorial in the use of Linux to get you The sins of LaTeX users: Browse
going (rather a large file. . . ). Its parent site, info/l2tabu for a copy of the
David Friggens’ documentation page is a document in a language that is
useful collection of links in itself. convenient for you
Andy Roberts’ introductory material
is a pleasing short introduction to the use 41 (La)TeX tutorials
of (La)TeX; some of the slides for actual The AMS publishes a “Short Math Guide
tutorials are to be found on the page, as for LaTeX”, which is available (in several
well. formats) via http://www.ams.org/tex/
D. R. Wilkins’ ‘Getting started with La- amslatex.html (the “Additional Docu-
TeX’ also looks good (it appears shorter — mentation” about half-way down the page.
more of a primer — than some of the other Herbert Voß has written an extensive
offerings). guide to mathematics in LaTeX, and a de-
Chris Harrison’s LaTeX tutorial velopment of it has been published as a
presents basic LaTeX in a rather pleas- book.
ing and straightforward way. Two documents written more than ten
Nicola Talbot’s LaTeX for complete years apart about font usage in TeX are
novices does what it claims: the author worth reading: Essential NFSS by Sebas-
teaches LaTeX at the University of East tian Rahtz, and Font selection in LaTeX,
Anglia. The “Novices” tutorial is one of cast in the form of an FAQ, by Walter
several introductory tutorials, which in- Schmidt. A general compendium of font
clude exercises (with solutions). Other information (including the two above) may
tutorials include those for writing the- be found on the TUG web site.
ses/dissertations with LaTeX, and for using TUG India is developing a series
LaTeX in administrative work of online LaTeX tutorials which can be
Engelbert Buxbaum provides the strongly recommended: select single chap-
‘slides’ for his LaTeX course ‘The LaTeX ters at a time from http://www.tug.
document preparation system’; this seems org/tutorials/tugindia — there are
to be a departmental course at his univer- 17 chapters in the series, two of which are
sity. mostly introductory.
Mark van Dongen’s ‘LaTeXand Peter Smith’s “LaTeX for Logicians”
friends’ appeared as he was writing his page covers a rather smaller subject area,
book on the subject (soon to be published). but is similarly comprehensive (mostly
An interesting (and practical) tutorial by links to documents on relevant topics,
about what not to do is l2tabu, or “A list rather than as a monolithic document).
of sins of LaTeX2e users” by Mark Tret- Keith Reckdahl’s “Using Imported
tin, translated into English by Jürgen Fenn. Graphics in LaTeX2e” (epslatex) is an ex-
The tutorial is available from CTAN as a cellent introduction to graphics use. It’s
PDF file (though the source is also avail- available on CTAN, but not in the TeX
able). Live or miktex distributions, for lack of
Beginner’s LaTeX: sources.
info/beginlatex/beginlatex- Stefan Kottwitz manages a web site de-
3.6.pdf voted to the use of the drawing packages
Getting something out of LaTeX: PGF and TikZ, http://www.texample.
net/
info/first-latex-doc
Included is examples catalogue in-
Getting up and running with AMSLaTeX: cludes examples (with output) from the
info/amslatex/primer package documentation as well as code
Slides for LaTeX course: written by the original site maintainer
info/latex-course (Kjell Magne Fauske) and others.
Not so Short Introduction: The compendious PGF/TikZ manual
info/lshort/english (in English, is clear, but is bewildering for some be-
you may browse for sources ginners. The ‘minimal’ introduction has
and other language versions at helped at least the present author.
info/lshort) Vincent Zoonekynd provides a set of
excellent (and graphic) tutorials on the pro-
Simplified LaTeX: info/simplified- gramming of title page styles, chapter head-
latex/simplified-intro.pdf
ing styles and section heading styles. In
Short Course in LaTeX: each file, there is a selection of graphics
info/Math_into_LaTeX- representing an output style, and for each
4/Short_Course.pdf style, the code that produces it is shown.
28
An invaluable step-by-step setup guide or less) everything you ‘ought to’ remem-
for establishing a “work flow” through ber, for basic LaTeX use. (It’s laid out very
your (La)TeX system, so that output ap- compactly for printing on N. American ‘let-
pears at the correct size and position on ter’; printed on ISO A4, using Adobe Acro-
standard-sized paper, and that the print bat’s “shrink to fit”, it strains aged eyes. . . )
quality is satisfactory, is Mike Shell’s For command organised references to
testflow. The tutorial consists of a large LaTeX, Karl Berry (et al)’s LaTeX ref-
plain text document, and there is a support- erence manual is (to an extent) work in
ing LaTeX file together with correct output, progress, but is generally reliable (source
both in PostScript and PDF, for each of A4 is available on the.archive as well).
and “letter” paper sizes. The complete kit Martin Scharrer’s “List of internal La-
is available on CTAN (distributed with the TeX macros” is a help to those aiming to
author’s macros for papers submitted for write a class or package.
IEEE publications). The issues are also The reference provided by the Emer-
covered in a later FAQ answer. son Center of Emory University), LaTeXe
Documentation of Japanese Ω use ap- help also looks good.
pears in Haruhiko Okumura’s page type- Cheat sheet: info/latexcheat/
setting Japanese with Omega (the parent latexcheat/latexsheet.pdf
page is in Japanese, so out of the scope of
this FAQ list). LaTeX reference manual:
info/latex2e-help-texinfo
Some university departments make
their local documentation available on the LaTeX internal macros: info/macros2e
web. Most straightforwardly, there’s the 43 WIKI books for TeX and friends
simple translation of existing documenta-
tion into HTML, for example the INFO The WIKI concept can be a boon to every-
documentation of the (La)TeX installation, one, if used sensibly. The “general” WIKI
of which a sample is the LaTeX documen- allows anyone to add stuff, or to edit stuff
tation available at http://www.tac.dk/ that someone else has added: while there
cgi-bin/info2www?(latex) is obvious potential for chaos, there is ev-
More ambitiously, some university de- idence that a strong user community can
partments have enthusiastic documenters keep a WIKI under control.
who make public record of their (La)TeX Following the encouraging perfor-
support. For example, Tim Love (of mance of the ConTeXt WIKI, valiant ef-
Cambridge University Engineering De- forts have been made generating “WIKI
partment) maintains his department’s books” for (La)TeX users. Thus we have
pages at http://www-h.eng.cam.ac. (Plain) TeX WIKI book and LaTeX WIKI
uk/help/tpl/textprocessing/
book — both well established. Both are
highly rated as reference sources, and even
Graphics in LaTeX2e: info/epslatex as introductory texts.
testflow : macros/latex/contrib/ 44 Typography tutorials
IEEEtran/testflow
Peter Wilson’s article memdesign has
Herbert Voß’s Maths tutorial: a lengthy introductory section on typo-
info/math/voss/mathmode/ graphic considerations, which is a fine tu-
Mathmode.pdf torial, written by someone who is aware
of the issues as they apply to (La)TeX
42 Reference documents
users. (Memdesign now distributed sep-
For TeX primitive commands a rather nice arately from the manual for his memoir
quick reference booklet, by John W. Ship- class, but was originally part of that man-
man, is available; it’s arranged in the same ual)
way as the TeXbook. By contrast, you can There’s also (at least one) typographic
view David Bausum’s list of TeX primi- style tutorial available on the Web, the
tives alphabetically or arranged by “fam- excellent “Guidelines for Typography in
ily”. Either way, the list has a link for NBCS”. In fact, its parent page is also
each control sequence, that leads you to a worth a read: among other things, it pro-
detailed description, which includes page vides copies of the “guidelines” document
references to the TeXbook. in a wide variety of primary fonts, for com-
There doesn’t seem to be a reference parison purposes. The author is careful to
that takes in Plain TeX as well as the prim- explain that he has no ambition to supplant
itive commands. such excellent books as Bringhurst’s, but
An interesting LaTeX “cheat sheet” is the document (though it does contain its
available from CTAN: it’s a list of (more Rutgers-local matter) is a fine introduction
29
to the issues of producing readable docu- which opens a window showing documen-
ments. tation of the footmisc package. (The win-
memdesign: info/memdesign dow is tailored to the file type, in the way
normal for the system.)
45 Freely available (La)TeX books If texdoc can’t find any documentation,
People have long argued for (La)TeX it may launch a Web browser to look at the
books to be made available on the web, package’s entry in the CTAN catalogue.
and until relatively recently this demand The catalogue has an entry for package
went un-answered. documentation, and most authors respond
The first to appear was Victor Ei- to the CTAN team’s request for documenta-
jkhout’s excellent “TeX by Topic” in 2001 tion of packages, you will more often than
(it had been published by Addison-Wesley, not find documentation that way.
but was long out of print). The book is now On MiKTeX systems, the same func-
available on CTAN; it’s not a beginner’s tion is provided by the mthelp.
tutorial but it’s a fine reference. It’s also Note that the site texdoc.net pro-
available, as a printed copy, via the on-line vides access to the documentation you
publishers Lulu (not quite free, of course, would have if you had a full installation of
but not a bad deal. . . ). TeX Live; on the site you can simply ask
Addison-Wesley have also released for a package (as you would ask texdoc, or
the copyright of “TeX for the Impatient” you can use the site’s index of documenta-
by Paul W. Abrahams, Karl Berry and tion to find what you want. (This is helpful
Kathryn A. Hargreaves, another book for some of us: many people don’t have a
whose unavailability many have lamented. full (La)TeX installation on their mobile
The authors have re-released the book un- phone . . . yet.)
der the GNU Free Documentation Licence, If your luck (as defined above) doesn’t
and it is available from CTAN. hold out, you’ve got to find documentation
Norm Walsh’s “Making TeX Work” by other means. That is, you have to find
(originally published by O’Reilly) is the documentation for yourself. The rest
also available (free) on the Web, at of this answer offers a range of possible
http://makingtexwork.sourceforge. techniques.
net/mtw/; the sources of the Web page
The commonest form of documenta-
are on CTAN. The book was an excellent tion of LaTeX add-ons is within the .dtx
resource in its day, but while it is now file in which the code is distributed (see
somewhat dated, it still has its uses, and is documented LaTeX sources). Such files
a welcome addition to the list of on-line re- are supposedly processable by LaTeX it-
sources. A project to update it is believed self, but there are occasional hiccups on
to be under way. the way to readable documentation. Com-
Making TeX Work: mon problems are that the package itself is
info/makingtexwork/mtw-1.0.1- needed to process its own documentation
html.tar.gz (so must be unpacked before processing),
TeX by Topic: info/texbytopic and that the .dtx file will not in fact pro-
cess with LaTeX. In the latter case, the
TeX for the Impatient: info/impatient .ins file will usually produce a .drv (or
46 Documentation of packages similarly-named) file, which you process
These FAQs regularly suggest packages with LaTeX instead. (Sometimes the pack-
that will “solve” particular problems. In age author even thinks to mention this wrin-
some cases, the answer provides a recipe kle in a package README file.)
for the job. In other cases, or when the Another common form is the separate
solution needs elaborating, how is the poor documentation file; particularly if a pack-
user to find out what to do? age is “conceptually large” (and therefore
If you’re lucky, the package you need needs a lot of documentation), the doc-
is already in your installation. If you’re par- umentation would prove a cumbersome
ticularly lucky, you’re using a distribution extension to the .dtx file. Examples
that gives access to package documenta- of such cases are the memoir class, the
tion and the documentation is available in KOMA-script bundle (whose developers
a form that can easily be shown. take the trouble to produce detailed doc-
On TeX Live-based distributions, help umentation in both German and English),
should be available from the texdoc com- the pgf documentation (which would make
mand, as in: a substantial book in its own right) and
the fancyhdr package (whose documenta-
texdoc footmisc tion derives from a definitive tutorial in a
30
mathematical journal). Even if the docu- a good idea to read some established ones
mentation is not separately identified in a (classes.dtx, for example, is the docu-
README file, it should not be too difficult mented source of the standard classes other
to recognise its existence. than Letter, and may itself be formatted
Documentation within the package it- with LaTeX). Classes that are not part of
self is the third common form. Such docu- the distribution are commonly based on
mentation ordinarily appears in comments ones that are, and start by loading the
at the head of the file, though at least one standard class with \LoadClass — an ex-
eminent author regularly places it after ample of this technique may be seen in
the \endinput command in the package. ltxguide.cls
(This is desirable, since \endinput is a An annotated version of article, as it
‘logical’ end-of-file, and (La)TeX doesn’t appears in classes.dtx, was published
read beyond it: thus such documentation in TUGboat 28(1). The article, by Peter
does not ‘cost’ any package loading time.) Flynn, is a good guide to understanding
The above suggestions cover most pos- classes.dtx
sible ways of finding documentation. If, classes.dtx :
despite your best efforts, you can’t find it macros/latex/base/classes.dtx
in any of the above places, there’s the aw-
clsguide.pdf :
ful possibility that the author didn’t bother
macros/latex/doc/clsguide.pdf
to document his package (on the “if it was
hard to write, it should be hard to use” phi- latex-tds rmfamilycollection:
losophy). Most ordinary mortals will seek macros/latex/contrib/latex-
support from some more experienced user tds
at this stage, though it is possible to pro- ltxguide.cls: macros/latex/base/
ceed in the way that the original author ap- ltxguide.cls
parently expected. . . by reading his code.
LaTeX documentation:
47 Learning to write LaTeX classes macros/latex/doc
and packages source2e.tex : macros/latex/base/
There’s nothing particularly magic about source2e.tex
the commands you use when writing a 48 LaTeX3 programming
package, so you can simply bundle up
As yet, there is no book “Programming in
a set of LaTeX \(re)newcommand and
LaTeX3”, and even if such a thing existed
\(re)newenvironment commands, put
there would be lots of gaps. So there is no
them in a file package.sty and you have
comprehensive support.
a package.
However, there are some ‘resources’:
However, any but the most trivial pack-
age will require rather more sophistica- • The “introduction to LaTeX3 ideas” in
tion. Some details of LaTeX commands the expl3 documentation gives a broad-
for the job are to be found in ‘LaTeX2e brush overview of the concepts.
for class and package writers’ (clsguide, • Joseph Wright has written a short se-
part of the LaTeX documentation distri- ries of blog posts, which may help.
bution). Beyond this, a good knowledge • There is also a complete command ref-
of TeX itself is valuable: thus books such erence in the interface3 document.
as the TeXbook or TeX by topic are rele-
vant. With good TeX knowledge it is pos- The documents are still subject to de-
sible to use the documented source of La- velopment; some of the broader design is-
TeX as reference material (dedicated au- sues are discussed on the LaTeX mailing
thors will acquaint themselves with the list latex-l — you may subscribe to that
source as a matter of course). A com- list by sending a message by sending a
plete set of the documented source of La- message
TeX may be prepared by processing the
‘subscribe latex-l <your
file source2e.tex in the LaTeX distribu-
name>’
tion. Such processing is noticeably tedious,
but Heiko Oberdiek has prepared a well- to [email protected]
linked PDF version, which is in the file
expl3.pdf : macros/latex/contrib/
base.tds.zip of his latex-tds distribu-
l3kernel/expl3.pdf
tion. Individual files in the LaTeX distribu-
tion may be processed separately with La- interface3.pdf :
TeX, like any well-constructed .dtx file. macros/latex/contrib/
Writing good classes is not easy; it’s l3kernel/interface3.pdf
31
49 Metafont and Metapost Tutorials Peter Wilson’s “experiences”: info/
metafont/metafp/metafp.pdf
Apart from Knuth’s book, there seems to
be only one publicly-available tutorial for Vincent Zoonekynd’s examples:
Metafont, by Christophe Grandsire (a copy info/metapost/examples
in PDF form may be downloaded). Geof-
50 BibTeX Documentation
frey Tobin’s Metafont for Beginners (see
using Metafont) describes how the Meta- BibTeX, a program originally designed to
font system works and how to avoid some produce bibliographies in conjunction with
of the potential pitfalls. LaTeX, is explained in Section 4.3 and Ap-
Peter Wilson’s experience of running pendix B of Leslie Lamport’s LaTeX man-
both Metafont and Metapost (the pro- ual. The document “BibTeXing”, in the
grams), Some Experiences in Running BibTeX distribution (look for btxdoc), ex-
Metafont and Metapost (available on pands on the chapter in Lamport’s book.
CTAN) offers the benefit of Peter’s experi- The LaTeX Companion also has informa-
ence (he has designed a number of ‘histor- tion on BibTeX and writing BibTeX style
ical’ fonts using Metafont). For Metafont files. (See LaTeX books for details of both
the article is geared towards testing and in- books.)
stalling new Metafont fonts, while its Meta- The web site “Your BibTeX resource”
post section describes how to use Metapost offers a solid introduction, but doesn’t go
illustrations in LaTeX and PDFLaTeX doc- into very great detail.
uments, with an emphasis on how to use The document “Designing BibTeX
appropriate fonts for any text or mathemat- Styles”, also in the BibTeX distribution
ics. (look for btxhak), explains the postfix
Hans Hagen (of ConTeXt fame) offers stack-based language used to write BibTeX
a Metapost tutorial called MetaFun (which styles (.bst files). The filebtxbst.doc,
admittedly concentrates on the use of Meta- also in the BibTeX distribution, is the tem-
post within ConTeXt). It may be found on plate for the four standard styles (plain,
his company’s ‘manuals’ page. abbrv, alpha, and unsrt); it also contains
their documentation.
Another Metapost tutorial in English
A useful tutorial of the whole pro-
is: http://www.tlhiv.org/MetaPost/
cess of using BibTeX is Nicolas Markey’s
tutorial/ by Urs Oswald. One in
“Tame the BeaST (The B to X of BibTeX)”,
French (listed here because it’s clearly
which may also be found on CTAN. A
enough written that even this author un-
summary and FAQ by Michael Shell and
derstands it), http://pauillac.inria.
David Hoadley, is also to be recommended.
fr/~cheno/metapost/metapost.pdf
by Laurent Chéno. BibTeX distribution:
Urs Oswald’s tutorial uses Troy Hen- biblio/bibtex/base
derson’s tool (http://www.tlhiv.org/ Shell and Hoadley’s FAQ: biblio/
mppreview) for testing little bits of Meta- bibtex/contrib/doc/btxFAQ.pdf
post; it is an invaluable aid to the learner:
Tame the BeaST: info/bibtex/
http://www.tlhiv.org/mppreview
tamethebeast/ttb_en.pdf
A three-part introduction, by Mari
Voipio, was published in TUGboat 4(1) 51 Where can I find the symbol
(Entry-level Metapost: On the grid), TUG- for . . .
boat 4(2) (Entry-level Metapost: Move it!),
There is a wide range of symbols avail-
and TUGboat 4(2) (Entry-level Metapost:
able for use with TeX, most of which are
Color).
not shown (or even mentioned) in (La)TeX
Vincent Zoonekynd’s massive set of ex- books. The Comprehensive LaTeX Sym-
ample Metapost files is available on CTAN; bol List (by Scott Pakin et al.) illustrates
the set includes a Perl script to convert the over 2000 symbols, and details the com-
set to html, and the set may be viewed on mands and the LaTeX packages needed to
the web. While these examples don’t ex- produce them.
actly constitute a “tutorial”, they’re most However, while the symbol list is a
certainly valuable learning material. Urs wonderful resource, it is never easy to find
Oswald presents a similar document, writ- a particular symbol there. A graphical sym-
ten more as a document, and presented in bol search is available on the web. The
PDF. site provides you a scratch area on which
Beginners’ guide: you draw the symbol you’re thinking of,
info/metafont/beginners/ with your mouse; when you’ve finished
metafont-for-beginners.pdf drawing, the classifier tries to match your
32
sketch with symbols it knows about. The C Bits and pieces of
matching process is pretty good, even for
the sketches of a really poor draughtsman
(La)TeX
(such as the present author), and it’s of- 53 What is a DVI file?
ten worth trying more than once. ‘Detex-
ify apps’ are available for both Android ‘DVI’ is supposed to be an acronym for
and iPhone devices, you can use them to DeVice-Independent, meaning that the file
draw the symbol with your fingertip — a may be processed for printing or viewing
less challenging procedure than using your on most kinds of typographic output device
workstation’s mouse, by all accounts! or display.
A DVI file (that is, a file with the type
If you are using Unicode maths in Xe- or extension .dvi) is the main output file
TeX or LuaTeX, your own distribution of “original” TeX (later TeX-like systems,
ought to provide the Unicode maths sym- such as PDFTeX may use other formats).
bol table unimath-symbols.pdf; this A DVI file contains all the information
lists the things available in the commonly- that is needed for printing or previewing,
used mathematics fonts. (If the file isn’t except for the actual bitmaps or outlines of
already available on your system, you can fonts, and any material to be introduced by
download it from CTAN, where it live with means of \special commands. Charac-
the unicode-math package. ters in the DVI file (representing glyphs for
Other questions in this FAQ offer spe- printing or display) appear in an encoding
cific help on kinds of symbols: determined in the document.
Any TeX input file should produce the
same DVI file regardless of which imple-
• Script fonts for mathematics mentation of TeX is used to produce it.
• Fonts for the number sets An DVI file may be processed by a
• Typesetting the principal value inte- DVI driver to produce further output de-
gral signed specifically for a particular printer,
or for output in another format (for distri-
Symbol List: Browse bution), or it may be used by a previewer
info/symbols/comprehensive; for display on a computer screen.
there are processed versions PDF Note that XeTeX (released some time
form for both A4 and letter paper. after PDFTeX) uses an “extended DVI for-
mat” (XDV) to send its output to a close-
Unicode maths symbols: coupled DVI driver, xdvipdfmx.
Distributed as part of The canonical reference for the struc-
macros/latex/contrib/unicode-
ture of a DVI file is the source of Knuth’s
math
program dvitype (whose original purpose,
as its name implies, was to view the con-
tent of a DVI file). A partially complete
52 The PiCTeX manual “standard” for the way they should be pro-
cessed may offer further enlightenment.
PiCTeX is a set of macros by Michael
rmfamilyDVI processing standard :
Wichura for drawing diagrams and pic-
dviware/driv-standard
tures. The macros are freely available;
however, the PiCTeX manual itself is not dvitype: systems/knuth/dist/
free. Unfortunately, TUG is no longer able texware/dvitype.web
to supply copies of the manual (as it once
did), and it is now available only through 54 What is a DVI driver?
Personal TeX Inc, the vendors of PCTeX A DVI driver is a program that takes as
(http://www.pctex.com/). The manual input a DVI file and (usually) produces a
is not available electronically. file in a format that something other than a
TeX-related program can process.
However, there is a summary of
A driver may be designed for produc-
PiCTeX commands available on CTAN,
ing output for printing (e.g., PostScript),
which is a great aide-memoire for those
for later processing (e.g., PostScript for
who basically know the package to start
inclusion in a later document), or for docu-
with.
ment exchange (e.g., PDF).
PiCTeX : graphics/pictex As well as the DVI file, the driver typ-
ically also needs font information. Font
PiCTeX summary : information may be held as bitmaps or as
info/pictex/summary outlines, or simply as a set of pointers into
33
the fonts that a printer itself provides. Each typesetting commands, and the positioning
driver will expect the font information in a information that specifies how everything
particular form. comes together.
For more information on the forms of An early instance of something like
font information, see PK files, TFM files, virtual fonts for TeX was implemented
virtual fonts and Using PostScript fonts by David Fuchs to use an unusual printer.
with TeX. However, for practical purposes for the rest
of us, virtual fonts date from when Knuth
55 What are PK files?
specified a format and wrote some support
PK files (packed raster) are the canonical software, in 1989 (he published an article
form of TeX font bitmaps. The output from in TUGboat at the time; a plain text copy
Metafont includes a generic font (GF) file is available on CTAN).
and the utility gftopk produces a PK file Virtual fonts provide a way of telling
from that. TeX about something more complicated
There are potentially a lot of PK files, than just a one-to-one character mapping.
as one is needed for each font: that is for TeX reads a TFM file of the font, just as
each magnification of each design (point) before, but the DVI processor will read the
size for each weight for each font in each VF and use its content to specify how each
family. glyph is to be processed.
Further, since the PK files for one The virtual font may contain com-
printer do not necessarily work well for mands:
another, the whole set needs to be dupli-
cated for each printer type at a site. • to ‘open’ one or more (real) fonts for
While this menagerie of bitmaps can subsequent use,
(in principle) provide fonts that are closely • to remap a glyph from one of the (real)
matched to the capabilities of each printer, fonts for use in the virtual font,
the size of the collection (and the result- • to build up a more complicated effect
ing difficulty of maintaining it) has been a (using DVI commands).
potent driver to the move towards outline
fonts such as Adobe Type 1 fonts. In practice, the most common use
56 What are TFM files? of virtual fonts is to remap Adobe Type
1 fonts (see font metrics), though there
TFM is an acronym for ‘TeX Font Metrics’; has also been useful useful work build-
TFM files hold information about the sizes ing ‘fake’ maths fonts (by bundling glyphs
of the characters of the font in question, from several fonts into a single virtual
and about ligatures and kerns within that font). Virtual Computer Modern fonts,
font. One TFM file is needed for each font making a Cork encoded font from Knuth’s
used by TeX, that is for each design (point) originals by using remapping and frag-
size for each weight for each family; each ments of DVI for single-glyph ‘accented
TFM file serves for all magnifications of characters’, were the first “Type 1 format”
‘its’ font, so that there are (typically) fewer Cork-encoded Computer Modern fonts
TFM files than there are PK files. TeX, available.
LaTeX, etc., themselves need only know
Virtual fonts are normally created in a
about the sizes of characters and their inter-
single ASCII VPL (Virtual Property List)
actions with each other, but not what char-
file, which includes two sets of informa-
acters look like. By contrast, TFM files are
tion. The vptovf utility will use the VPL
not, in principle, needed by the DVI driver,
file to create the binary TFM and VF files.
which only needs to know about the glyphs
A “how-to” document, explaining how
that each character selects, so as to print or
to generate a VPL, describes the endless
display them.
hours of fun that may be had, doing the job
Note that TrueType and OpenType
by hand. Despite the pleasures to be had,
fonts contain the necessary metrics, so that
the commonest way (nowadays) of gen-
XeTeX and LuaTeX, using such fonts, have
erating an VPL file is to use the fontinst
no need of TFM files. A corollary of this
package, which is described in more de-
is that setting up fonts for use by these
tail PostScript font metrics. Qdtexvpl is
engines is far easier.
another utility for creating ad-hoc virtual
57 What are virtual fonts? fonts (it uses TeX to parse a description
Virtual fonts provide a means of collecting of the virtual font, and qdtexvpl itself pro-
bits and pieces together to make the glyphs cesses the resulting DVI file).
of a font: the bits and pieces may be glyphs fontinst:
from “other” fonts, rules and other “basic” fonts/utilities/fontinst
34
Knuth on virtual fonts: or, in LaTeX speak:
info/knuth/virtual-fonts
\newcommand{\foo}[1]{This is a #1 bar}
Virtual fonts “how to”: ...
info/virtualfontshowto/ \foo{3/4}.
virtualfontshowto.txt
which produces:
qdtexvpl:
fonts/utilities/qdtexvpl This is 3/4 bar.
58 What are (TeX) macros (LaTeX users waltz through life, perhaps?)
You will have noticed that the argu-
TeX is a macro processor: this is a
ments, above, were enclosed in braces
computer-science-y term meaning “text ex-
({...}); this is the normal way of typing
pander” (more or less); TeX typesets text
arguments, though TeX is enormously flex-
as it goes along, but expands each macro it
ible, and you may find all sorts of other
finds. TeX’s macros may include instruc-
ways of passing arguments (if you stick
tions to TeX itself, on top of the simple
with it).
text generation one might expect.
Macro writing can get very compli-
Macros are a good thing, since they
cated, very quickly. If you are a begin-
allow the user to manipulate documents ac-
ner (La)TeX programmer, you are well ad-
cording to context. For example, the macro
vised to read something along the lines of
\TeX is usually defined to produce “TEX”
the TeXbook; once you’re under way, TeX
with the ‘E’ lowered (the original idea was
by Topic is possibly a more satisfactory
Knuth’s), but in these FAQs the default def-
choice. Rather a lot of the answers in these
inition of the macro is overridden, and it
FAQs tell you about various issues of how
simply expands to the letters “TeX”. (You
to write macros.
may not think this a good thing, but the
author of the macros has his reasons – see 59 \special commands
TeX-related logos.) TeX provides the means to express things
Macro names are conventionally built that device drivers can do, but about which
from a \ followed by a sequence of letters, TeX itself knows nothing. For example,
which may be upper or lower case (as in TeX itself knows nothing about how to in-
\TeX, mentioned above). They may also clude PostScript figures into documents, or
be \hany single character i, which al- how to set the colour of printed text; but
lows all sorts of oddities (many built in to some device drivers do.
most TeX macro sets, all the way up from Instructions for such things are intro-
the apparently simple ‘\’ meaning “insert duced to your document by means of
a space here”). \special commands; all that TeX does
Macro programming can be a com- with these commands is to expand their ar-
plicated business, but at their very sim- guments and then pass the command to the
plest they need little introduction — you’ll DVI file. In most cases, there are macro
hardly need to be told that: packages provided (often with the driver)
\def\foo{bar}
that provide a human-friendly interface to
the \special; for example, there’s little
replaces each instance of \foo with the point including a figure if you leave no
text “bar”. The command \def is Plain gap for it in your text, and changing colour
TeX syntax for defining commands; LaTeX proves to be a particularly fraught opera-
offers a macro \newcommand that goes tion that requires real wizardry. LaTeX2e
some way towards protecting users from has standard graphics and colour packages
themselves, but basically does the same that make figure inclusion, rotation and
thing: scaling, and colour typesetting relatively
straightforward, despite the rather daunt-
\newcommand{\foo}{bar}
ing \special commands involved. (Con-
Macros may have “arguments” , which are TeXt provides similar support, though not
used to substitute for marked bits of the by way of packages.)
macro expansion: The allowable arguments of \special
depend on the device driver you’re using.
\def\foo#1{This is a #1 bar} Apart from the examples above, there are
... \special commands in the emTeX drivers
\foo{2/4}. (e.g., dvihplj, dviscr, etc.) that will draw
which produces: lines at arbitrary orientations, and com-
mands in dvitoln03 that permit the page
This is a 2/4 bar. to be set in landscape orientation.
35
Note that \special behaves rather dif- TeX refers to each open file by a num-
ferently in PDFTeX, since there is no de- ber, not by a file name (although most of
vice driver around. There is a concept of the time we hide this). Originally, TeX
PDF specials, but in most cases \special would write to a file connected to a stream
will provoke a warning when used in PDF- numbered 0–15. More recently, a special
TeX. “stream 18” has been implemented: it is
not writing to a file, but rather tells TeX
60 Writing (text) files from TeX to ask the operating system to do some-
TeX allows you to write to output files thing. To run a command, we put it as
from within your document. The facility the argument to \write18. So to run the
is handy in many circumstances, but it is epstopdf utility on a file with name stored
vital for several of the things LaTeX (and as \epsfilename, we would write:
indeed almost any higher-level TeX-based \write18{epstopdf \epsfilename}
macro package) does for you.
The basic uses of writing to an external When using something like the epstopdf
file are “obvious” — remembering titles of package, the ‘stream’ write operation is
sections for a table of contents, remember- hidden away and you don’t need to worry
ing label names and corresponding section about the exact way it’s done.
or figure numbers, all for a later run of your However, there is a security issue. If
document. However, the “non-obvious” you download some (La)TeX code from
thing is easy to forget: that page numbers, the Internet, can you be sure that there is
in TeX, are slippery beasts, and have to be not some command in it (perhaps in a hid-
captured with some care. The trick is that den way) to do stuff that might be harmful
\write operations are only executed as the to your computer (let’s say: delete every-
page is sent to the DVI or PDF file. Thus, if thing on the hard disk!)? In the face of this
you arrange that your page-number macro problem, both MiKTeX and TeX Live have,
(\thepage, in LaTeX) is not expanded un- for some time, disabled \write18 by de-
til the page is written, then the number fault. To turn the facility on, both distribu-
written is correct, since that time is where tions support an additional argument when
TeX guarantees the page number tallies starting TeX from the command shell:
with the page being sent out. (pdf)(la)tex --shell-escape <file>
Now, there are times when you want to The problem with this is that many people
write something straight away: for exam- use (La)TeX via a graphical editor, so to
ple, to interact with the user. TeX captures use \write18 for a file the editor’s settings
that requirement, too, with the primitive must be changed. Of course, the settings
command \immediate: need restoring after the file is processed:
you
\immediate\write\terminal{I’m waiting...}
defeat the point of the original protec-
tion, that way.
writes a “computer-irritates-user” message, The latest MiKTeX (version 2.9), and
to the terminal. recent TeX Live (from the 2010 release)
Which brings us to the reason for that get around this by having a special “lim-
\terminal. TeX can “\write” up to ited” version of \write18 enabled ‘out of
16 streams simultaneously, and that ar- the box’. The idea is to allow only a pre-set
gument to \write says which is to be list of commands (for example, BibTeX,
used. Macro packages provide the means epstopdf , TeX itself, and so on). Those
of allocating streams for your use: Plain on the list are regarded as safe enough to
TeX provides a macro \newwrite (used allow, whereas anything else (for example
as “\newwrite\streamname”, which sets deleting files) still needs to be authorised
\streamname as the stream number). In by the user. This seems to be a good bal-
fact, \terminal (or its equivalent) is the ance: most people most of the time will not
first output stream ever set up (in most need to worry about \write18 at all, but it
macro packages): it is never attached to will be available for things like epstopdf .
a file, and if TeX is asked to write to any Note that the TeX system may tell you
stream that isn’t attached to a file it will that the mechanism is in use:
send the output to the terminal (and the This is pdfTeX, Version 3.1415926-1.40.11 (TeX Live 201
log). restricted \write18 enabled.
In either case, we’re asking TeX to load (for example). This will almost invari-
files from the root disc temporary files di- ably return a pointer to a subdirectory
rectory; in the Unix case, the “empty slot” texmf of your home directory; the com-
is designated by putting the path separator monest exception is Macintoshes, using
‘:’ on its own at the end of the line, while MacTeX, where the diretory is convention-
in the Windows case, the technique is the ally Library/texmf in your home direc-
same, but the path separator is ‘;’. tory.
63
If you can confirm that the technique it should be converted to:
does indeed work, install your new pack-
age (or whatever) in the correct place in a HOMETEXMF = $HOME/texmf
tree based on $HOME/texmf, and generate TEXMF = {$HOMETEXMF,!!$LOCALTEXMF,!!$TEXMFMAIN}
an index of that tree % TEXMF = {!!$LOCALTEXMF,!!$TEXMFMAIN}
2 On the grounds that a command plain could be misconstrued as a reference to Plain TeX
78
• The need to decide which printers to fonts/ps-type1/cm-super
generate fonts for. The broad-brush Latin Modern fonts: fonts/lm
approach taken for 300 dpi printers
was (more or less) justified back then,
given the dominance of certain printer L Hypertext and PDF
‘engines’, but nowadays one could not
make any such assumption. 140 Making PDF documents from
• Given the above, it has been near- (La)TeX
impossible to justify the space that There are three general routes to PDF out-
would be required by a huge array of put: Adobe’s original ‘distillation’ route
bitmap fonts. (via PostScript output), direct conversion
of a DVI file, and the use of a direct TeX-
Fortunately, (La)TeX distribution technol-
like PDF generator such as PDFTeX.
ogy has put a stop to these arguments: most
For simple documents (with no hyper-
(if not all) current distributions generate
references), you can either
bitmap fonts as needed, and cache them
for later re-use. The impatient user, who is • process the document in the normal
determined that all bitmap fonts should be way, produce PostScript output and
created once and for all, may be supported distill it;
by scripts such as allcm (distributed with • (on a Windows or Macintosh machine
TeX Live, at least; otherwise such a person with appropriate tools installed) pass
should consult “the use of Metafont)”. the output through a PDFwriter in
If your output is to a PostScript- place of a printer driver. This route
capable device, or if your output is des- is only appropriate for simple docu-
tined to be converted to PDF, you should ments: PDF writers cannot create hy-
switch to using Type 1 versions of the CM perlinks;
fonts. Two free sets are available; the older • process the document with “vanilla”
(bakoma) is somewhat less well produced LaTeX and generate PDF direct from
than the bluesky fonts, which were origi- the DVI using dvipdfm/dvipdfmx; or
nally professionally produced and sold, but • process the document direct to PDF
were then released for general public use with PDFTeX, LuaTeX, or XeTeX.
by their originators Y&Y and Bluesky Re-
search, in association with the AMS and To translate all the LaTeX cross-
other scientific publishers (they are nowa- referencing into Acrobat links, you need
days available under the SIL’s Open Fonts a LaTeX package to redefine the in-
Licence). The two sets contain slightly ternal commands. There are two of
different ranges of fonts, but you are ad- these for LaTeX, both capable of con-
vised to use the bluesky set except when forming to the HyperTeX specification:
bakoma is for some reason absolutely un- Heiko Oberdiek’s hyperref , and Michael
avoidable. In recent years, several other Mehlich’s hyper. (In practice, almost ev-
‘Metafont’ fonts have been converted to eryone uses hyperref ; hyper hasn’t been
Type 1 format; it’s uncommon ever to need updated since 2000.) Hyperref can of-
to generate bitmap fonts for any purpose ten determine how it should generate hy-
other than previewing — see “previewing pertext from its environment, but there is
documents with Type 1 fonts” — if even a wide set of configuration options you
then. can give via \usepackage. The pack-
More modern fonts may be used in age can operate using PDFTeX primi-
place of the Computer Modern set. The tives, the hyperTeX \specials, or DVI
EC fonts and the Latin Modern fonts are driver-specific \special commands. Both
both close relatives with wider ranges of dvips and Y&Y’s DVIPSONE can trans-
glyphs to offer. late the DVI with these \special com-
mands into PostScript acceptable to Dis-
BaKoMa fonts:
tiller, and dvipdfm and dvipdfmx have
fonts/cm/ps-type1/bakoma
\special commands of their own.
Bluesky fonts: Distributed as part of If you use Plain TeX, the Eplain
fonts/amsfonts macros can help you create PDF doc-
CM fonts (write-black printers): uments with hyper-references. It
fonts/cm/pk/pk300.zip can operate using PDFTeX primi-
tives, or \special commands for the
CM fonts (write-white printers): dvipdfm/dvipdfmx DVI drivers.
fonts/cm/pk/pk300w.zip
While there is no free implementation
EC fonts (Type 1 format): of all of Adobe Distiller’s functionality,
79
any but the implausibly old versions of The HyperTeX specification says that
ghostscript provide pretty reliable distil- conformant viewers/translators must rec-
lation (but beware of the problems with ognize the following set of \special com-
dvips output for distillation). mands:
For viewing (and printing) the result-
ing files, Adobe’s Acrobat Reader is avail- href: html:<a href = "href_string">
able for a fair range of platforms; for those name: html:<a name = "name_string">
for which Adobe’s reader is unavailable, end: html:</a>
remotely current versions of ghostscript image: html:<img src = "href_string">
combined with gv or gsview can display base_name: html:<base href = "href_string">
and print PDF files, as can xpdf . The href, name and end commands are
In some circumstances, a ghostscript- used to do the basic hypertext operations
based viewer application is actually prefer- of establishing links between sections of
able to Acrobat Reader. For example, on documents.
Windows Acrobat Reader locks the .pdf Further details are available on http:
file it’s displaying: this makes the tradi- //arXiv.org/hypertex/; there are two
tional (and highly effective) (La)TeX devel- commonly-used implementations of the
opment cycle of “Edit→Process→Preview” specification, a modified xdvi and (recent
become rather clumsy — gsview doesn’t releases of) dvips. Output from the lat-
make the same <mistake. ter may be used in recent releases of
Acrobat Reader: download from ghostscript or Acrobat Distiller.
http://get.adobe.com/reader
143 Quality of PDF from PostScript
dvipdfm : dviware/dvipdfm
Any reasonable PostScript, including any
dvipdfmx : dviware/dvipdfmx output of dvips, may be converted to PDF,
gv : Browse support/gv using (for example) a sufficiently recent
version of ghostscript, Frank Siegert’s
hyper.sty : (shareware) PStill, or Adobe’s (commer-
macros/latex/contrib/hyper cial) Distiller.
hyperref.sty : But, although the job may (almost al-
macros/latex/contrib/hyperref ways) be done, the results are often not
acceptable: the most frequent problem is
141 Making hypertext documents bad presentation of the character glyphs
from TeX that make up the document. The following
If you want on-line hypertext with a answers offer solutions to this (and other)
(La)TeX source, probably on the World problems of bad presentation. Issues cov-
Wide Web, there are four technologies to ered are:
consider:
• Wrong type of fonts used, which is the
• start from (La)TeX, and use one of commonest cause of fuzzy text.
a number of techniques to translate • Ghostscript too old, which can also
(more or less) directly to HTML; result in fuzzy text.
• Start from texinfo source, and use • Switching to font encoding T1 en-
the info viewer, or convert the texinfo coding, which is yet another possible
source to HTML using texi2html; cause of fuzzy text.
• Start from (La)TeX; use PDFTeX, Xe- • Another problem — missing charac-
TeX or LuaTeX to produce PDF, using ters — arises from an aged version of
hyperref to construct hyperlinks. Adobe Distiller.
• Start from (unconventional) (La)TeX • Finally, there’s the common confusion
which use the hyperTeX conventions. that arises from using the dvips con-
figuration file -Ppdf, the weird char-
texinfo: macros/texinfo/texinfo acters.
142 The hyperTeX project It should be noted that Adobe Reader 6
The hyperTeX project extended the func- (released in mid-2003, and later versions)
tionality of all the LaTeX cross-referencing does not exhibit the “fuzziness” that so
commands (including the table of contents) many of the answers below address. This
to produce \special commands which is of course good news: however, it will
are parsed by DVI processors conforming inevitably be a long time before every user
to the HyperTeX guidelines; it provides in the world has this (or later) versions, so
general hypertext links, including those to the remedies below are going to remain for
external documents. some time to come.
80
The problems are also discussed, dvips: warning: no config file for ‘pdf’
with practical examples, in Mike Shell’s
or something similar, or about failing to
testflow package, which these FAQs rec-
find a font file:
ommend as a “specialised tutorial.
dvips: ! Couldn’t find header file cmr10.pfb
testflow : macros/latex/contrib/
IEEEtran/testflow Either of these failures signals that your
system doesn’t have the fonts in the first
144 The wrong type of fonts in PDF
place.
This is far the commonest problem: the A way of using the fonts that doesn’t in-
symptom is that text in the document looks volve the sophistication of the -Ppdf mech-
“fuzzy”. anism is simply to load maps:
Most people use Adobe Acrobat
dvips -Pcmz -Pamz myfile -o myfile.ps
Reader to view their PDF: Reader is dis-
tributed free of charge, and is widely avail- You may encounter the same warning mes-
able, for all its faults. One of those faults sages as listed above.
is its failure to deal with bitmap fonts (at If your system does not have the fonts,
least, in all versions earlier than version 6, it won’t have the configuration file either;
all of which copies are pretty old, now . . . however, it might have the configuration
but some are occasionally found). file without the fonts. In either case, you
So we don’t want bitmap fonts in our need to install the fonts.
PostScript: with them, characters show up
145 Fuzzy fonts because Ghostscript
in Reader’s display as blurred blobs which
too old
are often not even recognisable as the origi-
nal letter, and are often not properly placed So you’ve done everything the FAQ has
on the line. Nevertheless, even now, most told you that you need, correct fonts prop-
TeX systems have dvips configured to use erly installed and appearing in the dvips
.pk files in its output. Even PDFTeX will output, but still you get fuzzy character
use .pk files if it can see no alternative for output after distilling with ghostscript.
a font in the document it is processing. The problem could arise from too old
Our remedy is to use “Adobe Type 1” a version of ghostscript, which you may
versions of the fonts we need. Since Adobe be using directly, or via a script such as
are in the business of selling Type 1 fonts, ps2pdf (distributed with ghostscript itself),
Reader was of course made to deal with dvipdf , or similar. Though ghostscript was
them really rather well, from the very be- capable of distillation from version 5.50,
ginning. that version could only produce bitmap
Of course, if your document uses noth- Type 3 output of any font other than the
ing but fonts that came from Adobe in fundamental 35 fonts (Times, Helvetica,
the first place — fonts such as Times that etc.). Later versions added ‘complete’ dis-
appear in pretty much every PostScript tillation, but it wasn’t until version 6.50
printer, or such as Adobe Sabon that you that one could rely on it for everyday work.
pay extra for — then there’s no problem. So, if your PDF output still looks fuzzy
But most people use Computer Modern in Acrobat Reader, upgrade ghostscript.
to start with, and even those relative so- The new version should be at least ver-
phisticates who use something as exotic sion 6.50, of course, but it’s usually good
as Sabon often find themselves using odd policy to go to the most recent version (ver-
characters from CM without really intend- sion 8.12 at the time of writing — 2003).
ing to do so. Fortunately, rather good ver- 146 Fonts go fuzzy when you switch
sions of the CM fonts are available from to T1
the AMS (who have them courtesy of Blue You’ve been having problems with hy-
Sky Research and Y&Y). phenation, and someone has suggested
Most modern systems have the fonts that you should use “\usepackage[T1]
installed ready to use; and any system in- {fontenc}” to help sort them out. Sud-
stalled less than 3 years ago has a dvips denly you find that your final PDF has
configuration file ‘pdf’ that signals the use become fuzzy. The problem may arise
of the CM fonts, and also sets a few other whether you are using PostScript output
parameters to improve dvips’ output. Use and then distilling it, or you are using PDF-
this configuration as: TeX for the whole job.
dvips -Ppdf myfile -o myfile.ps In fact, this is the same problem as
most others about the quality of PDF:
This may produce a warning message you’ve abandoned your previous setup us-
about failing to find the configuration file: ing Type 1 versions of the CM fonts, and
81
dvips has inserted Type 3 versions of the 148 Finding ‘8-bit’ Type 1 fonts
EC fonts into your document output. (See Elsewhere, answers to these FAQs recom-
“Adobe font types for details of these font mend that you use an ‘8-bit’ font to permit
types; also, note that the font encoding T1 accentuation of inflected languages, and
has nothing directly to do with the font also recommend the use of Type 1 fonts
format Type 1). to ensure that you get good quality PDF.
However, as noted in 8-bit Type 1 fonts, These recommendations used to be contra-
Type 1 versions of CM-like fonts in T1 dictory: one could not just “switch” from
(or equivalent) encoding are now available, the free CM fonts to free Cork- (or simi-
both as “real” fonts, and as virtual font larly) encoded Type 1 fonts. The first ap-
sets. One solution, therefore, is to use one proach that started to alleviate these prob-
of these alternatives. lems, was the development of virtual fonts
The alternative is to switch font fam- that make a good approach to the Cork en-
ily altogether, to something like Times (as coding (see below). Now, however, we
a no-thought default) or one of the many have “true” Type 1 fonts available: as al-
more pleasing Adobe-encoded fonts. The ways, we have an embarrassment of riches
default action of fontinst, when creating with three free alternatives, and one com-
metrics for such a font, is to create settings mercial and one shareware version.
for both OT1 and T1 encodings, so there’s CM-super is an auto-traced set which
little change in what goes on (at the user encompasses all of the T1 and TS1 encod-
level) even if you have switched to T1 en- ings as well as the T2* series (the family of
coding when using the fonts. encodings that cover languages based on
Cyrillic alphabets). These fonts are pretty
147 Characters missing from PDF easy to install (the installation instructions
output are clear), but they are huge: don’t try to
install them if you’re short of disc space.
If you’re using Acrobat Distiller to cre- CM-LGC is a similar “super-font” set,
ate your PDF output, you may find charac- but of much more modest size; it cov-
ters missing. This may manifest itself as ers T1, TS1 and T2A encodings (as does
messed-up maths equations (missing “−” CM-super, and also covers the LGR encod-
signs, for example), or bits missing from ing (for typesetting Greek, based on Clau-
large symbols. Early versions of Distiller dio Beccari’s Metafont sources). CM-LGC
used to ignore character positions 0–31 manages to be small by going to the op-
and 128–159 of every font: Adobe’s fonts posite extreme from CM-super, which in-
never use such positions, so why should cludes fonts at all the sizes supported by
Distiller? the original EC (a huge range); CM-LGC
Well, the answer to this question is “be- has one font per font shape, getting other
cause Adobe don’t produce all the world’s sizes by scaling. There is an inevitable
fonts” — fonts like Computer Modern loss of quality inherent in this approach,
were around before Adobe came on the but for the disc-space-challenged machine,
scene, and they use positions 0–31. Adobe CM-LGC is an obvious choice.
don’t react to complaints like that in the Tt2001 is a simple scan of the EC and
previous sentence, but they do release new TC fonts, and has some virtues — it’s no-
versions of their programs; and Distiller, ticeably smaller than CM-super while be-
since at least version 4.0, has recognised ing less stark than CM-LGC.
the font positions it used to shun. Latin Modern is produced using the
Meanwhile, TeX users with old ver- program MetaType1. The Latin Modern
sions of Distiller need to deal with their set comes with T1, TS1 LY1 encoded vari-
fonts. Dvips comes to our aid: the switch ants (as well as a variant using the Polish
-G1 (“remap characters”), which moves QX encoding); for the glyph set it cov-
the offending characters out of the way. ers, its outlines seem rather cleaner than
The PDF configuration file (-Ppdf), rec- those of CM-super. Latin Modern is more
ommended above, includes the switch. modest in its disc space demands than is
The switch is not without its problems; CM-super, while not being nearly as stark
pre-2003 versions of dvips will apply it to in its range of design sizes as is CM-LGC —
Adobe fonts as well, causing havoc, but Latin Modern’s fonts are offered in the
fortunately that problem is usually soluble. same set of sizes as the original CM fonts.
However, a document using both CM and It’s hard to argue with the choice: Knuth’s
Adobe-specified fonts is stuck. The only range of sizes has stood the test of time,
real solution is either to upgrade dvips, or and is one of the bases on which the excel-
to spend money to upgrade Distiller. lence of the TeX system rests.
82
Virtual fonts help us deal with the prob- systems/win32/bakoma/fonts
lem, since they allow us to map “bits of CM-LGC fonts:
DVI file” to single characters in the vir- fonts/ps-type1/cm-lgc
tual font; so we can create an “é” charac-
ter by recreating the DVI commands that CM-super fonts:
would result from the code “\’e”. How- fonts/ps-type1/cm-super
ever, since this involves two characters be- (beware: very large download)
ing selected from a font, the arrangement Latin Modern fonts: fonts/lm
is sufficient to fool Acrobat Reader: you
tt2001 fonts: fonts/ps-type1/tt2001
can’t use the program’s facilities for search-
ing for text that contains inflected charac- zefonts: fonts/zefonts
ters, and if you cut text from a window that
149 Replacing Type 3 fonts in
contains such a character, you’ll find some-
PostScript
thing unexpected (typically the accent and
the ‘base’ characters separated by a space) One often comes across a PostScript file
when you paste the result. However, if you generated by dvips which contains embed-
can live with this difficulty, virtual fonts ded PK fonts; if you try to generate PDF
are a useful and straightforward solution from such a file, the quality will be poor.
to the problem. Of course, the proper solution is to re-
There are two virtual-font offerings of generate the PostScript file, but if neither
CM-based 8-bit fonts — the ae (“almost the sources nor the DVI file are available,
EC”) and zefonts sets; the zefonts set has one must needs resort to some sort of patch-
wider coverage (though the ae set may be ing to replace the bitmap fonts in the file
extended to offer guillemets by use of the by outline fonts.
aeguill package). Neither offers characters The program pkfix (by Heiko Oberdiek)
such as eth and thorn (used in, for exam- will do this patching, for files created by
ple, in Icelandic), but the aecompl package “not too old versions” of dvips: it finds
works with the ae fonts to provide the miss- the fonts to be replaced by examining the
ing characters from the EC fonts (i.e., as PostScript comments dvips has put in the
bitmaps). file. For each font, pkfix puts appropriate
The sole remaining commercial CM- TeX commands in a file, which it then pro-
like 8-bit font comes from Micropress, cesses and runs through dvips (with switch
who offer the complete EC set in Type 1 -Ppdf) to acquire an appropriate copy of
format, as part of their range of outline the font; these copies are then patched back
versions of fonts that were originally dis- into the original file.
tributed in Metafont format. See “commer- If your source file is older than pkfix
cial distributions”. can deal with, there’s still a modicum of
The shareware BaKoMa TeX distribu- hope: pkfix-helper examines the bitmap
tion offers a set of Type 1 EC fonts, as fonts in a document, compares them with
an extra shareware option. (As far as the the metric (.tfm) fonts on your system
present author can tell, these fonts are only and comes to a view of which font might
available to users of BaKoMa TeX: they be which. The program reports on “poor”
are stored in an archive format that seems matches, and there are options for confirm-
not to be publicly available.) ing, or replacing, its guesses. The tech-
Finally, you can use one of the myr- nique (which sounds implausible) is suc-
iad text fonts available in Type 1 format cessful enough to be worth a try.
(with appropriate PSNFSS metrics for T1 A further option is Frank Siegert’s
encoding, or metrics for some other 8-bit (shareware) PStill, which is capable of pro-
encoding such as LY1). However, if you cessing the PostScript it is distilling, and
use someone else’s text font (even some- one option is to replace bitmap fonts in the
thing as simple as Adobe’s Times family) file with Type 1 versions.
you have to find a matching family of math- pkfix : support/pkfix
ematical fonts, which is a non-trivial un-
pkfix-helper :
dertaking — “choice of scalable fonts”.
support/pkfix-helper
ae fonts: fonts/ae
150 Hyperref and repeated page
aecompl.sty : Distributed with
numbers
fonts/ae
The book class (and its friends and rela-
aeguill.sty :
tions) automatically changes the display of
macros/latex/contrib/aeguill
page numbers in the frontmatter of the doc-
BaKoMa fonts: Browse ument to lower-case roman. This is fine
83
for human readers, but if hyperref has been OT1 or T1, your document will be OK for
misconfigured, the existence of pages have almost all ASCII characters, but it’s likely
the same page number can cause problems. that anything “out of the ordinary” will not
Fortunately, the configuration options to be represented properly. (Of course, PDF
make hyperref “do the right thing” are (by generated from XeTeX- or LuaTeX-based
default) set up to avoid problems. formats is going to be OK, since those en-
The two options in question are: gines work in Unicode througout.)
The solution comes from the character-
plainpages=false Make page anchors mapping facilities in the PDF specification:
using the formatted form of the page the file may specify a table of translations
number. With this option, hyperref of characters present in the coding used in
writes different anchors for pages ‘ii’ the file, to a Unicode version of the charac-
and ‘2’. (This is the default value for ters.
the option, which is a good thing. . . ) Packages cmap and mmap both offer
If the option is set ‘true’ hyperref means of generating such tables (mmap
writes page anchors as the arabic form has wider coverage, including the various
of the page number, rather than the maths encodings); both work with PDF-
formatted form that gets printed; this TeX and no other engine. Thus your docu-
is not usually appropriate. ment becomes something like:
pdfpagelabels Set PDF page labels; i.e.,
write the value of \thepage to the \documentclass{article}
PDF file so that Acrobat Reader can \usepackage{mmap} % (or cmap)
display the page number as (say) ‘ii (4 \usepackage[T1]{fontenc}
of 40)’ rather than simply ‘4 of 40’. ... % your other packages
\begin{document}
The two should be used whenever page ... % your actual text
numbering is not just ‘1..n’; they may be
used independently, but usually are not. Unfortunately, the packages only work
The recipe isn’t perfect: it relies on with fonts that are directly encoded, such
\thepage being different for every page in as the default (Computer Modern, i.e.,
the document. A common problem arises cm fonts, and things such as cm-super
when there is an unnumbered title page, or the Latin Modern sets. Fonts like
after which page numbers are reset: the Adobe Times Roman (which are encoded
PDFTeX warning of “duplicate destina- for (La)TeX use via virtual fonts) are not
tions” will happen in this case, regardless amenable to this treatment.
of the options. cmap.sty :
hyperref.sty : macros/latex/contrib/cmap
macros/latex/contrib/hyperref cm-super fonts:
151 Copy-paste-able/searchable PDF fonts/ps-type1/cm-super
files Latin Modern fonts: fonts/lm
PDF files generated from TeX (and mmap.sty :
friends), will by default hold their text in macros/latex/contrib/mmap
the encoding of the original TeX font used
by the document.
When PDF readers, etc., offer copy- M Graphics
paste or searching functions, the operations
take place on the glyph codes used for the 152 Importing graphics into (La)TeX
fonts selected by the document. This is documents
fine, for the simplest documents (in En- Knuth, when designing the current ver-
glish, at least); the problem comes when sion of TeX back in the early 1980s, could
you’re using an inflected language (with discern no “standard” way of expressing
accented letters, or composite glyphs such graphics in documents. He reasoned that
as ‘æ’) — TeX will typically use a non- this state could not persist for ever, but that
standard encoding, and there are likely be it would be foolish for him to define TeX
problems, since PDF readers assume the primitives that allowed the import of graph-
text is presented in Unicode. ical image definitions. He therefore de-
For PDF generated from LaTeX (the ferred the specification of the use of graph-
DVI being converted, by whatever means), ics to the writers of DVI drivers; TeX doc-
or from PDFLaTeX, the character codes uments would control the drivers by means
used in the PDF file are in fact those of the of \special commands (\special com-
document’s font encoding; if you’re using mands).
84
There is therefore a straightforward many other things. While this is all a con-
way for anyone to import graphics into venience (at some cost of syntax), it is also
their document: read the specification of capable of producing noticeably more ef-
the \special commands your driver uses, ficient PostScript, and some of its combi-
and ‘just’ code them. This is the hair-shirt nations are simply not possible with the
approach: it definitely works, but it’s not graphics package version.
for everyone. The epsfig package provides the same
Over the years, therefore, “graphics in- facilities as graphicx, but via a \psfig
clusion” packages have sprung up; most command (also known as \epsfig), capa-
were designed for inclusion of Encapsu- ble of emulating the behaviour (if not the
lated PostScript graphics (Encapsulated bugs) the old psfig package. Epsfig also
PostScript graphics) — which has become supplies homely support for former users
the lingua franca of graphics inclusion of the epsf package. However, there’s a
over the last decade or so. support issue: if you declare you’re using
Notable examples are the epsf pack- epsfig, any potential mailing list or usenet
age (distributed with dvips) and the psfig helper has to clear out of the equation the
package. (Both of these packages were de- possibility that you’re using “old” epsfig,
signed to work well with both Plain TeX so that support is slower coming than it
and LaTeX 2.09; they are both still avail- would otherwise be.
able.) All such packages were tied to a There is no rational reason to stick with
particular DVI driver (dvips, in the above the old packages, which have never been
two cases), but their code could be config- entirely satisfactory in the LaTeX context.
ured for others. (One irrational reason to leave them be-
The obvious next step was to make hind is that their replacement’s name tends
the code configurable dynamically. The not to imply that it’s exclusively related to
LaTeX standard graphics package and its PostScript graphics. The reasoning also
derivatives made this step: it is strongly excludes epsfig, of course.)
preferred for all current work. A wide variety of detailed techniques
Users of Plain TeX have two options and tricks have been developed over the
allowing them to use graphicx: the miniltx years, and Keith Reckdahl’s epslatex out-
“LaTeX emulator” and the graphicx.tex lines them in compendious detail: this
front-end allow you to load graphicx, and highly recommendable document is avail-
Eplain allows you to load it (using the full able from CTAN. An invaluable review of
LaTeX syntax) direct. the practicalities of exchanging graphics
The graphics package takes a variety between sites, “Graphics for Inclusion in
of “driver options” — package options that Electronic Documents” has been written
select code to generate the commands ap- by Ian Hutchinson; the document isn’t on
propriate to the DVI driver in use. In most CTAN, but may also be browsed on the
cases, your (La)TeX distribution will pro- Web.
vide a graphics.cfg file that will select epsf.tex :
the correct driver for what you’re doing macros/generic/epsf/epsf.tex
(for example, a distribution that provides epsfig.sty : Part of the macros/
both LaTeX and PDFLaTeX will usually latex/required/graphics bundle
provide a configuration file that determines
whether PDFLaTeX is running, and selects epslatex.pdf : info/epslatex
the definitions for it if so). graphics.sty : macros/latex/
The graphics package provides a required/graphics
toolkit of commands (insert graphics, scale
graphicx.sty : Part of the macros/
a box, rotate a box), which may be com-
latex/required/graphics bundle
posed to provide most facilities you need;
the basic command, \includegraphics, miniltx.tex :
takes one optional argument, which speci- macros/plain/graphics
fies the bounding box of the graphics to be psfig.sty : graphics/psfig
included.
The graphicx package uses the fa- 153 Imported graphics in dvips
cilities of of graphics behind a rather Dvips, as originally conceived, can only
more sophisticated command syntax import a single graphics format: encap-
to provide a very powerful version sulated PostScript (.eps files, encapsu-
of the \includegraphics command. lated PostScript). Dvips also deals with
graphicx’s version can combine scaling the slightly eccentric EPS that is created
and rotation, viewporting and clipping, and by Metapost.
85
Apart from the fact that a depressing The commonest problem users en-
proportion of drawing applications pro- counter, when switching from TeX, is
duce corrupt EPS when asked for such out- that there is no straightforward way to in-
put, this is pretty satisfactory for vector clude EPS files: since PDFTeX is its own
graphics work. “driver”, and since it contains no means of
To include bitmap graphics, you converting PostScript to PDF, there’s no
need some means of converting them to direct way the job can be done.
PostScript; in fact many standard im- The simple solution is to convert the
age manipulators (such as ImageMagick’s EPS to an appropriate PDF file. The
convert) make a good job of creating EPS epstopdf program will do this: it’s avail-
files (but be sure to ask for output at able either as a Windows executable or as
PostScript level 2 or higher). (Unix users a Perl script to run on Unix and other simi-
should beware of xv’s claims: it has a ten- lar systems. A LaTeX package, epstopdf ,
dency to downsample your bitmap to your can be used to generate the requisite PDF
screen resolution.) files “on the fly”; this is convenient, but
Special purpose applications jpeg2ps requires that you suppress one of TeX’s
(which converts JPEG files using security checks: don’t allow its use in files
PostScript level 2 functionality), bmeps from sources you don’t entirely trust.
(which converts both JPEG and PNG files) The package pst-pdf permits other
and a2ping/sam2p (which convert a bewil- things than ‘mere’ graphics files in its ar-
dering array of bitmap formats to EPS or gument. Pst-pdf operates (the authors sug-
PDF files; sam2p is one of the engines that gest) “like BibTeX” — you process your
a2ping uses) are also considered “good file using PDFLaTeX, then use LaTeX,
bets”. dvips and ps2pdf in succession, to pro-
Bmeps comes with patches to produce duce a secondary file to input to your next
your own version of dvips that can cope PDFLaTeX run. (Scripts are provided to
with JPEG and PNG direct, using bmeps’s ease the production of the secondary file.)
conversion library. Dvips, as distributed by A further extension is auto-pst-pdf ,
MiKTeX, comes with those patches built- which generates PDF (essentially) trans-
in, but assuming that capability destroys parently, by spawning a job to process out-
portability, and is only recommendable if put such as pst-pdf uses. If your PDFLa-
you are sure you will never want to share TeX installation doesn’t automatically al-
your document. low it — see spawning a process — then
you need to start PDFLaTeX with:
a2ping : graphics/a2ping
177 ‘Multi-letter’ initials in BibTeX The same trick can be played if you’re en-
tering whole names:
If your bibliographic style uses initials +
surname, you may encounter a problem ...
with some transcribed names (for exam- author = {Epifanov, Sasha {\relax Yu}ri and
ple, Russian ones). Consider the following ...
example from the real world:
(though no guarantee, that either of those
@article{epifanov1997, names is right, is offered!) However, if
you’re
author = {Epifanov, S. Yu. and typing the
Vigasin, A. names
A.}, in the “natural”
title = ... (Western) way, with given names first, the
} trick:
98
... Don’t try to tell BibTeX anything but the
author file Forster
= {P.M. {\relax de F.} name: sayand
bibtex myfile.aux (be-
... cause you know it’s going to read the .aux
file) and BibTeX will blindly attempt to
doesn’t work — “de F. Forster” is treated process myfile.aux.aux.
as a compound family names. BibTeX will scan the .aux file; it will
find which bibliography style it needs to
N.2 Creating citations use, and will “compile” that style; it will
note the citations; it will find which bibli-
178 “Normal” use of BibTeX from
ography files it needs, and will run through
LaTeX
them matching citations to entries in the
To create a bibliography for your docu- bibliography; and finally it will sort the
ment, you need to perform a sequence of entries that have been cited (if the bibliog-
steps, some of which seem a bit odd. If raphy style specifies that they should be
you choose to use BibTeX, the sequence sorted), and outputs the resulting details to
is: a .bbl file.
First: you need a BibTeX bibliography Fifth: you run LaTeX again. It warns,
file (a .bib file) — see “creating a BibTeX again, that each citation is (still) undefined,
file”. but when it gets to the \bibliography
Second: you must write your LaTeX command, it finds a .bbl file, and reads
document to include a declaration of the it. As it encounters each \bibitem com-
‘style’ of bibliography, citations, and a ref- mand in the file, it notes a definition of the
erence to the bibliography file mentioned citation.
above. So we may have a LaTeX file con- Sixth: you run LaTeX yet again. This
taining: time, it finds values for all the citations,
in its .aux file. Other things being equal,
\bibliographystyle{plain} you’re done. . . until you change the file.
... If, while editing, you change any of
Pooh is heroic~\cite{Milne:1926}. the citations, or add new ones, you need to
... go through the process above from steps 3
Alice struggles~\cite{Carroll:1865}. (first run of LaTeX) to 6, again, before the
... document is once again stable. These four
\bibliography{mybooks} mandatory runs of LaTeX make processing
a document with a bibliography even more
Note: we have bibliography style plain, tiresome than the normal two runs required
above, which is nearly the simplest to resolve labels.
of the lot: a sample text, show- To summarise: processing to resolve ci-
ing the sorts of style choices avail- tations requires: LaTeX; BibTeX; LaTeX;
able, can be found on Ken Turner’s LaTeX.
web site: http://www.cs.stir.ac.uk/
~kjt/software/latex/showbst.html 179 Choosing a bibliography style
Third: you must process the file. A large proportion of people are satis-
fied with one of Patashnik’s original “stan-
latex myfile dard” styles, plain, unsrt, abbrv and alpha.
However, no style in that set supports the
As LaTeX processes the file, the “author-date” citation style that is popular
\bibliographystyle command writes in many fields; but there are a very large
a note of the style to the .aux file; number of contributed styles available, that
each \cite command writes a note of do support the format.
the citation to the .aux file, and the (Note that author-date styles arose be-
\bibliography command writes a note cause the simple and clear citation style
of which .bib file is to be used, to the that plain produces is so awkward in a tra-
.aux file. ditional manuscript preparation scenario.
Note that, at this stage, LaTeX isn’t However, TeX-based document production
“resolving” any of the citations: at every does away with all those difficulties, leav-
\cite command, LaTeX will warn you ing us free once again to use the simple
of the undefined citation, and when the option.)
document finishes, there will be a further Fortunately, help is at hand, on the
warning of undefined references. Web, with this problem:
Fourth: you must run BibTeX:
• a sample text, showing the sorts of
bibtex myfile style choices available, can be found
99
on Ken Turner’s web site; Some text \cite{this}
• an excellent survey, that lists a huge with citations \cite{that}.
variety of styles, sorted into their nom- \printbibliography
inal topics as well as providing a good \end{refsection}
range of examples, is the Reed Col-
lege “Choosing a BibTeX style”. Then process with LaTeX (of what-
ever flavour) and use biber to pro-
Of course, these pages don’t cover ev- cess the bibliography output. Note
erything; the problem the inquisitive user that \printbibliography can take an
faces, in fact, is to find what the various optional argument heading=bib title
available styles actually do. This is best to provide the bibliography with a
achieved (if the links above don’t help) by (sub)section title.
using xampl.bib from the BibTeX docu-
biber : biblio/biber
mentation distribution: one can get a pretty
good feel for any style one has to hand us- biblatex :
ing this “standard” bibliography. For style macros/latex/contrib/biblatex
my-style.bst, the simple LaTeX document: bibunits.sty :
macros/latex/contrib/bibunits
\documentclass{article}
\begin{document} chapterbib.sty : distributed as part of
\bibliographystyle{my-style} macros/latex/contrib/cite
\nocite{*}
181 Multiple bibliographies?
\bibliography{xampl}
\end{document} If you’re thinking of multiple bibliogra-
phies tied to some part of your document
will produce a representative sample of the (such as the chapters within the document),
citations the style will produce. (Because please see bibliographies per chapter.
xampl.bib is so extreme in some of its “ex- For more than one bibliography, there
amples”, the BibTeX run will also give you are three options.
an interesting selection of BibTeX’s error The multibbl package offers a very
messages. . . ) simple interface: you use a command
xampl.bib: \newbibliography to define a bibliogra-
biblio/bibtex/base/xampl.bib phy “tag”. The package redefines the other
bibliography commands so that each time
180 Separate bibliographies per
you use any one of them, you give it the tag
chapter?
for the bibliography where you want the
A separate bibliography for each ‘chapter’ citations to appear. The \bibliography
of a document can be provided with the command itself also takes a further extra
package chapterbib (which comes with a argument that says what title to use for the
bunch of other good bibliographic things). resulting section or chapter (i.e., it patches
The package allows you a different bibli- \refname and \bibname — \refname
ography for each \included file (i.e., de- and \bibname — in a babel-safe way). So
spite the package’s name, the availability one might write:
of bibliographies is related to the compo-
nent source files of the document rather \usepackage{multibbl}
than to the chapters that logically structure \newbibliography{bk}
the document). \bibliographystyle{bk}{alpha}
The package bibunits ties bibliogra- \newbibliography{art}
phies to logical units within the document: \bibliographystyle{art}{plain}
the package will deal with chapters and ...
sections (as defined by LaTeX itself) and \cite[pp.~23--25]{bk}{milne:pooh-corner}
also defines a bibunit environment so ...
that users can select their own structuring. \cite{art}{einstein:1905}
The biblatex package, with biber, pro- ...
vides a similar facility; enclose the text \bibliography{bk}{book-bib}{References to books}
for which you want a local bibliography \bibliography{art}{art-bib}{References to articles}
in a refsection environment, and place
a \printbibliography command as the (Note that the optional argument of \cite
last thing in that environment: appears before the new tag argument, and
that the \bibliography commands may
\begin{refsection} list more than one .bib file — indeed all
\chapter{First chapter} \bibliography commands may list the
\section{Foo} same set of files.)
100
The \bibliography data goes into Note the different way of specifying a bib-
files whose names are htag-namei.aux, so liographystyle: if you want a different style
you will need to run for a particular bibliography, you may give
it as an optional argument to the btSect
bibtex bk
environment.
bibtex art
Processing with BibTeX, in this case,
after the first run of LaTeX, to get the cita- uses .aux files whose names are derived
tions in the correct place. from the name of the base document. So
The multibib package allows you to de- in this example you need to say:
fine a series of “additional topics”, each of
which comes with its own series of bibli- bibtex diss1
ography commands. So one might write: bibtex diss2
pdfpages.sty : europecv.cls:
macros/latex/contrib/pdfpages macros/latex/contrib/europecv
Andrej Brodnik’s class, vita, offers a frame- LaTeX itself provides a letter document
work for producing a curriculum vitae. class, which is widely disliked; the present
The class may be customised both for sub- author long since gave up trying with it.
ject (example class option files support If you nevertheless want to try it, but are
both computer scientists and singers), and irritated by its way of vertically-shifting a
for language (both the options provided are single-page letter, try the following hack:
available for both English and Slovene). \makeatletter
Extensions may be written by creating new \let\@texttop\relax
class option files, or by using macros de- \makeatother
fined in the class to define new entry types,
etc. in the preamble of your file.
Didier Verna’s class, curve, is based Doing-it-yourself is a common strat-
on a model in which the CV is made of a egy; Knuth (for use with Plain TeX, in
set of rubrics (each one dealing with a ma- the TeXbook), and Kopka and Daly (in
jor item that you want to discuss, such as their Guide to LaTeX) offer worked exam-
‘education’, ‘work experience’, etc). The ples. (The latest version of Knuth’s macros
class’s documentation is supported by a appear in his “local library” dump on the
couple of example files, and an emacs archive, which is updated in parallel with
mode is provided. new versions of TeX — so not very of-
Xavier Danaux offers a class moderncv ten. . . )
which supports typesetting modern curric- Nevertheless, there are contributed al-
ula vitarum, both in a classic and in a ca- ternatives — in fact there are an awfully
sual style. It is fairly customizable, allow- large number of them: the following list,
ing you to define your own style by chang- of necessity, makes but a small selection.
ing the colours, the fonts, etc. The largest, most comprehensive, class
The European Commission has recom- is newlfm; the lfm part of the name implies
mended a format for curricula vitarum that the class can create letters, faxes and
within Europe, and Nicola Vitacolonna has memoranda. The documentation is volumi-
developed a class europecv to produce it. nous, and the package seems very flexible.
While (by his own admission) the class Other classes recommended for inclu-
doesn’t solve all problems, it seems well- sion in this FAQ are akletter and isodoc.
thought out and supports all current official The dinbrief class, while recom-
EU languages (together with a few non- mended, is only documented in German.
official languages, such as Catalan, Gali- There are letter classes in each of
cian and Serbian). the excellent KOMA-script (scrlttr2: doc-
The alternative to using a separate class umentation is available in English) and
is to impose a package on one of the stan- ntgclass (brief : documentation in Dutch
dard classes. An example, Axel Reichert’s only) bundles. While these are probably
currvita package, has been recommended good (since the bundles themselves inspire
110
trust) they’ve not been specifically recom- (users should avoid becoming excited
mended by any users. about that. . . ). The package suffers from
akletter.cls: the same problem as does extsizes: the re-
macros/latex/contrib/akletter sulting font sizes are the only feature of
the document that is changed, and the ap-
brief.cls: Distributed as part of
pearance of the resulting document will
macros/latex/contrib/ntgclass
probably not be as good as if the document
dinbrief.cls: class had been designed for use at the size
macros/latex/contrib/dinbrief chosen.
isodoc.cls: Many classes, designed to produce
macros/latex/contrib/isodoc typeset results other than on “ordinary” pa-
per, will have their own font size mecha-
Knuth’s letter.tex: systems/knuth/
nisms and ranges of sizes. This is true,
local/lib/letter.tex
for example, of poster classes (such as
newlfm.cls: a0poster), and of presentation and lectur-
macros/latex/contrib/newlfm ing classes (such as beamer.
scrlttr2.cls: Distributed as part of a0poster.cls:
macros/latex/contrib/koma- macros/latex/contrib/a0poster
script
beamer.cls:
201 Other “document font” sizes? macros/latex/contrib/beamer
The LaTeX standard classes have a concept extsizes bundle:
of a (base) “document font” size; this size macros/latex/contrib/extsizes
is the basis on which other font sizes (those
from \tiny to \Huge) are determined. The KOMA script bundle:
macros/latex/contrib/koma-
classes are designed on the assumption that
script
they won’t be used with sizes other than
the set that LaTeX offers by default (10– memoir.cls:
12pt), but people regularly find they need macros/latex/contrib/memoir
other sizes. The proper response to such scrextend.sty : Distributed as part
a requirement is to produce a new design of macros/latex/contrib/koma-
for the document, but many people don’t script
fancy doing that.
A simple solution is to use the extsizes O.2 Document structure
bundle. This bundle offers “extended” ver-
sions of the article, report, book and letter 202 The style of document titles
classes, at sizes of 8, 9, 14, 17 and 20pt asThe titling package provides a number
well as the standard 10–12pt. Since little of facilities that permit manipulation of
has been done to these classes other than to the appearance of a \maketitle com-
adjust font sizes and things directly relatedmand, the \thanks commands within it,
to them, they may not be optimal — but and so on. The package also defines
they are at least practical. a titlingpage environment, that offers
More satisfactory are the KOMA-script something in between the standard classes’
classes, which are designed to work prop- titlepage option and the titlepage en-
erly with the class option files that come vironment, and is itself somewhat config-
with extsizes, and the memoir class that urable.
has its own options for document font The memoir class includes all the func-
sizes 9pt–12pt, 14pt, 17pt, 20pt, 25pt, 30pt,tionality of the titling package, while the
36pt, 48pt and 60pt. The classes also offer KOMA-script classes have their own range
size setup for any old font size, and the of different titling styles.
scrextend package can extend this facility Finally, the indefatigable Vincent
for use with any class: Zoonekynd supplies examples of how to
program alternative title styles. The web
\usepackage[fontsize=12.3]{scrextend}
page is not useful to users unless they are
will indeed set up the main document font willing to do their own LaTeX program-
to have size 12.3pt with an appropriate ming.
default baselineskip. The package “knows” KOMA script bundle:
about KOMA-script’s default sizes, and for macros/latex/contrib/koma-
eccentric sizes such as the example, it will script
produce a warning:
memoir.cls:
Using fallback calculation to setupmacros/latex/contrib/memoir
font sizes
111
titling.sty : provide programming examples, and ex-
macros/latex/contrib/titling pect users to adapt them to their own La-
TeX use.
203 The style of section headings
anonchap.sty :
Suppose that the editor of your favourite macros/latex/contrib/anonchap
journal has specified that section headings fncychap.sty :
must be centred, in small capitals, and sub- macros/latex/contrib/fncychap
section headings ragged right in italic, but
that you don’t want to get involved in the KOMA script bundle:
sort of programming described in section macros/latex/contrib/koma-
2.2 of The LaTeX Companion (see LaTeX script
books; the programming itself is discussed memoir.cls:
elsewhere in this FAQ). The following macros/latex/contrib/memoir
hack will probably satisfy your editor. De- sectsty.sty :
fine yourself new commands macros/latex/contrib/sectsty
\newcommand{\ssection}[1]{% titlesec.sty :
macros/latex/contrib/titlesec
\section[#1]{\centering\normalfont\scshape #1}}
\newcommand{\ssubsection}[1]{% tocbibind.sty : macros/latex/
\subsection[#1]{\raggedright\normalfont\itshape #1}}
contrib/tocbibind
222 Changing margins “on the fly” to make the page one line longer, or
One of the surprises characteristic of TeX \enlargethispage{-\baselineskip}
use is that you cannot change the width
or height of the text within the document, to make the page one line shorter. The
simply by modifying the text size param- process is (to an extent) simplified by the
eters; TeX can’t change the text width on addlines package: its \addlines com-
the fly, and LaTeX only ever looks at text mand takes as argument the number of
height when starting a new page. lines to add to the page (rather than a
So the simple rule is that the pa- length): the package documentation also
rameters should only be changed in the provides a useful analysis of when the com-
preamble of the document, i.e., before the mand may (or may not) be expected to
\begin{document} statement (so before work.
any typesetting has happened. addlines.sty :
To adjust text width within a document macros/latex/contrib/addlines
we define an environment:
changepage.sty : macros/latex/
\newenvironment{changemargin}[2]{% contrib/changepage
\begin{list}{}{%
223 How to get rid of page numbers
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%Very occasionally, one wants a document
with no page numbers. For such occa-
\setlength{\rightmargin}{#2}%
sions, the package nopageno will make
\setlength{\listparindent}{\parindent}%
\pagestyle{plain}
\setlength{\itemindent}{\parindent}% have the same effect
as
\setlength{\parsep}{\parskip}% \pagestyle{empty} ; in simple doc-
}% uments, this will suppress all page num-
\item[]}{\end{list}} bering (it will not work, of course, if the
document uses some other pagestyle than
The environment takes two arguments, and plain).
will indent the left and right margins, re- To suppress page numbers from
spectively, by the parameters’ values. Neg- a sequence of pages, you may use
ative values will cause the margins to \pagestyle{empty} at the start of the
be narrowed, so \begin{changemargin} sequence, and restore the original page
{-1cm}{-1cm} narrows the left and right style at the end. Unfortunately, you still
margins by 1 centimetre. have to deal with the page numbers on
Given that TeX can’t do this, how does pages containing a \maketitle, \part
it work? — well, the environment (which or \chapter command, since the standard
is a close relation of the LaTeX quote envi- classes; deal with those separately, as de-
ronment) doesn’t change the text width as scribed below.
far as TeX is concerned: it merely moves To suppress page numbers on a
text around inside the width that TeX be- single page, use \thispagestyle
lieves in. {empty} somewhere within the text of
121
the page. Note that, in the standard KOMA script bundle:
classes, \maketitle and \chapter use macros/latex/contrib/koma-
\thispagestyle internally, so your call script
must be after those commands. memoir.cls:
Unfortunately, \thispagestyle macros/latex/contrib/memoir
doesn’t work for book or report \part
nonumonpart.sty : macros/latex/
commands: they set the page style (as
contrib/nonumonpart
do \chapter commands), but then they
advance to the next page so that you have nopageno.sty :
no opportunity to change the style using macros/latex/contrib/nopageno
\thispagestyle. The present author scrpage2.sty : Distributed as part of
has proposed solving the problem with macros/latex/contrib/koma-
the following “grubby little patch”, on script
comp.text.tex:
224 How to create crop marks
\makeatletter If you’re printing something that’s eventu-
\let\sv@endpart\@endpart ally to be reproduced in significant quanti-
\def\@endpart{\thispagestyle{empty}\sv@endpart}
ties, and bound, it’s conventional to print
\makeatother on paper larger than your target product,
and to place “crop marks” outside the
Fortunately, that patch has now been incor-
printed area. These crop marks are avail-
porated in a small package nonumonpart
able to the production house, for lining up
(a difficult name. . . )
reproduction and trimming machines.
Both the KOMA-script classes and
You can save yourself the (consider-
memoir have separate page styles for the
able) trouble of programming these marks
styles of various “special” pages, so, in a
for yourself by using the package crop,
KOMA class document one might say:
which has facilities to satisfy any con-
ceivable production house. Users of the
\renewcommand*{\titlepagestyle}{empty}
memoir class don’t need the package, since
while memoir will do the job with memoir has its own facilities for program-
ming crop marks.
\aliaspagestyle{title}
crop.sty :
{empty}
macros/latex/contrib/crop
An alternative (in all classes) is to memoir.cls:
use the rather delightful \pagenumbering macros/latex/contrib/memoir
{gobble}; this has the simple effect
that any attempt to print a page num- 225 ‘Watermarks’ on every page
ber produces nothing, so there’s no is- It’s often useful to place some text (such
sue about preventing any part of LaTeX as ‘DRAFT’) in the background of every
from printing the number. However, the page of a document. For LaTeX users, the
\pagenumbering command does have the simplest way to do this uses the draftcopy
side effect that it resets the page number package. This can deal with many types of
(to 1), so it is unlikely to be helpful other DVI processors (in the same way that the
than at the beginning of a document. graphics package does) and knows trans-
The scrpage2 package separates out lations for the word ‘DRAFT’ into a wide
the representation of the page number (it range of languages (though you can choose
typesets the number using the \pagemark your own word, too). Unfortunately, how-
command) from the construction of the ever, the package relies on PostScript spe-
page header and footer; so one can say cials, and will therefore fail if you are view-
ing your document with xdvi, and won’t
\renewcommand*{\pagemark}{} even compile if you’re using PDFLaTeX.
(PDFLaTeX users need one of the other
which will also suppress the printing of the solutions below.)
page number. The wallpaper package builds on eso-
Neither of these “suppress the page pic (see below). Apart from the single-
number” techniques touches the page image backdrops described above (“wall-
style in use; in practice this means they papers”, of course, to this package), the
don’t make sense unless you are using package provides facilities for tiling im-
\pagestyle{plain} ages. All its commands come in pairs: one
fancyhdr.sty : for “general” use, and one applying to the
macros/latex/contrib/fancyhdr current page only.
122
The draftwatermark package uses the wallpaper.sty : macros/latex/
same author’s everypage package to pro- contrib/wallpaper
vide a simple interface for adding textual
(‘DRAFT’-like) watermarks. 226 Typesetting things in landscape
The xwatermark package provides very orientation
flexible watermarking, with a “modern” It’s often necessary to typeset part of a doc-
(key-value) interface. ument in landscape orientation; to achieve
More elaborate watermarks may be this, one needs not only to change the page
achieved using the eso-pic package, or by dimensions, but also to instruct the output
using everypage (see below). Eso-pic at- device to print the strange page differently.
taches a picture environment to every There are two “ordinary” mechanisms
page as it is shipped out; the user can put for doing two slight variations of landscape
things into that environment: the package typesetting:
provides commands for placing things at
certain useful points (like “text upper left” • If you have a single floating object
or “text centre”) in the picture, but the user that is wider than it is deep, and will
is at liberty to do what he or she likes. only fit on the page in landscape ori-
Eso-pic is, in turn, built upon the pack- entation, use the rotating package;
age atbegshi. That package has the capa- this defines sidewaysfigure and
bility to produce watermarks on top of the sidewaystable environments which
other material on the page; this doesn’t create floats that occupy a whole page.
sound very “watermark-like”, but can Note that rotating has problems in
be useful on pages where the watermark a document that also loads the float
would otherwise be hidden by graphics or package, which recommended in other
the like. The atbegshi command that eso- answers in these FAQs, for example
pic uses is \AtBeginShipoutUpperLeft; that on float placement. The rotfloat
\AtBeginShipoutUpperLeftForeground package loads rotating for you, and
is what’s needed instead to place the mate- smooths the interaction with float.
rial on top of the rest of the content of the • If you have a long sequence of
page. things that need to be typeset in
Everypage allows you to add “some- landscape (perhaps a code listing,
thing” to every page, or to a particular a wide tabbing environment, or a
page; you therefore need to construct your huge table typeset using longtable or
own apparatus for anything complicated. supertabular), use the lscape package
Finally, one can use the pdftk untility; (or pdflscape if you’re generating PDF
with it, the command: output, whether using PDFLaTeX or
dvips and generating PDF from that).
pdftk a.pdf background b.pdf outputBoth c.pdf
packages define an environment
will recreate a.pdf as c.pdf, having used landscape, which clears the current
the first page of b.pdf as background on page and restarts typesetting in land-
every page. If you have a standard back- scape orientation (and clears the page
ground (“DRAFT” or “SECRET”, or what- at the end of the environment before
ever) used in several files, pdftk might well returning to portrait orientation).
be attractive.
Pdftk is available as a command line No currently available package makes di-
tool; it is available in most linux distrit- rect provision for typesetting in both por-
butions, but may be downloaded from its trait and landscape orientation on the same
home site page (it’s not the sort of thing that TeX
is well set-up to do). If such behaviour
atbegshi.sty : Distributed as part of was an absolute necessity, one might use
macros/latex/contrib/oberdiek the techniques described in "flowing text
draftcopy.sty : macros/latex/ around figures", and would rotate the land-
contrib/draftcopy scape portion using the rotation facilities
draftwatermark.sty : macros/latex/ of the graphics package. (Returning from
contrib/draftwatermark landscape to portrait orientation would be
somewhat easier: the portrait part of the
eso-pic.sty :
page would be a bottom float at the end
macros/latex/contrib/eso-pic
of the landscape section, with its content
everypage.sty : macros/latex/ rotated.)
contrib/everypage To set an entire document in landscape
everyshi.sty : Distributed as part of orientation, one might use lscape around
macros/latex/contrib/ms the whole document. A better option is the
123
landscape option of the geometry pack- commands of picture-mode. (Eso-pic re-
age; if you also give it dvips or pdftex quires the services of everyshi, which must
option, geometry also emits the rotation therefore also be available.)
instructions to cause the output to be prop- eso-pic.sty :
erly oriented. The memoir class has the macros/latex/contrib/eso-pic
same facilities, in this respect, as does
geometry. everyshi.sty : Distributed as part of
A word of warning: most current TeX macros/latex/contrib/ms
previewers do not honour rotation requests textpos.sty :
in DVI files. Your best bet is to convert macros/latex/contrib/textpos
your output to PostScript or to PDF, and to
228 Preventing page breaks between
view these ‘final’ forms with an appropri-
lines
ate viewer.
One commonly requires that a block of
geometry.sty :
typeset material be kept on the same page;
macros/latex/contrib/geometry
it turns out to be surprisingly tricky to ar-
graphics.sty : Distributed as part range this.
of macros/latex/required/ LaTeX provides a samepage environ-
graphics ment which claims it does this sort of thing
longtable.sty : Distributed as part of for you. It proceeds by setting infinite
macros/latex/required/tools penalties for all sorts of page-break situ-
ations; but in many situations where you
lscape.sty : Distributed as part
want to prevent a page break, samepage
of macros/latex/required/
doesn’t help. If you’re trying to keep
graphics
running text together, you need to end
memoir.cls: the paragraph inside the environment (see
macros/latex/contrib/memoir preserving paragraph parameters). Also,
pdflscape.sty : Distributed with if the things you are trying to keep to-
Heiko Oberdiek’s packages gether insert their own pagebreak hints,
macros/latex/contrib/oberdiek samepage has no power over them (though
rotating.sty :
list items’ attempts — they suggest page
macros/latex/contrib/rotating
breaks between items — are subverted by
samepage). Naturally, if samepage does
rotfloat.sty : work, it is capable of leaving stuff jutting
macros/latex/contrib/rotfloat out at the bottom of the page.
supertabular.sty : macros/latex/ Another convenient trick is to set all
contrib/supertabular the relevant stuff in a \parbox (or a
minipage if it contains things like verba-
227 Putting things at fixed positions
tim text that may not be used in the argu-
on the page
ment of a \parbox). The resulting box
TeX’s model of the world is (broadly speak- certainly won’t break between pages, but
ing) that the author writes text, and TeX that’s not to say that it will actually do what
and its macros decide how it all fits on the you want it to do: again, the box may be
page. This is not good news for the author left jutting out at the bottom of the page.
who has, from whatever source, a require- Why do neither of these obvious things
ment that certain things go in exactly the work? — Because TeX can’t really dis-
right place on the page. tinguish between infinitely awful things.
There are places on the page, from Samepage will make any possible break
which things may be hung, and two La- point “infinitely bad” and boxes don’t even
TeX packages allow you position things offer the option of breaks, but if the alter-
relative to such points, thus providing a native is the leave an infinitely bad few
means of absolute positioning. centimetres of blank paper at the bottom
The textpos package aids the construc- of the page, TeX will take the line of least
tion of pages from “blobs”, dotted around resistance and do nothing.
over the page (as in a poster); you give it This problem still arises even if you
the location, and it places your typeset box have \raggedbottom in effect: TeX
accordingly. doesn’t notice the value of that until it
The eso-pic defines a “shipout picture” starts actually shipping a page out. One
that covers the page. The user may add approach is to set:
picture-mode commands to this picture,
which of course can include box place- \raggedbottom
ments as well as the other rather stilted \addtolength{\topskip}{0pt plus 10pt}
124
The 10pt offers a hint to the output rou- document and to check for things that have
tine that the column is stretchable; this will the potential to give trouble. In such a
cause TeX to be more tolerant of the need scenario (which has Knuth’s authority be-
to stretch while building the page. If you’re hind it, if one is to believe the rather few
doing this as a temporary measure, cancel words he says on the subject in the TeX-
the change to \topskip by: book) one can decide, case by case, how
to deal with problems at the last proof-
\addtolength{\topskip}{0pt plus-10pt}
reading stage. At this stage, you can
as well as resetting \flushbottom. (Note manually alter page breaking, using either
that the 10pt never actually shows up, be- \pagebreak or \clearpage, or you can
cause it is overwhelmed when the page place a \nopagebreak command to sup-
is shipped out by the stretchability intro- press unfortunate breaks. Otherwise, you
duced by \raggedbottom; however, it can make small adjustments to the page ge-
could well have an effect if \flushbottom ometry, using \enlargethispage. Sup-
was in effect.) posing you have a line or two that stray:
An alternative (which derives from issue the command \enlargethispage
a suggestion by Knuth in the TeXbook) {2\baselineskip} and two lines are
is the package needspace or the memoir added to the page you’re typesetting.
class, which both define a command Whether this looks impossibly awful or en-
\needspace whose argument tells it what tirely acceptable depends on the document
space is needed. If the space isn’t avail- context, but the command remains a useful
able, the current page is cleared, and the item in the armoury.
matter that needs to be kept together will Note that both \pagebreak and
be inserted on the new page. For example, \nopagebreak take an optional number
if 4 lines of text need to be kept together, argument to adjust how the command
the sequence is to be interpreted. Thus \pagebreak
\par [0], the command ‘suggests’ that a page
\needspace{4\baselineskip} break might be worth doing, whereas
% the stuff that must stay together \pagebreak[4] ‘demands’ a page break.
<text generating lines 1-4> Similarly \nopagebreak[0] makes a sug-
% now stuff we don’t mind about gestion, while \nopagebreak[4] is a de-
mand. In both commands, the default value
Yet another trick by Knuth is useful if you of the optional argument is 4.
have a sequence of small blocks of text
that need, individually, to be kept on their memoir.cls:
macros/latex/contrib/memoir
own page. Insert the command \filbreak
before each small block, and the effect is needspace.sty : macros/latex/
achieved. The technique can be used in contrib/needspace
the case of sequences of LaTeX-style sec- 229 Parallel setting of text
tions, by incorporating \filbreak into the
definition of a command (as in patching It’s commonly necessary to present text in
commands). A simple and effective patch two languages ‘together’ on a page, or on a
would be: two-page spread. For this to be satisfactory,
one usually needs some sort of alignment
\let\oldsubsubsection=\subsubsection between the two texts.
\renewcommand{\subsubsection}{% The parallel package satisfies the need,
\filbreak permitting typesetting in two columns (not
\oldsubsubsection necessarily of the same width) on one page,
} or on the two opposing pages of a two-page
While the trick works for consecutive se- spread. Use can be as simple as
quences of blocks, it’s slightly tricky to get \usepackage{parallel}
out of such sequences unless the sequence ...
is interrupted by a forced page break (such \begin{Parallel}{<left-width>}{<right-width}
as \clearpage, which may be introduced \ParallelLText{left-text}
by a \chapter command, or the end of \ParallelRText{right-text}
the document). If the sequence is not inter- \ParallelPar
rupted, the last block is likely to be forced ...
onto a new page, regardless of whether it \end{Parallel}
actually needs it.
If one is willing to accept that not ev- Parallel can get terribly confused with
erything can be accomplished totally auto- colour changes, in PDFTeX; the indefati-
matically, the way to go is to typeset the gable Heiko Oberdiek has a patch for this
125
issue — the pdfcolparallel package, which \epigraph{Oh! My ears and whiskers!}%
maintains separate colour stacks for the {Lewis Carroll}
columns.
The parcolumns package can (in prin- and an epigraphs environment, for entering
ciple) deal with any number of columns: more than one epigraph consecutively, in
the documentation shows its use with three a sort of list introduced by \qitem com-
columns. Usage is rather similar to that of mands:
parallel, though there is of course a “num-
\begin{epigraphs}
ber of columns to specify”:
\qitem{What I tell you three times is true}%
\usepackage{parcolumns} {Lewis Carroll}
... \qitem{Oh listen do, I’m telling you!}%
\begin{parcolumns}[<options>]{3} {A.A. Milne}
\colchunk{<Column 1 text>} \end{epigraphs}
\colchunk{<Column 2 text>}
\colchunk{<Column 3 text>}
The \epigraphhead command enables
\colplacechunks
you to place your epigraph above a chapter
...
header:
\end{parcolumns}
\setlength{\unitlength}{1pt}
The hoptionsi can specify the widths of ...
the columns, whether to place rules be- \chapter{The Social Life of Rabbits}
tween the columns, whether to set the \epigraphhead[<distance>]{%
columns sloppy, etc. Again, there are is- \epigraph{Oh! My ears and whiskers!}%
sues with colours, which are addressed by {Lewis Carroll}%
the pdfcolparcolumns package. }
The ledpar package is distributed with
The hdistancei says how far above the
(and integrated with) the ledmac package.
chapter heading the epigraph is to go; it’s
It provides parallel setting carefully inte-
expressed in terms of the \unitlength
grated with the needs of a scholarly text,
that’s used in the picture environment;
permitting translation, or notes, or both, to
the package’s author recommends 70pt.
be set in parallel with the ‘base’ text of the
The package also offers various tricks
document.
for adjusting the layout of chapter header
ledpar.sty : Distributed with (necessary if you’ve found a hugely long
macros/latex/contrib/ledmac quotation for an \epigraphhead), for
parallel.sty : patching the bibliography, for patching
macros/latex/contrib/parallel \part pages, and so on. (Some of these
suggested patches lead you through writ-
parcolumns.sty : Distributed as part of
ing your own package. . . )
macros/latex/contrib/sauerj
The quotchap package redefines chap-
pdfcolparallel.sty : ter headings (in a moderately striking way),
Distributed as part of and provides an environment savequotes
macros/latex/contrib/oberdiek in which you can provide one (or more)
pdfcolparcolumns.sty : quotations to use as epigraphs. The fa-
pdfcolparcolumns] cilities seem not as flexible as those of
epigraph, but it’s probably easier to use.
230 Typesetting epigraphs The memoir class offers all the fa-
Epigraphs are those neat quotations that cilities of the epigraph package. The
authors put at the start of chapters (or even Koma-script classes have commands
at the end of chapters: Knuth puts things \setchapterpreamble and \dictum to
at the ends of chapters of the TeXbook). provide these facilities.
Typesetting them is a bit of a fiddle, epigraph.sty :
but not impossible to do for yourself. For- macros/latex/contrib/epigraph
tunately, there are two packages that do the
job, to some extent; there are also facili- KOMA script bundle:
ties in the two “big” classes (memoir and macros/latex/contrib/koma-
koma-script. script
The epigraph package defines an memoir.cls:
\epigraph command, for creating a single macros/latex/contrib/memoir
epigraph (as at the top of a chapter):
quotchap.sty :
macros/latex/contrib/quotchap
\chapter{The Social Life of Rabbits}
126
O.4 Spacing of characters and between the letters (otherwise known as
lines the tracking). As a general rule, this is a
very bad idea: it detracts from legibility,
231 Double-spaced documents in which is contrary to the principles of type-
LaTeX setting (any respectable font you might be
A quick and easy way of getting inter- using should already have optimum track-
line space for copy-editing is to change ing built into it).
\baselinestretch — \linespread The great type designer, Eric Gill,
{1.2} (or, equivalently \renewcommand is credited with saying “he who would
{\baselinestretch}{1.2}) may be ad- letterspace lower-case text, would steal
equate. Note that \baselinestretch sheep”. (The attribution is probably apoc-
changes don’t take effect until you select aryphal: others are also credited with the
new font, so make the change in the pream- remark. Stealing sheep was, in the 19th
ble before any font is selected. Don’t try century, a capital offence in Britain.) As
changing \baselineskip: its value is re- the remark suggests, though, letterspacing
set at any size-changing command so that of upper-case text is less awful a crime; the
results will be inconsistent. technique used also to be used for empha-
For preference (and certainly for a pro-
sis of text set in Fraktur (or similar) fonts.
duction document, such as a dissertation or Straightforward macros (usable, in
an article submission), use a line-spacing principle, with any TeX macro package)
package. The only one currently supported may be found in letterspacing (which is
is setspace. Setspace switches off double- the name of the .tex file).
spacing at places where even the most die- A more comprehensive solution is to
hard official would doubt its utility (foot-be found in the soul package (which is op-
notes, figure captions, and so on); it’s very
timised for use with LaTeX, but also works
difficult to do this consistently if you’re ma-
with Plain TeX). Soul also permits hyphen-
nipulating \baselinestretch yourself. ation of letterspaced text; Gill’s view of
(Note: do not be tempted by such an activity is not (even apocryphally)
doublespace — its performance under cur- recorded. (Spacing-out forms part of the
rent LaTeX is at best problematical.) name of soul; the other half is described in
Of course, the real solution (other another question.)
than for private copy editing) is not to Possibly the ‘ultimate’ in this field
use double-spacing at all. Universities, is the microtype, which uses the micro-
in particular, have no excuse for speci- typography capabilities of current PDFTeX
fying double-spacing in submitted disser- to provide a \textls command, which op-
tations: LaTeX is a typesetting system, erates according to parameters declared in
not a typewriter-substitute, and can (prop- a \SetTracking command. Microtype’s
erly used) make single-spaced text even ‘tracking’ facility expands the natural spac-
more easily readable than double-spaced ing of the font itself, rather than insert-
typewritten text. If you have any influ- ing space between characters. Ordinarily,
ence on your university’s system (for ex- letter-spacing will destroy ligatures; how-
ample, through your dissertation supervi- ever, this is wrong for some font styles (for
sor), it may be worth attempting to get the example, fraktur), and the package pro-
rules changed (at least to permit a “well- vides a means of protecting the ligatures in
designed book” format). a letter-spaced text.
Double-spaced submissions are also letterspacing.tex :
commonly required when submitting pa- macros/generic/misc/
pers to conferences or journals. Fortu- letterspacing.tex
nately (judging by the questions from users
in this author’s department), this demand microtype.sty : macros/latex/
is becoming less common. contrib/microtype
Documentation of setspace appears as soul.sty :
TeX comments in the package file itself. macros/latex/contrib/soul
setspace.sty : macros/latex/
contrib/setspace/setspace.sty 233 Setting text ragged right
The trick with typesetting ragged right is
232 Changing the space between to be sure you’ve told the TeX engine
letters “make this paragraph ragged, but never too
A common technique in advertising copy ragged”. The LaTeX \raggedright com-
(and other text whose actual content need mand (and the corresponding flushleft
not actually be read) is to alter the space environment) has a tendency to miss the
127
“never” part, and will often create ridicu- O.5 Typesetting specialities
lously short lines, for some minor benefit 235 Including a file verbatim in
later in the paragraph. The Plain TeX ver- LaTeX
sion of the command doesn’t suffer this
failing, but is rather conservative: it is A good way is to use Rainer Schöpf’s
loath to create too large a gap at the end verbatim package, which provides a com-
of the line, but in some circumstances — mand \verbatiminput that takes a file
such as where hyphenation is suppressed — name as argument:
painfully large gaps may sometimes be re- \usepackage{verbatim}
quired. ...
Martin Schröder’s ragged2e package \verbatiminput{verb.txt}
offers the best of both worlds: it pro-
Another way is to use the alltt envi-
vides raggedness which is built on the
ronment, which requires the alltt pack-
Plain TeX model, but which is easily con-
age. The environment interprets its con-
figurable. It defines easily-remembered
tents ‘mostly’ verbatim, but executes any
command (e.g., \RaggedRight) and envi-
(La)TeX commands it finds:
ronment (e.g., FlushLeft) names that are
simply capitalised transformations of the \usepackage{alltt}
LaTeX kernel originals. The documenta- ...
tion discusses the issues and explains the \begin{alltt}
significance of the various parameters of \input{verb.txt}
ragged2e’s operation. \end{alltt}
ragged2e.sty : Distributed as part of of course, this is little use for inputting
macros/latex/contrib/ms (La)TeX source code. . .
The moreverb package extends the
234 Cancelling \ragged commands verbatim package, providing a listing
LaTeX provides commands \raggedright environment and a \listinginput com-
and \raggedleft, but none to cancel mand, which line-number the text of
their effect. The \centering command the file. The package also has a
is implemented in the same way as the \verbatimtabinput command, that hon-
\ragged* commands, and suffers in the ours TAB characters in the input (the
same way. package’s listing environment and the
The following code (to be inserted in \listinginput command also both hon-
a package of your own, or as internal La- our TAB).
TeX code —internal LaTeX code) defines The sverb package provides verbatim
a command that restores flush justification input (without recourse to the facilities of
at both margins: the verbatim package):
\def\flushboth{% \usepackage{sverb}
\let\\\@normalcr ...
\@rightskip\z@skip \rightskip\@rightskip
\verbinput{verb.txt}
\leftskip\z@skip
The fancyvrb package offers con-
\parindent 1.5em\relax}
figurable implementations of everything
There’s a problem with the setting of verbatim, sverb and moreverb have, and
\parindent in the code: it’s necessary more besides. It is nowadays the package
because both the \ragged commands set of choice for the discerning typesetter of
\parindent to zero, but the setting isn’t a verbatim text, but its wealth of facilities
constant of nature: documents using a stan- makes it a complex beast and study of the
dard LaTeX class with twocolumn option documentation is strongly advised.
will have 1.0em by default, and there’s no The memoir class includes the relevant
knowing what you (or some other class) functionality of the verbatim and moreverb
will have done. packages.
Any but a really old copy of Mar-
alltt.sty : Part of the LaTeX
tin Schröder’s ragged2e package has a
\justifying command to match its ver-
distribution.
sions of the LaTeX ‘ragged’ commands. fancyvrb.sty :
The package also provides a justify en- macros/latex/contrib/fancyvrb
vironment, which permits areas of justified memoir.cls:
text in a larger area which is ragged. macros/latex/contrib/memoir
ragged2e.sty : Distributed as part of moreverb.sty :
macros/latex/contrib/ms macros/latex/contrib/moreverb
128
sverb.sty : Distributed as part of in the typesetting of dissertations by com-
macros/latex/contrib/mdwtools puter science and other students who are
verbatim.sty : Distributed as part of
expected to write programs. Simple ver-
macros/latex/required/tools
batim listings of programs are commonly
useful, as well.
236 Including line numbers in typeset Verbatim listings are dealt with else-
output where, as is the problem of typesetting al-
For general numbering of lines, there are gorithm specifications.
two packages for use with LaTeX, lineno The listings package is widely regarded
(which permits labels attached to individ- as the best bet for formatted output (it is
ual lines of typeset output) and numline. capable of parsing program source, within
(Numline is considered obsolete, but re- the package itself), but there are several
mains available from the archive.) well-established packages that rely on a
Both of these packages play fast and pre-compiler of some sort. You may use
loose with the LaTeX output routine, listings to typeset snippets that you include
which can cause problems: the user should within your source:
beware. . . \usepackage{listings}
If the requirement is for numbering ver- \lstset{language=C}
batim text, moreverb, or fancyvrb (see in- ...
cluding files verbatim) may be used. Class \begin{document}
memoir also provides the necessary facili- \begin{lstlisting}
ties. #include <stdio.h>
One common use of line numbers is in
critical editions of texts, and for this the int main(int argc, char ** argv)
edmac package offers comprehensive sup- {
port; ledmac is a LaTeX port of edmac. printf("Hello world!\n");
The vruler package sidesteps many return 0;
of the problems associated with line- }
numbering, by offering (as its name sug- \end{lstlisting}
gests) a rule that numbers positions on the \end{document}
page. The effect is good, applied to even-
looking text, but is poor in texts that in- or you can have it typeset whole files:
volve breaks such as interpolated mathe-
\usepackage{listings}
matics or figures. Documentation of the
\lstset{language=C}
package, in the package itself, is pretty
...
tough going, though there is an example
\begin{document}
(also inside the package file).
\lstinputlisting{main.c}
edmac: macros/plain/contrib/edmac \end{document}
fancyvrb.sty : These very simple examples may be dec-
macros/latex/contrib/fancyvrb orated in a huge variety of ways, and of
ledmac.sty : course there are other languages in the
macros/latex/contrib/ledmac package’s vocabulary than just C. . .
For a long time, advice on (La)TeX
lineno.sty :
lists seemed to regard listings as the be-all
macros/latex/contrib/lineno
and end-all on this topic. In the last few
memoir.cls: years, viable alternatives have appeared
macros/latex/contrib/memoir Highlight is attractive if you need more
moreverb.sty : than one output format for your program:
macros/latex/contrib/moreverb as well as (La)TeX output, highlight will
produce (X)HTML, RTF and XSL-FO rep-
numline.sty :
resentations of your program listing. The
obsolete/macros/latex/
manual leads you through the details of
contrib/numline/numline.sty
defining a parameter file for a “new” lan-
vruler.sty : guage, as well as the presentation details
macros/latex/contrib/vruler of a language.
The minted package is another al-
237 Code listings in LaTeX ternative that offers the means of cre-
‘Pretty’ code listings are sometimes con- ating new language definitions. It re-
sidered worthwhile by the “ordinary” pro- quires that code be processed using
grammer, but they have a serious place an external (python) script, Pygments.
129
Pygments, in turn, needs a “lexer” that showexpl.sty :
knows the language you want to process; macros/latex/contrib/showexpl
lots of these are available, for the more tgrind : support/tgrind
commonly-used languages, and there is
advice on “rolling your own” on the <a tiny_c2l: support/tiny_c2l
href=’http://pygments.org/docs/lexerdevelopment/’>Pygments
238 Typesetting pseudocode in
site</a> LaTeX
Usage of minted can be as simple as
There is no consensus on the ‘right’ way to
\begin{minted}{hlanguagei} typeset pseudocode. Consequently, there
... are a variety of LaTeX packages to choose
\end{minted} from for producing æsthetically pleasing
pseudocode listings.
which processes the program code dynam-
Pseudocode differs from actual pro-
ically, at typesetting time — though such
gram listings in that it lacks strict syntax
usage is likely to require that separate pro-
and semantics. Also, because pseudocode
cessing be enabled.
is supposed to be a clear expression of
On a rather different path, the pack-
an algorithm it may need to incorporate
age showexpl supports typesetting (La)TeX
mathematical notation, figures, tables, and
code and its typeset output, in parallel
other LaTeX features that do not appear
‘panes’. (Thiscould provide support for
in conventional programming languages.
(La)TeX instruction texts, or for papers in
Typesetting program listings is described
TeX user group publications. The pack-
elsewhere.
age uses listings for its (La)TeX pane, and
You can certainly create your own envi-
typesets the result into a simple box, for
ronment for typesetting pseudocode using,
the other pane.
for example, the tabbing or list envi-
Longer-established, and variously less
ronments — it’s not difficult, but it may
“powerful” systems include:
prove boring. So it’s worth trying the fol-
• The lgrind system is a well- lowing packages, all designed specifically
established pre-compiler, with all for typesetting pseudocode.
the facilities one might need and a The algorithms bundle (which contains
wide repertoire of languages; it is de- packages algorithm and algorithmic, both
rived from the even longer-established of which are needed for ordinary use) has
tgrind, whose output is based on Plain a simple interface and produces fairly nice
TeX. output. It provides primitives for state-
• The tiny_c2l system is slightly more ments, which can contain arbitrary LaTeX
recent: users are again encouraged to commands, comments, and a set of iter-
generate their own driver files for lan- ative and conditional constructs. These
guages it doesn’t already deal with, primitives can easily be redefined to pro-
but its “tiny” name correctly hints that duce different text in the output. However,
it’s not a particularly elaborate system. there is no support for adding new primi-
• The C++2LaTeX system comes with tives. Typesetting the pseudocode itself is
strong recommendations for use with performed in algorithmic; the algorithms
C and C++. package uses the facilities of the float pack-
• An extremely simple system is age to number algorithms sequentially, en-
c2latex, for which you write LaTeX able algorithms to float like figures or ta-
source in your C program comments. bles, and support including a List of Algo-
The program then converts your pro- rithms in a document’s front matter.
gram into a LaTeX document for pro- Packages in the algorithmicx bundle
cessing. The program (implicitly) are similar both in concept and output
claims to be “self-documenting”. form to algorithmic but additionally pro-
vide support for adding new keywords and
c2latex : support/c2latex
altering the formatting. It provides the
C++2LaTeX : algpseudocode package which is (almost)
support/C++2LaTeX-1_1pl1 a drop-in replacement for algorithmic. An-
highlight: support/highlight other package in the bundle, algpascal,
lgrind : support/lgrind
uses Pascal-like keywords, indents differ-
ently from algpseudocode, and puts com-
listings.sty : mand arguments in maths mode instead of
macros/latex/contrib/listings text mode. There is no floating environ-
minted.sty : ment but algorithmicx, like algorithmic,
macros/latex/contrib/minted is compatible with the algorithm package.
130
(There have been reports of difficulty defin- algorithms bundle: macros/latex/
ing new commands to fit with the package; contrib/algorithms
unfortunately, the author is not available to alg.sty : macros/latex/contrib/alg
comment.)
clrscode.sty :
The alg package, like algorithms, of-
macros/latex/contrib/clrscode
fers a floating algorithm environment with
all of the ensuing niceties. alg, however, float.sty :
can caption its floats in a variety of (nat- macros/latex/contrib/float
ural) languages. In addition, alg unlike newalg.sty :
algorithms, makes it easy to add new con- macros/latex/contrib/newalg
structs.
program.sty :
The newalg package has a somewhat
macros/latex/contrib/program
similar interface to algorithms, but its out-
put is designed to mimic the rather pleas- pseudocode.sty : macros/latex/
ant typesetting used in the book “Introduc- contrib/pseudocode
tion to Algorithms” by Corman, Leiserson, 239 Generating an index in (La)TeX
Rivest and Stein. Unfortunately, newalg
does not support a floating environment or Making an index is not trivial; what to in-
any customisation of the output. dex, and how to index it, is difficult to de-
cide, and uniform implementation is diffi-
“Bona fide” use of the style of “Intro-
cult to achieve. You will need to mark all
duction to Algorithms” may be achieved
items to be indexed in your text (typically
with Cormen’s own clrscode: this is the
with \index commands).
package as used in the second edition of
It is not practical to sort a large index
the book.
within TeX, so a post-processing program
Similarly, the style of “Combinatorial
is used to sort the output of one TeX run, to
Algorithms: Generation, Enumeration and
be included into the document at the next
Search” is supported by the pseudocode
run.
package, written by the authors of the book.
The following programs are available:
It has the common ‘Pascal-like’ style, and
has some interesting constructs for what makeindex Comes with most distribu-
one thinks of as Pascal blocks. tions — a good workhorse, but is not
The algorithm2e is of very long stand- well-arranged to deal with other sort
ing, and is widely used and recommended. orders than the canonical ASCII order-
It loads the float package to provide the ing.
option of floating algorithm descriptions, The makeindex documentation is a
but you can always use the “H” option of good source of information on how to
float to have the algorithm appear “where create your own index. Makeindex can
you write it”. be used with some TeX macro pack-
The usage of the program package is a ages other than LaTeX, such as Eplain
little different from that of the other pack- (Eplain), and TeX (whose macros
ages. It typesets programs in maths mode can be used independently with Plain
instead of text mode; and linebreaks are TeX).
significant. program lacks a floating envi- idxtex for LaTeX under VMS; idxtex
ronment but does number algorithms like comes with a glossary-maker glotex.
alg and algorithms. Customisation and texindex(1) A witty little shell-script us-
extension are not supported. Documenta- ing sed and awk; designed for LaTeX
tion of the program package (such as it under Unix.
is) appears in a file program.msg in the texindex(2) The Texinfo system also of-
distribution. fers a program texindex, whose source
None of the above are perfect. The fac- is to be found in the texinfo distribu-
tors that should influence your choice of tion. The ltxindex package provides
package include the output style you prefer, macros that enable LaTeX users to use
how much you need to extend or modify this texindex.
the set of keywords, and whether you re- xindy arose from frustration at the diffi-
quire algorithms to float like figures and culty of making a multi-language ver-
tables. sion of makeindex. It is designed to be
a successor to makeindex, by a team
algorithm2e.sty : macros/latex/
that included the then-current main-
contrib/algorithm2e
tainer of makeindex. It successfully
algorithmicx bundle: macros/latex/ addresses many of makeindex’s short-
contrib/algorithmicx comings, including difficulties with
131
collation order in different languages, commands (use of \protect) for use
and it is highly flexible. within moving arguments.
Xindy itself will work with Unicode The package ordinarily ignores spaces
(UTF-8) encoded LaTeX input. A sep- in the URL, but unfortunately URLs
arate application (texindy) deals with that contain spaces do exist; to type-
‘standard’ LaTeX source, processes it set them, call the package with the
and passes ‘sanitised’ text to Xindy. obeyspaces option. Two other use-
ful options allow line breaks in the
idxtex : indexing/glo+idxtex URL in places where they are or-
ltxindex.sty : dinarily suppressed to avoid confu-
macros/latex/contrib/ltxindex sion: spaces to allow breaks at spaces
(note, this requires obeyspaces as
makeindex : indexing/makeindex
well, and hyphens to allow breaks af-
makeindex (Macintosh): systems/ ter hyphens. (Note that the package
mac/macmakeindex2.12.sea.hqx never does “ordinary” hyphenation of
texindex (the script): names inside an URL.)
indexing/texindex It is possible to use the url package in
Plain TeX, with the assistance of the
texindex (the program): Distributed miniltx package (which was originally
with macros/texinfo/texinfo developed for using the LaTeX graph-
texsis (system): macros/texsis ics package in Plain TeX). A small
patch is also necessary: the required
texsis (makeindex support):
sequence is therefore:
macros/texsis/index/index.tex
\input miniltx
xindy : indexing/xindy
\expandafter\def\expandafter\+\expandafter{\+}
240 Typesetting URLs \input url.sty
URLs tend to be very long, and con- • The hyperref package, which uses the
tain characters that would naturally pre- typesetting code of url, in a context
vent them being hyphenated even if they where the typeset text forms the an-
weren’t typically set in \ttfamily, ver- chor of a link.
batim. Therefore, without special treat-
The author of this answer prefers the
ment, they often produce wildly overfull
(rather newer) url package (directly or in-
\hboxes, and their typeset representation
directly); both path and url work well with
is awful.
Plain TeX (though of course, the fancy La-
There are three packages that help
TeX facilities of url don’t have much place
solve this problem:
there). (hyperref isn’t available in a ver-
• The path package, which defines a sion for use with Plain TeX.)
\path command. The command de- Note that neither \path (from package
fines each potential break character path) nor \url (from package url) is ro-
as a \discretionary, and offers the bust (in the LaTeX sense). If you need
user the opportunity of specifying a a URL to go in a moving argument, you
personal list of potential break charac- need the command \urldef from the url
ters. Its chief disadvantage is fragility package. So one might write:
in LaTeX moving arguments. The \urldef\faqhome\url{http://www.tex.ac.uk/faq}
Eplain macros — define a similar
\path command. after which, \faqhome is robust.
Path, though it works in simple situa- Documentation of both package path
tions, makes no attempt to work with and package url is in the package files.
LaTeX (it is irremediably fragile). De- hyperref.sty :
spite its long and honourable history, macros/latex/contrib/hyperref
it is no longer recommended for La-
miniltx.tex : Distributed as part of
TeX use.
macros/plain/graphics
• The url package, which defines an
\url command (among others, includ- path.sty : macros/generic/path
ing its own \path command). The url.sty : macros/latex/contrib/url
command gives each potential break
character a maths-mode ‘personality’, 241 Typesetting music in TeX
and then sets the URL itself (in the The current best bet for music typesetting
user’s choice of font) in maths mode. is to use musixtex. Musixtex is a three-
It can produce (LaTeX-style) ‘robust’ pass system that has a TeX-based pass,
132
a processing pass and then a further TeX mainstream, and is no longer maintained.
pass. The middle pass, a program called The current recommended way of doing
musixflx, optimises the spacing and sorts OpusTeX’s job is gregorio, which can in
out slurs and ties. Musixtex is demand- principle feed into a TeX-based document.
ing of TeX resources, and any significant Once Andreas Egler had withdrawn
score requires that typesetting is done us- (his last version of musixtex is preserved
ing e-TeX, whose expanded variable- and on the archive), Daniel Taupin took up the
box-register ranges allow for more of the development, leading to the musixtex used
“parallel” activities that abound in a music today.
score. Of course, musixtex also requires abc2mtex : support/abc2mtex
music fonts; those are available in a sepa-
rate package on the archive. lilyglyphs: macros/luatex/latex/
lilyglyphs
Musixtex requires pretty arcane input;
most people using it actually prepare (less M-Tx : support/m-tx
obscure) input for pmx, whose output is midi2tex : support/midi2tex
TeX input suitable for musixtex.
musictex : macros/musictex
A further preprocessor, M-Tx, allows
preparation of music with lyrics; M-Tx’s musixtex (Taupin’s version):
output is fed into pmx, and thence to macros/musixtex
musixtex. musixtex (Egler’s version): obsolete/
An alternative path to music examples macros/musixtex/egler
within a (La)TeX document is Lilypond.
musixtex fonts:
Lilypond is (at heart) a batch music typeset-
fonts/musixtex-fonts
ting system with plain text input that does
most of its work without TeX. Lilypond’s mutex : macros/mtex
input syntax is less cryptic than is MusiX- pmx : support/pmx
TeX’s, though similar quality is achieved.
The lilypond FAQ mentions programs with 242 Zero paragraph indent
graphical user interfaces, that export lily- The conventional way of typesetting run-
pond output. ning text has no separation between para-
For occasional music references (sharp graphs, and the first line of each paragraph
and flat signs, notes, clefs and so on, there in a block of text indented.
is a (LaTeX) package (with associated font) In contrast, one common convention
called lilyglyphs. This uses lilypond’s fonts for typewritten text was to have no inden-
(which are included in the package), and tation of paragraphs; such a style is often
also provides the means to add stuff from required for “brutalist” publications such
other sources. as technical manuals, and in styles that han-
Another alternative in the production ker after typewritten manuscripts, such as
of music is the ABC notation, which was officially-specified dissertation formats.
developed to notate the traditional music of Anyone can see, after no more than
Western Europe (which can be written on a moment’s thought, that if the paragraph
a single stave), though it can be used much indent is zero, the paragraphs must be sepa-
more widely. A front end to musictex (see rated by blank space: otherwise it is some-
below), abc2mtex, makes ABC typesetting times going to be impossible to see the
possible. breaks between paragraphs.
The program midi2tex can also gener- The simple-minded approach to zero
ate musictex output, from MIDI files. paragraph indentation is thus:
The history of music in TeX goes back \setlength{\parindent}{0pt}
some time; the earliest “working” macros \setlength{\parskip}{\baselineskip}
were MuTeX, by Angelika Schofer and
Andrea Steinbach. MuTeX was very lim- and in the very simplest text, it’s a fine
ited, but it was some time before Daniel solution.
Taupin took up the baton, and developed However, the non-zero \parskip inter-
MusicTeX, which allows the typesetting of feres with lists and the like, and the result
polyphonic and other multiple-stave mu- looks pretty awful. The parskip package
sic; MusicTeX remains available, but is no patches things up to look reasonable; it’s
longer recommended. not perfect, but it deals with most prob-
The first version of MusixTeX was de- lems.
veloped by Andreas Egler, but he with- The Netherlands Users’ Group’s set
drew from the project to work on another of classes includes an article equiva-
package, OpusTeX. That never reached the lent (artikel3) and a report equivalent
133
(rapport3) whose design incorporates zero Therefore, if you need to use commas
paragraph indent and non-zero paragraph as decimal separator, you will probably
skip. welcome macro support. There are two
NTG classes: packages that can help relieve the tedium:
macros/latex/contrib/ntgclass icomma and ziffer.
Icomma ensures that there will be no
parskip.sty :
extra space after a comma, unless you type
macros/latex/contrib/parskip
a space after it (as in f(x, y) — in the ab-
243 Big letters at the start of a sence of the package, you don’t need that
paragraph space), in which case the usual small space
A common style of typesetting, now sel- after the comma appears. Ziffer is specifi-
dom seen except in newspapers, is to start cally targeted at the needs of those typeset-
a paragraph (in books, usually the first of a ting German, but covers the present need,
chapter) with its first letter set large enough as well as providing the double-minus sign
to span several lines. used in German (and other languages) for
This style is known as “dropped capi- the empty ‘cents’ part of an amount of cur-
tals”, or (in French) “lettrines”, and TeX’s rency.
primitive facilities for hanging indentation The numprint package provides a com-
make its (simple) implementation pretty mand \numprint{number} that prints its
straightforward. argument according to settings you give it,
The dropping package does the job sim- or according to settings chosen to match
ply, but has a curious attitude to the calcula- the language you have selected in babel.
tion of the size of the font to be used for the The formatting works equally well in text
big letters. Examples appear in the pack- or maths. The command is very flexible
age documentation, so before you process (it can also group the digits of very ‘long’
the .dtx, the package itself must already numbers), but is inevitably less convenient
be installed. Unfortunately, dropping has than icomma or ziffer if you are typing a
an intimate relation to the set of device lot of numbers.
drivers available in an early version of the icomma.sty : Distributed as part of
LaTeX graphics package, and it cannot be macros/latex/contrib/was
trusted to work with modern offerings such
as PDFTeX or DVIpdfm, let alone such numprint.sty :
macros/latex/contrib/numprint
modernisms as XeTeX. As a result, the
package is widely deprecated, nowadays. ziffer.sty :
The more recent lettrine package is macros/latex/contrib/ziffer
generally more reliable. It has a well-
constructed array of options, and an im- 245 Breaking boxes of text
pressive set of examples adds to the pack- (La)TeX boxes may not be broken, in ordi-
age’s document. nary usage: once you’ve typeset something
dropping : into a box, it will stay there, and the box
macros/latex/contrib/dropping will jut out beyond the side or the bottom
of the page if it doesn’t fit in the typeset
lettrine:
area.
macros/latex/contrib/lettrine
If you want a substantial portion of
244 The comma as a decimal your text to be framed (or coloured), the re-
separator striction imposes a serious restriction. For-
TeX embodies the British/American cul- tunately, there are ways around the prob-
tural convention of using a period as the lem.
separator between the whole number and The framed package provides framed
the decimal fraction part of a decimal num- and shaded environments; both put their
ber. Other cultures use a comma as separa- content into something which looks like
tor, but if you use a comma in maths mode a framed (or coloured) box, but which
you get a small space after it; this space breaks as necessary at page end. The en-
makes a comma that is used as a decimal vironments “lose” footnotes, marginpars
separator look untidy. and head-line entries, and will not work
A simple solution to this problem, in with multicol or other column-balancing
maths mode, is to type 3{,}14 in place of macros. The memoir class includes the
3,14. While such a technique may pro- functionality of the framed package.
duce the right results, it is plainly not a The mdframed package does the same
comfortable way to undertake any but the job, using a different algorithm. The pack-
most trivial amounts of typing numbers. age also provides means of defining ‘pri-
134
vate’ framed environments, whose param- Documentation of ulem is in the pack-
eters are set at definition time, thus sav- age file.
ing considerable effort in documents with pdfcomment.sty : macros/latex/
many framed boxes. Its restrictions seem contrib/pdfcomment
much the same as those of framed; this is
as one would expect, but the list is notice- soul.sty :
ably different in the two packages’ docu- macros/latex/contrib/soul
mentation. ulem.sty :
The boites package provides a macros/latex/contrib/ulem
breakbox environment; examples of its
use may be found in the distribution, and
247 Realistic quotes for verbatim
the package’s README file contains terse
listings
documentation. The environments may be
nested, and may appear inside multicols The cmtt font has “curly” quotes
environments; however, floats, footnotes (‘thus’), which are pleasing on the eye,
and marginpars will be lost. but don’t really tally with what one sees on
For Plain TeX users, the facilities of a modern xterm (which look like `this').
the backgrnd package may be useful; this The appearance of these quotes is crit-
package subverts the output routine to pro- ical in program listings, particularly in
vide vertical bars to mark text, and the those of Unix-like shell scripts. The
macros are clearly marked to show where upquote package modifies the behaviour
coloured backgrounds may be introduced of the verbatim environment so that the
(this requires shade, which is distributed as output is a clearer representation of what
tex macros and device-independent Meta- the user must type.
font for the shading). The author of upquote.sty : macros/latex/
backgrnd claims that the package works contrib/upquote/upquote.sty
with LaTeX 2.09, but there are reasons to
suspect that it may be unstable working 248 Printing the time
with current LaTeX.
TeX has a primitive register that contains
backgrnd.tex : macros/generic/
“the number of minutes since midnight”;
misc/backgrnd.tex
with this knowledge it’s a moderately sim-
boites.sty : ple programming job to print the time
macros/latex/contrib/boites (one that no self-respecting Plain TeX user
framed.sty : would bother with anyone else’s code for).
macros/latex/contrib/framed However, LaTeX provides no primitive
mdframed.sty : for “time”, so the non-programming La-
macros/latex/contrib/mdframed TeX user needs help.
Two packages are available, both pro-
memoir.cls:
viding ranges of ways of printing the date,
macros/latex/contrib/memoir
as well as of the time: this question will
shade.tex : macros/generic/shade concentrate on the time-printing capabil-
246 Overstriking characters ities, and interested users can investigate
the documentation for details about dates.
This may be used, for example, to indicate
The datetime package defines two time-
text deleted in the course of editing. Both
printing functions: \xxivtime (for 24-
the ulem and the soul packages provide the
hour time), \ampmtime (for 12-hour time)
necessary facilities.
and \oclock (for time-as-words, albeit a
Overstriking with an “attached”
slightly eccentric set of words).
comment may be achieved using the
pdfcomment package, to which you can The scrtime package (part of the com-
give optional arguments with all sorts of pendious KOMA-Script bundle) takes a
detail. The comment text is encoded using package option (12h or 24h) to specify
an Adobe ‘annotation’; unfortunately, sup- how times are to be printed. The com-
port for these annotations is not a common mand \thistime then prints the time ap-
feature of PDF viewers, but if you can propriately (though there’s no am or pm
safely assume that your audience will use in 12h mode). The \thistime command
Acrobat Reader, the facility provides that also takes an optional argument, the char-
extra “shine” that business users so love. acter to separate the hours and minutes: the
Overstriking for cancellation in maths default is of course :.
expressions is achieved by a different datetime.sty :
mechanism. macros/latex/contrib/datetime
135
scrtime.sty : Distributed as part of the dotted leaders, respectively. The series
macros/latex/contrib/koma- of commands named \l@xxx , where xxx
script is the name of a sectional heading (such
as chapter or section, . . . ) control the
249 Redefining counters’
layout of the corresponding heading, in-
\the-commands
cluding the space for section numbers. All
Whenever you request a new LaTeX these internal commands may be individ-
counter, LaTeX creates a bunch of behind- ually redefined to give the effect that you
the-scenes commands, as well as defining want.
the counter itself. All that work may be avoided, using
Among other things, \newcounter the package tocloft which provides a set of
{fred} creates a command \thefred , user-level commands that may be used to
which expands to “the value of fred ” change the TOC formatting. Since exactly
when you’re typesetting. the same mechanisms are used for the List
The definition of \thefred should ex- of Figures and List of Tables, the layout
press the value of the counter: it is almost of these sections may be controlled in the
always always a mistake to use the com- same way.
mand to produce anything else. The value The etoc package offers similar flexi-
may reasonably be expressed as an arabic, bility, together with multicolumn tables of
a roman or a greek number, as an alpha- contents and boxes around tables (and the
betic expression, or even as a sequence (or like).
pattern of) symbols. If you need a decision The KOMA-Script classes provides
process on whether to re-define \thefred , an optional variant structure for the ta-
consider what might happen when you do ble of contents, and calculates the space
so. needed for the numbers automatically. The
So, for example, if you want your sec- memoir class includes the functionality of
tion numbers to be terminated by a pe- tocloft.
riod, you could make \thesection ex-
etoc.sty :
pand with a terminating period. However,
macros/latex/contrib/etoc
such a change to \thesection makes the
definition of \thesubsection look dis- KOMA script bundle:
tinctly odd: you are going to find your- macros/latex/contrib/koma-
self redefining things left, right and cen- script
tre. Rather, use the standard techniques
memoir.cls:
for adjusting the presentation of section
macros/latex/contrib/memoir
numbers.
Or, suppose you want the page number tocloft.sty :
to appear at the bottom of each page sur- macros/latex/contrib/tocloft
rounded by dashes (as in “--~nnn~--”).
If you try to achieve this by redefining 251 Unnumbered sections in the
\thepage, problems will arise from the Table of Contents
use of the page number in the table of con- The way the relevant parts of sectioning
tents (each number will have the dashes commands work is exemplified by the way
attached), and \pageref references will the \chapter command uses the counter
be oddly modified. In this case, the change secnumdepth (described in Appendix C
of appearance is best done by redefining of the LaTeX manual):
the page style itself, perhaps using package
fancyhdr. 1. put something in the .aux file, which
will appear in the .toc;
O.6 Tables of contents and 2. if secnumdepth ≥ 0, increase the
indexes counter for the chapter and write it
out.
250 The format of the Table of
3. write the chapter title.
Contents, etc.
The formats of entries in the table of con- Other sectioning commands are similar,
tents (TOC) are controlled by a number but with other values used in the test.
of internal commands (discussed in sec- So a simple way to get headings of
tion 2.3 of The LaTeX Companion. The funny ‘sections’ such as prefaces in the
commands \@pnumwidth, \@tocrmarg table of contents is to use the counter:
and \@dotsep control the space for page
numbers, the indentation of the right-hand \setcounter{secnumdepth}{-1}
margin, and the separation of the dots in \chapter{Preface}
136
Unfortunately, you have to set requirements. The macro to do the
secnumdepth back to its usual value job (\addcontentsline) is fairly simple,
(which is 2 in the standard styles) before but there is always an issue of ensuring
you do any ‘section’ which you want to be that the contents entry quotes the correct
numbered. page. Supposing that our the document
Similar settings are made, automati- is chapter-based (class report or book, for
cally, in the LaTeX book class by the example), the text:
\frontmatter and \backmatter com-
\bibliography{frooble}
mands.
\addcontentsline{toc}{chapter}{Bibliography}
The value of the counter tocdepth
controls which headings will be finally will produce the wrong answer if the bib-
printed in the table of contents; it is nor- liography is more than one page long. In-
mally set in the preamble and is a con- stead, one should say:
stant for the document. The package \cleardoublepage
tocvsec2 package takes the tedium out \addcontentsline{toc}{chapter}{Bibliography}
of changing the secnumdepth and/or the \bibliography{frooble}
tocdepth counter values at any point
in the body of the document; the com- (Note that \cleardoublepage does the
mands (respectively) \setsecnumdepth right thing, even if your document is single-
and \settocdepth make the changes sided — in that case, it’s a synonym for
based on the name of the sectional unit \clearpage). Ensuring that the entry
(chapter, section, etc.). refers to the right place is trickier still in a
The package abstract (see one-column \section -based class.
abstracts) includes an option to add the If you are using hyperref (which will
abstract to the table of contents, while link entries in the table of contents to the
the package tocbibind has options to in- relevant place in the file), a slight adjust-
clude the table of contents itself, the ment is necessary:
bibliography, index, etc., to the table \cleardoublepage
of contents. \phantomsection
The KOMA-Script classes have com- \addcontentsline{toc}{chapter}{Bibliography}
mands \addchap and \addled, which \bibliography{frooble}
work like \chapter and \section but
aren’t numbered. The memoir class in- The extra command (\phantomsection)
corporates the facilities of all three of the gives hyperref something to “hold on to”
abstract, tocbibind and tocvsec2 packages. when making the link.
The common solution, therefore, is to
abstract.sty : use the tocbibind package, which provides
macros/latex/contrib/abstract many facilities to control the way these
KOMA script bundle: entries appear in the table of contents.
macros/latex/contrib/koma- Classes of the KOMA-script bundle
script provide this functionality as a set of class
memoir.cls:
options (e.g., bibtotoc to add the bibliog-
macros/latex/contrib/memoir
raphy to the table of contents); the memoir
class includes tocbibind itself.
tocbibind.sty : macros/latex/
hyperref.sty :
contrib/tocbibind
macros/latex/contrib/hyperref
tocvsec2.sty :
KOMA script bundle:
macros/latex/contrib/tocvsec2
macros/latex/contrib/koma-
252 Bibliography, index, etc., in TOC script
The standard LaTeX classes (and many memoir.cls:
others) use \section* or \chapter* for macros/latex/contrib/memoir
auto-generated parts of the document (the tocbibind.sty : macros/latex/
tables of contents, lists of figures and ta- contrib/tocbibind
bles, the bibliography and the index). As a
result, these items aren’t numbered (which 253 Table of contents, etc., per
most people don’t mind), and (more im- chapter
portantly) they don’t appear in the table of The common style, of a “small” table of
contents. contents for each part, chapter, or even sec-
The correct solution (as always) is tion, is supported by the minitoc package.
to have a class of your own that for- The package also supports mini-lists of ta-
mats your document according to your bles and figures; but, as the documentation
137
observes, mini-bibliographies present a dif- \makeindex{authors}
ferent problem — see bibliographies per ...
chapter. \index{authors}{Eccentric Professor}
The package’s basic scheme is to gen- ...
erate a little .aux file for each chapter, and \index{general}{FAQs}
to process that within the chapter. Simple ...
usage would be: \printindex{general}{General index}
\printindex{authors}{Author index}
\usepackage{minitoc}
... To complete the job, run LaTeX on your
\begin{document} file enough times that labels, etc., are sta-
... ble, and then execute the commands
\dominitoc \tableofcontents
makeindex general
\dominilof \listoffigures
makeindex authors
...
\chapter{blah blah} before running LaTeX again. Note that
\minitoc \mtcskip \minilof the names of the index files to process
... are not necessarily related to the name of
the LaTeX file you’re processing, at all.
though a lot of elaborations are possible
(There’s no documentation that comes with
(for example, you don’t need a \minitoc
the package: what you see above is as good
for every chapter).
as you will get. . . )
Babel doesn’t know about minitoc, but
The multind package doesn’t work
minitoc makes provision for other docu-
with the AMSLaTeX classes, but the AMS
ment languages than English — a wide
provide a substitute, the amsmidx pack-
variety is available. Fortunately, the cur-
age. You use the amsmidx package pretty
rent version of the hyperref package does
much the same as you would multind, but
know about minitoc and treats \minitoc
if things aren’t clear, there is documenta-
tables in the same way as “real” tables of
tion (unlike multind).
contents.
The index package provides a com-
babel.sty : prehensive set of indexing facilities, in-
macros/latex/required/babel cluding a \newindex command that al-
hyperref.sty : lows the definition of new styles of index.
macros/latex/contrib/hyperref \newindex takes a ‘tag’ (for use in index-
ing commands), replacements for the .idx
minitoc.sty :
and .ind file extensions, and a title for
macros/latex/contrib/minitoc
the index when it’s finally printed; it can
254 Multiple indexes also change the item that’s being indexed
LaTeX’s standard indexing capabilities against (for example, one might have an
(those provided by the makeidx package) index of artists referenced by the figure
only provide for one index in your docu- number where their work is shown).
ment; even quite modest documents can be Using index, to create an author index
improved by indexes for separate topics. together with a “normal” index, one would
The multind package provides sim- start with preamble commands:
ple and straightforward multiple indexing. \usepackage{index}
You tag each \makeindex, \index and \makeindex
\printindex command with a file name, \newindex{aut}{adx}{and}{Name Index}
and indexing commands are written to (or
read from) the name with the appropriate which load the package, define a “main”
(.idx or .ind) extension appended. The (original-style) index, and then define an
\printindex command is modified from author index. Then, in the body of the doc-
an old version of the LaTeX 2.09 standard ument, we might find commands like:
so that it doesn’t create its own chapter or
\index[aut]{Another Idiot}
section heading; you therefore decide what
...
names (or sectioning level, even) to use
\index{FAQs}
for the indexes, and \indexname is com-
pletely ignored. Which place an entry in the author index,
To create a “general” and an “authors” and then one in the main index. At the end
index, one might write: of the document, we have two commands:
\usepackage{multind} \printindex
\makeindex{general} \printindex[aut]
138
Which will print the main index and then required/amslatex/amscls
the author index. Supposing this lot imakeidx.sty :
to be in myfile.tex, after enough runs macros/latex/contrib/imakeidx
through LaTeX that labels are stable, exe-
index.sty :
cute the following commands (Unix-style
macros/latex/contrib/index
shell commands shown here, but the prin-
ciple is the same whatever system you’re makeidx.sty : Part of the LaTeX
using): distribution
memoir.cls:
makeindex myfile
macros/latex/contrib/memoir
makeindex myfile.adx -o myfile.and
multind.sty : macros/latex209/
and rerun LaTeX. The makeindex com- contrib/misc/multind.sty
mands process myfile.idx to myfile.
splitidx.sty and splitindex :
ind (the default action), and then myfile.
macros/latex/contrib/
adx to myfile.and, the two files needed
splitindex
as input by the two \printindex com-
mands in myfile.tex. O.7 Labels and references
The splitidx package can operate in the
255 Referring to things by their name
same way as the others: load the package
with the split option, and declare each LaTeX’s labelling mechanism is designed
index with a \newindex command: for the impersonal world of the academic
publication, in which everything has a
\newindex[hindex namei] number: an extension is necessary if we
{hshortcuti} are to record the name of things we’ve la-
and splitidx will generate a file belled. The two packages available extend
\jobname.hshortcuti to receive index
the LaTeX sectioning commands to pro-
entries generated by commands like vide reference by the name of the section.
\sindex[hshortcuti]{hitem i}. As The titleref package is a simple ex-
with the other packages, this method is tension which provides the command
\titleref; it is a stand-alone package —
limited by TeX’s total number of output
files. However, splitindex also comes with don’t use it in a document in which you
a small executable splitindex (available also need to use hyperref .
for a variety of operating systems); if you The byname package is part of the
use this auxiliary program (and don’t use smartref bundle and works well with
split), there’s no limit to the number of
smartref , and works (to an extent) with
indexes. Apart from this trick, splitidx hyperref , but the links it defines are not
supports the same sorts of things as does hyperlinks.
index. An example of use appears in the The memoir class incorporates the
documentation. functionality of titleref , but doesn’t work
The imakeidx package can do a wide with byname (though a search of comp.
text.tex on groups.google.com will
range of things (in particular, it can run
an index-builder — via \write18 com- find a patch to byname to remedy the prob-
mands — so as to simplify business of lem).
making the final copy of a document). The The hyperref bundle includes a pack-
package can also make multiple indexes; it age nameref , which will work standing
can do the job in the conventional (multind) alone (i.e., without hyperref : of course,
way, or by using the external splitindex in this mode its references are not hy-
script provided with the splitindex pack- perlinked). If you load hyperref itself,
age. (This arrangement allows efficient nameref is automatically loaded. Memoir
operation with small numbers of indexes, requires the memhfixc when running with
while retaining the flexibility of permitting hyperref ; following the sequence:
large numbers of indexes without hitting \documentclass[...]{memoir}
the restriction of numbers of active output ...
streams.) \usepackage[...]{hyperref}
The memoir class has its own multiple- \usepackage{memhfixc}
index functionality (as well as its own nameref commands may be used in a
index layout options, which other pack- memoir document.
ages delegate to the index style used by Zref defines a proposed replacement
makeindex). for all of the LaTeX reference mechanisms,
amsmidx.sty : Part of the AMS class and among other things provides name-
distribution macros/latex/ referencing mechanisms:
139
\usepackage[user,titleref]{zref} \usepackage{xr}
... \externaldocument[V1-]{volume1}
\section{hello}\zlabel{sec:one} ...
The section name is: \ztitleref{sec:one}.
... the introduction to volume1 (\ref{V1-introduction})
(One might hope that something of this To have the facilities of xr working with
sort would be the “way of the future”, but hyperref , you need xr-hyper. For sim-
things move slowly in the LaTeX world: ple hyper-cross-referencing (i.e., to a local
don’t hold your breath.) PDF file you’ve just compiled), write:
Each of titleref , byname and nameref
defines a reference command with the \usepackage{xr-hyper}
same name as the package: \titleref, \usepackage{hyperref}
\byname and \nameref. The nameref \externaldocument[V1-]{volume1}
package also defines a command ...
\byshortnameref, which uses the op- ... the \nameref{V1-introduction})...
tional ‘short’ title argument to the chap-
and the name reference will appear as an
ter and section commands. (Although it
active link to the “introduction” chapter of
comes from the same author, zref doesn’t
volume1.pdf.
define a short-name variant.)
To link to a PDF document on the Web,
byname.sty : Distributed with for which you happen to have the .aux file,
macros/latex/contrib/smartref write:
hyperref.sty :
\usepackage{xr-hyper}
macros/latex/contrib/hyperref
\usepackage{hyperref}
memoir.cls: \externaldocument[V1-]{volume1}[http://mybook.com/volum
macros/latex/contrib/memoir ...
nameref.sty : Distributed with ... the \nameref{V1-introduction})...
macros/latex/contrib/hyperref
Heiko Oberdiek’s experimental zref bun-
smartref.sty :
dle includes a hyper-crossreferencing
macros/latex/contrib/smartref
mechanism using its zref-xr module. Us-
titleref.sty : age is closely modelled on xr and xr-hyper;
macros/latex/contrib/titleref a trivial example (from a comp.text.tex
zref.sty : Distributed as part of posting) is
macros/latex/contrib/oberdiek
\usepackage{zref-xr,zref-user}
256 Referring to labels in other \zexternaldocument*{xr02}
documents ...
When producing a set of inter-related doc- \zref{foo}
uments, you’ll often want to refer to labels
The module provides all the facilities of
in another document of the set; but LaTeX,
the older packages, and can deal both with
of its own accord, doesn’t permit this.
“traditional” LaTeX labels and with zref ’s
So the package xr was written: if you
style of labels.
say
xr.sty : Distributed as part of
\usepackage{xr} macros/latex/required/tools
\externaldocument{volume1}
xr-hyper.sty : Distributed with
will load all the references from volume1 macros/latex/contrib/hyperref
into your present document.
zref bundle: Distributed as part of
But what if the documents both have
macros/latex/contrib/oberdiek
a section labelled “introduction” (likely
enough, after all)? The package provides a
means to transform all the imported labels, P How do I do. . . ?
so you don’t have to change label names
in either document. For example: P.1 Mathematics
\usepackage{xr} 257 Proof environment
\externaldocument[V1-]{volume1}
It was long thought impossible to make a
loads the references from volume1, but proof environment which automatically
prefixes every one with the string V1-. So includes an ‘end-of-proof’ symbol. Some
you would refer to the introduction to vol- proofs end in displayed maths; others do
ume 1 as: not. If the input file contains ...\] \end
140
{proof} then LaTeX finishes off the dis- 259 Defining a new log-like function
played maths and gets ready for a new line in LaTeX
before it reads any instructions connected Use the \mathop command, as in:
with ending the proof, so the code is very
tricky. You can insert the symbol by hand, \newcommand{\diag}{\mathop{\mathrm{diag}}}
but the (apparently) original ‘automatic’ Subscripts and superscripts on \diag
solution came with Paul Taylor’s QED. will be placed below and above the func-
Nowadays, the ntheorem package now tion name, as they are on \lim. If you
solves the problem for LaTeX users: it pro- want your subscripts and superscripts al-
vides an automatic way of signalling the ways placed to the right, do:
end of a proof.
\newcommand{\diag}{\mathop{\mathrm{diag}}\nolimits}
The AMSLaTeX package amsthm also
provides a proof environment that does AMSLaTeX (in its amsopn pack-
the job; though you need to insert a age, which is automatically loaded
\qedhere command if the proof ends with by amsmath) provides a command
a displayed equation: \DeclareMathOperator that takes does
the same job as the first definition above.
\begin{proof} To create our original \diag command,
text... one would say:
\begin{equation*}
maths... \tag*{\qedhere} \DeclareMathOperator{\diag}{diag}
\end{equation*} \DeclareMathOperator* declares the
\end{proof} operator always to have its sub- and su-
perscripts in the “\limits position”.
The \tag*{\qedhere} construction may The amsopn command \operatorname
be used in any of AMSLaTeX’s numbering allows you to introduce ad hoc operators
environments. into your mathematics, so
amsthm.sty : Distributed as part of the
\[ \operatorname{foo}(bar)
AMSLaTeX bundle macros/latex/
\]
required/amslatex
typesets the same as
ntheorem.sty :
macros/latex/contrib/ntheorem \DeclareMathOperator{\foo}{foo}
...
258 Theorem bodies printed in a
\[ \foo(bar) \]
roman font
As with \DeclareMathOperator there’s
If you want to take advantage of the pow-
a starred version \operatorname* for sub-
erful \newtheorem command without the
and superscripts in the limits position.
constraint that the contents of the theorem
(It should be noted that “log-like” was
is in a sloped font (for example, you may
reportedly a joke on Lamport’s part; it is
want to use it to create remarks, examples,
of course clear what was meant.)
proofs, . . . ) then you can use the AMS-
LaTeX amsthm package (which now su- amsopn.sty : Distributed as part of the
persedes the theorem package previously AMSLaTeX distribution macros/
recommended in these answers). Alterna- latex/required/amslatex
tively, the following sets up an environ- 260 Set specifications and Dirac
ment remark whose content is in the de- brackets
fault roman font.
One of the few glaring omissions from
\newtheorem{preremark}{Remark} TeX’s mathematical typesetting capabil-
\newenvironment{remark}% ities is a means of setting separators in
the middle of mathematical expressions.
{\begin{preremark}\upshape}{\end{preremark}}
TeX provides primitives called \left
The ntheorem package provides control of and \right, which can be used to mod-
the fonts used by theorems, directly. ify brackets (of whatever sort) around a
amsthm.sty : Distributed as part mathematical expression, as in: \left(
of macros/latex/required/ <expression> \right) — the size of
amslatex the parentheses is matched to the vertical
extent of the expression.
ntheorem.sty :
However, in all sorts of mathematical
macros/latex/contrib/ntheorem
enterprises one may find oneself needing
theorem.sty : Distributed as part of a \middle command, to be used in expres-
macros/latex/required/tools sions like
141
sizes).
\left\{ x \in \mathbb{N} \middle| This establishes
x \mbox{ (or re-establishes)
even} \right\}
the maths font sizes to be used when
to specify the set of even natural numbers.
the surrounding text font size is htfsi;
The e-TeX system defines just such a com-
(htsi being the size used for \textfont,
mand, but users of Knuth’s original need
hssi for \scriptfont and hsssi for
some support. Donald Arseneau’s braket
\scriptscriptfont).
package provides commands for set speci-
For example, you might want to use a
fications (as above) and for Dirac brackets
font with a smaller body height than Com-
(and bras and kets). The package uses the
puter Modern, but still prefer CM math to
e-TeX built-in command if it finds itself
any of the alternatives. In this case, you
running under e-TeX.
might use:
braket.sty :
macros/latex/contrib/braket \DeclareMathSizes{10}{9}{7}{5}
261 Cancelling terms in maths to get 9pt maths when the surrounding
expressions body text is (nominal) 10pt.
\DeclareMathSizes may only be
A technique used when explaining the be-
used in the preamble of the document: only
haviour of expressions or equations (of-
one association is available for each text
ten for pedagogical purposes). The cancel
font size for the whole document. The
package provides several variants of can-
default settings are specified in fontdef.
cellation marks (“\”, “/” and “X”), and a
dtx in the latex distribution, and are com-
means of cancelling ‘to’ a particular value.
piled into fontmath.ltx; the arguments
Documentation of cancel is in the pack-
to the command are just numbers (‘pt’ is
age file.
assumed), but some of them are written us-
cancel.sty : ing LaTeX abbreviations for standard font
macros/latex/contrib/cancel sizes. Beware simply copying (parts of)
262 Adjusting maths font sizes the LaTeX definitions — since they con-
tain those internal abbreviations, they need
In Plain TeX, when you introduce a new
to be treated as internal commands.
font size you must also declare what size
fonts are to be used in mathematics with fontdef.dtx :
it. This is done by declaring \textfont, macros/latex/base/fontdef.dtx
\scriptfont and \scriptscriptfont fontmath.ltx : macros/latex/
for the maths families you’re using; all unpacked/fontmath.ltx
such things are described in chapter 17 of
the TeXbook and in other books and tuto- 263 Ellipses
rials that discuss Plain TeX in sufficient Ellipses are commonly required, and La-
detail. TeX natively supplies a fair range (\dots,
In LaTeX, of course, all this stuff is \cdots, \vdots and \ddots). By using
automated: there is a scheme that, for the graphics package, one can change the
each (text) font size, determines what slope of the \ddots command, as in
maths font sizes are to be used. The
$ ... \reflectbox{$\ddots$} ... $
scheme first checks a set of “known”
text sizes, for each of which maths sizes While this works, it is not a recommended
are declared in advance. If the text size way of achieving the desired result (see
isn’t “known”, the script- and scriptscript- below). Moreover, LaTeX’s range is not
font sizes are calculated as fixed ratios adequate to everyone’s requirements, and
of the tex font size. (The values used at least three packages provide extensions
are \defaultscriptratio=0.7, and to the set.
\defaultscriptscriptratio=0.5.) The AMSLaTeX bundle provides a
The fixed-ratio formula is capable of range of “semantically-named” ellipses,
producing inconvenient results (particu- for use in different situations: \dotsb
larly if you are using fonts which LaTeX for use between pairs of binary operators,
believes are only available in a fixed set of \dotsc for use between pairs of commas,
sizes). You may also want to replace La- and so on.
TeX’s ideas altogether, for example by set- The yhmath package defines an
ting maths noticeably larger or smaller than \adots command, which is the analogue
its surrounding text. For this purpose, the of \ddots, sloping forwards rather than
LaTeX command \DeclareMathSizes backwards. The yhmath package comes
{htfsi}{htsi}{hssi}{hsssi} may be with a rather interesting font that extends
used (this is the same command that La- the standard cmex; details are in the docu-
TeX itself uses to define its own set of mentation.
142
The mathdots package (besides fix- and for “\nolimits placement” in display
ing up the behaviour of (La)TeX \ddots maths, \nolimits:
and \vdots when the font size changes)
provides an “inverse diagonal” ellipsis \[\textstyle\sum_{n=1}^{m} ...\]
\iddots (doing the same job as yhmath’s
will serve. Either of these forms may have
\adots, but better).
effects other than on the operator you’re
Documentation of yhmath appears, pro- considering, but there are still those who
cessed, in the distribution (thus saving you prefer this formulation.
the bother of installing the package be-
Remember, if you’re declaring a spe-
fore being able to read the documentation).
cial operator of your own, the AMSLaTeX
Documentation of mathdots appears at the
functions (that you ought to be using) al-
end the package file itself.
low you to choose how limits are displayed,
amslatex : macros/latex/required/ at definition time.
amslatex (Note that the macro \int normally
graphics.sty : Part of the macros/ has \nolimits built in to its definition.
latex/required/graphics bundle There is an example in the TeXbook to
show how odd \int\limits looks when
mathdots.sty :
typeset.)
macros/generic/mathdots
yhmath: fonts/yhmath
265 Text inside maths
When we type maths in (La)TeX, the let-
264 Sub- and superscript positioning
ters from which we make up ordinary text
for operators
assume a special significance: they all be-
The commonest hand-written style for ex- come single-letter variable names. The let-
pressions is to place the limit expressions ters appear in italics, but it’s not the same
on operators such as \sum and \int phys- sort of italics that you see when you’re typ-
ically above and below the operator. In ing ordinary text: a run of maths letters
(La)TeX, we write these limit expressions (for example “here”) looks oddly “lumpy”
using sub- and superscripts applied to the when compared with the word written in
operator, but they don’t always appear in italic text. The difference is that the italic
the “handwritten” way in TeX’s output. text is kerned to make the letters fit well
The reason is, that when an expres- together, whereas the maths is set to look
sion appears in non-display maths, in as if you’re multiplying h by e by r by e.
running text (and is therefore in TeX The other way things are odd in TeX maths
\textstyle), placing the limits thus could typing is that spaces are ignored: at best
lead to ragged line spacing (and hence we can write single words in this oddly
difficult-to-read text). It is therefore com- lumpy font.
mon (in \textstyle) to place the limits So, if we’re going to have good-
as one would sub- and superscripts of vari- looking text in amongst maths we’re writ-
ables. ing, we have to take special precautions. If
This is not universally satisfactory, so you’re using LaTeX, the following should
the primitive \limits is provided: help.
The simplest is to use \mbox or
$\sum\limits_{n=1}^{m} ...$
\textrm:
which will place the limits right above and
$e = mc^2 \mbox{here we go again}$
below the symbol (and be blowed to the
typography. . . ). The problem is that, with either, the size of
Contrariwise, you may wish to change the text remains firmly at the surrounding
the arrangement of the limits when in text size, so that
\displaystyle. For this purpose, there’s
a corresponding \nolimits: $z = a_{\mbox{other end}}$
places the text “and” on a separate line 267 Line-breaking in in-line maths
before the last line of the display. If
TeX, by default, allows you to split a math-
the interjected text is short, or the equa-
ematical expression at the end of the line;
tions themselves are light-weight, you
it allows breaks at relational operators (like
may find that \intertext leaves too
“=”, “<”, etc.) and at binary operators (like
much space. Slightly more modest is
“+”, “-”, etc.). In the case of large expres-
the \shortintertext command from the
sions, this can sometimes be a life-saver.
mathtools package:
However, in the case of simple expres-
\begin{align} sions like a = b + c, a break can be really
a =& b disturbing to the reader, and one would like
\shortintertext{or} to avoid it.
c =& b Fortunately, these breaks are control-
\end{align} lable: there are “penalties” associated with
each type of operator: the penalty says how
To have the text on the same line as the undesirable a break at each point is. De-
second equation, one can use the flalign fault values are:
environment (from amsmath) with lots of
dummy equations (represented by the dou- \relpenalty = 500
ble & signs): \binoppenalty = 700
144
You make the break progressively less at- 269 Even subscript height
tractive by increasing these values. You Other things being equal, TeX will aim
can actually forbid all breaks, everywhere, to position subscripts and superscripts in
by: places that “look good”. Unfortunately, it
only does this for the sub- and superscripts
\relpenalty = 10000
of each atom at a time, so if you have
\binoppenalty = 10000
$ X^{1}_{2} X_{2} $
If you want just to prevent breaks in a sin-
gle expression, write: the second subscript will appear higher,
since the first has moved down to avoid the
{%
superscript; the effect can be noticeably
\relpenalty = 10000
distracting:
\binoppenalty = 10000
$a=b+c$ X21 X2
}
You can avoid the problem, for a single
and the original values will remain undis- instance, by
turbed outside the braces. This is tedious:
there is often value in an alternative ap- $ X^{1}_{2} X^{}_{2} $
proach, in which you say which parts of the
here, the dummy superscript has the requi-
expression may not break whatever hap-
site “pushing down” effect:
pens, and fortunately this is surprisingly
easy. Suppose we want to defer a break X21 X2
until after the equality, we could write:
While this technique does what is nec-
${a+b+c+d} = z+y+x+w$ essary, it is tedious and potentially error-
prone. So, for more than one or two equa-
The braces say “treat this subformula as
tions in a document, the LaTeX user is ad-
one atom” and (in TeX at least) atoms don’t
vised to use the subdepth package, which
get split: not a \binoppenalty change in
forces the lower position for all subscripts.
sight.
subdepth.sty :
268 Numbers for referenced macros/latex/contrib/subdepth
equations only
There are those who consider that papers
P.2 Lists
look untidy with numbers on every equa- 270 Fancy enumeration lists
tion; there is also a school of thought that The enumerate package allows you to con-
claims that there should be numbers every- trol the display of the enumeration counter.
where, in case some reader wants to make The package adds an optional parameter
reference an equation to which the author to the enumerate environment, which is
made no cross-reference. used to specify the layout of the labels.
If you hold to the “only cross- The layout parameter contains an enumer-
referenced” school of thought, you can ation type (‘1’ for arabic numerals, ‘a’ or
(using the \nonumber command on the ‘A’ for alphabetic enumeration, and ‘i’ or
relevant equations, or by using the AM- ‘I’ for Roman numerals), and things to act
SLaTeX unnumbered environments such as decoration of the enumeration. So, for
as equation*) mark those of your equa- example
tions to which you make no reference. In
a long or complex paper, this procedure \usepackage{enumerate}
could well become deeply tedious. ...
Fortunately, help is at hand: the \begin{enumerate}[(a)]
mh bundle’s mathtools package offers \item ... ...
a ‘showonlyrefs’ switch through its \end{enumerate}
\mathtoolsset command; when that’s in
operation, only those equations to which starts a list whose labels run (a), (b), (c),
you make reference will be numbered in . . . ; while
the final output. See the package’s docu-
\usepackage{enumerate}
mentation for details of how to make refer-
...
ences when the switch is in effect.
\begin{enumerate}[I/]
mathtools.sty : Distributed as part of \item ... ...
macros/latex/contrib/mh \end{enumerate}
145
starts a list whose labels run I/, II/, III/, . . . \tightlist (and *-ed versions of them);
The paralist package, whose primary
see section 8.6 of the memoir manual.
purpose is compaction of lists, provides There are packages that provide some
the same facilities for its enumerate-like
control of list spacing, but they seldom
environments. address the separation from surrounding
If you need non-stereotyped designs,
text (defined by \topsep). The expdlist
the enumitem package gives you most of
package, among its many controls of the
the flexibility you might want to design
appearance of description lists, offers
your own. The silly roman example above
a compaction parameter (see the docu-
could be achieved by: mentation); the mdwlist package offers a
\makecompactlist command for users’
\usepackage{enumitem}
own list definitions, and uses it to define
...
compact lists itemize*, enumerate* and
\begin{enumerate}[label=\Roman{*}/]
description*. In fact, you can write
\item ... ...
lists such as these commands define pretty
\end{enumerate}
straightforwardly — for example:
Note that the ‘*’ in the key value stands for \newenvironment{itemize*}%
the list counter at this level. You can also {\begin{itemize}%
manipulate the format of references to list \setlength{\itemsep}{0pt}%
item labels: \setlength{\parskip}{0pt}}%
\usepackage{enumitem} {\end{itemize}}
...
The paralist package provides several ap-
\begin{enumerate}[label=\Roman{*}/, ref=(\roman{*})]
proaches to list compaction:
\item ... ...
\end{enumerate} • its asparaenum environment formats
each item as if it were a paragraph
to make references to the list items format introduced by the enumeration label
appear as (i), (ii), (iii), etc. (which saves space if the item texts
The memoir class includes functions are long);
that match those in the enumerate package, • its compactenum environment is the
and has similar functionality for itemize same sort of compact list as is pro-
lists. vided in expdlist and mdwlist; and
enumerate.sty : Distributed as part of • its inparaenum environment pro-
macros/latex/required/tools duces a list “in the paragraph”, i.e.,
enumitem.sty : with no line break between items,
macros/latex/contrib/enumitem which is a great space-saver if the list
item texts are short.
memoir.cls:
macros/latex/contrib/memoir The package will manipulate its
paralist.sty : enumerate environment labels just like
macros/latex/contrib/paralist the enumerate package does.
Paralist also provides itemize
271 How to adjust list spacing equivalents (asparaitem, etc.), and
Lamport’s book lists various parameters description equivalents (asparadesc,
for the layout of list (things like \topsep, etc.).
\itemsep and \parsep), but fails to men- The multenum package offers a more
tion that they’re set automatically within regular form of paralist’s inparaenum;
the standard (LaTeX-defined) lists. This you define a notional grid on which list
happens because each list executes a com- entries are to appear, and list items will
mand \@listhdepthi (the depth appear- always appear at positions on that grid.
ing as a lower-case roman numeral); what’s The effect is somewhat like that of the
more, the top-level \@listi is usually re- ‘tab’ keys on traditional typewriters; the
set when the font size is changed. As a package was designed for example sheets,
result, it’s rather tricky for the user to con- or lists of answers in the appendices of a
trol list spacing. Of course, the real an- book.
swer is to use a document class designed The expdlist, mdwlist and paralist
with more modest list spacing, but we all packages all offer other facilities for list
know such things are hard to come by. configuration: you should probably not try
The memoir class doesn’t provide more the “do-it-yourself” approaches outlined
compact lists, but offers the user control below if you need one of the packages for
over the list spacing using \firmlist and some other list configuration purpose.
146
For ultimate flexibility (including ma-
while in the case of description lists, the
nipulation of \topsep), the enumitem
item labels are under the user’s control so
package permits adjustment of list param-
there’s no automatic issue of continuity.
eters using a “key=hvaluei” format. ForFor enumerate lists, the labels are
example, one might write generated automatically, and are context-
sensitive, so the context (in this case, the
\usepackage{enumitem} state of the enumeration counter) needs to
... be preserved.
\begin{enumerate}[topsep=0pt, partopsep=0pt]
The belt-and-braces approach is to re-
\item ... member the state of the enumeration in
\item ... your own counter variable, and then restore
\end{enumerate} it when restarting enumerate:
to suppress all spacing above and below \newcounter{saveenum}
your list, or ...
\usepackage{enumitem} \begin{enumerate}
... ...
\setcounter{saveenum}{\value{enumi}}
\begin{enumerate}[itemsep=2pt,parsep=2pt]
\item ... \end{enumerate}
\item ... <Commentary text>
\end{enumerate} \begin{enumerate}
\setcounter{enumi}{\value{saveenum}}
to set spacing between items and between ...
paragraphs within items. Enumitem also \end{enumerate}
permits manipulation of the label format
in a more “basic” (and therefore more flex- This is reasonable, in small doses. . .
ible) manner than the enumerate package Problems (apart from sheer verbosity)
does. are getting the level right (“should I use
The ultimate in compaction (of every counter enumi, enumii, . . . ”) and remem-
sort) is offered by the savetrees package; bering not to nest the interruptions (i.e., not
compaction of lists is included. The pack- to have a separate list, that is itself inter-
age’s prime purpose is to save space at rupted) in the “commentary text”).
every touch and turn: don’t use it if you’re The mdwlist package defines com-
under any design constraint whatever! mands \suspend and \resume that sim-
plify the process:
enumerate.sty : Distributed as part of
macros/latex/required/tools \begin{enumerate}
enumitem.sty : ...
macros/latex/contrib/enumitem \suspend{enumerate}
<Commentary text>
expdlist.sty :
\resume{enumerate}
macros/latex/contrib/expdlist
...
memoir.cls: \end{enumerate}
macros/latex/contrib/memoir
The package allows an optional name (as
memoir manual: macros/latex/
in \suspend[id]{enumerate}) to allow
contrib/memoir/memman.pdf
you to identify a particular suspension, and
mdwlist.sty : Distributed as part of hence provide a handle for manipulating
macros/latex/contrib/mdwtools nested suspensions.
multenum.sty : If you’re suspending a fancy-
macros/latex/contrib/multenum enumeration list, you need to re-supply
the optional “item label layout” parame-
paralist.sty :
ters required by the enumerate package
macros/latex/contrib/paralist
when resuming the list, whether by the belt-
savetrees.sty : macros/latex/ and-braces approach, or by the mdwlist
contrib/savetrees \resume{enumerate} technique. The
272 Interrupting enumerated lists task is a little tedious in the mdwlist case,
since the optional argument has to be
It’s often convenient to have commentary encapsulated, whole, inside an optional
text, ‘outside’ the list, between successive argument to \resume, which requires use
entries of a list. In the case of itemize of extra braces:
lists this is no problem, since there’s never
anything to distinguish successive items, \begin{enumerate}[\textbf{Item} i]
147
... if it were a second paragraph to “outer item
\suspend{enumerate} 2”, which is hardly satisfactory.
<comment> enumerate.sty : Distributed as part of
\resume{enumerate}[{[\textbf{Item} macros/latex/required/tools
i]}]
...
enumitem.sty :
\end{enumerate}
macros/latex/contrib/enumitem
The enumitem package, in its most recent expdlist.sty :
release, will also allow you to resume lists: macros/latex/contrib/expdlist
xtab.sty :
279 The thickness of rules in LaTeX
macros/latex/contrib/xtab
tables
278 How to alter the alignment of The rules in a LaTeX table are by default
tabular cells 0.4pt thick; this is in fact a default built
One often needs to alter the alignment of a in at the lowest level, and applies to all
tabular p (‘paragraph’) cell, but problems rules (including those separating blocks of
at the end of a table row are common. With running text).
a p cell that looks like: Sometimes, however, we look at a table
and find we want the rules to stand out —
... & \centering blah ... \\ perhaps to separate the text from the rest of
one is liable to encounter errors that com- the body text, or to make the sections of the
plain about a “misplaced \noalign” or table stand out from one another. However,
“extra alignment tab”, or the like. The a quick review of any LaTeX manual will
problem is that the command \\ means reveal no technique for making any one
different things in different circumstances: rule stand out, and a little experimentation
the tabular environment switches the shows that it is indeed pretty difficult to
meaning to a value for use in the ta- prevent a change “bleeding” out to affect
ble, and \centering, \raggedright and other rules in the same table.
\raggedleft all change the meaning to If you look at what we have to say
something incompatible. Note that the on the design of tables, elsewhere among
problem only arises in the last cell of a row: these FAQs, and you may sense that the
since each cell is set into a box, its settings design of LaTeX simply skipped the issues
are lost at the & (or \\) that terminates it. surrounding table design: that’s presum-
In the old days, the actual value of \\ ably why there’s no facilities to help you.
that the tabular environment uses was Specifically, the length \arrayrulewidth
only available as an internal command. affects the thickness of the rules (both hor-
Nowadays, the value is a public command, izontal and vertical) within both tabular
and you can in principle use it explicitly: and array environments. If you change
from the default (see above) only as far as
... & \centering blah ... \tabularnewline
\setlength{\arrayrulewidth}{1pt}
(but that’s a rather verbose way of doing
the change is remarkably striking. How-
things).
ever, really quite subtle user level program-
The array package provides a com-
ming proves incapable of changing just
mand \arraybackslash which restores
one rule: it’s necessary to delve into the
\\ to its correct (within table) meaning;
(rather tricky) code of \hline and \cline
the command may be used in array’s “field
themselves.
format” preamble specifications:
Fortunately, this job has already
been done for the community: the
\begin{tabular}{... >{\centering\arraybackslash}p{50mm}}
... booktabs package defines three different
classes of rule (\toprule, \midrule and
The \tabularnewline and \bottomrule), and the package documen-
\arraybackslash commands are (some- tation offers hints on how to use them. You
what) modern additions to LaTeX and are strongly advised to read the documen-
the array package, respectively. In the tation pretty carefully.
unlikely event that neither is available, The memoir class includes the
the user may try the (old) solution which booktabs package, and repeats the doc-
preserves the meaning of \\: umentation in its compendious manual.
\newcommand\PBS[1]{\let\temp=\\%
Note that none of the above mentions
#1%
the issue of the weight of vertical rules
\let\\=\temp
(except in passing). For the reasons, see
}
the documentation of the booktabs pack-
age (again); vertical rules in tables are in
which one uses within a table as: any case even more trickily coded than are
152
horizontal rules, and if their lack of con- with shadow boxes, various MS-DOS
figurability makes them still less attractive, formats, etc.). The command for in-
so much the better for the design of your serting a picture at the start of a para-
document. graph is:
booktabs.sty : \parpic(width,height)(x-off,y-off)[Options][Position
macros/latex/contrib/booktabs Paragraph text
memoir.cls: All parameters except the Picture are
macros/latex/contrib/memoir optional. The picture can be posi-
280 Flowing text around figures tioned left or right, boxed with a rect-
angle, oval, shadowbox, dashed box,
There are several LaTeX packages that pur-
and a caption can be given which will
port to do this, but they all have their limita-
be included in the list of figures.
tions because the TeX machine isn’t really
Unfortunately (for those of us whose
designed to solve this sort of problem. Piet
understanding of German is not good),
van Oostrum has conducted a survey of the
the documentation is in German. Piet
available packages; he recommends:
van Oostrum has written a summary
floatflt floatflt is an improved version in English.
(for LaTeX2e) of floatfig.sty, and
its syntax is: All of the above deal insertions at one or
other margin; they are able to take advan-
\begin{floatingfigure}[options]{width of figure}
tage of the TeX \parshape primitive that
figure contents allows you to adjust the margins of the text
\end{floatingfigure} of a paragraph, by line (Knuth provides
There is a (more or less similar) an example of such use, with text typeset
floatingtable environment. in a circle, half-overlapping the margin,
The tables or figures can be set left or in chapter 14 of the TeXbook). To place
right, or alternating on even/odd pages insertions in the middle of a paragraph re-
in a double-sided document. quires effort of an entirely different sort;
The package works with the the cutwin package does this for you. It re-
multicol package, but doesn’t work quires a set of “part line widths” (two per
well in the neighbourhood of list en- line), and typesets the “cutout” section of
vironments (unless you change your the paragraph line by line. The examples in
LaTeX document). the package documentation look enticing.
wrapfig wrapfig has syntax: Plain TeX users only have one option:
\begin{wrapfigure}[height of figure (which
figflow doesn’t work in LaTeX).
in lines]{l,r,...}[overhang]{width}
figure, caption, etc. Figflow only offers flowed figures at the
\end{wrapfigure} start of the paragraph, but it seems per-
fectly functional. Syntax is
The syntax of the wraptable environ-
ment is similar. \figflow{hwidthi}{hheighti}
The height may be omitted, in which {hfigurei}
case it will be calculated from the size
of the figure; the package will use (the user is responsible for having the di-
the greater of the specified and the ac- mensions correct, and for ensuring the fig-
tual width. The {l,r,etc.} parame- ure fits on the page).
ter may also be specified as i(nside)
cutwin.sty :
or o(utside) for two-sided documents,
macros/latex/contrib/cutwin
and uppercase may be used to indicate
that the picture should float. The over- figflow.tex :
hang allows the figure to be moved macros/plain/contrib/figflow
into the margin. The figure or table
floatflt.sty :
will entered into the list of figures or
macros/latex/contrib/floatflt
tables if you use the \caption com-
mand. picins.sty : macros/latex209/
The environments do not work within contrib/picins
list environments that end before the picins documentation summary:
figure or table has finished, but can be macros/latex209/contrib/
used in a parbox or minipage, and in picins/picins.txt
twocolumn format.
picins Picins is part of a large bundle wrapfig.sty :
that allows inclusion of pictures (e.g., macros/latex/contrib/wrapfig
153
281 Diagonal separation in corner \usepackage{array}
cells of tables \newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
You want to label both the top or bot- \newcolumntype{^}{>{\currentrowstyle}}
tom row and the left- or rightmost column, \newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
somewhere at the corner of the table where #1\ignorespaces
the row and column meet. A simple way to }
achieve the result is to construct the table
Now, we put ‘$’ before the first column
with an arrangement of rules (and possibly
specifier; and we put ‘^’ before the mod-
\multicolumn entries), to look like:
ifiers of subsequent ones. We then use
----------------- \rowstyle at the start of each row we
x y want to modify:
--------------
\begin{tabular}{|$l|^l|^l|} \hline
1 2 3 4 5
\rowstyle{\bfseries}
-----------------
Heading & Big and & Bold \\ \hline
1
Meek & mild & entry \\
2
Meek & mild & entry \\
3
\rowstyle{\itshape}
4
Strange & and & italic \\
5
Meek & mild & entry \\ \hline
-----------------
\end{tabular}
However, this doesn’t satisfy everyone:
many want the labelling in a single cell The array package works with several
at the top left of the table. It sounds a other tabular-like environments from
simple enough requirement, yet it calls for other packages (for example longtable),
some slightly tricky LaTeX coding. The but unfortunately this trick won’t always
diagbox package does this job for you: it work.
defines a command \diagbox whose two array.sty : Distributed as part of
arguments provide the texts to be used; an macros/latex/required/tools
optional argument may be used for fine
tuning of the result. It draws a picture with 283 Merging cells in a column of a
the two labels on either side of a slanting table
line; the command (and hence the picture) It’s easy to come up with a table design
may be placed in the corner cell, where the that requires a cell that spans several rows.
labelled row and column meet. An example is something where the left-
The diagbox package supersedes most column labels the rest of the table;
slashbox; the older package’s commands this can be done (in simple cases) by using
\slashbox and \backslashbox are pro- diagonal separation in corner cells, but that
vided in a compatible way in the newer technique rather strictly limits what can be
package, to ease transition. used as the content of the cell.
diagbox.sty : The multirow package enables you to
macros/latex/contrib/diagbox construct such multi-row cells, in a very
simple manner. For the simplest possible
slashbox.sty : use, one might write:
macros/latex/contrib/slashbox
\begin{tabular}{|c|c|}
282 How to change a whole row of a
\hline
table
\multirow{4}{*}{Common g text}
Each cell of a table is set in a box, so that & Column g2a\\
a change of font style (or whatever) only & Column g2b \\
lasts to the end of the cell. If one has a & Column g2c \\
many-celled table, or a long one which & Column g2d \\
needs lots of rows emphasising, putting a \hline
font style change command in every cell \end{tabular}
will be impossibly tedious.
With the array package, you can define and multirow will position “Common g
column modifiers which will change the text” at the vertical centre of the space de-
font style for a whole column. However, fined by the other rows. Note that the rows
with a bit of subtlety, one can make such that don’t contain the “multi-row” speci-
modifiers affect rows rather than columns. fication must have empty cells where the
So, we set things up by: multi-row is going to appear.
154
The “*” may be replaced by a column multirow.sty :
width specification. In this case, the argu- macros/latex/contrib/multirow
ment may contain forced line-breaks:
P.4 Floating tables, figures, etc.
\begin{tabular}{|c|c|}
284 Floats on their own on float pages
\hline
It’s sometimes necessary to force a float
\multirow{4}{25mm}{Common\\g text}
& Column g2a\\ to live on a page by itself. (It’s sometimes
& Column g2b \\ even necessary for every float to live on
& Column g2c \\ a page by itself.) When the float fails to
& Column g2d \\ ‘set’, and waits for the end of a chapter or
\hline of the document, the natural thing to do is
\end{tabular} to declare the float as
• Take advantage of the fact that the So, we make an entry for the List of Fig-
mandatory argument doesn’t ‘move’ ures, which doesn’t hold troublesome com-
if the optional argument is present: mands, such as \footnote.
\section[title]{title\footnote However, as well as all of the above,
{title ftnt}} one also has to deal with the tendency of
• Use the footmisc package, with pack- the \caption command to produce the
age option stable — this modi- footnote’s text twice. For this last prob-
fies footnotes so that they softly and lem, there is no tidy solution this author is
silently vanish away if used in a mov- aware of.
ing argument. With this, you simply If you’re suffering the problem, a
need: well-constructed \caption command in
% in the document preamble a minipage environment within a float (as
\usepackage[stable]{footmisc} in the example above) can produce two
... copies of the footnote body “something”.
% in the body of the document (In fact, the effect only occurs with cap-
\section{title\footnote{title ftnt}} tions that are long enough to require two
lines to be typeset, and so wouldn’t appear
footmisc.sty : with such a short caption as that in the ex-
macros/latex/contrib/footmisc ample above.)
159
The documentation of the ccaption defined in the footmisc package and in the
package describes a really rather awful memoir class (at least); \footref reduces
work-around for this problem. the above example to:
ccaption.sty : ...\footnote{Text to repeat\label{fn:repeat}}
macros/latex/contrib/ccaption ...
threeparttable.sty : macros/latex/ ...\footref{fn:repeat}
contrib/threeparttable
This is the cleanest simple way of doing the
294 Footnotes whose texts are job. Note that the \label command must
identical be inside the argument of \footnote.
If the same footnote turns up at several The fixfoot package takes away some
places within a document, it’s often inap- of the pain of the matter: you declare foot-
propriate to repeat the footnote in its en- notes you’re going to reuse, typically in
tirety over and over again. We can avoid the preamble of your document, using a
repetition by semi-automatic means, or by \DeclareFixedFoot command, and then
simply labelling footnotes that we know use the command you’ve ‘declared’ in the
we’re going to repeat and then referencing body of the document:
the result. There is no completely auto-
\DeclareFixedFootnote{\rep}{Text to repeat}
matic solution (that detects and suppresses
...
repeats) available.
...\rep{}
If you know you only have one foot-
...\rep{}
note, which you want to repeat, the solu-
tion is simple: merely use the optional ar- The package ensures that the repeated text
gument of \footnotemark to signify the appears at most once per page: it will usu-
repeats: ally take more than one run of LaTeX to
get rid of the repeats.
...\footnote{Repeating note}
... fixfoot.sty :
...\footnotemark[1] macros/latex/contrib/fixfoot
footmisc.sty :
. . . which is very easy, since we know there
macros/latex/contrib/footmisc
will only ever be a footnote number 1. A
similar technique can be used once the foot- memoir.cls:
notes are stable, reusing the number that macros/latex/contrib/memoir
LaTeX has allocated. This can be tiresome, 295 More than one sequence of
though, as any change of typesetting could footnotes
change the relationships of footnote and
repeat: labelling is inevitably better. The need for more than one series of foot-
Simple hand-labelling of footnotes isnotes is common in critical editions (and
possible, using a counter dedicated to the other literary criticism), but occasionally
job: arises in other areas.
Of course, the canonical critical edition
\newcounter{fnnumber} package, edmac, offers the facility, as does
... its LaTeX port, the ledmac package.
...\footnote{Text to repeat}% Multiple ranges of footnotes are of-
\setcounter{fnnumber}{\thefootnote}% fered to LaTeX users by the manyfoot pack-
... age. The package provides a fair array of
...\footnotemark[\thefnnumber] presentation options, as well. Another crit-
ical edition ednotes package is built upon
but this is somewhat tedious. LaTeX’s la- a basis that includes manyfoot, as its mech-
belling mechanism can be summoned to anism for multiple sets of footnotes.
our aid, but there are ugly error messages The bigfoot package also uses
before the \ref is resolved on a second manyfoot as part of its highly sophisti-
run through LaTeX: cated structure of footnote facilities, which
was also designed to support typesetting
...\footnote{Text to repeat\label{fn:repeat}}
... critical editions.
...\footnotemark[\ref{fn:repeat}] bigfoot:
macros/latex/contrib/bigfoot
Alternatively, one may use the \footref
command, which has the advantage of edmac: macros/plain/contrib/edmac
working even when the footnote mark isn’t ednotes:
expressed as a number. The command is macros/latex/contrib/ednotes
160
ledmac: zref-perpage.sty :
macros/latex/contrib/ledmac Distributed as part of zref in
macros/latex/contrib/oberdiek
manyfoot.sty : Distributed as part of
macros/latex/contrib/ncctools 297 Not resetting footnote numbers
per chapter
296 Footnotes numbered “per page” Some classes (for example, book and
The obvious solution is to make the foot- report) set up a different set of footnotes
note number reset whenever the page num- per chapter, by resetting the footnote num-
ber is stepped, using the LaTeX internal ber at the start of the chapter. This is essen-
mechanism. Sadly, the place in the docu- tially the same action as that of equation,
ment where the page number is stepped is figure and table numbers, except that foot-
unpredictable, not (“tidily”) at the end of note numbers don’t get “decorated” with
the printed page; so changing the footnote the chapter number, as happens with those
number only ever works by ‘luck’. other numbers.
As a result, resetting footnotes is in- The solution is the same: use the
evitably a complicated process, using la- chngcntr package; since the numbers
bels of some sort. It’s nevertheless im- aren’t “decorated” you can use the
portant, given the common requirement \counterwithout* variant; the code:
for footnotes marked by symbols (with \counterwithout*{footnote}{chapter}
painfully small symbol sets). There are
four packages that manage it, one way or is all you need
another. chngcntr.sty :
The perpage and zref-perpage pack- macros/latex/contrib/chngcntr
ages provide a general mechanism for re-
setting counters per page, so can obviously P.6 Document management
be used for this task. The interface is pretty 298 What’s the name of this file
simple: \MakePerPage{footnote} (in
One might want this so as to automatically
perpage) or \zmakeperpage{footnote}
generate a page header or footer record-
(in zref-perpage). If you want to restart
ing what file is being processed. It’s not
the counter at something other than 1
easy. . .
(for example to avoid something in
TeX retains what it considers the name
the LaTeX footnote symbol list), you
of the job, only, in the primitive \jobname;
can use: \MakePerPage[2]{footnote}
this is the name of the file first handed to
(in perpage) or \zmakeperpage[2]
TeX, stripped of its directory name and of
{footnote} (in zref-perpage). Note that
any extension (such as .tex). If no file
you can also load zref-perpage
was passed (i.e., you’re using TeX inter-
Perpage is a compact and efficient
actively), \jobname has the value texput
package; zref-perpage, being a zref “mod-
(the name that’s given to .log files in this
ule”, comes with zref ’s general mech-
case).
anism for extending the the \label—
This is fine, for the case of a small doc-
\[page]ref of LaTeX, which can offer
ument, held in a single file; most signifi-
many other useful facilities.
cant documents will be held in a bunch of
The footmisc package provides a va- files, and TeX makes no attempt to keep
riety of means of controlling footnote ap- track of files input to the job. So the user
pearance, among them a package option has to keep track, himself — the only way
perpage that adjusts the numbering per
is to patch the input commands and cause
page; if you’re doing something else odd them to retain details of the file name. This
about footnotes, it means you may only is particularly difficult in the case of Plain
need the one package to achieve your ends. TeX, since the syntax of the \input com-
The footnpag package also does per- mand is so peculiar.
page footnotes (and nothing else). With In the case of LaTeX, the input com-
the competition from perpage, it’s proba- mands have pretty regular syntax, and the
bly not particularly useful any more. simplest patching techniques can be used
footmisc.sty : on them. (Note that latex’s \input com-
macros/latex/contrib/footmisc mand is itself a patch on top of the Plain
TeX command. Our patches apply to the
footnpag.sty :
LaTeX version of the command, which is
macros/latex/contrib/footnpag
used as \input{file})
perpage.sty : Distributed as part It is possible to keep track of the name
macros/latex/contrib/bigfoot of the file currently being processed, but
161
it’s surprisingly difficult (these FAQs of- \input, as:
fered code, for a long time, that just didn’t \input mymacros
work in many cases). mymacros.tex won’t be recorded, and so
The currfile package provides a regular won’t listed by \listfiles — you’ve by-
means of keeping track of the details of the passed the mechanism that records its use.
current file (its name in \currfilename, The snapshot package helps the owner
directory in \currfiledir, as well as the of a LaTeX document obtain a list of the
file ‘base’ name (less its extension) and external dependencies of the document, in
its extension). Currfile does this with the a form that can be embedded at the top
help of a second package, filehook, which of the document. The intended use of the
spots file operations that use \input, package is the creation of archival copies
\InputIfFileExists and \include, as
of documents, but it has application in doc-
well as package and class loading. ument exchange situations too.
The FiNK (“File Name Keeper”) pack- The bundledoc system uses the
age keeps track of the file name and ex- snapshot to produce an archive (e.g.,
tension, in a macro \finkfile. FiNK is .tar.gz or .zip) of the files needed by
now deprecated, in favour of currfile, but your document; it comes with configura-
remains available for use in old documents. tion files for use with TeX Live-Unix and
The FiNK bundle includes a fink.el that \miktex{}. It’s plainly useful when you’re
provides support under emacs with AUC- sending the first copy of a document.
TeX.
The mkjobtexmf finds which files are
currfile.sty : used in a ‘job’, either via the -recorder
macros/latex/contrib/currfile option of TeX, or by using the (Unix) com-
filehook.sty : mand strace to keep an eye on what TeX is
macros/latex/contrib/filehook doing. The files thus found are copied (or
linked) to a directory which may then be
fink.sty : saved for transmission or archiving.
macros/latex/contrib/fink
bundledoc: support/bundledoc
299 All the files used by this
mkjobtexmf : support/mkjobtexmf
document
snapshot.sty :
When you’re sharing a document with
macros/latex/contrib/snapshot
someone else (perhaps as part of a co-
development cycle) it’s as well to arrange 300 Marking changed parts of your
that both correspondents have the same set document
of auxiliary files, as well as the document
One often needs clear indications of how a
in question. Your correspondent obviously
document has changed, but the commonest
needs the same set of files (if you use the
technique, “change bars” (also known as
url package, she has to have url too, for
“revision bars”), requires surprisingly much
example). But suppose you have a bug- trickery of the programmer. The problem
free version of the shinynew package butis that TeX ‘proper’ doesn’t provide the
her copy is still the unstable original; until
programmer with any information about
you both realise what is happening, such a
the “current position” from which a puta-
situation can be very confusing. tive start- or end-point of a bar might be
The simplest solution is the LaTeX calculated. PDFTeX does provide that in-
\listfiles command. This places a list
formation, but no PDFTeX-based change-
of the files used and their version numbers
bar package has been published, that takes
in the log file. If you extract that list and
advantage of that.
transmit it with your file, it can be used asThe simplest package that offers
a check-list in case that problems arise.
change bars is Peter Schmitt’s backgrnd.
Note that \listfiles only reg- tex; this was written as a Plain TeX appli-
isters things that are input by cation that patches the output routine, but
the “standard” LaTeX mechanisms it appears to work at least on simple La-
(\documentclass, \usepackage,
TeX documents. Wise LaTeX users will be
\include, \includegraphics and so
alerted by the information that backgrnd
on). The \input command, as modified patches their output routine, and will watch
by LaTeX and used, with LaTeX syntax, its behaviour very carefully (patching the
as: LaTeX output routine is not something to
\input{mymacros} undertake lightly. . . ).
records file details for mymacros.tex, The longest-established LaTeX-
but if you use TeX primitive syntax for specific solution is the changebar package,
162
which uses \special commands supplied documentation, latexdiff-man.pdf (part of
by the driver you’re using. You need there- the distribution). A rudimentary revision
fore to tell the package which driver to facility is provided by another Perl script,
you’re using (in the same way that you latexrevise, which accepts or rejects all
need to tell the graphics package); the changes. Manual editing of the difference
list of available drivers is pretty wide, but file can be used to accept or reject selected
does not include dvipdfm. The package changes only.
comes with a shell script chbar.sh (for backgrnd.tex : macros/generic/
use on Unix machines) that will compare misc/backgrnd.tex
two documents and generate a third which
changebar.sty : macros/latex/
is marked-up with changebar macros to
contrib/changebar
highlight changes.
The shareware WinEDT editor has changes.sty :
a macro that will generate changebar macros/latex/contrib/changes
(or other) macros to show differences framed.sty :
from an earlier version of your file, macros/latex/contrib/framed
stored in an RCS-controlled repository —
latexdiff, latexrevise:
see http://www.winedt.org/Macros/
support/latexdiff
LaTeX/RCSdiff.php
The vertbars package uses the tech- lineno.sty :
niques of the lineno package (which it macros/latex/contrib/lineno
loads, so the lineno itself must be in- memoir.cls:
stalled); it’s thus the smallest of the pack- macros/latex/contrib/memoir
ages for change bar marking, since it vertbars.sty :
leaves all the trickery to another package. macros/latex/contrib/vertbars
Vertbars defines a vertbar environment
winedt: systems/win32/winedt
to create changebars.
The framed package is another that 301 Conditional compilation and
provides bars as a side-effect of other de- “comments”
sirable functionality: its leftbar envi- While LaTeX (or any other TeX-derived
ronment is simply a stripped-down frame package) isn’t really like a compiler, peo-
(note, though, that the environment makes ple regularly want to do compiler-like
a separate paragraph of its contents, so it is things using it. Common requirements are
best used when the convention is to mark conditional ‘compilation’ and ‘block com-
a whole changed paragraph. ments’, and several LaTeX-specific means
Finally, the memoir class allows to this end are available.
marginal editorial comments, which you The simple \newcommand{\gobble}
can obviously use to delimit areas of [1]{} and \iffalse ... \fi aren’t re-
changed text. ally satisfactory (as a general solution) for
An even more comprehensive way to comments, since the matter being skipped
keep track of changes is employed by some is nevertheless scanned by TeX, not always
word-processors — to produce a document as you would expect. The scanning im-
that embodies both “old” and “new” ver- poses restrictions on what you’re allowed
sions. to skip; this may not be a problem in to-
To this end, the package changes al- day’s job, but could return to bite you to-
lows the user to manually markup changes morrow. For an example of surprises that
of text, such as additions, deletions, or may come to bite you, consider the fol-
replacements. Changed text is shown in lowing example (derived from real user
a different colour; deleted text is crossed experience):
out. The package allows you to define addi-
\iffalse % ignoring this bit
tional authors and their associated colour;
consider what happens if we
it also allows you to define a markup for
use \verb+\iftrue+ -- a surprise
authors or annotations. The documenta-
\fi
tion (very clearly) demonstrates how the
various functions work. The \iftrue is spotted by TeX as it
The Perl script latexdiff may also be scans, ignoring the \verb command; so
used to generate such markup for LaTeX the \iffalse isn’t terminated by the fol-
documents; you feed it the two documents, lowing \fi. Also, \gobble is pretty inef-
and it produces a new LaTeX document ficient at consuming anything non-trivial,
in which the changes are very visible. An since all the matter to be skipped is copied
example of the output is embedded in the to the argument stack before being ignored.
163
If your requirement is for a doc- (To include all of the document, you write
ument from which whole chapters (or
the like) are missing, consider the La- \includepdf[pages=-]{yoursource.pdf}
TeX \include/\includeonly system. If
omitting the start and end pages in the op-
you ‘\include’ your files (rather than
tional argument.)
\input them — see What’s going on in
If you want flexible facilities for includ-
my \include commands?), LaTeX writes
ing or excluding small portions of a file,
macro traces of what’s going on at the end
consider the comment, version or optional
of each chapter to the .aux file; by using
packages.
\includeonly, you can give LaTeX an
The comment package allows you
exhaustive list of the files that are needed.
to declare areas of a document to be
Files that don’t get \included are skipped
included or excluded; you make these
entirely, but the document processing con-
declarations in the preamble of your
tinues as if they were there, and page, foot-
file. The command \includecomment
note, and other numbers are not disturbed.
{version-name} declares an environ-
Note that you can choose which sections
ment version-name whose content will
you want included interactively, using the
be included in your document, while
askinclude package.
\excludecomment{version-name} de-
A variant on the \includeonly mech-
fines an environment whose content will
anism is offered by the stampinclude pack-
be excluded from the document. The pack-
age, which takes advantage of the PDF-
age uses a method for exclusion that is
TeX \pdffilemoddate command. When pretty robust, and can cope with ill-formed
an \included file is processed in abunches of text (e.g., with unbalanced
LaTeX document, an .aux file is cre-
braces or \if commands).
ated holding data such as page-number (These FAQs employ the comment
ranges and chapter/section numbers. When
package to alter layout between the printed
\stampinclude is included in a document,
(two-column) version and the PDF version
it compares the file system modification
for browsing; there are narrowversion
times for each file and its corresponding
and wideversion for the two versions of
.aux file; the file is only compiled in “this
the file.)
run” of the document if the file is newer
version offers similar facilities to
than its corresponding .aux file. The pack-
comment.sty (i.e., \includeversion
age requires a current PDFTeX, and will
and \excludeversion commands); it’s
also run on LuaTeX if the pdftexcmds pack-
far “lighter weight”, but is less robust (and
age is available (pdftexcmds emulates the
in particular, cannot deal with very large
requisite PDFTeX commands using lua.
areas of text being included/excluded).
Apart from this requirement, stampinclude
A significant development of version,
is a low-maintenace object; include it in
confusingly called versions (i.e., merely
your document and it silently does its job.
a plural of the old package name).
When you want a final version of your doc-
Versions adds a command \markversion
ument, delete all the .aux files, and and
{version-name} which defines an envi-
stampinclude won’t interfere.) ronment that prints the included text, with
The inverse can be done using the
a clear printed mark around it.
excludeonly package: this allows you to ex-
optional defines a command \opt; its
clude a (list of) \included files from your
first argument is an ‘inclusion flag’, and its
document, by means of an \excludeonly
second is text to be included or excluded.
command. Text to be included or excluded must be
If you want to select particular pages
well-formed (nothing mismatched), and
of your document, use Heiko Oberdiek’s
should not be too big — if a large body
pagesel or the selectp packages. You can
of text is needed, \input should be used
do something similar with an existing PDF
in the argument. The documentation (in
document (which you may have compiled
the package file itself) tells you how to
using pdflatex in the first place), using the
declare which sections are to be included:
pdfpages package. The job is then done
this can be done in the document preamble,
with a document looking like: but the documentation also suggests ways
in which it can be done on the command
\documentclass{article} line that invokes LaTeX, or interactively.
\usepackage[final]{pdfpages} And, not least of this style of con-
\begin{document} ditional compilation, verbatim (which
should be available in any distribution) de-
\includepdf[pages=30-40]{yoursource.pdf}
\end{document} fines a comment environment, which en-
164
ables the dedicated user of the source text
which will cause the package to pro-
editor to suppress bits of a LaTeX source
duce a file foobar.tex containing all the
file. The memoir class offers the same en-
figure and table environments, and the
vironment. \chapter and \section commands, from
An interesting variation is the
the document being processed. The new
xcomment package. This defines an envi-
file foobar.tex is generated in the course
ronment whose body is all excluded, apart
of an otherwise ordinary run on the ‘mas-
from environments named in its argument.
ter’ document. The package provides a
So, for example: good number of other facilities, including
(numeric or labelled) ranges of environ-
\begin{xcomment}{figure,table}
ments to extract, and an extract environ-
This text is not included
ment which you can use to create complete
\begin{figure}
ready-to-run LaTeX documents with stuff
This figure is included
you’ve extracted.
\end{figure}
This is not included, either askinclude.sty : Distributed as part of
\begin{table} macros/latex/contrib/oberdiek
This table also included comment.sty :
\end{table} macros/latex/contrib/comment
... excludeonly.sty : macros/latex/
\end{xcomment} contrib/excludeonly
The tagging package offers another extract.sty :
neat set of syntax, which allow the user macros/latex/contrib/extract
to apply “tags” to chunks of text, and to memoir.cls:
include and exclude tagged text, according macros/latex/contrib/memoir
to the tags. For example, the user may ‘use’
optional.sty :
text marked with some tags, and to ‘drop’
macros/latex/contrib/optional
marked with others:
pagesel.sty : Distributed as part of
\usetag{<tag list>} macros/latex/contrib/oberdiek
\droptag{<tag list>}
pdfpages.sty :
(the tag lists consist of comma-separated macros/latex/contrib/pdfpages
single words). selectp.sty :
There are then commands macros/latex/contrib/selectp
\tagged{<tag list>}{<text>} stampinclude.sty :
Distributed as part of
which reproduces the text only if the htag
macros/latex/contrib/oberdiek
listi contains at least one tag listed in the
\usetag comand, and tagging.sty :
macros/latex/contrib/tagging
\untagged{<tag list>}{<text>}
verbatim.sty : Distributed as part of
which only reproduces the text unless the macros/latex/required/tools
htag listi contains none of the tags mention version.sty :
in the \droptag command. macros/latex/contrib/version
Further commands offer an if-then-
versions.sty : macros/latex/
else setup, and specify taggedblock and
contrib/versions/versions.sty
untaggedblock environments that.
Another valuable aspect of the prob- xcomment.sty :
lem is covered by the extract package. The macros/generic/xcomment
package allows you to produce a “partial 302 Bits of document from other
copy” of an existing document: the pack- directories
age was developed to permit production of
A common way of constructing a large doc-
a “book of examples” from a set of lecture
ument is to break it into a set of files (for
notes. The package documentation shows
example, one per chapter) and to keep ev-
the following usage:
erything related to each of these subsidiary
\usepackage[ files in a subdirectory.
active, Unfortunately, TeX doesn’t have a
generate=foobar, changeable “current directory”, so that all
extract-env={figure,table}, files you refer to have to be specified rela-
extract-cmd={chapter,section} tive to the same directory as the main file.
]{extract} Most people find this counter-intuitive.
165
It may be appropriate to use the chapterfolder.sty : macros/latex/
“path extension” technique used in tempo- contrib/chapterfolder
rary installations to deal with this prob- import.sty :
lem. However, if there several files with macros/latex/contrib/import
the same name in your document, such
as chapter1/fig1.eps and chapter2/ 303 Version control using RCS, CVS
fig1.eps, you’re not giving TeX any hint or the like
If you use RCS, CVS, Subversion, Bazaar
as to which you’re referring to when in the
or Git to maintain your (La)TeX docu-
main chapter file you say \input{sect1};
ments under version control, you may need
while this is readily soluble in the case
some mechanism for including the version
of human-prepared files (just don’t name
details in your document, in such a way
them all the same), automatically produced
files have a way of having repetitiousthat they can be typeset (that is, rather than
just hiding them inside a comment).
names, and changing them is a procedure
prone to error. The most complete solution for RCS
The import package comes to your and CVS is to use the (LaTeX) package rcs,
which allows you to parse and display the
help here: it defines an \import command
contents of RCS keyword fields in an ex-
that accepts a full path name and the name
tremely flexible way. The package rcsinfo
of a file in that directory, and arranges
is simpler, but does most of what you want,
things to “work properly”. So, for example,
if /home/friend/results.tex contains and some people prefer it; it is explicitly
compatible with LaTeX2HTML.
Graph: \includegraphics{picture} If, however, you need a solution which
\input{explanation} works without using external packages, or
then \import{/home/friend/} which will work in Plain TeX, then you
{results} will include both graph and can use the following minimal solution:
explanation as one might hope. A \def\RCS$#1: #2 ${\expandafter\def\csname RCS#1\endcsna
\subimport command does the same \RCS$Revision: 1.47 $ % or any RCS keyword
sort of thing for a subdirectory (a rela- \RCS$Date: 2014/01/28 18:17:23 $
tive path rather than an absolute one), and ...
there are corresponding \includefrom \date{Revision \RCSRevision, \RCSDate}
and \subincludefrom commands.
If you are a user of Subversion, the
The chapterfolder package provides
package svn may be for you. It has explicit
commands to deal with its (fixed) model
cleverness about dealing with dates:
of file inclusion in a document. It pro-
vides commands \cfpart, \cfchapter, \documentclass{hfooi}
\cfsection and \cfsubsection, each of ...
which takes directory and file arguments, \usepackage{svn}
e.g.: \SVNdate $Date$
\author{...}
\cfpart[pt 1]{Part One}{part1}{part} \title{...}
...
which command will issue a ‘normal’ com-
\begin{document}
mand \part[pt 1]{Part One} and then
\maketitle
input the file part1/part.tex, remem-
...
bering that part1/ is now the “current
\end{document}
folder”. There are also commands of the
form \cfpartstar (which corresponds to will (once subversion has committed a
a \part* command). copy of the document) cause \maketitle
Once you’re “in” a chapterfolder- use the date that has been written into the
included document, you may use $Date$ keyword.
\cfinput to input something relative Another alternative for Subversion
to the “current folder”, or you may users is the svninfo package, which has
use \input, using \cfcurrentfolder much the same mechanisms as does svn
to provide a path to the file. (There but with a rather different focus. Svninfo
are also \cfcurrentfolderfigure does the date trick that svn performs (con-
for a figure/ subdirectory and trolled by a package option), and can set
\cfcurrentfolderlistings for a up page foot-lines using package fancyhdr.
listings/ subdirectory.) There isn’t much to choose between the
Documentation of chapterfolder is in two packages: you should read the pack-
French, but the README in the directory is ages’ documentation to see which suits you
in English. best.
166
An alternative script-based approach Newer still is the Python script try,
to version control has been taken by the which has a similar structure to arara —
vc bundle, that in certain situations might it, too, reads instructions in the document
work more reliably than any of the pack- source.
ages mentioned above. The vc bundle sup- Apparently along the same lines, is Au-
ports Bazaar, Git and Subversion usage toLaTeX. The README of the distribution
and works with both LaTeX and Plain TeX. is actual a Unix-type man-page output, and
Note that vc is the only option that cur- shows great attention to the details of the
rently claims to support Bazaar-controlled document production process.
repositories. The (Ruby) script mk (also, apparently,
Finally, for now, the gitinfo package known as latex_maker) works well with
supports Git-controlled documents. another of the author’s scripts script called
gitinfo.sty : vpp (View and Print PostScript/PDF).
macros/latex/contrib/gitinfo Windows users of the MiKTeX system
may use that system’s texify application.
rcs.sty : macros/latex/contrib/rcs
Texify deals with basic LaTeX features,
rcsinfo.sty : including generating a bibliography and
macros/latex/contrib/rcsinfo an index; it makes no claim to deal with
svn.sty : macros/latex/contrib/svn other things (such as multiple bibliogra-
phies or indexes, or lists of terminology,
svninfo.sty :
etc.), which AutoLaTeX can be configured
macros/latex/contrib/svninfo
to process.
vc: support/vc The texinfo system comes with a simi-
304 Makefiles for LaTeX documents lar utility called texi2dvi, which is capable
of “converting” either LaTeX or texinfo
LaTeX documents are tricky beasts for
files into DVI (or into PDF, using PDF-
building using (Uni*x) make on: the need
TeX).
to instruct LaTeX to run several times for
A later contribution is the bundle
essentially different reasons (for example,
latexmake, which offers a set of make rules
“get the table of contents stable”, “get the la-
that invoke texi2dvi as necessary.
bels stable”, “add the bibliography”, “add
The curious may examine the rules em-
the index”) is actually rather difficult to ex-
ployed to run the present FAQ through La-
press in the ‘ordinary’ sort of dependency
TeX: we don’t present them as a complete
graph that one constructs for make.
solution, but some of the tricks employed
The latex-make package offers help
are surely re-usable.
with this task (far more sophisticated tech-
niques than in the script that builds these arara: support/arara
FAQs); it looks good, but reports of its use AutoLaTeX: support/autolatex
(other than by its author) are scarce. FAQ distribution: help/uk-tex-faq
For a long time, the only make-like
package on CTAN was latexmk, which latexmake: support/latexmake
is a Perl script that analyses your LaTeX latex-make: support/latex-make
source for its dependencies, runs BibTeX latex_make: support/latex_maker
or makeindex as and when it notices that
latexmk : support/latexmk
those programs’ input (parts of the .aux
file, or the .idx file, respectively) has texi2dvi: Distributed as part of
changed, and so on. Latexmk is a fine solu- macros/texinfo/texinfo
tion (and was used in generating printable try : support/try
versions of these FAQs for some time); it vpp: support/view_print_ps_pdf
has recently been upgraded and has many
bells and whistles that allow it to operate as 305 How many pages are there in my
if it were a poor man’s WYSIWYG system. document?
A recent strong contender is arara, Simple documents (those that start at page
written in Java. It is (the documentation 1, and don’t have any breaks in their page
says) based on “rules” and “directives”; its numbering until their last page) present
aim is to determine what to do from ex- no problem to the seeker after this truth.
plicit instructions in the document’s source The number of pages is reported by the
code, rather than secondary sources such lastpage package in its LastPage label.
as log file analysis. Arara is relatively new For more complicated documents
on CTAN, and comes with recommenda- (most obviously, books with frontmatter
tions from many of the great and good of in a different series of page numbers) this
the LaTeX world. simple approach will not do.
167
The count1to package defines a label plain.sty : Distributed as part of
TotalPages; this is the value of its copy macros/latex/contrib/carlisle
of \count1 (a reserved TeX count register)
at the end of the document. P.7 Hyphenation
Package totpages defines a label 307 My words aren’t being
TotPages, but it also makes the regis- hyphenated
ter it uses available as a LaTeX counter, Let’s assume you’ve selected the right TeX
TotPages, which you can also reference ‘language’ — as explained in “how hyphen-
via \theTotPages. Of course, the counter ation works”, you’re not likely to get the
TotPages is asynchronous in the same correct results typesetting one language us-
way that page numbers are, but snapshots ing the hyphenation rules of another. (Se-
may safely be taken in the output routine. lect the proper language, using babel if
The memoir class defines two counters you’re a LaTeX user. This may reveal that
lastpage and lastsheet, which are set you need another set of hyphenation pat-
(after the first run of a document) to the terns; see “using a new language” for ad-
equivalent of the LastPage label and the vice on how to install it.)
TotalPages labels. So what else can go wrong?
Both count1to and totpages need the
support of the everyshi package. • Since TeX version 3.0, the limits on
how near to either end of a word hy-
count1to.sty : Distributed as part of
phenation may take place have been
macros/latex/contrib/ms
programmable (see “weird hyphen-
everyshi.sty : Distributed as part of ation”), and for some reason the
macros/latex/contrib/ms values in question may have been
lastpage.sty : corrupted in some macros you are
macros/latex/contrib/lastpage using. TeX won’t hyphenate less
than \lefthyphenmin characters af-
memoir.cls: ter the start of a word, nor less than
macros/latex/contrib/memoir \righthyphenmin before the end of a
totpages.sty : word; thus it won’t hyphenate a word
macros/latex/contrib/totpages shorter than the sum of the two min-
ima, at all. For example, since the
306 Including Plain TeX files in minima are 2 and 3 for English, TeX
LaTeX won’t hyphenate a word shorter than
LaTeX, though originally based on Plain 5 letters long, if it believes the word
TeX, does not contain all of Plain TeX’s to be English.
commands. Worse, some Plain TeX com- • TeX won’t hyphenate a word that’s
mand names appear in LaTeX, with differ- already been hyphenated. For ex-
ent semantics. As a result, special mea- ample, the (caricature) English sur-
sures need to be taken to allow general name Smyth-Postlethwaite wouldn’t
Plain TeX documents (or parts of docu- hyphenate, which could be trouble-
ments) to be typeset within LaTeX. some. This is correct English type-
The truly reliable way is to translate the setting style (it may not be correct for
Plain TeX commands, to produce an equiv- other languages), but if needs must,
alent of the original’s semantics. However, you can replace the hyphen in the
this is not practical in many circumstances, name with a \hyph command, defined
and for those occasions, the plain package \def\hyph{-\penalty0\hskip0pt\relax}
will often come to your aid. The package
This is not the sort of thing this FAQ
defines a plain environment, in which a
would ordinarily recommend. . . The
Plain TeX document may be processed:
hyphenat package defines a bundle of
\begin{plain} such commands (for introducing hy-
\input{plain-doc} phenation points at various punctua-
\end{plain} tion characters).
• There may be accent commands in the
The package is known to fail, for exam- word. The causes of and remedies for
ple, with documents that use AMSTeX; no this effect are discussed in accents and
doubt it would also fail if asked to load hyphens.
Eplain. All these things can be overcome • The hyphenation may simply not have
(although it’s not often easy), but the en- been spotted; while TeX’s algorithm
vironment saves a lot of work on many is good, it’s not infallible, and it does
occasions. miss perfectly good hyphenations in
168
some languages. When this happens, 309 (Merely) peculiar hyphenation
you need to give TeX explicit instruc- You may have found that TeX’s famed auto-
tions on how to hyphenate. matic word-division does not produce the
The \hyphenation command allows you break-points recommended by your dic-
to give explicit instructions. Provided that tionary. This may be because TeX is set
the word will hyphenate at all (that is, it up for American English, whose rules for
is not prevented from hyphenating by any word division (as specified, for example, in
of the other restrictions above), the com- Webster’s Dictionary) are completely dif-
mand will override anything the hyphen- ferent from the British ones (as specified,
ation patterns might dictate. The command for example, in the Oxford Dictionaries).
takes one or more hyphenated words as This problem is being addressed by the
argument — \hyphenation{ana-lysis UK TeX User community (see Baskerville,
pot-able}; note that (as here, for analy- issue 4.4) but an entirely satisfactory so-
sis) you can use the command to overrule lution will take time; the current status is
TeX’s choice of hyphenation (ana-lysis to be found on CTAN (see “using a new
is the British etymological hyphenation; language” for instructions on adding this
some feel the American hyphenation feels new “language”).
‘unfortunate’. . . ). UK patterns: language/
hyphenat.sty : hyphenation/ukhyphen.tex
macros/latex/contrib/hyphenat 310 Accented words aren’t
308 Weird hyphenation of words hyphenated
If your words are being h-yphenated, like TeX’s algorithm for hyphenation gives up
this, with jus-t single letters at the begin- when it encounters an \accent command;
ning or the end of the word, you may have there are good reasons for this, but it means
a version mismatch problem. TeX’s hy- that quality typesetting in non-English lan-
phenation system changed between ver- guages can be difficult.
sion 2.9 and 3.0, and macros written for For TeX macro packages, you can
use with version 2.9 can have this effect avoiding the effect by using an appropri-
with a version 3.0 system. If you are using ately encoded font (for example, a Cork-
Plain TeX, make sure your plain.tex file encoded font — see the EC fonts) which
has a version number which is at least 3.0, contains accented letters as single glyphs.
and rebuild your format. If you are using LaTeX users can achieve this end simply
LaTeX 2.09 your best plan is to upgrade by adding the command
to LaTeX2e. If for some reason you can’t, \usepackage[T1]{fontenc}
the last version of LaTeX 2.09 (released on to the preamble of their document. Other
25 March 1992) is still available (for the encodings (notably LY1, once promoted
time being at least) and ought to solve this by Y&Y inc) may be used in place of T1.
problem. Indeed, most current 8-bit TeX font encod-
If you’re using LaTeX2e, the problem ings will ‘work’ with the relevant sets of
probably arises from your hyphen.cfg hyphenation patterns.
file, which has to be created if you’re using With the advance of XeTeX and Lua-
a multi-lingual version. TeX to the mainstream, a new regime for
A further source of oddity can derive generating hyphenation tables is in place.
from the 1995 release of Cork-encoded For each language, a table is written in Uni-
fonts, which introduced an alternative hy- code, and “8-bit” versions are generated
phen character. The LaTeX2e configura- for use with various LaTeX font encod-
tion files in the font release specified use ings. Original sets of patterns remain on
of the alternative hyphen, and this could CTAN, for use when an older environment
produce odd effects with words contain- is needed.
ing an explicit hyphen. The font configu-
ration files in the December 1995 release 311 Using a new language with Babel
of LaTeX2e do not use the alternative hy- Babel is capable of working with a large
phen character, and therefore removed this range of languages, and a new user often
source of problems; the solution, again, is wants to use a language that her TeX in-
to upgrade your LaTeX. stallation is not set up to employ. Simply
LaTeX 2.09: asking Babel to use the language, with the
obsolete/macros/latex209/ command
distribs/latex209.tar.gz \usepackage[catalan]{babel}
plain.tex : macros/plain/base provokes the warning message
169
Start→Programs
Package babel Warning: No hyphenation patterns →MiKTeX
were loaded for→
(babel) Maintenance→Create all
the language ‘Catalan’
(babel) I will use the patterns
format files
loaded for \language=0 instead.
The problem is that your TeX system or get a DOS window and run:
doesn’t know how to hyphenate Catalan initexmf --dump
text: you need to tell it how before Babel On a \miktex{} distribution v2.0 or
can do its work properly. To do this, for later, the whole procedure can be
LaTeX installations, one needs to change done via the GUI. To select the new
language.dat (which is part of the Babel language, do:
installation); it will contain a line Start→Programs→MiKTeX 2→
%catalan cahyphen.tex MiKTeX Options, and select the
Languages tab. Select your language
which, if you remove the comment marker,
from the list, press the Apply button,
is supposed to instruct LaTeX to load Cata-
and then the OK button. Then select
lan hyphenation patterns when you tell it
the General tab and press the Update
to build a new format.
Now button.
Unfortunately, in many Babel distri-
Otherwise, edit the language.dat
butions, the line just isn’t right — you
file (as outlined above), and then run:
need to check the name of the file contain-
initexmf --dump
ing the patterns you’re going to use. As
just as for a pre-v2.0 system.
you can see, in the author’s system, the
name is supposed to be cahyphen.tex; Caveat: It is (just) possible that your TeX
however the file actually present on the system may run out of “pattern memory”
system is cahyph.tex — fortunately, the while generating the new format. Most
error should prove little more than an in- TeX implementations have fixed-size ar-
convenience (most of the files are in better rays for storing the details of hyphenation
distributions anyway, but an elusive one patterns, but although their size is ad-
may be found on CTAN; if you have to justable in most modern distributions, actu-
retrieve a new file, ensure that it’s correctly ally changing the size is a fiddle. If you do
installed, for which see installing a new find you’ve run out of memory, it may be
package). worth scanning the list of languages in your
Finally, you need to regenerate the for- language.dat to see whether any could
mats used (in fact, most users of Babel are reasonably be removed.
using it in their LaTeX documents, so re-
babel:
generating the LaTeX-related formats will
macros/latex/required/babel
ordinarily be enough; however, the author
always generates the lot, regardless). hyphenation patterns:
language/hyphenation
teTeX It’s possible to do the whole opera-
tion in one go, by using the texconfig 312 Stopping all hyphenation
command: It may seem an odd thing to want to do
texconfig hyphen latex (after all, one of TeX’s great advertised
which first enters an editor for you to virtues is the quality of its hyphenation) but
edit language.dat, and then regener- it’s sometimes necessary. The real problem
ates the format you specify (latex in is, that the quality of TeX’s output is by de-
this case). fault largely dependent on the presence of
Otherwise, to regenerate all formats, hyphenation; if you want to abandon hy-
do: phenation, something has to give.
fmtutil --all TeX (slightly confusingly) offers four
If you’re willing to think through what possible mechanisms for suppressing hy-
you’re doing (this is not for the faint- phenation (there were only two prior to
hearted), you can select a sequence of the extensions that arrived with TeX ver-
formats and for each one, run: sion 3).
fmtutil --byfmt hformatnamei First, one can set the hyphen-
where formatname is something like ation penalties \hyphenpenalty and
‘latex’, or: \exhyphenpenalty to an ‘infinite’ value
fmtutil --byhyphen hhyphenfilei (that is to say, 10000). This means that all
where hyphenfile is the file speci- hyphenations will sufficiently penalise the
fying hyphenation to the format — line that would contain them, that the hy-
usually language.dat phenation won’t happen. The disadvantage
MiKTeX On a \miktex{} distribution ear- of this method is that TeX will re-evaluate
lier than v2.0, do: any paragraph for which hyphenations
170
might help, which will slow TeX down. The simplest route is to use \sloppy
Second, one can select a language (or its environment version sloppypar),
for which no hyphenation patterns ex- and have TeX stretch what would other-
ist. Some distributions create a language wise be underfull lines to fill the space of-
nohyphenation, and the hyphenat pack- fered, while prematurely wrapping overfull
age uses this technique for its \nohyphens lines and stretching the remainder.
command which sets its argument without The better bet is to set the text ragged
any hyphenation. You can load hyphenat right, and at least get rid of the overfull
with the command lines; this technique is ‘traditional’ (in the
sense that typists have always done it) and
\usepackage[none]{hyphenat} may be expected to appeal to the specifiers
of eccentric document layouts (such as
to prevent any hyphenation in a single- those for dissertations), but for once their
language document. The technique can- sense conforms with typographic style. (Or
not work in a document in which babel at least, style constrained in this curious
controls language selection, since babel way.)
incorporates hyphenation change into its
language change facilities. hyphenat.sty :
macros/latex/contrib/hyphenat
Third, one can set \left- and/or
\righthyphenmin to a sufficiently large 313 Preventing hyphenation of a
value that no hyphenation could possibly particular word
succeed, since the minimum is larger than
It’s quite possible for (any) hyphenation
the length of the longest word TeX is will-
of a particular word to seem “completely
ing to hyphenate (the appropriate value is
wrong”, so that you want to prevent it be-
62).
ing hyphenated.
Fourth, one can suppress hyphenation
If the word occurs in just one place, put
for all text using the current font by the
it in a box:
command
\mbox{oddword}
\hyphenchar\font=-1
(Plain TeX users should use \hbox, and
This isn’t a particularly practical way for take care at the start of paragraphs.) How-
users to suppress hyphenation — the com- ever, boxing the word is not really advis-
mand has to be issued for every font the able unless you are sure it only occurs
document uses — but it’s how LaTeX itself once.
suppresses hyphenation in tt and other If the word occurs commonly, the best
fixed-width fonts. choice is to assert an hyphenation excep-
Which of the techniques you should tion for it:
use depends on what you actually want
to do. If the text whose hyphenation is \hyphenation{oddword}
to be suppressed runs for less than a para-
graph, your only choice is the no-hyphens This hyphenation exception (with no break
language: the language value is preserved points) will be used in preference to what
along with the text (in the same way that TeX’s hyphenation algorithm may come
the current font is); the values for penalties up with.
and hyphen minima active at the end of a In a multilingual document, repeat the
paragraph are used when hyphenation is exception specification for each language
calculated. the word may appear in. So:
Contrariwise, if you are writing a mul- \usepackage[french,english]{babel}
tilanguage document using the babel pack- \selectlanguage{english}
age, you cannot suppress hyphenation \hyphenation{oddword}
throughout using either the no-hyphens lan- \selectlanguage{french}
guage or the hyphen minima: all those val- \hyphenation{oddword}
ues get changed at a babel language switch:
use the penalties instead. (note that babel will select the default lan-
If you simply switch off hyphenation guage for the document — English, in this
for a good bit of text, the output will have case — at \begin{document}.)
a jagged edge (with many lines seriously A particular instance of this require-
overfull), and your (La)TeX run will bom- ment is avoiding the hyphenation of
bard you with warnings about overfull and acronyms; a general rule for those that con-
underfull boxes (that is, really, lines). To coct acronyms seems to be to make the
avoid this you have two options. capital-letter sequence read as near as is
171
possible like a “real” word, but hyphenat- tells us that the hyphenation is “improper”,
ing an acronym often looks silly. The TeX and that it will be “flushed”. But, just as hy-
control \uchyph is designed for suppress- phenation of words is enabled by selecting
ing such behaviour: an 8-bit font encoding, so \hyphenation
commands are rendered proper again by
\uchyph=0 selecting that same 8-bit font encoding.
For the hyphenation patterns provided for
will stop hyphenation of upper-case words.
‘legacy’, the encoding is Cork, so the com-
(Note that Plain TeX syntax is needed here:
plete sequence is:
there’s no LaTeX alternative for setting this
value.) \usepackage[T1]{fontenc}
\usepackage[french]{babel}
314 Hyphenation exceptions
\selectlanguage{french}
While TeX’s hyphenation rules are good, \hyphenation{r\’e-f\’e-rence}
they’re not infallible: you will occasion-
ally find words TeX just gets wrong. So The same sort of performance goes for any
for example, TeX’s default hyphenation language for which 8-bit fonts and corre-
rules (for American English) don’t know sponding hyphenation patterns are avail-
the word “manuscript”, and since it’s a able. Since you have to select both the lan-
long word you may find you need to hy- guage and the font encoding to have your
phenate it. You can “write the hyphenation document typeset correctly, it should not
out” each time you use the word: be a great imposition to do the selections
before setting up hyphenation exceptions.
... man\-u\-script ... Modern TeX variants (principally Xe-
TeX and LuaTeX) use unicode, internally,
Here, each of the \- commands is con- and distributions that offer them also of-
verted to a hyphenated break, if (and only fer UTF-8-encoded patterns; since the hy-
if ) necessary. phenation team do all the work “behind the
That technique can rapidly become te- scenes”, the use of Unicode hyphenation
dious: you’ll probably only accept it if is deceptively similar to what we are used
there are no more than one or two wrongly- to.
hyphenated words in your document. The
alternative is to set up hyphenations in the P.8 Odds and ends
document preamble. To do that, for the 315 Typesetting all those TeX-related
hyphenation above, you would write: logos
\hyphenation{man-u-script} Knuth was making a particular point about
the capabilities of TeX when he defined
and the hyphenation would be set for the the logo. Unfortunately (in some people’s
whole document. Barbara Beeton pub- opinion) he thereby opened floodgates to
lishes articles containing lists of these “hy- give the world a whole range of rather silly
phenation exceptions”, in TUGboat; the ‘bumpy road’ logos for TeX entities such
hyphenation ‘man-u-script’ comes from as AMSTeX, PiCTeX, BibTeX, and so
one of those articles. on, produced in a flurry of different fonts,
What if you have more than one lan- sizes, and baselines — indeed, everything
guage in your document? Simple: select one might hope to cause them to obstruct
the appropriate language, and do the same the reading process. In particular, Lam-
as above: port invented LaTeX (silly enough in itself,
with a raised small ‘A’ and a lowered ‘E’)
\usepackage[french]{babel}
and marketing input from Addison-Wesley
\selectlanguage{french}
led to the even stranger current logo for
\hyphenation{re-cher-cher}
LaTeX2e, which appends a lowered ε.
(nothing clever here: this is the “correct” Sensible users don’t have to follow this
hyphenation of the word, in the current ta- stuff wherever it goes, but, for those who
bles). However, there’s a problem here: insist, a large collection of logos is defined
just as words with accent macros in them in the texnames package (but note that this
won’t break, so an \hyphenation com- set of macros isn’t entirely reliable in La-
mands with accent macros in its argument TeX2e). The Metafont and Metapost logos
will produce an error: can be set in fonts that LaTeX2e knows
about (so that they scale with the surround-
\usepackage[french]{babel} ing text) using the mflogo package; but be
\selectlanguage{french} aware that booby-traps surround the use
\hyphenation{r\’e-f\’e-rence} of the Knuthian font for Metapost (you
172
might get META O T). You needn’t de- tures so that you can use the fonts within
spair, however — most versions of the logo LaTeX.
font distributed nowadays contain the miss- Another alternative is to use the EC
ing letters, and the author himself uses just fonts, which come with bold variants of
‘MetaPost’. the small-caps fonts.
A well-designed set of macros is pro- If you need to use Type 1 fonts, you
vided by package hologo, which defines a can’t proceed with Knuth-style fonts, since
command \hologo, which one uses as (for there are no Type 1 versions of the mf-extra
example) \hologo{pdfLaTeX} for what set. There are, however, Type 1 distribu-
you might get by typing “pdf\LaTeX”, tions of the EC fonts, so you can switch
as well as a capitalised version \Hologo to EC and use them; alternatives are dis-
{pdfLaTeX} for “Pdf\LaTeX”. cussed in 8-bit Type 1 fonts.
The package metalogo deals with a Of course, commercial fixed-width
problem of these myriad logos, that’s often fonts (even the default Courier) almost al-
ignored nowadays: the geometry of char- ways come with a bold variant, so that’s
acters from different fonts is (obviously) not a problem. Furthermore PSNFSS will
different, and they naturally fit together dif- usually provide “faked” small caps fonts,
ferently. The package makes it possible for and has no compunctions about providing
you to adjust the spacing between the the them in a bold form. Courier is (as we
letters of one of these odd logos (even the all know, to our cost) freely available; a
especially weird mirrored “E” in XeTeX). far more presentable monospace font is
For those who don’t wish to acquire LuxiMono, which is also freely available
the ‘proper’ logos, the canonical thing to (monospace text in the typeset version of
do is to say AMS-\TeX{} for AMSTeX, this FAQ uses LuxiMono, with the met-
Pic\TeX{} for PiCTeX, Bib\TeX{} for rics and LaTeX support available on the
BibTeX, and so on. archive.
hologo.sty : Distributed as part of bold-extra.sty :
macros/latex/contrib/oberdiek macros/latex/contrib/bold-
metalogo.sty : extra
macros/latex/contrib/metalogo bold tt and small caps fonts:
mflogo.sty : fonts/cm/mf-extra/bold
macros/latex/contrib/mflogo LuxiMono fonts: fonts/LuxiMono
texnames.sty :
317 Automatic sizing of minipage
info/biblio/texnames.sty
The minipage environment requires you
316 How to do bold-tt or bold-sc to specify the width of the “page” you’re
LaTeX, as delivered, offers no means of going to create. This is sometimes inconve-
handling bold “teletype” or small-caps nient: you would like to occupy less space,
fonts. There’s a practical reason for this if possible, but minipage sets a box that is
(Knuth never designed such fonts), but exactly the width you specified.
there are typographical considerations too The pbox package defines a \pbox
(the “medium weight” cmtt font is al- whose width is exactly that of the
ready pretty bold (by comparison with longest enclosed line, subject to a max-
other fixed-width fonts), and bold small- imum width that you give it. So while
caps is not popular with many professional \parbox{2cm}{Hello\\world!} pro-
typographers). duces a box of width exactly 2cm, \pbox
There’s a set of “extra” Metafont files {2cm}{Hello\\world!} produces one
on CTAN that provide bold versions of whose width is 1.79cm (if one’s using the
both cmtt and cmcsc (the small caps font). default cmr font for the text, at least). The
With modern TeX distributions, one may package also provides a \settominwidth
bring these fonts into use simply by placing [min]{length}{text} (which looks (al-
them in an appropriate place in the texmf most) like the standard \settowidth com-
tree (these are (La)TeX-specific files, so mand), and a \widthofpbox function anal-
the “public” supplier would be an appro- ogous to the \widthof command for use
priate place). Once you’ve rebuilt the file with the calc package.
indexes as necessary, TeX (and friends) The eqparbox package extends pbox’s
will automatically build whatever font files idea, by allowing you to set a series of
they need when you first make reference to boxes, all with the same (minimised) width.
them. There’s a jiffy package bold-extra (Note that it doesn’t accept a limiting max-
that builds the necessary font data struc- imum width parameter.) The package doc-
173
umentation shows the following example cover fonts which duplicate symbols — an
drawn from a joke curriculum vitae: issue which is discussed in “symbol al-
ready defined”. Some font sets (for exam-
\noindent% ple the related set: FdSymbol, MdSymbol
\eqparbox{place}{\textbf{Widgets, andInc.}}
MnSymbol) \hfill
are huge, and the accompa-
\eqparbox{title}{\textbf{Senior nying Widget Designer}}
macros cover so many \hfill
symbols that
\eqparbox{dates}{\textbf{1/95--present}}name clashes are surely a serious problem.
The pifont package (originally de-
... signed to use the Adobe Zapf Dingbats
font) avoids this sort of problem: it re-
\noindent% quires you to know the font position of
\eqparbox{place}{\textbf{Thingamabobs, any symbol Ltd.}} \hfill
you want to use (the documen-
\eqparbox{title}{\textbf{Lead Engineer}} \hfill
tation provides font tables). The basic com-
\eqparbox{dates}{\textbf{9/92--12/94}} mand is \ding{number} for a single sym-
The code makes the three items on each bol; there are commands for other fancier
of the heading lines have exactly the same uses. Pifont also allows you to select other
width, so that the lines as a whole produce fonts, for similar use.
a regular pattern down the page. A com- The yagusylo describes itself as “an
mand \eqboxwidth allows you to use the extended version of pifont, gone techni-
measured width of a group: the documenta- color”. It provides all the facilities of
tion shows how the command may be used pifont, but allows you to create your own
to produce sensible-looking columns that mnemonic names for symbols. Thus, while
mix c-, r- or l-rows, with the equivalent of you can say \yagding[family]{symbol
a p{...} entry, by making the fixed-width number}[colour], you can also define
rows an eqparbox group, and making the symbol names with \defdingname, and
last from a \parbox using the width that’s then use them with \yagding*{symbol
name} (the defined name carries the font
been measured for the group.
The varwidth package defines a family and colour specified in the argu-
varwidth environment which sets the con-
ments of \defdingname).
tent of the box to match a “narrower nat- Yagusylo is somewhat complicated, but
ural width” if it finds one. (You give it its documentation is clear; it is probably
the same parameters as you would give the best tool to use for picking and choos-
minipage: in effect, it is a ‘drop-in’ re-
ing symbols from a variety of font families.
placement.) Varwidth provides its own FdSymbol fonts: fonts/fdsymbol
ragged text command: \narrowragged, MdSymbol fonts: fonts/mdsymbol
which aims to make narrower lines and
MnSymbol fonts: fonts/mnsymbol
to put more text in the last line of the
paragraph (thus producing lines with more pifont.sty : Distributed as part of
nearly equal lengths than typically happens macros/latex/required/psnfss
with \raggedright itself). yagusylo.sty :
The documentation (in the package macros/latex/contrib/yagusylo
file) lists various restrictions and things
still to be done, but the package is already 319 Symbols for the number sets
proving useful for a variety of jobs. Mathematicians commonly use special let-
eqparbox.sty : tering for the real numbers and other stan-
macros/latex/contrib/eqparbox dard number sets. Traditionally these were
typeset in bold. In the ordinary course of
pbox.sty :
events, but mathematicians do not have ac-
macros/latex/contrib/pbox
cess to bold chalk, so they invented special
varwidth.sty : symbols that are now often used for the
macros/latex/contrib/varwidth number sets. Such symbols are known as
“blackboard bold” (or double-stroked) let-
ters; in place of the heavier strokes of a
Q Symbols, etc. bold font, (some) strokes of the letters are
doubled. The minimum useful set is upper-
318 Using symbols case letters ‘I’, ‘N’, ‘R’, ‘Q’ and ‘Z’; some
Most symbol font sets come with a pack- fonts offer a figure ‘1’ (for a unit matrix —
age that defines commands for every sym- not a number set at all).
bol in the font. While this is convenient, A set of blackboard bold capitals is
it can lead to difficulties, particularly with available in the AMS msbm fonts (msbm
name clashes when you load packages that is available at a range of design sizes, with
174
names such as msbm10). The AMS actu- The “lazy person’s” blackboard bold
ally provides a pair of font families (the macros:
other is called msam), which offer a large
number of mathematical symbols to sup- \newcommand{\R}{{\textsf{R}\hspace*{-0.9ex}%
plement those provided in Knuth’s fonts. \rule{0.15ex}{1.5ex}\hspace*{0.9ex}}}
The fonts are available in Type 1 format \newcommand{\N}{{\textsf{N}\hspace*{-1.0ex}%
in modern distributions. Support for us- \rule{0.15ex}{1.3ex}\hspace*{1.0ex}}}
ing the fonts under LaTeX is available in \newcommand{\Q}{{\textsf{Q}\hspace*{-1.1ex}%
packages amssymb and amsfonts. The font \rule{0.15ex}{1.5ex}\hspace*{1.1ex}}}
shape is a rather austere sans, which many \newcommand{\C}{{\textsf{C}\hspace*{-0.9ex}%
people don’t like (though it captures the \rule{0.15ex}{1.3ex}\hspace*{0.9ex}}}
essence of quickly-chalked writing rather
are almost acceptable at normal size if the
well).
surrounding text is cmr10 (the position of
The bbold family is set of blackboard
the vertical bar can be affected by the sur-
bold fonts written in Metafont. This set of-
rounding font). However, they are not part
fers blackboard bold forms of lower-case
of a proper maths font, and do not work
letters; the font source directory also con-
in sub- and superscripts. As we’ve seen,
tains sources for a LaTeX package that en-
there are plenty of alternatives: that mythi-
ables use of the fonts. The fonts are not
cal “lazy” person can inevitably do better
available in Type 1 format.
than the macros, or anything similar us-
The bbm family claims to provide ing capital ‘I’ (which looks even worse!).
‘blackboard’ versions of most of the cm Voluntary (La)TeX effort has redefined the
fonts . . . including the bold and bold- meaning of laziness (in this respect!).
extended series. Again, the fonts are de-
signed in Metafont and are not available AMS support files: Distributed as part
in Type 1 format. LaTeX macro support of fonts/amsfonts
comes from a package by Torsten Hilbrich. AMS symbol fonts: Distributed as part
The doublestroke family comes in just of fonts/amsfonts
roman and sans shapes, at a single weight,
bbm fonts: fonts/cm/bbm
and is available both as Metafont sources
and as Type 1; the font covers the upper- bbm macros:
case latin letters, lowercase ‘h’ and ’k’, and macros/latex/contrib/bbm
the digit ‘1’. bbold fonts: fonts/bbold
A document that shows the bbm, bbold,
blackboard evaluation set:
doublestroke and msbm fonts, so that you
info/symbols/blackboard
can get a feel for their appearance, is avail-
able (CTAN package blackboard). doublestroke fonts:
The boondox font set consists of fonts/doublestroke
Type 1 versions of the STIX mathe- fourier fonts: fonts/fourier-GUT
matics set (the originals are distributed
in OTF format). The set contains a mathpazo fonts: fonts/mathpazo
font ‘BOONDOXDoubleStruck-Regular’ newpx : fonts/newpx
(blackboard bold) (as well as a ‘bold’ ver-
newtx : fonts/newtx
sion of that.
An alternative source of Type 1 fonts pxfonts: fonts/pxfonts
with blackboard bold characters may be txfonts: fonts/txfonts
found in the steadily increasing set of
complete families, both commercial and 320 Better script fonts for maths
free, that have been prepared for use with The font selected by \mathcal is the only
(La)TeX (see choice of outline fonts). Of script font ‘built in’. However, there are
the free sets, the txfonts and pxfonts fam- other useful calligraphic fonts included
ilies both come with replicas of msam with modern TeX distributions.
and msbm, but (as noted elsewhere, there
are other reasons not to use these fonts); Euler The eucal package (part of most
revised versions of the fonts, newtx and sensible TeX distributions; the fonts
newpx are better adjusted. The mathpazo are part of the AMS font set) gives a
family includes a “mathematically signifi- slightly curlier font than the default.
cant” choice of blackboard bold characters, The package changes the font that is
and the fourier fonts contain blackboard selected by \mathcal.
bold upper-case letters, the digit ‘1’, and Type 1 versions of the fonts are avail-
lower-case ‘k’. able in the AMS fonts distribution.
175
mathabx The mathabx bundle provides eucal.sty : Distributed as part of
calligraphic letters (in both upper and fonts/amsfonts
lower case); the fonts were developed euler fonts: Distributed as part of
in MetaFont, but a version in Adobe fonts/amsfonts
Type 1 format is available. The bun-
mathabx as Metafont: fonts/mathabx
dle’s documentation offers a series
of comparisons of its calligraphic set mathabx in Type 1 format:
with Computer Modern’s (both regu- fonts/ps-type1/mathabx
lar mathematical and calligraphic let- mathrsfs.sty : Distributed as part of
ters); the difference are not large. macros/latex/contrib/jknappen
mnsymbol The mnsymbol bundle pro-
mnsymbol fonts: fonts/mnsymbol
vides (among many other symbols)
a set of calligraphic letters, though rsfs fonts: fonts/rsfs
(again) they’re rather similar to the de- rsfso fonts: fonts/rsfso
fault Computer Modern set. Script font examples: info/
RSFS The mathrsfs package uses a really symbols/math/scriptfonts.pdf
fancy script font (the name stands for
“Ralph Smith’s Formal Script”) which TeX Gyre Chorus font family :
is already part of most modern TeX Distributed as part of
distributions (Type 1 versions of the fonts/tex-gyre
font are also provided, courtesy of urwchancal: fonts/urwchancal
Taco Hoekwater). The package cre- URW Chancery L: Distributed as part of
ates a new command \mathscr. fonts/urw/base35
RSFSO The bundle rsfso provides a less
dramatically oblique version of the 321 Setting bold Greek letters in
RSFS fonts; the result proves quite LaTeX maths
pleasing — similar to the effect of The issue here is complicated by the fact
the the (commercial) script font in the that \mathbf (the command for setting
Adobe Mathematical Pi collection. bold text in TeX maths) affects a select
Zapf Chancery is the standard PostScript few mathematical ‘symbols’ (the upper-
calligraphic font. There is no package case Greek letters).
but you can easily make it available In the default configuration, lower-
by means of the command case Greek letters behave differently from
upper-case Greek letters (the lower-case
\DeclareMathAlphabet{\mathscr}{OT1}{pzc}{m}{it}
greek letters are in the maths fonts, while
in your preamble. You may find the the upper-case letters are in the original
font rather too big; if so, you can use (OT1-encoded) text fonts).
a scaled version of it like this: The Plain TeX solution does work, in a
\DeclareFontFamily{OT1}{pzc}{} limited way; you set a maths style, before
you
\DeclareFontShape{OT1}{pzc}{m}{it}{<-> start an equation;
s thus pzcmi7t}{}
[0.900]
*
\DeclareMathAlphabet{\mathscr}{OT1}{pzc}{m}{it}
{\boldmath$\theta$}
Adobe Zapf Chancery (which the does the job, but \boldmath may not be
above examples use) is distributed used in maths mode. As a result, this so-
in any but the most basic PostScript lution requires that you embed single bold
printers. A substantially identical characters in a text box:
font (to the extent that the same met-
rics may be used) is available from $... \mbox{\boldmath$\theta$} ...$
URW, called URW Chancery L: it which then causes problems in super-
is distributed as part of the “URW scripts, etc. With amsmath loaded,
base35” bundle; the urwchancal pack-
age (which includes virtual fonts to $... \text{\boldmath$\theta$} ...$
tweak appearance) provides for its use does the trick (and is less bad in regard to
as a calligraphic font. superscripts, etc), but is an unsatisfactory
The TeX Gyre font family also solution, too.
includes a Chancery replacement, These problems may be addressed by
Chorus; use it with tgchorus (and ig- using a bold mathematics package.
nore the complaints about needing to
change font shape). • The bm package, which is part of the
LaTeX tools distribution, defines a
Examples of the available styles are linked command \bm which may be used any-
from the packages’ catalogue entries. where in maths mode.
176
• The amsbsy package (which is part There is a problem, though: OT1 text
of AMSLaTeX) defines a command fonts don’t contain an underscore charac-
\boldsymbol, which (though slightly ter, unless they’re in the typewriter version
less comprehensive than \bm) covers of the encoding (used by fixed-width fonts
almost all common cases. such as cmtt). In place of such a charac-
ter, LaTeX (in OT1 encoding) uses a short
All these solutions apply to all mathe-
rule for the command \textunderscore,
matical symbols, not merely Greek letters.
but this poses problems for systems that
bm.sty : Distributed as part of interpret PDF — for example those PDF-
macros/latex/required/tools to-voice systems used by those who find
amsbsy.sty : Distributed as part of reading difficult.
AMSLaTeX macros/latex/ So either you must ensure that your un-
required/amslatex derscore characters only occur in text set in
amsmath.sty : Distributed as part a typewriter font, or you must use a more
of AMSLaTeX macros/latex/ modern encoding, such as T1, which has
required/amslatex the same layout for every font, and thus an
underscore in every font.
322 The Principal Value Integral A stable procedure to achieve this is:
symbol
% (1) choose a font that is available as T1
This symbol (an integral sign, ‘crossed’) % for example:
does not appear in any of the fonts ordinar- \usepackage{lmodern}
ily available to (La)TeX users, but it can
be created by use of the following macros: % (2) specify encoding
\def\Xint#1{\mathchoice \usepackage[T1]{fontenc}
{\XXint\displaystyle\textstyle{#1}}%
{\XXint\textstyle\scriptstyle{#1}}% % (3) load symbol definitions
\usepackage{textcomp}
{\XXint\scriptstyle\scriptscriptstyle{#1}}%
{\XXint\scriptscriptstyle\scriptscriptstyle{#1}}%
which will provide a command
\!\int}
\textunderscore which robustly selects
\def\XXint#1#2#3{{\setbox0=\hbox{$#1{#2#3}{\int}$}
the right character. The underscore pack-
\vcenter{\hbox{$#2#3$}}\kern-.5\wd0}}
age, mentioned above, will use this com-
\def\ddashint{\Xint=}
mand.
\def\dashint{\Xint-}
underscore.sty : macros/latex/
\dashint gives a single-dashed integral contrib/underscore
sign, \ddashint a double-dashed one.
324 How to type an ‘@’ sign?
323 How to typeset an underscore
character Long ago, some packages used to use the
‘@’ sign as a special character, so that
The underscore character ‘_’ is ordinar- special measures were needed to type it.
ily used in TeX to indicate a subscript in While those packages are still in princi-
maths mode; if you type _, on its own, in ple available, few people use them, and
the course of ordinary text, TeX will com- those that do use them have ready access
plain. The “proper” LaTeX command for to rather good documentation.
underscore is \textunderscore, but the Ordinary people (such as the author of
LaTeX 2.09 command \_ is an established this FAQ) need only type ‘@’.
alias. Even so, if you’re writing a docu-
ment which will contain a large number 325 Typesetting the Euro sign
of underscore characters, the prospect of The European currency “Euro” (C) is rep-
typing \_ for every one of them will daunt resented by a symbol of somewhat dubious
most ordinary people. design, but it’s an important currency and
Moderately skilled macro program- (La)TeX users need to typeset it. When the
mers can readily generate a quick hack currency first appeared, typesetting it was a
to permit typing ‘_’ to mean ‘text under- serious problem for (La)TeX users; things
score’ (the answer in “defining characters are easier now (most fonts have some way
as macros” uses this example to illustrate of providing a Euro sign), but this answer
its techniques). However, the code is some- provides a summary of methods “just in
what tricky, and more importantly there case”.
are significant points where it’s easy to Note that the Commission of the Euro-
get it wrong. There is therefore a pack- pean Community at first deemed that the
age underscore which provides a general Euro symbol should always be set in a sans-
solution to this requirement. serif font; fortunately, this eccentric ruling
177
has now been rescinded, and one may ap- bet for use in non-Computer Modern en-
ply best typesetting efforts to making it vironments. They are apparently designed
appear at least slightly “respectable” (typo- to fit with Adobe Times, Helvetica and
graphically). Courier, but can probably fit with a wider
The TS1-encoded TC fonts provided range of modern fonts.
as part of the EC font distribution provide The eurofont package provides a com-
Euro glyphs. The fonts are called Text pendious analysis of the “problem of the
Companion (TC) fonts, and offer the same euro symbol” in its documentation, and of-
range of faces as do the EC fonts them- fers macros for configuring the source of
selves. The textcomp package provides the glyphs to be used; however, it seems
a \texteuro command for accessing the rather large for everyday use.
symbol, which selects a symbol to match The euro-ce bundle is a rather pleas-
the surrounding text. The design of the ing Metafont-only design providing Euro
symbol in the TC fonts is not universally symbols in a number of shapes. The file
loved. . . Nevertheless, use the TC font ver- euro-ce.tex, in the distribution, offers
sion of the symbol if you are producing hints as to how a Plain TeX user might
documents using Knuth’s Computer Mod- make use of the fonts.
ern Fonts. Euro symbols are found in several
The each of the latin9 and latin10 input other places, which we list here for com-
encoding definitions for the inputenc pack- pleteness.
age has a euro character defined (character The marvosym font contains a Euro
position 164, occupied in other ISO Latin symbol (in a number of typographic styles),
character sets by the “currency symbol” ¤, among many other good things; the font is
which ordinary people seldom see except available in both Adobe Type 1 and True-
in character-set listings. . . ). The TC encod- Type formats.
ing file offers the command \texteuro for Other Metafont-based bundles con-
the character; that command is (probably) taining Euro symbols are to be found
only available from the textcomp package. in china2e (whose primary aim is Chi-
Use of the TC encoding character may nese dates and suchlike matters) and the
therefore made via \texteuro or via the eurosym fonts.
Latin-9 or Latin-10 character in ordinary china2e bundle:
text. macros/latex/contrib/china2e
Note that there is a Microsoft code EC fonts: fonts/ec
page position (128), too, and that has
been added to inputenc tables for CP1252 euro fonts: fonts/euro
and CP1257. (There’s another position in euro-ce fonts: fonts/euro-ce
CP858, which has it in place of “dotless eurofont.sty :
i” in CP850; the standardisation of these macros/latex/contrib/eurofont
things remains within Microsoft, so one
can never tell what will come next. . . ) eurosym fonts: fonts/eurosym
Outline fonts which contain nothing marvosym fonts: fonts/marvosym
but Euro symbols are available (free) from textcomp.sty : Part of the LaTeX
Adobe — the file is packaged as a Windows distribution.
self-extracting executable, but it may be
decoded as a .zip format archive on 326 How to get copyright, trademark,
other operating systems. The euro bun- etc.
dle contains metrics, dvips map files, and The “Comprehensive symbol list” (Com-
macros (for Plain TeX and LaTeX), for prehensive symbol list), lists the
using these fonts in documents. LaTeX symbol commands \textcopyright,
users will find two packages in the bun- \textregistered and \texttrademark,
dle: eurosans only offers the sans-serif which are available in TS1-encoded fonts,
version (to conform with the obsolete rul- and which are enabled using the textcomp
ing about sans-serif-only symbols; the package.
package provides the command \euro), In fact, all three commands are en-
whereas europs matches the Euro symbol abled in default LaTeX, but the glyphs
with the surrounding text (providing the you get aren’t terribly beautiful. In par-
command \EUR). To use either package ticular, \textregistered behaves oddly
with the latin9 encoding, you need to de- when included in bold text (for example,
fine \texteuro as an alias for the euro in a section heading), since it is composed
command the package defines. of a small-caps letter, which typically de-
The Adobe fonts are probably the best grades to a regular shape letter when asked
178
to set in a bold font. This means that the lm family offers old-style figures to Open-
glyph becomes a circled “r”, whereas the Type users (see below), but we have no
proper symbol is a circled “R”. stable mapping for lm with old-style dig-
This effect is of course avoided by use its from the Adobe Type 1 versions of the
of textcomp. fonts.
Another problem arises if you want Originally, oldstyle figures were only
\textregistered in a superscript posi- to be found the expert sets of commercial
tion (to look similar to \texttrademark). fonts, but now they are increasingly widely
Using a maths-mode superscript to do this available. An example is Matthew Carter’s
provokes lots of pointless errors: you must Georgia font, which has old-style figures
use as its normal form (the font was created for
inclusion with certain Microsoft products
\textsuperscript{\textregistered}
and is intended for on-screen viewing).
327 Using “old-style” figures OpenType fonts have a pair of axes for
number variations — proportional/tabular
These numbers are also called medieval or
and lining/oldstyle selections are com-
lowercase figures and their use is mostly
monly available. “Full feature access”
font-specific. Terminology is confusing
to OpenType fonts, making such options
since the lining figures (which are now the
available to the (La)TeX user, is already
default) are a relatively recent development
supported by XeTeX using, for example,
(19th century) and before they arrived, old-
the fontspec package. Similar support is
style figures were the norm, even when set-
also in the works for LuaTeX.
ting mathematics. (An example is Thomas
Harriot’s Artis Analyticae Praxis published boondox fonts: fonts/boondox
in 1631). In a typical old style 3, 4, 5, 7 cmolddig fonts: fonts/cmolddig
and 9 have descenders and 6 and 8 ascend eco fonts: fonts/eco
above the x-height; sometimes 2 will also
ascend (this last seems to be a variation fontinst:
fonts/utilities/fontinst
associated with French typography).
LaTeX provides a command fontspec.sty :
\oldstylenums{digits}, which by de- macros/latex/contrib/fontspec
fault uses an old-style set embedded in mathpazo fonts: fonts/mathpazo
Knuth’s ‘math italic’ font. The command
is only sensitive to ‘bold’ of the font style
of surrounding text: glyphs (for this com- R Macro programming
mand) are only available to match the nor-
mal medium and bold (i.e., bold-extended) R.1 “Generic” macros and
weights of the Computer Modern Roman techniques
fonts.
328 Non-letters in macro names
The textcomp package changes
\oldstylenums to use the glyphs in the New LaTeX users are often suprised that
Text Companion fonts (LaTeX TS1 en- macro definitions containing non-letters,
coding) when in text mode, and also such as
makes them available using the macros of \newcommand{\cul8r}{Goodbye!}
the form \text<number>oldstyle, e.g.,
fail to compile. The reason is that the TeX
\textzerooldstyle. (Of course, not all
macro language, unlike most programming
font families can provide this facility.)
languages, allows nothing but letters in
Some font packages (e.g., mathpazo)
macro names.
make old-style figures available and pro-
There are a number of techniques for
vide explicit support for making them the
defining a macro with a name like \cul8r.
default: \usepackage[osf]{mathpazo}
Unfortunately, none of the techniques is
selects a form where digits are always old-
particularly good:
style in text. The fontinst package will
automatically generate “old-style versions” 1. Use \csname. . . \endcsname to de-
of commercial Adobe Type 1 font families fine and invoke the macro:
for which “expert” sets are available. \expandafter\newcommand\csname cul8r\endcsname{Goodb
It’s also possible to make virtual fonts, I said, ‘‘\csname cul8r\endcsname’’.
that offer old-style digits, from existing
font packages. The cmolddig bundle pro- Pro: No unexpected side effects
vides a such a virtual version of Knuth’s Con: So verbose as to be unusable
originals, and the eco or hfoldsty bundles 2. Define a “special-command genera-
both provide versions of the EC fonts. The tor”, and use the resulting commands:
179
convention is to use “@” within the names
\newcommand{\DefineRemark}[2]{%
of internal
\expandafter\newcommand\csname macros to hide them from the
rmk-#1\endcsname{#2}%
} user and thereby prevent naming conflicts.
To this
\newcommand{\Remark}[1]{\csname end, LaTeX automatically treats
rmk-#1\endcsname}
... “@” as a letter while processing classes and
packages and as a non-letter while process-
\DefineRemark{cul8r}{Goodbye!}
... ing the user’s document. The key to this
\Remark{cul8r} technique is the separation: internally a
non-letter is used for macro names, and
Pro: Straightforward to use, not too
the user doesn’t see anything of it, while
untidy
the status remains “frozen” in all the defi-
Con: It’s hardly doing what we set
nitions created within the class or package.
out to do (experts will see that you
See \@ and @ in macro names for more
are defining a macro, but others
information.
likely won’t)
Note that analogous use of technique 3
3. Convince TeX that “8” is a letter: in this example would give us
\catcode‘8 = 11
\begingroup
\newcommand{\cul8r}{Goodbye!}
\catcode‘8 = 11
I said, ‘‘\cul8r’’.
\gdef\cul8r{Goodbye!}
Pro: \cul8r can be used directly \gdef\later{\cul8r}
Con: Likely to break other uses of “8” \endgroup
(such as numbers or dimensions; I said, ‘‘\later’’.
so \setlength{\paperwidth}
{8in} tells us: which works, but rather defeats the object
of the exercise. (\later has the “frozen”
! Missing number, treated as zero.
catcode for ‘8’, even though the value has
<to be read again>
reverted to normal by the time it’s used;
8
note, also, the use of the primitive com-
As a general rule, changing category mand \gdef, since \newcommand can’t
codes is something to use in extremis, make a macro that’s available outside the
after detailed examination of options. group.)
It is conceivable that such drastic ac- Recommendation: Either choose
tion could be useful for you, but most another mechanism (such as
ordinary users are well advised not \DefineRemark above), or choose another
even to try such a technique. name for your macro, one that contains
4. Define a macro \cul which must al- only ordinary letters. A common approach
ways be followed by “8r”: is to use roman numerals in place of arabic
\def\cul8r{Goodbye!} ones:
I said, ‘‘\cul8r’’.
\newcommand{\culVIIIr}{Goodbye!}
Pro: \cul8r can be used directly
Con #1: Breaks if \cul is followed which rather spoils the intent of the joke
by anything other than “8r”, with implicit in the example \cul8r!
a confusing diagnostic — \cul99
produces: 329 Repeating a command n times
! Use of \cul doesn’t matchTeX itswas not designed as a programming
definition.
<*> \cul9 language, but there are occasions when
9 you want to repeat some part of your doc-
(which would confuse someone ument, just as parts of programs need to
who hadn’t even realised there was run several times. An obvious example is
a definition of \cul in the docu- TeX-based drawing: LaTeX’s picture en-
ment). vironment and pgf (at least) provide repeat
Con #2: Silently redefines existing facilities — they are useful for drawing re-
\cul, if any; as a result, the tech-
peating patterns. As a result, “common”
nique cannot be used to define programming techniques often have to be
both a \cul8r and, say, a \cul123 emulated using obscure macro TeXniques.
macro in the same document. This answer deals with repeating an op-
eration a given number of times; repeating
Technique 3 is in fact commonly used — operations once for each of a set of objects
in a limited form — within most LaTeX is dealt with in the answer repeating “over
packages and within LaTeX itself. The a set”.
180
Plain TeX itself provides a \loop . . . \thect\
\repeat contruct, which enables you to }
repeat a command (or set of commands).
The syntax is simple enough, but it use of as you can see, the arguments are counter,
TeX conditionals is different enough that starting value and termination condition;
many people find it confusing. an optional argument supplies a step value
(default step is 1).
\newcount\foo The LaTeX picture environment has
\foo=10 a simple command for repeated drawing:
\loop
\message{\the\foo} \multiput(x,y)(xstep,ystep){n}{obj}
\advance \foo -1
\ifnum \foo>0 which places hobji (intended to be a bit of
\repeat picture) hni times at positions (hxi, hyi),
(hxi+hxstepi, hyi+hystepi), (hxi+2hxstepi,
In this slightly tricky code, \loop starts the hyi+2hystepi) and so on, adding the dis-
construct ended by \repeat, but \repeat placement again each time. The command
also “serves as” the \fi to the \ifnum. was designed for use in picture, but it
The loop above prints the numbers from makes no check, and may even be used to
10 down to 1 via TeX \message (i.e., on provide eccentric typesetting in a “regular”
the console output). sentence, such as:
The multido package is also ‘generic’
(usable both in Plain TeX and latex); it Here \multiput(0,0)(1,1){3}{we} are again.
defines a command \multido with three
arguments: with predictable (if not actually desirable)
effect. It may be used with nothing but
\multido{hvariablesi} an iterative calculation in the braced argu-
{hrepetitionsi}{hstuff to ment, in which case its graphical capabili-
repeati} ties have no effect.
When the macro is executing, the hstuff to The pgffor package, which is part of
repeati gets executed hrepetitionsi times; the pgf distribution, also provides itera-
the hvariablesi gives a list of variables that tions to support the needs of graphics. Its
can be used in hstuff i. Each variable is syntax is in the style of common program-
a composite of a command sequence and ming languages:
how it varies; so a variable “\iz=2+4” sets
\usepackage{pgffor}
\iz to 2 first time around, then 6 and 10
\newcommand{\cmd}{-x-}
in the next two iterations, and so on. (The
...
variable \iz is an integer; variables with
\foreach \n in {1,...,4}{\cmd{}}
other initial letters represent different data
types.) typesets “-x--x--x--x-”
Both current LaTeX and (experimen-
The \foreach command has the po-
tal) LaTeX3 have iteration commands for
tential drawback that its repeated unit is
internal use and for package writers; their
executed in a group, so that any calcula-
use is probably not recommendable.
tions done within the loop are lost (unless
The LaTeX distribution package ifthen
their result is made \global); however, it
offers the macro \whiledo:
does not ‘build in’ its graphical origins (as
\newcounter{ct} \multiput does) so its potential outside
... its own graphics environment “home” is
\setcounter{ct}{1} more clear.
\whiledo {\value{ct} < 5}%
forarray.sty :
{%
macros/latex/contrib/forarray
\thect\
\stepcounter {ct}% forloop.sty :
} macros/latex/contrib/forloop
The situation is more difficult still if we will have a new version of \b defined
\smooth takes an optional argument; the as “abc”.
structure of the command is so complex The ted package is a ‘token list editor’,
that the simple \let command does not and provides a command \substitute
retain the necessary detail. In this case, we which will patch the contents of a macro,
need the letltxmacro package which knows putting the result in a token-list, or (in the
about all sorts of LaTeX commands and form \Substitute*) using the result to
how to replicate them. Suppose we have a (re)define a macro. The following example
command defined as: defines a simple macro, and then changes
its definition:
\newcommand{\rough}[1][\default]{...}
\newcommand{\myfont}%
with an optional argument (substituted {\Large\sffamily\selectfont}
with \default if it’s not present) as well \Substitute*[\renewcommand{\myfont}]{\myfont}%
as an ordinary one. In this case we copy it {\Large\sffamily}{\huge\itshape}
using
The macro’s definition is now:
\LetLtxMacro{\NewRough}{\rough}
\huge\itshape\selectfont
and then repeat the technique we had
above, with one extension: The package also offers a command
\ShowTokens, which shows the content of
\renewcommand{\rough}[1][\newdef]%
its argument, one token to a line, with de-
{\mumble\OldRough[{#1}]{#2}}
tails of the token’s category code, etc. This
is recommended as a debugging tool.
We see here that (for tedious argument-
The etoolbox package (which provides
matching reasons) it is necessary to pro-
user access to e-TeX’s programming fa-
vide braces arround the optional argument
cilities) provides a command \patchcmd
that is being passed on.
which is very similar to \Substitute,
The general case may be achieved in
except that it only replaces a single in-
two ways. First, one can use the LaTeX
stance of the token(s) in its search pat-
command \CheckCommand; this compares
tern. Since not all commands may be
an existing command with the definition
patched in this way, \patchcmd takes
you give it, and issues a warning if two
extra arguments for success and failure
don’t match. Use is therefore:
cases. The package also provides com-
\CheckCommand{\complex}{horiginal mands that prepend (\pretocmd) or ap-
definitioni} pend (\apptocmd) to the definition of a
\renewcommand{\complex}{hnew command. Not all commands may be
definitioni} patched in this way; the package provides
a command \ifpatchable which checks
This technique is obviously somewhat the prerequisites, and checks that the tar-
laborious, but if the original command get command’s body does indeed include
comes from a source that’s liable to change the patch string you propose to use. (The
under the control of someone else, it does command \ifpatchable* omits the test
at least warn you that your patch is in dan- on the patch string.)
ger of going wrong. The regexpatch package deals with
Otherwise, LaTeX users may use one cases that are inaccessible with etoolbox;
of the patchcmd, ted or etoolbox packages. it uses the regular expression (pattern-
The patchcmd package addresses a matching) package l3regex from the La-
slightly simpler task, by restricting the set TeX3 distribution to find the code you need
of commands that you may patch; you to patch. The package also “knows about”
mayn’t patch any command that has an robust commands and about biblatex.
optional argument, though it does deal Finally, we’ll briefly consider a pack-
with the case of commands defined with age that is (just about) usable, but not
\DeclareRobustCommand. The package really recommendable. Patch gives you
defines a \patchcommand command, that an ingenious (and difficult to understand)
takes three arguments: the command to mechanism, and comes as an old-style La-
patch, stuff to stick at the front of its def- TeX documented macro file, which can no
inition, and stuff to stick on the end of its longer be processed to produce formatted
definition. So, after documentation, etc.. Fortunately, the file
183
(patch.doc) may be input directly, and 334 Is the argument a number?
“documentation” may found by reading the TeX’s own lexical analysis doesn’t offer
source of the package. Roughly speaking, the macro programmer terribly much sup-
one gives the command a set of instruc- port: while category codes will distinguish
tions analogous to sed substitutions, and letters (or what TeX currently thinks of
it regenerates the command thus amended. as letters) from everything else, there’s no
Unless you can’t do your job any other support for analysing numbers.
way, patch is best avoided. The simple-minded solution is to com-
etoolbox.sty : pare numeric characters with the characters
macros/latex/contrib/etoolbox of the argument, one by one, by a sequence
of direct tests, and to declare the argument
l3regex.sty : Distributed as part
“not a number” if any character fails all
of macros/latex/contrib/
comparisons:
l3experimental
\ifx1#1
letltxmacro.sty :
\else\ifx2#1
Distributed as part of
...
macros/latex/contrib/oberdiek
\else\ifx9#1
patch.doc: \else\isanumfalse
macros/generic/misc/patch.doc \fi\fi...\fi
(which technique is due to David Kastrup; 335 Defining macros within macros
the trick for avoiding the errors, noted in The way to think of this is that ## gets
an earlier version of this answer, was sug- replaced by # in just the same way that
gested by Andreas Matthias). In a later #1 gets replaced by ‘whatever is the first
thread on the same topic, Michael Downes argument’.
offered:
So if you define a macro:
\def\IsInteger#1{%
TT\fi \newcommand\a[1]{+#1+#1+#1+}
\begingroup \lccode‘\-=‘\0 \lccode‘+=‘\0
or (using the TeX primitive \def):
\lccode‘\1=‘\0 \lccode‘\2=‘\0 \lccode‘\3=‘\0
\lccode‘\4=‘\0 \lccode‘\5=‘\0 \lccode‘\6=‘\0
\def\a#1{+#1+#1+#1+}
\lccode‘\7=‘\0 \lccode‘\8=‘\0 \lccode‘\9=‘\0
\lowercase{\endgroup
and use it as \a{b}, the macro expan-
\expandafter\ifx\expandafter\delimiter
sion produces ‘+b+b+b+’, as most people
\romannumeral0\string#1}\delimiter
would expect.
}
However, if we now replace part of the
which relies on \romannumeral produc- macro:
ing an empty result if its argument is zero.
Sadly, this technique has the unfortunate \newcommand\a[1]{+#1+\newcommand\x[1]{xxx#1}}
property that it accepts simple expressions
such as ‘1+2-3’; this could be solved by an then \a{b} will give us the rather odd
initial \gobbleminus-like construction.
+b+\newcommand{x}[1]
All the complete functions above are
{xxxb}
designed to be used in TeX conditionals
written “naturally” — for example:
so that the new \x ignores its argument.
\if\IsInteger{<subject of test>}% If we use the TeX primitive:
<deal with integer>%
\else \def\a#1{+#1+\def\x #1{xxx#1}}
<deal with non-integer>%
\fi \a{b} will expand to ‘+b+\def\x b{xxxb}’.
This defines \x to be a macro delimited
The LaTeX memoir class has an internal by b, and taking no arguments, which is
command of its own, \checkifinteger surely not what was intended!
{num}, that sets the conditional command Actually, to define \x to take an argu-
\ifinteger according to whether the ar- ment, we need
gument was an integer.
Of course, all this kerfuffle would \newcommand\a[1]{+#1+\newcommand\x[1]{xxx##1}}
be (essentially) void if there was a sim-
ple means of “catching” TeX errors. or, using the TeX primitive definition:
Imagining an error-catching primitive
\ifnoerror, one might write: \def\a#1{+#1+\def\x ##1{xxx##1}}
357 How to print contents of (etc.) not work; thus the technique may not
variables? be relied upon.
It is often useful to print out the values The solution is to use the refcount
of variables in the log file or on the termi- package (incidentally, by the author of
nal. Three possible ways to print out the hyperref ). The package provides four com-
contents of \textheight variable are: mands, all similar to:
1. \showthe\textheight \usepackage{refcount}
2. \message{The text height is ...
\the\textheight} \label{bar}
3. \typeout{The text height is ...
\the\textheight} \setcounterref{foo}{bar}
These techniques use the TeX primitives (the other three are \addtocounterref,
\the (which provides the value of a vari- \setcounterpageref and \addtocounterpageref).
able), \showthe (print a variable to the ter- The package also provides a command
minal and the log, on a line of its own), and \getrefnumber{label-name} that may
\message, which interpolates something be used where a ‘number’ value is needed.
into the log. The command \typeout is For example:
LaTeX’s general message output mecha-
... \footnote{foo bar ...\label{foofoot}}
nism.
...
In each case, the variable’s value is
\footnotemark[\getrefnumber{foofoot}]
printed as a number of points.
To typeset the value of \textheight, which gives you a second footnote mark
just \the\textheight is enough, but a reference the the footnote. (There is
more flexible alternative is to use the also a command \getpagerefnumber, of
printlen package. Printlen allows you to course).
choose the units in which you print a vari- The commands could be used by one
able; this is useful, given that the most determined not to use changepage to de-
ordinary people don’t think in points (par- termine whether the current page is odd,
ticularly Knuth’s points, of which there are but it’s probably no more trouble to use the
72.27 to the inch). fully-developed tool in this case.
So, using printlen, we could say: refount.sty : Distributed as part of
\newlength{\foo} macros/latex/contrib/oberdiek
\setlength{\foo}{12pt}
R.3 LaTeX macro
\verb|\foo| is \printlength{\foo}
programming
and get:
359 How to change LaTeX’s “fixed
\foo is 12pt names”
LaTeX document classes define several ty-
while, if we say:
pographic operations that need ‘canned
\newlength{\foo} text’ (text not supplied by the user). In
\setlength{\foo}{12pt} the earliest days of LaTeX 2.09 these bits
\uselengthunit{mm} of text were built in to the body of La-
\verb|foo| is \printlength{\foo}TeX’s macros and were rather difficult to
201
change, but “fixed name” macros were in- \renewcommand{\contentsname}%
troduced for the benefit of those wishing to {Indholdsfortegnelse}
use LaTeX in languages other than English. in the preamble of her document.
For example, the special section produced However, it’s natural for a user of a
by the \tableofcontents command is non-English language to use babel, be-
always called \contentsname (or rather, cause it offers many conveniences and
what \contentsname is defined to mean). typesetting niceties for those preparing
Changing the canned text is now one of documents in those languages. In particu-
the easiest customisations a user can do to lar, when babel is selecting a new language,
LaTeX. it ensures that LaTeX’s symbolic names are
The canned text macros are all of the translated appropriately for the language
form \hthing iname, and changing them in question. Unfortunately, babel’s choice
is simplicity itself. Put: of names isn’t always to everyone’s choice,
\renewcommand{\hthing iname} and there is still a need for a mechanism to
{Res minor} replace the ‘standard’ names.
Whenever a new language is selected,
in the preamble of your document, and the babel resets all the names to the settings
job is done. (However, beware of the babel for that language. In particular, babel se-
package, which requires you to use a differ- lects the document’s main language when
ent mechanism: be sure to check changing \begin{document} is executed, which
babel names if you’re using it.) immediately destroys any changes to these
The names that are defined in the stan- symbolic names made in the prologue of a
dard LaTeX classes (and the makeidx pack- document that uses babel.
age) are listed below. Some of the names Therefore, babel defines a command to
are only defined in a subset of the classes enable users to change the definitions of
(and the letter class has a set of names all the symbolic names, on a per-language ba-
of its own); the list shows the specialisation sis: \addto\captionshlanguagei is the
of each name, where appropriate. thing (hlanguagei being the language op-
\abstractname Abstract tion you gave to babel in the first place).
\alsoname see also (makeidx package)
For example:
\appendixname Appendix
\addto\captionsdanish{%
\bibname Bibliography (report,book)
\renewcommand{\contentsname}%
\ccname cc (letter)
{Indholdsfortegnelse}%
\chaptername Chapter (report,book)
}
\contentsname Contents
\enclname encl (letter) 361 Running equation, figure and
\figurename Figure (for captions) table numbering
\headtoname To (letter) Many LaTeX classes (including the stan-
\indexname Index dard book class) number things per chap-
\listfigurename List of Figures ter; so figures in chapter 1 are numbered
\listtablename List of Tables 1.1, 1.2, and so on. Sometimes this is not
\pagename Page (letter) appropriate for the user’s needs.
\partname Part Short of rewriting the whole class, one
\refname References (article) may use the chngcntr package, which pro-
\seename see (makeidx package)vides commands \counterwithin (which
\tablename Table (for caption) establishes this nested numbering relation-
360 Changing the words babel uses ship) and \counterwithout (which un-
does it).
LaTeX uses symbolic names for many
So if you have figures numbered by
of the automatically-generated text it pro-
chapter as 1.1, 1.2, 2.1, . . . , the command
duces (special-purpose section headings,
captions, etc.). As noted in “LaTeX \counterwithout{figure}{chapter}
fixed names” (which includes a list of the
will convert them to figures 1, 2, 3, . . . .
names themselves), this enables the user
(Note that the command has also removed
to change the names used by the standard
the chapter number from the counter’s def-
classes, which is particularly useful if the
inition.)
document is being prepared in some lan-
More elaborate use could change
guage other than LaTeX’s default English.
things numbered per section to things num-
So, for example, a Danish author may wish
bered per chapter:
that her table of contents was called “Ind-
holdsfortegnelse”, and so would expect to \counterwithout{equation}{section}
place a command \counterwithin{equation}{chapter}
202
(assuming there was a class that did such a \stepcounter{foo} that does this spe-
thing in the first place...) cial case of increasing-by-one.
The chngcntr approach doesn’t involve
There’s an internal LaTeX variable, the
much programming, and the enthusias-
“current label”, that remembers the last ‘la-
tic LaTeX programmer might choose to
bellable’ thing that LaTeX has processed.
try the technique that we had to use be-
You could (if you were to insist) set that
fore the advent of chngcntr. Each of the
value by the relevant TeX command (hav-
packages removefr and remreset defines a
ing taken the necessary precautions to en-
\@removefromreset command, and hav-sure that the internal command worked) —
ing included the package one writes some-
but it’s not necessary. If, instead of ei-
thing like: ther of the stepping methods above, you
say \refstepcounter{foo}, the internal
\makeatletter variable is set to the new value, and (until
\@removefromreset{figure}{chapter}
something else comes along), \label will
\makeatother refer to the counter.
and the automatic renumbering stops. You 363 Finding if you’re on an odd or an
may then need to redefine the way in which even page
the figure number (in this case) is printed:
Another question discusses the issue of get-
\makeatletter ting \marginpar commands to put their
output in the correct margin of two-sided
\renewcommand{\thefigure}{\@arabic\c@figure}
\makeatother documents. This is an example of the gen-
eral problem of knowing where a particular
(remember to do the whole job, for every bit of text lies: the output routine is asyn-
counter you want to manipulate, within chronous, and (La)TeX will usually pro-
\makeatletter . . . \makeatother). cess quite a bit of the “next” page before
This technique, too, may be used to deciding to output any page. As a result,
change where in a multilevel structure a the page counter (known internally in La-
counter is reset. Suppose your class num- TeX as \c@page) is normally only reliable
bers figures as hchapteri.hsectioni.hfigurei, when you’re actually in the output routine.
and you want figures numbered per chap- The solution is to use some version of
ter, try: the \label mechanism to determine which
side of the page you’re on; the value of the
\makeatletter
page counter that appears in a \pageref
\@removefromreset{figure}{section}
command has been inserted in the course
\@addtoreset{figure}{chapter}
of the output routine, and is therefore safe.
\renewcommand{\thefigure}{\thechapter.\@arabic\c@figure}
\makeatother
However, \pageref itself isn’t reli-
able: one might hope that
(the command \@addtoreset is a part of
LaTeX itself). \ifthenelse{\isodd{\pageref{foo}}}{odd}{even}
3 The fonts acquired their label ‘Almost’ following the realisation that their first implementation in Meta-
font79 still wasn’t quite right; Knuth’s original intention had been that they were the final answer.
212
\begin{figure} This particular example could be coded
<the illustration itself> (without any problems) in verbatim, but
\label{myfig} the behaviour does confuse people.
\caption{My figure} The problem also appears in maths
\end{figure} mode, in arrays and so on. In this case,
large-scale bracketing of things is not
the label will report the number of the sec- a good idea; the TeX primitive \relax
tion (or whatever) in which the surround- (which does nothing except to block
ing text resides, or the like. searches of this nature) may be used. From
You can, with the same malign effect, another comp.text.tex example:
shield the \caption command from its as-
sociated \label command, by enclosing \begin{eqnarray}
the caption in an environment of its own. [a] &=& b \\
This effect will be seen with: \relax[a] &=& b
\end{eqnarray}
\begin{figure}
<the illustration itself> which is a usage this FAQ would not rec-
\caption{A Figure} ommend, anyway: refer to the reason not
\end{figure} to use eqnarray.
\label{myfig} Note that the amsmath package mod-
ifies the behaviour of \\ in maths. With
where the \label definitely is after the amsmath, the eqnarray example doesn’t
\caption, but because the figure envi-
need any special action (\relax or
ronment closed before the \label com- braces).
mand, the \caption is no longer “visible”.
In summary, the \label must be af- 384 Why doesn’t verbatim work
ter the command that defines it (e.g., within . . . ?
\caption), and if the \caption is inside The LaTeX verbatim commands work by
an environment, the \label must be in changing category codes. Knuth says of
there too. this sort of thing “Some care is needed
383 Start of line goes awry to get the timing right. . . ”, since once the
category code has been assigned to a char-
This answer concerns two sorts of prob- acter, it doesn’t change. So \verb and
lems: errors of the form \begin{verbatim} have to assume that
! Missing number, treated as zero. they are getting the first look at the param-
<to be read again> eter text; if they aren’t, TeX has already
p assigned category codes so that the verba-
<*> [perhaps] tim command doesn’t have a chance. For
example:
and errors where a single asterisk at the
start of a line mysteriously fails to appear \verb+\error+
in the typeset output. will work (typesetting ‘\error’), but if we
Both problems arise because \\ takes define no more than a no-op macro,
optional arguments. The command \\*
means “break the line here, and inhibit \newcommand{\unbrace}[1]{#1}
page break following the line break”; the
command \\[hdimeni] means “break the which simply regurgitates its argument,
line here and add hdimeni extra vertical and use it as:
space afterwards”. \unbrace{\verb+\error+}
The problem arises because \\ looks
for the next non-blank thing; the test it the combinartion will not (it will attempt to
uses ignores the end of the line in your in- execute \error). Other errors one may en-
put text, so that \\ comes to imagine that counter are ‘\verb ended by end of line’,
you were giving it a ‘modifier’. or even the rather more helpful ‘\verb ille-
An obvious solution is to enclose the gal in command argument’. The same sorts
stuff at the start of the new line in braces, of thing happen with \begin{verbatim}
typing: . . . \end{verbatim}:
{\ttfamily \ifthenelse{\boolean{foo}}{%
/* C-language comment\\ \begin{verbatim}
{[perhaps]} this could be done better\\
foobar
{*}/ \end{verbatim}
} }{%
213
\begin{verbatim} \NewDocumentCommand\cmd{ m v m }{#1 ‘#2’ #3}
barfoo \cmd{Command }|\furble|{ isn’t defined}
\end{verbatim}
} Which gives us:
provokes errors like ‘File ended while Command \furble isn’t defined
scanning use of \@xverbatim’, as \begin
{verbatim} fails to see its matching \end The “m” tag argument specifies a normal
{verbatim}. mandatory argument, and the “v” speci-
This is why the LaTeX book insists fies one of these verbatim arguments. As
that verbatim commands must not appear you see, it’s implanting a \verb-style com-
in the argument of any other command; mand argument in the argument sequence
of an otherwise “normal” sort of command;
they aren’t just fragile, they’re quite unus-
able in any “normal” command parameter, that ‘|’ may be any old character that
regardless of \protection. (The \verb doesn’t conflict with the content of the ar-
command tries hard to detect if you’re mis- gument.
using it; unfortunately, it can’t always do This is pretty neat (even if the verba-
so, and the error message is therefore not tim is in an argument of its own) but the
reliable as an indication of problems.) downside is that xparse pulls in the experi-
mental LaTeX3 programming environment
The first question to ask yourself is: “is
\verb actually necessary?”. (l3kernel) which is pretty big.
Other than the cprotect package, there
• If \texttt{your text} produces are four partial solutions to the problem:
the same result as \verb+your
text+, then there’s no need of \verb • Some packages have macros which
in the first place. are designed to be responsive to ver-
• If you’re using \verb to typeset a batim text in their arguments. For ex-
URL or email address or the like, then ample, the fancyvrb package defines
the \url command from the url will a command \VerbatimFootnotes,
help: it doesn’t suffer from all the which redefines the \footnotetext
problems of \verb, though it’s still command, and hence also the be-
not robust; “typesetting URLs” offers haviour of the \footnote) command,
advice here. in such a way that you can in-
• If you’re putting \verb into the argu- clude \verb commands in its ar-
ment of a boxing command (such as gument. This approach could in
\fbox), consider using the lrbox en- principle be extended to the argu-
vironment: ments of other commands, but it can
clash with other packages: for exam-
\newsavebox{\mybox}
ple, \VerbatimFootnotes interacts
...
poorly with the para option of the
\begin{lrbox}{\mybox}
footmisc package.
\verb!VerbatimStuff!
The memoir class defines its
\end{lrbox}
\footnote command so that it will
\fbox{\usebox{\mybox}}
accept verbatim in its arguments, with-
If you can’t avoid verbatim, the out any supporting package.
\cprotect command (from the package
• The fancyvrb package defines a com-
cprotect) might help. The package man- mand \SaveVerb, with a correspond-
ages to make a macro read a verbatim ar- ing \UseVerb command, that allow
gument in a “sanitised” way by the sim- you to save and then to reuse the con-
ple medium of prefixing the macro with tent of its argument; for details of this
\cprotect:
extremely powerful facility, see the
package documentation.
\cprotect\section{Using \verb|verbatim|} Rather simpler is the verbdef pack-
age, whose \verbdef command de-
The package does work in this simple case, fines a (robust) command which ex-
and deserves consideration in many others pands to the verbatim argument given;
cases; the package documentation gives the newverbs package provides a simi-
more details. lar function as well as several related
Another way out is to use ones.
one of “argument types” of the • In a similar vein, the verbatimbox
\NewDocumentCommand command in the package makes it possible to put ver-
experimental LaTeX3 package xparse: batim material in a box:
214
\begin{verbbox} doesn’t provide an anonynous file.
some exotic _&$ stuff Macros, to achieve the same effect, are
\end{verbbox} outlined in the documentation of the
\theverbbox verbatim package; the macros use the
the operation typesets exotic stuff into facilities of the package, but the user
an anonymous box, and its contents has to write a mini-package actually
may be retrieved using the command to use them.
\theverbbox. It is clear that it’s in cprotect.sty :
the same mould as the \verbdef com- macros/latex/contrib/cprotect
mand mentioned above; the package
defines other similar commands. fancyvrb.sty :
• The tcolorbox package provides a sim- macros/latex/contrib/fancyvrb
ilar facility l3kernel bundle:
• If you have a single character that macros/latex/contrib/l3kernel
is giving trouble (in its absence you memoir.cls:
could simply use \texttt), con- macros/latex/contrib/memoir
sider using \string. \texttt
{my\string_name} typesets the same newverbs.sty :
as \verb+my_name+, and will work in macros/latex/contrib/newverbs
the argument of a command. It won’t, tcolorbox.sty : macros/latex/
however, work in a moving argument, contrib/tcolorbox
and no amount of \protection will url.sty : macros/latex/contrib/url
make it work in such a case.
A robust alternative is: verbatim.sty :
macros/latex/required/tools
\chardef\us=‘\_
... verbatimbox.sty : macros/latex/
\section{... \texttt{my\us name}}contrib/verbatimbox
Such a definition is ‘naturally’ robust; verbdef.sty :
macros/latex/contrib/verbdef
the construction “hback-ticki\hchar i”
may be used for any troublesome char- xparse.sty : Distributed as part
acter (though it’s plainly not neces- of macros/latex/contrib/
sary for things like percent signs for l3packages
which (La)TeX already provides ro-
385 “No line here to end”
bust macros).
• One may also consider putting verba- The error
tim material in an external file; this is
! LaTeX Error: There’s no line here to end.
somewhat more tedious, but the file
may be reused several times within a
See the LaTeX manual or LaTeX Companion for explanation
single document. The tcolorbox per-
mits this: appears when you give LaTeX a \\ com-
\begin{tcbverbatimwrite}{<file mand at a time when it’s not expecting it;
name>}
... it is a line-breaking command, and is con-
\end{tcbverbatimwrite} fused if LaTeX isn’t building a paragraph
when you give the command. A common
which (as one might guess) writes to case is where you’ve decided you want the
the named file; load the saved contents label of a list item to be on a line of its own,
using \input{<file name>} and written (for example):
A second environment puts your ver-
batim material in an (apparently) \begin{description}
anonymous temporary file: \item[Very long label] \\
\begin{tcbwritetemp}{<file name>} Text...
... \end{description}
\end{tcbverbatimwrite}
The proper solution to the problem is to
In this case, you use the anonymous write a new sort of description environ-
file with the \tcbusetemp macro. ment, that does just what you’re after. (The
(You can change the name used for the LaTeX Companion — see LaTeX Compan-
‘anonymous’ file, if its default proves ion — offers a rather wide selection of
troublesome.) variants of these things.)
The moreverb package provides a A straightforward solution, which
\verbatimwrite command, which avoids the warning, is to write:
215
\begin{description} material around them. Meanwhile, there
are parameters
\item[Very long label] \leavevmode \\ provided to adjust the spac-
Text... ing between floating environments and
\end{description} their surroundings; so if we have:
which starts a paragraph before forcing a \begin{figure}
break. The expdlist package provides the \begin{center}
same functionality with its \breaklabel \includegraphics{...}
command, and mdwlist provides it via its \caption{...}
\desclabelstyle command. \end{center}
The other common occasion for the \end{figure}
message is when you’re using the center
(or flushleft or flushright) environ- or worse still:
ment, and have decided you need extra \begin{figure}
separation between lines in the environ- \begin{center}
ment: \includegraphics{...}
\end{center}
\begin{center}
\caption{...}
First (heading) line\\
\end{figure}
\\
body of the centred text... unwarranted vertical space is going to ap-
\end{center} pear.
The solution here is plain: use the \\ The solution is to let the float and the
command in the way it’s supposed to be objects in it position themselves, and to
used, to provide more than just a single use “generic” layout commands rather than
line break space. \\ takes an optional ar- their list-based encapsulations.
gument, which specifies how much extra \begin{figure}
space to add; the required effect in the text
\centering
above can be had by saying: \includegraphics{...}
\caption{...}
\begin{center}
\end{figure}
First (heading) line\\[\baselineskip]
body of the centred text... (which even involves less typing).
\end{center} This alternative code will work with
You can use \leavevmode, as above: any LaTeX package. It will not work
with obsolete (pre-LaTeX2e) packages
\begin{center} such as psfig or epsf — see graphics in-
First (heading) line\\ clusion for discussion of the genesis of
\leavevmode\\ \includegraphics.
body of the centred text...
387 Why is my table/figure/. . . not
\end{center}
centred?
but that is just as tiresome to type as \\ You want a float whose contents are cen-
with an optional argument, and can not be tred, but LaTeX ignores your center envi-
recommended. ronment. Most likely, you have written:
expdlist.sty :
\begin{center}
macros/latex/contrib/expdlist
\begin{figure}
mdwlist.sty : Distributed as part of ...
macros/latex/contrib/mdwtools \end{figure}
386 Extra vertical space in floats \end{center}
A common complaint is that extra verti- In this case, LaTeX has “taken the figure
cal space has crept into figure or table away”, and will typeset it at some location
floating environments. More common still it fancies (it does the same with tables)
are users who post code that introduces the only thing we can say (for sure) about
this extra space, and haven’t noticed the the location is that it won’t be inside that
problem! center environment. As a result, the
The trouble arises from the fact that center environment is left with nothing
the center environment (and its siblings to do . . . except to make a mess of your
flushleft and flushright) are actually vertical spacing.
based on LaTeX’s list-handling code; and The solution is the same as that out-
lists always separate themselves from the lined in the same answer, noting that all
216
control of an figure or table needs to be type accented characters you need to use
inside the environment. So the example’s the \a kludge: so \a’{e} inside tabbing
code should be converted to for \’{e} outside, and similarly \a‘ for \‘
and \a= for \=. This whole procedure is
\begin{figure}
of course hideous and error-prone.
\centering
The simplest alternative is to type in an
...
encoding that has the diacriticised charac-
\end{figure}
ters in it, and to use an appropriate encod-
(or something similar for a table). ing definition file in the inputenc package.
So for example, type:
388 Two-column float numbers out of
order \usepackage[latin1]
{inputenc}
When LaTeX can’t place a float immedi-
...
ately, it places it on one of several “de-
\begin{tabbing}
fer” lists. If another float of the same type
...
comes along, and the “defer” list for that
... \> voilà \> ...
type still has something in it, the later float
has to wait for everything earlier in the list. for:
Now, standard LaTeX has differ-
... voilà ...
ent lists for single-column floats, and
double-column floats; this means that and the internal mechanisms of the
single-column figures can overtake double- inputenc package will put the right version
column figures (or vice-versa), and you ob- of the accent command in there.
serve later figures appear in the document A witty reversal of the rôles is intro-
before early ones. The same is true, of duced by the package Tabbing (note the
course, for tables, or for any user-defined capital “T”): it provides a Tabbing envi-
float. ronment which duplicates tabbing, but
The LaTeX team recognise the prob- all the single-character commands become
lem, and provides a package (fixltx2e) to complicated objects. So tabbing’s \> be-
deal with it. Fixltx2e amalgamates the two comes \TAB>, \= becomes \TAB=, and so
defer lists, so that floats don’t get out of on. The above trivial example would there-
order. fore become:
For those who are still running an older
\usepackage{Tabbing}
LaTeX distribution, the package fix2col
...
should serve. This package (also by a mem-
\begin{Tabbing}
ber of the LaTeX team) was the basis of the
... ... \TAB> voil\‘a \TAB> ...
relevant part of fixltx2e. The functionality
has also been included in dblfloatfix, which Tabbing.sty :
also has code to place full-width floats at macros/latex/contrib/Tabbing
[b] placement.
390 Package reports “command
Once you have loaded the package, no
already defined”
more remains to be done: the whole re-
quirement is to patch the output routine; You load a pair of packages, and the second
no extra commands are needed. reports that one of the commands it defines
is already present. For example, both the
dblfloatfix.sty : macros/latex/
txfonts and amsmath define a command
contrib/dblfloatfix
\iint (and \iiint and so on); so
fix2col.sty :
...
macros/latex/contrib/fix2col
\usepackage{txfonts}
fixltx2e.sty : Part of the LaTeX \usepackage{amsmath}
distribution
produces a string of error messages of the
389 Accents misbehave in tabbing form:
So you are constructing a tabbing envi-
! LaTeX Error: Command \iint already defined.
ronment, and you have the need of some
Or name \end... illegal, see p.192 of th
diacriticised text — perhaps something as
simple as \’{e} — and the accent disap- As a general rule, things that amsmath de-
pears because it has been interpreted as a fines, it defines well; however, there is a
tabbing command, and everything goes good case for using the txfonts version of
wrong. \iint — the associated tx fonts have a
This is really a rather ghastly feature double integral symbol that doesn’t need
of the tabbing environment; in order to to be “faked” in the way amsmath does. In
217
the case that you are loading several sym- 392 Link text doesn’t break at end
bol packages, every one of which defines line
the same symbol, you are likely to experi-
When using the hyperref package, you
ence the problem in a big way (\euro is a
make a block of text “active” when you
common victim).
define a hyper-link (when the user clicks
There are similar cases where one pack- on that text, the reader program will divert
age redefines another’s command, but no to the target of the link).
error occurs because the redefining pack-
The hyperref package uses a driver
age doesn’t use \newcommand. Often, in
(in the same way as the graphics package
such a case, you only notice the change be-
does), to determine how to implement all
cause you assume the definition given by
that hyper-stuff.
the first package. The amsmath–txfonts
If you use the driver for dvips out-
packages are just such a pair; txfonts
put (presumably you want to distill the re-
doesn’t provoke errors.
sulting PostScript), limitations in the way
You may deal with the problem by sav-
dvips deals with the \special commands
ing and restoring the command. Macro
mean that hyperref must prevent link an-
programmers may care to do this for them-
chors from breaking at the end of lines.
selves; for the rest of us, there’s the pack-
Other drivers (notably those for PDFTeX
age savesym. The sequence:
and for dvipdfm) don’t suffer from this
\usepackage{savesym} problem.
\usepackage{amsmath} The problem may occur in a number
\savesymbol{iint} of different circumstances. For a couple of
\usepackage{txfonts} them, there are work-arounds:
\restoresymbol{TXF}{iint} First, if you have an URL which is ac-
tive (so that clicking on it will activate your
does the job; restoring the amsmath ver- web browser to “go to” the URL). In this
sion of the command, and making the case hyperref employs the url package to
txfonts version of the command available split up the URL (as described in type-
as \TXFiint. setting URLs), but the dvips driver then
Documentation of savesym doesn’t suppresses the breaks. The way out is
amount to much: the only commands are the breakurl package, which modifies the
\savesymbol and \restoresymbol, as \url command to produce several smaller
noted above. pieces, between each of which a line break
amsmath.sty : Part of macros/latex/ is permitted. Each group of pieces, that
required/amslatex ends up together in one line, is converted
to a single clickable link.
savesym.sty : macros/latex/
contrib/savesym/savesym.sty
Second, if you have a table of contents,
list of figure or tables, or the like, hyperref
txfonts.sty : Part of fonts/txfonts will ordinarily make the titles in the ta-
391 Why are my sections numbered ble of contents, or captions in the lists, ac-
0.1 . . . ? tive. If the title or caption is long, it will
need to break within the table, but the dvips
This happens when your document is us- driver will prevent that. In this case, load
ing the standard book or report class (or hyperref with the option linktocpage,
one similar), and you’ve got a \section and only the page number will be made
before your first \chapter. active.
What happens is, that the class num- Otherwise, if you have a lengthy piece
bers sections as “hchapter noi.hsection of text that you want active, you have at
noi”, and until the first \chapter has present no simple solution: you have to
appeared, the chapter number is 0. (If rewrite your text, or to use a different PDF
you use\chapter*, which doesn’t num- generation mechanism.
ber the chapter it produces, the problem
still arises.) breakurl.sty :
If you’re doing this, it’s possible that macros/latex/contrib/breakurl
the article class is for you; try it and see.
393 Page number is wrong at start of
Otherwise, put a \chapter before your
page
sections, or do away with section num-
bering by using \section* instead. An This is a long story, whose sources are deep
alternative way of avoiding numbering is inside the workings of TeX itself; it all de-
discussed in “unnumbered sections in the rives from the TeX’s striving to generate
table of contents”. the best possible output.
218
The page number is conventionally Fortunately, TeX’s scanning mecha-
stored in \count0; LaTeX users see this nisms helps us by accepting the syntax
as the counter page, and may typeset its “{]}” to ‘hide’ the closing bracket from
value using \thepage. the scanning mechanism that LaTeX uses.
The number (that is to say, \count0) In practice, the commonest way to use this
is only updated when TeX actually outputs facility is:
a page. TeX only even tries to do this when
it detects a hint that it may be a good thing \section[All {[OK]} now]{All \emph{OK} now.}
to do. From TeX’s point of view, the end
since bracing the bracket on its own “looks
of a paragraph is a good time to consider
odd”.
outputting a page; it will output a page if it
LaTeX has another argument syntax,
has more than a page’s worth of material to
even less regular, where the argument is
output. (Ensuring it always has something
enclosed in parentheses, as in:
in hand makes some optimisations possi-
ble.) As a result, \count0 (\thepage) is \put(1,2){foo}
almost always wrong in the first paragraph
of a page (the exception is where the page (a picture environment command).
number has been “forcibly” changed, ei- This mechanism is also prone to prob-
ther by changing its value directly, or by lems with matching closing parentheses,
breaking the page where TeX wouldn’t nec- but the issue seldom arises since such ar-
essarily have chosen to break). guments rarely contain text. If it were to
LaTeX provides a safe way of referring arise, the same solution (enclosing the con-
to the page number, by using label refer- fused characters in braces) would solve the
ences. So, rather than writing: problem.
Here is page \thepage{}. 395 Characters disappear from
figures in PDFTeX
you should write:
You have a PDF figure, which you want to
Here is page \pageref{here}\label{here}.
use in your PDFLaTeX document. When
(note: no space between the \pageref and you compile the document, PDFTeX com-
the \label, since that could potentially plains about “missing glyphs”, and some
end up as a page-break space itself, which (or all) of the labelling text or symbols in
rather defeats the purpose of the exercise!). the original figure is no longer visible.
What has happened is:
394 My brackets don’t match
(La)TeX has a low-level mechanism for 1. Your figure file (say fig.pdf) has a
matching braces in document text. This font font.pfb embedded in it.
means you can type something like: 2. PDFTeX notes that it has font.pfb
on disc, and loads that in place of the
\section{All \emph{OK} now.} copy in fig.pdf.
3. It turns out that the copy in fig.pdf
and know that the first brace (for the argu-
has glyphs that aren’t in font.pfb on
ment of \section) will be matched with
disc, so that you get errors while com-
the last brace, and the internal pair of
piling and you see that characters are
braces (for the argument of \emph) will
missing when you view the output.
be matched with each other. It’s all very
(PDFTeX can’t know that the fonts
simple.
are different, since they have the same
However, LaTeX has a convention of
name.)
enclosing optional arguments in brackets,
as in: Which is all very undesirable.
\section[OK]{All \emph{OK} now.} PDFTeX does this to keep file sizes
down: suppose you have a document that
These brackets are not matched by loads figures fig1.pdf and fig2.pdf;
TeX mechanisms, despite the superficial both of those use font font.pfb. If PDF-
similarity of their use. As a result, TeX takes no action, there will be two
straightforward-looking usages like: copies of font.pfb in the output. (If your
document also uses the font, there could
\section[All [OK] now]{All \emph{OK} now.}
be three copies.)
aren’t OK at all — the optional argu- A real case is the URW font
ment comes to consist of “All [OK”, and NimbusRomNo9L-Regu (a clone of Times
\section takes the single character “n” Roman), which is available in a version
(of the first “now”) as its argument. with Cyrillic letters, while the version in
219
TeX distributions doesn’t have those let- each included file, and makes a ‘check-
ters. Both versions, as distributed, have the point’ of important parameters (such as
same name. page, figure, table and footnote numbers).
The simple (“quick and dirty”) solution As a direct result, it must clear the current
is to add the command page both before and after the \include
command. (The requirement derives from
\pdfinclusioncopyfonts=1
the difficulties of observing page numbers.)
to the preamble of your document. What’s more, this mechanism doesn’t work
The “real” solution is that one or other if a \include command appears in a file
font should be renamed. In either case, this that was \included itself: LaTeX diag-
would require that you reconfigure some noses this as an error.
program’s (TeX’s or your drawing pack- So, we can now answer the two com-
age’s) font tables — inevitably a tiresome monest questions about \include:
job.
• Why does LaTeX throw a page before
396 I asked for “empty”, but the page and after \include commands?
is numbered Answer: because it has to. If you don’t
If you use \pagestyle{empty} and you like it, replace the \include com-
find some pages are numbered anyway, mand with \input — you won’t be
you are probably encountering one of the able to use \includeonly any more,
style decisions built into the standard La- but you probably don’t need it anyway,
TeX classes: that certain special pages so don’t worry.
should always appear with \pagestyle • Why can’t I nest \included files? —
{plain}, with a page number at the cen- I always used to be able to under La-
tre of the page foot. The special pages in TeX 2.09.
question are those (in article class) contain- Answer: in fact, you couldn’t, even un-
ing a \maketitle, or (in book and report der LaTeX 2.09, but the failure wasn’t
classes) \chapter or \part commands. diagnosed. However, since you were
The simple solution is to reissue the happy with the behaviour under La-
page style after the command, with ef- TeX 2.09, replace the \include com-
fect for a single page, as, for example (in mands with \input commands (with
article): \clearpage as appropriate).
The matter is discussed in more detail in {\bf Fred} was {\it here\/}.
a PracTeX journal paper by Lars Madsen; with the font change enclosed in a group,
Stefan Kottwitz offers a TeX blog entry so as to limit its effect; note the italic cor-
which includes screen shots of the output, rection command \/ that was necessary at
convincingly demonstrating the problem. the end of a section in italics.
AMSLaTeX : macros/latex/required/ At the release of LaTeX2e in summer
amslatex 1994, these simple commands were dep-
recated, but recognising that their use is
414 Why use \[ . . . \] in place of deeply embedded in the brains of LaTeX
$$ . . . $$? users, the commands themselves remain in
LaTeX defines inline- and display-maths LaTeX, with their LaTeX 2.09 semantics.
commands, apparently duplicating the TeX Those semantics were part of the reason
primitive maths sequences which surround they were deprecated: each \xx overrides
maths commands with single (or pairs of) any other font settings, keeping only the
dollar signs. size. So, for example,
In fact, LaTeX’s inline maths group- {\bf\it Here we are again\/}
ing, \( ... \), has (almost) exactly the
ignores \bf and produces text in italic,
same effect as the TeX primitive version
medium weight (and the italic correction
$... $. (The exception: the LaTeX ver-
has a real effect), whereas
sion checks to ensure you don’t put \( and
\) the wrong way round; this does occa- {\it\bf happy as can be\/}
sionally detect errors. . . .) ignores \it and produces upright text at
Since this is the case, one often finds bold weight (and the italic correction has
LaTeX users, who have some experience nothing to do). The same holds if you mix
of using Plain TeX, merely assuming that LaTeX2e font selections with the old style
LaTeX’s display maths grouping \[ ... commands:
\] may be replaced by the TeX primitive
display maths $$... $$. \textbf{\tt all good friends}
Unfortunately, the assumption is ignores the \textbf that encloses the text,
wrong: some LaTeX code needs to patch and produces typewriter text at medium
display maths, it can only do so by patch- weight.
ing \[ and \] (or their equivalents). Most So why are these commands depre-
obviously, the class option fleqn simply cated? — it is because of confusions such
does not work for equations coded us- as that in the last example. The alternative
ing $$... $$, whether you’re using the (LaTeX2e) commands are discussed in the
standard classes alone, or using package rest of this answer.
amsmath. Also, the \[ and \] construct LaTeX2e’s font commands come in
has code for rationalising vertical spacing two forms: modal commands and text-
in some extreme cases; that code is not block commands. The default set of modal
provided $$... $$, so if you use the commands offers weights \mdseries and
Plain TeX version, you may occasionally \bfseries, shapes \upshape, \itshape,
observe inconsistent vertical spacing. Sim- \scshape and \slshape, and families
ilar behaviour can bite if you are writing a \rmfamily, \sffamily and \ttfamily.
228
A font selection requires a family, a shape 416 What’s wrong with \newfont?
and a series (as well as a size, of course). If all else fails, you can specify a font us-
A few examples ing the LaTeX \newfont command. The
{\bfseries\ttfamily and jolly good font company!}
so specified doesn’t fit into the La-
TeX font selection mechanism, but the
produces bold typewriter text (but note the
technique can be tempting under several
lack of a bold typewriter font in the default
circumstances. The command is merely
Computer Modern fonts), or
the thinnest of wrappers around the \font
{\slshape\sffamily Never mind the primitive, and doesn’t really fit with LaTeX
weather\/}
at all. A simple, but really rather funny, ex-
(note the italic correction needed on
ample of the problems it poses, may be
slanted fonts, too).
seen in:
LaTeX2e’s text block commands take
the first two letters of the modal com- \documentclass[10pt]{article}
mands, and form a \textxx com- \begin{document}
mand from them. Thus \bfseries be- \newfont{\myfont}{cmr17 scaled 2000}
comes \textbf{text}, \itshape be- \myfont
comes \textit{text}, and \ttfamily \LaTeX
becomes \texttt{text}. Block com- \end{document}
mands may be nested, as:
(the reader is encouraged to try this). The
\textit{\textbf{Never mind the rain}}
“A” of \LaTeX pretty much disappears: La-
to produce bold italic text (note that the TeX chooses the size on the “A” according
block commands supply italic corrections to its idea of the font size (10pt), but po-
where necessary), and they be nested with sitions it according to the dimensions of
the LaTeX2e modal commands, too: “\myfont”, which is more than three times
\texttt{\bfseries So long as we’re that size.
together}
Another “\myfont” example arises
for bold typewriter, or from an entirely different source. The mini-
{\slshape \textbf{Whoops! she goes document:
again}\/}
\documentclass[...]{bar}
produces no error and does nothing for the
\usepackage[draft]{graphics}
second load.
you would write: However
\PassOptionsToPackage
\usepackage[a]{foo}
{draft}{graphics}
...
\documentclass[...]{bar}
\usepackage[b]{foo}
with \PassOptionsToPackage before the
\documentclass command. produces the error; even if option ‘b’ is an
However, if the foo package or the bar alias for option ‘a’ — LaTeX doesn’t “look
class loads graphics with an option of its inside” the package to check anything like
own that clashes with what you need in that.
some way, you’re stymied. For example: The general rule is: the first load of a
package defines a set of options; if a fur-
\PassOptionsToPackage ther \usepackage or \RequirePackage
{draft}{graphics} also calls for the package, the options on
that call may not extend the set on the first
where the package or class does:
load.
\usepackage[final]{graphics} Fortunately, the error (in that sort of
case) is easily curable once you’ve exam-
sets final after it’s dealt with option you ined the preamble of your document.
passed to it, so your draft will get forgot-
Now, suppose package foo loads bar
ten. In extreme cases, the package might
with option b, and your document says:
generate an error here (graphics doesn’t
go in for that kind of thing, and there’s no
indication that draft has been forgotten). \usepackage{foo}
In such a case, you have to modify the ...
package or class itself (subject to the terms \usepackage[a]{bar}
of its licence). It may prove useful to con-
tact the author: she may have a useful al- or
ternative to suggest.
\usepackage[a]{bar}
425 Option clash for package
...
The error message \usepackage{foo}
will resolve the error, and will behave as ! LaTeX Error: Missing \begin{document}.
you might hope. ...
If you’re using the simpler graphics l.1 <?>
package, use the * form of the <?><?>\documentclass{article}
\resizebox command to specify the use
of totalheight:
(Those <?>s are your operating system’s
\resizebox*{!}{5cm}{% representation of an unknown character;
\rotatebox{180}{% on the author’s system it’s a reverse video
\includegraphics{myfig.eps}%
‘?’ sign.)
}% You can spot the BOM by examining
} the bytes; for example, the Unix hexdump
graphics.sty,graphicx.sty : application can help:
Both parts of the macros/latex/
required/graphics bundle $ hexdump -C <file>
00000000 ef bb bf 5c 64 6f 63 75 ...
443 Missing \begin{document}
The preamble of your document is the
stuff before \begin{document}; you put The 5c 64 6f 63 75 are the “\docu” at
\usepackage commands and your own
the start of (the ‘real’ part of) your doc-
macro definitions in there. LaTeX doesn’t ument; the three bytes before it form the
like typesetting anything in the preamble, BOM.
so if you have: How to stop your editor from doing
this to you depends, of course, on the
• typed the odd grumble, editor you use; if you are using GNU
• created a box with \newsavebox and Emacs, you have to change the encoding
put something in it using \sbox (or from utf-8-with-signature to ‘plain’
the like), utf-8; instructions for that are found on
• forgotten to put \begin{document} the “stack overflow” site
into the document, at all, or even
(So far, all instances of this problem
• gave it the wrong file
that the author has seen have afflicted GNU
the error is inevitable and the solution is Emacs users.)
simple — judicious use of comment mark- Fortunately XeTeX and LuaTeX know
ers (‘%’) at the beginning of a line, moving about BOMs and what to do with them, so
things around, providing something that LaTeX using them is “safe”.
was missing . . . or switching to the correct
file.
The error may also occur while read- 444 \normalsize not defined
ing the .aux file from an earlier processing
The LaTeX error:
run on the document; if so, delete the .aux
file and start again from scratch. If the er-
ror recurs, it could well be due to a buggy The font size command \normalsize is not defined:
class or package. there is probably something wrong with the class file.
However, it may be that none of the
above solves the problem. reports something pretty fundamental (doc-
If so, remember that things that appear ument base font size has not been set,
before \documentclass are also problem- something the document class does for
atical: they are inevitably before \begin you). It can, in principle, be a problem
{document}! with the document class, but is more of-
Unfortunately, modern editors are ca- ten caused by the user forgetting to start
pable of putting things there, and prevent- their document with a \documentclass
ing you from seeing them. This can happen command.
242
445 Too many math alphabets \begin{figure}
TeX mathematics is one of its most impres- \includegraphics{foo}
sive features, yet the internal structure of \end{figure}
the mechanism that produces it is painfully \hline
complicated and (in some senses) patheti- \end{tabular}
cally limited. One area of limitation is that a construction that was supposed to put
one is only allowed 16 ”maths alphabets” a frame around the diagram, but doesn’t
LaTeX offers the user quite a lot of work, any more than:
flexibility with allocating maths alphabets,
\framebox{\begin{figure}
but few people use the flexibility directly.
\includegraphics{foo}
Nevertheless, there are many packages that
\end{figure}%
provide symbols, or that manipulate them,
}
which allocate themselves one or more
maths alphabet. The problem is, that the tabular environ-
If you can’t afford to drop any of these ment, and the \framebox command re-
packages, you might be able to consider strain the figure environment from its
switching to use of XeTeX or LuaTeX, natural métier, which is to float around the
which both have 65536 alphabet slots avail- document.
able. (Such a change is best not done The solution is simply not to use the
when under pressure to complete a doc- figure environment here:
ument; other issues, such as font availabil-
\begin{tabular}{|l|}
ity) could make a change impractical.)
\hline
Even if switching is not possible,
\includegraphics{foo}
there’s still hope if you’re using the bm
\hline
package to support bold maths: bm is capa-
\end{tabular}
ble of gobbling alphabets as if there is no
tomorrow. The package defines two lim- What was the float for? — as written in
iter commands: \bmmax (for bold symbols; the first two examples, it serves no useful
default 4) and \hmmax (for heavy symbols, purpose; but perhaps you actually wanted a
if you have them; default 3), which control diagram and its caption framed, in a float.
the number of alphabets to be used. It’s simple to achieve this — just re-
Any reduction of the \xxmax variables verse the order of the environments (or
will slow bm down — but that’s surely bet- of the figure environment and the com-
ter than the document not running at all. So mand):
unless you’re using maths fonts (such as \begin{figure}
Mathtime Plus) that feature a heavy sym- \begin{tabular}{|l|}
bol weight, suppress all use of heavy fami- \hline
lies by \includegraphics{foo}
\newcommand{\hmmax}{0} \caption{A foo}
\hline
(before loading bm), and then steadily re- \end{tabular}
duce the bold families, starting with \end{figure}
254