Newfaq
Newfaq
October 5, 2006
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
A Introduction 9
B The Background 10
1 What is TeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 How should I pronounce “TeX”? . . . . . . . . . . . . . . . . . . . 10
3 What is MetaFont? . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4 What is MetaPost? . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5 How can I be sure it’s really TeX? . . . . . . . . . . . . . . . . . . . 11
6 Are TeX and friends Y2K compliant? . . . . . . . . . . . . . . . . . 11
7 What is e-TeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
8 What is PDFTeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
9 What is LaTeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
10 What is LaTeX 2ε ? . . . . . . . . . . . . . . . . . . . . . . . . . . 12
11 How should I pronounce “LaTeX(2e)”? . . . . . . . . . . . . . . . . 13
12 Should I use Plain TeX or LaTeX? . . . . . . . . . . . . . . . . . . 13
13 How does LaTeX relate to Plain TeX? . . . . . . . . . . . . . . . . 13
14 What is ConTeXt? . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
15 What are the AMS packages (AMSTeX, etc.)? . . . . . . . . . . . . 14
16 What is Eplain? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
17 What is Lollipop? . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
18 What is Texinfo? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
19 If TeX is so good, how come it’s free? . . . . . . . . . . . . . . . . 15
20 What is the future of TeX? . . . . . . . . . . . . . . . . . . . . . . . 15
21 Reading (La)TeX files . . . . . . . . . . . . . . . . . . . . . . . . . 15
22 Why is TeX not a WYSIWYG system? . . . . . . . . . . . . . . . . . 16
23 TeX User Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
C Documentation and Help 17
24 Books on TeX and its relations . . . . . . . . . . . . . . . . . . . . 17
25 Books on Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
26 Where to find FAQs . . . . . . . . . . . . . . . . . . . . . . . . . . 20
27 How to get help . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
28 Specialist mailing lists . . . . . . . . . . . . . . . . . . . . . . . . . 21
29 How to ask a question . . . . . . . . . . . . . . . . . . . . . . . . . 21
30 How to make a “minimum example” . . . . . . . . . . . . . . . . . 22
31 (La)TeX Tutorials, etc. . . . . . . . . . . . . . . . . . . . . . . . . . 23
32 Online introductions: Plain TeX . . . . . . . . . . . . . . . . . . . . 23
33 Online introductions: LaTeX . . . . . . . . . . . . . . . . . . . . . 23
34 Specialised (La)TeX tutorials . . . . . . . . . . . . . . . . . . . . . 23
35 Reference documents . . . . . . . . . . . . . . . . . . . . . . . . . 24
1
36 WIKI pages for TeX and friends . . . . . . . . . . . . . . . . . . . 24
37 Typography tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . 25
38 Directories of (La)TeX information . . . . . . . . . . . . . . . . . . 25
39 Freely available (La)TeX books . . . . . . . . . . . . . . . . . . . . 25
40 Documentation of packages . . . . . . . . . . . . . . . . . . . . . . 25
41 Learning to write LaTeX classes and packages . . . . . . . . . . . . 26
42 MetaFont and MetaPost Tutorials . . . . . . . . . . . . . . . . . . . 26
43 BibTeX Documentation . . . . . . . . . . . . . . . . . . . . . . . . 27
44 Where can I find the symbol for . . . . . . . . . . . . . . . . . . . . . 27
45 The PiCTeX manual . . . . . . . . . . . . . . . . . . . . . . . . . . 28
D Bits and pieces of (La)TeX 28
46 What is a DVI file? . . . . . . . . . . . . . . . . . . . . . . . . . . 28
47 What is a driver? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
48 What are PK files? . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
49 What are TFM files? . . . . . . . . . . . . . . . . . . . . . . . . . . 28
50 Virtual fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
51 \special commands . . . . . . . . . . . . . . . . . . . . . . . . . 29
52 How does hyphenation work in TeX? . . . . . . . . . . . . . . . . . 29
53 What are LaTeX classes and packages? . . . . . . . . . . . . . . . . 30
54 Documented LaTeX sources (.dtx files) . . . . . . . . . . . . . . . 30
55 What are encodings? . . . . . . . . . . . . . . . . . . . . . . . . . . 31
56 What are the EC fonts? . . . . . . . . . . . . . . . . . . . . . . . . 32
57 What is the TDS? . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
58 What is “Encapsulated PostScript” (“EPS”) . . . . . . . . . . . . . . 33
59 Adobe font formats . . . . . . . . . . . . . . . . . . . . . . . . . . 33
60 What are “resolutions” . . . . . . . . . . . . . . . . . . . . . . . . . 34
61 What is the “Berry naming scheme” . . . . . . . . . . . . . . . . . 34
E Acquiring the Software 35
62 Repositories of TeX material . . . . . . . . . . . . . . . . . . . . . 35
63 What’s the CTAN nonfree tree? . . . . . . . . . . . . . . . . . . . 35
64 Contributing a file to the archives . . . . . . . . . . . . . . . . . . . 35
65 Finding (La)TeX files . . . . . . . . . . . . . . . . . . . . . . . . . 36
66 Finding new fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
67 The TeX Live distribution . . . . . . . . . . . . . . . . . . . . . . . 37
F TeX Systems 37
68 (La)TeX for different machines . . . . . . . . . . . . . . . . . . . . 37
69 TeX-friendly editors and shells . . . . . . . . . . . . . . . . . . . . 39
70 Commercial TeX implementations . . . . . . . . . . . . . . . . . . 40
G DVI Drivers and Previewers 42
71 DVI to PostScript conversion programs . . . . . . . . . . . . . . . . 42
72 DVI drivers for HP LaserJet . . . . . . . . . . . . . . . . . . . . . . 42
73 Output to “other” printers . . . . . . . . . . . . . . . . . . . . . . . 42
74 DVI previewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
75 Generating bitmaps from DVI . . . . . . . . . . . . . . . . . . . . . 43
H Support Packages for TeX 43
76 Fig, a (La)TeX-friendly drawing package . . . . . . . . . . . . . . . 43
77 TeXCAD, a drawing package for LaTeX . . . . . . . . . . . . . . . 44
78 Spelling checkers for work with TeX . . . . . . . . . . . . . . . . . 44
79 How many words have you written? . . . . . . . . . . . . . . . . . . 44
I Literate programming 45
80 What is Literate Programming? . . . . . . . . . . . . . . . . . . . . 45
81 WEB systems for various languages . . . . . . . . . . . . . . . . . 45
J Format conversions 46
82 Conversion from (La)TeX to plain text . . . . . . . . . . . . . . . . 46
83 Conversion from SGML or HTML to TeX . . . . . . . . . . . . . . 46
84 Conversion from (La)TeX to HTML . . . . . . . . . . . . . . . . . 47
85 Other conversions to and from (La)TeX . . . . . . . . . . . . . . . . 48
86 Using TeX to read SGML or XML directly . . . . . . . . . . . . . . 49
87 Retrieving (La)TeX from DVI, etc. . . . . . . . . . . . . . . . . . . 49
88 Translating LaTeX to Plain TeX . . . . . . . . . . . . . . . . . . . . 50
2
K Installing (La)TeX files 50
89 Installing a new package . . . . . . . . . . . . . . . . . . . . . . . . 50
90 Where to put new files . . . . . . . . . . . . . . . . . . . . . . . . . 51
91 Installing MiKTeX “known packages” . . . . . . . . . . . . . . . . 52
92 “Temporary” installation of (La)TeX files . . . . . . . . . . . . . . . 52
93 “Private” installations of files . . . . . . . . . . . . . . . . . . . . . 53
94 Installing a new font . . . . . . . . . . . . . . . . . . . . . . . . . . 54
95 Installing a font provided as MetaFont source . . . . . . . . . . . . . 54
96 Installing a PostScript printer built-in font . . . . . . . . . . . . . . 54
97 Installing the Bluesky versions of the CM fonts . . . . . . . . . . . . 55
98 Installing a Type 1 font . . . . . . . . . . . . . . . . . . . . . . . . 55
L Fonts 57
L.1 MetaFont fonts 57
99 Getting MetaFont to do what you want . . . . . . . . . . . . . . . . 57
100 Which font files should be kept . . . . . . . . . . . . . . . . . . . . 58
101 Acquiring bitmap fonts . . . . . . . . . . . . . . . . . . . . . . . . 58
L.2 Adobe Type 1 (“PostScript”) fonts 59
102 Using PostScript fonts with TeX . . . . . . . . . . . . . . . . . . . 59
103 Previewing files using Type 1 fonts . . . . . . . . . . . . . . . . . . 59
104 TeX font metric files for PostScript fonts . . . . . . . . . . . . . . . 60
105 Deploying Type 1 fonts . . . . . . . . . . . . . . . . . . . . . . . . 60
106 Choice of scalable outline fonts . . . . . . . . . . . . . . . . . . . . 61
107 Weird characters in dvips output . . . . . . . . . . . . . . . . . . . . 65
L.3 Macros for using fonts 65
108 Using non-standard fonts in Plain TeX . . . . . . . . . . . . . . . . 65
L.4 Particular font families 66
109 Using the “Concrete” fonts . . . . . . . . . . . . . . . . . . . . . . 66
110 Using the Latin Modern fonts . . . . . . . . . . . . . . . . . . . . . 67
M Hypertext and PDF 68
111 Making hypertext documents from TeX . . . . . . . . . . . . . . . . 68
112 Making Acrobat PDF documents from (La)TeX . . . . . . . . . . . 68
113 Quality of PDF from PostScript . . . . . . . . . . . . . . . . . . . . 69
114 The wrong type of fonts in PDF . . . . . . . . . . . . . . . . . . . . 69
115 Fuzzy fonts because Ghostscript too old . . . . . . . . . . . . . . . 70
116 Fonts go fuzzy when you switch to T1 . . . . . . . . . . . . . . . . 70
117 Characters missing from PDF output . . . . . . . . . . . . . . . . . 71
118 Finding ‘8-bit’ Type 1 fonts . . . . . . . . . . . . . . . . . . . . . . 71
119 Replacing Type 3 fonts in PostScript . . . . . . . . . . . . . . . . . 72
120 Hyperref and repeated page numbers . . . . . . . . . . . . . . . . . 72
121 Searching PDF files . . . . . . . . . . . . . . . . . . . . . . . . . . 73
N Graphics 73
122 How to import graphics into (La)TeX documents . . . . . . . . . . . 73
123 Imported graphics in dvips . . . . . . . . . . . . . . . . . . . . . . . 74
124 Imported graphics in PDFLaTeX . . . . . . . . . . . . . . . . . . . 75
125 Imported graphics in dvipdfm . . . . . . . . . . . . . . . . . . . . . 75
126 Importing graphics from “somewhere else” . . . . . . . . . . . . . . 76
127 Portable imported graphics . . . . . . . . . . . . . . . . . . . . . . 77
128 Repeated graphics in a document . . . . . . . . . . . . . . . . . . . 77
129 Limit the width of imported graphics . . . . . . . . . . . . . . . . . 78
130 Top-aligning imported graphics . . . . . . . . . . . . . . . . . . . . 78
131 Displaying MetaPost output in ghostscript . . . . . . . . . . . . . . 79
132 Drawing with TeX . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
133 Drawing Feynman diagrams in LaTeX . . . . . . . . . . . . . . . . 80
134 Labelling graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
O Bibliographies and citations 82
3
O.1 Creating bibliographies 82
135 Creating a BibTeX bibliography file . . . . . . . . . . . . . . . . . . 82
136 Creating a bibliography style . . . . . . . . . . . . . . . . . . . . . 82
137 Capitalisation in BibTeX . . . . . . . . . . . . . . . . . . . . . . . 83
138 Accents in bibliographies . . . . . . . . . . . . . . . . . . . . . . . 83
139 ‘String too long’ in BibTeX . . . . . . . . . . . . . . . . . . . . . . 83
140 BibTeX doesn’t understand lists of names . . . . . . . . . . . . . . 84
141 URLs in BibTeX bibliographies . . . . . . . . . . . . . . . . . . . . 84
142 Using BibTeX with Plain TeX . . . . . . . . . . . . . . . . . . . . . 85
143 Reconstructing .bib files . . . . . . . . . . . . . . . . . . . . . . . 85
144 BibTeX sorting and name prefixes . . . . . . . . . . . . . . . . . . . 86
145 Transcribed initials in BibTeX . . . . . . . . . . . . . . . . . . . . . 86
O.2 Creating citations 86
146 “Normal” use of BibTeX from LaTeX . . . . . . . . . . . . . . . . 86
147 Choosing a bibliography style . . . . . . . . . . . . . . . . . . . . . 87
148 Separate bibliographies per chapter? . . . . . . . . . . . . . . . . . 88
149 Multiple bibliographies? . . . . . . . . . . . . . . . . . . . . . . . . 88
150 Putting bibliography entries in text . . . . . . . . . . . . . . . . . . 90
151 Sorting and compressing citations . . . . . . . . . . . . . . . . . . . 90
152 Multiple citations . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
153 References from the bibliography to the citation . . . . . . . . . . . 91
154 Sorting lists of citations . . . . . . . . . . . . . . . . . . . . . . . . 92
155 Reducing spacing in the bibliography . . . . . . . . . . . . . . . . . 92
156 Table of contents rearranges “unsrt” ordering . . . . . . . . . . . . . 92
157 Non-english bibliographies . . . . . . . . . . . . . . . . . . . . . . 93
158 Format of numbers in the bibliography . . . . . . . . . . . . . . . . 93
O.3 Manipulating whole bibliographies 94
159 Listing all your BibTeX entries . . . . . . . . . . . . . . . . . . . . 94
160 Making HTML of your Bibliography . . . . . . . . . . . . . . . . . 94
P Adjusting the typesetting 94
P.1 Alternative document classes 94
161 Replacing the standard classes . . . . . . . . . . . . . . . . . . . . . 94
162 Producing slides . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
163 Creating posters with LaTeX . . . . . . . . . . . . . . . . . . . . . 96
164 Formatting a thesis in LaTeX . . . . . . . . . . . . . . . . . . . . . 96
165 Setting papers for journals . . . . . . . . . . . . . . . . . . . . . . . 96
166 A ‘report’ from lots of ‘article’s . . . . . . . . . . . . . . . . . . . . 97
167 Curriculum Vitae (Résumé) . . . . . . . . . . . . . . . . . . . . . . 97
168 Letters and the like . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
169 Other “document font” sizes? . . . . . . . . . . . . . . . . . . . . . 98
P.2 Document structure 99
170 The style of document titles . . . . . . . . . . . . . . . . . . . . . . 99
171 The style of section headings . . . . . . . . . . . . . . . . . . . . . 99
172 Appendixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
173 Indent after section headings . . . . . . . . . . . . . . . . . . . . . 101
174 How to create a \subsubsubsection . . . . . . . . . . . . . . . . . 101
175 The style of captions . . . . . . . . . . . . . . . . . . . . . . . . . . 102
176 Alternative head- and footlines in LaTeX . . . . . . . . . . . . . . . 102
177 Wide figures in two-column documents . . . . . . . . . . . . . . . . 103
178 1-column abstract in 2-column document . . . . . . . . . . . . . . . 103
179 Really blank pages between chapters . . . . . . . . . . . . . . . . . 103
180 Balancing columns at the end of a document . . . . . . . . . . . . . 104
181 My section title is too wide for the page header . . . . . . . . . . . . 105
182 Page numbering “hni of hmi” . . . . . . . . . . . . . . . . . . . . . 106
183 Page numbering by chapter . . . . . . . . . . . . . . . . . . . . . . 106
4
P.3 Page layout 106
184 Printer paper sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
185 Changing the margins in LaTeX . . . . . . . . . . . . . . . . . . . . 107
186 Packages to set up page designs . . . . . . . . . . . . . . . . . . . . 107
187 How to set up page layout “by hand” . . . . . . . . . . . . . . . . . 108
188 Changing margins “on the fly” . . . . . . . . . . . . . . . . . . . . 108
189 How to get rid of page numbers . . . . . . . . . . . . . . . . . . . . 109
190 \pagestyle{empty} on first page in LaTeX . . . . . . . . . . . . . 109
191 How to create crop marks . . . . . . . . . . . . . . . . . . . . . . . 110
192 ‘Watermarks’ on every page . . . . . . . . . . . . . . . . . . . . . . 110
193 Typesetting things in landscape orientation . . . . . . . . . . . . . . 110
194 Putting things at fixed positions on the page . . . . . . . . . . . . . 111
195 Preventing page breaks between lines . . . . . . . . . . . . . . . . . 112
196 Parallel setting of text . . . . . . . . . . . . . . . . . . . . . . . . . 113
197 Typesetting epigraphs . . . . . . . . . . . . . . . . . . . . . . . . . 114
198 (La)TeX PDF output prints at wrong size . . . . . . . . . . . . . . . 114
P.4 Spacing of characters and lines 115
199 Double-spaced documents in LaTeX . . . . . . . . . . . . . . . . . 115
200 Changing the space between letters . . . . . . . . . . . . . . . . . . 115
201 Setting text ragged right . . . . . . . . . . . . . . . . . . . . . . . . 116
202 Cancelling \ragged commands . . . . . . . . . . . . . . . . . . . . 116
P.5 Typesetting specialities 116
203 Including a file verbatim in LaTeX . . . . . . . . . . . . . . . . . . 116
204 Including line numbers in typeset output . . . . . . . . . . . . . . . 117
205 Code listings in LaTeX . . . . . . . . . . . . . . . . . . . . . . . . 117
206 Typesetting pseudocode in LaTeX . . . . . . . . . . . . . . . . . . . 118
207 Generating an index in (La)TeX . . . . . . . . . . . . . . . . . . . . 119
208 Typesetting URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
209 Typesetting music in TeX . . . . . . . . . . . . . . . . . . . . . . . 121
210 Zero paragraph indent . . . . . . . . . . . . . . . . . . . . . . . . . 122
211 Big letters at the start of a paragraph . . . . . . . . . . . . . . . . . 122
212 The comma as a decimal separator . . . . . . . . . . . . . . . . . . 122
213 Breaking boxes of text . . . . . . . . . . . . . . . . . . . . . . . . . 123
214 Overstriking characters . . . . . . . . . . . . . . . . . . . . . . . . 123
215 Realistic quotes for verbatim listings . . . . . . . . . . . . . . . . . 123
216 Printing the time . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
217 Redefining counters’ \the-commands . . . . . . . . . . . . . . . . 124
P.6 Tables of contents and indexes 124
218 The format of the Table of Contents, etc. . . . . . . . . . . . . . . . 124
219 Unnumbered sections in the Table of Contents . . . . . . . . . . . . 124
220 Bibliography, index, etc., in TOC . . . . . . . . . . . . . . . . . . . 125
221 Table of contents, etc., per chapter . . . . . . . . . . . . . . . . . . 126
222 Multiple indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
P.7 Labels and references 127
223 Referring to things by their name . . . . . . . . . . . . . . . . . . . 127
224 Referring to labels in other documents . . . . . . . . . . . . . . . . 128
Q How do I do. . . ? 129
Q.1 Mathematics 129
225 Proof environment . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
226 Roman theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
227 Defining a new log-like function in LaTeX . . . . . . . . . . . . . . 130
228 Set specifications and Dirac brackets . . . . . . . . . . . . . . . . . 130
229 Cancelling terms in maths expressions . . . . . . . . . . . . . . . . 130
230 Adjusting maths font sizes . . . . . . . . . . . . . . . . . . . . . . . 130
231 Ellipses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
232 Sub- and superscript positioning for operators . . . . . . . . . . . . 131
233 Text inside maths . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
234 Re-using an equation . . . . . . . . . . . . . . . . . . . . . . . . . 133
235 Line-breaking in in-line maths . . . . . . . . . . . . . . . . . . . . . 134
5
Q.2 Lists 134
236 Fancy enumeration lists . . . . . . . . . . . . . . . . . . . . . . . . 134
237 How to reduce list spacing . . . . . . . . . . . . . . . . . . . . . . . 135
238 Interrupting enumerated lists . . . . . . . . . . . . . . . . . . . . . 136
Q.3 Tables, figures and diagrams 138
239 The design of tables . . . . . . . . . . . . . . . . . . . . . . . . . . 138
240 Fixed-width tables . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
241 Variable-width columns in tables . . . . . . . . . . . . . . . . . . . 139
242 Spacing lines in tables . . . . . . . . . . . . . . . . . . . . . . . . . 140
243 Tables longer than a single page . . . . . . . . . . . . . . . . . . . . 141
244 How to alter the alignment of tabular cells . . . . . . . . . . . . . . 141
245 The thickness of rules in LaTeX tables . . . . . . . . . . . . . . . . 143
246 Flowing text around figures in LaTeX . . . . . . . . . . . . . . . . . 143
247 Diagonal separation in corner cells of tables . . . . . . . . . . . . . 144
248 How to change a whole row of a table . . . . . . . . . . . . . . . . . 144
249 Merging cells in a column of a table . . . . . . . . . . . . . . . . . 145
Q.4 Floating tables, figures, etc. 146
250 Floats on their own on float pages . . . . . . . . . . . . . . . . . . . 146
251 Extra vertical space in floats . . . . . . . . . . . . . . . . . . . . . . 146
252 Placing two-column floats at bottom of page . . . . . . . . . . . . . 147
253 Floats in multicolumn setting . . . . . . . . . . . . . . . . . . . . . 147
254 Facing floats on 2-page spread . . . . . . . . . . . . . . . . . . . . 148
255 Vertical layout of float pages . . . . . . . . . . . . . . . . . . . . . 148
Q.5 Footnotes 148
256 Footnotes in tables . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
257 Footnotes in LaTeX section headings . . . . . . . . . . . . . . . . . 149
258 Footnotes in captions . . . . . . . . . . . . . . . . . . . . . . . . . 149
259 Footnotes whose texts are identical . . . . . . . . . . . . . . . . . . 150
260 More than one sequence of footnotes . . . . . . . . . . . . . . . . . 151
261 Footnotes numbered “per page” . . . . . . . . . . . . . . . . . . . . 151
Q.6 Document management 152
262 What’s the name of this file . . . . . . . . . . . . . . . . . . . . . . 152
263 All the files used by this document . . . . . . . . . . . . . . . . . . 153
264 Marking changed parts of your document . . . . . . . . . . . . . . . 153
265 Conditional compilation and “comments” . . . . . . . . . . . . . . . 154
266 Bits of document from other directories . . . . . . . . . . . . . . . . 156
267 Version control using RCS, CVS or Subversion . . . . . . . . . . . . 157
268 Makefiles for LaTeX documents . . . . . . . . . . . . . . . . . . . . 158
269 How many pages are there in my document? . . . . . . . . . . . . . 158
270 Including Plain TeX files in LaTeX . . . . . . . . . . . . . . . . . . 158
Q.7 Hyphenation 159
271 My words aren’t being hyphenated . . . . . . . . . . . . . . . . . . 159
272 Weird hyphenation of words . . . . . . . . . . . . . . . . . . . . . . 159
273 (Merely) peculiar hyphenation . . . . . . . . . . . . . . . . . . . . 160
274 Accented words aren’t hyphenated . . . . . . . . . . . . . . . . . . 160
275 Using a new language with Babel . . . . . . . . . . . . . . . . . . . 160
276 Stopping all hyphenation . . . . . . . . . . . . . . . . . . . . . . . 161
277 Preventing hyphenation of a particular word . . . . . . . . . . . . . 162
278 Hyphenation exceptions . . . . . . . . . . . . . . . . . . . . . . . . 162
Q.8 Odds and ends 163
279 Typesetting all those TeX-related logos . . . . . . . . . . . . . . . . 163
280 How to do bold-tt or bold-sc . . . . . . . . . . . . . . . . . . . . . . 163
281 Automatic sizing of minipage . . . . . . . . . . . . . . . . . . . . 164
R Symbols, etc. 165
282 Symbols for the number sets . . . . . . . . . . . . . . . . . . . . . . 165
283 Better script fonts for maths . . . . . . . . . . . . . . . . . . . . . . 166
284 Setting bold Greek letters in LaTeX . . . . . . . . . . . . . . . . . . 167
285 The Principal Value Integral symbol . . . . . . . . . . . . . . . . . 167
286 How to use the underscore character . . . . . . . . . . . . . . . . . 167
287 How to type an ‘@’ sign? . . . . . . . . . . . . . . . . . . . . . . . 168
288 Typesetting the Euro sign . . . . . . . . . . . . . . . . . . . . . . . 168
6
289 How to get copyright, trademark, etc. . . . . . . . . . . . . . . . . . 169
S Macro programming 169
S.1 “Generic” macros and techniques 169
290 Finding the width of a letter, word, or phrase . . . . . . . . . . . . . 169
291 Patching existing commands . . . . . . . . . . . . . . . . . . . . . 169
292 Comparing the “job name” . . . . . . . . . . . . . . . . . . . . . . 170
293 Is the argument a number? . . . . . . . . . . . . . . . . . . . . . . . 171
294 Defining macros within macros . . . . . . . . . . . . . . . . . . . . 172
295 Spaces in macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
296 How to break the 9-argument limit . . . . . . . . . . . . . . . . . . 174
297 Defining characters as macros . . . . . . . . . . . . . . . . . . . . . 175
298 Active characters in command arguments . . . . . . . . . . . . . . . 176
299 Defining a macro from an argument . . . . . . . . . . . . . . . . . . 177
300 Transcribing LaTeX command definitions . . . . . . . . . . . . . . 177
301 Detecting that something is empty . . . . . . . . . . . . . . . . . . 178
302 Am I using PDFTeX? . . . . . . . . . . . . . . . . . . . . . . . . . 179
303 Subverting a token register . . . . . . . . . . . . . . . . . . . . . . 180
S.2 LaTeX macro tools and techniques 180
304 Using Plain or primitive commands in LaTeX . . . . . . . . . . . . 180
305 \@ and @ in macro names . . . . . . . . . . . . . . . . . . . . . . . 181
306 What’s the reason for ‘protection’? . . . . . . . . . . . . . . . . . . 182
307 \edef does not work with \protect . . . . . . . . . . . . . . . . . 182
308 The definitions of LaTeX commands . . . . . . . . . . . . . . . . . 182
309 Optional arguments like \section . . . . . . . . . . . . . . . . . . 184
310 More than one optional argument . . . . . . . . . . . . . . . . . . . 184
311 Commands defined with * options . . . . . . . . . . . . . . . . . . 185
312 LaTeX internal “abbreviations”, etc. . . . . . . . . . . . . . . . . . 185
313 Defining LaTeX commands within other commands . . . . . . . . . 186
S.3 LaTeX macro programming 187
314 How to change LaTeX’s “fixed names” . . . . . . . . . . . . . . . . 187
315 Changing the words babel uses . . . . . . . . . . . . . . . . . . . . 187
316 Running equation, figure and table numbering . . . . . . . . . . . . 188
317 Making labels from a counter . . . . . . . . . . . . . . . . . . . . . 188
318 Finding if you’re on an odd or an even page . . . . . . . . . . . . . 189
319 How to change the format of labels . . . . . . . . . . . . . . . . . . 189
320 Adjusting the presentation of section numbers . . . . . . . . . . . . 190
321 There’s a space added after my environment . . . . . . . . . . . . . 191
322 Finding if a label is undefined . . . . . . . . . . . . . . . . . . . . . 191
323 Master and slave counters . . . . . . . . . . . . . . . . . . . . . . . 191
T Things are Going Wrong. . . 192
T.1 Getting things to fit 192
324 Enlarging TeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
325 Why can’t I load PiCTeX? . . . . . . . . . . . . . . . . . . . . . . . 192
T.2 Making things stay where you want them 193
326 Moving tables and figures in LaTeX . . . . . . . . . . . . . . . . . . 193
327 Underlined text won’t break . . . . . . . . . . . . . . . . . . . . . . 194
328 Controlling widows and orphans . . . . . . . . . . . . . . . . . . . 195
T.3 Things have “gone away” 195
329 Old LaTeX font references such as \tenrm . . . . . . . . . . . . . . 195
330 Missing symbol commands . . . . . . . . . . . . . . . . . . . . . . 195
331 Where are the msx and msy fonts? . . . . . . . . . . . . . . . . . . . 196
332 Where are the am fonts? . . . . . . . . . . . . . . . . . . . . . . . . 196
U Why does it do that? 196
U.1 Common errors 196
333 LaTeX gets cross-references wrong . . . . . . . . . . . . . . . . . . 196
334 Start of line goes awry . . . . . . . . . . . . . . . . . . . . . . . . . 197
335 Why doesn’t verbatim work within . . . ? . . . . . . . . . . . . . . . . 197
336 No line here to end . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
337 Two-column float numbers out of order . . . . . . . . . . . . . . . . 200
338 Accents misbehave in tabbing . . . . . . . . . . . . . . . . . . . . 200
339 Package reports “command already defined” . . . . . . . . . . . . . 200
7
340 Why are my sections numbered 0.1 . . . ? . . . . . . . . . . . . . . . 201
341 Link text doesn’t break at end line . . . . . . . . . . . . . . . . . . . 201
342 Page number is wrong at start of page . . . . . . . . . . . . . . . . . 202
343 My brackets don’t match . . . . . . . . . . . . . . . . . . . . . . . 202
U.2 Common misunderstandings 203
344 What’s going on in my \include commands? . . . . . . . . . . . . 203
345 Why does it ignore paragraph parameters? . . . . . . . . . . . . . . 203
346 Case-changing oddities . . . . . . . . . . . . . . . . . . . . . . . . 204
347 Why does LaTeX split footnotes across pages? . . . . . . . . . . . . 204
348 Getting \marginpar on the right side . . . . . . . . . . . . . . . . . 205
349 Where have my characters gone? . . . . . . . . . . . . . . . . . . . 205
350 “Rerun” messages won’t go away . . . . . . . . . . . . . . . . . . . 206
351 Commands gobble following space . . . . . . . . . . . . . . . . . . 206
352 (La)TeX makes overfull lines . . . . . . . . . . . . . . . . . . . . . 207
353 Maths symbols don’t scale up . . . . . . . . . . . . . . . . . . . . . 208
354 Why doesn’t \linespread work? . . . . . . . . . . . . . . . . . . 208
355 Only one \baselineskip per paragraph . . . . . . . . . . . . . . . 209
356 Numbers too large in table of contents, etc. . . . . . . . . . . . . . . 209
357 Why is the inside margin so narrow? . . . . . . . . . . . . . . . . . 210
U.3 Why shouldn’t I? 210
358 Why use fontenc rather than t1enc? . . . . . . . . . . . . . . . . . . 210
359 Why bother with inputenc and fontenc? . . . . . . . . . . . . . . . . 211
360 Why not use eqnarray? . . . . . . . . . . . . . . . . . . . . . . . . 211
361 Why use \[ . . . \] in place of $$ . . . $$? . . . . . . . . . . . . . . . . 211
362 What’s wrong with \bf, \it, etc.? . . . . . . . . . . . . . . . . . . 212
363 What’s wrong with \newfont? . . . . . . . . . . . . . . . . . . . . 213
V The joy of TeX errors 213
364 How to approach errors . . . . . . . . . . . . . . . . . . . . . . . . 213
365 The structure of TeX error messages . . . . . . . . . . . . . . . . . 214
366 An extra ‘}’?? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
367 Capacity exceeded [semantic nest . . . ] . . . . . . . . . . . . . . . . 216
368 No room for a new ‘thing’ . . . . . . . . . . . . . . . . . . . . . . . 216
369 epsf gives up after a bit . . . . . . . . . . . . . . . . . . . . . . . . 217
370 Improper \hyphenation will be flushed . . . . . . . . . . . . . . . 217
371 “Too many unprocessed floats” . . . . . . . . . . . . . . . . . . . . 217
372 \spacefactor complaints . . . . . . . . . . . . . . . . . . . . . . 218
373 \end occurred inside a group . . . . . . . . . . . . . . . . . . . . . 218
374 “Missing number, treated as zero” . . . . . . . . . . . . . . . . . . . 219
375 “Please type a command or say \end” . . . . . . . . . . . . . . . . 219
376 “Unknown graphics extension” . . . . . . . . . . . . . . . . . . . . 220
377 “Missing $ inserted” . . . . . . . . . . . . . . . . . . . . . . . . . . 220
378 Warning: “Font shape . . . not available” . . . . . . . . . . . . . . . 221
379 Unable to read an entire line . . . . . . . . . . . . . . . . . . . . . . 221
380 “Fatal format file error; I’m stymied” . . . . . . . . . . . . . . . . . 222
381 Non-PDF special ignored! . . . . . . . . . . . . . . . . . . . . . . . 222
382 Mismatched mode ljfour and resolution 8000 . . . . . . . . . . . . . 223
383 “Too deeply nested” . . . . . . . . . . . . . . . . . . . . . . . . . . 223
384 Capacity exceeded — input levels . . . . . . . . . . . . . . . . . . . 224
385 PDFTeX destination . . . ignored . . . . . . . . . . . . . . . . . . . 224
386 Alignment tab changed to \cr . . . . . . . . . . . . . . . . . . . . . 224
387 Graphics division by zero . . . . . . . . . . . . . . . . . . . . . . . 225
388 Missing \begin{document} . . . . . . . . . . . . . . . . . . . . . 225
389 \normalsize not defined . . . . . . . . . . . . . . . . . . . . . . . 226
390 Too many math alphabets . . . . . . . . . . . . . . . . . . . . . . . 226
391 Not in outer par mode . . . . . . . . . . . . . . . . . . . . . . . . . 226
392 Perhaps a missing \item? . . . . . . . . . . . . . . . . . . . . . . . 227
393 Illegal parameter number in definition . . . . . . . . . . . . . . . . 228
394 Float(s) lost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
395 Option clash for package . . . . . . . . . . . . . . . . . . . . . . . 229
8
W Current TeX-related projects 230
396 The LaTeX3 project . . . . . . . . . . . . . . . . . . . . . . . . . . 230
397 Future WWW technologies and (La)TeX . . . . . . . . . . . . . . . 230
398 Making outline fonts from MetaFont . . . . . . . . . . . . . . . . . 231
399 The TeX document preparation environment . . . . . . . . . . . . . 232
400 The ANT typesetting system . . . . . . . . . . . . . . . . . . . . . 233
401 The ExTeX project . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
402 Omega and Aleph . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
403 PDFTeX becomes LUATeX . . . . . . . . . . . . . . . . . . . . . . 233
404 The XeTeX project . . . . . . . . . . . . . . . . . . . . . . . . . . 234
X You’re still stuck? 234
405 You don’t understand the answer . . . . . . . . . . . . . . . . . . . 234
406 Submitting new material for the FAQ . . . . . . . . . . . . . . . . . 234
407 Reporting a LaTeX bug . . . . . . . . . . . . . . . . . . . . . . . . 234
408 What to do if you find a bug . . . . . . . . . . . . . . . . . . . . . . 235
§ § § § § § § § § § § § § § § § § §
A Introduction
This is a set of Frequently Asked Questions (FAQ) for English-speaking users of TeX.
The questions answered here cover a wide range of topics, but the actual typesetting
issues are mostly covered from the viewpoint of a LaTeX user.
You may use the FAQ
Origins
The FAQ was originated by the Committee of the UK TeX Users’ Group (UK TUG)
as a development of a regular posting to the Usenet newsgroup comp.text.tex that
was maintained for some time by Bobby Bodenheimer. The first UK version was much
re-arranged and corrected from the original, and little of Bodenheimer’s work now
remains.
Most members of the committee of UK TUG, over the years since 1994, have con-
tributed to this FAQ to some extent. The following people, who have never been mem-
bers of the committee, have also contributed help or advice: Donald Arseneau, Bar-
bara Beeton, Karl Berry, Giuseppe Bilotta, Charles Cameron, Damian Cugley, Michael
Dewey, Michael Downes, Jean-Pierre Drucbert, Thomas Esser, Ulrike Fischer, An-
thony Goreham, Norman Gray, Eitan Gurari, William Hammond, Hartmut Henkel,
John Hobby, Morten Høgholm, Berthold Horn, Ian Hutchinson, Werner Icking, Reg-
nor Jernsletten, David Kastrup, Oleg Katsitadze, Isaac Khabaza, Ulrich Klauer, Markus
9
Kohm, Simon Law, Daniel Luecking, Sanjoy Mahajan, Andreas Matthias, Brooks
Moses, Iain Murray, Vilar Camara Neto, Ted Nieland, Hans Nordhaug, Pat Rau, Heiko
Oberdiek, Piet van Oostrum, Scott Pakin, Oren Patashnik, Steve Peter, Philip Ratcliffe,
José Carlos Santos, Walter Schmidt, Hans-Peter Schröcker, Joachim Schrod, Maarten
Sneep, James Szinger, Ulrik Vieth, Mike Vulis, Chris Walker, Peter Wilson, Rick Zac-
cone and Reinhard Zierke.
B The Background
1 What is TeX?
TeX is a typesetting system written by Donald E. Knuth, who says in the Preface to
his book on TeX (see books about TeX) that it is “intended for the creation of beautiful
books — and especially for books that contain a lot of mathematics”.
Knuth is Emeritus Professor of the Art of Computer Programming at Stanford Uni-
versity in California, USA. Knuth developed the first version of TeX in 1978 to deal
with revisions to his series “the Art of Computer Programming”. The idea proved pop-
ular and Knuth produced a second version (in 1982) which is the basis of what we use
today.
Knuth developed a system of ‘literate programming’ to write TeX, and he provides
the literate (WEB) source of TeX free of charge, together with tools for processing the
web source into something that can be compiled and something that can be printed;
there’s never any mystery about what TeX does. Furthermore, the WEB system pro-
vides mechanisms to port TeX to new operating systems and computers; and in order
that one may have some confidence in the ports, Knuth supplied a test by means of
which one may judge the fidelity of a TeX system. TeX and its documents are there-
fore highly portable.
TeX is a macro processor, and offers its users a powerful programming capabil-
ity. For this reason, TeX on its own is a pretty difficult beast to deal with, so Knuth
provided a package of macros for use with TeX called Plain TeX; Plain TeX is effec-
tively the minimum set of macros one can usefully employ with TeX, together with
some demonstration versions of higher-level commands (the latter are better regarded
as models than used as-is). When people say they’re “programming in TeX”, they
usually mean they’re programming in Plain TeX.
2 How should I pronounce “TeX”?
The ‘X’ is “really” the Greek letter Chi (χ, in lower case), and is pronounced by
English-speakers either a bit like the ‘ch’ in the Scots word ‘loch’ ([x] in the IPA)
or (at a pinch, if you can’t do the Greek sound) like ‘k’. It definitely is not pronounced
‘ks’ (the Greek letter with that sound doesn’t look remotely like the Latin alphabet
‘X’).
This curious usage derives from Knuth’s explanation in the TeXbook that the name
comes from the Greek word for ‘art’ or ‘craft’ (‘τε χνη’), which is the root of the
English word ‘technology’. Knuth’s logo for TeX is merely the uppercase version of
the first three (Greek) letters of the word, jiggled about a bit; we don’t use that logo
(and logos like it) in this FAQ (see Typesetting TeX-related logos).
3 What is MetaFont?
MetaFont was written by Knuth as a companion to TeX; whereas TeX defines the lay-
out of glyphs on a page, MetaFont defines the shapes of the glyphs and the relations
between them. MetaFont details the sizes of glyphs, for TeX’s benefit, and details
the rasters used to represent the glyphs, for the benefit of programs that will produce
printed output as post processes after a run of TeX.
MetaFont’s language for defining fonts permits the expression of several classes of
things: first (of course), the simple geometry of the glyphs; second, the properties of
the print engine for which the output is intended; and third, ‘meta’-information which
can distinguish different design sizes of the same font, or the difference between two
fonts that belong to the same (or related) families.
Knuth (and others) have designed a fair range of fonts using MetaFont, but font
design using MetaFont is much more of a minority skill than is TeX macro-writing.
The complete TeX-user nevertheless needs to be aware of MetaFont, and to be able to
run MetaFont to generate personal copies of new fonts.
10
4 What is MetaPost?
The MetaPost system (by John Hobby) implements a picture-drawing language very
much like that of MetaFont except that it outputs Encapsulated PostScript files in-
stead of run-length-encoded bitmaps. MetaPost is a powerful language for producing
figures for documents to be printed on PostScript printers, either directly or embed-
ded in (La)TeX documents. It includes facilities for directly integrating TeX text and
mathematics with the graphics. (Knuth tells us that he uses nothing but MetaPost for
diagrams in text that he is writing.)
Although PDFLaTeX cannot ordinarily handle PostScript graphics, the output of
MetaPost is sufficiently simple and regular that PDFLaTeX can handle it direct, using
code borrowed from ConTeXt — see graphics in PDFLaTeX.
Much of MetaPost’s source code was copied from MetaFont’s sources, with
Knuth’s permission.
A mailing list discussing MetaPost is available; subscribe via the TUG mailman
interface. The TUG website also hosts a MetaPost summary page.
5 How can I be sure it’s really TeX?
TeX (and MetaFont and MetaPost) are written in a ‘literate’ programming language
called Web which is designed to be portable across a wide range of computer systems.
How, then, is a new version of TeX checked?
Of course, any sensible software implementor will have his own suite of tests to
check that his software runs: those who port TeX and its friends to other platforms do
indeed perform such tests.
Knuth, however, provides a ‘conformance test’ for both TeX (trip) and Meta-
Font (trap). He characterises these as ‘torture tests’: they are designed not to check
the obvious things that ordinary typeset documents, or font designs, will exercise, but
rather to explore small alleyways off the main path through the code of TeX. They are,
to the casual reader, pretty incomprehensible!
Once an implementation of TeX has passed its trip test, or an implementation of
MetaFont has passed its trap test, then it may in principe be distributed as a working
version. (In practice, any distributor would test new versions against “real” documents
or fonts, too; trip and trap don’t actually test any for real world problems.
6 Are TeX and friends Y2K compliant?
Crashing: None of TeX, MetaFont or MetaPost can themselves crash due to any
change whatever in the date of any sort.
Timestamps: In the original sources, a 2-digit year was stored as the creation time
for format files and that value is printed in logfiles. These items should not be of
general concern, since the only use of the date format file is to produce the log
output, and the log file is designed for human readers only.
Knuth announced in 1998 that implementators could alter this code without fear
of being accused of non-compliance. Nearly all implementations that are being
actively maintained had been modified to generate 4-digit years in the format file
and the log, by the end of 1998. The original sources themselves have now been
modified so that 4-digit year numbers are stored.
The \year primitive: Certification of a TeX implementation (see trip/trap testing)
does not require that \year return a meaningful value (which means that TeX
can, in principle, be implemented on platforms that don’t make the value of the
clock available to user programs). The TeXbook (see TeX-related books) defines
\year as “the current year of our Lord”, which is the only correct meaning for
\year for those implementations which can supply a meaningful value, which is
to say nearly all of them.
In short, TeX implementations should provide a value in \year giving the 4-digit
year Anno Domini, or the value 1776 if the platform does not support a date func-
tion.
Note that if the system itself fails to deliver a correct date to TeX, then \year will
of course return an incorrect value. TeX cannot be considered Y2K compliant, in
this sense, on a system that is not itself Y2K compliant.
Macros: TeX macros can in principle perform calculations on the basis of the value of
\year. The LaTeX suite performs such calculations in a small number of places;
11
the calculations performed in the current (supported) version of LaTeX are known
to be Y2K compliant.
Other macros and macro packages should be individually checked.
External software: Software such as DVI translators needs to be individually checked.
7 What is e-TeX?
While Knuth has declared that TeX will never change in any substantial way, there
remain things that one might wish had been done differently, or indeed implemented at
all.
The NTS project set out to produce an advanced replacement for TeX, to provide a
basis for developing such modifications: this “New Typesetting System” would share
Knuth’s aims, but would implement the work in a modern way taking account of the
lessons learned with TeX. While a first demonstrator NTS did appear, it wasn’t practi-
cally useful, and the project seems no longer active.
In parallel with its work on NTS itself, the project developed a set of extensions
that can be used with a (“true”) TeX system. Such a modified system is known as
an e-TeX system, and the concept has proved widely successful. Indeed, current TeX
distributions are delivered with most formats built with an e-TeX system (for those who
don’t want them, e-TeX’s extensions can be disabled, leaving a functionally standard
TeX system).
The extensions range from the simple (increasing the number of available registers
from 256 to 65536) through to extremely subtle programming support.
ConTeXt has required e-TeX for its operation for some time.
Some LaTeX packages already specify the use of e-TeX. Some such packages may
not work at all on a non-e-TeX system; others will work, but not as well as on an e-
TeX system. The LaTeX team has announced that future LaTeX packages (specifically
those from the team, as opposed to those individually contributed) may require e-TeX
for optimum performance.
8 What is PDFTeX?
PDFTeX has entered the main stream of TeX distributions: most LaTeX and ConTeXt
users nowadays use PDFTeX whether they know it or not (more precisely, they use an
amalgam of PDFTeX and e-TeX). So what is PDFTeX?
PDFTeX is a development of TeX that is capable of generating typeset PDF out-
put in place of DVI. PDFTeX has other capabilities, most notably in the area of fine
typographic detail (for example, its support for optimising line breaks), but its greatest
impact to date has been in the area of PDF output.
PDFTeX started as a topic for Hàn Thế Thành’s Master’s thesis, and seems first to
have been published in TUGboat 18(4), in 1997 (though it was certainly discussed at
the TUG’96 conference in Russia).
While the world was making good use of “pre-releases” of PDFTeX, Thành used
it as a test-bed for the micro-typography which was the prime subject of his Ph.D.
research. Since Thành was finally awarded his Ph.D., day-to-day maintenance and de-
velopment of PDFTeX 1.0 (and later) has been in the hands of a group of PDFTeX
maintainers (which includes Thành); the group has managed to maintain a stable plat-
form for general use.
9 What is LaTeX?
LaTeX is a TeX macro package, originally written by Leslie Lamport, that provides a
document processing system. LaTeX allows markup to describe the structure of a doc-
ument, so that the user need not think about presentation. By using document classes
and add-on packages, the same document can be produced in a variety of different
layouts.
Lamport says that LaTeX “represents a balance between functionality and ease of
use”. This shows itself as a continual conflict that leads to the need for such things as
FAQs: LaTeX can meet most user requirements, but finding out how is often tricky.
10 What is LaTeX 2ε ?
Lamport’s last version of LaTeX (LaTeX 2.09, last updated in 1992) was superseded
in 1994 by a new version (LaTeX 2ε ) provided by the LaTeX team (the LaTeX team).
LaTeX 2ε is now the only readily-available version of LaTeX, and draws together sev-
eral threads of LaTeX development from the later days of LaTeX 2.09.
12
LaTeX 2ε has several enhancements over LaTeX 2.09, but they were all rather mi-
nor, with a view to continuity and stability rather than the “big push” that some had
expected from the team. LaTeX 2ε continues to this day to offer a compatibility mode
in which most files prepared for use with LaTeX 2.09 will run (albeit with somewhat
reduced performance, and subject to bitter complaints in the log file). Differences
between LaTeX 2ε and LaTeX 2.09 are outlined in a series of ‘guide’ files that are
available in every LaTeX distribution (the same directory also contains “news” about
each new release of LaTeX 2ε ).
LaTeX guides and news: macros/latex/doc
11 How should I pronounce “LaTeX(2e)”?
Lamport never recommended how one should pronounce LaTeX, but a lot of people
pronounce it ‘Lay TeX’ or perhaps ‘Lah TeX’ (with TeX pronounced as the program
itself; see the rules for TeX). It is definitely not to be pronounced in the same way as
the rubber-tree gum.
The ‘epsilon’ in ‘LaTeX 2ε ’ is supposed to be suggestive of a small improvement
over the old LaTeX 2.09. Nevertheless, most people pronounce the name as ‘LaTeX-
two-ee’.
12 Should I use Plain TeX or LaTeX?
There’s no straightforward answer to this question. Many people swear by Plain TeX,
and produce highly respectable documents using it (Knuth is an example of this, of
course). But equally, many people are happy to let someone else take the design deci-
sions for them, accepting a small loss of flexibility in exchange for a saving of brain
power.
The arguments around this topic can provoke huge amounts of noise and heat, with-
out offering much by way of light; your best bet is to find out what those around you
are using, and to go with the crowd. Later on, you can always switch your allegiance;
don’t bother about it.
If you are preparing a manuscript for a publisher or journal, ask them what markup
they want before you develop your own; many big publishers have developed their
own (La)TeX styles for journals and books, and insist that authors stick closely to their
markup.
13 How does LaTeX relate to Plain TeX?
LaTeX is a program written in the programming language TeX. (In the same sense, any
LaTeX document is also a program, which is designed to run ‘alongside’, or ‘inside’
LaTeX, whichever metaphor you prefer.)
Plain TeX is also a program written in the programming language TeX.
Both exist because writing your documents in ‘raw’ TeX would involve much rein-
venting of wheels for every document. They both serve as convenient aids to make
document writing more pleasant: LaTeX is a far more extensive aid.
LaTeX is close to being a superset of Plain TeX. Many documents designed for
Plain TeX will work with LaTeX with no more than minor modifications (though some
will require substantial work).
Interpretation of any (La)TeX program involves some data-driven elements, and
LaTeX has a wider range of such elements than does Plain TeX. As a result, the map-
ping from LaTeX to Plain TeX is far less clear than that in the other direction.
14 What is ConTeXt?
ConTeXt is a macro package developed by Hans Hagen, originally to serve the needs
of his (Dutch) firm Pragma. It was designed with the same general-purpose aims as
LaTeX, but (being younger) reflects much more recent thinking about the structure of
markup, etc. In particular, ConTeXt can customise its markup to an author’s language
(customising modules for Dutch, English and German are provided, at present).
ConTeXt is well integrated, in all of its structure, with the needs of hypertext
markup, and in particular with the facilities offered by PDFTeX. The default instal-
lation employs a version of PDFTeX built with the e-TeX extensions, which allows
further flexibility.
ConTeXt doesn’t yet have quite such a large developer community as does LaTeX,
but those developers who are active seem to have prodigious energy. Some support is
available via a WIKI site.
13
ConTeXt distribution: macros/context
15 What are the AMS packages (AMSTeX, etc.)?
AMSTeX is a TeX macro package, originally written by Michael Spivak for the Ameri-
can Mathematical Society (AMS) during 1983–1985 and is described in the book “The
Joy of TeX” (The Joy of TeX). It is based on Plain TeX, and provides many features for
producing more professional-looking maths formulas with less burden on authors. It
pays attention to the finer details of sizing and positioning that mathematical publishers
care about. The aspects covered include multi-line displayed equations, equation num-
bering, ellipsis dots, matrices, double accents, multi-line subscripts, syntax checking
(faster processing on initial error-checking TeX runs), and other things.
As LaTeX increased in popularity, authors asked to submit papers to the AMS in
LaTeX, and so the AMS developed AMSLaTeX, which is a collection of LaTeX pack-
ages and classes that offer authors most of the functionality of AMSTeX. The AMS
no longer recommends the use of AMSTeX, and urges its users to use AMSLaTeX
instead.
AMSTeX distribution: macros/amstex
AMSLaTeX distribution: macros/latex/required/amslatex
16 What is Eplain?
The Eplain macro package expands on and extends the definitions in Plain TeX. Eplain
is not intended to provide “generic typesetting capabilities”, as do LaTeX or Texinfo.
Instead, it defines macro tools that should be useful whatever commands you choose to
use when you prepare your manuscript.
For example, Eplain does not have a command \section, which would format sec-
tion headings in an “appropriate” way, as LaTeX’s \section does. The philosophy of
Eplain is that some people will always need or want to go beyond the macro designer’s
idea of “appropriate”. Such canned macros are fine — as long as you are willing to
accept the resulting output. If you don’t like the results, or if you are trying to match a
different format, you are out of luck.
On the other hand, almost everyone would like capabilities such as cross-referencing
by labels, so that you don’t have to put actual page numbers in the manuscript. The
authors of Eplain are not aware of any generally available macro packages that do not
force their typographic style on an author, and yet provide such capabilities.
Another useful feature of Eplain is the ability to create PDF files with hyper-
links. The cross-referencing macros can implicitly generate hyperlinks for the cross-
references, but you can also create explicit hyperlinks, both internal (pointing to a des-
tination within the current document) and external (pointing to another local document
or a URL).
Several LaTeX packages provide capabilities which Plain TeX users are lacking,
most notably text colouring and rotation provided by the graphics bundle (packages
color and graphics). Although the graphics bundle provides a Plain TeX “loader” for
some of the packages, it is not a trivial job to pass options to those packages under
Plain TeX, and much of the functionality of the packages is accessed through package
options. Eplain extends the loader so that options can be passed to the packages just as
they are in LaTeX. The following packages are known to work with Eplain: graphics,
graphicx, color, autopict (LaTeX picture environment), psfrag, and url.
Eplain documentation is available online, and there’s also a mailing list — sign up,
or browse the list archives, via http://tug.org/mailman/listinfo/tex-eplain
Eplain distribution: macros/eplain
17 What is Lollipop?
Lollipop is a macro package written by Victor Eijkhout; it was used in the production
of his book “TeX by Topic” (see (La)TeX Tutorials). The manual says of it:
14
Lollipop is an attempt to make structured text formatting available for envi-
ronments where previously only WYSIWYG packages could be used because
adapting the layout is so much more easy with them than with traditional TeX
macro packages.
The manual goes on to talk of ambitions to “capture some of the LaTeX market
share”; it’s a very witty package, but little sign of it taking over from LaTeX is de-
tectable. . . An article about Lollipop appeared in TUGboat 13(3).
Lollipop distribution: nonfree/macros/lollipop
18 What is Texinfo?
Texinfo is a documentation system that uses one source file to produce both on-line
information and printed output. So instead of writing two different documents, one
for the on-line help and the other for a typeset manual, you need write only one doc-
ument source file. When the work is revised, you need only revise one document. By
convention, Texinfo source file names end with a .texi or .texinfo extension.
Texinfo is a macro language, somewhat similar to LaTeX, but with slightly less
expressive power. Its appearance is of course rather similar to any TeX-based macro
language, except that its macros start with @ rather than the \ that’s more commonly
used in TeX systems.
You can write and format Texinfo files into Info files within GNU emacs, and read
them using the emacs Info reader. You can also format Texinfo files into Info files using
makeinfo and read them using info, so you’re not dependent on emacs. The distribution
includes a Perl script, texi2html, that will convert Texinfo sources into HTML: the
language is a far better fit to HTML than is LaTeX, so that the breast-beating agonies
of converting LaTeX to HTML are largely avoided.
Finally, of course, you can also print the files, or convert them to PDF using PDF-
TeX.
Texinfo distribution: macros/texinfo/texinfo
19 If TeX is so good, how come it’s free?
It’s free because Knuth chose to make it so. He is nevertheless apparently happy that
others should earn money by selling TeX-based services and products. While several
valuable TeX-related tools and packages are offered subject to restrictions imposed by
the GNU General Public Licence (‘Copyleft’), TeX itself is not subject to Copyleft.
There are commercial versions of TeX available; for some users, it’s reassuring
to have paid support. What is more, some of the commercial implementations have
features that are not available in free versions. (The reverse is also true: some free
implementations have features not available commercially.)
This FAQ concentrates on ‘free’ distributions of TeX, but we do at least list the
major vendors.
20 What is the future of TeX?
Knuth has declared that he will do no further development of TeX; he will continue to
fix any bugs that are reported to him (though bugs are rare). This decision was made
soon after TeX version 3.0 was released; at each bug-fix release the version number
acquires one more digit, so that it tends to the limit π (at the time of writing, Knuth’s
latest release is version 3.141592). Knuth wants TeX to be frozen at version π when
he dies; thereafter, no further changes may be made to Knuth’s source. (A similar rule
is applied to MetaFont; its version number tends to the limit e, and currently stands at
2.71828.)
Knuth explains his decision, and exhorts us all to respect it, in a paper originally
published in TUGboat 11(4) (and reprinted in the NTG journal MAPS).
There are projects (some of them long-term projects: see, for example, the LaTeX3
project) to build substantial new macro packages based on TeX. For the even longer
term, there are various projects to build a successor to TeX; see, for example, the
Omega/Aleph and ExTeX projects.
21 Reading (La)TeX files
So you’ve been sent a TeX file: what are you going to do with it?
15
You can, of course, “just read it”, since it’s a plain text file, but the markup tags in
the document may prove distracting. Most of the time, even TeX experts will typeset a
TeX file before attempting to read it.
So, you need to typeset the document. The good news is that TeX systems are
available, free, for most sorts of computer; the bad news is that you need a pretty
complete TeX system even to read a single file, and complete TeX systems are pretty
large.
TeX is a typesetting system that arose from a publishing project (see what is TeX),
and its basic source is available free from its author. However, at its root, it is just a
typesetting engine: even to view or to print the typeset output, you will need ancil-
iary programs. In short, you need a TeX distribution — a collection of TeX-related
programs tailored to your operating system: for details of the sorts of things that are
available, see TeX distributions or commercial TeX distributions (for commercial dis-
tributions).
But beware — TeX makes no attempt to look like the sort of WYSIWYG system
you’re probably used to (see why is TeX not WYSIWYG): while many modern versions
of TeX have a compile–view cycle that rivals the best commercial word processors in
its responsiveness, what you type is usually markup, which typically defines a logical
(rather than a visual) view of what you want typeset.
However, in this context markup proves to be a blessing in disguise: a good pro-
portion of most TeX documents is immediately readable in an ordinary text editor. So,
while you need to install a considerable system to attain the full benefits of the TeX
document that you were sent, the chances are you can understand quite a bit of it with
nothing more than the ordinary tools you already have on your computer.
22 Why is TeX not a WYSIWYG system?
W YSIWYG is a marketing term (“What you see is what you get”) for a particular style
of text processor. W YSIWYG systems are characterised by two principal claims: that
you type what you want to print, and that what you see on the screen as you type is a
close approximation to how your text will finally be printed.
The simple answer to the question is, of course, that TeX was conceived long be-
fore the marketing term, at a time when the marketing imperative wasn’t perceived as
significant. However, that was a long time ago: why has nothing been done with the
“wonder text processor” to make it fit with modern perceptions?
There are two answers to this. First, the simple “things have been done” (but
they’ve not taken over the TeX world); and second, “there are philosophical reasons
why the way TeX has developed is ill-suited to the WYSIWYG style”. Indeed, there is
a fundamental problem with applying WYSIWYG techniques to TeX: the complexity of
TeX makes it hard to get the equivalent of TeX’s output without actually running TeX.
A celebrated early system offering “WYSIWYG using TeX” came from the VorTeX
project: a pair of (early) Sun workstations worked in tandem, one handling the user in-
terface while the other beavered away in the background typesetting the result. VorTeX
was quite impressive for its time, but the two workstations combined had hugely less
power than the average sub-thousand dollar Personal Computer nowadays, and its code
has not proved portable (it never even made the last ‘great’ TeX version change, at the
turn of the 1990s, to TeX version 3). Modern systems that are similar in their approach
are Lightning Textures (an extension of Blue Sky’s original TeX system for the Macin-
tosh), and Scientific Word (which can also cooperate with a computer algebra system);
both these systems are commercially available (commercially available).
The issue has of recent years started to attract attention from TeX developers, and
several interesting projects addressing the “TeX document preparation environment”
(TeX document preparation environment) are in progress.
Nevertheless, the TeX world has taken a long time to latch onto the idea of WYSI -
WYG . Apart from simple arrogance (“we’re better, and have no need to consider the
petty doings of the commercial word processor market”), there is a real conceptual
difference between the word processor model of the world and the model LaTeX and
ConTeXt employ — the idea of “markup”. “Pure” markup expresses a logical model
of a document, where every object within the document is labelled according to what
it is rather than how it should appear: appearance is deduced from the properties of
the type of object. Properly applied, markup can provide valuable assistance when it
comes to re-use of documents.
16
Established WYSIWYG systems find the expression of this sort of structured markup
difficult; however, markup is starting to appear in the lists of the commercial world’s
requirements, for two reasons. First, an element of markup helps impose style on a
document, and commercial users are increasingly obsessed with uniformity of style;
and second, the increasingly pervasive use of XML-derived document archival formats
demands it. The same challenges must needs be addressed by TeX-based document
preparation support schemes, so we are observing a degree of confluence of the needs
of the two communities: interesting times may be ahead of us.
23 TeX User Groups
There has been a TeX User Group since very near the time TeX first appeared. That
first group, TUG, is still active and its journal TUGboat continues in regular publica-
tion with articles about TeX, MetaFont and related technologies, and about document
design, processing and production. TUG holds a yearly conference, whose proceedings
are published in TUGboat.
TUG’s web site is a valuable resource for all sorts of TeX-related matters, such as
details of TeX software, and lists of TeX vendors and TeX consultants. Back articles
from TUGboat are slowly (subject to copyright issues, etc.) making their way to the
site, too.
Some time ago, TUG established a “technical council”, whose task was to oversee
the development of TeXnical projects. Most such projects nowadays go on their way
without any support from TUG, but TUG’s web site lists its Technical Working Groups
(TWGs).
TUG has a reasonable claim to be considered a world-wide organisation, but there
are many national and regional user groups, too; TUG’s web site maintains a list of
“Local User Groups” (LUGs).
Contact TUG itself via:
17
TeX for the Impatient by Paul W. Abrahams, Karl Berry and Kathryn A. Hargreaves
(Addison-Wesley, 1990, ISBN 0-201-51375-7 — now out of print, but see online
books)
TeX in Practice by Stephan von Bechtolsheim (Springer Verlag, 1993, 4 volumes,
ISBN 3-540-97296-X for the set, or Vol. 1: ISBN 0-387-97595-0, Vol. 2: ISBN 0-
387-97596-9, Vol. 3: ISBN 0-387-97597-7, and Vol. 4: ISBN 0-387-97598-5)
TeX: Starting from 1 1 by Michael Doob (Springer Verlag, 1993, ISBN 3-540-
56441-1 — now out of print)
The Joy of TeX by Michael D. Spivak (second edition, AMS, 1990, ISBN 0-821-
82997-1)
The Advanced TeXbook by David Salomon (Springer Verlag, 1995, ISBN 0-387-
94556-3)
Digital Typography by Donald Knuth (CSLI and Cambridge University Press, 1999,
ISBN 1-57586-011-2, paperback ISBN 1-57586-010-4).
and in late 2000, a “Millennium Boxed Set” of all 5 volumes of Knuth’s “Computers
and Typesetting” series (about TeX and MetaFont) was published by Addison Wesley:
Computers & Typesetting, Volumes A–E Boxed Set by Donald Knuth (Addison-Wesley,
2001, ISBN 0-201-73416-8).
18
A sample of George Grätzer’s “Math into LaTeX”, in Adobe Acrobat format, and ex-
ample files for the three LaTeX Companions, and for Grätzer’s “First Steps in LaTeX”,
are all available on CTAN.
There’s a nicely-presented list of of “recommended books” to be had on the web:
http://www.macrotex.net/texbooks/
The list of MetaFont books is rather short:
The MetaFontbook by Donald Knuth (Addison Wesley, 1986, ISBN 0-201-13445-4,
ISBN 0-201-52983-1 paperback)
Alan Hoenig’s ‘TeX Unbound ’ includes some discussion and examples of using Meta-
Font.
A book covering a wide range of topics (including installation and maintenance) is:
Making TeX Work by Norman Walsh (O’Reilly and Associates, Inc, 1994, ISBN 1-
56592-051-1)
The book is decidedly dated, and is now out of print, but a copy is available via
sourceforge and on CTAN, and we list it under “online books”.
This list only covers books in English: notices of new books, or warnings that
books are now out of print are always welcome. However, this FAQ does not carry
reviews of current published material.
Examples for First Steps in LaTeX: info/examples/FirstSteps
Examples for LaTeX Companion: info/examples/tlc2
Examples for LaTeX Graphics Companion: info/examples/lgc
Examples for LaTeX Web Companion: info/examples/lwc
Sample of Math into LaTeX: info/mil/mil.pdf
25 Books on Type
The following is a partial listing of books on typography in general. Of these,
Bringhurst seems to be the one most often recommended.
The Elements of Typographic Style by Robert Bringhurst (Hartley & Marks, 1992,
ISBN 0-88179-033-8)
Finer Points in the Spacing & Arrangement of Type by Geoffrey Dowding (Hartley &
Marks, 1996, ISBN 0-88179-119-9)
The Thames & Hudson Manual of Typography by Ruari McLean (Thames & Hudson,
1980, ISBN 0-500-68022-1)
The Form of the Book by Jan Tschichold (Lund Humphries, 1991, ISBN 0-85331-623-
6)
Type & Layout by Colin Wheildon (Strathmore Press, 2006, ISBN 1-875750-22-3)
The Design of Books by Adrian Wilson (Chronicle Books, 1993, ISBN 0-8118-0304-
X)
Optical Letter Spacing by David Kindersley and Lida Cardozo Kindersley (The Car-
dozo Kindersley Workshop 2001, ISBN 1-874426-139)
There are many catalogues of type specimens but the following books provide a
more interesting overall view of types in general and some of their history.
Alphabets Old & New by Lewis F. Day (Senate, 1995, ISBN 1-85958-160-9)
An Introduction to the History of Printing Types by Geoffrey Dowding (British Li-
brary, 1998, UK ISBN 0-7123-4563-9; USA ISBN 1-884718-44-2)
The Alphabet Abecedarium by Richar A. Firmage (David R. Godine, 1993, ISBN 0-
87923-998-0)
The Alphabet and Elements of Lettering by Frederick Goudy (Dover, 1963, ISBN 0-
486-20792-7)
Anatomy of a Typeface by Alexander Lawson (David R. Godine, 1990, ISBN 0-
87923-338-8)
A Tally of Types by Stanley Morison (David R. Godine, 1999, ISBN 1-56792-004-7)
19
Counterpunch by Fred Smeijers (Hyphen, 1996, ISBN 0-907259-06-5)
Treasury of Alphabets and Lettering by Jan Tschichold (W. W. Norton, 1992, ISBN 0-
393-70197-2)
A Short History of the Printed Word by Warren Chappell and Robert Bringhurst (Hart-
ley & Marks, 1999, ISBN 0-88179-154-7)
The above lists are limited to books published in English. Typographic styles are
somewhat language-dependent, and similarly the ‘interesting’ fonts depend on the par-
ticular writing system involved.
26 Where to find FAQs
Bobby Bodenheimer’s article, from which this FAQ was developed, used to be posted
(nominally monthly) to newsgroup comp.text.tex. The (long obsolete) last posted
copy of that article is kept on CTAN for auld lang syne.
A version of the present FAQ may be browsed via the World-Wide Web, and its
sources are available from CTAN.
This FAQ and others are regularly mentioned, on comp.text.tex and elsewhere,
in a “pointer FAQ” which is also saved at http://tug.org/tex-ptr-faq
A 2006 innovation from Scott Pakin is the “visual” LaTeX FAQ. This is a document
with (mostly rubbish) text formatted so as to highlight things we discuss here, and pro-
viding Acrobat hyper-links to the relevant answers in this FAQ on the Web. The visual
FAQ is provided in PDF format, on CTAN; it works best using Adobe Acrobat Reader
7 (or later); some features are missing with other readers, or with earlier versions of
Acrobat Reader
Another excellent information source, available in English, is the (La)TeX naviga-
tor.
Both the Francophone TeX usergroup Gutenberg and the Czech/Slovak usergroup
CS-TUG have published translations of this FAQ, with extensions appropriate to their
languages.
Herbert Voß’s excellent LaTeX tips and tricks provides excellent advice on most
topics one might imagine (though it’s not strictly a FAQ) — highly recommended for
most ordinary mortals’ use.
The Open Directory Project (ODP) maintains a list of sources of (La)TeX help,
including FAQs. View the TeX area at http://dmoz.org/Computers/Software/
Typesetting/TeX/
Other non-English FAQs are available (off-CTAN):
German Posted regularly to de.comp.tex, and archived on CTAN; the FAQ also ap-
pears at http://www.dante.de/faq/de-tex-faq/
French An interactive (full-screen!) FAQ may be found at http://www.frenchpro6.
com/screen.pdf/FAQscreen.pdf, and a copy for printing at http://frenchle.
free.fr/FAQ.pdf; A FAQ used to be posted regularly to fr.comp.text.tex,
and is archived on CTAN — sadly, that effort seems to have fallen by the wayside.
Spanish See http://apolo.us.es/CervanTeX/FAQ/
Czech See http://www.fi.muni.cz/cstug/csfaq/
Resources available on CTAN are:
Dante FAQ: help/de-tex-faq
French FAQ: help/LaTeX-FAQ-francaise
Sources of this FAQ: help/uk-tex-faq
Obsolete comp.text.tex FAQ: obsolete/help/TeX,_LaTeX,_etc.:
_Frequently_Asked_Questions_with_Answers
The visual FAQ: info/visualFAQ/visualFAQ.pdf
27 How to get help
So you’ve looked at all relevant FAQs you can find, you’ve looked in any books you
have, and scanned relevant tutorials. . . and still you don’t know what to do.
If you are seeking a particular package or program, look on your own system first:
you might already have it — the better TeX distributions contain a wide range of sup-
porting material. The CTAN Catalogue can also help: you can search it, or you can
20
browse it “by topic” (see http://www.tex.ac.uk/tex-archive/help/Catalogue/
bytopic.html). A catalogue entry has a description of the package, and links to any
documentation known on the net. . . . when the entry is up-to-date.
Failing all that, look to see if anyone else has had the problem before; there are two
places where people ask: browse or search the newsgroup comp.text.tex via Google
groups, and the mailing list texhax via its archive
If those “back question” searches fail, you’ll have to ask the world at large. To ask
a question on comp.text.tex, you can use your own news client (if you have one),
or use the “start a new topic” button on http://groups.google.com/group/comp.
text.tex. To ask a question on texhax, you may simply send mail to texhax@tug.
org, but it’s probably better to subscribe to the list (via http://tug.org/mailman/
listinfo/texhax) first — not everyone will answer to you as well as to the list.
subscribe metafont
to [email protected]
Note that there’s also a MetaPost-specific mailing list available via the TUG lists;
in fact there’s little danger of becoming confused by subscribing to both.
Announcements of TeX-related installations on the CTAN archives are sent to
the mailing list ctan-ann. Subscribe to the list via its MailMan web-site https:
//lists.dante.de/mailman/listinfo/ctan-ann; list archives are available at
the same address. The list archives may also be browsed via http://www.mail-
archive.com/[email protected]/, and an RSS feed is also available: http:
//www.mail-archive.com/[email protected]/maillist.xml
• Make sure you’re asking the right people. Don’t ask in a TeX forum about printer
device drivers for the Foobar operating system. Yes, TeX users need printers, but
no, TeX users will typically not be Foobar systems managers.
Similarly, avoid posing a question in a language that the majority of the group
don’t use: post in Ruritanian to de.comp.text.tex and you may have a long wait
before a German- and Ruritanian-speaking TeX expert notices your question.
• If your question is (or may be) TeX-system-specific, report what system you’re
using, or intend to use: “I can’t install TeX” is as good as useless, whereas “I’m
trying to install the mumbleTeX distribution on the Grobble operating system”
gives all the context a potential respondent might need. Another common situ-
ation where this information is important is when you’re having trouble installing
something new in your system: “I want to add the glugtheory package to my
mumbleTeX v12.0 distribution on the Grobble 2024 operating system”.
• If you need to know how to do something, make clear what your environment is:
“I want to do x in Plain TeX”, or “I want to do y in LaTeX running the boggle
class”. If you thought you knew how, but your attempts are failing, tell us what
21
you’ve tried: “I’ve already tried installing the elephant in the minicar directory,
and it didn’t work, even after refreshing the filename database”.
• If something’s going wrong within (La)TeX, pretend you’re submitting a LaTeX
bug report, and try to generate a minimum failing example. If your example needs
your local xyzthesis class, or some other resource not generally available, be sure
to include a pointer to how the resource can be obtained.
• Be as succinct as possible. Your helpers don’t usually need to know why you’re
doing something, just what you’re doing and where the problem is.
22
31 (La)TeX Tutorials, etc.
From a situation where every (La)TeX user had to buy a book if she was not to find
herself groping blindly along, we now have what almost amounts to an embarrassment
of riches of online documentation. The following answers attempt to create lists of
sources “by topic”.
First we have introductory manuals, for Plain TeX and LaTeX.
Next comes a selection of “specialised” (La)TeX tutorials, each of which concen-
trates on a single LaTeX topic.
A couple of reference documents (it would be good to have more) are listed in an
answer of their own.
Next comes the (rather new) field of TeX-related WIKIs.
A rather short list gives us a Typography style tutorial.
Finally, we have a set of links to Directories of (La)TeX information, and details of
some “books” that were once published conventionally, but are now available on-line.
32 Online introductions: Plain TeX
Michael Doob’s splendid ‘Gentle Introduction’ to Plain TeX (available on CTAN) has
been stable for a very long time.
Another recommendable document is D. R. Wilkins ‘Getting started with TeX’,
available on the web at http://www.ntg.nl/doc/wilkins/pllong.pdf
Gentle Introduction: info/gentle/gentle.pdf
33 Online introductions: LaTeX
Tobias Oetiker’s ‘(Not so) Short Introduction to LaTeX 2ε ’, is regularly updated, as
people suggest better ways of explaining things, etc. The introduction is available on
CTAN, together with translations into a rather large set of languages.
Peter Flynn’s “Beginner’s LaTeX” (which also started as course material) is a pleas-
ing read. A complete copy may be found on CTAN, but it may also be browsed over
the web (http://www.tex.ac.uk/tex-archive/info/beginlatex/html/).
Harvey Greenberg’s ‘Simplified Introduction to LaTeX’ was written for a lecture
course, and is also available on CTAN (in PostScript only, unfortunately).
Edith Hodgen’s LaTeX, a Braindump starts you from the ground up — giving a
basic tutorial in the use of Linux to get you going (rather a large file. . . ). Its parent site,
David Friggens’ documentation page is a useful collection of links in itself.
Andy Roberts’ introductory material is a pleasing short introduction to the use of
(La)TeX; some of the slides for actual tutorials are to be found on the page, as well.
Chris Harrison’s TeX book presents basic LaTeX with useful hints for extensions
Nicola Talbot’s LaTeX for complete novices does what it claims: the author teaches
LaTeX at the University of East Anglia.
Nicola Talbot also provides a set of introductory tutorials, which include exercises
(with solutions). The page was developed as an extension to the LaTeX course Nicola
teaches at the University of East Anglia.
An interesting (and practical) tutorial about what not to do is l2tabu, or “A list of
sins of LaTeX 2ε users” by Mark Trettin, translated into English by Jürgen Fenn. The
tutorial is available from CTAN as a PDF file (though the source is also available).
Beginner’s LaTeX: info/beginlatex/beginlatex-3.6.pdf
Not so Short Introduction: info/lshort/english/lshort.pdf (in English, you
may browse for sources and other language versions at info/lshort)
Simplified LaTeX: info/simplified-latex/simplified-intro.ps
The sins of LaTeX users: info/l2tabu/english/l2tabuen.pdf; source also
available: info/l2tabu/english/l2tabuen.tex
34 Specialised (La)TeX tutorials
The AMS publishes a “Short Math Guide for LaTeX”, which is available (in several
formats) via http://www.ams.org/tex/short-math-guide.html
Herbert Voß is developing a parallel document, that is also very useful; it’s part of
his “tips and tricks” and a copy is maintained on CTAN.
Two documents written more than ten years apart about font usage in TeX are
worth reading: Essential NFSS by Sebastian Rahtz, and Font selection in LaTeX, cast
23
in the form of an FAQ, by Walter Schmidt. A general compendium of font information
(including the two above) may be found on the TUG web site.
Peter Smith’s “LaTeX for Logicians” covers a rather smaller subject area, but is
similarly comprehensive (mostly by links to documents on relevant topics, rather than
as a monolithic document).
Keith Reckdahl’s “Using Imported Graphics in LaTeX 2ε ” is an excellent introduc-
tion to graphics use. It’s available on CTAN, but the sources aren’t available (promised
“some time soon”).
Vincent Zoonekynd provides a set of excellent (and graphic) tutorials on the pro-
gramming of title page styles, chapter heading styles and section heading styles. In
each file, there is a selection of graphics representing an output style, and for each
style, the code that produces it is shown.
An invaluable step-by-step setup guide for establishing a “work flow” through your
(La)TeX system, so that output appears at the correct size and position on standard-
sized paper, and that the print quality is satisfactory, is Mike Shell’s testflow. The
tutorial consists of a large plain text document, and there is a supporting LaTeX file
together with correct output, both in PostScript and PDF, for each of A4 and “letter”
paper sizes. The complete kit is available on CTAN (distributed with the author’s
macros for papers submitted for IEEE publications). The issues are also covered in a
later FAQ answer.
Documentation of Japanese TeX use appears at least twice on the web: Haruhiko
Okumura’s page on typesetting Japanese with Omega (the parent page is in Japanese,
so out of the scope of this FAQ).
One “Tim” documents pTeX (a TeX system widely used in Japan) in his “English
notes on pTeX”.
Some university departments make their local documentation available on the web.
Most straightforwardly, there’s the simple translation of existing documentation into
HTML, for example the INFO documentation of the (La)TeX installation, of which
a sample is the LaTeX documentation available at http://www.tac.dk/cgi-bin/
info2www?(latex)
More ambitiously, some university departments have enthusiastic documenters who
make public record of their (La)TeX support. For example, Tim Love (of Cambridge
University Engineering Department) maintains his deparment’s pages at http://www-
h.eng.cam.ac.uk/help/tpl/textprocessing/
Graphics in LaTeX 2ε : the document is available in PostScript and PDF formats
as info/epslatex/english/epslatex.ps and info/epslatex/english/
epslatex.pdf respectively
testflow : macros/latex/contrib/IEEEtran/testflow
Herbert Voß’s Maths tutorial: info/math/voss/mathmode/Mathmode.pdf
35 Reference documents
For TeX primitive commands a rather nice quick reference booklet, by John W. Ship-
man, is available; it’s arranged in the same way as the TeXbook. By contrast, you can
view David Bausum’s list of TeX primitives alphabetically or arranged by “family”.
Either way, the list has a link for each control sequence, that leads you to a detailed
description, which includes page references to the TeXbook.
There doesn’t seem to be a reference that takes in Plain TeX as well as the primitive
commands.
Similarly, there’s no completely reliable command-organised reference to LaTeX,
but the NASA Hypertext Help with LaTeX is recently much improved. It still talks in
LaTeX 2.09-isms in places, but it’s been updated for current LaTeX; there are a number
of mirrors of the site, and it may be worth choosing a “local” one if you’re going to use
it a lot.
36 WIKI pages for TeX and friends
The WIKI concept can be a boon to everyone, if used sensibly. The “general” WIKI
allows anyone to add stuff, or to edit stuff that someone else has added: while there is
obvious potential for chaos, there is evidence that a strong user community can keep a
WIKI under control.
Following the encouraging performance of the ConTeXt WIKI, both a (Plain) TeX
WIKI and a LaTeX WIKI have been established. Both seem rather sparse, as yet, and
24
the LaTeX WIKI contains some suggestions that go counter to established advice (e.g.,
the LaTeX WIKI has details on the use of the eqnarray environment); however one
may hope that both will become useful resources in the longer term.
37 Typography tutorials
There’s also (at least one) typographic style tutorial available on the Web, the excellent
“Guidelines for Typography in NBCS”. In fact, its parent page is also worth a read:
among other things, it provides copies of the “guidelines” document in a wide variety
of primary fonts, for comparison purposes. The author is careful to explain that he
has no ambition to supplant such excellent books as Bringhurst’s, but the document
(though it does contain its Rutgers-local matter) is a fine introduction to the issues of
producing readable documents.
Peter Wilson’s manual for his memoir class has a lengthy introductory section on
typographic considerations, which is a fine tutorial, written by someone who is aware
of the issues as they apply to (La)TeX users.
memoir distribution: macros/latex/contrib/memoir
texdoc footmisc
which opens an xdvi window showing documentation of the footmisc package. Accord-
ing to the type of file texdoc finds, it will launch xdvi, a ghostscript-based PostScript
viewer or a PDF reader. If it can’t find any documentation, it may launch a Web browser
to look at its copy of the CTAN catalogue. The catalogue has an entry for package doc-
umentation, and since CTAN now encourages authors to submit documentation of their
packages, that entry may provide a useful lead.
25
If your luck (as defined above) doesn’t hold out, you’ve got to find documentation
by other means. This is where you need to exercise your intelligence: you have to find
the documentation for yourself. What follows offers a range of possible techniques.
The commonest form of documentation of LaTeX add-ons is within the .dtx file
in which the code is distributed (see documented LaTeX sources). Such files are sup-
posedly processable by LaTeX itself, but there are occasional hiccups on the way to
readable documentation. Common problems are that the package itself is needed to
process its own documentation (so must be unpacked before processing), and that the
.dtx file will not in fact process with LaTeX. In the latter case, the .ins file will
usually produce a .drv (or similarly-named) file, which you process with LaTeX in-
stead. (Sometimes the package author even thinks to mention this wrinkle in a package
README file.)
Another common form is the separate documentation file; particularly if a package
is “conceptually large” (and therefore needs a lot of documentation), the documentation
would prove a cumbersome extension to the .dtx file. Examples of such cases are
the memoir class (whose documentation, memman, is widely praised as an introduction
to typesetting concepts), the KOMA-script bundle (whose developers take the trouble
to produce detailed documentation in both German and English), and the fancyhdr
package (whose documentation derives from a definitive tutorial in a mathematical
journal). Even if the documentation is not separately identified in a README file, it
should not be too difficult to recognise its existence.
Documentation within the package itself is the third common form. Such docu-
mentation ordinarily appears in comments at the head of the file, though at least one
eminent author regularly places it after the \endinput command in the package. (This
is desirable, since \endinput is a ‘logical’ end-of-file, and (La)TeX doesn’t read be-
yond it: thus such documentation does not ‘cost’ any package loading time.)
The above suggestions cover most possible ways of finding documentation. If,
despite your best efforts, you can’t find it in any of the above places, there’s the awful
possibility that the author didn’t bother to document his package (on the “if it was hard
to write, it should be hard to use” philosophy). Most ordinary mortals will seek support
from some more experienced user at this stage, though it is possible to proceed in the
way that the original author apparently expected. . . by reading his code.
41 Learning to write LaTeX classes and packages
There’s nothing particularly magic about the commands you use when writing a
package, so you can simply bundle up a set of LaTeX \(re)newcommand and
\(re)newenvironment commands, put them in a file package.sty and you have
a package.
However, any but the most trivial package will require rather more sophistication.
Some details of LaTeX commands for the job are to be found in ‘LaTeX 2ε for class
and package writers’ (clsguide, part of the LaTeX documentation distribution). Be-
yond this, a good knowledge of TeX itself is valuable: thus books such as the TeX-
book or TeX by topic are relevant. With good TeX knowledge it is possible to use the
documented source of LaTeX as reference material (dedicated authors will acquaint
themselves with the source as a matter of course). A complete set of the documented
source of LaTeX may be prepared by processing the file source2e.tex in the LaTeX
distribution, but individual files in the distribution may be processed separately with
LaTeX, like any well-constructed .dtx file.
Writing good classes is not easy; it’s a good idea to read some established ones
(classes.dtx, for example, is the documented source of the standard classes other
than Letter, and may itself be formatted with LaTeX). Classes that are not part of the
distribution are commonly based on ones that are, and start by loading the standard
class with \LoadClass — an example of this technique may be seen in ltxguide.cls
classes.dtx : macros/latex/base/classes.dtx
ltxguide.cls: macros/latex/base/ltxguide.cls
LaTeX documentation: macros/latex/doc
source2e.tex : macros/latex/base/source2e.tex
42 MetaFont and MetaPost Tutorials
Apart from Knuth’s book, there seems to be only one publicly-available tutorial for
MetaFont, by Christophe Grandsire (a copy in PDF form may be downloaded). Geof-
26
frey Tobin’s MetaFont for Beginners (see using MetaFont) describes how the MetaFont
system works and how to avoid some of the potential pitfalls.
There is also an article on how to run both MetaFont and MetaPost (the programs).
Peter Wilson’s Some Experiences in Running MetaFont and MetaPost offers the benefit
of Peter’s experience (he has designed a number of ‘historical’ fonts using MetaFont).
For MetaFont the article is geared towards testing and installing new MetaFont fonts,
while its MetaPost section describes how to use MetaPost illustrations in LaTeX and
PDFLaTeX documents, with an emphasis on how to use appropriate fonts for any text
or mathematics.
Hans Hagen (of ConTeXt fame) offers a MetaPost tutorial called MetaFun (which
admittedly concentrates on the use of MetaPost within ConTeXt). It may be found on
his company’s MetaPost page.
Other MetaPost tutorials that have appeared are two in English by André Heck and
Urs Oswald, and one in French (listed here because it’s clearly enough written that this
author understands it), by Laurent Chéno; both have been recommended for inclusion
in the FAQ
Urs Oswald’s tutorial is accompanied by a super tool for testing little bits of Meta-
Post, which is an invaluable aid to the learner: http://www.tlhiv.org/cgi-bin/
MetaPostPreviewer/index.cgi
Vincent Zoonekynd’s massive set of example MetaPost files is available on CTAN;
the set includes a Perl script to convert the set to html, and the set may be viewed on the
web. While these examples don’t exactly constitute a “tutorial”, they’re most certainly
valuable learning material. Urs Oswald presents a similar document, written more as a
document, and presented in PDF.
Beginners’ guide: info/metafont/beginners/metafont-for-beginners.pdf
Peter Wilson’s “experiences”: info/metafont/metafp/metafp.pdf (PDF format)
Vincent Zoonekynd’s examples: info/metapost/examples
43 BibTeX Documentation
BibTeX, a program originally designed to produce bibliographies in conjunction with
LaTeX, is explained in Section 4.3 and Appendix B of Leslie Lamport’s LaTeX manual
(see TeX-related books). The document “BibTeXing”, contained in the file btxdoc.
tex, expands on the chapter in Lamport’s book. The LaTeX Companion (see TeX-
related books) also has information on BibTeX and writing BibTeX style files.
The document “Designing BibTeX Styles”, contained in the file btxhak.tex, ex-
plains the postfix stack-based language used to write BibTeX styles (.bst files). The
file btxbst.doc is the template for the four standard styles (plain, abbrv, alpha,
unsrt). It also contains their documentation. The complete BibTeX documentation
set (including the files above) is available on CTAN.
A useful tutorial of the whole process of using BibTeX is Nicolas Markey’s “Tame
the BeaST (The B to X of BibTeX)”, which may also be found on CTAN.
BibTeX documentation: biblio/bibtex/distribs/doc
BibTeX documentation, in PDF: biblio/bibtex/contrib/doc
Tame the BeaST: info/bibtex/tamethebeast/ttb_en.pdf
44 Where can I find the symbol for . . .
There is a wide range of symbols available for use with TeX, most of which are not
shown (or even mentioned) in (La)TeX books. The Comprehensive LaTeX Symbol List
(by Scott Pakin et al.) illustrates over 2000 symbols, and details the commands and
packages needed to produce them.
Other questions in this FAQ offer specific help on kinds of symbols:
27
45 The PiCTeX manual
PiCTeX is a set of macros by Michael Wichura for drawing diagrams and pictures.
The macros are freely available; however, the PiCTeX manual itself is not free. Un-
fortunately, TUG is no longer able to supply copies of the manual (as it once did),
and it is now available only through Personal TeX Inc, the vendors of PCTeX (http:
//www.pctex.com/). The manual is not available electronically.
pictex : graphics/pictex
47 What is a driver?
A driver is a program that takes as input a DVI file (DVI files) and (usually) produces
a file that can be sent to a typographic output device, called a printer for short.
A driver will usually be specific to a particular printer, although any PostScript
printer ought to be able to print the output from a PostScript driver.
As well as the DVI file, the driver needs font information. Font information may
be held as bitmaps or as outlines, or simply as a set of pointers into the fonts that the
printer itself ‘has’. Each driver will expect the font information in a particular form.
For more information on the forms of fonts, see PK files, TFM files, virtual fonts and
Using PostScript fonts with TeX.
48 What are PK files?
PK files (packed raster) contain font bitmaps. The output from MetaFont () includes a
generic font (GF) file and the utility gftopk produces the PK file from that. There are a
lot of PK files, as one is needed for each font, that is each magnification (size) of each
design (point) size for each weight for each family. Further, since the PK files for one
printer do not necessarily work well for another, the whole set needs to be duplicated
for each printer type at a site. As a result, they are often held in an elaborate directory
structure, or in ‘font library files’, to regularise access.
49 What are TFM files?
TFM stands for TeX Font Metrics; TFM files hold information about the sizes of the
characters of the font in question, and about ligatures and kerns within that font. One
TFM file is needed for each font used by TeX, that is for each design (point) size for
each weight for each family; one TFM file serves for all magnifications, so that there
are (typically) fewer TFM files than there are PK files. The important point is that TFM
files are used by TeX (LaTeX, etc.), but are not, generally, needed by the printer driver.
50 Virtual fonts
Virtual fonts for TeX were first implemented by David Fuchs in the early days of TeX,
but for most people they date from when Knuth redefined the format, and wrote some
support software, in 1989 (he published an article in TUGboat at the time, and a plain
text copy is available on CTAN).
Virtual fonts provide a way of telling TeX about something more complicated than
just a one-to-one character mapping. The entities you define in a virtual font look
28
like characters to TeX (they appear with their sizes in a font metric file), but the DVI
processor may expand them to something quite different.
Specifically, TeX itself only looks at a TFM file that contains details of how the
virtual font will appear: but of course, TeX only cares about the metrics of a character,
so its demands are pretty small. The acroDVI processor, however, has to understand
the details of what is in the virtual font, so as to know “what to draw, where”. So, for
every virtual font read by a DVI driver, there has to be a TFM file to be read by TeX.
(PDFTeX, of course, needs both the TFM and the translation of the virtual font, since
it does the whole job in the one program.)
You can use a virtual font:
In practice, the most common use of virtual fonts is to remap Adobe Type 1 fonts
(see font metrics), though there has also been useful useful work building ‘fake’ maths
fonts (by bundling glyphs from several fonts into a single virtual font). Virtual Com-
puter Modern fonts, making a Cork encoded font from Knuth’s originals by using
remapping and fragments of DVI for single-glyph ‘accented characters’, were the first
“Type 1 format” versions available.
Virtual fonts are normally created in a single ASCII VPL (Virtual Property List)
file, which includes both sets of information. The vptovf program is then used to the
create the binary TFM and VF files.
A “how-to” document, explaining how to generate a VPL, describes the endless
hours of fun that may be had, doing the job by hand. Despite the pleasures to be had of
the manual method, the commonest way (nowadays) of generating VPL files is to use
the fontinst package, which is described in detail PostScript font metrics. Qdtexvpl is
another utility for creating ad-hoc virtual fonts (it uses TeX to parse a description of
the virtual font, and qdtexvpl itself processes the resulting DVI file).
fontinst: fonts/utilities/fontinst
Knuth on virtual fonts: info/knuth/virtual-fonts
Virtual fonts “how to”: info/virtualfontshowto/virtualfontshowto.txt
qdtexvpl: fonts/utilities/qdtexvpl
51 \special commands
TeX provides the means to express things that device drivers can do, but about which
TeX itself knows nothing. For example, TeX itself knows nothing about how to include
PostScript figures into documents, or how to set the colour of printed text; but some
device drivers do.
Such things are introduced to your document by means of \special commands;
all that TeX does with these commands is to expand their arguments and then pass the
command to the DVI file. In most cases, there are macro packages provided (often
with the driver) that provide a comprehensible interface to the \special; for exam-
ple, there’s little point including a figure if you leave no gap for it in your text, and
changing colour proves to be a particularly fraught operation that requires real wiz-
ardry. LaTeX 2ε has standard graphics and colour packages that make figure inclusion,
rotation and scaling, and colour typesetting via \specials all easy.
The allowable arguments of \special depend on the device driver you’re using.
Apart from the examples above, there are \special commands in the emTeX drivers
(e.g., dvihplj, dviscr, etc.) that will draw lines at arbitrary orientations, and commands
in dvitoln03 that permit the page to be set in landscape orientation.
52 How does hyphenation work in TeX?
Everyone knows what hyphenation is: we see it in most books we read, and (if we’re
alert) often spot ridiculous mis-hyphenation from time to time (at one time, British
newspapers were a fertile source).
Hyphenation styles are culturally-determined, and the same language may be hy-
phenated differently in different countries — for example, British and American styles
of hyphenation of English are very different. As a result, a typesetting system that
29
is not restricted to a single language at a single locale needs to be able to change its
hyphenation rules from time to time.
TeX uses a pretty good system for hyphenation (originally designed by Frank
Liang), and while it’s capable of missing “sensible” hyphenation points, it seldom se-
lects grossly wrong ones. The algorithm matches candidates for hyphenation against
a set of “hyphenation patterns”. The candidates for hyphenation must be sequences of
letters (or other single characters that TeX may be persuaded to think of as letters) —
things such as TeX’s \accent primitive interrupt hyphenation.
Sets of hyphenation patterns are usually derived from analysis of a list of valid
hyphenations (the process of derivation, using a tool called patgen, is not ordinarily a
participatory sport).
The patterns for the languages a TeX system is going to deal with may only be
loaded when the system is installed. To change the set of languages, a partial reinstal-
lation is necessary.
TeX provides two “user-level” commands for control of hyphenation: \language
(which selects a hyphenation style), and \hyphenation (which gives explicit instruc-
tions to the hyphenation engine, overriding the effect of the patterns).
The ordinary LaTeX user need not worry about \language, since it is very thor-
oughly managed by the babel package; use of \hyphenation is discussed in hyphen-
ation failure.
53 What are LaTeX classes and packages?
Current LaTeX makes a distinction between the macros that define the overall layout of
a document, and the macros that tweak that layout (to one extent or another) to provide
what the author really wants.
The distinction was not very clear in LaTeX 2.09, and after some discussion (in the
later stages of development of current LaTeX) the names “class” and “package” were
applied to the two concepts.
The idea is that a document’s class tells LaTeX what sort of document it’s dealing
with, while the packages the document loads “refine” that overall specification.
On the disc, the files only appear different by virtue of their name “extension” —
class files are called *.cls while package files are called *.sty. Thus we find that the
LaTeX standard article class is represented on disc by a file called article.cls, while
the footmisc package (which refines article’s definition of footnotes) is represented on
disc by a file called footmisc.sty.
The user defines the class of his document with the \documentclass command
(typically the first command in a document), and loads packages with the \usepackage
command. A document may have several \usepackage commands, but it may have
only one \documentclass command. (Note that there are programming-interface ver-
sions of both commands, since a class may choose to load another class to refine its
capabilities, and both classes and packages may choose to load other packages.)
54 Documented LaTeX sources (.dtx files)
LaTeX 2ε , and many support macro packages, are now written in a literate program-
ming style (literate programming), with source and documentation in the same file.
This format, known as ‘doc’, in fact originated before the days of the LaTeX project as
one of the “Mainz” series of packages. The documented sources conventionally have
the suffix .dtx, and should normally be stripped of documentation before use with
LaTeX. Alternatively you can run LaTeX on a .dtx file to produce a nicely formatted
version of the documented code. An installation script (with suffix .ins) is usually
provided, which needs the standard LaTeX 2ε docstrip package (among other things,
the installation process strips all the comments that make up the documentation for
speed when loading the file into a running LaTeX system). Several packages can be
included in one .dtx file, with conditional sections, and there facilities for indices of
macros etc. Anyone can write .dtx files; the format is explained in The LaTeX Com-
panion, and a tutorial is available from CTAN (which comes with skeleton .dtx and
.ins files).
Composition of .dtx files is supported in emacs by Matt Swift’s swiftex system: it
provides a doc-tex mode which treats .dtx files rather better than AUC-TeX manages.
Another useful way of generating .dtx files is to write the documentation and the
code separately, and then to combine them using the makedtx system. This technique
has particular value in that the documentation file can be used separately to generate
30
HTML output; it is often quite difficult to make LaTeX to HTML conversion tools deal
with .dtx files, since they use an unusual class file.
.dtx files are not used by LaTeX after they have been processed to produce .sty
or .cls (or whatever) files. They need not be kept with the working system; however,
for many packages the .dtx file is the primary source of documentation, so you may
want to keep .dtx files elsewhere.
An interesting sideline to the story of .dtx files is the docmfp package, which
extends the model of the doc package to MetaFont and MetaPost ( and), thus permit-
ting documented distribution of bundles containing code for MetaFont and MetaPost
together with related LaTeX code.
clsguide.pdf : macros/latex/doc/clsguide.pdf
docmfp.sty : macros/latex/contrib/docmfp
docstrip.tex : Part of the LaTeX distribution
DTX tutorial: info/dtxtut
makedtx : support/makedtx
swiftex.el: support/emacs-modes/swiftex
• certain “structured comments” are required; important ones are the identification
of the file type, and information about the “bounding box” of the figure (i.e., the
minimum rectangle enclosing it);
• some commands are forbidden — for example, a showpage command will cause
the image to disappear, in most TeX-output environments; and
• “preview information” is permitted, for the benefit of things such as word proces-
sors that don’t have the ability to draw PostScript in their own right — this preview
information may be in any one of a number of system-specific formats, and any
viewing program may choose to ignore it.
1. Licence: in the spirit of TeX, we hope for free software; in the spirit of today’s
lawyer-enthralled society, CTAN provides a list of “standard” licence statements.
2. Documentation: it’s good for users to be able to browse documentation before
downloading a package. You need at least a plain text README file (exactly that
name); best is a PDF file of the package documentation, prepared for screen read-
ing.
3. Name: endless confusion is caused by name clashes. If your package has the same
name as one already on CTAN, or if your package installation generates files of
the same name as something in a “normal” distribution, the CTAN team will delay
installation while they check that you’re doing the right thing: they may nag you
to change the name, or to negotiate a take-over with the author of the original
package. Browse the archive to ensure uniqueness.
The name you choose should also (as far as possible) be somewhat descriptive of
what your submission actually does; while “descriptiveness” is to some extent in
the eye of the beholder, it’s clear that names such as mypackage or jiffy aren’t
suitable.
If you are able to use anonymous ftp, get yourself a copy of the file README.
uploads from any CTAN archive. The file tells you where to upload, what to up-
35
load, and how to notify the CTAN management about what you want doing with your
upload.
You may also upload via the Web: each of the principle CTAN sites offers an
upload page — choose from http://www.ctan.org/upload.html, http://www.
dante.de/CTAN/upload.html or http://www.tex.ac.uk/upload.html; the pages
lead you through the process, showing you the information you need to supply.
If you can use neither of these methods, ask advice of the CTAN management: if
the worst comes to the worst, it may be possible to mail a contribution.
If it’s appropriate (if your package is large, or regularly updated), the CTAN man-
agement can arrange to mirror your contribution direct into the archive. At present this
may only be done if your contribution is available via ftp, and of course the directory
structure on your archive must ‘fit’.
README.uploads: README.uploads
in Google’s “search box”. You can also enforce the restriction using Google’s “ad-
vanced search” mechanism; other search engines (presumably) have similar facilities.
Many people avoid the need to go over the network at all, for their searches, by
downloading the file list that the archives’ web file searches use. This file, FILES.
byname, presents a unified listing of the archive (omitting directory names and cross-
links). Its companion FILES.last07days is also useful, to keep an eye on the changes
on the archive. Since these files are updated only once a day, a nightly automatic
download (perhaps using rsync) makes good sense.
FILES.byname: FILES.byname
FILES.last07days: FILES.last07days
F TeX Systems
68 (La)TeX for different machines
We list here the free or shareware packages; see for details of commercial packages.
Unix Instructions for retrieving the web2c Unix TeX distribution via anonymous ftp
are to be found in unixtex.ftp, though nowadays the sensible installer will take
(and possibly customise) one of the packaged distributions such as teTeX, or the
TeX Live distribution.
To compile and produce a complete teTeX distribution, you need a .tar.gz file
for each of teTeX-src, teTeX-texmf and teTeX-texmfsrc.
No sets of teTeX binaries are provided on CTAN; however, compilation of teTeX
is pretty stable, on a wide variety of platforms. If you don’t have the means to
compile teTeX yourself, you will find that most “support” sites carry compiled
versions in their “free area”, and the TeX-live discs also carry a wide range of
binary distributions.
There’s a mailing list for teTeX installation problems (and the like): subscribe
by sending mail to [email protected] containing nothing more
than “subscribe tetex”. The list is archived at http://www.mail-archive.
com/[email protected]/, and an RSS feed is available at the same
site: http://www.mail-archive.com/[email protected]/maillist.
xml
During periods when teTeX is itself under development, a “teTeX-beta” is avail-
able. Before proceeding with the β -release, check the ANNOUNCE files in the two
directories on CTAN: it may well be that the β -release doesn’t offer you anything
new, that you need.
MacOS X users should refer to the information below, under item “Mac”.
tetex : Browse systems/unix/teTeX/current/distrib
tetex-beta: systems/unix/teTeX-beta
unixtex.ftp: systems/unix/unixtex.ftp
web2c: systems/web2c
Linux Linux users may use teTeX (see above).
The most recent offering is a free version of the commercial VTeX (see VTeX),
which among other things, specialises in direct production of PDF from (La)TeX
input.
tetex : Browse systems/unix/teTeX/current/distrib
vtex : systems/vtex/linux
vtex required common files: systems/vtex/common
PC: Win32 MiKTeX, by Christian Schenk, is also a comprehensive distribution, de-
veloped separately from the teTeX work. It has its own previewer, YAP, which is
itself capable of printing, though the distribution also includes a port of dvips. The
current version is available for file-by-file download (the HTML files in the direc-
tory offer hints on what you need to get going). The MiKTeX developers provide a
ready-to-run copy of the distribution, on CD-ROM (for purchase) via the MiKTeX
web site; otherwise the setup executable is available on CTAN, together with all
the optional packages.
37
ProTeXt, by Thomas Feuerstack, is a further option for installing MiKTeX. It bun-
dles a MiKTeX setup with some further useful utilities, together with a PDF file
which contains clickable links for the various installation steps, along with expla-
nations. It again it is freeware, and copies are distributed with the TeX-live CD
set.
XEmTeX, by Fabrice Popineau (he who created the excellent, but now defunct, fp-
TeX distribution), is an integrated distribution of TeX, LaTeX, ConTeXt, XEmacs
and friends for Windows. All programs have been compiled natively to take the
best advantage of the Windows environment. Configuration is provided so that the
resulting set of programs runs out-of-the-box.
The (Japanese) W32TEX distribution was motivated by the needs of Japanese
users (Japanese won’t fit in a “simple” character set like ASCII, but TeX is based
on a version of ASCII). Despite its origins, W32TEX is said to be a good bet for
Western users, notably those whose disks are short of space: the minimum docu-
mented download is as small as 95 MBytes. Investigate the distribution at http:
//www.fsci.fuk.kindai.ac.jp/kakuto/win32-ptex/web2c75-e.html
A further (free) option arises from the “CygWin” bundle, which presents a Unix-
like environment over the Win32 interface; an X-windows server is available. If
you run CygWin on your Windows machine, you have the option of using teTeX,
too (you will need the X-server, to run xdvi). Of course, teTeX components will
look like Unix applications (but that’s presumably what you wanted), but it’s also
reputedly somewhat slower than native Win32 implementations such as MiKTeX
or XEmTeX. TeTeX is available as part of the CygWin distribution (in the same
way that a version is available with most Linux distributions, nowadays), and you
may also build your own copy from the current sources.
BaKoMa TeX, by Basil Malyshev, is a comprehensive (shareware) distribution,
which focuses on support of Acrobat. The distribution comes with a bunch of
Type 1 fonts packaged to work with BaKoMa TeX, which further the focus.
bakoma: nonfree/systems/win32/bakoma
miktex : Acquire systems/win32/miktex/setup/setup.exe (also available
from the MiKTeX web site), and read installation instructions from the
MiKTeX installation page
protext.exe: systems/texlive/Images/protext.exe
tetex : systems/unix/teTeX/current/distrib
PC: MS-DOS or OS/2 EmTeX, by Eberhard Mattes, includes LaTeX, BibTeX, pre-
viewers, and drivers, and is available as a series of zip archives. Documentation is
available in both German and English. Appropriate memory managers for using
emTeX with 386 (and better) processors and under Windows, are included in the
distribution. EmTeX will operate under Windows, but Windows users are better
advised to use a distribution tailored for the Windows environment.
A version of emTeX, packaged to use a TDS directory structure, is separately avail-
able as an emTeX ‘contribution’. Note that neither emTeX itself, nor emTeXTDS,
is maintained. Most users of Microsoft operating systems, who want an up-to-date
(La)TeX system, need to migrate to Win32-based systems.
emtex : systems/msdos/emtex
emtexTDS : obsolete/systems/os2/emtex-contrib/emtexTDS
PC: MS-DOS The most recent MS-DOS offering is a port of the Web2C 7.0 imple-
mentation, using the GNU djgpp compiler. While this package is more recent than
emTeX, it still implements a rather old instance of (La)TeX.
djgpp: systems/msdos/djgpp
PC: OS/2 OS/2 may also use a free version of the commercial VTeX (see VTeX),
which specialises in direct production of PDF from (La)TeX input.
vtex : systems/vtex/os2
vtex required common files: systems/vtex/common
Windows NT, other platforms Ports of MiKTeX for NT on Power PC and AXP are
available. Neither version has been updated for version 1.2 (or later) of MiK-
TeX — they may not be satisfactory.
miktex for AXP : obsolete/systems/win32/miktex-AXP
38
miktex for Power PC : obsolete/systems/win32/miktexppc
Mac OzTeX, by Andrew Trevorrow, is a shareware version of TeX for the Macintosh.
A DVI previewer and PostScript driver are also included.
UK TUG prepays the shareware fee for its members, so that they may acquire
the software without further payment. Questions about OzTeX may be directed to
[email protected]
Another partly shareware program is CMacTeX, put together by Tom Kiffe. This is
much closer to the Unix TeX setup (it uses dvips, for instance). CMacTeX includes
a port of a version of Omega.
Both OzTeX and CMacTeX run on either MacOS X or on a sufficiently recent
MacOS with CarbonLib (v1.3 for OzTeX, v1.4 for CMacTeX). MacOS X users
also have the option of gwTeX, by Gerben Wierda (which is based on teTeX).
This is naturally usable from the command line, just like any other Unix-based
system, but it can also be used Mac-style as the engine behind Richard Koch’s
(free) TeXShop, which is an integrated TeX editor and previewer.
From its 2005 release, the TeX-Live disc set includes “MacTeX”, a CD-ROM
image that contains MacOS X teTeX (the Gerben Wierda set mentioned above),
TeXshop, and XeTeX. Details (and a downloadable distribution set) may be found
on the TUG web site; the distribution is also on CTAN.
A useful resource for Mac users has a news and ‘help’ section, as well as details
of systems and tools.
cmactex : nonfree/systems/mac/cmactex
mactex : systems/mac/mactex
oztex : nonfree/systems/mac/oztex
MacOS X teTeX : ftp://ftp.nluug.nl/pub/comp/macosx/tex-gs/
TeXShop: http://darkwing.uoregon.edu/~koch/texshop/texshop.html
OpenVMS TeX for OpenVMS is available.
OpenVMS : systems/OpenVMS/TEX97_CTAN.ZIP
Note that the company Y&Y has gone out of business, and Y&Y TeX (and support
for it) is therefore no longer available. Users of Y&Y systems may care to use the self-
help mailing list that was established in 2003; the remaining usable content of Y&Y’s
web site is available at http://www.tug.org/yandy/
42
74 DVI previewers
EmTeX for PCs running MS-DOS or OS/2, MiKTeX and XEmTeX for PCs running
Windows and OzTeX for the Macintosh, all come with previewers that can be used on
those platforms. EmTeX’s previewer can also be run under Windows 3.1.
Commercial PC TeX packages (see commercial vendors) have good previewers for
PCs running Windows, or for Macintoshes.
For Unix systems, there is one ‘canonical’ viewer, xdvi. Xdvik is a version of xdvi
using the web2c libraries; it is now built from the same distribution as xdvi. Unix
TeX distributions (such as teTeX) include a version of xdvik using the same version of
web2c as the rest of the distribution.
Alternatives to previewing include
• conversion to ‘similar’ ASCII text (see converting to ASCII) and using a conven-
tional text viewer to look at that,
• generating a PostScript version of your document and viewing it with a Ghostscript-
based previewer (see previewing PostScript files), and
• generating PDF output, and viewing that with Acrobat Reader or one of the sub-
stitutes for that.
xdvi: dviware/xdvi
43
There’s no explicit port of xfig to windows (although it is believed to work under
cygwin with their X-windows system). However, the program jfig is thought by many
to be an acceptable substitute, written in Java.
xfig : graphics/xfig
transfig : graphics/transfig
44
The latexcount script does the same sort of job, in one “step”; being a perl script, it is
in principle rather easily configured (see documentation inside the script). Winedt (see
editors and shells) provides this functionality direct in the Windows environment.
Simply stripping (La)TeX markup isn’t entirely reliable, however: that markup
itself may contribute typeset words, and this could be a problem. The wordcount pack-
age contains a Bourne shell (i.e., typically Unix) script for running a LaTeX file with
a special piece of supporting TeX code, and then counting word indications in the log
file. This is probably as accurate automatic counting as you can get.
detex : support/detex
wordcount: macros/latex/contrib/wordcount
I Literate programming
80 What is Literate Programming?
Literate programming is the combination of documentation and source together in a
fashion suited for reading by human beings. In general, literate programs combine
source and documentation in a single file. Literate programming tools then parse the
file to produce either readable documentation or compilable source. The WEB style of
literate programming was created by D. E. Knuth during the development of TeX.
The “documented LaTeX” style of programming () is regarded by some as a form
of literate programming, though it only contains a subset of the constructs Knuth used.
Discussion of literate programming is conducted in the newsgroup comp.programming.
literate, whose FAQ is stored on CTAN. Another good source of information is
http://www.literateprogramming.com/
Literate Programming FAQ: help/comp.programming.literate_FAQ
81 WEB systems for various languages
TeX is written in the programming language WEB; WEB is a tool to implement the
concept of “literate programming”. Knuth’s original implementation will be in any
respectable distribution of TeX, but the sources of the two tools (tangle and weave),
together with a manual outlining the programming techniques, may be had from CTAN.
CWEB, by Silvio Levy, is a WEB for C programs.
Spidery WEB, by Norman Ramsey, supports many languages including Ada, awk,
and C and, while not in the public domain, is usable without charge. It is now super-
seded by noweb (also by Norman Ramsay) which incorporates the lessons learned in
implementing spidery WEB, and which is a simpler, equally powerful, tool.
FWEB, by John Krommes, is a version for Fortran, Ratfor, and C.
SchemeWEB, by John Ramsdell, is a Unix filter that translates SchemeWEB into
LaTeX source or Scheme source.
APLWEB is a version of WEB for APL.
FunnelWeb is a version of WEB that is language independent.
Other language independent versions of WEB are nuweb (which is written in ANSI
C).
Tweb is a WEB for Plain TeX macro files, using noweb.
aplweb: web/apl/aplweb
cweb: web/c_cpp/cweb
funnelweb: web/funnelweb
fweb: web/fweb
noweb: web/noweb
nuweb: web/nuweb
schemeweb: web/schemeweb
spiderweb: web/spiderweb
tangle: systems/knuth/web
tweb: web/tweb
weave: systems/knuth/web
45
J Format conversions
82 Conversion from (La)TeX to plain text
The aim here is to emulate the Unix nroff , which formats text as best it can for the
screen, from the same input as the Unix typesetting program troff .
Converting DVI to plain text is the basis of many of these techniques; sometimes
the simple conversion provides a good enough response. Options are:
A common problem is the hyphenation that TeX inserts when typesetting something:
since the output is inevitably viewed using fonts that don’t match the original, the
hyphenation usually looks silly.
Ralph Droms provides a txt bundle of things in support of ASCII generation, but
it doesn’t do a good job with tables and mathematics. An alternative is the screen
package.
Another possibility is to use the LaTeX-to-ASCII conversion program, l2a, al-
though this is really more of a de-TeXing program.
The canonical de-TeXing program is detex, which removes all comments and con-
trol sequences from its input before writing it to its output. Its original purpose was
to prepare input for a dumb spelling checker, and it’s only usable for preparing useful
ASCII versions of a document in highly restricted circumstances.
Tex2mail is slightly more than a de-TeXer — it’s a Perl script that converts TeX
files into plain text files, expanding various mathematical symbols (sums, products,
integrals, sub/superscripts, fractions, square roots, . . . ) into “ASCII art” that spreads
over multiple lines if necessary. The result is more readable to human beings than the
flat-style TeX code.
Another significant possibility is to use one of the HTML-generation solutions
(HTML-generation solutions), and then to use a browser such as lynx to dump the
resulting HTML as plain text.
catdvi: dviware/catdvi
crudetype: dviware/crudetype
detex : support/detex
dvi2tty : nonfree/dviware/dvi2tty
l2a: support/l2a
screen.sty : macros/latex209/contrib/misc/screen.sty
tex2mail: support/tex2mail
txt: support/txt
1. Write a free-standing translator in the traditional way, with tools like yacc and lex;
this is hard, in practice, because of the complexity of SGML.
2. Use a specialist language designed for SGML transformations; the best known are
probably Omnimark and Balise. They are expensive, but powerful, incorporating
SGML query and transformation abilities as well as simple translation.
46
3. Build a translator on top of an existing SGML parser. By far the best-known (and
free!) parser is James Clark’s nsgmls, and this produces a much simpler output
format, called ESIS, which can be parsed quite straightforwardly (one also has the
benefit of an SGML parse against the DTD). Two good public domain packages
use this method:
• David Megginson’s sgmlspm, written in Perl 5.
• Joachim Schrod and Christine Detig’s STIL, (‘SGML Transformations in
Lisp’).
Both of these allow the user to write ‘handlers’ for every SGML element, with
plenty of access to attributes, entities, and information about the context within
the document tree.
If these packages don’t meet your needs for an average SGML typesetting job, you
need the big commercial stuff.
Since HTML is simply an example of SGML, we do not need a specific system for
HTML. However, Nathan Torkington developed html2latex from the HTML parser in
NCSA’s Xmosaic package. The program takes an HTML file and generates a LaTeX
file from it. The conversion code is subject to NCSA restrictions, but the whole source
is available on CTAN.
Michel Goossens and Janne Saarela published a very useful summary of SGML,
and of public domain tools for writing and manipulating it, in TUGboat 16(2).
html2latex source: support/html2latex
47
TeXpider a commercial program from MicroPress (see Micropress), which is de-
scribed on http://www.micropress-inc.com/webb/wbstart.htm; it uses
bitmaps for equations.
Hevea a compiled program that supports LaTeX only, and uses the font/table tech-
nique for equations (indeed its entire approach is very similar to TtH). It is writ-
ten in Objective CAML by Luc Maranget. Hevea isn’t archived on CTAN; de-
tails (including download points) are available via http://pauillac.inria.fr/
~maranget/hevea/
An interesting set of samples, including conversion of the same text by the four
free programs listed above, is available at http://www.mayer.dial.pipex.com/
samples/example.htm; a linked page gives lists of pros and cons, by way of compar-
ison.
The World Wide Web Consortium maintains a list of “filters” to HTML, with
sections on (La)TeX and BibTeX — see http://www.w3.org/Tools/Word_proc_
filters.html
latex2html: Browse support/latex2html
tex4ht: support/TeX4ht/tex4ht-all.zip
tth: nonfree/support/tth/dist/tth_C.tgz
85 Other conversions to and from (La)TeX
troff Tr2latex, assists in the translation of a troff document into LaTeX 2.09 format. It
recognises most -ms and -man macros, plus most eqn and some tbl preprocessor
commands. Anything fancier needs to be done by hand. Two style files are pro-
vided. There is also a man page (which converts very well to LaTeX. . . ). Tr2latex
is an enhanced version of the earlier troff-to-latex (which is no longer available).
WordPerfect wp2latex has recently been much improved, and is now available either
for MS-DOS or for Unix systems, thanks to its current maintainer Jaroslav Fojtik.
PC-Write pcwritex.arc is a print driver for PC-Write that “prints” a PC-Write V2.71
document to a TeX-compatible disk file. It was written by Peter Flynn at University
College, Cork, Republic of Ireland.
runoff Peter Vanroose’s rnototex conversion program is written in VMS Pascal. The
sources are distributed with a VAX executable.
refer/tib There are a few programs for converting bibliographic data between BibTeX
and refer/tib formats. The collection includes a shell script converter from BibTeX
to refer format as well. The collection is not maintained.
RTF Rtf2tex, by Robert Lupton, is for converting Microsoft’s Rich Text Format to
TeX. There is also a convertor to LaTeX by Erwin Wechtl, called rtf2latex. The
latest converter, by Ujwal Sathyam and Scott Prahl, is rtf2latex2e; this system
seems rather good already, and is still being improved.
Translation to RTF may be done (for a somewhat constrained set of LaTeX doc-
uments) by TeX2RTF, which can produce ordinary RTF, Windows Help RTF (as
well as HTML, conversion to HTML). TeX2RTF is supported on various Unix
platforms and under Windows 3.1
Microsoft Word A rudimentary (free) program for converting MS-Word to LaTeX
is wd2latex, which runs on MS-DOS. Word2TeX and TeX2Word are shareware
translators from Chikrii Softlab; users’ reports are very positive.
If cost is a constraint, the best bet is probably to use an intermediate format such
as RTF or HTML. Word outputs and reads both, so in principle this route may be
useful.
Another, unlikely, intermediate form is PDF: Acrobat Reader for Windows (ver-
sion 5.0 and later) will output rather feeble RTF that Word can read.
Excel Excel2Latex converts an Excel file into a LaTeX tabular environment; it comes
as a .xls file which defines some Excel macros to produce output in a new format.
Wilfried Hennings’ FAQ, which deals specifically with conversions between TeX-
based formats and word processor formats, offers much detail as well as tables that
allow quick comparison of features.
A group at Ohio State University (USA) is working on a common document format
based on SGML, with the ambition that any format could be translated to or from
this one. FrameMaker provides “import filters” to aid translation from alien formats
(presumably including TeX) to FrameMaker’s own.
48
excel2latex : support/excel2latex/xl2latex.zip
pcwritex.arc: support/pcwritex
refer and tib tools: biblio/bibtex/utils/refer-tools
rnototex : support/rnototex
rtf2latex : support/rtf2latex
rtf2latex2e: support/rtf2latex2e
rtf2tex : support/rtf2tex
tex2rtf : support/tex2rtf
tr2latex : support/tr2latex
wd2latex : dviware/wd2latex
wp2latex : support/wp2latex
Word processor FAQ (source): help/wp-conv
86 Using TeX to read SGML or XML directly
This can nowadays be done, with a certain amount of clever macro programming.
David Carlisle’s xmltex is the prime example; it offers a practical solution to typesetting
XML files.
One use of a TeX that can typeset XML files is as a backend processor for XSL
formatting objects, serialized as XML. Sebastian Rahtz’s PassiveTeX uses xmltex to
achieve this end.
xmltex : macros/xmltex/base
passivetex : macros/xmltex/contrib/passivetex
51
91 Installing MiKTeX “known packages”
MiKTeX 2.1 (and later) maintains a database of packages it “knows about”, together
with (coded) installation instructions that enable it to install the packages with minimal
user intervention.
If MiKTeX does know about a package you need installed, it’s worth using the
system.
First, open the MiKTeX packages window: click on Start→Programs→MiKTeX→
MiKTeX Options, and select the Packages tab.
On the tab, there is an Explorer-style display of packages. Right-click on the root
of the tree, “MiKTeX Packages”, and select “Search”: enter the name of the package
you’re interested in, and press the “Search” button. If MiKTeX knows about your
package, it will open up the tree to show you a tick box for your package: check that
box.
If you prefer a command-line utility, there’s mpm. Open a command shell, and
type:
mpm --install=<package>
(which of course assumes you know the name by which MiKTeX refers to your pack-
age).
If MiKTeX doesn’t know about the package you’re interested in, you have to use
the long-winded procedure outlined elsewhere in this FAQ.
If necessary, repeat to select other packages, and then press “OK”; MiKTeX tells you
how many packages you have selected — if you’re happy, press “OK” again. MiKTeX
will go off, download the package (as a .cab file), if necessary, install the files of the
package, and then refresh the filename database so that the files will be found.
92 “Temporary” installation of (La)TeX files
Operating systems and applications need to know where to find files: many files that
they need are “just named” — the user doesn’t necessarily know where they are, but
knows to ask for them. The commonest case, of course, is the commands whose names
you type to a shell (yes, even Windows’ “MS-DOS prompt”) are using a shell to read
what you type: many of the commands simply involve loading and executing a file, and
the PATH variable tells the shell where to find those files.
Modern TeX implementations come with a bunch of search paths built in to them.
In most circumstances these paths are adequate, but one sometimes needs to extend
them to pick up files in strange places: for example, we may wish to try a new bundle
of packages before installing them ‘properly’ (installing them ‘properly’). To do this,
we need to change the relevant path as TeX perceives it. However, we don’t want to
throw away TeX’s built-in path (all of a sudden, TeX won’t know how to deal with all
sorts of things).
To extend a TeX path, we define an operating system environment variable in ‘path
format’, but leaving a gap which TeX will fill with its built-in value for the path. The
commonest case is that we want to place our extension in front of the path, so that our
new things will be chosen in preference, so we leave our ‘gap to be filled’ at the end of
the environment variable. The syntax is simple (though it depends which shell you’re
actually using): so on a Unix-like system, using the bash shell, the job might be done
like:
export TEXINPUTS=/tmp:
while in a Windows system, within a MS-DOS window, it would be:
set TEXINPUTS=C:/temp;
In either case, we’re asking TeX to load files from the root disc temporary files direc-
tory; in the Unix case, the “empty slot” is designated by putting the path separator ‘:’
on its own at the end of the line, while in the Windows case, the technique is the same,
but the path separator is ‘;’.
Note that in either sort of system, the change will only affect instances of TeX that
are started from the shell where the environment variable was set. If you run TeX from
another window, it will use the original input path. To make a change of input path
that will “stick” for all windows, set the environment variable in your login script or
profile (or whatever) in a Unix system and log out and in again, or in autoexec.bat
in a Windows system, and reboot the system.
52
While all of the above has talked about where TeX finds its macro files, it’s appli-
cable to pretty much any sort of file any TeX-related program reads — there are lots
of these paths, and of their corresponding environment variables. In a web2c-based
system, the copious annotations in the texmf.cnf system configuration file help you
to learn which path names correspond to which type of file.
93 “Private” installations of files
It sometimes happens that you need a new version of some macro package or font,
but that the machine you use is maintained by someone who’s unwilling to update
and won’t give you privileges to do the job yourself. A “temporary” installation is
sometimes the correct approach, but if there’s the slightest chance that the installation
will be needed on more than one project, temporary installations aren’t right.
In circumstances where you have plenty of quota on backed-up media, or adequate
local scratch space, the correct approach is to create a private installation of (La)TeX
which includes the new stuff you need; this is the ideal, but is not generally possible.
So, since you can’t install into the public texmf tree, you have to install into a
texmf of your own; fortunately, the TDS standard allows for this, and teTeX 2.0 ac-
tually makes provision for it, defining an internal variable HOMETEXMF which points
to the directory $HOME/texmf. (TeTeX 1.0 had the definition, but suppressed it with
comment markers.)
So, install your new package (or whatever) in the correct place in a tree based on
$HOME/texmf, and generate an index of that tree
texhash $HOME/texmf
(the argument specifies which tree you are indexing: it’s necessary since you don’t, by
hypothesis, have access to the main tree, and texhash without the argument would try
to write the main tree.
There are two wrinkles to this simple formula: first, the installation you’re using
may not define HOMETEXMF (teTeX 1.0 didn’t, for example), and second, there may be
some obstruction to using $HOME/texmf as the default name. In either case, a good
solution is to have your own texmf.cnf — an idea that sounds more frightening that
it actually is. The installation’s existing file may be located with the command:
kpsewhich texmf.cnf
Take a copy of the file and put it into a directory of your own; this could be any di-
rectory, but an obvious choice is the web2c directory of the tree you want to create,
i.e., $HOME/texmf/web2c or the like. Make an environment variable to point to this
directory:
TEXMFCNF=$HOME/texmf/web2c
export TEXMFCNF
TEXMF = !!$TEXMFMAIN
but, as teTeX 1.0 is distributed, there are several alternative settings behind comment
markers (“%”), and the person who installed your system may have left them there.
Whatever, you need to modify the line that’s in effect: change the above to three lines:
HOMETEXMF = $HOME/texmf
TEXMF = {$HOMETEXMF,!!$TEXMFMAIN}
% TEXMF = !!$TEXMFMAIN
the important point being that $HOMETEXMF must come before whatever was there be-
fore, inside the braces. For example, if the original was
TEXMF = {!!$LOCALTEXMF,!!$TEXMFMAIN}
53
it should be converted to:
HOMETEXMF = $HOME/texmf
TEXMF = {$HOMETEXMF,!!$LOCALTEXMF,!!$TEXMFMAIN}
% TEXMF = {!!$LOCALTEXMF,!!$TEXMFMAIN}
• Acquire the font. A very small set of Type 1 fonts is installed in most PostScript
printers you will encounter. For those few (whose use is covered by the basic
PSNFSS package), you don’t need the Type 1 font itself, to be able to print using
the font.
55
For all the myriad other Type 1 fonts, to be able to print using the font you need the
Type 1 file itself. Some of these are available for free (they’ve either been donated
to the public domain, or were developed as part of a free software project), but the
vast majority are commercial products, requiring you to spend real money.
• Acquire the fonts’ AFM files. AFM files contain information from the font
foundry, about the sizes of the characters in the font, and how they fit together.
One measure of the quality of a font-supplier is that they provide the AFM files
by default: if the files are not available, you are unlikely to be able to use the font
with (La)TeX.
• Rename the AFM files and the Type 1 files to match the Berry font naming scheme.
• Generate TeX metric files from the AFM files. The commonest tool for this task
is fontinst; the package documentation helps, but other guides are available (see
below). The simplest possible script to pass to fontinst is:
\latinfamily{xyz}{}
\bye
where xyz is the Berry name of the font family. This simple script is adequate
for most purposes: its output covers the font family in both T1 and OT1 font
encodings. Nevertheless, with fancier fonts, more elaborate things are possible
with fontinst: see the documentation for details.
Fontinst also generates map files, and LaTeX font definition (.fd) files.
• Install the files, in your texmf tree. All the strictures about installing non-standard
things apply here: be sure to put the files in the local tree. The list gives reasonable
destinations for the various files related to a font whose Berry name is hbnamei:
.pfb,
.pfa .../fonts/type1/<foundry>/<bname>
.tfm .../fonts/tfm/<foundry>/<bname>
.vf .../fonts/vf/<foundry>/<bname>
.fd .../tex/latex/fontinst/<foundry>/<bname>
The irregular things being .map files: in teTeX 3.0 and later, these should be placed
according to the revised TDS as
.map .../fonts/map/dvips/<foundry>
and in other (earlier) systems as
.map .../dvips/fontinst/<foundry>
• Regenerate the file indexes (as described in package installation).
• Update the dvips and other maps:
– On a teTeX system earlier than version 2.0, edit the file $TEXMF/dvips/
config/updmap and insert an absolute path for the lm.map just after the line
that starts extra_modules=" (and before the closing quotes).
– On a teTeX version 2.0 (or later), execute the command
updmap --enable Map <xyz>.map
– On a MiKTeX system earlier than version 2.2, the “Refresh filename database”
operation, which you performed after installing files, also updates the system’s
“PostScript resources database”.
– On a MiKTeX system, version 2.2 or later, update updmap.cfg which is
described in MiKTeX online documentation. Then execute the command
initexmf --mkmaps, and the job is done.
The whole process is very well (and thoroughly) described in Philipp Lehman’s guide
to font installation, which may be found on CTAN.
fontinst.sty : fonts/utilities/fontinst
Type 1 installation guide: info/Type1fonts/fontinstallationguide/
fontinstallationguide.pdf
56
L Fonts
L.1 MetaFont fonts
99 Getting MetaFont to do what you want
MetaFont allows you to create your own fonts, and most TeX users will never need
to use it. MetaFont, unlike TeX, requires some customisation: each output device for
which you will be generating fonts needs a mode associated with it. Modes are defined
using the mode_def convention described on page 94 of The MetaFontbook (see TeX-
related books). You will need a file, which conventionally called local.mf, containing
all the mode_defs you will be using. If local.mf doesn’t already exist, Karl Berry’s
collection of modes (modes.mf) is a good starting point (it can be used as a ‘local.mf’
without modification in a ‘big enough’ implementation of MetaFont). Lists of settings
for various output devices are also published periodically in TUGboat (see TUG). Now
create a plain base file using inimf , plain.mf, and local.mf:
% inimf
This is METAFONT. . .
**plain you type ‘plain’
(output)
*input local you type this
(output)
*dump you type this
Beginning to dump on file plain. . .
(output)
This will create a base file named plain.base (or something similar; for example,
it will be PLAIN.BAS on MS-DOS systems) which should be moved to the directory
containing the base files on your system (note that some systems have two or more
such directories, one for each ‘size’ of MetaFont used).
Now you need to make sure MetaFont loads this new base when it starts up. If
MetaFont loads the plain base by default on your system, then you’re ready to go.
Under Unix (using the default web2c distribution2 ) this does indeed happen, but we
could for instance define a command mf which executes virmf &plain loading the
plain base file.
The usual way to create a font with plain MetaFont is to start it with the line
in response to the ‘**’ prompt or on the MetaFont command line. (If <mode name> is
unknown or omitted, the mode defaults to ‘proof’ and MetaFont will produce an out-
put file called <font file name>.2602gf) The <magnification> is a floating point
number or ‘magstep’ (magsteps are defined in The MetaFontbook and The TeXbook).
If mag=<magnification> is omitted, then the default is 1 (magstep 0). For example,
to generate cmr10 at 12pt for an epson printer you would type
mf \mode=epson; mag=magstep 1; input cmr10
Note that under Unix the \ and ; characters must usually be quoted or escaped, so this
would typically look something like
mf ’\mode=epson; mag=magstep 1; input cmr10’
If you don’t have inimf or need a special mode that isn’t in the base, you can put its
commands in a file (e.g., ln03.mf) and invoke it on the fly with the \smode command.
For example, to create cmr10.300gf for an LN03 printer, using the file
% This is ln03.mf as of 1990/02/27
% mode_def courtesy of John Sauter
proofing:=0;
fontmaking:=1;
tracingtitles:=0;
pixels_per_inch:=300;
blacker:=0.65;
• The need to decide which printers to generate fonts for. The broad-brush approach
taken for 300 dpi printers was (more or less) justified back then, given the dom-
inance of certain printer ‘engines’, but nowadays one could not make any such
assumption.
• Given the above, justifying the space taken up by a huge array of bitmap fonts.
Fortunately, (La)TeX distribution technology has put a stop to these arguments: most
(if not all) current distributions generate bitmap fonts as needed, and cache them for
later re-use. The impatient user, who is determined that all bitmap fonts should be
created once and for all, may be supported by scripts such as allcm (distributed with
teTeX, at least; otherwise such a person should consult "the use of MetaFont").
If your output is to a PostScript-capable device, you advised to switch to using
Type 1 versions of the CM fonts. Two free sets are currently available; the older
(bakoma) is somewhat less well produced than the bluesky fonts, which were origi-
nally professionally produced and sold, but were then donated to the public domain
by their originators Y&Y and Bluesky Research, in association with the AMS. Unfor-
tunately, the coverage of the sets is slightly different, but you are advised to use the
bluesky set except when bakoma is for some reason absolutely unavoidable. In recent
years, several other ‘MetaFont’ fonts have been converted to Type 1 format; it’s com-
mon never to need to generate bitmap fonts for any purpose other than previewing (see
“previewing documents with Type 1 fonts”).
bakoma: fonts/cm/ps-type1/bakoma
3 Note that the file name may be transmuted by such operating systems as MS-DOS, which don’t permit
58
bluesky : Browse fonts/cm/ps-type1/bluesky
cm fonts (write-black printers): fonts/cm/pk/pk300.zip
cm fonts (write-white printers): fonts/cm/pk/pk300w.zip
• Convert the DVI file to PostScript and use a PostScript previewer. Some sys-
tems offer this capability as standard, but most people will need to use a separate
previewer such as ghostscript or ghostscript-based viewers such as ghostview or
shareware offering GSview.
• Under Windows on a PC, or on a Macintosh, let Adobe Type Manager display the
fonts (textures, on the Macintosh, works like this). (See commercial suppliers for
details.)
• If you have the PostScript fonts in Type 1 format, use ps2pk or gsftopk (designed
for use with the ghostscript fonts) to make PK bitmap fonts which your previewer
will understand. This can produce excellent results, also suitable for printing with
non-PostScript devices. Check the legalities of this if you have purchased the
fonts.
59
ghostscript: Browse nonfree/support/ghostscript
ghostview : Browse support/ghostscript/gnu/ghostview
gsftopk : fonts/utilities/gsftopk
GSview : Browse nonfree/support/ghostscript/ghostgum
ps2pk : fonts/utilities/ps2pk
xdvi: dviware/xdvi
60
106 Choice of scalable outline fonts
If you are interested in text alone, you can in principle use any of the huge numbers
of text fonts in Adobe Type 1, TrueType or OpenType formats. The constraint is, of
course, that your previewer and printer driver should support such fonts (TeX itself
only cares about metrics, not the actual character programs).
If you also need mathematics, then you are severely limited by the demands that
TeX makes of maths fonts (for details, see the paper by B.K.P. Horn in TUGboat 14(3)).
For maths, then, there are relatively few choices (though the list is at last growing).
There are several font families available that are based on Knuth’s original designs,
and some that complement other commercial text font designs; one set (MicroPress’s
‘informal math’) stands alone. “Free” font families that will support TeX mathematics
include:
Computer Modern (75 fonts — optical scaling) Donald E. Knuth
The CM fonts were originally designed in MetaFont, but are also now available in
scalable outline form. There are commercial as well as public domain versions,
and there are both Adobe Type 1 and TrueType versions. A set of outline versions
of the fonts was developed as a commercial venture by Y&Y and Blue Sky Re-
search; they have since assigned the copyright to the AMS, and the fonts are now
freely available from CTAN. Their quality is such that they have become the de
facto standard for Type 1 versions of the fonts.
AMS fonts (52 fonts, optical scaling) The AMS
This set of fonts offers adjuncts to the CM set, including two sets of symbol fonts
(msam and msbm) and Euler text fonts. These are not a self-standing family, but
merit discussion here (not least because several other families mimic the sym-
bol fonts). Freely-available Type 1 versions of the fonts are available on CTAN.
The eulervm package permits use of the Euler maths alphabet in conjunction with
text fonts that do not provide maths alphabets of their own (for instance, Adobe
Palatino or Minion).
mathpazo version 1.003 (5 fonts) Diego Puga
The Pazo Math fonts are a family of type 1 fonts suitable for typesetting maths in
combination with the Palatino family of text fonts. Four of the five fonts of the
distribution are maths alphabets, in upright and italic shapes, medium and bold
weights; the fifth font contains a small selection of “blackboard bold” characters
(chosen for their mathematical significance). Support under LaTeX 2ε is avail-
able in PSNFSS (PSNFSS); the fonts are licensed under the GPL, with legalese
permitting the use of the fonts in published documents.
Fourier/Utopia (15 fonts) Michel Bovani
Fourier is a family built on Adobe Utopia (which has been released for usage
free of charge by Adobe). The fonts provide the basic Computer Modern set of
mathematical symbols, and add many of the AMS mathematical symbols (though
you are expected to use some from the AMS fonts themselves). There are also
several other mathematical and decorative symbols. The fonts come with a fourier
package for use with LaTeX; text support of OT1 encoding is not provided — you
are expected to use T1.
MathDesign (3 entire families. . . so far) Paul Pichareau
This (very new: first release was in April 2005) set so far offers mathematics fonts
to match Adobe Utopia, URW Garamond and Bitstream Charter (all of which are
separately available, on CTAN, in Type 1 format). There has been a little comment
on these fonts, but none from actual users posted to the public forums. Users,
particularly those who are willing to discuss their experiences, would obviously
be welcome. Browse the CTAN directory and see which you want: there is a
wealth of documentation and examples.
Belleek (3 fonts) Richard Kinch
Belleek is the upshot of Kinch’s thoughts on how MetaFont might be used in the
future: they were published simultaneously as MetaFont source, as Type 1 fonts,
and as TrueType fonts. The fonts act as “drop-in” replacements for the basic Math-
Time set (as an example of “what might be done”).
The paper outlining Kinch’s thoughts, proceeding from considerations of the ‘in-
tellectual’ superiority of MetaFont to evaluations of why its adoption is so limited
61
and what might be done about the problem, is to be found at http://truetex.
com/belleek.pdf (the paper is a good read, but exhibits the problems discussed
in getting good PDF — don’t try to read it on-screen in Acrobat reader).
mathptmx Alan Jeffrey, Walter Schmidt and others.
This set contains maths italic, symbol, extension, and roman virtual fonts, built
from Adobe Times, Symbol, Zapf Chancery, and the Computer Modern fonts. The
resulting mixture is not entirely acceptable, but can pass in many circumstances.
The real advantage is that the mathptm fonts are (effectively) free, and the resulting
PostScript files can be freely exchanged. Support under LaTeX 2ε is available in
PSNFSS.
Computer Modern Bright Free scalable outline versions of these fonts do exist; they
are covered below together with their commercial parallels.
Fonts capable of setting TeX mathematics, that are available commercially, include:
Two other font sets should be mentioned, even though they don’t currently produce
satisfactory output — their author is no longer working on them, and several problems
have been identified:
63
pxfonts set version 1.0 (26 fonts) by Young Ryu
The pxfonts set consists of
• virtual text fonts using Adobe Palatino (or the URW replacement used by
ghostscript) with modified plus, equal and slash symbols;
• maths alphabets using Palatino;
• maths fonts of all symbols in the computer modern maths fonts (cmsy, cmmi,
cmex and the Greek letters of cmr)
• maths fonts of all symbols corresponding to the AMS fonts (msam and msbm);
• additional maths fonts of various symbols.
The text fonts are available in OT1, T1 and LY1 encodings, and TS encoded sym-
bols are also available. The sans serif and monospaced fonts supplied with the
txfonts set (see below) may be used with pxfonts; the txfonts set should be installed
whenever pxfonts are. LaTeX, dvips and PDFTeX support files are included. Doc-
umentation is readily available.
The fonts are licensed under the GPL; use in published documents is permitted.
txfonts set version 3.1 (42 fonts) by Young Ryu
The txfonts set consists of
• virtual text fonts using Adobe Times (or the URW replacement used by
ghostscript) with modified plus, equal and slash symbols;
• matching sets of sans serif and monospace (‘typewriter’) fonts (the sans serif
set is based on Adobe Helvetica);
• maths alphabets using Times;
• maths fonts of all symbols in the computer modern maths fonts (cmsy, cmmi,
cmex and the Greek letters of cmr)
• maths fonts of all symbols corresponding to the AMS fonts (msam and msbm);
• additional maths fonts of various symbols.
The text fonts are available in OT1, T1 and LY1 encodings, and TS encoded sym-
bols are also available. Documentation is readily available.
The fonts are licensed under the GPL; use in published documents is permitted.
Finally, one must not forget:
Proprietary fonts Various sources.
Since having a high quality font set in scalable outline form that works with TeX
can give a publisher a real competitive advantage, there are some publishers that
have paid (a lot) to have such font sets made for them. Unfortunately, these sets are
not available on the open market, despite the likelihood that they’re more complete
than those that are.
We observe a very limited selection of commercial maths font sets; a maths font has to
be explicitly designed for use with TeX, which is an expensive business, and is of little
appeal in other markets. Furthermore, the TeX market for commercial fonts is minute
by comparison with the huge sales of other font sets.
Text fonts in Type 1 format are available from many vendors including Adobe,
Monotype and Bitstream. However, be careful with cheap font “collections”; many of
them dodge copyright restrictions by removing (or crippling) parts of the font programs
such as hinting. Such behaviour is both unethical and bad for the consumer. The fonts
may not render well (or at all, under ATM), may not have the ‘standard’ complement
of 228 glyphs, or may not include metric files (which you need to make TFM files).
TrueType remains the “native” format for Windows. Some TeX implementations
such as TrueTeX use TrueType versions of Computer Modern and Times Maths fonts
to render TeX documents in Windows without the need for additional system software
like ATM. (When used on a system running Windows XP, TrueTeX can also use Type 1
fonts.)
When choosing fonts, your own system environment may not be the only one of
interest. If you will be sending your finished documents to others for further use, you
should consider whether a given font format will introduce compatibility problems.
Publishers may require TrueType exclusively because their systems are Windows-
based, or Type 1 exclusively, because their systems are based on the early popularity
64
of that format in the publishing industry. Many service bureaus don’t care as long as
you present them with a finished print file (PostScript or PDF) for their output device.
CM family collection: Browse fonts/cm/ps-type1/bluesky
AMS font collection: Browse fonts/amsfonts/ps-type1
Belleek fonts: fonts/belleek/belleek.zip
CM-super collection: fonts/ps-type1/cm-super
eulervm.sty and supporting metrics: fonts/eulervm
fourier (including metrics and other support for utopia: fonts/fourier-GUT
hfbright collection: fonts/ps-type1/hfbright
hvmath (free bitmapped version): fonts/micropress/hvmath
Lucida Bright/Math metrics: fonts/psfonts/bh/lucida
Lucida PSNFSS support: macros/latex/contrib/psnfssx/lucidabr
MathDesign collection: fonts/mathdesign
pxfonts: fonts/pxfonts
tmmath (free bitmapped version): fonts/micropress/tmmath
txfonts: fonts/txfonts
utopia fonts: fonts/utopia
\font\foo=nonstdfont
...
\foo
Text set using nonstdfont ...
The name you use (nonstdfont, above) is the name of the .tfm file for the font you
want.
If you want to use an italic version of \foo, you need to use \font again:
\font\fooi=nonstdfont-italic
...
\fooi
Text set using nonstdfont italic...
This is all very elementary stuff, and serves for simple use of fonts. However, there
are wrinkles, the most important of which is the matter of font encodings. Unfortu-
nately, many fonts that have appeared recently simply don’t come in versions using
Knuth’s eccentric font encodings — but those encodings are built into Plain TeX, so
that some macros of Plain TeX need to be changed to use the fonts. LaTeX gets around
65
all these problems by using a “font selection scheme” — this ‘NFSS’ (‘N’ for ‘new’, as
opposed to what LaTeX 2.09 had) carries around with it separate information about the
fonts you use, so the changes to encoding-specific commands happen automagically.
If you only want to use the EC fonts, you can in principle use the ec-plain bundle,
which gives you a version of Plain TeX which you can run in the same way that you
run Plain TeX using the original CM fonts, by invoking tex. (Ec-plain also extends the
EC fonts, for reasons which aren’t immediately clear, but which might cause problems
if you’re hoping to use Type 1 versions of the fonts.)
The font_selection package provides a sort of halfway house: it provides font face
and size, but not family selection. This gives you considerable freedom, but leaves you
stuck with the original CM fonts. It’s a compact solution, within its restrictions.
Other Plain TeX approaches to the problem (packages plnfss, fontch and ofs) break
out of the Plain TeX model, towards the sort of font selection provided by ConTeXt and
LaTeX — font selection that allows you to change family, as well as size and face. The
remaining packages all make provision for using encodings other than Knuth’s OT1.
Plnfss has a rather basic set of font family details; however, it is capable of us-
ing font description (.fd) files created for LaTeX. (This is useful, since most modern
mechanisms for integrating outline fonts with TeX generate .fd files in their process.)
Fontch has special provision for T1 and TS1 encodings, which you select by arcane
commands, such as:
\let\LMTone\relax
\input fontch.tex
for T1.
Ofs seems to be the most thoroughly thought-through of the alternatives, and can
select more than one encoding: as well as T1 it covers the encoding IL2, which is
favoured in the Czech Republic and Slovakia. Ofs also covers mathematical fonts,
allowing you the dubious pleasure of using fonts such as the pxfonts and txfonts.
ec-plain: macros/ec-plain
fontch: macros/plain/contrib/fontch
font_selection: macros/plain/contrib/font_selection
ofs: macros/generic/ofs
plnfss: macros/plain/contrib/plnfss
this will make the fonts the default for all three LaTeX font families (“roman”, “sans-
serif” and “typewriter”). You also need
\usepackage[T1]{fontenc}
if you want to use any of the TS1-encoding symbols. There is no support for using
fonts according to the OT1 encoding.
Latin Modern fonts: fonts/lm
67
M Hypertext and PDF
111 Making hypertext documents from TeX
If you want on-line hypertext with a (La)TeX source, probably on the World Wide Web,
there are four technologies to consider:
The HyperTeX project extended the functionality of all the LaTeX cross-referencing
commands (including the table of contents) to produce \special commands which
are parsed by DVI processors conforming to the HyperTeX guidelines; it provides
general hypertext links, including those to external documents.
The HyperTeX specification says that conformant viewers/translators must recog-
nize the following set of \special commands:
The href, name and end commands are used to do the basic hypertext operations of
establishing links between sections of documents.
Further details are available on http://arXiv.org/hypertex/; there are two
commonly-used implementations of the specification, a modified xdvi and (recent re-
leases of) dvips. Output from the latter may be used in recent releases of ghostscript or
Acrobat Distiller.
112 Making Acrobat PDF documents from (La)TeX
There are three general routes to Acrobat output: Adobe’s original ‘distillation’ route
(via PostScript output), conversion of a DVI file, and the use of a direct PDF gener-
ator such as PDFTeX (see PDFTeX) or MicroPress’s VTeX (which comes both as a
commercial version for Windows PCs, and as a ‘free’ version) for Linux systems).
For simple documents (with no hyper-references), you can either
• process the document in the normal way, produce PostScript output and distill it;
• (on a Windows or Macintosh machine with the appropriate Adobe tools installed)
pass the output through the PDFwriter in place of a printer driver (this route is a
dead end: the PDFwriter cannot create hyperlinks);
• process the document in the normal way and generate PDF direct from the DVI
with dvipdfm; or
• process the document direct to PDF with PDFTeX or VTeX. PDFTeX has the
advantage of availability for a wide range of platforms, VTeX (available com-
mercially for Windows, or free of charge for Linux or OS/2) has wider graphics
capability, dealing with encapsulated PostScript and some in-line PostScript.
To translate all the LaTeX cross-referencing into Acrobat links, you need a La-
TeX package to suitably redefine the internal commands. There are two of these for
LaTeX, both capable of conforming to the HyperTeX specification (see Making hyper-
text documents from TeX): Heiko Oberdiek’s hyperref , and Michael Mehlich’s hyper.
uses a configuration file to determine how it will generate hypertext; it can operate
using PDFTeX primitives, the hyperTeX \specials, or DVI driver-specific \special
commands. Dvips translates the DVI with these \special commands into PostScript
acceptable to Distiller, and dvipdfm has \special commands of its own.
(In practice, almost everyone uses hyperref ; hyper hasn’t been updated since 2000.)
If you use Plain TeX, Eplain macro package can help you create Acrobat documents
with hyper-references (see what is Eplain). It can operate using PDFTeX primitives, or
\special commands for the dvipdfm DVI driver.
68
There is no free implementation of all of Adobe Distiller’s functionality, any but
the very oldest versions of ghostscript provide pretty reliable distillation (but beware
of the problems discussed in dvips output for distillation). In fact, Distiller itself is now
remarkably cheap (for academics at least).
For viewing (and printing) the resulting files, Adobe’s Acrobat Reader is available
for a fair range of platforms; for those for which Adobe’s reader is unavailable, re-
motely current versions of ghostscript combined with ghostview or GSview can display
and print PDF files.
In many circumstances, ghostscript combined with a viewer application is actually
preferable to Acrobat Reader. For example, on Windows Acrobat Reader locks the
.pdf file it’s displaying: this makes the traditional (and highly effective) (La)TeX de-
velopment cycle of “Edit→Process→Preview” become incredibly clumsy — GSview
doesn’t make the same mistake.
Acrobat Reader: browse ftp://ftp.adobe.com/pub/adobe/acrobatreader
dvipdfm : dviware/dvipdfm
ghostscript: Browse nonfree/support/ghostscript
ghostview : Browse support/ghostscript/gnu/ghostview
GSview : Browse nonfree/support/ghostscript/ghostgum
hyper.sty : macros/latex/contrib/hyper
hyperref.sty : macros/latex/contrib/hyperref
It should be noted that Adobe Reader 6 (released in mid-2003, and later versions) does
not exhibit the “fuzziness” that so many of the answers below address. This is of course
good news: however, it will inevitably be a long time before every user in the world
has this (or later) versions, so the remedies below are going to remain for some time to
come.
The problems are also discussed, with practical examples, in Mike Shell’s testflow
package, which these FAQs recommend as a “specialised tutorial.
testflow : macros/latex/contrib/IEEEtran/testflow
69
Our remedy is to use “Adobe Type 1” (Adobe Type 1) versions of the fonts we
need. Since Adobe are in the business of selling Type 1 fonts, Reader was of course
made to deal with them really rather well, from the very beginning.
Of course, if your document uses nothing but fonts that came from Adobe in the
first place — fonts such as Times that appear in pretty much every PostScript printer,
or such as Adobe Sabon that you pay extra for — then there’s no problem.
But most people use Computer Modern to start with, and even those relative so-
phisticates who use something as exotic as Sabon often find themselves using odd
characters from CM without really intending to do so. Fortunately, rather good ver-
sions of the CM fonts are available from the AMS (who have them courtesy of Blue
Sky Research — Blue Sky Research and Y&Y).
Most modern systems have the fonts installed ready to use; and any system installed
less than 3 years ago has a dvips configuration file ‘pdf’ that signals the use of the
CM fonts, and also sets a few other parameters to improve dvips’ output. Use this
configuration as:
dvips -Ppdf myfile -o myfile.ps
This may produce a warning message about failing to find the configuration file:
dvips: warning: no config file for ‘pdf’
or something similar, or about failing to find a font file:
dvips: ! Couldn’t find header file cmr10.pfb
Either of these failures signals that your system doesn’t have the fonts in the first place.
A way of using the fonts that doesn’t involve the sophistication of the -Ppdf mech-
anism is simply to load maps:
dvips -Pcmz -Pamz myfile -o myfile.ps
You may encounter the same warning messages as listed above.
If your system does not have the fonts, it won’t have the configuration file either;
however, it might have the configuration file without the fonts. In either case, you need
to install the fonts (install the fonts).
115 Fuzzy fonts because Ghostscript too old
So you’ve done everything the FAQ has told you that you need, correct fonts properly
installed and appearing in the dvips output, but still you get fuzzy character output after
distilling with ghostscript.
The problem could arise from too old a version of ghostscript, which you may
be using directly, or via a script such as ps2pdf (distributed with ghostscript itself),
dvipdf , or similar. Though ghostscript was capable of distillation from version 5.50,
that version could only produce bitmap Type 3 output of any font other than the funda-
mental 35 fonts (Times, Helvetica, etc.). Later versions added ‘complete’ distillation,
but it wasn’t until version 6.50 that one could rely on it for everyday work.
So, if your PDF output still looks fuzzy in Acrobat Reader, upgrade ghostscript.
The new version should be at least version 6.50, of course, but it’s usually good policy
to go to the most recent version (version 8.12 at the time of writing — 2003).
116 Fonts go fuzzy when you switch to T1
You’ve been having problems with hyphenation, and someone has suggested that you
should use “\usepackage[T1]{fontenc}” to help sort them out. Suddenly you find
that your final PDF has become fuzzy. The problem may arise whether you are using
PostScript output and then distilling it, or you are using PDFTeX for the whole job.
In fact, this is the same problem as most others about the quality of PDF (quality of
PDF): you’ve abandoned your previous setup using Type 1 versions of the CM fonts,
and dvips has inserted Type 3 versions of the EC fonts into your document output. (See
Adobe font types for details of these font types; also, note that the font encoding T1
has nothing directly to do with the font format Type 1).
However, as noted in 8-bit Type 1 fonts, Type 1 versions of CM-like fonts in T1 (or
equivalent) encoding are now available, both as “real” fonts, and as virtual font sets.
One solution, therefore, is to use one of these alternatives.
The alternative is to switch font family altogether, to something like Times (as a no-
thought default) or one of the many more pleasing Adobe-encoded fonts. The default
action of fontinst, when creating metrics for such a font, is to create settings for both
70
OT1 and T1 encodings, so there’s little change in what goes on (at the user level) even
if you have switched to T1 encoding when using the fonts.
117 Characters missing from PDF output
If you’re using Acrobat Distiller to create your PDF output, you may find characters
missing. This may manifest itself as messed-up maths equations (missing “−” signs,
for example), or bits missing from large symbols. Early versions of Distiller used to
ignore character positions 0–31 and 128–159 of every font: Adobe’s fonts never use
such positions, so why should Distiller?
Well, the answer to this question is “because Adobe don’t produce all the world’s
fonts” — fonts like Computer Modern were around before Adobe came on the scene,
and they use positions 0–31. Adobe don’t react to complaints like that in the previous
sentence, but they do release new versions of their programs; and Distiller, since at
least version 4.0, has recognised the font positions it used to shun.
Meanwhile, TeX users with old versions of Distiller need to deal with their fonts.
Dvips comes to our aid: the switch -G1 (“remap characters”), which moves the of-
fending characters out of the way. The PDF configuration file (-Ppdf), recommended
above, includes the switch.
The switch is not without its problems; pre-2003 versions of dvips will apply it
to Adobe fonts as well, causing havoc (havoc), but fortunately that problem is usually
soluble. However, a document using both CM and Adobe-specified fonts is stuck. The
only real solution is either to upgrade dvips, or to spend money to upgrade Distiller.
118 Finding ‘8-bit’ Type 1 fonts
Elsewhere, answers to these FAQs recommend that you use an ‘8-bit’ font to permit
accentuation of inflected languages, and also recommend the use of Type 1 fonts to
ensure that you get good quality PDF. These recommendations used to be contradic-
tory: one could not just “switch” from the free CM fonts to free Cork- (or similarly)
encoded Type 1 fonts. The first approach that started to alleviate these problems, was
the development of virtual fonts that make a good approach to the Cork encoding (see
below). Now, however, we have “true” Type 1 fonts available: as always, we have
an embarrassment of riches with three free alternatives, and one commercial and one
shareware version.
CM-super is an auto-traced set which encompasses all of the T1 and TS1 encodings
as well as the T2* series (the family of encodings that cover languages based on Cyrillic
alphabets). These fonts are pretty easy to install (the installation instructions are clear),
but they are huge: don’t try to install them if you’re short of disc space.
CM-LGC is a similar “super-font” set, but of much more modest size; it covers T1,
TS1 and T2A encodings (as does CM-super, and also covers the LGR encoding (for
typesetting Greek, based on Claudio Beccari’s MetaFont sources). CM-LGC manages
to be small by going to the opposite extreme from CM-super, which includes fonts at
all the sizes supported by the original EC (a huge range); CM-LGC has one font per
font shape, getting other sizes by scaling. There is an inevitable loss of quality inherent
in this approach, but for the disc-space-challenged machine, CM-LGC is an obvious
choice.
Tt2001 is a simple scan of the EC and TC fonts, and has some virtues — it’s no-
ticeably smaller than CM-super while being less stark than CM-LGC.
Latin Modern is produced using the program MetaType1. The Latin Modern set
comes with T1, TS1 LY1 encoded variants (as well as a variant using the Polish QX
encoding); for the glyph set it covers, its outlines seem rather cleaner than those of
CM-super. Latin Modern is more modest in its disc space demands than is CM-super,
while not being nearly as stark in its range of design sizes as is CM-LGC — Latin
Modern’s fonts are offered in the same set of sizes as the original CM fonts. It’s hard
to argue with the choice: Knuth’s range of sizes has stood the test of time, and is one
of the bases on which the excellence of the TeX system rests.
Virtual fonts help us deal with the problem, since they allow us to map “bits of
DVI file” to single characters in the virtual font; so we can create an “é” character by
recreating the DVI commands that would result from the code “\’e”. However, since
this involves two characters being selected from a font, the arrangement is sufficient to
fool Acrobat Reader: you can’t use the program’s facilities for searching for text that
contains inflected characters, and if you cut text from a window that contains such a
71
character, you’ll find something unexpected (typically the accent and the ‘base’ char-
acters separated by a space) when you paste the result. However, if you can live with
this difficulty, virtual fonts are a useful and straightforward solution to the problem.
There are two virtual-font offerings of CM-based 8-bit fonts — the ae (“almost
EC”) and zefonts sets; the zefonts set has wider coverage (though the ae set may be
extended to offer guillemets by use of the aeguill package). Neither offers characters
such as eth and thorn (used in, for example, in Icelandic), but the aecompl package
works with the ae fonts to provide the missing characters from the EC fonts (i.e., as
bitmaps).
The sole remaining commercial CM-like 8-bit font comes from Micropress, who
offer the complete EC set in Type 1 format, as part of their range of outline versions of
fonts that were originally distributed in MetaFont format. See “commercial distribu-
tions”.
The shareware BaKoMa TeX distribution offers a set of Type 1 EC fonts, as an extra
shareware option. (As far as the present author can tell, these fonts are only available
to users of BaKoMa TeX: they are stored in an archive format that seems not to be
publicly available.)
Finally, you can use one of the myriad text fonts available in Type 1 format (with
appropriate PSNFSS metrics for T1 encoding, or metrics for some other 8-bit encoding
such as LY1). However, if you use someone else’s text font (even something as simple
as Adobe’s Times family) you have to find a matching family of mathematical fonts,
which is a non-trivial undertaking — “choice of scalable fonts”.
ae fonts: fonts/ae
aecompl.sty : Distributed with fonts/ae
aeguill.sty : macros/latex/contrib/aeguill
BaKoMa fonts: Browse nonfree/systems/win32/bakoma/fonts
CM-LGC fonts: fonts/ps-type1/cm-lgc
CM-super fonts: fonts/ps-type1/cm-super (beware: very large download)
Latin Modern fonts: fonts/lm
tt2001 fonts: fonts/ps-type1/tt2001
zefonts: fonts/zefonts
119 Replacing Type 3 fonts in PostScript
One often comes across a PostScript file generated by dvips which contains embedded
PK fonts; if you try to generate PDF from such a file, the quality will be poor.
Of course, the proper solution is to regenerate the PostScript file, but if neither the
sources nor the DVI file are available, one must needs resort to some sort of patching
to replace the bitmap fonts in the file by outline fonts.
The program pkfix (by Heiko Oberdiek) will do this patching, for files created by
“not too old versions” of dvips: it finds the fonts to be replaced by examining the
PostScript comments dvips has put in the file. For each font, pkfix puts appropriate
TeX commands in a file, which it then processes and runs through dvips (with switch
-Ppdf) to acquire an appropriate copy of the font; these copies are then patched back
into the original file.
Yet another option is Frank Siegert’s (shareware) PStill, which is capable of pro-
cessing the PostScript it is distilling, and one option is to replace bitmap fonts in the
file with Type 1 versions.
pkfix : support/pkfix
plainpages=false Make page anchors using the formatted form of the page number.
With this option, hyperref writes different anchors for pages ‘ii’ and ‘2’. (If the
72
option is set ‘true’ — the default — hyperref writes page anchors as the arabic
form of the absolute page number, rather than the formatted form.)
pdfpagelabels Set PDF page labels; i.e., write the value of \thepage to the PDF file
so that Acrobat Reader can display the page number as (say) ‘ii (4 of 40)’ rather
than simply ‘4 of 40’.
The two should be used whenever page numbering is not just ‘1..n’; they may be used
independently, but usually are not.
The recipe isn’t perfect: it relies on \thepage being different for every page in the
document. A common problem arises when there is an unnumbered title page, after
which page numbers are reset: the PDFTeX warning of “duplicate destinations” will
happen in this case, regardless of the options.
hyperref.sty : macros/latex/contrib/hyperref
N Graphics
122 How to import graphics into (La)TeX documents
Knuth, when designing the current version of TeX back in the early 1980s, could dis-
cern no “standard” way of expressing graphics in documents. He reasoned that this
state could not persist for ever, but that it would be foolish for him to define TeX prim-
itives that allowed the import of graphical image definitions. He therefore deferred the
specification of the use of graphics to the writers of DVI drivers; TeX documents would
control the drivers by means of \special commands (\special commands).
There is therefore a straightforward way for anyone to import graphics into their
document: read the specification of the \special commands your driver uses, and
‘just’ code them. This is the hair-shirt approach: it definitely works, but it’s not for
everyone.
Over the years, therefore, “graphics inclusion” packages have sprung up; most were
designed for inclusion of Encapsulated PostScript graphics (Encapsulated PostScript
graphics) — which has become the lingua franca of graphics inclusion over the last
decade or so.
Notable examples are the epsf package (distributed with dvips) and the psfig pack-
age. (Both of these packages were designed to work well with both Plain TeX and
LaTeX 2.09; they are both still available.) All such packages were tied to a particu-
lar DVI driver (dvips, in the above two cases), but their code could be configured for
others.
The obvious next step was to make the code configurable dynamically. The LaTeX
standard graphics package and its derivatives made this step: it is strongly preferred
73
for all current work. It can also be used (with the help of the miniltx “LaTeX emulator”
and the graphicx.tex front-end) in documents written in Plain TeX.
The graphics package takes a variety of “driver options” — package options that
select code to generate the commands appropriate to the DVI driver in use. In most
cases, your (La)TeX distribution will provide a graphics.cfg file that will select the
correct driver for what you’re doing (for example, a distribution that provides both
LaTeX and PDFLaTeX will usually provide a configuration file that determins whether
PDFLaTeX is running, and selects the definitions for it if so).
The graphics package provides a toolkit of commands (insert graphics, scale a
box, rotate a box), which may be composed to provide most facilities you need; the
basic command, \includegraphics, takes one optional argument, which specifies
the bounding box of the graphics to be included.
The graphicx package uses the facilities of of graphics behind a rather more sophis-
ticated command syntax to provide a very powerful version of the \includegraphics
command. graphicx’s version can combine scaling and rotation, viewporting and clip-
ping, and many other things. While this is all a convenience (at some cost of syntax),
it is also capable of producing noticeably more efficient PostScript, and some of its
combinations are simply not possible with the graphics package version.
The epsfig package provides the same facilities as graphicx, but via a \psfig com-
mand (also known as \epsfig), capable of emulating the behaviour (if not the bugs)
the old psfig package. Epsfig also supplies homely support for former users of the epsf
package. However, there’s a support issue: if you declare you’re using epsfig, any po-
tential mailing list or usenet helper has to clear out of the equation the possibility that
you’re using “old” epsfig, so that support is slower coming than it would otherwise be.
There is no rational reason to stick with the old packages, which have never been
entirely satisfactory in the LaTeX context. (One irrational reason to leave them be-
hind is that their replacement’s name tends not to imply that it’s exclusively related to
PostScript graphics. The reasoning also excludes epsfig, of course.)
A wide variety of detailed techniques and tricks have been developed over the years,
and Keith Reckdahl’s epslatex outlines them in compendious detail: this highly recom-
mendable document is available from CTAN. An invaluable review of the practicalities
of exchanging graphics between sites, “Graphics for Inclusion in Electronic Docu-
ments” has been written by Ian Hutchinson; the document isn’t on CTAN, but may
also be browsed on the Web.
epsf.tex : macros/generic/epsf/epsf.tex
epsfig.sty : Part of the macros/latex/required/graphics bundle
epslatex.pdf : info/epslatex/english/epslatex.pdf; the document is also
available in PostScript format as info/epslatex/english/epslatex.ps
graphics.sty : macros/latex/required/graphics
graphicx.sty : Part of the macros/latex/required/graphics bundle
miniltx.tex : macros/plain/graphics
psfig.sty : nonfree/graphics/psfig
74
Bmeps comes with patches to produce your own version of dvips that can cope
with JPEG and PNG direct, using bmeps’s conversion library. Dvips, as distributed by
MiKTeX, comes with those patches built-in.
a2ping : graphics/a2ping
bmeps: support/bmeps
jpeg2ps: nonfree/support/jpeg2ps
sam2p: graphics/sam2p
75
Unfortunately, “ordinary” LaTeX can’t deduce the bounding box of a binary bitmap
file (such as JPEG or PNG), so you have to specify the bounding box. This may be
done explicitly, in the document:
\usepackage[dvipdfm]{graphicx}
...
\includegraphics[bb=0 0 540 405]{photo.jpg}
It’s usually not obvious what values to give the “bb” key, but the program ebb will
generate a file containing the information; the above numbers came from an ebb output
file photo.bb:
%%Title: /home/gsm10/photo.jpg
%%Creator: ebb Version 0.5.2
%%BoundingBox: 0 0 540 405
%%CreationDate: Mon Mar 8 15:17:47 2004
However, if such a file is available, you may abbreviate the inclusion code, above, to
read:
\usepackage[dvipdfm]{graphicx}
...
\includegraphics{photo}
which makes the operation feel as simple as does including .eps images in a LaTeX
file for processing with dvips; the graphicx package knows to look for a .bb file if no
bounding box is provided in the \includegraphics command.
The one place where usage isn’t quite so simple is the need to quote dvipdfm ex-
plicitly, as an option when loading the graphicx package: if you are using dvips, you
don’t ordinarily need to specify the fact, since the default graphics configuration file
(of most distributions) “guesses” the dvips option if you’re using TeX.
dvipdfm : dviware/dvipdfm
ebb: Distributed as part of dviware/dvipdfm
TEXINPUTS=.:<graphics path(s)>:
on a Unix system; on a Windows system the separator will be “;” rather than “:”. The
“.” is there to ensure that the current directory is searched first; the trailing “:” says
“patch in the value of TEXINPUTS from your configuration file, here”.
This method has the merit of efficiency ((La)TeX does all of the searches, which is
quick), but it’s always clumsy and may prove inconvenient to use in Windows setups
(at least).
The alternative is to use the graphics package command \graphicspath; this com-
mand is of course also available to users of the graphicx and the epsfig packages. The
syntax of \graphicspath’s one argument is slightly odd: it’s a sequence of paths (typ-
ically relative paths), each of which is enclosed in braces. A slightly odd sample, given
in the graphics bundle documentation, is:
\graphicspath{{eps/}{tiff/}}
however, if the security checks on your (La)TeX system allow, the path may be any-
thing you choose (rather than strictly relative, like those above); note that the trailing
“/” is required.
76
Be aware that \graphicspath does not affect the operations of graphics macros
other than those from the graphics bundle — in particular, those of the outdated epsf
and psfig packages are immune.
The disadvantage of the \graphicspath method is inefficiency. The package will
call (La)TeX once for each entry in the list, which is itself slows things. More seriously,
TeX remembers the file name, thus effectively losing memory, every time it’s asked to
look up a file, so a document that uses a huge number of graphical inputs could be
embarrassed by lack of memory.
If your document is split into a variety of directories, and each directory has its as-
sociated graphics, the import package may well be the thing for you; see the discussion
of “bits of document in other directories” (bits of document in other directories).
graphics bundle: macros/latex/required/graphics
import.sty : macros/latex/contrib/misc/import.sty
and each of the graphics in the list is converted to an “object” for use within the re-
sulting PostScript output. (This is, in essence, an automated version of the epslatex
technique described above.)
Having loaded the package as above, whenever you use \includegraphics, the
command checks if the file you’ve asked for is one of the graphics in \loadgraphics’
list. If so, the operation is converted into a call to the “object” rather than a new copy
of the file; the resulting PostScript can of course be much smaller.
Note that the package requires a recent dvips, version 5.95b (this version isn’t —
yet — widely distributed).
If your PostScript is destined for conversion to PDF, either by a ghostscript-based
mechanism such as ps2pdf or by (for example) Acrobat Distiller, the issue isn’t so
pressing, since the distillation mechanism will amalgamate graphics objects whether or
not the PostScript has them amalgamated. PDFTeX does the same job with graphics,
automatically converting multiple uses into references to graphics objects.
graphicx-psmin.sty : macros/latex/contrib/graphicx-psmin
This defines a “variable” width which has the properties you want. Replace \linewidth
if you have a different constraint on the width of the graphic.
Use the command as follows:
\includegraphics[width=\maxwidth]{figure}
The \vtop primitive sets the base-line of the resulting object to that of the first “line”
in it; the \vskip creates the illusion of an empty line, so \vtop makes the very top of
the box into the base-line.
In cases where the graphics are to be aligned with text, there is a case for making
the base-line one ex-height below the top of the box, as in:
\vtop{%
\vskip-1ex
78
\hbox{%
\includegraphics{figure}%
}%
}
A more LaTeX-y way of doing the job (somewhat innefficiently) uses the calc package:
\usepackage{calc}
...
\raisebox{1ex-\height}{\includegraphics{figure}}
There is provision in MetaPost for avoiding this problem: issue the command
prologues := 2; at the start of the .mp file.
Unfortunately, the PostScript that MetaPost inserts in its output, following this
command, is incompatible with ordinary use of the PostScript in inclusions into
(La)TeX documents, so it’s best to make the prologues command optional. Further-
more, MetaPost takes a very simple-minded approach to font encoding: since TeX font
encodings regularly confuse sophisticated minds, this can prove troublesome. If you’re
suffering such problems (the symptom is that characters disappear, or are wrongly
presented) the only solution is to view the ‘original’ metapost output after processing
through LaTeX and dvips.
Conditional compilation may be done either by inputting MyFigure.mp indirectly
from a simple wrapper MyFigureDisplay.mp:
prologues := 2;
input MyFigure
(which will work without the quote marks if you’re not using a Unix shell).
A suitable LaTeX route would involve processing MyFigure.tex, which contains:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\thispagestyle{empty}
\includegraphics{MyFigure.1}
\end{document}
would then give a satisfactory Encapsulated PostScript file. This procedure may be
automated using the Perl script mps2eps, thus saving a certain amount of tedium.
The Plain TeX user may use an adaptation of a jiffy of Knuth’s, by Dan Luecking.
Dan’s version mpsproof.tex will work under TeX to produce a DVI file for use with
dvips, or under PDFTeX to produce a PDF file, direct. The output is set up to look like
a proof sheet.
A script application, mptopdf , is available in recent (La)TeX distributions: it seems
fairly reliably to produce PDF from MetaPost, so may reasonably be considered an
answer to the question. . .
79
mps2eps: support/mps2eps
mpsproof.tex : graphics/metapost/contrib/misc/mpsproof.tex
• pict2e; this was advertised in the LaTeX manual, but didn’t appear for nearly ten
years after publication of the book! It removes all the petty niggles that surround
the use of the picture environment. It therefore suffers only from the rather ec-
centric drawing language of the environment, and is a far more useful tool than the
original environment has ever been. (Note that pict2e supersedes David Carlisle’s
stop-gap pspicture.)
• pstricks; this gives you access to all the power of PostScript from TeX itself, by
sophisticated use of \special commands. Since PostScript is itself a pretty pow-
erful programming language, this means there are many astounding things that can
in principle be achieved. pstricks’ \specials are by default specific to dvips, but
VTeX (both in its commercial and in its free versions) understands them. PDFTeX
users may use pdftricks, which (like epstopdf — see PDFLaTeX graphics) gen-
erates PDF files on the fly from pstricks commands. The documentation is good
(you may browse it via the pstricks page on the TUG web site). There is also a
mailing list ([email protected]) which you may join, or you may just browse
the list archives.
• pgf : while pstricks is very powerful and convenient, using it with PDFLaTeX is
an awful fidget: if you simply want the graphical capabilities, pgf , together with
its rather pleasing “user-oriented” interface tikz, may be a good bet for you. While
PDF has (in essence) the same graphical capabilities as PostScript, it isn’t pro-
grammable; pgf provides common LaTeX commands that will utilise the graphical
capabilities of both PostScript and PDF equally.
• MetaPost; you liked MetaFont, but never got to grips with font files? Try Meta-
Post — all the power of MetaFont, but it generates PostScript figures; MetaPost
is nowadays part of most serious (La)TeX distributions. Knuth uses it for all his
work. . .
• Mfpic; you liked MetaFont, but can’t understand the language? The package
makes up MetaFont or MetaPost code for you within using familiar-looking TeX
macros. Not quite the full power of MetaPost, but a friendlier interface; of course,
with MetaPost output, the results can be used equally well in either LaTeX or
PDFLaTeX.
• You liked PiCTeX but don’t have enough memory or time? Look at Eitan Gurari’s
dratex, which is as powerful as most other TeX drawing packages, but is an entirely
new implementation, which is not as hard on memory, is much more readable (and
is fully documented).
dratex.sty : graphics/dratex
mfpic: graphics/mfpic
pdftricks.sty : macros/latex/contrib/pdftricks
pspicture.sty : Distributed as part of macros/latex/contrib/carlisle
pgf.sty : graphics/pgf
pict2e.sty : macros/latex/contrib/pict2e
pstricks: graphics/pstricks
tikz.sty : Distributed with graphics/pgf
bids.to.bibtex : biblio/bibtex/utils/bids/bids.to.bibtex
btOOL: biblio/bibtex/utils/btOOL
ebib: biblio/bibtex/utils/ebib
isi2bibtex : biblio/bibtex/utils/isi2bibtex
tex2bib: biblio/bibtex/utils/tex2bib/tex2bib
tex2bib.readme: biblio/bibtex/utils/tex2bib/README
xbibfile: biblio/bibtex/utils/xbibfile
82
written is pretty obscure, and one would not recommend anyone who’s not a confi-
dent programmer to write their own, though minor changes to an existing style may be
within the grasp of many.
If your style isn’t too ‘far out’, you can probably generate it by using the facilities
of the custom-bib bundle. This contains a file makebst.tex, which runs you through a
text menu to produce a file of instructions, with which you can generate your own .bst
file. This technique doesn’t offer entirely new styles of document, but the system’s
“master BibTeX styles” already offer significantly more than the BibTeX standard set.
BibTeX documentation: biblio/bibtex/distribs/doc
makebst.tex : Distributed with macros/latex/contrib/custom-bib
Sometimes you find BibTeX changing the case of a single letter inappropriately. No
matter: the technique can be applied to single letters, as in:
though that does ensure that the capitalisation is not changed. Your BibTeX database
should be a general-purpose thing, not something tuned to the requirements of a par-
ticular document, or to the way you are thinking today.
There’s more on the subject in the BibTeX documentation.
138 Accents in bibliographies
BibTeX not only has a tendency (by default) to mess about with the case of letters in
your bibliography, also makes a hash of accent commands: “ma\~nana” comes out as
“ma nana” (!). The solution is similar: enclose the troublesome sequence in braces, as
“{\~n}”, in this example.
139 ‘String too long’ in BibTeX
The BibTeX diagnostic “Warning–you’ve exceeded 1000, the global-string-size,
for entry foo” usually arises from a very large abstract or annotation included in
the database. The diagnostic usually arises because of an infelicity in the coding of
abstract.bst, or styles derived from it. (One doesn’t ordinarily output annotations
in other styles.)
The solution is to make a copy of the style file (or get a clean copy from
CTAN — biblio/bibtex/utils/bibtools/abstract.bst), and rename it (e.g.,
on a long file-name system, to abstract-long.bst). Now edit it: find function
output.nonnull and
83
Finally, change your \bibliographystyle command to refer to the name of the new
file.
This technique applies equally to any bibliography style: the same change can be
made to any similar output.nonnull function.
If you’re reluctant to make this sort of change, the only way forward is to take the
entry out of the database, so that you don’t encounter BibTeX’s limit, but you may need
to retain the entry because it will be included in the typeset document. In such cases,
put the body of the entry in a separate file:
@article{long.boring,
author = "Fred Verbose",
...
abstract = "{\input{abstracts/long.tex}}"
}
In this way, you arrange that all BibTeX has to deal with is the file name, though it will
tell TeX (when appropriate) to include all the long text.
140 BibTeX doesn’t understand lists of names
BibTeX has a strict syntax for lists of authors’ (or editors’) names in the BibTeX data
file; if you write the list of names in a “natural”-seeming way, the chances are you will
confuse BibTeX, and the output produced will be quite different from what you had
hoped.
Names should be expressed in one of the forms
First Last
Last, First
Last, Suffix, First
falls foul of two of the above rules: a syntactically significant comma appears in an
incorrect place, and ‘\&’ is being used as a name separator. The output of the above
might be something like:
because “John P. Doe & Another Idiot has become the ‘first name’, while “Fred Q.
Bloggs” has become the ‘last name’ of a single person. The example should have been
written:
Some bibliography styles implement clever acrobatics with very long author lists. You
can force truncation by using the pseudo-name “others”, which will usually translate
to something like “et al” in the typeset output. So, if Mr. Bloggs wanted to distract
attention from his co-authors, he would write:
84
@misc{...,
...,
howpublished = "\url{http://...}"
}
A possible alternative approach is to use BibTeX styles other than the standard ones,
that already have URL entry types. Pre-eminent are the natbib styles (plainnat,
unsrtnat and abbrevnat). These styles are extensions of the standard styles, principally
for use with natbib itself, but they’ve acquired URLs and other “modern” entries along
the way. The same author’s custom-bib is also capable of generating styles that honour
URL entries.
Another candidate is the harvard package (if its citation styles are otherwise satis-
factory for you). Harvard bibliography styles all include a “url” field in their specifi-
cation; however, the typesetting offered is somewhat feeble (though it does recognise
and use LaTeX2HTML macros if they are available, to create hyperlinks).
You can also acquire new BibTeX styles by use of Norman Gray’s urlbst system,
which is based on a Perl script that edits an existing BibTeX style file to produce a
new style. The new style thus generated has a webpage entry type, and also offers
support for url and lastchecked fields in the other entry types. The Perl script comes
with a set of converted versions of the standard bibliography styles. Documentation is
distributed as LaTeX source.
Another possibility is that some conventionally-published paper, technical report
(or even book) is also available on the Web. In such cases, a useful technique is some-
thing like:
@techreport{...,
...,
note = "Also available as \url{http://...}"
}
There is good reason to use the url or hyperref packages in this context: BibTeX has a
habit of splitting lines it considers excessively long, and if there are no space characters
for it to use as ‘natural’ breakpoints, BibTeX will insert a comment (‘%’) character . . .
which is an acceptable character in an URL. Any current version of the url or hyperref
package detects this “%–end-of-line” structure in its argument, and removes it.
custom-bib bundle: macros/latex/contrib/custom-bib
harvard.sty : macros/latex/contrib/harvard
hyperref.sty : macros/latex/contrib/hyperref
natbib styles: macros/latex/contrib/natbib
url.sty : macros/latex/contrib/misc/url.sty
urlbst: biblio/bibtex/contrib/urlbst
142 Using BibTeX with Plain TeX
The file btxmac.tex (which is part of the Eplain system) contains macros and docu-
mentation for using BibTeX with Plain TeX, either directly or with Eplain. See the use
of BibTeX for more information about BibTeX itself.
btxmac.tex : macros/eplain/btxmac.tex
eplain system: macros/eplain
143 Reconstructing .bib files
Perhaps you’ve lost the .bib file you generated your document from, or have been sent
a document without one. Or even, you’ve realised the error of building a substantial
document without the benefit of BibTeX. . .
The Perl script, tex2bib makes a reasonable job of regenerating .bib files from
thebibliography environments, provided that the original (whether automatically or
manually generated) doesn’t deviate too far from the “standard” styles.
You are well-advised to check the output of the script. While it will not usually
destroy information, it can quite reasonably mislabel it.
Documentation of the script is to be found in the file tex2bib.readme
tex2bib: biblio/bibtex/utils/tex2bib/tex2bib
tex2bib.readme: biblio/bibtex/utils/tex2bib/README
85
144 BibTeX sorting and name prefixes
BibTeX recognises a bewildering array of name prefixes (mostly those deriving from
European language names); it ignores the prefixes when sorting the bibliography —
you want “Ludwig van Beethoven” sorted under “Beethoven”, not under “van”. (Lam-
port made a witty deliberate mistake with Beethoven’s name, in the first edition of his
LaTeX manual.)
However, a recurring issue is the desire to quote Lord Rayleigh’s publications
(“Lord” isn’t an acceptable prefix), or names from languages that weren’t considered
when BibTeX was designed such as “al-Wakil” (transcribed from the Arabic). What’s
needed is a separate “sort key”, but BibTeX only allows such a thing in citations of
items that have no author or editor.
The solution is to embed the sort key in the author’s name, but to prevent it from be-
ing typeset. Patashnik recommends a command \noopsort (no-output-sortkey), which
is defined and used as follows:
@PREAMBLE{ {\providecommand{\noopsort}[1]{}} }
...
@ARTICLE{Rayleigh1,
AUTHOR = "{\noopsort{Rayleigh}}{Lord Rayleigh}",
...
Note that the “Yu” is the initial, not a complete name. However, BibTeX’s algorithms
will leave you with a citation — slightly depending on the bibliographic style — that
reads: “S. Y. Epifanov and A. A. Vigasin, . . . ”. instead of the intended “S. Yu. Epifanov
and A. A. Vigasin, . . . ”.
One solution is to replace each affected initial by a command that prints the correct
combination. To keep your bibliography portable, you need to add that command to
your bibliography with the @preamble directive:
@preamble{ {\providecommand{\BIBYu}{Yu} } }
@article{epifanov1997,
author = {Epifanov, S. {\BIBYu}. and Vigasin, A. A.},
title = ...
}
If you have many such commands, you may want to put them in a separate file and
\input that LaTeX file in a @preamble directive.
An alternative is to make the transcription look like an accent, from BibTeX’s point
of view. For this we need a control sequence that does nothing:
@article{epifanov1997,
author = {Epifanov, S. {\relax Yu}. and Vigasin, A. A.},
title = ...
}
Like the solution by generating extra commands, this involves tedious extra typing;
which of the two techniques is preferable for a given bibliography will be determined
by the names in it.
\bibliographystyle{plain}
...
Pooh is heroic~\cite{Milne:1926}.
...
Alice struggles~\cite{Carroll:1865}.
...
\bibliography{mybooks}
Note: we have bibliography style plain, above, which is nearly the simplest of the lot: a
sample text, showing the sorts of style choices available, can be found on Ken Turner’s
web site: http://www.cs.stir.ac.uk/~kjt/software/latex/showbst.html
Third: you must process the file.
latex myfile
As LaTeX processes the file, the \bibliographystyle command writes a note of the
style to the .aux file; each \cite command writes a note of the citation to the .aux
file, and the \bibliography command writes a note of which .bib file is to be used,
to the .aux file.
Note that, at this stage, LaTeX isn’t “resolving” any of the citations: at every \cite
command, LaTeX will warn you of the undefined citation, and when the document
finishes, there will be a further warning of undefined references.
Fourth: you must run BibTeX:
bibtex myfile
Don’t try to tell BibTeX anything but the file name: say bibtex myfile.aux (because
you know it’s going to read the .aux file) and BibTeX will blindly attempt to process
myfile.aux.aux.
BibTeX will scan the .aux file; it will find which bibliography style it needs to use,
and will “compile” that style; it will note the citations; it will find which bibliography
files it needs, and will run through them matching citations to entries in the bibliogra-
phy; and finally it will sort the entries that have been cited (if the bibliography style
specifies that they should be sorted), and outputs the resulting details to a .bbl file.
Fifth: you run LaTeX again. It warns, again, that each citation is (still) undefined,
but when it gets to the \bibliography command, it finds a .bbl file, and reads it. As
it encounters each \bibitem command in the file, it notes a definition of the citation.
Sixth: you run LaTeX yet again. This time, it finds values for all the citations, in
its .aux file. Other things being equal, you’re done. . . until you change the file.
If, while editing, you change any of the citations, or add new ones, you need to
go through the process above from steps 3 (first run of LaTeX) to 6, again, before the
document is once again stable. These four mandatory runs of LaTeX make processing
a document with a bibliography even more tiresome than the normal two runs required
to resolve labels.
To summarise: processing to resolve citations requires: LaTeX; BibTeX; LaTeX;
LaTeX.
147 Choosing a bibliography style
A large proportion of people are satisfied with one of Patashnik’s original “standard”
styles, plain, unsrt, abbrv and alpha. However, no style in that set supports the “author-
date” citation style that is popular in many fields; but there are a very large number of
contributed styles available, that do support the format.
(Note that author-date styles arose because the simple and clear citation style that
plain produces is so awkward in a traditional manuscript preparation scenario. How-
ever, TeX-based document production does away with all those difficulties, leaving us
free once again to use the simple option.)
Fortunately, help is at hand, on the Web, with this problem:
87
• a sample text, showing the sorts of style choices available, can be found on Ken
Turner’s web site;
• an excellent survey, that lists a huge variety of styles, sorted into their nominal
topics as well as providing a good range of examples, is the Reed College “Bibli-
ographies in LaTeX”.
Of course, these pages don’t cover everything; the problem the inquisitive user
faces, in fact, is to find what the various available styles actually do. This is best
achieved (if the links above don’t help) by using xampl.bib from the BibTeX documen-
tation distribution: one can get a pretty good feel for any style one has to hand using
this “standard” bibliography. For style my-style.bst, the simple LaTeX document:
\documentclass{article}
\begin{document}
\bibliographystyle{my-style}
\nocite{*}
\bibliography{xampl}
\end{document}
will produce a representative sample of the citations the style will produce. (Because
xampl.bib is so extreme in some of its “examples”, the BibTeX run will also give you
an interesting selection of BibTeX’s error messages. . . )
xampl.bib: biblio/bibtex/distribs/doc/xampl.bib
\usepackage{multibbl}
\newbibliography{bk}
\bibliographystyle{bk}{alpha}
\newbibliography{art}
\bibliographystyle{art}{plain}
...
\cite[pp.~23--25]{bk}{milne:pooh-corner}
...
\cite{art}{einstein:1905}
...
\bibliography{bk}{book-bib}{References to books}
\bibliography{art}{art-bib}{References to articles}
88
(Note that the optional argument of \cite appears before the new tag argument, and
that the \bibliography commands may list more than one .bib file — indeed all
\bibliography commands may list the same set of files.)
The \bibliography data goes into files whose names are htag-namei.aux, so you
will need to run
bibtex bk
bibtex art
after the first run of LaTeX, to get the citations in the correct place.
The multibib package allows you to define a series of “additional topics”, each of
which comes with its own series of bibliography commands. So one might write:
\usepackage{multibib}
\newcites{bk,art}%
{References from books,%
References from articles}
\bibliographystylebk{alpha}
\bibliographystyleart{plain}
...
\citebk[pp.~23--25]{milne:pooh-corner}
...
\citeart{einstein:1905}
...
\bibliographybk{book-bib}
\bibliographyart{art-bib}
Again, as for multibbl, any \bibliography... command may scan any list of .bib
files.
BibTeX processing with multibib is much like that with multibbl; with the above
example, one needs:
bibtex bk
bibtex art
Note that, unlike multibbl, multibib allows a simple, unmodified bibliography (as well
as the “topic” ones).
The bibtopic package allows you separately to cite several different bibliographies.
At the appropriate place in your document, you put a sequence of btSect environ-
ments (each of which specifies a bibliography database to scan) to typeset the separate
bibliographies. Thus, one might have a file diss.tex containing:
\usepackage{bibtopic}
\bibliographystyle{alpha}
...
\cite[pp.~23--25]{milne:pooh-corner}
...
\cite{einstein:1905}
...
\begin{btSect}{book-bib}
\section{References from books}
\btPrintCited
\end{btSect}
\begin{btSect}[plain]{art-bib}
\section{References from articles}
\btPrintCited
\end{btSect}
Note the different way of specifying a bibliographystyle: if you want a different style
for a particular bibliography, you may give it as an optional argument to the btSect
environment.
Processing with BibTeX, in this case, uses .aux files whose names are derived from
the name of the base document. So in this example you need to say:
bibtex diss1
bibtex diss2
89
There is also a command \btPrintNotCited, which gives the rest of the content
of the database (if nothing has been cited from the database, this is equivalent to LaTeX
standard \nocite{*}).
However, the real difference from miltibbl and mltibib is that selection of what
appears in each bibliography section is determined in bibtopic by what’s in the .bib
files.
An entirely different approach is taken by the splitbib package. You provide a
category environment, in the preamble of your document, for each category you want
a separate citation list for. In each environment, you list the \cite keys that you
want listed in each category. The \bibliography command (or, more precisely, the
thebibliograph environment it uses) will sort the keys as requested. (Keys not men-
tioned in a category appear in a “misc” category created in the sorting process.) A
code example appears in the package documentation (a PDF file in the CTAN directory,
see the file list, below).
bibtopic.sty : macros/latex/contrib/bibtopic
multibbl.sty : macros/latex/contrib/multibbl
multibib.sty : macros/latex/contrib/multibib
splitbib.sty : macros/latex/contrib/splitbib
• The package bibentry, which puts slight restrictions on the format of entry that
your .bst file generates, but is otherwise undemanding of the bibliography style.
• The package inlinebib, which requires that you use its inlinebib.bst. Inlinebib
was actually designed for footnote citations: its expected use is that you place a
citation inline as the argument of a \footnote command.
• The package jurabib, which was originally designed for German law documents,
and has comprehensive facilities for the manipulation of citations. The package
comes with four bibliography styles that you may use: jurabib.bst, jhuman.bst
and two Chicago-like ones.
Note that jurabib does the job using LaTeX’s standard footnotes, whereas footbib cre-
ates its own sequence of footnotes. Therefore, in a document which has other footnotes,
it may be advisable to use jurabib (or of course inlinebib), to avoid confusion of foot-
notes and foot-citations.
bibentry.sty : Distributed with macros/latex/contrib/natbib
footbib.sty : macros/latex/contrib/footbib
inlinebib.sty : biblio/bibtex/contrib/inlinebib
jurabib.sty : macros/latex/contrib/jurabib
90
\usepackage[...]{hyperref}
\usepackage[numbers,sort&compress]{natbib}
\usepackage{hypernat}
...
\bibliographystyle{plainnat}
the natbib and hyperref packages will interwork.
cite.sty : macros/latex/contrib/cite
hypernat.sty : macros/latex/contrib/misc/hypernat.sty
hyperref.sty : macros/latex/contrib/hyperref
plainnat.bst: Distributed with macros/latex/contrib/natbib
unsrtnat.bst: Distributed with macros/latex/contrib/natbib
\cite{paper1,*paper2}
appear in the document as a single citation, and appear arranged appropriately in the
bibliography itself. You’re not limited to collapsing just two references. You can mix
“collapsed” references with “ordinary” ones, as in
\cite{paper0,paper1,*paper2,paper3}
Which will appear in the document as 3 citations “[4,7,11]” (say) — citation ‘4’ will
refer to paper 0, ‘7’ will refer to a combined entry for paper 1 and paper 2, and ‘11’
will refer to paper 3.
You need to make a small change to the bibliography style (.bst) file you use; the
mcite package documentation tells you how to do that.
Unfortunately, the revtex system doesn’t play with mcite. As a result, for that (pri-
marily physics-targeted system) you need to play silly games like:
\cite{paper0,paper1,paper3}
\nocite{paper2}
and then edit the .bbl file to merge the two citations, to achieve the effects of mcite.
mcite.sty : macros/latex/contrib/mcite
revtex bundle: macros/latex/contrib/revtex
91
154 Sorting lists of citations
BibTeX has a sorting function, and most BibTeX styles sort the citation list they pro-
duce; most people find this desirable.
However, it is perfectly possible to write a thebibliography environment that
looks as if it came from BibTeX, and many people do so (in order to save time in the
short term).
The problem arises when thebibliography-writers decide their citations need to
be sorted. A common misapprehension is to insert \bibliographystyle{alpha}
(or similar) and expect the typeset output to be sorted in some magical way. BibTeX
doesn’t work that way! — if you write thebibliography, you get to sort its contents.
BibTeX will only sort the contents of a thebibliography environment when it creates
it, to be inserted from a .bbl file by a \bibliography command.
155 Reducing spacing in the bibliography
Bibliographies are, in fact, implemented as lists, so all the confusion about reducing
list item spacing also applies to bibliographies.
If the natbib package ‘works’ for you (it may not if you are using some special-
purpose bibliography style), the solution is relatively simple — add
\usepackage{natbib}
\setlength{\bibsep}{0.0pt}
The savetrees package performs such a patch, among a plethora of space-saving mea-
sures: you can, in principle, suppress all its other actions, and have it provide you a
compressed bibliography only.
mdwlist.sty : Distributed as part of macros/latex/contrib/mdwtools
natbib.sty : macros/latex/contrib/natbib
savetrees.sty : macros/latex/contrib/savetrees
\renewcommand{\bibnumfmt}[1]{#1.}
but if you’re not using such a package, the following internal LaTeX commands, in the
preamble of your document, will do the job:
\makeatletter
\renewcommand*{\@biblabel}[1]{\hfill#1.}
\makeatother
natbib.sty : macros/latex/contrib/natbib
93
O.3 Manipulating whole bibliographies
159 Listing all your BibTeX entries
LaTeX and BibTeX co-operate to offer special treatment of this requirement. The
command \nocite{*} is specially treated, and causes BibTeX to generate bibliogra-
phy entries for every entry in each .bib file listed in your \bibliography statement,
so that after a LaTeX–BibTeX–LaTeX sequence, you have a document with the whole
thing listed.
Note that LaTeX doesn’t produce “Citation ... undefined” or “There were
undefined references” warnings in respect of \nocite{*}. This isn’t a problem
if you’re running LaTeX “by hand” (you know exactly how many times you have to
run things), but the lack might confuse automatic processors that scan the log file to
determine whether another run is necessary.
160 Making HTML of your Bibliography
A neat solution is offered by the noTeX bibliography style. This style produces a .bbl
file which is in fact a series of HTML ‘P’ elements of class noTeX, and which may
therefore be included in an HTML file. Provision is made for customising your bibli-
ography so that its content when processed by noTeX is different from that presented
when it is processed in the ordinary way by (La)TeX.
A thorough solution is offered by bib2xhtml; using it, you make use of one of its
modified versions of many common BibTeX styles, and post-process the output so
produced using a perl script.
A more conventional translator is the awk script bbl2html, which translates the
.bbl file you’ve generated: a sample of the script’s output may be viewed on the web,
at http://rikblok.cjb.net/lib/refs.html
bbl2html.awk : biblio/bibtex/utils/misc/bbl2html.awk
bib2xhtml: biblio/bibtex/utils/bib2xhtml
noTeX.bst: biblio/bibtex/utils/misc/noTeX.bst
94
162 Producing slides
Lamport’s original LaTeX had a separate program (SliTeX) for producing slides; it
dates from the age when colour effects were produced by printing separate slides in
different-coloured inks, and overlaying them, and was just about acceptable back then.
When LaTeX 2ε came along, the reason SliTeX had to be a separate program went
away, and its functionality was supplied by the slides class. While this makes life a
little easier for system administrators, it does nothing for the inferior functionality of
the class: no-one “who knows” uses slides nowadays.
The ‘classic’ alternatives have been seminar and foils (originally known as Foil-
TeX). Both were originally designed to produce output on acetate foils, though subse-
quent work has provided environments in which they can be used with screen projectors
(see below).
The advent of Microsoft PowerPoint (feeble though early versions of it were) has
created a demand for “dynamic” slides — images that develop their content in a more
elaborate fashion than by merely replacing one foil with the next in the way that was
the norm when slides, foils and seminar were designed.
The prosper class builds on seminar to provide dynamic effects and the like; it
retains the ability to provide PDF for a projected presentation, or to print foils for a
foil-based presentation. The add-on package ppr-prv adds “preview” facilities (that
which is commonly called “hand-out printing”). The HA-prosper package, which you
load with prosper, mends a few bugs, and adds several facilities and slide design styles.
The (relatively new) powerdot class is designed as a replacement for prosper and HA-
prosper, co-authored by the author of HA-prosper.
Beamer is a relatively easy-to-learn, yet powerful, class that (as its name implies)
was designed for use with projection displays. It needs the pgf package (for graphics
support), which in turn requires xcolor; while this adds to the tedium of installing
beamer “from scratch”, both are good additions to a modern LaTeX installation.
Beamer has reasonable facilities for producing printed copies of slides.
Talk is another highly functional, yet easy-to-learn class which claims to differ from
the systems mentioned above, such as beamer, in that it doesn’t impose a slide style
on you. You get to specify a bunch of slide styles, and you can switch from one to
the other between slides, as you need. (The class itself provides just the one style, in
the package greybars: the author hopes users will contribute their own styles, based on
greybars.)
Ppower4 (commonly known as pp4) is a Java-based support program that will
postprocess PDF, to ‘animate’ the file at places you’ve marked with commands from
one of the pp4 packages. The commands don’t work on PDF that has come from
dvips output; they work with PDF generated by PDFLaTeX, VTeX LaTeX, or dvipdfm
running on LaTeX output.
Pdfscreen and texpower are add-on pakages that permit dynamic effects in doc-
uments formatted in “more modest” classes; pdfscreen will even allow you to plug
“presentation effects” into an article-class document.
A more detailed examination of the alternatives (including examples of code using
many of them) may be found at Michael Wiedmann’s fine http://www.miwie.org/
presentations/presentations.html
beamer.cls: Download all of macros/latex/contrib/beamer
foils.cls: nonfree/macros/latex/contrib/foiltex
greybars.sty : distributed with macros/latex/contrib/talk
HA-prosper.sty : macros/latex/contrib/ha-prosper
seminar.cls: macros/latex/contrib/seminar
pgf.sty : graphics/pgf
powerdot.cls: macros/latex/contrib/powerdot
pp4: support/ppower4
ppr-prv.sty : macros/latex/contrib/ppr-prv
prosper.cls: macros/latex/contrib/prosper
talk.cls: macros/latex/contrib/talk
texpower : macros/latex/contrib/texpower
95
xcolor.sty : macros/latex/contrib/xcolor
97
it. While (by his own admission) the class doesn’t solve all problems, it seems
well-thought out and supports all current official EU languages (together with a few
non-official languages, such as Catalan, Galician and Serbian).
The alternative to using a separate class is to impose a package on one of the stan-
dard classes. An example, Axel Reichert’s currvita package, has been recommended
to the FAQ team. Its output certainly looks good.
There is also a LaTeX 2.09 package resume, which comes with little but advice
against trying to use it.
currvita.sty : macros/latex/contrib/currvita
curve.cls: macros/latex/contrib/curve
europecv.cls: macros/latex/contrib/europecv
moderncv.cls: macros/latex/contrib/moderncv
resume.sty : obsolete/macros/latex209/contrib/resume/resume.sty
vita.cls: macros/latex/contrib/vita
\newcommand{\ssection}[1]{%
\section[#1]{\centering\normalfont\scshape #1}}
\newcommand{\ssubsection}[1]{%
\subsection[#1]{\raggedright\normalfont\itshape #1}}
and then use \ssection and \ssubsection in place of \section and \subsection.
This isn’t perfect: section numbers remain in bold, and starred forms need a separate
redefinition.
The package sectsty provides an easy-to-use set of tools to do this job, while the
package titlesec has a structured approach based on redefinition of the sectioning and
chapter commands themselves. Titlesec’s approach allows it to offer far more radical
adjustment: its options provide (in effect) a toolbox for designing your own sectioning
commands’ output.
The fncychap package provides a nice collection of customised chapter heading
designs. The anonchap package provides a simple means of typesetting chapter head-
ings “like section headings” (i.e., without the “Chapter” part of the heading); the
tocbibind package provides the same commands, in pursuit of another end. Unfor-
tunately, fncychap is not attuned to the existence of front- and backmatter in book class
documents.
The memoir class includes facilities that match sectsty and titlesec, as well as a bun-
dle of chapter heading styles (including an anonchap-equivalent). The KOMA-script
classes also have sets of tools that provide equivalent functionality, notably format-
ting specifications \partformat, \chapterformat, \sectionformat, . . . , as well as
several useful overall formatting specifications defined in class options.
Finally, the indefatigable Vincent Zoonekynd supplies examples of how to program
alternative chapter heading styles and section heading styles. The web pages are not
useful to users unless they are willing to do their own LaTeX programming.
The documentation of fncychap is distributed as a separate PostScript file.
anonchap.sty : macros/latex/contrib/misc/anonchap.sty
fncychap.sty : macros/latex/contrib/fncychap
KOMA script bundle: macros/latex/contrib/koma-script
99
memoir.cls: macros/latex/contrib/memoir
sectsty.sty : macros/latex/contrib/sectsty
titlesec.sty : macros/latex/contrib/titlesec
tocbibind.sty : macros/latex/contrib/tocbibind
172 Appendixes
LaTeX provides an exceedingly simple mechanism for appendixes: the command
\appendix switches the document from generating sections (in article class) or chap-
ters (in report or book classes) to producing appendixes. Section or chapter numbering
is restarted and the representation of the counter switches to alphabetic. So:
\section{My inspiration}
...
\appendix
\section{How I became inspired}
...
The \appendixpage command adds a separate title “Appendices” above the first ap-
pendix, and \addappheadtotoc adds a similar title to the table of contents. These
simple modifications cover many people’s needs about appendixes.
The package also provides an appendices environment, which provides for fancier
use. The environment is best controlled by package options; the above example would
be achieved by
\usepackage[toc,page]{appendix}
...
\begin{appendices}
...
\end{appendices}
The great thing that the appendices environment gives you, is that once the environ-
ment ends, you can carry on with sections or chapters as before — numbering isn’t
affected by the intervening appendixes.
The package provides another alternative way of setting appendixes, as inferior di-
visions in the document. The subappendices environment allows you to put separate
appendixes for a particular section, coded as \subsections, or for a particular chapter,
coded as \sections. So one might write:
100
\usepackage{appendix}
...
\section{My inspiration}
...
\begin{subappendices}
\subsection{How I became inspired}
...
\end{subappendices}
1 My inspiration
...
1.A How I became inspired
...
2 Developing the inspiration
...
There are many other merry things one may do with the package; the user is referred
to the package documentation for further details.
The memoir class includes the facilities of the appendix package. The KOMA-
script classes offer a \appendixprefix command for manipulating the appearance of
appendixes.
appendix.sty : macros/latex/contrib/appendix
KOMA script bundle: macros/latex/contrib/koma-script
memoir.cls: macros/latex/contrib/memoir
101
175 The style of captions
Changes to the style of captions may be made by redefining the commands that produce
the caption. So, for example, \fnum@figure (which produces the float number for
figure floats) may be redefined, in a package of your own, or between \makeatletter–
\makeatother:
\renewcommand{\fnum@figure}{\textbf{Fig.~\thefigure}}
which will cause the number to be typeset in bold face. (Note that the original def-
inition used \figurename — \figurename.) More elaborate changes can be made
by patching the \caption command, but since there are packages to do the job, such
changes (which can get rather tricky) aren’t recommended for ordinary users.
The float package provides some control of the appearance of captions, though it’s
principally designed for the creation of non-standard floats. The caption and ccaption
(note the double “c”) packages provide a range of different formatting options.
ccaption also provides ‘continuation’ captions and captions that can be placed out-
side of float environments. The (very simple) capt-of package also allows captions
outside a float environment. Note that care is needed when doing things that assume
the sequence of floats (as in continuation captions), or potentially mix non-floating
captions with floating ones.
The memoir class includes the facilities of the ccaption package; the KOMA-script
classes also provide a wide range of caption-formatting commands.
The documentation of caption is available by processing a file manual.tex, which
is created when you unpack caption.dtx
Note that the previously-recommended package caption2 has now been overtaken
again by caption; however, caption2 remains available for use in older documents.
caption.sty : macros/latex/contrib/caption
capt-of.sty : macros/latex/contrib/misc/capt-of.sty
ccaption.sty : macros/latex/contrib/ccaption
float.sty : macros/latex/contrib/float
KOMA script bundle: macros/latex/contrib/koma-script
memoir.cls: macros/latex/contrib/memoir
102
177 Wide figures in two-column documents
Floating figures and tables ordinarily come out the same width as the page, but in two-
column documents they’re restricted to the width of the column. This is sometimes
not good enough; so there are alternative versions of the float environments — in two-
column documents, figure* provides a floating page-wide figure (and table* a page-
wide table) which will do the necessary.
The “*”ed float environments can only appear at the top of a page, or on a whole
page — h or b float placement directives are simply ignored.
Unfortunately, page-wide equations can only be accommodated inside float en-
vironments. You should include them in figure environments, or use the float or
ccaptionpackage to define a new float type.
ccaption.sty : macros/latex/contrib/ccaption
float.sty : macros/latex/contrib/float
103
command between chapters (rather than a mere \clearpage). The empty page thus
created gets to have a normal running header, which some people don’t like.
The (excellent) fancyhdr manual covers this issue, basically advising the creation
of a command \clearemptydoublepage:
\let\origdoublepage\cleardoublepage
\newcommand{\clearemptydoublepage}{%
\clearpage
{\pagestyle{empty}\origdoublepage}%
}
\let\cleardoublepage\clearemptydoublepage
104
The user should be aware that any of these packages are liable to become confused
in the presence of floats: if problems arise, manual adjustment of the floats in the
document is likely to be necessary. It is this difficulty (what’s required in any instance
can’t really be expressed in current LaTeX) that led the author of multicol to suppress
single-column-wide floats.
balance.sty : Distributed as part of macros/latex/contrib/preprint
flushend.sty : Distributed as part of macros/latex/contrib/sttools
multicol.sty : Distributed as part of macros/latex/required/tools
If the hshort titlei is present, it is used both for the table of contents and for the page
heading. The usual answer to people who complain that their title is too big for the
running head is to suggest that they the optional argument.
However, using the same text for the table of contents as for the running head may
also be unsatisfactory: if your chapter titles are seriously long (like those of a Victorian
novel), a valid and rational scheme is to have a shortened table of contents entry, and a
really terse entry in the running head.
One of the problems is the tendency of page headings to be set in capitals (which
take up more space); so why not set headings as written for “ordinary” reading? It’s
not possible to do so with unmodified LaTeX, but the fancyhdr package provides a
command \nouppercase for use in its header (and footer) lines to suppress LaTeX’s
uppercasing tendencies. Classes in the KOMA-script bundle don’t uppercase in the first
place.
In fact, the sectioning commands use ‘mark’ commands to pass information to
the page headers. For example, \chapter uses \chaptermark, \section uses
\sectionmark, and so on. With this knowledge, one can achieve a three-layer struc-
ture for chapters:
\chapter[middling version]{verbose version}
\chaptermark{terse version}
(the first \sectionmark deals with the header of the page the \section command falls
on, and the second deal with subsequent pages; note that here, you need the optional
argument to \section, even if “middling version” is in fact the same text as “long
version”.)
A similar arrangement is necessary even for chapters if the class you’re using is
odd enough that it puts a page header on a chapter’s opening page.
Note that the titlesec package manages the running heads in a completely different
fashion; users of that package should refer to the documentation.
The memoir class avoids all the silliness by providing an extra optional argument
for chapter and sectioning commands, for example:
\section[middling version][terse version]{verbose version}
As a result, it is always possible for users of memoir to tailor the header text to fit, with
very little trouble.
105
fancyhdr.sty : macros/latex/contrib/fancyhdr
KOMA script bundle: macros/latex/contrib/koma-script
memoir.cls: macros/latex/contrib/memoir
titlesec.sty : macros/latex/contrib/titlesec
106
TeX or e-TeX engine, there are two package options (dvipdfm and dvips) which in-
struct geometry which \special commands to use. (Note that the options are ignored
if you are using either PDFLaTeX or VTeX.)
So, the resolution of the problem is to add
\usepackage[dvixxx,...]{geometry}
(where dvixxx is your current favourite DVI driver), and the document will run cor-
rectly with any of LaTeX (whether or not run on VTeX) or PDFLaTeX.
Give the typearea package the pagesize and it will do the same job, for PDFLaTeX
output and PostScript output from LaTeX via dvips.
geometry.sty : macros/latex/contrib/geometry
typearea.sty : Distributed as part of macros/latex/contrib/koma-script
\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}
The environment takes two arguments, and will indent the left and right margins, re-
spectively, by the parameters’ values. Negative values will cause the margins to be
narrowed, so \begin{changemargin}{-1cm}{-1cm} narrows the left and right mar-
gins by 1 centimetre.
Given that TeX can’t do this, how does it work? — well, the environment (which is
a close relation of the LaTeX quote environment) doesn’t change the text width as far
as TeX is concerned: it merely moves text around inside the width that TeX believes
in.
108
The chngpage package provides ready-built commands to do the above; it includes
provision for changing the shifts applied to your text according to whether you’re on
an odd or an even page of a two-sided document. The package’s documentation (in
the file itself) suggests a strategy for changing text dimensions between pages — as
mentioned above, changing the text dimensions within the body of a page may lead to
unpredictable results.
Changing the vertical dimensions of a page is clunkier still: the LaTeX command
\enlargethispage adjusts the size of the current page by the size of its argument.
Common uses are
\enlargethispage{\baselineskip}
\enlargethispage{-\baselineskip}
\renewcommand*{\titlepagestyle}{empty}
\renewcommand*{\pagemark}{}
to have the same effect as the gobble trick, without resetting the page number.
nopageno: macros/latex/contrib/carlisle/nopageno.sty
KOMA script bundle: macros/latex/contrib/koma-script
memoir.cls: macros/latex/contrib/memoir
scrpage2.sty : Distributed as part of macros/latex/contrib/koma-script
109
• Use the fancyhdr or scrpage2 packages, which allow you to customise the style
for initial pages independently of that for body pages.
For example, use fancyhdr commands:
\fancypagestyle{plain}{%
\fancyhf{}%
\renewcommand{\headrulewidth}{0pt}%
\renewcommand{\footrulewidth}{0pt}%
}
and the “empty” page style (invoked by \chapter commands and title pages) will
have no header or footer.
• If you are using either the memoir class or a KOMA-script class, use the techniques
outlined for them in “no page numbers”.
fancyhdr.sty : macros/latex/contrib/fancyhdr
KOMA script bundle: macros/latex/contrib/koma-script
memoir.cls: macros/latex/contrib/memoir
nopageno.sty : macros/latex/contrib/carlisle/nopageno.sty
scrpage2.sty : Distributed as part of macros/latex/contrib/koma-script
110
• If you have a single floating object that is wider than it is deep, and will only
fit on the page in landscape orientation, use the rotating package; this defines
sidewaysfigure and sidewaystable environments which create floats that oc-
cupy a whole page.
Note that rotating has problems in a document that also loads the float package,
which recommended in other answers in these FAQs, for example that on float
placement. The rotfloat package loads rotating for you, and smooths the interac-
tion with float.
• If you have a long sequence of things that need to be typeset in landscape (per-
haps a code listing, a wide tabbing environment, or a huge table typeset using
longtable or supertabular), use the lscape package (or pdflscape if you’re gener-
ating PDF output, whether using PDFLaTeX or dvips and generating PDF from
that). Both packages define an environment landscape, which clears the current
page and restarts typesetting in landscape orientation (and clears the page at the
end of the environment before returning to portrait orientation).
No currently available package makes direct provision for typesetting in both portrait
and landscape orientation on the same page (it’s not the sort of thing that TeX is well
set-up to do). If such behaviour was an absolute necessity, one might use the techniques
described in "flowing text around figures", and would rotate the landscape portion using
the rotation facilities of the graphics package. (Returning from landscape to portrait
orientation would be somewhat easier: the portrait part of the page would be a bottom
float at the end of the landscape section, with its content rotated.)
To set an entire document in landscape orientation, one might use lscape around the
whole document. A better option is the landscape option of the geometry package; if
you also give it dvips or pdftex option, geometry also emits the rotation instructions
to cause the output to be properly oriented. The memoir class has the same facilities,
in this respect, as does geometry.
A word of warning: most current TeX previewers do not honour rotation requests
in DVI files. Your best bet is to convert your output to PostScript or to PDF, and to
view these ‘final’ forms with an appropriate viewer.
geometry.sty : macros/latex/contrib/geometry
graphics.sty : Distributed as part of macros/latex/required/graphics
longtable.sty : Distributed as part of macros/latex/required/tools
lscape.sty : Distributed as part of macros/latex/required/graphics
memoir.cls: macros/latex/contrib/memoir
pdflscape.sty : Distributed with Heiko Oberdiek’s packages macros/latex/
contrib/oberdiek
rotating.sty : macros/latex/contrib/rotating
rotfloat.sty : macros/latex/contrib/rotfloat
supertabular.sty : macros/latex/contrib/supertabular
111
everyshi.sty : Distributed as part of macros/latex/contrib/ms
textpos.sty : macros/latex/contrib/textpos
The 10pt offers a hint to the output routine that the column is stretchable; this will
cause TeX to be more tolerant of the need to stretch while building the page. If you’re
doing this as a temporary measure, cancel the change to \topskip by:
\addtolength{\topskip}{0pt plus-10pt}
as well as resetting \flushbottom. (Note that the 10pt never actually shows up, be-
cause it is overwhelmed when the page is shipped out by the stretchability introduced
by \raggedbottom; however, it could well have an effect if \flushbottom was in
effect.)
An alternative (which derives from a suggestion by Knuth in the TeXbook) is the
package needspace or the memoir class, which both define a command \needspace
whose argument tells it what space is needed. If the space isn’t available, the current
page is cleared, and the matter that needs to be kept together will be inserted on the
new page. For example, if 4 lines of text need to be kept together, the sequence
\par
\needspace{4\baselineskip}
% the stuff that must stay together
<text generating lines 1-4>
% now stuff we don’t mind about
Yet another trick by Knuth is useful if you have a sequence of small blocks of text that
need, individually, to be kept on their own page. Insert the command \filbreak before
each small block, and the effect is achieved. The technique can be used in the case of
sequences of LaTeX-style sections, by incorporating \filbreak into the definition of
a command (as in patching commands). A simple and effective patch would be:
\let\oldsubsubsection=\subsubsection
\renewcommand{\subsubsection}{%
\filbreak
\oldsubsubsection
}
112
While the trick works for consecutive sequences of blocks, it’s slightly tricky to get
out of such sequences unless the sequence is interrupted by a forced page break (such
as \clearpage, which may be introduced by a \chapter command, or the end of the
document). If the sequence is not interrupted, the last block is likely to be forced onto
a new page, regardless of whether it actually needs it.
If one is willing to accept that not everything can be accomplished totally automat-
ically, the way to go is to typeset the document and to check for things that have the po-
tential to give trouble. In such a scenario (which has Knuth’s authority behind it, if one
is to believe the rather few words he says on the subject in the TeXbook) one can decide,
case by case, how to deal with problems at the last proof-reading stage. The alterna-
tives are to insert \clearpage commands as necessary, or to use \enlargethispage.
Supposing you have a line or two that stray: issue the command \enlargethispage
{2\baselineskip} and two lines are added to the page you’re typesetting. It depends
on the document whether this looks impossibly awful or entirely acceptable, but the
command remains a useful item in the armoury.
memoir.cls: macros/latex/contrib/memoir
needspace.sty : macros/latex/contrib/misc/needspace.sty
\usepackage{parallel}
...
\begin{Parallel}{<left-width>}{<right-width}
\ParallelLText{left-text}
\ParallelRText{right-text}
\ParallelPar
...
\end{Parallel}
The parcolumns package can (in principle) deal with any number of columns: the
documentation shows its use with three columns. Usage is rather similar to that of
parallel, though there is of course a “number of columns to specify”:
\usepackage{parcolumns}
...
\begin{parcolumns}[<options>]{3}
\colchunk{<Column 1 text>}
\colchunk{<Column 2 text>}
\colchunk{<Column 3 text>}
\colplacechunks
...
\end{parcolumns}
The hoptionsi can specify the widths of the columns, whether to place rules between
the columns, whether to set the columns sloppy, etc.
The ledpar package is distributed with (and integrated with) the ledmac package.
It provides parallel setting carefully integrated with the needs of a scholarly text, per-
mitting translation, or notes, or both, to be set in parallel with the ‘base’ text of the
document.
ledpar.sty : Distributed with macros/latex/contrib/ledmac
parallel.sty : macros/latex/contrib/parallel
parcolumns.sty : Distributed as part of macros/latex/contrib/sauerj
113
197 Typesetting epigraphs
Epigraphs are those neat quotations that authors put at the start of chapters (or even at
the end of chapters: Knuth puts things at the ends of chapters of the TeXbook).
Typesetting them is a bit of a fiddle, but not impossible to do for yourself. Fortu-
nately, there are two packages that do the job, to some extent; there are also facilities
in the two “big” classes (memoir and koma-script.
The epigraph package defines an \epigraph command, for creating a single epi-
graph (as at the top of a chapter):
and an epigraphs environment, for entering more than one epigraph consecutively, in a
sort of list introduced by \qitem commands:
\begin{epigraphs}
\qitem{What I tell you three times is true}%
{Lewis Carroll}
\qitem{Oh listen do, I’m telling you!}%
{A.A. Milne}
\end{epigraphs}
The \epigraphhead command enables you to place your epigraph above a chapter
header:
\setlength{\unitlength}{1pt}
...
\chapter{The Social Life of Rabbits}
\epigraphhead[<distance>]{%
\epigraph{Oh! My ears and whiskers!}%
{Lewis Carroll}%
}
The hdistancei says how far above the chapter heading the epigraph is to go; it’s ex-
pressed in terms of the \unitlength that’s used in the picture environment; the
package’s author recommends 70pt.
The package also offers various tricks for adjusting the layout of chapter header
(necessary if you’ve found a hugely long quotation for an \epigraphhead), for patch-
ing the bibliography, for patching \part pages, and so on. (Some of these suggested
patches lead you through writing your own package. . . )
The quotchap package redefines chapter headings (in a moderately striking way),
and provides an environment savequotes in which you can provide one (or more)
quotations to use as epigraphs. The facilities seem not as flexible as those of epigraph,
but it’s probably easier to use.
The memoir class offers all the facilities of the epigraph package. The Koma-
script classes have commands \setchapterpreamble and \dictum to provide these
facilities.
epigraph.sty : macros/latex/contrib/epigraph
KOMA script bundle: macros/latex/contrib/koma-script
memoir.cls: macros/latex/contrib/memoir
quotchap.sty : macros/latex/contrib/quotchap
115
201 Setting text ragged right
The trick with typesetting ragged right is to be sure you’ve told the TeX engine “make
this paragraph ragged, but never too ragged”. The LaTeX \raggedright command
(and the corresponding flushleft environment) has a tendency to miss the “never”
part, and will often create ridiculously short lines, for some minor benefit later in the
paragraph. The Plain TeX version of the command doesn’t suffer this failing, but is
rather conservative: it is loath to create too large a gap at the end of the line, but in some
circumstances (such as where hyphenation is suppressed hyphenation is suppressed)
painfully large gaps may sometimes be required.
Martin Schröder’s ragged2e package offers the best of both worlds: it provides
raggedness which is built on the Plain TeX model, but which is easily configurable.
It defines easily-remembered command (e.g., \RaggedRight) and environment (e.g.,
FlushLeft) names that are simply capitalised transformations of the LaTeX kernel
originals. The documentation discusses the issues and explains the signficance of the
various parameters of ragged2e’s operation.
ragged2e.sty : Distributed as part of macros/latex/contrib/ms
\usepackage{verbatim}
...
\verbatiminput{verb.txt}
Another way is to use the alltt environment, which requires the alltt package. The
environment interprets its contents ‘mostly’ verbatim, but executes any (La)TeX com-
mands it finds:
\usepackage{alltt}
...
\begin{alltt}
\input{verb.txt}
\end{alltt}
117
\usepackage{listings}
\lstset{language=C}
...
\begin{document}
\begin{lstlisting}
#include <stdio.h>
These very simple examples may be decorated in a huge variety of ways, and of course
there are other languages in the package’s vocabulary than just C. . .
Most people, advising others on (La)TeX lists, seem to regard listings as the be-all
and end-all on this topic. But there are alternatives, which may be worth considering,
in some situations.
Highlight is attractive if you need more than one output format for your program:
as well as (La)TeX output, highlight will produce (X)HTML, RTF and XSL-FO repre-
sentations of your program listing. Documentation is available on the highlight project
site.
The lgrind system is another well-established pre-compiler, with all the facilities
one might need and a wide repertoire of languages; it is derived from the very long-
established tgrind, whose output is based on Plain TeX
The tiny_c2l system is more recent: users are encouraged to generate their own
driver files for languages it doesn’t already deal with.
The C++2LaTeX system comes with strong recommendations for use with C and
C++.
An extremely simple system is c2latex, for which you write LaTeX source in your C
program comments. The program then converts your program into a LaTeX document
for processing. The program (implicitly) claims to be “self-documenting”.
c2latex : support/c2latex
C++2LaTeX : support/C++2LaTeX-1_1pl1
highlight: support/highlight
lgrind : nonfree/support/lgrind
listings.sty : macros/latex/contrib/listings
tgrind : support/tgrind
tiny_c2l: support/tiny_c2l
118
You can certainly create your own environment for typesetting pseudocode using,
for example, the tabbing or list environments — it’s not difficult, but it may prove
boring. So it’s worth trying the following packages, all designed specifically for type-
setting pseudocode.
The algorithms bundle (which contains packages algorithm and algorithmic, both
of which are needed for ordinary use) has a simple interface and produces fairly nice
output. It provides primitives for statements, which can contain arbitrary LaTeX com-
mands, comments, and a set of iterative and conditional constructs. These primitives
can easily be redefined to produce different text in the output. However, there is no
support for adding new primitives. Typesetting the pseudocode itself is performed in
algorithmic; the algorithms package uses the facilities of the float package to number
algorithms sequentially, enable algorithms to float like figures or tables, and support
including a List of Algorithms in a document’s front matter.
Packages in the algorithmicx bundle are similiar both in concept and output form
to algorithmic but additionally provide support for adding new keywords and altering
the formatting. It provides the algpseudocode package which is (almost) a drop-in
replacement for algorithmic. Another package in the bundle, algpascal, uses Pascal-
like keywords, indents differently from algpseudocode, and puts command arguments
in maths mode instead of text mode. There is no floating environment but algorithmicx,
like algorithmic, is compatible with the algorithm package.
The alg package, like algorithms, offers a floating algorithm environment with all
of the ensuing niceties. alg, however, can caption its floats in a variety of (natural)
languages. In addition, alg unlike algorithms, makes it easy to add new constructs.
The newalg package has a somewhat similar interface to algorithms, but its output
is designed to mimic the rather pleasant typesetting used in the book “Introduction to
Algorithms” by Corman, Leiserson, Rivest and Stein. Unfortunately, newalg does not
support a floating environment or any customisation of the output.
“Bona fide” use of the style of “Introduction to Algorithms” may be achieved with
Cormen’s own clrscode: this is the package as used in the second edition of the book.
Similarly, the style of “Combinatorial Algorithms: Generation, Enumeration and
Search” is supported by the pseudocode package, written by the authors of the book. It
has the common ‘Pascal-like’ style, and has some interesting constructs for what one
thinks of as Pascal blocks.
The algorithm2e is of very long standing, and is widely used and recommended. It
loads the float package to provide the option of floating algorithm descriptions, but you
can always use the “H” option of float to have the algorithm appear “where you write
it”.
The usage of the program package is a little different from that of the other pack-
ages. It typesets programs in maths mode instead of text mode; and linebreaks are
significant. program lacks a floating environment but does number algorithms like alg
and algorithms. Customisation and extension are not supported. Documentation of the
program package (such as it is) appears in a file program.msg in the distribution.
None of the above are perfect. The factors that should influence your choice of
package include the output style you prefer, how much you need to extend or modify
the set of keywords, and whether you require algorithms to float like figures and tables.
algorithm2e.sty : macros/latex/contrib/algorithm2e
algorithmicx bundle: macros/latex/contrib/algorithmicx
algorithms bundle: macros/latex/contrib/algorithms
alg.sty : macros/latex/contrib/alg
clrscode.sty : macros/latex/contrib/clrscode
float.sty : macros/latex/contrib/float
newalg.sty : macros/latex/contrib/newalg
program.sty : macros/latex/contrib/program
pseudocode.sty : macros/latex/contrib/pseudocode
The author of this answer prefers the (rather newer) url package (directly or indi-
rectly); both path and url work well with Plain TeX (though of course, the fancy LaTeX
facilities of url don’t have much place there). (hyperref isn’t available in a version for
use with Plain TeX.)
Documentation of both path and url is in the package files.
hyperref.sty : macros/latex/contrib/hyperref
miniltx.tex : Distributed as part of macros/plain/graphics
path.sty : macros/latex/contrib/misc/path.sty
url.sty : macros/latex/contrib/misc/url.sty
121
210 Zero paragraph indent
The conventional way of typesetting running text has no separation between para-
graphs, and the first line of each paragraph in a block of text indented.
In contrast, one common convention for typewritten text was to have no inden-
tation of paragraphs; such a style is often required for “brutalist” publications such
as technical manuals, and in styles that hanker after typewritten manuscripts, such as
officially-specified dissertation formats.
Anyone can see, after no more than a moment’s thought, that if the paragraph indent
is zero, the paragraphs must be separated by blank space: otherwise it is sometimes
going to be impossible to see the breaks between paragraphs.
The simple-minded approach to zero paragraph indentation is thus:
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}
and in the very simplest text, it’s a fine solution.
However, the non-zero \parskip interferes with lists and the like, and the result
looks pretty awful. The parskip package patches things up to look reasonable; it’s not
perfect, but it deals with most problems.
The Netherlands Users’ Group’s set of classes includes an article equivalent
(artikel3) and a report equivalent (rapport3) whose design incorporates zero para-
graph indent and non-zero paragraph skip.
NTG classes: macros/latex/contrib/ntgclass
parskip.sty : macros/latex/contrib/misc/parskip.sty
122
213 Breaking boxes of text
(La)TeX boxes may not be broken, in ordinary usage: once you’ve typeset something
into a box, it will stay there, and the box will jut out beyond the side or the bottom of
the page if it doesn’t fit in the typeset area.
If you want a substantial portion of your text to be framed (or coloured), the restric-
tion starts to seem a real imposition. Fortunately, there are ways around the problem.
The framed package provides framed and shaded environments; both put their
content into something which looks like a framed (or coloured) box, but which breaks
as necessary at page end. The environments “lose” footnotes, marginpars and head-
line entries, and will not work with multicol or other column-balancing macros. The
memoir class includes the functionality of the framed package.
The boites package provides a breakbox environment; examples of its use may be
found in the distribution, and the package’s README file contains terse documentation.
The environments may be nested, and may appear inside multicols environments;
however, floats, footnotes and marginpars will be lost.
For Plain TeX users, the facilities of the backgrnd package may be useful; this pack-
age subverts the output routine to provide vertical bars to mark text, and the macros are
clearly marked to show where coloured backgrounds may be introduced (this requires
shade, which is distributed as tex macros and device-independent MetaFont for the
shading). The author of backgrnd claims that the package works with LaTeX 2.09, but
there are reasons to suspect that it may be unstable working with current LaTeX.
backgrnd.tex : macros/generic/misc/backgrnd.tex
boites.sty : macros/latex/contrib/boites
framed.sty : macros/latex/contrib/misc/framed.sty
memoir.cls: macros/latex/contrib/memoir
shade.tex : macros/generic/shade
Unfortunately, you have to set secnumdepth back to its usual value (which is 2 in the
standard styles) before you do any ‘section’ which you want to be numbered.
Similar settings are made, automatically, in the LaTeX book class by the \frontmatter
and \backmatter commands.
The value of the counter tocdepth controls which headings will be finally printed
in the table of contents. This normally has to be set in the preamble and is a constant for
the document. The package tocvsec2 package provides a convenient interface to allow
you to change the secnumdepth and/or the tocdepth counter values at any point in the
body of the document; this provides convenient independent controls over the sectional
numbering and the table of contents.
The package abstract (see one-column abstracts) includes an option to add the
abstract to the table of contents, while the package tocbibind has options to include
the table of contents itself, the bibliography, index, etc., to the table of contents.
The KOMA-Script classes have commands \addchap and \addsec, which work
like \chapter and \section but aren’t numbered. The memoir class incorporates the
facilities of all three of the abstract, tocbibind and tocvsec2 packages.
abstract.sty : macros/latex/contrib/abstract
KOMA script bundle: macros/latex/contrib/koma-script
memoir.cls: macros/latex/contrib/memoir
tocbibind.sty : macros/latex/contrib/tocbibind
tocvsec2.sty : macros/latex/contrib/tocvsec2
\bibliography{frooble}
\addcontentsline{toc}{chapter}{Bibliography}
will produce the wrong answer if the bibliography is more than one page long. Instead,
one should say:
\cleardoublepage
\addcontentsline{toc}{chapter}{Bibliography}
\bibliography{frooble}
(Note that \cleardoublepage does the right thing, even if your document is single-
sided — in that case, it’s a synonym for \clearpage). Ensuring that the entry refers to
the right place is trickier still in a \section-based class.
The common solution, therefore, is to use the tocbibind package, which provides
many facilities to control the way these entries appear in the table of contents.
Classes of the KOMA-script bundle provide this functionality as a set of class op-
tions; the memoir class includes tocbibind itself.
KOMA script bundle: macros/latex/contrib/koma-script
memoir.cls: macros/latex/contrib/memoir
tocbibind.sty : macros/latex/contrib/tocbibind
125
221 Table of contents, etc., per chapter
The common style, of a “small” table of contents for each part, chapter, or even section,
is supported by the minitoc package. The package also supports mini-lists of tables
and figures; but, as the documentation observes, mini-bibliographies are a different
problem — see bibliographies per chapter.
The package’s basic scheme is to generate a little .aux file for each chapter, and to
process that within the chapter. Simple usage would be:
\usepackage{minitoc}
...
\begin{document}
...
\dominitoc \tableofcontents
\dominilof \listoffigures
...
\chapter{blah blah}
\minitoc \mtcskip \minilof
...
though a lot of elaborations are possible (for example, you don’t need a \minitoc for
every chapter).
Babel doesn’t know about minitoc, but minitoc makes provision for other document
languages than English — a wide variety is available. Fortunately, the current version
of the hyperref package does know about minitoc and treats \minitoc tables in the
same way as “real” tables of contents.
babel.sty : macros/latex/required/babel
hyperref.sty : macros/latex/contrib/hyperref
minitoc.sty : macros/latex/contrib/minitoc
To complete the job, run LaTeX on your file enough times that labels, etc., are stable,
and then execute the commands
makeindex general
makeindex authors
before running LaTeX again. Note that the names of the index files to process are not
necessarily related to the name of the LaTeX file you’re processing, at all. (There’s no
documentation that comes with the package: what you see above is as good as you will
get. . . )
126
The index package provides a comprehensive set of indexing facilities, including
a \newindex command that allows the definition of new styles of index. \newindex
takes a ‘tag’ (for use in indexing commands), replacements for the .idx and .ind file
extensions, and a title for the index when it’s finally printed; it can also change the item
that’s being indexed against (for example, one might have an index of artists referenced
by the figure number where their work is shown).
Using index, to create an author index together with a “normal” index, one would
start with preamble commands:
\usepackage{index}
\makeindex
\newindex{aut}{adx}{and}{Name Index}
which load the package, define a “main” (original-style) index, and then define an
author index. Then, in the body of the document, we might find commands like:
\index[aut]{Another Idiot}
...
\index{FAQs}
Which place an entry in the author index, and then one in the main index. At the end
of the document, we have two commands:
\printindex
\printindex[aut]
Which will print the main index and then the author index. Supposing this lot to be
in myfile.tex, after enough runs through LaTeX that labels are stable, execute the
following commands (Unix-style shell commands shown here, but the principle is the
same whatever system you’re using):
makeindex myfile
makeindex myfile.adx -o myfile.and
and rerun LaTeX. The makeindex commands process myfile.idx to myfile.ind (the
default action), and then myfile.adx to myfile.and, the two files needed as input by
the two \printindex commands in myfile.tex.
The splitidx package can operate in the same way as the others: load the package
with the split option, and declare each index with a \newindex command:
\newindex[hindex namei]{hshortcuti}
and splitidx will generate a file \jobname.hshortcuti to receive index entries gener-
ated by commands like \sindex[hshortcuti]{hitem i}. As with the other packages,
this method is limited by TeX’s total number of output files. However, splitindex also
comes with a small executable splitindex (available for a variety of operating systems);
if you use this auxiliary program (and don’t use split), there’s no limit to the number
of indexes. Apart from this trick, splitidx supports the same sorts of things as does
index. An example of use appears in the documentation.
The memoir class has its own multiple-index functionality (as well as index layout
options, which other packages delegate to the index style used by makeindex.
index.sty : macros/latex/contrib/index
makeidx.sty : Part of the LaTeX distribution
memoir.cls: macros/latex/contrib/memoir
multind.sty : macros/latex209/contrib/misc/multind.sty
splitidx.sty and splitindex : macros/latex/contrib/splitindex
\documentclass[...]{memoir}
...
\usepackage[...]{hyperref}
\usepackage{memhfixc}
\usepackage{xr}
\externaldocument{volume1}
will load all the references from volume1 into your present document.
But what if the documents both have a section labelled “introduction” (likely
enough, after all)? The package provides a means to transform all the imported labels,
so you don’t have to change label names in either document. For example:
\usepackage{xr}
\externaldocument[V1-]{volume1}
loads the references from volume1, but prefixes every one with the string V1-. So you
would refer to the introduction to volume 1 as:
\usepackage{xr}
\externaldocument[V1-]{volume1}
...
... the introduction to volume1 (\ref{V1-introduction})...
To have the facilities of xr working with hyperref , you need xr-hyper. For simple
hyper-cross-referencing (i.e., to a local PDF file you’ve just compiled), write:
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[V1-]{volume1}
...
... the \nameref{V1-introduction})...
128
and the name reference will appear as an active link to the “introduction” chapter of
volume1.pdf.
To link to a PDF document on the Web, for which you happen to have the .aux file,
write:
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[V1-]{volume1}[http://mybook.com/volume1.pdf]
...
... the \nameref{V1-introduction})...
Q How do I do. . . ?
Q.1 Mathematics
225 Proof environment
It has long been thought impossible to make a proof environment which automatically
includes an ‘end-of-proof’ symbol. Some proofs end in displayed maths; others do not.
If the input file contains ...\] \end{proof} then LaTeX finishes off the displayed
maths and gets ready for a new line before it reads any instructions connected with
ending the proof, so the code is very tricky. You can insert the symbol by hand, but the
ntheorem package now solves the problem for LaTeX users: it does indeed provide an
automatic way of signalling the end of a proof.
The AMSLaTeX package amsthm also provides a proof environment that does the
job; though you need to insert a \qedhere command if the proof ends with a displayed
equation:
\begin{proof}
text...
\begin{equation*}
maths... \tag*{\qedhere}
\end{equation*}
\end{proof}
129
227 Defining a new log-like function in LaTeX
Use the \mathop command, as in:
\newcommand{\diag}{\mathop{\mathrm{diag}}}
Subscripts and superscripts on \diag will be placed below and above the function
name, as they are on \lim. If you want your subscripts and superscripts always placed
to the right, do:
\newcommand{\diag}{\mathop{\mathrm{diag}}\nolimits}
\DeclareMathOperator{\diag}{diag}
\DeclareMathOperator* declares the operator always to have its sub- and super-
scripts in the “\limits position”.
The amsopn command \operatorname allows you to introduce ad hoc opera-
tors into your mathematics; as with \DeclareMathOperator there’s a starred version
\operatorname* for sub- and superscripts in the limits position.
(It should be noted that “log-like” was reportedly a joke on Lamport’s part; it is of
course clear what was meant.)
amsopn.sty : In the AMSLaTeX distribution macros/latex/required/amslatex
to specify the set of even natural numbers. The e-TeX system defines just such a com-
mand, but users of Knuth’s original need some support. Donald Arseneau’s braket
package provides commands for set specifications (as above) and for Dirac brackets
(and bras and kets). The package uses the e-TeX built-in command if it finds itself
running under e-TeX.
braket.sty : macros/latex/contrib/misc/braket.sty
130
The fixed-ratio formula is capable of producing inconvenient results (particularly
if you are using fonts which LaTeX believes are only available in a fixed set of sizes).
You may also want to replace LaTeX’s ideas altogether, for example by setting maths
noticeably larger or smaller than its surrounding text. For this purpose, the LaTeX
command \DeclareMathSizes{htfsi}{htsi}{hssi}{hsssi} may be used (this is the
same command that LaTeX itself uses to define its own set of sizes). This establishes
(or re-establishes) the maths font sizes to be used when the surrounding text font size
is htfsi; (htsi being the size used for \textfont, hssi for \scriptfont and hsssi
for \scriptscriptfont).
For example, you might want to use a font with a smaller body height than Com-
puter Modern, but still prefer CM math to any of the alternatives. In this case, you
might use:
\DeclareMathSizes{10}{9}{7}{5}
to get 9pt maths when the surrounding body text is (nominal) 10pt.
\DeclareMathSizes may only be used in the preamble of the document: only one
association is available for each text font size for the whole document. The default
settings are specified in fontdef.dtx in the latex distribution, and are compiled into
fontmath.ltx; the arguments to the command are just numbers (‘pt’ is assumed), but
some of them are written using LaTeX abbreviations for standard font sizes. Beware
simply copying (parts of) the LaTeX definitions — since they contain those internal
abbreviations, they need to be treated as internal commands.
fontdef.dtx : macros/latex/base/fontdef.dtx
fontmath.ltx : macros/latex/unpacked/fontmath.ltx
231 Ellipses
Ellipses are commonly required, and LaTeX natively supplies a fair range (\dots,
\cdots, \vdots and \ddots). By using the graphics package, one can change the
slope of the \ddots command, as in
$ ... \reflectbox{$\ddots$} ... $
While this works, it is not a recommended way of achieving the desired result (see
below). Moreover, LaTeX’s range is not adequate to everyone’s requirements, and at
least three packages provide extensions to the set.
The AMSLaTeX bundle provides a range of “semantically-named” ellipses, for use
in different situations: \dotsb for use between pairs of binary operators, \dotsc for
use between pairs of commas, and so on.
The yhmath package defines an \adots command, which is the analogue of
\ddots, sloping forwards rather than backwards. The yhmath package comes with a
rather interesting font that extends the standard cmex; details are in the documentation.
The disadvantage of this setup is, that although \adots is merely a macro, the package
tries to load its own font and produces a “missing font” substitution warning message
if you haven’t installed the font.
The mathdots package (besides fixing up the behaviour of (La)TeX \ddots and
\vdots when the font size changes) provides an “inverse diagonal” ellipsis \iddots
(doing the same job as yhmath’s \adots, but better).
Documentation of yhmath appears, processed, in the distribution (thus saving you
the bother of installing the package before being able to read the documentation). Doc-
umentation of mathdots appears at the end the package file itself.
amslatex : macros/latex/required/amslatex
graphics.sty : Part of the macros/latex/required/graphics bundle
mathdots.sty : macros/generic/mathdots
yhmath (fonts): fonts/yhmath
yhmath (macros): macros/latex/contrib/yhmath
which will place the limits right above and below the symbol (and be blowed to the
typography. . . ).
Contrariwise, you may wish to change the arrangement of the limits when in
\displaystyle. For this purpose, there’s a corresponding \nolimits:
\[\sum\nolimits_{n=1}^{m} ...\]
$\displaystyle\sum_{n=1}^{m} ...$
\[\textstyle\sum_{n=1}^{m} ...\]
will serve. Either of these forms may have effects other than on the operator you’re
considering, but there are still those who prefer this formulation.
(Note that the macro \int normally has \nolimits built in to its definition. There
is an example in the TeXbook to show how odd \int\limits looks when typeset.)
233 Text inside maths
When we type maths in (La)TeX, the letters from which we make up ordinary text
assume a special significance: they all become single-letter variable names. The letters
appear in italics, but it’s not the same sort of italics that you see when you’re typing
ordinary text: a run of maths letters (for example “here”) looks oddly “lumpy” when
compared with the word written in italic text. The difference is that the italic text is
kerned to make the letters fit well together, whereas the maths is set to look as if you’re
multiplying h by e by r by e. The other way things are odd in TeX maths typing is that
spaces are ignored: at best we can write single words in this oddly lumpy font.
So, if we’re going to have good-looking text in amongst maths we’re writing, we
have to take special precautions. If you’re using LaTeX, the following should help.
The simplest is to use \mbox or \textrm:
The problem is that, with either, the size of the text remains firmly at the surrounding
text size, so that
$z = a_{\mbox{other end}}$
is definitely right. However, the surrounding text may not be in your roman font; if you
care about matching text, you need to choose between \textrm, \textsf, and so on.
(The maths-mode instance of your roman font (\mathrm) gets the size right, but
since it’s intended for use in maths, its spaces get ignored — use \mathrm for upright
roman alphabetic variable names, but not otherwise.)
You can correct these problems with size selectors in the text, as:
132
which works if your surrounding text is at default document size, but gives you the
wrong size otherwise.
These short cuts are (just about) OK for the “occasional” mathematician, but se-
rious mathematics calls for a technique that relieves the typist of the sort of thought
required. As usual, the AMSLaTeX system provides what’s necessary — the \text
command. The command is actually provided by the amstext package, but the “global”
amsmath package loads it, so anyone using AMSLaTeX proper has the command avail-
able, so even joke mathematicians can write:
\usepackage{amsmath}
...
$z = a_{\text{other end}}$
and the text will be at the right size, and in the same font as surrounding text.
AMSLaTeX also makes provision for interpolated comments in the middle of one
of its multi-line display structures, through the \intertext command. For example:
\begin{align}
A_1&=N_0(\lambda;\Omega’)-\phi(\lambda;\Omega’),\\
A_2&=\phi(\lambda;\Omega’)-\phi(\lambda;\Omega),\\
\intertext{and} A_3&=\mathcal{N}(\lambda;\omega).
\end{align}
places the text “and” on a separate line before the last line of the display. If the in-
terjected text is short, or the equations themselves are light-weight, you may find that
\intertext leaves too much space. Slightly more modest is the \shortintertext
command from the mathtools package:
\begin{align}
a =& b
\shortintertext{or}
c =& b
\end{align}
To have the text on the same line as the second equation, one can use the flalign
environment (from amsmath) with lots of dummy equations (represented by the double
& signs):
\begin{flalign}
&& a =& b && \\
\text{or} && c =& b &&
\end{flalign}
Here, the second instance of a = b will be typeset with a copy, made by the \tag
command, of the label of the first instance.
Comprehensive documentation of AMSLaTeX is to be found in amsldoc, in the
distribution; it is also available on the web at ftp://ftp.ams.org/pub/tex/doc/
amsmath/amsldoc.pdf
amsldoc.tex : Distributed as part of AMSLaTeX macros/latex/required/
amslatex
amsmath.sty : Distributed as part of AMSLaTeX macros/latex/required/
amslatex
\relpenalty = 500
\binoppenalty = 700
You make the break progressively less attractive by increasing these values. You can
actually forbid all breaks, everywhere, by:
\relpenalty = 10000
\binoppenalty = 10000
{%
\relpenalty = 10000
\binoppenalty = 10000
$a=b+c$
}
and the original values will remain undisturbed outside the braces. This is tedious:
there is often value in an alternative approach, in which you say which parts of the
expression may not break whatever happens, and fortunately this is surprisingly easy.
Suppose we want to defer a break until after the equality, we could write:
${a+b+c+d} = z+y+x+w$
The braces say “treat this subformula as one atom” and (in TeX at least) atoms don’t
get split: not a \binoppenalty change in sight.
Q.2 Lists
236 Fancy enumeration lists
The enumerate package allows you to control the display of the enumeration counter.
The package adds an optional parameter to the enumerate environment, which is used
to specify the layout of the labels. The layout parameter contains an enumeration type
(‘1’ for arabic numerals, ‘a’ or ‘A’ for alphabetic enumeration, and ‘i’ or ‘I’ for Roman
numerals), and things to act as decoration of the enumeration. So, for example
134
\usepackage{enumerate}
...
\begin{enumerate}[(a)]
\item ... ...
\end{enumerate}
\usepackage{enumerate}
...
\begin{enumerate}[I/]
\item ... ...
\end{enumerate}
\usepackage{enumitem}
...
\begin{enumerate}[label=\Roman{*}/]
\item ... ...
\end{enumerate}
Note that the ‘*’ in the key value stands for the list counter at this level. You can also
manipulate the format of references to list item labels:
\usepackage{enumitem}
...
\begin{enumerate}[label=\Roman{*}/, ref=(\roman{*})]
\item ... ...
\end{enumerate}
to make references to the list items format appear as (i), (ii), (iii), etc.
The memoir class includes functions that match those in the enumerate package,
and has similar functionality for itemize lists.
enumerate.sty : Distributed as part of macros/latex/required/tools
enumitem.sty : macros/latex/contrib/enumitem
memoir.cls: macros/latex/contrib/memoir
paralist.sty : macros/latex/contrib/paralist
135
\newenvironment{itemize*}%
{\begin{itemize}%
\setlength{\itemsep}{0pt}%
\setlength{\parskip}{0pt}}%
{\end{itemize}}
to suppress all spacing above and below your list. Enumitem also permits manipulation
of the label format in a more “basic” manner than the enumerate package does.
enumerate.sty : Distributed as part of macros/latex/required/tools
enumitem.sty : macros/latex/contrib/enumitem
expdlist.sty : macros/latex/contrib/expdlist
memoir.cls: macros/latex/contrib/memoir
mdwlist.sty : Distributed as part of macros/latex/contrib/mdwtools
multenum.sty : macros/latex/contrib/multenum
paralist.sty : macros/latex/contrib/paralist
savetrees.sty : macros/latex/contrib/savetrees
This is reasonable, in small doses. . . Problems (apart from sheer verbosity) are
getting the level right (“should I use counter enumi, enumii, . . . ”) and remembering
not to nest the interruptions (i.e., not to have a separate list, that is itself interrupted) in
the “commentary text”).
The mdwlist package defines commands \suspend and \resume that simplify the
process:
\begin{enumerate}
...
\suspend{enumerate}
<Commentary text>
\resume{enumerate}
...
\end{enumerate}
\begin{enumerate}[\textbf{Item} i]
...
\suspend{enumerate}
<comment>
\resume{enumerate}[{[\textbf{Item} i]}]
...
\end{enumerate}
The enumitem package, in its most recent release, will allow you to resume lists, at one
level only:
\begin{enumerate}
...
\end{enumerate}
<comment>
\begin{enumerate}[resume]
...
\end{enumerate}
which feels just as “natural” as the mdwtools facility, and has the advantage of playing
well with the other excellent facilities of enumitem.
enumerate.sty : Distributed as part of macros/latex/required/tools
enumitem.sty : macros/latex/contrib/enumitem
mdwlist.sty : Distributed as part of macros/latex/contrib/mdwtools
137
Q.3 Tables, figures and diagrams
239 The design of tables
In recent years, several authors have argued that the examples, set out by Lamport in
his LaTeX manual, have cramped authors’ style and have led to extremely poor table
design. It is in fact difficult even to work out what many of the examples in Lamport’s
book “mean”.
The criticism focuses on the excessive use of rules (both horizontal and vertical)
and on the poor vertical spacing that Lamport’s macros offer.
The problem of vertical spacing is plain for all to see, and is addressed in several
packages — see “spacing of lines in tables”.
The argument about rules is presented in the excellent essay that prefaces the doc-
umentation of Simon Fear’s booktabs package, which (of course) implements Fear’s
scheme for ‘comfortable’ rules. (The same rule commands are implemented in the
memoir class.)
Lamport’s LaTeX was also inflexibly wrong in “insisting” that captions should
come at the bottom of a table. Since a table may extend over several pages, traditional
typography places the caption at the top of a table float. The \caption command will
get its position wrong (by 10pt) if you simply write:
\begin{table}
\caption{Example table}
\begin{tabular}{...}
...
\end{tabular}
\end{table}
\usepackage{topcaption}
...
\begin{table}
\topcaption{Example table}
\begin{tabular}{...}
...
\end{tabular}
\end{table}
\usepackage[tableposition=top]{caption}
Doing the job yourself is pretty easy: topcapt switches the values of the LaTeX 2ε
parameters \abovecaptionskip (default value 10pt) and \belowcaptionskip (de-
fault value 0pt), so:
\begin{table}
\setlength{\abovecaptionskip}{0pt}
\setlength{\belowcaptionskip}{10pt}
\caption{Example table}
\begin{tabular}{...}
...
\end{tabular}
\end{table}
does the job. (The package itself is very slightly more elaborate. . . )
booktabs.sty : macros/latex/contrib/booktabs
KOMA script bundle: macros/latex/contrib/koma-script
memoir.cls: macros/latex/contrib/memoir
topcapt.sty : macros/latex/contrib/misc/topcapt.sty
138
240 Fixed-width tables
There are two basic techniques for making fixed-width tables in LaTeX: you can make
the gaps between the columns stretch, or you can stretch particular cells in the table.
Basic LaTeX can make the gaps stretch: the tabular* environment takes an extra
argument (before the clpr layout one) which takes a length specification: you can say
things like “15cm” or “\columnwidth” here. You must also have an \extracolsep
command in the clpr layout argument, inside an @{} directive. So, for example, one
might have
\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}}lllr}
The \extracolsep applies to all inter-column gaps to its right as well; if you don’t
want all gaps stretched, add \extracolsep{0pt} to cancel the original.
The tabularx package defines an extra clpr column specification, X; X columns
behave as p columns which expand to fill the space available. If there’s more than one
X column in a table, the spare space is distributed between them.
The tabulary package (by the same author) provides a way of “balancing” the space
taken by the columns of a table. The package defines column specifications C, L, R and
J, giving, respectively, centred, left, right and fully-justified versions of space-sharing
columns. The package examines how long each column would be “naturally” (i.e., on
a piece of paper of unlimited width), and allocates space to each column accordingly.
There are “sanity checks” so that really large entries don’t cause everything else to
collapse into nothingness (there’s a “maximum width” that any column can exert), and
so that tiny entries can’t get smaller than a specified minimum. Of course, all this
work means that the package has to typeset each row several times, so things that leave
“side-effects” (for example, a counter used to produce a row-number somewhere) are
inevitably unreliable, and should not even be tried.
The ltxtable combines the features of the longtable and tabularx packages: it’s
important to read the documentation, since usage is distinctly odd.
ltxtable.sty : Distributed as part of macros/latex/contrib/carlisle
tabularx.sty : Distributed as part of macros/latex/required/tools
tabulary.sty : macros/latex/contrib/tabulary
varwidth defines a new column-type “V”, which you can use as follows:
\begin{tabular}{l V{3.5cm} r}
foo & blah & bar \\
foo & blah blah & bar \\
\end{tabular}
when the second column ends up less than 3.5cm wide; or you can use it as follows:
\begin{tabular}{l V{3.5cm} r}
foo & blah & bar \\
139
foo & blah blah & bar \\
foo & blah blah blah blah blah blah
& bar \\
\end{tabular}
where the second column will end up noticeably wider, and will wrap to a second line
in the third row.
array.sty : Distributed as part of macros/latex/required/tools
varwidth.sty : macros/latex/contrib/misc/varwidth.sty
would become
\cmdinvoke{begin}{tabular}{Sl Sl Sl Sp{3cm}}
and so on. This technique shows promise of not interfering so much with other pack-
ages, but this author has heard of no reports from the field.
The booktabs package comes with a thought-provoking essay about how tables
should be designed. Since table row-spacing problems most often appear in collisions
with rules, the author’s thesis, that LaTeX users tend too often to rule their tables, is
interesting. The package provides rule commands to support the author’s scheme, but
deals with inter-row spacing too. The most recent release of booktabs sports compati-
bility with packages such as longtable.
Documentation of both bigstrut and tabls may be found as comments in the package
files themselves.
array.sty : Distributed as part of macros/latex/required/tools
bigstrut.sty : Distributed as part of macros/latex/contrib/multirow
140
booktabs.sty : macros/latex/contrib/booktabs
cellspace.sty : macros/latex/contrib/cellspace
tabls.sty : macros/latex/contrib/misc/tabls.sty
one is liable to encounter errors that complain about a “misplaced \noalign” or “extra
alignment tab”, or the like. The problem is that the command \\ means different things
in different circumstances: the tabular environment switches the meaning to a value
141
for use in the table, and \centering, \raggedright and \raggedleft all change
the meaning to something incompatible. Note that the problem only arises in the last
cell of a row: since each cell is set into a box, its settings are lost at the & (or \\) that
terminates it.
The simple (old) solution is to preserve the meaning of \\:
\newcommand\PBS[1]{\let\temp=\\%
#1%
\let\\=\temp
}
(for example).
The technique using \PBS was developed in the days of LaTeX 2.09 because the
actual value of \\ that the tabular environment uses was only available as an internal
command. Nowadays, the value is a public command, and you can in principle use it
explicitly:
... & \centering blah ... \tabularnewline
\newcommand{\RBS}{\let\\=\tabularnewline}
and used as
(note, you Preserve backslash with \PBS before the command that changes it, and Re-
store it with \RBS after the command; in fact, \RBS is marginally preferable, but the
old trick lingers on).
The \PBS and \RBS tricks also serve well in array package “field format” preamble
specifications:
\begin{tabular}{... >{\centering\RBS}p{50mm}}
...
or
\begin{tabular}{... >{\PBS\centering}p{50mm}}
...
In the tabularx and tabulary packages, there’s a command \arraybackslash that has
same effect as \RBS (above); so in those packages, one might say:
\begin{tabular}{... >{\centering\arraybackslash}p{50mm}}
...
in place of the example above; in fact, the very latest (2003/12/01) release of array.sty
also provides a \tabularnewline command, that has the “basic tabular/array” mean-
ing of ‘\\’. The command does rather lack brevity, but at least you don’t have to define
it for yourself.
array.sty : Distributed as part of macros/latex/required/tools
tabularx.sty : Distributed as part of macros/latex/required/tools
tabulary.sty : macros/latex/contrib/tabulary
142
245 The thickness of rules in LaTeX tables
The rules in a LaTeX table are by default 0.4pt thick; this is in fact a default built in at
the lowest level, and applies to all rules (including those separating blocks of running
text).
Sometimes, however, we look at a table and find we want the rules to stand out —
perhaps to separate the text from the rest of the body text, or to make the sections of
the table stand out from one another. However, a quick review of any LaTeX manual
will reveal no technique for making any one rule stand out, and a little experimentation
shows that it is indeed pretty difficult to prevent a change “bleeding” out to affect other
rules in the same table.
If you look at what we have to say on the design of tables, elsewhere among these
FAQs, and you may sense that the design of LaTeX simply skipped the issues surround-
ing table design: that’s presumably why there’s no facilities to help you.
Specifically, the length \arrayrulewidth affects the thickness of the rules (both
horizontal and vertical) within both tabular and array environments. If you change
from the default (see above) only as far as
\setlength{\arrayrulewidth}{1pt}
the change is remarkably striking. However, really quite subtle user level programming
proves incapable of changing just one rule: it’s necessary to delve into the (rather
tricky) code of \hline and \cline themselves.
Fortunately, this job has already been done for the community: the booktabs pack-
age defines three different classes of rule (\toprule, \midrule and \bottomrule),
and the package documentation offers hints on how to use them. You are strongly
advised to read the documentation pretty carefully.
The memoir class includes the booktabs package, and repeats the documentation in
its compendious manual.
Note that none of the above mentions the issue of the weight of vertical rules
(except in passing). For the reasons, see the documentation of the booktabs pack-
age (again); vertical rules in tables are in any case even more trickily coded than are
horizontal rules, and if their lack of configurability makes them still less attractive, so
much the better for the design of your document.
booktabs.sty : macros/latex/contrib/booktabs
memoir.cls: macros/latex/contrib/memoir
143
allows the figure to be moved into the margin. The figure or table will entered into
the list of figures or tables if you use the \caption command.
The environments do not work within list environments that end before the figure
or table has finished, but can be used in a parbox or minipage, and in twocolumn
format.
picins Picins is part of a large bundle that allows inclusion of pictures (e.g., with
shadow boxes, various MS-DOS formats, etc.). The command is:
\parpic(width,height)(x-off,y-off )[Options][Position]
{Picture}
Paragraph text
All parameters except the Picture are optional. The picture can be positioned left
or right, boxed with a rectangle, oval, shadowbox, dashed box, and a caption can
be given which will be included in the list of figures.
Unfortunately (for those of us whose understanding of German is not good), the
documentation is in German. Piet van Oostrum has written an English summary.
floatflt.sty : macros/latex/contrib/floatflt
picins.sty : systems/msdos/picins/picins.zip
picins documentation summary: macros/latex209/contrib/picins/picins.
txt
wrapfig.sty : macros/latex/contrib/wrapfig
-----------------
x y
--------------
1 2 3 4 5
-----------------
1
2
3
4
5
-----------------
However, this doesn’t satisfy everyone: many want the labelling in a single cell at
the top left of the table. It sounds a simple enough requirement, yet it calls for some
slightly tricky LaTeX coding. The slashbox package does the job for you: it defines
commands \slashbox and \backslashbox, each taking the two labels as arguments.
It draws a picture with the two labels on either side of a slanting line; the command
(and hence the picture) may be placed in the corner cell, where the labelled row and
column meet.
The package isn’t the world’s neatest: it uses LaTeX picture mode to draw its line,
and picture mode has many tedious restrictions (and doesn’t, in all honesty, produce
particularly good pictures). Load slashbox with the pict2e package, and at least the
picture quality will be improved.
Documentation of slashbox is less than satisfactory: a LaTeX source file of rather
startling starkness accompanies the package file in the distribution. It does, however,
process to a DVI file that gives some idea of how the \slashbox may be expected to
look. (The third example in the file shows the effect of picture mode’s restrictions:
the dividing line doesn’t go from corner to corner in the box: to correct this requires
revision of slashbox — pict2e alone doesn’t help in this regard.)
slashbox.sty : macros/latex/contrib/slashbox
Now, we put ‘$’ before the first column specifier; and we put ‘^’ before the modifiers of
subsequent ones. We then use \rowstyle at the start of each row we want to modify:
\begin{tabular}{|$l|^l|^l|} \hline
\rowstyle{\bfseries}
Heading & Big and & Bold \\ \hline
Meek & mild & entry \\
Meek & mild & entry \\
\rowstyle{\itshape}
Strange & and & italic \\
Meek & mild & entry \\ \hline
\end{tabular}
The array package works with several other tabular-like environments from other
packages (for example longtable), but unfortunately this trick won’t always work.
array.sty : Distributed as part of macros/latex/required/tools
\begin{tabular}{|c|c|}
\hline
\multirow{4}{*}{Common g text}
& Column g2a\\
& Column g2b \\
& Column g2c \\
& Column g2d \\
\hline
\end{tabular}
and multirow will position “Common g text” at the vertical centre of the space defined
by the other rows. Note that the rows that don’t contain the “multi-row” specification
must have empty cells where the multi-row is going to appear.
The “*” may be replaced by a column width specification. In this case, the argu-
ment may contain forced line-breaks:
\begin{tabular}{|c|c|}
\hline
\multirow{4}{25mm}{Common\\g text}
& Column g2a\\
& Column g2b \\
& Column g2c \\
& Column g2d \\
\hline
\end{tabular}
145
A similar effect (with the possibility of a little more sophistication) may be achieved
by putting a smaller table that lines up the text into a *-declared \multirow.
The \multirow command may also used to write labels vertically down one or
other side of a table (with the help of the graphics or graphicx package, which provide
the \rotatebox command):
\begin{tabular}{|l|l|}
\hline
\multirow{4}{*}{\rotatebox{90}{hi there}}
& Column g2a\\
& Column g2b \\
& Column g2c \\
& Column g2d \\
\hline
\end{tabular}
(which gives text going upwards; use angle -90 for text going downwards, of course).
Multirow is set up to interact with the bigstrut package (which is also discussed in
the answer to spacing lines in tables). You use an optional argument to the \multirow
command to say how many of the rows in the multi-row have been opened up with
\bigstrut.
The documentation of both multirow and bigstrut is to be found, as comments, in
the package files themselves.
bigstrut.sty : Distributed as part of macros/latex/contrib/multirow
multirow.sty : macros/latex/contrib/multirow
147
254 Facing floats on 2-page spread
If a pair of floats are to be forced to form a 2-page spread (in a book, or whatever),
the first must lie on the left side of the spread, on an even-numbered page. The dpfloat
package provides for this: the construction to use is:
\begin{figure}[p]
\begin{leftfullpage}
<left side figure>
\end{leftfullpage}
\end{figure}
\begin{figure}[p]
\begin{fullpage}
<right side figure>
\end{fullpage}
\end{figure}
The construction has no effect unless the standard class option twoside is in effect.
Full documentation of the package (such as it is) is to be found in README.dpfloat
dpfloat.sty : macros/latex/contrib/dpfloat
\@fptop defines the distance from the top of the page to the top of the first float,
\@fpsep defines the separation between floats, and
\@fpbot defines the distance from the bottom of the last float on the page to the bottom
of the page.
(In fact, the output routine places a skip of \@fpsep above each float, so the \@fptop
skip is always followed by a correction for that.)
The LaTeX defaults are:
\@fptop = 0pt + 1fil
\@fpsep = 8pt + 2fil
\@fpbot = 0pt + 1fil
so that the gaps expand to fill the space not occupied by floats, but if there is more than
one float on the page, the gap between them will expand to twice the space at top and
bottom.
Those who understand this stuff will be able to play elaborate games, but the com-
monest requirement, that the floats start at the top of the page, is a simple thing to
do:
\makeatletter
\setlength{\@fptop}{0pt}
\makeatother
Surprisingly, you may find this setting leaves your floats too high on the page. One can
justify a value of 5pt (in place of 0pt) — it’s roughly the difference between \topskip
and the height of normal (10pt) text.
Note that this is a “global” setting (best established in a class file, or at worst in the
document preamble); making the change for a single float page is likely (at the least)
to be rather tricky.
Q.5 Footnotes
256 Footnotes in tables
The standard LaTeX \footnote command doesn’t work in tables; the table traps the
footnotes and they can’t escape to the bottom of the page.
If your table is floating, your best bet is (unfortunately) to put the table in a
minipage environment and to put the notes underneath the table, or to use Donald
Arseneau’s package threeparttable (which implements “table notes” proper).
148
The ctable package extends the model of threeparttable, and also uses the ideas
of the booktabs package. The \ctable command does the complete job of setting
the table, placing the caption, and defining the notes. The “table” may consist of dia-
grams, and a parameter in \ctable’s optional argument makes the float that is created
a “figure” rather than a “table”.
Otherwise, if your table is not floating (it’s just a ‘tabular’ in the middle of some
text), there are several things you can do to fix the problem.
• Use \footnotemark to position the little marker appropriately, and then put in
\footnotetext commands to fill in the text once you’ve closed the tabular en-
vironment. This is described in Lamport’s book, but it gets messy if there’s more
than one footnote.
• Stick the table in a minipage anyway. This provides all the ugliness of footnotes
in a minipage with no extra effort.
• Use threeparttable anyway; the package is intended for floating tables, and the
result might look odd if the table is not floating, but it will be reasonable.
• Use tabularx or longtable from the LaTeX tools distribution; they’re noticeably
less efficient than the standard tabular environment, but they do allow footnotes.
• Grab hold of footnote, and put your tabular environment inside a savenotes
environment. Alternatively, say \makesavenoteenv{tabular} in the preamble
of your document, and tables will all handle footnotes correctly.
• Use mdwtab from the same bundle; it will handle footnotes properly, and has other
facilities to increase the beauty of your tables. It may also cause other table-related
packages (not the standard ‘tools’ ones, though) to become very unhappy and stop
working.
The documentation of threeparttable appears in the package file itself; that of ctable
is distributed as a PDF file (for convenience’s sake).
ctable.sty : macros/latex/contrib/ctable
footnote.sty : Distributed as part of macros/latex/contrib/mdwtools
longtable.sty : Distributed as part of macros/latex/required/tools
mdwtab.sty : Distributed as part of macros/latex/contrib/mdwtools
threeparttable.sty : macros/latex/contrib/misc/threeparttable.sty
tabularx.sty : Distributed as part of macros/latex/required/tools
• Take advantage of the fact that the mandatory argument doesn’t ‘move’ if the op-
tional argument is present: \section[title]{title\footnote{title ftnt}}
• Use the footmisc package, with package option stable — this modifies footnotes
so that they softly and silently vanish away if used in a moving argument.
footmisc.sty : macros/latex/contrib/footmisc
149
• use an optional argument in your \caption command, that doesn’t have the foot-
note in it; this prevents the footnote appearing in the “List of . . . ”, and
• put your whole float in a minipage so as to keep the footnotes with the float.
so we have:
\begin{figure}
\begin{minipage}{\textwidth}
...
\caption[Caption for LOF]%
{Real caption\footnote{blah}}
\end{minipage}
\end{figure}
However, as well as all of the above, one also has to deal with the tendency of the
\caption command to produce the footnote’s text twice. For this last problem, there
is no tidy solution this author is aware of.
If you’re suffering the problem, a well-constructed \caption command in a
minipage environment within a float (as in the example above) can produce two
copies of the footnote body “blah”. (In fact, the effect only occurs with captions that
are long enough to require two lines to be typeset, and so wouldn’t appear with such a
short caption.)
The documentation of the ccaption package describes a really rather awful work-
around.
ccaption.sty : macros/latex/contrib/ccaption
threeparttable.sty : macros/latex/contrib/misc/threeparttable.sty
. . . which is very easy, since we know there will only ever be a footnote number 1. A
similar technique can be used once the footnotes are stable, reusing the number that
LaTeX has allocated. This can be tiresome, though, as any change of typesetting could
change the relationships of footnote and repeat: labelling is inevitably better.
Simple hand-labelling of footnotes is possible, using a counter dedicated to the job:
\newcounter{fnnumber}
...
...\footnote{Text to repeat}%
\setcounter{fnnumber}{\thefootnote}%
...
...\footnotemark[\thefnnumber]
but this is somewhat tedious. LaTeX’s labelling mechanism can be summoned to our
aid, but there are ugly error messages before the \ref is resolved on a second run
through LaTeX:
...\footnote{Text to repeat\label{fn:repeat}}
...
...\footnotemark[\ref{fn:repeat}]
Alternatively, one may use the \footref command, which has the advantage of work-
ing even when the footnote mark isn’t expressed as a number. The command is defined
in the footmisc package and in the memoir class (at least); \footref reduces the above
example to:
150
...\footnote{Text to repeat\label{fn:repeat}}
...
...\footref{fn:repeat}
This is the cleanest simple way of doing the job. Note that the \label command must
be inside the argument of \footnote.
The fixfoot package takes away some of the pain of the matter: you declare foot-
notes you’re going to reuse, typically in the preamble of your document, using a
\DeclareFixedFoot command, and then use the command you’ve ‘declared’ in the
body of the document:
\DeclareFixedFootnote{\rep}{Text to repeat}
...
...\rep{}
...\rep{}
The package ensures that the repeated text appears at most once per page: it will usually
take more than one run of LaTeX to get rid of the repeats.
fixfoot.sty : macros/latex/contrib/fixfoot
footmisc.sty : macros/latex/contrib/footmisc
memoir.cls: macros/latex/contrib/memoir
151
Q.6 Document management
262 What’s the name of this file
One might want this so as to automatically generate a page header or footer recording
what file is being processed. It’s not easy. . .
TeX retains what it considers the name of the job, only, in the primitive \jobname;
this is the name of the file first handed to TeX, stripped of its directory name and of any
extension (such as .tex). If no file was passed (i.e., you’re using TeX interactively),
\jobname has the value texput (the name that’s given to .log files in this case).
This is fine, for the case of a small document, held in a single file; most significant
documents will be held in a bunch of files, and TeX makes no attempt to keep track
of files input to the job. So the user has to keep track, himself — the only way is to
patch the input commands and cause them to retain details of the file name. This is
particularly difficult in the case of Plain TeX, since the syntax of the \input command
is so peculiar.
In the case of LaTeX, the input commands have pretty regular syntax, and the
simplest patching techniques can be used on them.
If you’re not inputting things from a file that’s already been input, the job is almost
trivial:
\def\ThisFile{\jobname}
\let\OldInput\input
\renewcommand{\input}[1]{%
\renewcommand{\ThisFile}{#1}%
\OldInput{#1}%
}
With that, the macro \ThisFile always contains the last thing input: it starts pointing
at the base file of your document (\jobname), and thereafter changes every time you
use \input{file}.
Most ordinary users will quickly become irritated with the simplicity of of the
\ThisFile mechanism above. The following code is more cunning: it maintains
details of the files you’ve ‘come through’ to get to where you are, and it restores
\ThisFile to what the previous file was before returning.
\def\ThisFile{\jobname}
\newcounter{FileStack}
\let\OrigInput\input
\renewcommand{\input}[1]{%
\stackinput{#1}{\OrigInput}%
}
\newcommand{\stackinput}[2]{%
\stepcounter{FileStack}%
\expandafter\let
\csname NameStack\theFileStack\endcsname
\ThisFile
\def\ThisFile{#1}%
#2{#1}%
\expandafter\let\expandafter
\ThisFile
\csname NameStack\theFileStack\endcsname
\addtocounter{FileStack}{-1}%
}
\let\OrigInclude\include
\renewcommand{\include}[1]{%
\stackinput{#1}{\OrigInclude}%
}
Both examples of patching \input assume you always use LaTeX syntax, i.e., always
use braces around the argument.
152
The FiNK (“File Name Keeper”) package provides a regular means of keeping track
of the current file name (with its extension), in a macro \finkfile. If you need the
unadorned file name (without its ‘.tex’), use the commands:
\def\striptexext#1.tex{#1}
...
\edef\ThisFile{\expandafter\stripext\finkfile}
The FiNK bundle includes a fink.el that provides support under emacs with AUC-
TeX.
fink.sty : macros/latex/contrib/fink
The \iftrue is spotted by TeX as it scans, ignoring the \verb command; so the
\iffalse isn’t terminated by the following \fi. Also, \gobble is pretty inefficient
at consuming anything non-trivial, since all the matter to be skipped is copied to the
argument stack before being ignored.
If your requirement is for a document from which whole chapters (or the like) are
missing, consider the LaTeX \include/\includeonly system. If you ‘\include’
your files (rather than \input them — see What’s going on in my \include com-
mands?), LaTeX writes macro traces of what’s going on at the end of each chapter to
the .aux file; by using \includeonly, you can give LaTeX an exhaustive list of the
files that are needed. Files that don’t get \included are skipped entirely, but the docu-
ment processing continues as if they were there, and page, footnote, and other numbers
are not disturbed. Note that you can choose which sections you want included interac-
tively, using the askinclude package.
The inverse can be done using the excludeonly package: this allows you to ex-
clude a (list of) \included files from your document, by means of an \excludeonly
command.
154
If you want to select particular pages of your document, use Heiko Oberdiek’s
pagesel or the selectp packages. You can do something similar with an existing PDF
document (which you may have compiled using pdflatex in the first place), using the
pdfpages package. The job is then done with a document looking like:
\documentclass{article}
\usepackage[final]{pdfpages}
\begin{document}
\includepdf[pages=30-40]{yoursource.pdf}
\end{document}
A further valuable twist is offered by the extract package. This allows you to pro-
duce a “partial copy” of an existing document: the package was developed to permit
155
production of a “book of examples” from a set of lecture notes. The package documen-
tation shows the following usage:
\usepackage[
active,
generate=foobar,
extract-env={figure,table},
extract-cmd={chapter,section}
]{extract}
which will cause the package to produce a file foobar.tex containing all the figure
and table environments, and the \chapter and \section commands, from the docu-
ment being processed. The new file foobar.tex is generated in the course of an other-
wise ordinary run on the ‘master’ document. The package provides a good number of
other facilities, including (numeric or labelled) ranges of environments to extract, and
an extract environment which you can use to create complete ready-to-run LaTeX
documents with stuff you’ve extracted.
askinclude.sty : macros/latex/contrib/misc/askinclude.sty
comment.sty : macros/latex/contrib/comment
excludeonly.sty : macros/latex/contrib/misc/excludeonly.sty
extract.sty : macros/latex/contrib/extract
memoir.cls: macros/latex/contrib/memoir
optional.sty : macros/latex/contrib/misc/optional.sty
pagesel.sty : Distributed with Heiko Oberdiek’s packages macros/latex/
contrib/oberdiek
pdfpages.sty : macros/latex/contrib/pdfpages
selectp.sty : macros/latex/contrib/misc/selectp.sty
verbatim.sty : Distributed as part of macros/latex/required/tools
version.sty : macros/latex/contrib/misc/version.sty
versions.sty : macros/latex/contrib/versions/versions.sty
xcomment.sty : Distributed as part of macros/latex/contrib/seminar
which command will issue a ‘normal’ command \part[pt 1]{Part One} and then
input the file part1/part.tex, remembering that part1/ is now the “current folder”.
There are also commands of the form \cfpartstar (which corresponds to a \part*
command).
Once you’re “in” a chapterfolder-included document, you may use \cfinput
to input something relative to the “current folder”, or you may use \input, using
\cfcurrentfolder to provide a path to the file. (There are also \cfcurrentfolderfigure
for a figure/ subdirectory and \cfcurrentfolderlistings for a listings/ sub-
directory.)
Documentation of chapterfolder is in French, but the README in the directory is in
English.
chapterfolder.sty : macros/latex/contrib/chapterfolder
import.sty : macros/latex/contrib/misc/import.sty
If you’ve entered the brave new world of subversion, the package svn may be for
you. It has explicit cleverness about dealing with dates:
\documentclass{hfooi}
...
\usepackage{svn}
\SVNdate $Date$
\author{...}
\title{...}
...
\begin{document}
\maketitle
...
\end{document}
will (once subversion has committed a copy of the document) cause \maketitle use
the date that has been written into the $Date$ keyword.
The alternative is the svninfo package, which has much the same mechanisms as
does svn but with a rather different focus. Svninfo does the date trick that svn per-
forms (controlled by a package option), and can set up page foot-lines using package
fancyhdr. There isn’t much to choose between the two packages: you should read the
packages’ documentation to see which you find best.
rcs.sty : macros/latex/contrib/rcs
rcsinfo.sty : macros/latex/contrib/rcsinfo
svn.sty : macros/latex/contrib/svn
svninfo.sty : macros/latex/contrib/svninfo
157
268 Makefiles for LaTeX documents
LaTeX is a tricky beast for running make on: the need to instruct LaTeX to run several
times for essentially different reasons (for example, “get the table of contents stable”,
“get the labels stable”, “add the bibliography”, “add the index”) is actually rather diffi-
cult to express in the ‘ordinary’ sort of dependency graph that one constructs for make.
For this reason, the only make-like package on CTAN (for a long time) was latexmk,
which is a Perl script that analyses your LaTeX source for its dependencies, runs Bib-
TeX or makeindex as and when it notices that those programs’ input (parts of the .aux
file, or the .idx file, respectively) has changed, and so on. Latexmk is a fine solution
(and was used in generating printable versions of these FAQs for a long time); it has
recently been upgraded and has many bells and whistles that allow it to operate as if it
were a poor man’s WYSIWYG system.
The texinfo system comes with a utility called texi2dvi, which is capable of “con-
verting” either LaTeX or texinfo files into DVI (or into PDF, using PDFTeX).
A later contribution is the bundle latexmake, which offers a set of make rules that
invoke texi2dvi as necessary.
The curious may examine the rules employed to run the present FAQ through La-
TeX: we don’t present them as a complete solution, but some of the tricks employed
are surely re-usable.
FAQ distribution: help/uk-tex-faq
latexmake: support/latexmake
latexmk : support/latexmk
texi2dvi: Distributed as part of macros/texinfo/texinfo
\begin{plain}
\input{plain-doc}
\end{plain}
158
The package is known to fail, for example, with documents that use AMSTeX; no doubt
it would also fail if asked to load Eplain. All these things can be overcome (although
it’s not often easy), but the environment saves a lot of work on many occasions.
plain.sty : Distributed as part of macros/latex/contrib/carlisle
Q.7 Hyphenation
271 My words aren’t being hyphenated
Let’s assume you’ve selected the right TeX ‘language’ — as explained in “how hyphen-
ation works”, you’re not likely to get the correct results typesetting one language using
the hyphenation rules of another. (Select the proper language, using babel if you’re a
LaTeX user. This may reveal that you need another set of hyphenation patterns; see
“using a new language” for advice on how to install it.)
So what else can go wrong?
• Since TeX version 3.0, the limits on how near to either end of a word hyphenation
may take place have been programmable (see “weird hyphenation”), and for some
reason the values in question may have been corrupted in some macros you are
using. TeX won’t hyphenate less than \lefthyphenmin characters after the start
of a word, nor less than \righthyphenmin before the end of a word; thus it won’t
hyphenate a word shorter than the sum of the two minima, at all. For example,
since the minima are 2 and 3 for English, TeX won’t hyphenate a word shorter
than 5 letters long, if it believes the word to be English.
• TeX won’t hyphenate a word that’s already been hyphenated. For example, the
(caricature) English surname Smyth-Postlethwaite wouldn’t hyphenate, which
could be troublesome. This is correct English typesetting style (it may not be
correct for other languages), but if needs must, you can replace the hyphen in the
name with a \hyph command, defined
\def\hyph{-\penalty0\hskip0pt\relax}
This is not the sort of thing this FAQ would ordinarily recommend. . . The
hyphenat package defines a bundle of such commands (for introducing hyphen-
ation points at various punctuation characters).
• There may be accents in the word. The causes of and remedies for this effect are
discussed in accents and hyphens.
• The hyphenation may simply not have been spotted; while TeX’s algorithm is
good, it’s not infallible, and it does miss perfectly good hyphenations in some
languages. When this happens, you need to give TeX explicit instructions on how
to hyphenate.
The \hyphenation command allows you to give explicit instructions. Provided that
the word will hyphenate at all (that is, it is not prevented from hyphenating by any of
the other restrictions above), the command will override anything the hyphenation pat-
terns might dictate. The command takes one or more hyphenated words as argument —
\hyphenation{ana-lysis pot-able}; note that (as here, for analysis) you can use
the command to overrule TeX’s choice of hyphenation (ana-lysis is the British etymo-
logical hyphenation; some feel the American hyphenation feels ‘unfortunate’. . . ).
hyphenat.sty : macros/latex/contrib/hyphenat
This isn’t a particularly practical way for users to suppress hyphenation — the com-
mand has to be issued for every font the document uses — but it’s how LaTeX itself
161
suppresses hyphenation in tt and other fixed-width fonts.
Which of the techniques you should use depends on what you actually want to do.
If the text whose hyphenation is to be suppressed runs for less than a paragraph, your
only choice is the no-hyphens language: the language value is preserved along with
the text (in the same way that the current font is); the values for penalties and hyphen
minima active at the end of a paragraph are used when hyphenation is calculated.
Contrariwise, if you are writing a multilanguage document using the babel package,
you cannot suppress hyphenation throughout using either the no-hyphens language or
the hyphen minima: all those values get changed at a babel language switch: use the
penalties instead.
If you simply switch off hyphenation for a good bit of text, the output will have a
jagged edge (with many lines seriously overfull), and your (La)TeX run will bombard
you with warnings about overfull and underfull lines. To avoid this you have two
options. You may use \sloppy (or its environment version sloppypar), and have
TeX stretch what would otherwise be underfull lines to fill the space offered, and wrap
other lines, while prematurely wrapping overfull lines and stretching the remainder.
Alternatively, you may set the text ragged right, and at least get rid of the overfull lines;
this technique is ‘traditional’ (in the sense that typists do it) and may be expected to
appeal to the specifiers of eccentric document layouts (such as those for dissertations),
but for once their sense conforms with typographic style. (Or at least, style constrained
in this curious way.)
hyphenat.sty : macros/latex/contrib/hyphenat
(Plain TeX users should use \hbox, and take care at the start of paragraphs.) However,
boxing the word is not really advisable unless you are sure it only occurs once.
If the word occurs commonly, the best choice is to assert a non-hyphenation for it:
\hyphenation{oddword}
This hyphenation exception (with no break points) will be used in preference to what
TeX’s hyphenation algorithm may come up with.
In a multilingual document, repeat the exception specification for each language
the word may appear in. So:
\usepackage[french,english]{babel}
\selectlanguage{english}
\hyphenation{oddword}
\selectlanguage{french}
\hyphenation{oddword}
(note that babel will select the default language for the document — English, in this
case — at \begin{document}.)
278 Hyphenation exceptions
While TeX’s hyphenation rules are good, they’re not infallible: you will occasionally
find words TeX just gets wrong. So for example, TeX’s default hyphenation rules (for
American English) don’t know the word “manuscript”, and since it’s a long word you
may find you need to hyphenate it. You can “write the hyphenation out” each time you
use the word:
... man\-u\-script ...
and the hyphenation would be set for the whole document. Barbara Beeton publishes
articles containing lists of these “hyphenation exceptions”, in TUGboat; the hyphen-
ation ‘man-u-script’ comes from one of those articles.
What if you have more than one language in your document? Simple: select the
appropriate language, and do the same as above:
\usepackage[french]{babel}
\selectlanguage{french}
\hyphenation{re-cher-cher}
(nothing clever here: this is the “correct” hyphenation of the word, in the current ta-
bles). However, there’s a problem here: just as words with accents in them won’t break,
so \hyphenation commands with accents in them produce an error:
\usepackage[french]{babel}
\selectlanguage{french}
\hyphenation{r\’e-f\’e-rence}
tells us that the hyphenation is “improper”, and that it will be “flushed”. But, just as
hyphenation of words is enabled by selecting an 8-bit font encoding, so \hyphenation
commands are rendered proper again by selecting that same 8-bit font encoding. For
the hyphenation patterns provided in the usual distributions, the encoding is Cork, so
the complete sequence is:
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\selectlanguage{french}
\hyphenation{r\’e-f\’e-rence}
The same sort of performance goes for any language for which 8-bit fonts and
corresponding hyphenation patterns are available. Since you have to select both the
language and the font encoding to have your document typeset correctly, it should not
be a great imposition to do the selections before setting up hyphenation exceptions.
163
bold (by comparison with other fixed-width fonts), and bold small-caps is not popular
with many professional typographers).
There’s a set of “extra” MetaFont files on CTAN that provide bold versions of
both cmtt and cmcsc (the small caps font). With modern TeX distributions, one may
bring these fonts into use simply by placing them in an appropriate place in the texmf
tree (these are (La)TeX-specific files, so the “public” supplier would be an appropriate
place). Once you’ve rebuilt the file indexes as necessary, TeX (and friends) will auto-
matically build whatever font files they need when you first make reference to them.
There’s a jiffy package bold-extra that builds the necessary font data structures so that
you can use the fonts within LaTeX.
Another alternative is to use the EC fonts, which come with bold variants of the
small-caps fonts.
If you need to use Type 1 fonts, you can’t proceed with Knuth-style fonts, since
there are no Type 1 versions of the mf-extra set. There are, however, Type 1 distribu-
tions of the EC fonts, so you can switch to EC and use them; alternatives are discussed
in 8-bit Type 1 fonts.
Of course, commercial fixed-width fonts (even the default Courier) almost always
come with a bold variant, so that’s not a problem. Furthermore PSNFSS will usually
provide “faked” small caps fonts, and has no compunctions about providing them in
a bold form. Courier is (as we all know, to our cost) freely available; a far more
presentable monospace font is LuxiMono, which is also freely available (monospace
text in the typeset version of this FAQ uses LuxiMono, with the metrics and LaTeX
support available on the archive.
bold-extra.sty : macros/latex/contrib/misc/bold-extra.sty
bold tt and small caps fonts: fonts/cm/mf-extra/bold
rmfamilyLuxiMono fonts: fonts/LuxiMono
...
\noindent%
\eqparbox{place}{\textbf{Thingamabobs, Ltd.}} \hfill
\eqparbox{title}{\textbf{Lead Engineer}} \hfill
\eqparbox{dates}{\textbf{9/92--12/94}}
The code makes the three items on each of the heading lines have exactly the same
width, so that the lines as a whole produce a regular pattern down the page. A command
\eqboxwidth allows you to use the measured width of a group: the documentation
shows how the command may be used to produce sensible-looking columns that mix
c-, r- or l-rows, with the equivalent of a p{...} entry, by making the fixed-width rows
an eqparbox group, and making the last from a \parbox using the width that’s been
measured for the group.
164
The varwidth package defines a varwidth environment which sets the content of
the box to match a “narrower natural width” if it finds one. (You give it the same param-
eters as you would give minipage: in effect, it is a ‘drop-in’ replacement.) Varwidth
provides its own ragged text command: \narrowragged, which aims to make narrower
lines and to put more text in the last line of the paragraph (thus producing lines with
more nearly equal lengths than typically happens with \raggedright itself).
The documentation (in the package file) lists various restrictions and things still to
be done, but the package is already proving useful for a variety of jobs.
eqparbox.sty : macros/latex/contrib/eqparbox
pbox.sty : macros/latex/contrib/pbox
varwidth.sty : macros/latex/contrib/misc/varwidth.sty
R Symbols, etc.
282 Symbols for the number sets
It is a good idea to have commands such as \R for the real numbers and other standard
number sets. Traditionally these were typeset in bold. Because, in the ordinary course
of events, mathematicians do not have access to bold chalk, they invented the special
symbols that are now often used for \R, \C, etc. These symbols are known as “black-
board bold”. Before insisting on using them, consider whether going back to the old
system of ordinary bold might not be acceptable (it is certainly simpler).
A set of blackboard bold capitals is available in the AMS msbm fonts (msbm is
available at a range of design sizes, with names such as msbm10). The pair of font
families (the other is called msam) have a large number of mathematical symbols to
supplement the ones in the standard TeX distribution, and are available in Type 1 format
with most modern distributions. Support files for using the fonts, both under Plain TeX
and LaTeX (packages amssymb and amsfonts), are available. The font shape is a rather
austere sans, which many people don’t like (though it captures the essence of quickly-
chalked writing rather well).
The bbold family is set of blackboard bold fonts written in MetaFont. This set offers
blackboard bold forms of lower-case letters; the font source directory also contains
sources for a LaTeX package that enables use of the fonts. The fonts are not available
in Type 1 format.
The bbm family claims to provide ‘blackboard’ versions of most of the cm fonts . . .
including the bold and bold-extended series. Again, the fonts are designed in MetaFont
and are not available in Type 1 format. LaTeX macro support comes from a package
by Torsten Hilbrich.
The doublestroke family comes in just roman and sans shapes, at a single weight,
and is available both as MetaFont sources and as Type 1; the font covers the uppercase
latin letters, lowercase ‘h’ and ’k’, and the digit ‘1’.
An alternative source of Type 1 fonts with blackboard bold characters may be found
in the steadily increasing set of complete families, both commercial and free, that have
been prepared for use with (La)TeX (see choice of outline fonts). Of the free sets, the
txfonts and pxfonts families both come with replicas of msam and msbm (though, as
noted elsewhere, there are other reasons not to use these fonts). The mathpazo family
includes a “mathematically significant” choice of blackboard bold characters, and the
fourier fonts contain blackboard bold upper-case letters, the digit ‘1’, and lower-case
‘k’.
The “lazy person’s” blackboard bold macros:
\newcommand{\R}{{\sf R\hspace*{-0.9ex}%
\rule{0.15ex}{1.5ex}\hspace*{0.9ex}}}
\newcommand{\N}{{\sf N\hspace*{-1.0ex}%
\rule{0.15ex}{1.3ex}\hspace*{1.0ex}}}
\newcommand{\Q}{{\sf Q\hspace*{-1.1ex}%
\rule{0.15ex}{1.5ex}\hspace*{1.1ex}}}
\newcommand{\C}{{\sf C\hspace*{-0.9ex}%
\rule{0.15ex}{1.3ex}\hspace*{0.9ex}}}
165
are almost acceptable at normal size if the surrounding text is cmr10. However, they are
not part of a proper maths font, and so do not work in sub- and superscripts. Moreover,
the size and position of the vertical bar can be affected by the font of the surrounding
text. As we’ve seen, there are plenty of alternatives: don’t try the macros, or anything
similar using capital ‘I’ (which looks even worse!).
AMS support files (Plain): fonts/amsfonts/plaintex
AMS support files (LaTeX): fonts/amsfonts/latex
AMS symbol fonts: fonts/amsfonts/sources/symbols
AMS symbol fonts in Type 1 format: Browse fonts/amsfonts/ps-type1
bbm fonts: fonts/cm/bbm
bbm macros: macros/latex/contrib/bbm
bbold fonts: fonts/bbold
doublestroke fonts: fonts/doublestroke
fourier fonts: fonts/fourier-GUT
mathpazo fonts: fonts/mathpazo
pxfonts: fonts/pxfonts
txfonts: fonts/txfonts
Euler The eucal package (part of most sensible TeX distributions; the fonts are part
of the AMS font set) gives a slightly curlier font than the default. The package
changes the font that is selected by \mathcal.
Type 1 versions of the fonts are available in the AMS fonts distribution.
RSFS The mathrsfs package uses a really fancy script font (the name stands for “Ralph
Smith’s Formal Script”) which is already part of most modern TeX distributions.
The package creates a new command \mathscr.
Type 1 versions of the font have been made available by Taco Hoekwater.
Zapf Chancery is the standard PostScript calligraphic font. There is no package but
you can easily make it available by means of the command
\DeclareMathAlphabet{\mathscr}{OT1}{pzc}%
{m}{it}
in your preamble. You may find the font rather too big; if so, you can use a scaled
version of it like this:
\DeclareFontFamily{OT1}{pzc}{}
\DeclareFontShape{OT1}{pzc}{m}{it}%
{<-> s * [0.900] pzcmi7t}{}
\DeclareMathAlphabet{\mathscr}{OT1}{pzc}%
{m}{it}
Adobe Zapf Chancery (which the above examples use) is distributed in any but
the most basic PostScript printers. A substantially identical font (to the extent
that the same metrics may be used) is available from URW and is distributed with
ghostscript.
Examples of the available styles are available on CTAN.
eucal.sty : fonts/amsfonts/latex/eucal.sty
euler fonts: fonts/amsfonts/sources/euler
euler fonts, in Type 1 format: fonts/amsfonts/ps-type1
ghostscript: Browse nonfree/support/ghostscript
mathrsfs.sty : Distributed as part of macros/latex/contrib/jknappen
rsfs fonts: fonts/rsfs
rsfs fonts, in Type 1 format: fonts/rsfs/ps-type1/hoekwater
Script font examples: info/symbols/math/scriptfonts.pdf
166
284 Setting bold Greek letters in LaTeX
The issue here is complicated by the fact that \mathbf (the command for setting bold
text in TeX maths) affects a select few mathematical symbols (the uppercase Greek
letters). However lower-case Greek letters behave differently from upper-case Greek
letters (due to Knuth’s esoteric font encoding decisions). However, \mathbf can’t be
used even for upper-case Greek letters in the AMSLaTeX amsmath package, which
disables this font-switching and you must use one of the techniques outlined below.
The Plain TeX solution does work, in a limited way:
{\boldmath$\theta$}
but \boldmath may not be used in maths mode, so this ‘solution’ requires arcana such
as:
$... \mbox{\boldmath$\theta$} ...$
The construction isn’t in the least robust (in the normal English sense of the word), but
it is robust under expansion (i.e., the LaTeX sense of the word); so use it with care, but
don’t worry about section headings and the like.
underscore.sty : macros/latex/contrib/misc/underscore.sty
168
euro fonts: fonts/euro
euro-ce fonts: fonts/euro-ce
eurofont.sty : macros/latex/contrib/eurofont
eurosym fonts: fonts/eurosym
marvosym fonts: fonts/psfonts/marvosym
textcomp.sty : Part of the LaTeX distribution.
\textsuperscript{\textregistered}
S Macro programming
S.1 “Generic” macros and techniques
290 Finding the width of a letter, word, or phrase
Put the word in a box, and measure the width of the box. For example,
\newdimen\stringwidth
\setbox0=\hbox{hi}
\stringwidth=\wd0
Note that if the quantity in the \hbox is a phrase, the actual measurement only approx-
imates the width that the phrase will occupy in running text, since the inter-word glue
can be adjusted in paragraph mode.
The same sort of thing is expressed in LaTeX by:
\newlength{\gnat}
\settowidth{\gnat}{\textbf{small}}
This sets the value of the length command \gnat to the width of “small” in bold-face
text.
291 Patching existing commands
In the general case (possibly sticking something in the middle of an existing command)
this is difficult. However, the common requirement, to add some code at the beginning
or the end of an existing command, is conceptually quite easy. Suppose we want to
define a version of a command that does some small extension of its original definition:
we would naturally write:
\renewcommand{\splat}{\mumble\splat}
However, this would not work: a call to \splat would execute \mumble, and the call
the redefined \splat again; this is an infinite recursive loop, that will quickly exhaust
TeX’s memory.
Fortunately, the TeX primitive \let command comes to our rescue; it allows us
to take a “snapshot” of the current state of a command, which we can then use in the
redefinition of the command. So:
169
\let\OldSmooth\smooth
\renewcommand{\smooth}{\mumble\OldSmooth}
effects the required patch, safely. Adding things at the end of a command works simi-
larly. If \smooth takes arguments, one must pass them on:
\renewcommand{\smooth}[2]{\mumble\OldSmooth{#1}{#2}}
The general case may be achieved in two ways. First, one can use the LaTeX
command \CheckCommand; this compares an existing command with the definition
you give it, and issues a warning if two don’t match. Use is therefore:
\CheckCommand{\complex}{horiginal definitioni}
\renewcommand{\complex}{hnew definitioni}
This technique is obviously somewhat laborious, but if the original command comes
from a source that’s liable to change under the control of someone else, it does at least
warn you that your patch is in danger of going wrong.
Otherwise, LaTeX users may use one of the patch or patchcmd systems.
Patch gives you an ingenious (and difficult to understand) mechanism, and comes
as an old-style LaTeX documented macro file. Sadly the old-style doc macros are no
longer available, but the file (patch.doc) may be input directly, and the documentation
may be read (un-typeset). Roughly speaking, one gives the command a set of instruc-
tions analagous to sed substitutions, and it regenerates the command thus amended.
The author of this FAQ has (slightly reluctantly) given up using patch. . .
The patchcmd package addresses a slightly simpler task, by restricting the set
of commands that you may patch; you mayn’t patch any command that has an
optional argument, though it does deal with the case of commands defined with
\DeclareRobustCommand. The package defines a \patchcommand command, that
takes three arguments: the command to patch, stuff to stick at the front of its def-
inition, and stuff to stick on the end of its definition. So, if \b contains “b”, then
\patchcommand\b{a}{c} will produce a new version of \b that contains “abc”.
patch.doc: macros/generic/misc/patch.doc
patchcommand.sty : macros/latex/contrib/patchcmd
\def\StripPrefix#1>{}
\def\jobis#1{FF\fi
\def\predicate{#1}%
\edef\predicate{\expandafter\StripPrefix\meaning\predicate}%
\edef\job{\jobname}%
\ifx\job\predicate
}
\if\jobis{mainfile}%
\message{YES}%
\else
\message{NO}%
\fi
Note that the command \StripPrefix need not be defined if you’re using LaTeX —
there’s already an internal command \strip@prefix that you can use.
170
293 Is the argument a number?
TeX’s own lexical analysis doesn’t offer the macro programmer terribly much support:
while category codes will distinguish letters (or what TeX currently thinks of as letters)
from everything else, there’s no support for analysing numbers.
The simple-minded solution is to compare numeric characters with the characters
of the argument, one by one, by a sequence of direct tests, and to declare the argument
“not a number” if any character fails all comparisons:
\ifx1#1
\else\ifx2#1
...
\else\ifx9#1
\else\isanumfalse
\fi\fi...\fi
which one would then use in a tail-recursing macro to gobble an argument. One could
do slightly better by assuming (pretty safely) that the digits’ character codes are con-
secutive:
\ifnum‘#1<‘0 \isanumfalse
\else\ifnum‘#1>‘9 \isanumfalse
\fi
\fi
again used in tail-recursion. However, these forms aren’t very satisfactory: getting the
recursion “right” is troublesome (it has a tendency to gobble spaces in the argument),
and in any case TeX itself has mechanisms for reading numbers, and it would be nice
to use them.
Donald Arseneau’s cite package offers the following test for an argument being a
strictly positive integer:
\def\IsPositive#1{%
TT\fi
\ifcat_\ifnum0<0#1 _\else A\fi
}
(which technique is due to David Kastrup); this can provoke errors. In a later thread on
the same topic, Michael Downes offered:
\def\IsInteger#1{%
TT\fi
\begingroup \lccode‘\-=‘\0 \lccode‘+=‘\0
\lccode‘\1=‘\0 \lccode‘\2=‘\0 \lccode‘\3=‘\0
\lccode‘\4=‘\0 \lccode‘\5=‘\0 \lccode‘\6=‘\0
\lccode‘\7=‘\0 \lccode‘\8=‘\0 \lccode‘\9=‘\0
171
\lowercase{\endgroup
\expandafter\ifx\expandafter\delimiter
\romannumeral0\string#1}\delimiter
}
The LaTeX memoir class has an internal command of its own, \checkifinteger
{num}, that sets the conditional command \ifinteger according to whether the ar-
gument was an integer.
Of course, all this kerfuffle would be (essentially) void if there was a simple means
of “catching” TeX errors. Imagining an error-catching primitive \ifnoerror, one
might write:
\def\IsInteger#1{%
TT%
\ifnoerror
\tempcount=#1\relax
% carries on if no error
\expandafter\iftrue
\else
% here if there was an error
\expandafter\iffalse
\fi
}
thus using TeX’s own integer-parsing code to do the check. It’s a pity that such a
mechanism was never defined (it could be that it’s impossible to program within TeX!).
memoir.cls: macros/latex/contrib/memoir
\def\a#1{+++#1+++#1+++#1+++} \a{b}
the macro expansion produces ‘+++b+++b+++b+++’, which people find normal. How-
ever, if we now replace part of the macro:
\def\a#1{+++#1+++\def\x #1{xxx#1}}
\def\a#1{+++#1+++\def\x ##1{xxx##1}}
172
295 Spaces in macros
It’s very easy to write macros that produce space in the typeset output where it’s neither
desired nor expected. Spaces introduced by macros are particularly insidious because
they don’t amalgamate with spaces around the macro (unlike consecutive spaces that
you type), so your output can have a single bloated space that proves to be made up
of two or even more spaces that haven’t amalgamated. And of course, your output can
also have a space where none was wanted at all.
Spaces are produced, inside a macro as elsewhere, by space or tab characters, or by
end-of-line characters. There are two basic rules to remember when writing a macro:
first, the rules for ignoring spaces when you’re typing macros are just the same as the
rules that apply when you’re typing ordinary text, and second, rules for ignoring spaces
do not apply to spaces produced while a macro is being obeyed (“expanded”).
Spaces are ignored in vertical mode (between paragraphs), at the beginning of a
line, and after a command name. Since sequences of spaces are collapsed into one, it
‘feels as if’ spaces are ignored if they follow another space. Space can have syntactic
meaning after certain sorts of non-braced arguments (e.g., count and dimen variable
assignments in Plain TeX) and after certain control words (e.g., in \hbox to, so again
we have instances where it ‘feels as if’ spaces are being ignored when they’re merely
working quietly for their living.
Consider the following macro, fairly faithfully adapted from one that appeared on
comp.text.tex:
• after the opening { of the macro body; this space will be ignored, not because
“because the macro appears at the start of a line”, but rather because the macro
was designed to operate between paragraphs
• after \bigskip; this space will be ignored (while the macro is being defined)
because it follows a command name
• after the { of the mandatory argument of \makebox; even though this space will
inevitably appear at the start of an output line, it will not be ignored
• after the } closing the argument of \textbf; this space will not be ignored, but
may be overlooked if the argument is well within the 2cm allowed for it
• after the } closing the mandatory argument of \makebox; this space will not be
ignored
The original author of the macro had been concerned that the starts of his lines with this
macro in them were not at the left margin, and that the text appearing after the macro
wasn’t always properly aligned. These problems arose from the space at the start of the
mandatory argument of \makebox and the space immediately after the same argument.
He had written his macro in that way to emphasise the meaning of its various parts;
unfortunately the meaning was rather lost in the problems the macro caused.
The principal technique for suppressing spaces is the use of % characters: everything
after a % is ignored, even the end of line itself (so that not even the end of line can
contribute an unwanted space). The secondary technique is to ensure that the end of
line is preceded by a command name (since the end of line behaves like a space, it will
be ignored following a command name). Thus the above command would be written
(by an experienced programmer with a similar eye to emphasising the structure):
\newcommand{\stline}[1]{%
\bigskip
\makebox[2cm]{%
\textbf{#1}\relax
}%
}
Care has been taken to ensure that every space in the revised definition is ignored, so
none appears in the output. The revised definition takes the “belt and braces” approach,
explicitly dealing with every line ending (although, as noted above, a space introduced
at the end of the first line of the macro would have been ignored in actual use of the
macro. This is the best technique, in fact — it’s easier to blindly suppress spaces than
173
to analyse at every point whether you actually need to. Three techniques were used to
suppress spaces:
• placing a % character at the end of a line (as in the 1st, 3rd and 5th lines),
• ending a line ‘naturally’ with a control sequence, as in line 2, and
• ending a line with an ‘artificial’ control sequence, as in line 4; the control sequence
in this case (\relax) is a no-op in many circumstances (as here), but this usage is
deprecated — a % character would have been better.
is intrinsically limited to just 9 arguments. There’s no direct way round this: how
would you express a 10th argument? — and ensure that the syntax didn’t gobble some
other valid usage?
If you really must have more than 9 arguments, the way to go is:
This technique is easily extendible by concert pianists of the TeX keyboard, but is really
hard to recommend.
LaTeX users have the small convenience of merely giving a number of arguments in
the \newcommand that defines each part of the relaying mechanism: Knuth’s restriction
applies to \newcommand just as it does to \def. However, LaTeX users also have the
way out of such barbarous command syntax: the keyval package. With keyval, and a bit
of programming, one can write really quite sophisticated commands, whose invocation
might look like:
\flowerinstance{species=Primula veris,
family=Primulaceae,
location=Coldham’s Common,
locationtype=Common grazing land,
date=1995/04/24,
numplants=50,
soiltype=alkaline
}
The merit of such verbosity is that it is self-explanatory: the typist doesn’t have to
remember that argument twelve is soiltype, and so on: the commands may be copied
from field notes quickly and accurately.
keyval.sty : Distributed as part of macros/latex/required/graphics
174
297 Defining characters as macros
Single characters can act as macros (defined commands), and both Plain TeX and
LaTeX define the character “~” as a “non-breakable space”. A character is made
definable, or “active”, by setting its category code (catcode) to be \active (13):
\catcode‘_=\active.
Any character could, in principle, be activated this way and defined as a macro
(\def_{\_} — the simple answer to using underscores), but you must be wary:
whereas people expect an active tilde, other active characters may be unexpected and
interact badly with other macros. Furthermore, by defining an active character, you
preclude the character’s use for other purposes, and there are few characters “free” to
be subverted in this way.
To define the character “z” as a command, one would say something like:
\catcode‘\z=\active
\def z{Yawn, I’m tired}%
and each subsequent “z” in the text would become a yawn. This would be an astound-
ingly bad idea for most documents, but might have special applications. (Note that,
in “\def z”, “z” is no longer interpreted as a letter; the space is therefore not neces-
sary — “\defz” would do; we choose to retain the space, for what little clarity we can
manage.) Some LaTeX packages facilitate such definitions. For example, the shortvrb
package with its \MakeShortVerb command.
TeX uses category codes to interpret characters as they are read from the input.
Changing a catcode value will not affect characters that have already been read.
Therefore, it is best if characters have fixed category codes for the duration of a docu-
ment. If catcodes are changed for particular purposes (the \verb command does this),
then the altered characters will not be interpreted properly when they appear in the
argument to another command (as, for example, in \verb in command arguments).
An exemplary case is the doc package, which processes .dtx files using the shortvrb
package to define |...| as a shorthand for \verb|...|. But | is also used in the
preambles of tabular environments, so that tables in .dtx files can only have vertical
line separation between columns by employing special measures of some sort.
Another consequence is that catcode assignments made in macros often don’t work
as expected (Active characters in command arguments). For example, the definition
\def\mistake{%
\catcode‘_=\active
\def_{\textunderscore\-}%
}
does not work because it attemts to define an ordinary _ character: When the macro
is used, the category change does not apply to the underscore character already in the
macro definition. Instead, one may use:
\begingroup
\catcode‘_=\active
\gdef\works{% note the global \gdef
\catcode‘_=\active
\def_{\textunderscore\-}%
}
\endgroup
The alternative (“tricksy”) way of creating such an isolated definition depends on the
curious properties of \lowercase, which changes characters without altering their cat-
codes. Since there is always one active character (“~”), we can fool \lowercase into
patching up a definition without ever explicitly changing a catcode:
\begingroup
\lccode‘\~=‘\_
\lowercase{\endgroup
\def~{\textunderscore\-}%
}%
175
The two definitions have the same overall effect (the character is defined as a com-
mand, but the character does not remain active), except that the first defines a \global
command.
For active characters to be used only in maths mode, it is much better to leave the
character having its ordinary catcode, but assign it a special active maths code, as with
\begingroup
\lccode‘~=‘x
\lowercase{\endgroup
\def~{\times}%
}%
\mathcode‘x="8000
The special character does not need to be redefined whenever it is made active — the
definition of the command persists even if the character’s catcode reverts to its original
value; the definition becomes accessible again if the character once again becomes
active.
doc.sty : Distributed as part of the source of LaTeX, macros/latex/base
shortvrb.sty : Distributed as part of macros/latex/required/tools
\begingroup
\catcode‘\#=\active
\gdef#{$\sharp$}
\endgroup
and:
\begingroup
\lccode‘\~=‘\b
\lowercase{\endgroup
\def~{$\flat$}%
}
The second problem is one of timing: the command has to make each character ac-
tive before its arguments are read: this means that the command can’t actually “have”
arguments itself, but must be split in two. So we write:
\def\chord{%
\begingroup
\catcode‘\#=\active
\catcode‘\b=\active
\Xchord
}
\def\Xchord#1{%
\chordfont#1%
\endgroup
}
176
• \begingroup in \chord opens a group that is closed by \endgroup in \Xchord;
this group limits the change of category codes, which is the raison d’être of the
whole exercise.
• Although # is active while \Xchord is executed, it’s not active when it’s being
defined, so that the use of #1 doesn’t require any special attention.
Note that the technique used in such macros as \chord, here, is analagous to that
used in such commands as \verb; and, in just the same way as \verb (see \verb
doesn’t work in arguments), \chord won’t work inside the argument of another com-
mand (the error messages, if they appear at all, will probably be rather odd).
299 Defining a macro from an argument
It’s common to want a command to create another command: often one wants the new
command’s name to derive from an argument. LaTeX does this all the time: for exam-
ple, \newenvironment creates start- and end-environment commands whose names
are derived from the name of the environment command.
The (seemingly) obvious approach:
\def\relay#1#2{\def\#1{#2}}
doesn’t work (the TeX engine interprets it as a rather strange redefinition of \#). The
trick is to use \csname, which is a TeX primitive for generating command names from
random text, together with \expandafter. The definition above should read:
\def\relay#1#2{%
\expandafter\def\csname #1\endcsname{#2}%
}
With commands
\def\start#1{\csname start#1\endcsname}
\def\finish#1{\csname finish#1\endcsname}
177
of view, \DeclareRobustCommand should be treated as a non-checking version of
\newcommand.
LaTeX commands are, by default, defined \long; an optional * between the
\newcommand and its (other) arguments specifies that the command is not to be defined
\long. The * is detected by a command \@ifstar which uses \futurelet to switch
between two branches, and gobbles the *: LaTeX users are encouraged to think of the
* as part of the command name.
LaTeX’s checks for unknown command are done by \ifx comparison of a \csname
construction with \relax; since the command name argument is the desired control
sequence name, this proves a little long-winded. Since #1 is the requisite argument, we
have:
\expandafter\ifx
\csname\expandafter\@gobble\string#1\endcsname
\relax
...
In the last case, \foo may be called as \foo{goodbye}, which is equivalent to \foo
[boo]{goodbye} (employing the default value given for the first argument), or as \foo
[hello]{goodbye} (with an explicit first argument).
Coding of commands with optional arguments is exemplified by the coding of the
last \foo above:
\def\foo{\futurelet\next\@r@foo}
\def\@r@foo{\ifx\next[%
\let\next\@x@foo
\else
\def\next{\@x@foo[boo]}%
\fi
\next
}
\def\@x@foo[#1]#2{...#1...#2...}
The case where you want to ignore an argument that consists of nothing but spaces,
rather than something completely empty, is more tricky. It’s solved in the code frag-
ment ifmtarg, which defines commands \@ifmtarg and \@ifnotmtarg, which distin-
guish (in opposite directions) between a second and third argument. The package’s
code also appears in the LaTeX memoir class.
Ifmtarg makes challenging reading; there’s also a discussion of the issue in number
two of the “around the bend” articles by the late lamented Mike Downes.
178
Around the bend series: info/aro-bend
ifmtarg.sty : macros/latex/contrib/misc/ifmtarg.sty
memoir.cls: macros/latex/contrib/memoir
\ifx\pdfoutput\undefined
<not running PDFTeX>
\else
<running PDFTeX>
\fi
Except that neither branch of this conditional is rock-solid. The first branch can be
misleading, since the “awkward” user could have written:
\let\pdfoutput\undefined
so that your test will falsely choose the first alternative. While this is a theoretical
problem, it is unlikely to be a major one.
More important is the user who loads a package that uses LaTeX-style testing for
the command name’s existence (for example, the LaTeX graphics package, which is
useful even to the Plain TeX user). Such a package may have gone ahead of you, so the
test may need to be elaborated:
\ifx\pdfoutput\undefined
<not running PDFTeX>
\else
\ifx\pdfoutput\relax
<not running PDFTeX>
\else
<running PDFTeX>
\fi
\fi
If you only want to know whether some PDFTeX extension (such as marginal kerning)
is present, you can stop at this point: you know as much as you need.
However, if you need to know whether you’re creating PDF output, you also need
to know about the value of \pdfoutput:
\ifx\pdfoutput\undefined
<not running PDFTeX>
\else
\ifx\pdfoutput\relax
<not running PDFTeX>
\else
<running PDFTeX, with...>
\ifnum\pdfoutput>0
<...PDF output>
\else
<...DVI output>
\fi
\fi
\fi
The above is, in essence, what Heiko Oberdiek’s ifpdf package does; the reasoning is
the FAQ’s interpretation of Heiko’s explanation.
ifpdf.sty : Distributed with Heiko Oberdiek’s packages macros/latex/
contrib/oberdiek
179
303 Subverting a token register
A common requirement is to “subvert” a token register that other macros may use.
The requirement arises when you want to add something to a system token register
(\output or \every*), but know that other macros use the token register, too. (A
common requirement is to work on \everypar, but LaTeX changes \everypar at
every touch and turn.)
The following technique, due to David Kastrup, does what you need, and allows an
independent package to play the exact same game:
\let\mypkg@@everypar\everypar
\newtoks\mypkg@everypar
\mypkg@everypar\expandafter{\the\everypar}
\mypkg@@everypar{\mypkgs@ownstuff\the\mypkg@everypar}
\def\mypkgs@ownstuff{%
<stuff to do at the start of the token register>%
}
\let\everypar\mypkg@everypar
• creates an alias for the existing “system” \everypar (which is frozen into any
surrounding environment, which will carry on using the original);
• creates a token register to subvert \everypar and initialises it with the current
contents of \everypar;
• sets the “old” \everypar to execute its own extra code, as well as the contents of
its own token register;
• defines the macro for the extra code; and
• points the token \everypar at the new token register.
180
wherever possible: the possibilities of confusion with constructs that vary their be-
haviour according to the font size that LaTeX has recorded are (sadly) legion. A really
rather funny example is to be had by saying:
\documentclass{article}
\begin{document}
\font \myfont=cmr17 scaled 2000
\myfont
\LaTeX
\end{document}
(the reader is encouraged to try this). The “A” of LaTeX has pretty much disappeared:
LaTeX sets the “A” according to its idea of the font size (10pt), but “\myfont” is more
than three times that size.
Another “\myfont” example arises from an entirely different source. The mini-
document:
\documentclass{article}
\begin{document}
\font \myfont=ecrm1000
{\myfont par\‘a}
\end{document}
gives you “German low double quotes” in place of the grave accent. This problem
arises because ecrm1000 is in a different font encoding than LaTeX is expecting — if
you use LaTeX font commands, all the tiresome encoding issues are solved for you,
behind the scenes.
So, whether you’re dealing with a one-off font or a major new family, you are far
more likely to be satisfied with the LaTeX file selection system, so it’s worth investing
a small amount of effort to write declarations of the font’s family and how it should
be loaded. For details of the commands you need, see the LaTeX font usage guide,
fntguide: this may be viewed on the archive, but you should find a copy of the docu-
ment in your own system.
fntguide.pdf : macros/latex/doc/fntguide.pdf
fntguide.tex : Distributed with macros/latex/base
*\makeatletter
*\show\protected@edef
> \protected@edef=macro:
->\let \@@protect \protect
\let \protect \@unexpandable@protect
\afterassignment \restore@protect \edef .
(I’ve rearranged the output there, from the rather confused version TeX itself produces.)
We may perhaps, now, wonder about \@unexpandable@protect:
182
*\show\@unexpandable@protect
> \@unexpandable@protect=macro:
->\noexpand \protect \noexpand .
and we’re starting to see how one part of the \protection mechanism works (one can
probably fairly safely guess what \restore@protect does).
Many kernel commands are declared robust:
*\show\texttt
> \texttt=macro:
->\protect \texttt .
so that \show isn’t much help. Define a command \pshow as shown below, and use
that instead:
*\def\pshow#1{{\let\protect\show #1}}
*\pshow\texttt
> \texttt =\long macro:
#1->\ifmmode \nfss@text {\ttfamily #1}%
\else \hmode@bgroup \text@command {#1}%
\ttfamily \check@icl #1\check@icr
\expandafter \egroup \fi .
Note that the command name that is protected is the ‘base’ command, with a space
appended. This is cryptically visible, in a couple of places above. (Again, the output
has been sanitised.)
If one has a malleable text editor, the same investigation may more comfortably be
conducted by examining the file latex.ltx (which is usually to be found, in a TDS
system, in directory tex/latex/base).
In fact, latex.ltx is the product of a docstrip process on a large number of
.dtx files, and you can refer to those instead. The LaTeX distribution includes a file
source2e.tex, and most systems retain it, again in tex/latex/base. Source2e.tex
may be processed to provide a complete source listing of the LaTeX kernel (in fact the
process isn’t entirely straightforward, but the file produces messages advising you what
to do). The result is a huge document, with a line-number index of control sequences
the entire kernel and a separate index of changes recorded in each of the files since the
LaTeX team took over.
The printed kernel is a nice thing to have, but it’s unwieldy and sits on my shelves,
seldom used. One problem is that the comments are patchy: the different modules
range from well and lucidly documented, through modules documented only through
an automatic process that converted the documentation of the source of LaTeX 2.09, to
modules that hardly had any useful documentation even in the LaTeX 2.09 original.
In fact, each kernel module .dtx file will process separately through LaTeX, so
you don’t have to work with the whole of source2e. You can easily determine which
module defines the macro you’re interested in: use your “malleable text editor” to find
the definition in latex.ltx; then search backwards from that point for a line that starts
%%% From File: — that line tells you which .dtx file contains the definition you are
interested in. Doing this for \protected@edef, we find:
%%% From File: ltdefns.dtx
\thing[opti]{manda}% #1="opti"
\end{document}
184
newcommand.py : support/newcommand
optparams.sty : Distributed as part of macros/latex/contrib/sauerj
twoopt.sty : Distributed as part of macros/latex/contrib/oberdiek
This does the trick, for sufficiently simple commands, but it has various tiresome failure
modes, and it requires \mycommandnostar to take an argument.
Of course, the LaTeX kernel has something slicker than this:
\newcommand{\mycommand}{\@ifstar
\mycommandStar%
\mycommandNoStar%
}
\newcommand{\mycommandStar}[2]{starred version}
\newcommand{\mycommandNoStar}[1]{normal version}
The package needs e-LaTeX, but any new enough distribution defines LaTeX as e-
LaTeX by default. Command arguments may be specified in the normal way, in both
command definitions (after the “*” in the \WithSuffix version). You can also use the
TeX primitive commands, creating a definition like:
\WithSuffix\gdef\mycommand*{starred version}
\newcommand{\abc}[1]{joy, oh #1!%
\newcommand{\ghi}[1]{gloom, oh #1!}%
}
followed by a call:
\cmdinvoke{abc}{joy}
typesets “joy, oh joy!”, but defines a command \ghi that takes one parameter, which it
ignores; \ghi{gloom} will expand to “gloom, oh joy!”, which is presumably not what
was expected.
And (as you will probably guess, if you’ve read the earlier question) the definition:
\newcommand{\abc}[1]{joy, oh #1!%
\newcommand{\ghi}[1]{gloom, oh ##1!}%
}
does what is required, and \ghi{gloom} will expand to “gloom, oh gloom!”, whatever
the argument to \abc.
The doubling is needed whether or not the enclosing command has an argument,
so:
186
\newcommand{\abc}{joy, oh joy!%
\newcommand{\ghi}[1]{gloom, oh ##1!}%
}
in the preamble of your document, and the job is done. (However, beware of the babel
package, which requires you to use a different mechanism: be sure to check changing
babel names if you’re using it.)
The names that are defined in the standard LaTeX classes (and the makeidex pack-
age) are listed below. Some of the names are only defined in a subset of the classes
(and the letter class has a set of names all of its own); the list shows the specialisation
of each name, where appropriate.
\abstractname Abstract
\alsoname see also (makeidx package)
\appendixname Appendix
\bibname Bibliography (report,book)
\ccname cc (letter)
\chaptername Chapter (report,book)
\contentsname Contents
\enclname encl (letter)
\figurename Figure (for captions)
\headtoname To (letter)
\indexname Index
\listfigurename List of Figures
\listtablename List of Tables
\pagename Page (letter)
\partname Part
\refname References (article)
\seename see (makeidx package)
\tablename Table (for caption)
315 Changing the words babel uses
LaTeX uses symbolic names for many of the automatically-generated text it produces
(special-purpose section headings, captions, etc.). As noted in “LaTeXfixed names”
(which includes a list of the names themselves), this enables the user to change the
names used by the standard classes, which is particularly useful if the document is
being prepared in some language other than LaTeX’s default English. So, for example,
a Danish author may wish that her table of contents was called “Indholdsfortegnelse”,
and so would expect to place a command
\renewcommand{\contentsname}%
{Indholdsfortegnelse}
in the preamble of her document.
However, it’s natural for a user of a non-English language to use babel, because
it offers many conveniences and typesetting niceties for those preparing documents
in those languages. In particular, when babel is selecting a new language, it ensures
that LaTeX’s symbolic names are translated appropriately for the language in question.
187
Unfortunately, babel’s choice of names isn’t always to everyone’s choice, and there is
still a need for a mechanism to replace the ‘standard’ names.
Whenever a new language is selected, babel resets all the names to the settings for
that language. In particular, babel selects the document’s main language when \begin
{document} is executed, which immediately destroys any changes to these symbolic
names made in the prologue of a document that uses babel.
Therefore, babel defines a command to enable users to change the definitions of
the symbolic names, on a per-language basis: \addto\captionshlanguagei is the
thing (hlanguagei being the language option you gave to babel in the first place). For
example:
\addto\captionsdanish{%
\renewcommand{\contentsname}%
{Indholdsfortegnelse}%
}
\makeatletter
\@removefromreset{figure}{chapter}
and the automatic renumbering stops. You then need to redefine the way in which the
figure number (in this case) is printed:
\renewcommand{\thefigure}{\@arabic\c@figure}
\makeatother
(remember to do the whole job, for every counter you want to manipulate, within
\makeatletter . . . \makeatother).
The technique may also be used to change where in a multilevel structure a counter
is reset. Suppose your class numbers figures as hchapteri.hsectioni.hfigurei, and you
want figures numbered per chapter, try:
\@removefromreset{figure}{section}
\@addtoreset{figure}{chapter}
\renewcommand{\thefigure}{\thechapter.\@arabic\c@figure}
188
the stepping methods above, you say \refstepcounter{foo}, the internal variable is
set to the new value, and (until something else comes along), \label will refer to the
counter.
318 Finding if you’re on an odd or an even page
Another question discusses the issue of getting \marginpar commands to put their
output in the correct margin of two-sided documents. This is an example of the general
problem of knowing where a particular bit of text lies: the output routine is asyn-
chronous, and (La)TeX will usually process quite a bit of the “next” page before de-
ciding to output any page. As a result, the page counter (known internally in LaTeX as
\c@page) is normally only reliable when you’re actually in the output routine.
The solution is to use some version of the \label mechanism to determine which
side of the page you’re on; the value of the page counter that appears in a \pageref
command has been inserted in the course of the output routine, and is therefore safe.
However, \pageref itself isn’t reliable: one might hope that
\ifthenelse{\isodd{\pageref{foo}}}{odd}{even}
would do the necessary, but both the babel and hyperref packages have been known to
interfere with the output of \pageref; be careful!
The chngpage package needs to provide this functionality for its own use, and
therefore provides a command \checkoddpage; this sets a private-use label, and the
page reference part of that label is then examined (in a hyperref -safe way) to set a con-
ditional \ifcpoddpage true if the command was issued on an odd page. The memoir
class has the same command setting a conditional \ifoddpage. Of course, the \label
contributes to LaTeX’s “Rerun to get cross-references right” error messages. . .
The Koma-Script classes have an addmargin* environment that also provides
the sorts of facilities that the chngpage offers. Koma-Script’s supporting command
is \ifthispageodd{<true>}{<false>} executes different things depending on the
page number.
chngpage.sty : macros/latex/contrib/misc/chngpage.sty
KOMA script bundle: macros/latex/contrib/koma-script
memoir.cls: macros/latex/contrib/memoir
which would be both tedious and error-prone. What’s more, it would be undesir-
able, since you would be constructing a visual representation which is inflexible (you
couldn’t change all the references to elements of a list at one fell swoop).
LaTeX in fact has a label-formatting command built into every label definition; by
default it’s null, but it’s available for the user to program. For any label hcounteri
there’s a LaTeX internal command \p@hcounter i; for example, a label definition on
an inner list item is supposedly done using the command \p@enumii{\theenumii}.
Unfortunately, the internal workings of this aren’t quite right, and you need to patch
the \refstepcounter command:
\renewcommand*\refstepcounter[1]{\stepcounter{#1}%
\protected@edef\@currentlabel{%
\csname p@#1\expandafter\endcsname
\csname the#1\endcsname
}%
}
With the patch in place you can now, for example, change the labels on all inner lists
by adding the following code in your preamble:
189
\makeatletter
\renewcommand{\p@enumii}[1]{\theenumi(#1)}
\makeatother
This would make the labels for second-level enumerated lists appear as “1(a)” (and so
on). The analogous change works for any counter that gets used in a \label command.
In fact, the fncylab package does all the above (including the patch to LaTeX it-
self). With the package, the code above is (actually quite efficiently) rendered by the
command:
\labelformat{enumii}{\theenumi(#1)}
In fact, the above example, which we can do in several different ways, has been ren-
dered obsolete by the appearance of the enumitem package, which is discussed in the
answer about decorating enumeration lists.
enumitem.sty : macros/latex/contrib/enumitem
fncylab.sty : macros/latex/contrib/misc/fncylab.sty
Many people (for some reason) want a stop after a section number, but not after a
subsection number, or any of the others. To do this, one must make \@seccntformat
switch according to its argument. The following technique for doing the job is slightly
wasteful, but is efficient enough for a relatively rare operation:
\let\@@seccntformat\@seccntformat
\renewcommand*{\@seccntformat}[1]{%
\expandafter\ifx\csname @seccntformat@#1\endcsname\relax
\expandafter\@@seccntformat
\else
\expandafter
\csname @seccntformat@#1\expandafter\endcsname
\fi
{#1}%
}
which looks to see if a second-level command has been defined, and uses it if so;
otherwise it uses the original. The second-level command to define stops after section
numbers (only) has the same definition as the original “all levels alike” version:
\newcommand*{\@seccntformat@section}[1]{%
\csname the#1\endcsname.\quad
}
Note that all the command definitions of this answer are dealing in LaTeX internal
commands, so the above code should be in a package file, for preference.
The Koma-script classes have different commands for specifying changes to sec-
tion number presentation: \partformat, \chapterformat and \othersectionlevelsformat,
but otherwise their facilities are similar to those of “raw” LaTeX.
KOMA script bundle: macros/latex/contrib/koma-script
190
321 There’s a space added after my environment
You’ve written your own environment env, and it works except that a space appears
at the start of the first line of typeset text after \end{env}. This doesn’t happen with
similar LaTeX-supplied environments.
You could impose the restriction that your users always put a “%” sign after the
environment . . . but LaTeX environments don’t require that, either.
The LaTeX environments’ “secret” is an internal flag which causes the unwanted
spaces to be ignored. Fortunately, you don’t have to use the internal form: since 1996,
LaTeX has had a user command \ignorespacesafterend, which sets the internal
flag.
322 Finding if a label is undefined
People seem to want to know (at run time) if a label is undefined (I don’t actually
understand why, particularly: it’s a transient state, and LaTeX deals with it quite well).
A resolved label is simply a command: \r@hlabel-namei; determining if the label
is set is then simply a matter of detecting if the command exists. The usual LaTeX
internal way of doing this is to use the command \@ifundefined:
\@ifundefined{r@label-name}{undef-cmds}{def-cmds}
In which, hlabel-namei is exactly what you would use in a \label command, and the
remaining two arguments are command sequences to be used if the label is undefined
(hundef-cmdsi) or if it is defined (hdef-cmdsi).
Note that any command that incorporates \@ifundefined is naturally fragile, so
remember to create it with \DeclareRobustCommand or to use it with \protect in a
moving argument.
If you’re into this game, you may well not care about LaTeX’s warning about un-
defined labels at the end of the document; however, if you are, include the command
\G@refundefinedtrue in hundef-cmdsi.
And of course, remember you’re dealing in internal commands, and pay attention
to the at-signs.
All the above can be avoided by using the labelcas package: it provides commands
that enable you to switch according to the state of a single label, or the states of a list
of labels. The package’s definition is a bit complicated, but the package itself is pretty
powerful.
labelcas.sty : macros/latex/contrib/labelcas
\newcounter{new-name}[master]
says that every time counter hmasteri is stepped, counter hnew-namei will be reset.
But what if you have an uncooperative package, that defines the objects for you,
but doesn’t provide a programmer interface to make the counters behave as you want?
The \newcounter command uses a LaTeX internal command, and you can also
use it:
\@addtoreset{new-name}{master}
\counterwithin*{corrollary}{theorem}
191
will make the corrollary counter slave to theorem counters. The command without its
asterisk:
\counterwithin{corrollary}{theorem}
will cause hcounteri to be reset for each page. The package uses a label-like mech-
anism, and may require more than one run of LaTeX to stabilise counter values —
LaTeX will generate the usual warnings about labels changing.
chngcntr.sty : macros/latex/contrib/misc/chngcntr.sty
perpage.sty : Distributed as part macros/latex/contrib/bigfoot
Most of the time this error can be fixed without enlarging TeX. The most common
causes are unmatched braces, extra-long lines, and poorly-written macros. Extra-long
lines are often introduced when files are transferred incorrectly between operating sys-
tems, and line-endings are not preserved properly (the tell-tale sign of an extra-long
line error is the complaint that the ‘buf_size’ has overflowed).
If you really need to extend your TeX’s capacity, the proper method depends on
your installation. There is no need (with modern TeX implementations) to change the
defaults in Knuth’s WEB source; but if you do need to do so, use a change file to modify
the values set in module 11, recompile your TeX and regenerate all format files.
Modern implementations allow the sizes of the various bits of TeX’s memory to be
changed semi-dynamically. Some (such as emTeX) allow the memory parameters to be
changed in command-line switches when TeX is started; most frequently, a configura-
tion file is read which specifies the size of the memory. On web2c-based systems, this
file is called texmf.cnf: see the documentation that comes with the distribution for
other implementations. Almost invariably, after such a change, the format files need to
be regenerated after changing the memory parameters.
325 Why can’t I load PiCTeX?
PiCTeX is a resource hog; fortunately, most modern TeX implementations offer gener-
ous amounts of space, and most modern computers are pretty fast, so users aren’t too
badly affected by its performance.
However, PiCTeX has the further unfortunate tendency to fill up TeX’s fixed-size
arrays — notably the array of 256 ‘dimension’ registers. This is a particular problem
when you’re using pictex.sty with LaTeX and some other packages that also need
dimension registers. When this happens, you will see the TeX error message:
192
! No room for a new \dimen.
There is nothing that can directly be done about this error: you can’t extend the number
of available \dimen registers without extending TeX itself. e-TeX and Omega both do
this, as does MicroPress Inc’s VTeX.
It’s actually quite practical (with most modern distributions) to use e-TeX’s ex-
tended register set: use package etex (which comes with e-TeX distributions) and the
allocation mechanism is altered to cope with the larger register set: PiCTeX will now
load.
If you’re in some situation where you can’t use e-TeX, you need to change PiCTeX;
unfortunately PiCTeX’s author is no longer active in the TeX world, so one must resort
to patching. There are two solutions available.
The ConTeXt module m-pictex.tex (for Plain TeX and variants) or the corre-
sponding LaTeX m-pictex package provide an ingenious solution to the problem based
on hacking the code of \newdimen itself.
Alternatively, Andreas Schell’s pictexwd and related packages replace PiCTeX with
a version that uses 33 fewer \dimen registers; so use pictexwd in place of pictex (either
as a LaTeX package, or as a file to read into Plain TeX).
And how does one use PiCTeX anyway, given that the manual is so hard to come
by? Fortunately for us all, the MathsPic system may be used to translate a somewhat
different language into PiCTeX commands; and the MathsPic manual is free (and part
of the distribution). MathsPic is available either as a Basic program for DOS, or as a
Perl program for other systems (including Windows, nowadays).
m-pictex.sty : Distributed as part of macros/context/current/cont-tmf.zip
m-pictex.tex : Distributed as part of macros/context/current/cont-tmf.zip
MathsPic: graphics/mathspic
pictexwd.sty : Distributed as part of graphics/pictex/addon
• Do your figures need to float at all? If not, consider the [H] placement option
offered by the float package: figures with this placement are made up to look as
if they’re floating, but they don’t in fact float. Beware outstanding floats, though:
the \caption commands are numbered in the order they appear in the document,
and a [H] float can ‘overtake’ a float that hasn’t yet been placed, so that figures
numbers get out of order.
• Are the placement parameters on your figures right? The default (tbp) is reason-
able, but you can reasonably change it (for example, to add an h). Whatever you
do, don’t omit the ‘p’: doing so could cause LaTeX to believe that if you can’t
have your figure here, you don’t want it anywhere. (LaTeX does try hard to avoid
being confused in this way. . . )
• LaTeX’s own float placement parameters could be preventing placements that
seem entirely “reasonable” to you — they’re notoriously rather conservative. To
encourage LaTeX not to move your figure, you need to loosen its demands. (The
most important ones are the ratio of text to float on a given page, but it’s sensible
to have a fixed set that changes the whole lot, to meet every eventuality.)
\renewcommand{\topfraction}{.85}
\renewcommand{\bottomfraction}{.7}
193
\renewcommand{\textfraction}{.15}
\renewcommand{\floatpagefraction}{.66}
\renewcommand{\dbltopfraction}{.66}
\renewcommand{\dblfloatpagefraction}{.66}
\setcounter{topnumber}{9}
\setcounter{bottomnumber}{9}
\setcounter{totalnumber}{20}
\setcounter{dbltopnumber}{9}
The meanings of these parameters are described on pages 199–200, section C.9 of
the LaTeX manual.
• Are there places in your document where you could ‘naturally’ put a \clearpage
command? If so, do: the backlog of floats is cleared after a \clearpage. (Note
that the \chapter command in the standard book and report classes implicitly
executes \clearpage, so you can’t float past the end of a chapter.)
• Try the placeins package: it defines a \FloatBarrier command beyond which
floats may not pass. A package option allows you to declare that floats may not
pass a \section command, but you can place \FloatBarriers wherever you
choose.
• If you are bothered by floats appearing at the top of the page (before they are spec-
ified in your text), try the flafter package, which avoids this problem by insisting
that floats should always appear after their definition.
• Have a look at the LaTeX 2ε afterpage package. Its documentation gives as an
example the idea of putting \clearpage after the current page (where it will clear
the backlog, but not cause an ugly gap in your text), but also admits that the pack-
age is somewhat fragile. Use it as a last resort if the other possibilities below don’t
help.
• If you would actually like great blocks of floats at the end of each of your chapters,
try the morefloats package; this ‘simply’ increases the number of floating inserts
that LaTeX can handle at one time (from 18 to 36).
• If you actually wanted all your figures to float to the end (e.g., for submitting a draft
copy of a paper), don’t rely on LaTeX’s mechanism: get the endfloat package to
do the job for you.
195
331 Where are the msx and msy fonts?
The msx and msy fonts were designed by the American Mathematical Society in the
very early days of TeX, for use in typesetting papers for mathematical journals. They
were designed using the ‘old’ MetaFont, which wasn’t portable and is no longer avail-
able; for a long time they were only available in 300dpi versions which only imperfectly
matched modern printers. The AMS has now redesigned the fonts, using the current
version of MetaFont, and the new versions are called the msa and msb families.
Nevertheless, msx and msy continue to turn up to plague us. There are, of course,
still sites that haven’t got around to upgrading; but, even if everyone upgraded, there
would still be the problem of old documents that specify them.
If you have a .tex source that requests msx and msy, the best technique is to edit
it so that it requests msa and msb (you only need to change the single letter in the font
names).
If you have a DVI file that requests the fonts, there is a package of virtual fonts to
map the old to the new series.
msa and msb fonts: fonts/amsfonts/sources/symbols
virtual font set: fonts/vf-files/msx2msa
has failed to label correctly. If you really need this centring (and those in the know
commonly reject it), code it as:
\begin{center}
\caption{A Figure}
\label{fig}
\end{center}
4 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.
196
334 Start of line goes awry
This answer concerns two sorts of problems: errors of the form
and those where a single asterisk at the start of a line mysteriously fails to appear in the
output.
Both problems arise because \\ takes optional arguments. The command \\*
means “break the line here, and inhibit page break following the line break”; the com-
mand \\[hdimeni] means “break the line here and add hdimeni extra vertical space
afterwards”.
So why does \\ get confused by these things at the start of a line? It’s looking for
the first non-blank thing, and in the test it uses ignores the end of the line in your input
text.
The solution is to enclose the stuff at the start of the new line in braces:
{\ttfamily
/* C-language comment\\
{[grump]} I don’t like this format\\
{*}/
}
(The above text derives from an actual post to comp.text.tex; this particular bit of
typesetting could plainly also be done using the verbatim environment.)
The problem also appears in maths mode, in arrays and so on. In this case, large-
scale bracketing of things is not a good idea; the TeX primitive \relax (which does
nothing except to block searches of this nature) may be used. From another comp.
text.tex example:
\begin{eqnarray}
[a] &=& b \\
\relax[a] &=& b
\end{eqnarray}
which is a usage this FAQ would not recommend, anyway: refer to the reason not to
use eqnarray.
Note that the amsmath package modifies the behaviour of \\ in maths. With
amsmath, the eqnarray example doesn’t need any special measures.
335 Why doesn’t verbatim work within . . . ?
The LaTeX verbatim commands work by changing category codes. Knuth says of this
sort of thing “Some care is needed to get the timing right. . . ”, since once the cate-
gory code has been assigned to a character, it doesn’t change. So \verb and \begin
{verbatim} have to assume that they are getting the first look at the parameter text;
if they aren’t, TeX has already assigned category codes so that the verbatim command
doesn’t have a chance. For example:
\verb+\error+
\newcommand{\unbrace}[1]{#1}
\unbrace{\verb+\error+}
will not (it will attempt to execute \error). Other errors one may encounter are
‘\verb ended by end of line’, or even the rather more helpful ‘\verb illegal in com-
mand argument’. The same sorts of thing happen with \begin{verbatim} . . . \end
{verbatim}:
\ifthenelse{\boolean{foo}}{%
\begin{verbatim}
foobar
197
\end{verbatim}
}{%
\begin{verbatim}
barfoo
\end{verbatim}
}
provokes errors like ‘File ended while scanning use of \@xverbatim’, as \begin
{verbatim} fails to see its matching \end{verbatim}.
This is why the LaTeX book insists that verbatim commands must not appear in the
argument of any other command; they aren’t just fragile, they’re quite unusable in any
command parameter, regardless of \protection. (The \verb command tries hard to
detect if you’re misusing it; unfortunately, it can’t always do so, and the error message
is therefore not a reliable indication of problems.)
The first question to ask yourself is: “is \verb actually necessary?”.
comes in reaction to you giving LaTeX a \\ command at a time when it’s not expecting
it. The commonest case is where you’ve decided you want the label of a list item to be
on a line of its own, so you’ve written (for example):
\begin{description}
\item[Very long label] \\
Text...
\end{description}
\\ is actually a rather bad command to use in this case (even if it worked), since it
would force the ‘paragraph’ that’s made up of the text of the item to terminate a line
which has nothing on it but the label. This would lead to an “Underfull \hbox”
warning message (usually with ‘infinite’ badness of 10000); while this message doesn’t
do any actual harm other than slowing down your LaTeX run, any message that doesn’t
convey any information distracts for no useful purpose.
The proper solution to the problem is to write a new sort of description en-
vironment, that does just what you’re after. (The LaTeX Companion — see LaTeX
Companion — offers a rather wide selection of variants of these things.)
The quick-and-easy solution, which avoids the warning, is to write:
\begin{description}
\item[Very long label] \hspace*{\fill} \\
Text...
\end{description}
which fills out the under-full line before forcing its closure. The expdlist package
provides the same functionality with its \breaklabel command, and mdwlist provides
it via its \desclabelstyle command.
The other common occasion for the message is when you’re using the center (or
flushleft or flushright) environment, and have decided you need extra separation
between lines in the environment:
\begin{center}
First (heading) line\\
\\
body of the centred text...
\end{center}
The solution here is plain: use the \\ command in the way it’s supposed to be used, to
provide more than just a single line break space. \\ takes an optional argument, which
specifies how much extra space to add; the required effect in the text above can be had
by saying:
\begin{center}
First (heading) line\\[\baselineskip]
body of the centred text...
\end{center}
expdlist.sty : macros/latex/contrib/expdlist
mdwlist.sty : Distributed as part of macros/latex/contrib/mdwtools
199
337 Two-column float numbers out of order
When LaTeX can’t place a float immediately, it places it on one of several “defer” lists.
If another float of the same type comes along, and the “defer” list for that type still has
something in it, the later float has to wait for everything earlier in the list.
Now, standard LaTeX has different lists for single-column floats, and double-
column floats; this means that single-column figures can overtake double-column
figures (or vice-versa), and you observe later figures appear in the document before
early ones. The same is true, of course, for tables, or for any user-defined float.
The LaTeX team recognise the problem, and provides a package (fixltx2e) to deal
with it. Fixltx2e amalgamates the two defer lists, so that floats don’t get out of order.
For those who are still running an older LaTeX distribution, the package fix2col
should serve. This package (also by a member of the LaTeX team) was the basis of the
relevant part of fixltx2e. The functionality has also been included in dblfloatfix, which
also has code to place full-width floats at [b] placement.
Once you have loaded the package, no more remains to be done: the whole require-
ment is to patch the output routine; no extra commands are needed.
dblfloatfix.sty : macros/latex/contrib/misc/dblfloatfix.sty
fix2col.sty : Distributed as part of macros/latex/contrib/carlisle
fixltx2e.sty : Part of the LaTeX distribution.
for:
... voilà ...
and the internal mechanisms of the inputenc package will put the right version of the
accent command in there.
A witty reversal of the rôles is introduced by the package Tabbing (note the capital
“T”): it provides a Tabbing environment which duplicates tabbing, but all the single-
character commands become complicated objects. So tabbing’s \> becomes \TAB>,
\= becomes \TAB=, and so on. The above trivial example would therefore become:
\usepackage{Tabbing}
...
\begin{Tabbing}
... ... \TAB> voil\‘a \TAB> ...
Tabbing.sty : macros/latex/contrib/Tabbing
As a general rule, things that amsmath defines, it defines well; however, there is a good
case for using the txfonts version of \iint — the associated tx fonts have a double
integral symbol that doesn’t need to be “faked” in the way amsmath does. In the case
that you are loading several symbol packages, every one of which defines the same
symbol, you are likely to experience the problem in a big way (\euro is a common
victim).
There are similar cases where one package redefines another’s command, but no
error occurs because the redefining package doesn’t use \newcommand. Often, in such
a case, you only notice the change because you assume the definition given by the first
package. The amsmath–txfonts packages are just such a pair; txfonts doesn’t provoke
errors.
You may deal with the problem by saving and restoring the command. Macro
programmers may care to do this for themselves; for the rest of us, there’s the package
savesym. The sequence:
\usepackage{savesym}
\usepackage{amsmath}
\savesymbol{iint}
\usepackage{txfonts}
\restoresymbol{TXF}{iint}
does the job; restoring the amsmath version of the command, and making the txfonts
version of the command available as \TXFiint.
Documentation of savesym doesn’t amount to much: the only commands are
\savesymbol and \restoresymbol, as noted above.
amsmath.sty : Part of macros/latex/required/amslatex
savesym.sty : macros/latex/contrib/savesym/savesym.sty
txfonts.sty : Part of fonts/txfonts
(note: no space between the \pageref and the \label, since that could potentially
end up as a page-break space itself, which rather defeats the purpose of the exercise!).
343 My brackets don’t match
(La)TeX has a low-level mechanism for matching braces in document text. This means
you can type something like:
\section{All \emph{OK} now.}
and know that the first brace (for the argument of \section) will be matched with the
last brace, and the internal pair of braces (for the argument of \emph) will be matched
with each other. It’s all very simple.
However, LaTeX has a convention of enclosing optional arguments in brackets, as
in:
\section[OK]{All \emph{OK} now.}
These brackets are not matched by TeX mechanisms, despite the superficial similarity
of their use. As a result, straightforward-looking usages like:
\section[All [OK] now]{All \emph{OK} now.}
aren’t OK at all — the optional argument comes to consist of “All [OK”, and \section
takes the single character “n” (of the first “now”) as its argument.
Fortunately, TeX’s scanning mechanisms helps us by accepting the syntax “{]}” to
‘hide’ the closing bracket from the scanning mechanism that LaTeX uses. In practice,
the commonest way to use this facility is:
\section[All {[OK]} now]{All \emph{OK} now.}
• Why does LaTeX throw a page before and after \include commands?
Answer: because it has to. If you don’t like it, replace the \include command
with \input — you won’t be able to use \includeonly any more, but you prob-
ably don’t need it anyway, so don’t worry.
• Why can’t I nest \included files? — I always used to be able to under LaTeX 2.09.
Answer: in fact, you couldn’t, even under LaTeX 2.09, but the failure wasn’t di-
agnosed. However, since you were happy with the behaviour under LaTeX 2.09,
replace the \include commands with \input commands (with \clearpage as
appropriate).
TeX will open a group, and impose the ragged-setting parameters within that group;
it will then save a couple of sentences of text and close the group (thus restoring the
previous value of the parameters that \raggedright set). Then TeX encounters a
blank line, which it knows to treat as a \par token, so it typesets the two sentences;
but because the enclosing group has now been closed, the parameter settings have been
lost, and the paragraph will be typeset normally.
The solution is simple: close the paragraph inside the group, so that the setting
parameters remain in place. An appropriate way of doing that is to replace the last
three lines above with:
203
In this way, the paragraph is completed while \raggedright’s parameters are still in
force within the enclosing group.
Another alternative is to define an environment that does the appropriate job for
you. For the above example, LaTeX already defines an appropriate one:
\begin{flushleft}
Here’s text to be ranged left...
\end{flushleft}
In fact, there are a number of parameters for which TeX only maintains one value
per paragraph. A tiresome one is the set of upper case/lower case translations, which
(oddly enough) constrains hyphenation of mutilingual texts. Another that regularly
creates confusion is \baselineskip.
346 Case-changing oddities
TeX provides two primitive commands \uppercase and \lowercase to change the
case of text; they’re not much used, but are capable creating confusion.
The two commands do not expand the text that is their parameter — the result
of \uppercase{abc} is ‘ABC’, but \uppercase{\abc} is always ‘\abc’, whatever
the meaning of \abc. The commands are simply interpreting a table of equivalences
between upper- and lowercase characters. They have (for example) no mathematical
sense, and
\uppercase{About $y=f(x)$}
will produce
ABOUT $Y=F(X)$
\newcommand{\mytable}{\begin{tabular}...
\end{tabular}}
\section{A section title \protect\mytable{}
with a table}
Note that \mytable has to be protected, otherwise it will be expanded and made upper
case; you can achieve the same result by declaring it with \DeclareRobustCommand,
in which case the \protect won’t be necessary.
David Carlisle’s textcase package addresses many of these problems in a transpar-
ent way. It defines commands \MakeTextUppercase and \MakeTextLowercase
which do upper- or lowercase, with the fancier features of the LaTeX standard
\Make*-commands but without the problems mentioned above. Load the package with
\usepackage[overload]{textcase}, and it will redefine the LaTeX commands (not
the TeX primitive commands \uppercase and \lowercase), so that section headings
and the like don’t produce broken page headings.
textcase.sty : macros/latex/contrib/textcase
204
As always, the best solution is to change your text so that the problem doesn’t occur
in the first place. Consider whether the text that bears the footnote could move earlier
in the current page, or on to the next page.
If this isn’t possible, you might want to change LaTeX’s perception of its priorities:
they’re controlled by \interfootnotelinepenalty — the larger it is, the less willing
LaTeX is to split footnotes.
Setting
\interfootnotelinepenalty=10000
inhibits split footnotes altogether, which will cause ‘Underfull \vbox’ messages un-
less you also specify \raggedbottom. The default value of the penalty is 100, which
is rather mild.
An alternative technique is to juggle with the actual size of the pages. \enlargethispage
changes the size of the current page by its argument (for example, you might say
\enlargethispage{\baselineskip} to add a single line to the page, but you can
use any ordinary TeX length such as 15mm or -20pt as argument). Reducing the size
of the current page could force the offending text to the next page; increasing the size
of the page may allow the footnote to be included in its entirety. It may be necessary
to change the size of more than one page.
The fnbreak package detects (and generates warnings about) split footnotes.
fnbreak.sty : macros/latex/contrib/fnbreak
(the former demonstrating my TeX’s unwillingness to deal in characters which have the
eighth bit set, while the rsfs10 example shows that TeX will log the actual character
in error, if it thinks it’s possible).
Somewhat more understandable are the diagnostics you may get from dvips when
using the OT1 and T1 versions of fonts that were supplied in Adobe standard encoding:
205
The process that generates the metrics for using the fonts generates an instruction to
dvips to produce these diagnostics, so that their non-appearance in the printed output is
less surprising than it might be. Quite a few glyphs provided in Knuth’s text encodings
and in the Cork encoding are not available in the Adobe fonts. In these cases, there is
a typeset sign of the character: dvips produces a black rectangle of whatever size the
concocted font file has specified.
350 “Rerun” messages won’t go away
The LaTeX message “Rerun to get crossreferences right” is supposed to warn the user
that the job needs to be processed again, since labels seem to have changed since
the previous run. (LaTeX compares the labels it has created this time round with
what it found from the previous run when it started; it does this comparison at \end
{document}.)
Sometimes, the message won’t go away: however often you reprocess your docu-
ment, LaTeX still tells you that “Label(s) may have changed”. This can sometimes be
caused by a broken package: both footmisc (with the perpage option) and hyperref
have been known to give trouble, in the past: if you are using either, check you have
the latest version, and upgrade if possible.
However, there is a rare occasion when this error can happen as a result of patholog-
ical structure of the document itself. Suppose you have pages numbered in roman, and
you add a reference to a label on page “ix” (9). The presence of the reference pushes
the thing referred to onto page “x” (10), but since that’s a shorter reference the label
moves back to page “ix” at the next run. Such a sequence can obviously not terminate.
The only solution to this problem is to make a small change to your document
(something as small as adding or deleting a comma will often be enough).
footmisc.sty : macros/latex/contrib/footmisc
hyperref.sty : macros/latex/contrib/hyperref
\usepackage{xspace}
...
\newcommand{\restenergy}{\ensuremath{mc^2}\xspace}
...
and we find \restenergy available to us...
The \xspace command must be the last thing in your macro definition (as in the exam-
ple); it’s not completely foolproof, but it copes with most obvious situations in running
text.
The xspace package doesn’t save you anything if you only use a modified macro
once or twice within your document. In any case, be careful with usage of \xspace —
it changes your input syntax, which can be confusing, notably to a collaborating author
(particularly if you create some commands which use it and some which don’t). Of
course, no command built into LaTeX or into any “standard” class or package will use
\xspace.
206
xspace.sty : Distributed as part of macros/latex/required/tools
\pretolerance=150
For both, an “infinite” tolerance is represented by the value 10 000, but infinite toler-
ance is rarely appropriate, since it can lead to very bad line breaks indeed.
\emergencystretch is a TeX-internal ‘dimen’ register, and can be set as normal
for dimens in Plain TeX; in LaTeX, use \setlength — for example:
\setlength{\emergencystretch}{3em}
The choice of method has time implications — each of the passes takes time, so
adding a pass (by changing \emergencystretch) is less desirable than suppressing
one (by changing \pretolerance). However, it’s unusual nowadays to find a com-
puter that’s slow enough that the extra passes are really troublesome.
In practice, \pretolerance is rarely used other than to manipulate the use of hy-
phenation; Plain TeX and LaTeX both set its value to 100. To suppress the first scan of
paragraphs, set \pretolerance to -1.
\tolerance is often a good method for adjusting spacing; Plain TeX and LaTeX
both set its value to 200. LaTeX’s \sloppy command sets it to 9999, as does the
sloppypar environment. This value is the largest available, this side of infinity, and
can allow pretty poor-looking breaks (this author rarely uses \sloppy “bare”, though
he does occasionally use sloppypar — that way, the change of \tolerance is con-
fined to the environment). More satisfactory is to make small changes to \tolerance,
incrementally, and then to look to see how the change affects the result; very small
increases can often do what’s necessary. Remember that \tolerance is a paragraph
parameter, so you need to ensure it’s actually applied — see “ignoring paragraph pa-
rameters”. LaTeX users could use an environment like:
207
\newenvironment{tolerant}[1]{%
\par\tolerance=#1\relax
}{%
\par
}
\fontsize{10}{12}%
\selectfont
or:
\linespread{1.2}%
\selectfont
Of course, a package such as setspace, whose job is to manage the baseline, will
deal with all this stuff — see “managing double-spaced documents”. If you want to
208
avoid setspace, beware the behaviour of linespread changes within a paragraph: read
“\baselineskip is a paragraph parameter”.
setspace.sty : macros/latex/contrib/setspace/setspace.sty
will be squashed into the paragraph: TeX will make sure it doesn’t scrape up against
the line above, but won’t give it “room to breathe”, as it does the text at standard size;
that is, its size (24.88pt) is taken account of, but its \baselineskip (30pt) isn’t.
Similarly
Paragraph text ...
{\footnotesize Extended interjection ...
... into the paragraph.}
... paragraph continues ...
will look silly, since the 8pt interjection will end up set on the 12pt \baselineskip
of the paragraph, rather than its preferred 8.5pt. Finally, something like
Paragraph text ...
... paragraph body ends.
{\footnotesize Short comment on paragraph.}
will set the body of the first paragraph on the constricted \baselineskip of the
\footnotesize comment.
So, how to deal with these problems? The oversized (short) section is typically
corrected by a strut: this word comes from movable metal typography, and refers to a
spacer that held the boxes (that contained the metal character shapes) apart. Every time
you change font size, LaTeX redefines the command \strut to provide the equivalent
of a metal-type strut for the size chosen. So for the example above, we would type
Paragraph text ...
{\Huge A\strut}
... paragraph continues ...
However, more extended insertions (whether of larger or smaller text) are always going
to cause problems; while you can strut larger text, ensuring that you strut every line will
be tiresome, and there’s no such thing as a “negative strut” that pulls the lines together
for smaller text.
The only satisfactory way to deal with an extended insertion at a different size is
to set it off as a separate paragraph. A satisfactory route to achieving this is the quote
environment, which sets its text modestly inset from the enclosing paragraph:
Paragraph text ...
\begin{quote}
\footnotesize This is an inset account
of something relevant to the enclosing
paragraph...
\end{quote}
... paragraph continues ...
Such quote-bracketing also deals with the problem of a trailing comment on the para-
graph.
356 Numbers too large in table of contents, etc.
LaTeX constructs the table of contents, list of figures, tables, and similar tables, on the
basis of a layout specified in the class. As a result, they do not react to the sizes of
things in them, as they would if a tabular environment (or something similar) was
used.
209
This arrangement can provoke problems, most commonly with deep section nesting
or very large page numbers: the numbers in question just don’t fit in the space allowed
for them in the class.
A separate answer discusses re-designing the tables — re-designing the tables —
and those techniques can be employed to make the numbers fit.
357 Why is the inside margin so narrow?
If you give the standard classes the twoside option, the class sets the margins narrow
on the left of odd-numbered pages, and on the right of even-numbered pages. This is
often thought to look odd, but it is quite right.
The idea is that the typographic urge for symmetry should also apply to margins: if
you lay an even numbered page to the left of an odd-numbered one, you will see that
you’ve three equal chunks of un-printed paper: the left margin of the even page, the
right margin of the odd page, and the two abutting margins together.
This is all very fine in the abstract, but in practical book(let) production it only
works “sometimes”.
If your booklet is produced on double-width paper and stapled, the effect will be
good; if your book(let) is produced using a so-called “perfect” binding, the effect will
again be good.
However, almost any “quality” book-binder will need some of your paper to grab
hold of, and a book bound in such a way won’t exhibit the treasured symmetry unless
you’ve done something about the margin settings.
The packages recommended in “setting up margins” mostly have provision for
a “binding offset” or a “binding correction” — search for “binding” in the manuals
(vmargin doesn’t help, here).
If you’re doing the job by hand (see manual margin setup), the trick is to calculate
your page and margin dimensions as normal, and then:
210
359 Why bother with inputenc and fontenc?
The standard input encoding for Western Europe (pending the arrival of Unicode) is
ISO 8859–1 (commonly known by the standard’s subtitle ‘Latin-1’). Latin-1 is re-
markably close, in the codepoints it covers, to the (La)TeX T1 encoding.
In this circumstance, why should one bother with inputenc and fontenc? Since
they’re pretty exactly mirroring each other, one could do away with both, and use just
t1enc, despite its shortcomings.
One doesn’t do this for a variety of small reasons:
Confusion You’ve been happily working in this mode, and for some reason find you’re
to switch to writing in German: the effect of using “ß” is somewhat startling, since
T1 and Latin-1 treat the codepoint differently.
Compatibility You find yourself needing to work with a colleague in Eastern Europe:
their keyboard is likely to be set to produce Latin-2, so that the simple mapping
doesn’t work.
Traditional LaTeX You lapse and write something like \’e rather than typing é; only
fontenc has the means to convert this LaTeX sequence into the T1 character, so an
\accent primitive slips through into the output, and hyphenation is in danger.
The inputenc–fontenc combination seems slow and cumbersome, but it’s safe.
360 Why not use eqnarray?
The environment eqnarray is attractive for the occasional user of mathematics in La-
TeX documents: it seems to allow aligned systems of equations. Indeed it does supply
such things, but it makes a serious mess of spacing. In the system:
\begin{eqnarray}
a & = & b + c \\
x & = & y - z
\end{eqnarray}
the spacing around the “=” signs is not that defined in the metrics for the font from
which the glyph comes — it’s \arraycolsep, which may be set to some very odd
value for reasons associated with real arrays elsewhere in the document.
The user is far better served by the AMSLaTeX bundle, which provides an align
environment, which is designed with the needs of mathematicians in mind (as opposed
to the convenience of LaTeX programmers). For this simple case (align is capable of
far greater things), code as:
\begin{align}
a & = b + c \\
x & = y - z
\end{align}
AMSLaTeX : macros/latex/required/amslatex
with the font change enclosed in a group, so as to limit its effect; note the italic correc-
tion command \/ that was necessary at the end of a section in italics.
At the release of LaTeX 2ε in summer 1994, these simple commands were depre-
cated, but recognising that their use is deeply embedded in the brains of LaTeX users,
the commands themselves remain in LaTeX, with their LaTeX 2.09 semantics. Those
semantics were part of the reason they were deprecated: each \xx overrides any other
font settings, keeping only the size. So, for example,
{\bf\it Here we are again\/}
ignores \bf and produces text in italic, medium weight (and the italic correction has a
real effect), whereas
{\it\bf happy as can be\/}
ignore \it and produces upright text at bold weight (and the italic correction has noth-
ing to do). The same holds if you mix LaTeX 2ε font selections with the old style
commands:
\textbf{\tt all good friends}
ignores the \textbf that encloses the text, and produces typewriter text at medium
weight.
So why are these commands deprecated? — it is because of confusions such as that
in the last example. The alternative (LaTeX 2ε ) commands are discussed in the rest of
this answer.
LaTeX 2ε ’s font commands come in two forms: modal commands and text-block
commands. The default set of modal commands offers weights \mdseries and
\bfseries, shapes \upshape, \itshape, \scshape and \slshape, and families
\rmfamily, \sffamily and \ttfamily. A font selection requires a family, a shape
and a series (as well as a size, of course). A few examples
{\bfseries\ttfamily and jolly good company!}
produces bold typewriter text (but note the lack of a bold typewriter font in the default
Computer Modern fonts), or
{\slshape\sffamily Never mind the weather\/}
to produce bold italic text (note that the block commands supply italic corrections
where necessary), and they be nested with the LaTeX 2ε modal commands, too:
\texttt{\bfseries So long as we’re together}
for a bold slanted instance of the current family (note the italic correction applied at
the end of the modal command group, again).
The new commands (as noted above) override commands of the same type. In
almost all cases, this merely excludes ludicrous ideas such as “upright slanted” fonts,
or “teletype roman” fonts. There are a couple of immediate oddities, though. The first
is the conflict between \itshape (or \slshape) and \scshape: while many claim
212
that an italic small-caps font is typographically unsound, such fonts do exist. Daniel
Taupin’s smallcap package enables use of the instances in the EC fonts, and similar
techniques could be brought to bear on many other font sets. The second is the conflict
between \upshape and \itshape: Knuth actually offers an upright-italic font which
LaTeX uses for the “£” symbol in the default font set. The combination is sufficiently
weird that, while there’s a defined font shape, no default LaTeX commands exist; to
use the shape, the (eccentric) user needs LaTeX’s simplest font selection commands:
{\fontshape{ui}\selectfont Tra la la, di dee}
smallcap.sty : macros/latex/contrib/smallcap
which will indeed work, but will actually produce a worse result than
\usepackage{fix-cm}
...
{%
\fontsize{30}{36}\selectfont
Huge text%
}
Note that the fix-cm package was not distributed until the December 2003 edition of
LaTeX; if you have an older distribution, the packages type1cm (for CM fonts) and
type1ec (for EC fonts) are available.
fix-cm.sty : Distributed as part of macros/latex/base (an unpacked version is
available at macros/latex/unpacked/fix-cm.sty)
type1cm.sty : macros/latex/contrib/type1cm
type1ec.sty : fonts/ps-type1/cm-super/type1ec.sty (the package is actually
part of the fonts/ps-type1/cm-super distribution, but it works happily in
the absence of the scaled fonts)
The best advice to those faced with TeX errors is not to panic: most of the common
errors are plain to the eye when you go back to the source line that TeX tells you of.
If that approach doesn’t work, the remaining answers in this section deal with some of
the odder error messages you may encounter. You should not ordinarily need to appeal
to the wider public for assistance, but if you do, be sure to report full backtraces (see
errorcontextlines above) and so on.
trace.sty : Distributed as part of macros/latex/required/tools
• An error message
• Some ‘context’
• An error prompt
The error message will relate to the TeX condition that is causing a problem. Sadly, in
the case of complex macro packages such as LaTeX, the underlying TeX problem may
be superficially difficult to relate to the actual problem in the “higher-level” macros.
Many LaTeX-detected problems manifest themselves as ‘generic’ errors, with error
text provided by LaTeX itself (or by a LaTeX class or package).
The context of the error is a stylised representation of what TeX was doing at the
point that it detected the error. As noted in approaching errors, a macro package can
tell TeX how much context to display, and the user may need to undo what the package
has done. Each line of context is split at the point of the error; if the error actually
occurred in a macro called from the present line, the break is at the point of the call. (If
the called object is defined with arguments, the “point of call” is after all the arguments
have been scanned.) For example:
\blah and so on
produces the error report
214
! Undefined control sequence.
l.4 \blah
and so on
while:
\newcommand{\blah}[1]{\bleah #1}
\blah{to you}, folks
produces the error report
! Undefined control sequence.
\blah #1->\bleah
#1
l.5 \blah{to you}
, folks
If the argument itself is in error, we will see things such as
\newcommand{\blah}[1]{#1 to you}
\blah{\bleah}, folks
producing
! Undefined control sequence.
<argument> \bleah
l.5 \blah{\bleah}
, folks
The prompt accepts single-character commands: the list of what’s available may
be had by typing ?. One immediately valuable command is h, which gives you an
expansion of TeXs original précis message, sometimes accompanied by a hint on what
to do to work round the problem in the short term. If you simply type ‘return’ (or
whatever else your system uses to signal the end of a line) at the prompt, TeX will
attempt to carry on (often with rather little success).
366 An extra ‘}’??
You’ve looked at your LaTeX source and there’s no sign of a misplaced } on the line
in question.
Well, no: this is TeX’s cryptic way of hinting that you’ve put a fragile command in
a moving argument.
For example, \footnote is fragile, and if we put that in the moving argument of a
\section command, as
\section{Mumble\footnote{I couldn’t think of anything better}}
we get told
! Argument of \@sect has an extra }.
The same happens with captions (the following is a simplification of a comp.text.tex
post):
\caption{Energy: \[e=mc^2\]}
giving us the error message
! Argument of \@caption has an extra }.
The solution is usually to use a robust command in place of the one you are using,
or to force your command to be robust by prefixing it with \protect, which in the
\section case would show as
\section{Mumble\protect\footnote{I couldn’t think of anything better}}
In both the \section case and the \caption case, you can separate the moving ar-
gument, as in \section[moving]{static}; this gives us another standard route —
simply to omit (or otherwise sanitise) the fragile command in the moving argument.
So, one might rewrite the \caption example as:
\caption[Energy: $E=mc^2$]{Energy: \[E=mc^2\]}
for, after all, even if you want display maths in a caption, you surely don’t want it in
the list of figures.
The case of footnotes is somewhat more complex; “footnotes in LaTeX section
headings” deals specifically with that issue.
215
367 Capacity exceeded [semantic nest . . . ]
! TeX capacity exceeded, sorry [semantic nest size=100].
...
If you really absolutely need more capacity,
you can ask a wizard to enlarge me.
Even though TeX suggests (as always) that enlargement by a wizard may help, this
message usually results from a broken macro or bad parameters to an otherwise work-
ing macro.
The “semantic nest” TeX talks about is the nesting of boxes within boxes. A stupid
macro can provoke the error pretty easily:
The extended traceback (see general advice on errors) does help, though it does rather
run on. In the case above, the traceback consists of
\silly ->\hbox {
here’s \silly being executed}
followed by 100 instances of
\silly ->\hbox {here’s \silly
being executed}
The repeated lines are broken at exactly the offending macro; of course the loop need
not be as simple as this — if \silly calls \dopy which boxes \silly, the effect is just
the same and alternate lines in the traceback are broken at alternate positions.
There are in fact two items being consumed when you nest boxes: the other is the
grouping level. Whether you exhaust your semantic nest or your permitted grouping
levels first is controlled entirely by the relative size of the two different sets of buffers
in your (La)TeX executable.
368 No room for a new ‘thing’
The technology available to Knuth at the time TeX was written is said to have been
particularly poor at managing dynamic storage; as a result much of the storage used
within TeX is allocated as fixed arrays, in the reference implementations. Many of these
fixed arrays are expandable in modern TeX implementations, but size of the arrays of
“registers” is written into the specification as being 256 (usually); this number may not
be changed if you still wish to call the result TeX (see testing TeX implementations).
If you fill up one of these register arrays, you get a TeX error message saying
The \things in question may be \count (the object underlying LaTeX’s \newcounter
command), \skip (the object underlying LaTeX’s \newlength command), \box (the
object underlying LaTeX’s \newsavebox command), or \dimen, \muskip, \toks,
\read, \write or \language (all types of object whose use is “hidden” in LaTeX;
the limit on the number of \read or \write objects is just 16).
There is nothing that can directly be done about this error, as you can’t extend the
number of available registers without extending TeX itself. Of course, Ω and e-TeX —
respectively — both do this, as does MicroPress Inc’s VTeX.
The commonest way to encounter one of these error messages is to have broken
macros of some sort, or incorrect usage of macros (an example is discussed in epsf
problems).
However, sometimes one just needs more than TeX can offer, and when this hap-
pens, you’ve just got to work out a different way of doing things. An example is the
difficulty of loading PiCTeX with LaTeX. In cases like PiCTeX, it may be possible
to use e-TeX (all modern distributions provide it). The LaTeX package etex modifies
the register allocation mechanism to make use of e-TeX’s extended register sets (it’s a
derivative of the Plain TeX macro file etex.src, which is used in building the e-TeX Plain
format; both files are part of the e-TeX distribution). Unfortunately, e-TeX doesn’t help
with \read or \write objects.
216
369 epsf gives up after a bit
Some copies of the documentation of epsf.tex seem to suggest that the command
\input epsf
is needed for every figure included. If you follow this suggestion too literally, you get
an error
! No room for a new \read .
after a while; this is because each time epsf.tex is loaded, it allocates itself a new file-
reading handle to check the figure for its bounding box, and there just aren’t enough of
these things (see no room for a new thing).
The solution is simple — this is in fact an example of misuse of macros; one only
need read epsf.tex once, so change
...
\input epsf
\epsffile{...}
...
\input epsf
\epsffile{...}
(and so on) with a single
\input epsf
somewhere near the start of your document, and then decorate your \epsffile state-
ments with no more than adjustments of \epsfxsize and so on.
370 Improper \hyphenation will be flushed
For example
! Improper \hyphenation will be flushed.
\’#1->{
\accent 19 #1}
<*> \hyphenation{Ji-m\’e
-nez}
(in Plain TeX) or
! Improper \hyphenation will be flushed.
\leavevmode ->\unhbox
\voidb@x
<*> \hyphenation{Ji-m\’e
-nez}
in LaTeX.
As mentioned in “hyphenation failures”, words with accents in them may not be
hyphenated. As a result, any such word is deemed improper in a \hyphenation com-
mand.
The solution is to use a font that contains the character in question, and to express
the \hyphenation command in terms of that character; this “hides” the accent from
the hyphenation mechanisms. LaTeX users can be achieved this by use of the fontenc
package (part of the LaTeX distribution). If you select an 8-bit font with the pack-
age, as in \usepackage[T1]{fontenc}, accented-letter commands such as the \’e
in \hyphenation{Ji-m\’e-nez} automatically become the single accented character
by the time the hyphenation gets to look at it.
371 “Too many unprocessed floats”
If LaTeX responds to a \begin{figure} or \begin{table} command with the error
message
! LaTeX Error: Too many unprocessed floats.
217
in the document: the caption number is allocated when the figure (or whatever) is cre-
ated, and can’t be changed, so that placement out of order would mean figure numbers
appearing out of order in the document (and in the list of figures, or whatever). So
a simple failure to place a figure means that no subsequent figure can be placed; and
hence (eventually) the error.
Techniques for solving the problem are discussed in the floats question (floats ques-
tion) already referenced.
The error also occurs in a long sequence of figure or table environments, with no
intervening text. Unless the environments will fit “here” (and you’ve allowed them to
go “here”), there will never be a page break, and so there will never be an opportunity
for LaTeX to reconsider placement. (Of course, the floats can’t all fit “here” if the
sequence is sufficiently prolonged: once the page fills, LaTeX won’t place any more
floats, leading to the error.
Techniques for resolution may involve redefining the floats using the float pack-
age’s [H] float qualifier, but you are unlikely to get away without using \clearpage
from time to time.
float.sty : macros/latex/contrib/float
219
whatever. Other common errors are failure to close the braces round a command’s ar-
gument, or (in LaTeX) failure to close a verbatim environment: in such cases you’ve
already read and accepted an error message about encountering end of file while scan-
ning something.
If the error is indeed because you’ve forgotten to end your document, you can
insert the missing text: if you’re running Plain TeX, the advice, to “say \end” is good
enough: it will kill the run; if you’re running LaTeX, the argument will be necessary:
\end{document}.
However, as often as not this isn’t the problem, and (short of debugging the source
of the document before ending) brute force is probably necessary. Excessive force
(killing the job that’s running TeX) is to be avoided: there may well be evidence in
the .log file that will be useful in determining what the problem is — so the aim is to
persuade TeX to shut itself down and hence flush all log output to file.
If you can persuade TeX to read it, an end-of-file indication (control-D under Unix,
control-Z under Windows) will provoke TeX to report an error and exit immediately.
Otherwise you should attempt to provoke an error dialogue, from which you can exit
(using the x ‘command’). An accessible error could well be inserting an illegal char-
acter: what it is will depend on what macros you are running. If you can’t make that
work, try a silly command name or two.
376 “Unknown graphics extension”
The LaTeX graphics package deals with several different types of DVI (or other) output
drivers; each one of them has a potential to deal with a different selection of graphics
formats. The package therefore has to be told what graphics file types its output driver
knows about; this is usually done in the hdriveri.def file corresponding to the output
driver you’re using.
The error message arises, then, if you have a graphics file whose extension doesn’t
correspond with one your driver knows about. Most often, this is because you’re being
optimistic: asking dvips to deal with a .png file, or PDFTeX to deal with a .eps file:
the solution in this case is to transform the graphics file to a format your driver knows
about.
If you happen to know that your device driver deals with the format of your file, you
are probably falling foul of a limitation of the file name parsing code that the graphics
package uses. Suppose you want to include a graphics file home.bedroom.eps using
the dvips driver; the package will conclude that your file’s extension is .bedroom.eps,
and will complain. To get around this limitation, you have three alternatives:
221
• A file transferred from another system, without translating record endings. With
the decline of fixed-format records (on mainframe operating systems) and the in-
creased intelligence of TeX distributions at recognising other systems’ explicit
record-ending characters, this is nowadays rather a rare cause of the problem.
• A graphics input file, which a package is examining for its bounding box, contains
a binary preview section. Again, sufficiently clever TeX distributions recognise
this situation, and ignore the previews (which are only of interest, if at all, to a
TeX previewer).
The usual advice is to ignore what TeX says (i.e., anything about enlarging), and to
put the problem right in the source.
If the real problem is over-long text lines, most self-respecting text editors will be
pleased to automatically split long lines (while preserving the “word” structure) so that
they are nowhere any longer than a given length; so the solution is just to edit the file.
If the problem is a ridiculous preview section, try using ghostscript to reprocess the
file, outputting a “plain .eps” file. (Ghostscript is distributed with a script ps2epsi
which will regenerate the preview if necessary.) Users of the shareware program
GSview will find buttons to perform the required transformation of the file being dis-
played.
ghostscript: Browse nonfree/support/ghostscript
GSview : Browse nonfree/support/ghostscript/ghostgum
In the example,
• the first enumerate has labels as for a first-level enumerate, and is indented as
for a first-level list;
• the first itemize has labels as for a first level itemize, and is indented as for a
second-level list; and
• the second enumerate has labels as for a second-level enumerate, and is indented
as for a third-level list.
Now, as well as LaTeX knowing that there are 6 sets of parameters for indentation, it
also knows that there are only 4 types of labels each, for the environments enumerate
and itemize (this “knowledge” spells out a requirement for class writers, since the
class supplies the sets of parameters).
From the above, we can deduce that there are several ways we can run out of
space: we can have 6 lists (of any sort) nested, and try to start a new one; we can
223
have 4 enumerate environments somewhere among the set of nested lists, and try to
add another one; and we can have 4 itemize environments somewhere among the set
of nested lists, and try to add another one.
What can be done about the problem? Not much, short of rewriting LaTeX — you
really need to rewrite your document in a slightly less labyrinthine way.
384 Capacity exceeded — input levels
The error
! TeX capacity exceeded, sorry [text input levels=15].
is caused by nesting your input too deeply. You can provoke it with the trivial (Plain
TeX) file input.tex, which contains nothing but:
\input input
In the real world, you are unlikely to encounter the error with a modern TeX distribu-
tion. TeTeX (used to produce the error message above) allows 15 files open for TeX
input at any one time, which is improbably huge for a document generated by real
human beings.
However, for those improbable (or machine-generated) situations, some distribu-
tions offer the opportunity to adjust the parameter max_in_open in a configuration file.
385 PDFTeX destination . . . ignored
The warning:
arises because of duplicate page numbers in your document. The problem is usually
soluble: see PDF page destinations — which answer also describes the problem in
more detail.
If the identifier in the message is different, for example name{figure.1.1}, the
problem is (usually) due to a problem of package interaction. Some packages are
simply incompatible with hyperref , but most work simply by ignoring it. In most
cases, therefore, you should load your package before you load hyperref , and hyperref
will patch things up so that they work:
\usepackage{your package}
...
\usepackage[opts]{hyperref}
\begin{tabular}{ll}
hello & there & jim \\
goodbye & now
\end{tabular}
where the second & in the first line of the table is more than the two-column ll column
specification can cope with — an extra “l” in that solves the problem. (As a result of
the error, “jim” will be moved to a row of his own.)
Rather more difficult to spot is the occurrence of the error when you’re using align-
ment instructions in a “p” column:
224
\usepackage{array}
...
\begin{tabular}{l>{\raggedright}p{2in}}
here & we are again \\
happy & as can be
\end{tabular}
the problem here (as explained in tabular cell alignment) is that the \raggedright
command in the column specification has overwritten tabular’s definition of \\, so
that “happy” appears in a new line of the second column, and the following & appears
to LaTeX just like the second & in the first example above.
Get rid of the error in the way described in tabular cell alignment — either use
\tabularnewline explicitly, or use the \RBS trick described there.
array.sty : Distributed as part of macros/latex/required/tools
can actually be caused by offering the package a figure which claims to have a zero
dimension, it’s more commonly caused by rotation.
Objects in TeX may have both height (the height above the baseline) and depth (the
distance the object goes below the baseline). If you rotate an object by 180 degrees,
you convert its height into depth, and vice versa; if the object started with zero depth,
you’ve converted it to a zero-height object.
Suppose you’re including your graphic with a command like:
\includegraphics[angle=180,height=5cm]{myfig.eps}
In the case that myfig.eps has no depth to start with, the scaling calculations will
produce the division-by-zero error.
Fortunately, the graphicx package has a keyword totalheight, which allows you
to specify the size of the image relative to the sum of the object’s height and depth,
so
\includegraphics[angle=180,totalheight=5cm]{myfig.eps}
will resolve the error, and will behave as you might hope.
If you’re using the simpler graphics package, use the * form of the \resizebox
command to specify the use of totalheight:
\resizebox*{!}{5cm}{%
\rotatebox{180}{%
\includegraphics{myfig.eps}%
}%
}
225
If the error occurs while LaTeX is reading a class or package, then there’s probably
a bug in the file. The author of the class or package stands the best chance of finding the
bug, but with luck you (or someone you ask on a mailing list or on comp.text.tex)
will be able to spot the problem and provide a work-around. Always report such bugs,
even if you have found a work-around.
389 \normalsize not defined
The LaTeX error:
is reporting something pretty fundamental (document base font size not set up). While
this can, as the message implies, be due to a broken class file, the more common
cause is that you have simply forgotten to put a \documentclass command in your
document.
390 Too many math alphabets
TeX mathematics is one of its most impressive features, yet the internal structure of the
mechanism that produces it is painfully complicated and (in some senses) pathetically
limited. One area of limitation is that one is only allowed 16 ”maths alphabets”
LaTeX offers the user quite a lot of flexibility with allocating maths alphabets, but
few people use the flexibility directly. Nevertheless, there are many packages that pro-
vide symbols, or that manipulate them, which allocate themselves one or more maths
alphabet.
If you can’t afford to drop any of these packages, there’s still hope if you’re using
the bm package to support bold maths: bm is capable of gobbling alphabets as if there is
no tomorrow. The package defines two limiter commands: \bmmax (for bold symbols;
default 4) and \hmmax (for heavy symbols, if you have them; default 3), which control
the number of alphabets to be used.
Any reduction of the \xxmax variables will slow bm down — but that’s surely
better than the document not running at all. So unless you’re using maths fonts (such as
Mathtime Plus) that feature a heavy symbol weight, suppress all use of heavy families
by
\renewcommand{\hmmax}{0}
\renewcommand{\bmmax}{3}
comes when some “main” document feature is shut up somewhere it doesn’t like.
The commonest occurrence is when the user wants a figure somewhere inside a
table:
\begin{tabular}{|l|}
\hline
\begin{figure}
\includegraphics{foo}
\end{figure}
\hline
\end{tabular}
a construction that was supposed to put a frame around the diagram, but doesn’t work,
any more than:
226
\framebox{\begin{figure}
\includegraphics{foo}
\end{figure}%
}
The problem is, that the tabular environment, and the \framebox command restrain
the figure environment from its natural métier, which is to float around the document.
The solution is simply not to use the figure environment here:
\begin{tabular}{|l|}
\hline
\includegraphics{foo}
\hline
\end{tabular}
What was the float for? — as written in the first two examples, it serves no useful
purpose; but perhaps you actually wanted a diagram and its caption framed, in a float.
It’s simple to achieve this — just reverse the order of the environments (or of the
figure environment and the command):
\begin{figure}
\begin{tabular}{|l|}
\hline
\includegraphics{foo}
\caption{A foo}
\hline
\end{tabular}
\end{figure}
The same goes for table environments (or any other sort of float you’ve defined for
yourself) inside tabulars or box commands; you must get the float environment out
from inside, one way or another.
392 Perhaps a missing \item?
Sometimes, the error
\begin{itemize}
boo!
\end{itemize}
\fbox{%
\begin{alltt}
boo!
\end{alltt}%
}
produces the error (the same happens with \mbox in place of \fbox, or with either of
their “big brothers”, \framebox and \makebox). This is because the alltt environ-
ment uses a “trivial” list, hidden inside their definition. (The itemize environment
also has this construct inside itself, in fact, so \begin{itemize} won’t work inside an
\fbox, either.) The list construct wants to happen between paragraphs, so it makes a
new paragraph of its own. Inside the \fbox command, that doesn’t work, and subse-
quent macros convince themselves that there’s a missing \item command.
To solve this rather cryptic error, one must put the alltt inside a paragraph-style
box. The following modification of the above does work:
227
\fbox{%
\begin{minipage}{0.75\textwidth}
\begin{alltt}
hi, there!
\end{alltt}
\end{minipage}
}
The code above produces a box that’s far too wide for the text. One may want to use
something that allows variable size boxes in place of the minipage environment.
Oddly, although the verbatim environment wouldn’t work inside a \fbox com-
mand argument (see verbatim in command arguments), you get an error that complains
about \item: the environment’s internal list bites you before verbatim has even had a
chance to create its own sort of chaos.
Another (seemingly) obvious use of \fbox also falls foul of this error:
\fbox{\section{Boxy section}}
This is a case where you’ve simply got to be more subtle; you should either write your
own macros to replace the insides of LaTeX’s sectioning macros, or look for some
alternative in the packages discussed in “The style of section headings”.
393 Illegal parameter number in definition
The error message means what it says. In the simple case, you’ve attempted a definition
like:
\newcommand{\abc}{joy, oh #1!}
In either of the above, the definition uses an argument, but the programmer did not tell
(La)TeX, in advance, that she was going to. The fix is simple — \newcommand{\abc}
[1], in the LaTeX case, \def\abc#1 in the basic TeX case.
The more complicated case is exemplified by the attempted definition:
\newcommand{\abc}{joy, oh joy!%
\newcommand{\ghi}[1]{gloom, oh #1!}%
}
will also produce this error, as will its TeX primitive equivalent:
\def\abc{joy, oh joy!%
\def\ghi#1{gloom, oh #1!}%
}
This is because special care is needed when defining one macro within the code of
another macro. This is explained elsewhere, separately for LaTeX definitions and for
TeX primitive definitions
394 Float(s) lost
The error
! LaTeX Error: Float(s) lost.
seldom occurs, but always seems deeply cryptic when it does appear.
The message means what it says: one or more figures, tables, etc., or marginpars
has not been typeset. (Marginpars are treated internally as floats, which is how they
come to be lumped into this error message.)
The most likely reason is that you placed a float or a \marginpar command in-
side another float or marginpar, or inside a minipage environment, a \parbox or
\footnote. Note that the error may be detected a long way from the problematic
command(s), so the techniques of tracking down elusive errors all need to be called
into play.
This author has also encountered the error when developing macros that used the
LaTeX internal float mechanisms. Most people doing that sort of thing are expected to
be able to work out their own problems. . .
228
395 Option clash for package
So you’ve innocently added:
\usepackage[draft]{graphics}
The error is a complaint about loading a package with options, more than once
(LaTeX doesn’t actually examine what options there are: it complains because it can’t
do anything with the multiple sets of options). You can load a package any number
of times, with no options, and LaTeX will be happy, but you may only supply options
when you first load the package.
So perhaps you weren’t entirely innocent — the error would have occurred on the
second line of:
\usepackage[dvips]{graphics}
\usepackage[draft]{graphics}
which could quite reasonably (and indeed correctly) have been typed:
\usepackage[dvips,draft]{graphics}
But if you’ve not made that mistake (even with several lines separating the
\usepackage commands, it’s pretty easy to spot), the problem could arise from
something else loading the package for you. How do you find the culprit? Well, it’s
down to the log analysis games discussed in “How to approach errors”; the trick to
remember is that that the process of loading each file is parenthesised in the log; so if
package foo loads graphics, the log will contain something like:
(<path>/foo.sty ...
...
(<path>/graphics.sty ...
...)
...
)
(the parentheses for graphics are completely enclosed in those for foo; the same is of
course true if bar is the culprit, except that the line will start with the path to bar.cls).
If we’re dealing with a package that loads the package you are interested in, you
need to ask LaTeX to slip in options when foo loads it. Instead of:
\usepackage{foo}
\usepackage[draft]{graphics}
\usepackage[final]{graphics}
sets final after it’s dealt with option you passed to it, so your draft will get forgotten.
In extreme cases, the package might generate an error here (graphics doesn’t go in for
that kind of thing, and there’s no indication that draft has been forgotten).
In such a case, you have to modify the package or class itself (subject to the terms of
its licence). It may prove useful to contact the author: she may have a useful alternative
to suggest.
230
Direct represention of mathematics MathML is a standard for representing maths on
the Web; its original version was distinctly limited, but version 2 of MathML has
had major browser support since 2002 with richness of mathematical content for
online purposes approaching that of TeX for print. Browser support for MathML
is provided by amaya, the ‘Open Source’ browser mozilla (and its derivatives in-
cluding NetScape, Firefox and Galeon) and Internet Explorer when equipped with
a suitable plugin such as MathPlayer. There’s evidence that (La)TeX users are
starting to use such browsers. Some believe that XHTML+MathML now provides
better online viewing than PDF. Work to produce XHTML+MathML is well ad-
vanced in both the TeX4ht and TtH projects for (La)TeX conversion.
An approach different from (La)TeX conversion is taken by the GELLMU Project.
Its article XML document type, which has a markup vocabulary close to La-
TeX that can be edited using LaTeX-like markup (even though it is not La-
TeX — so far), comes with translators that make both PDF (via pdflatex) and
XHTML+MathML. Such an approach avoids the inherent limitations of the “tra-
ditional” (La)TeX translation processes, which have traps that can be sprung by
unfettered use of (La)TeX markup.
Graphics SVG is a standard for graphics representation on the web. While the natural
use is for converting existing figures, representations of formulas are also possible,
in place of the separate bitmaps that have been used in the past (and while we wait
for the wider deployment of MathML).
Browser plug-ins, that deal with SVG are already available (Adobe offer one, for
example). More recently, the open source graphics editor Inkscape has appeared,
and has been reported to be useful for SVG-related work in at least one TeX-related
project. Be aware that the developers of Inkscape have no illusions about being
able to replace commercial software, yet. . .
Direct use of TeX markup Some time back, IBM developed a browser plug-in called
TechExplorer, which would display (La)TeX documents direct in a browser. Over
the years, it developed into a MathML browser plug-in, while still retaining its
(La)TeX abilities, but it’s now distributed (free for Linux and Windows platforms)
by Integre Technical Publishing.
The disadvantage of the TechExplorer approach is that it places the onus on the
browser user; and however technically proficient you are, it’s never safe to assume
too much of your readers. An interesting alternative is MimeTeX, which sits on
your server as a CGI script, and you use it to include your TeX, in your HTML, as
if it were an image:
<img src="../cgi-bin/mimetex.cgi?f(x)=\int\limits_{-\infty}^xe^{-t^2}dt">
GELLMU : support/gellmu
MimeTeX : support/mimetex
TeX4HT : support/TeX4ht/tex4ht-all.zip
232
texmacs: Browse systems/unix/TeXmacs
234
3. Prepare a “minimum” file that exhibits the problem. Ideally, such a file should
contain no contributed packages — the LaTeX team as a whole takes no responsibility
for such packages (if they’re supported at all, they’re supported by their authors). The
“minimum” file should be self-sufficient: if a member of the team should run it in
a clean directory, on a system with no contributed packages, it should replicate your
problem.
4. Run your file through LaTeX: the bug system needs the .log file that this process
creates.
You now have two possible ways to proceed: either create a mail report to send to
the bug processing mechanism (5, below), or submit your bug report via the web (7,
below).
5. Process the bug-report creation file, using LaTeX itself:
latex latexbug
latexbug asks you some questions, and then lets you describe the bug you’ve found.
It produces an output file latexbug.msg, which includes the details you’ve supplied,
your “minimum” example file, and the log file you got after running the example. (I
always need to edit the result before submitting it: typing text into latexbug isn’t
much fun.)
6. Mail the resulting file to [email protected]; the subject line of
your email should be the same as the bug title you gave to latexbug. The file
latexbug.msg should be included into your message in-line: attachments are likely to
be rejected by the bug processor.
7. Connect to the latex bugs processing web page and enter details of your bug —
category, summary and full description, and the two important files (source and log
file); note that members of the LaTeX team need your name and email address, as they
may need to discuss the bug with you, or to advise you of a work-around.
408 What to do if you find a bug
For a start, make entirely sure you have found a bug. Double-check with books about
TeX, LaTeX, or whatever you’re using; compare what you’re seeing against the other
answers above; ask every possible person you know who has any TeX-related expertise.
The reasons for all this caution are various.
If you’ve found a bug in TeX itself, you’re a rare animal indeed. Don Knuth is so
sure of the quality of his code that he offers real money prizes to finders of bugs; the
cheques he writes are such rare items that they are seldom cashed. If you think you
have found a genuine fault in TeX itself (or MetaFont, or the CM fonts, or the TeX-
book), don’t immediately write to Knuth, however. He only looks at bugs infrequently,
and even then only after they are agreed as bugs by a small vetting team. In the first
instance, contact Barbara Beeton at the AMS ([email protected]), or contact TUG.
If you’ve found a bug in LaTeX 2ε , report it using mechanisms supplied by the
LaTeX team. (Please be careful to ensure you’ve got a LaTeX bug, or a bug in one of
the “required” packages distributed by the LaTeX team.)
If you’ve found a bug in a contributed LaTeX package, you could try contacting
the author (if you can find a contact address). However, it’s generally best to treat
any package as unsupported, in the first instance, and only try the author after mailing
list/news group support has failed you.
If you’ve found a bug in LaTeX 2.09, or some other such unsupported software,
you may find help or de facto support on a newsgroup such as comp.tex.tex or on
a mailing list such as [email protected]; be carefule to include a code example of the
failure, if relevant.
Failing all else, you may need to pay for help — TUG maintains a register of TeX
consultants.
235