# LaTeX - Wikimedia Commons

## LaTeX - Wikimedia Commons

LaTeX en.wikibooks.org June 18, 2016 On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia projects were...

#### Recommend Documents

Personal Computer - Wikimedia Commons
The PS/2's Model M keyboard from which modern PC ... two-handed alternatives more akin to a game controller, such as the

Cables v1.3 - Wikimedia Commons
Some computers and monitors. Some laptop computers. Some laptop computers. Aluminum Unibody MacBook (late 2008 - mid 200

13.05.2004 - Viele dieser Browser (wie Mozilla, Internet Explorer) werden heu- ... Camino (frÃ¼her: Chimera, fÃ¼r Mac OS

Inhaltsverzeichnis - Wikimedia Commons
Staaten, HauptstÃ¤dte und Landessprachen zuzuordnen. Flagge. Land. Hauptstadt. Landessprachen. (Minderheiten siehe. FuÃ

Cloud Computing - Wikimedia Commons
Mar 10, 2015 - works: A revolution in the earth system science? ...... Grow to 26 Billion Units By 2020â. ... the Inte

Quizspiel - Wikimedia Commons
Absurdistan. Allwissende Müllhalde. Partymeile. Pommesgabel. Wikimedia logo family of Wikimedia Foundation. Wikipedia lo

Arduino - Wikimedia Commons
Jul 28, 2017 - Massimo Banzi (http://twit.tv/show/triangulation/110/) interviewed on the TV show Triangulation on the. T

Scientific mtti - Wikimedia Commons
with each other to co-operate i.n producing I others after It. The. oupling ... I pletely across a broad and deep river

nagarjunasagar dam - Wikimedia Commons
G. V. Gopalarao. Abstract. This article deals with the design and construction aspects of Nagarjunasagar. Dam situated i

LaTeX

en.wikibooks.org

June 18, 2016

Contents

I. 1.

2.

3.

4.

II. 5.

Getting Started

3

Introduction 1.1. What is TeX? . . . . 1.2. What is LaTeX? . . 1.3. Philosophy of use . . 1.4. Terms regarding TeX 1.5. What next? . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

Installation 2.1. Distributions . . . . . . . . . . . . 2.2. Custom installation with TeX Live 2.3. Editors . . . . . . . . . . . . . . . . 2.4. Bibliography management . . . . . 2.5. Viewers . . . . . . . . . . . . . . . 2.6. Tables and graphics tools . . . . . 2.7. References . . . . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . .

5 5 5 7 7 9

. . . . . . .

11 11 13 17 24 26 27 27

Installing Extra Packages 3.1. Automatic installation . 3.2. Manual installation . . . 3.3. Checking package status 3.4. Package documentation 3.5. External resources . . . 3.6. See Also . . . . . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

29 29 30 33 34 34 35

Basics 4.1. The LaTeX syntax 4.2. Our ﬁrst document 4.3. Compilation . . . . 4.4. Files . . . . . . . . 4.5. And what now? . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

37 37 41 42 45 47

. . . . .

. . . . .

. . . . .

Common Elements Document Structure 5.1. Global structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2. Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

49 51 51 52

III

Contents

6.

7.

8.

9.

IV

5.3. 5.4. 5.5. 5.6.

The document environment Book structure . . . . . . . Special pages . . . . . . . . Notes and references . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

54 59 61 62

Text 6.1. 6.2. 6.3. 6.4. 6.5. 6.6. 6.7. 6.8. 6.9. 6.10. 6.11. 6.12. 6.13. 6.14. 6.15.

Formatting Spacing . . . . . . . . . . . . . . . . . . . . Hyphenation . . . . . . . . . . . . . . . . . Quote-marks . . . . . . . . . . . . . . . . . Diacritics and accents . . . . . . . . . . . . Margin misalignment and interword spacing Ligatures . . . . . . . . . . . . . . . . . . . Slash marks . . . . . . . . . . . . . . . . . . Fonts . . . . . . . . . . . . . . . . . . . . . . Formatting macros . . . . . . . . . . . . . . Text mode superscript and subscript . . . . Text ﬁgures (”old style”numerals) . . . . . . Dashes and hyphens . . . . . . . . . . . . . Ellipsis (…) . . . . . . . . . . . . . . . . . . Ready-made strings . . . . . . . . . . . . . . Notes and References . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

63 63 66 67 68 69 69 70 71 71 71 72 73 74 74 75

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

77 77 77 79 79 80 81 86 87 87 87 88 88 90 92

Paragraph Formatting 7.1. Paragraph alignment . . . . 7.2. Paragraph indent and break 7.3. \paragraph line break . . . 7.4. Line spacing . . . . . . . . . 7.5. Manual breaks . . . . . . . 7.6. Special paragraphs . . . . . 7.7. Notes and References . . . .

. . . .

. . . . . . .

. . . .

. . . . . . .

. . . .

. . . . . . .

. . . .

. . . . . . .

. . . .

. . . . . . .

. . . .

. . . . . . .

. . . .

. . . . . . .

. . . .

. . . . . . .

. . . . . . .

Colors 8.1. Adding the color package . . . . . . . . 8.2. Entering colored text . . . . . . . . . . . 8.3. Entering colored background for the text 8.4. Predeﬁned colors . . . . . . . . . . . . . 8.5. Deﬁning new colors . . . . . . . . . . . . 8.6. Sources . . . . . . . . . . . . . . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

Fonts 9.1. Introduction . . . . . . 9.2. Font families . . . . . 9.3. Available LaTeX Fonts 9.4. Emphasizing text . . . 9.5. Font encoding . . . . . 9.6. Font styles . . . . . . . 9.7. Local font selection . . 9.8. Arbitrary font size . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

93 . 93 . 94 . 95 . 96 . 97 . 99 . 102 . 103

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

Contents 9.9. 9.10. 9.11. 9.12. 9.13.

Finding fonts . . . . . . . . Using arbitrary system fonts PDF fonts and properties . Useful websites . . . . . . . References . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

103 103 104 104 105

Structures List structures . Some special lists Customizing lists Easylist package

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

107 107 110 113 115

11. Special Characters 11.1. Input encoding . . . . . . . . . . . 11.2. Escaped codes . . . . . . . . . . . . 11.3. Less than < and greater than > . . 11.4. Euro € currency symbol . . . . . . 11.5. Degree symbol for temperature and 11.6. Other symbols . . . . . . . . . . . 11.7. In special environments . . . . . . 11.8. Unicode keyboard input . . . . . . 11.9. External links . . . . . . . . . . . . 11.10. Notes and References . . . . . . . .

. . . . . . . . . . . . . . . . math . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

119 119 122 123 124 124 125 127 128 129 129

12. Internationalization 12.1. Prerequisites . . . . 12.2. Babel . . . . . . . . 12.3. Multilingual versions 12.4. Speciﬁc languages . . 12.5. References . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

131 131 132 133 133 148

10. List 10.1. 10.2. 10.3. 10.4.

. . . .

. . . .

. . . .

. . . . .

. . . .

. . . . .

. . . .

. . . . .

. . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

13. Rotations 149 13.1. The rotating package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 13.2. The rotﬂoat package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 14. Tables 14.1. The tabular environment . 14.2. Row speciﬁcation . . . . . 14.3. Spanning . . . . . . . . . 14.4. Controlling table size . . . 14.5. Colors . . . . . . . . . . . 14.6. Width and stretching . . . 14.7. Table across several pages 14.8. Partial vertical lines . . . 14.9. Vertically centered images 14.10. Footnotes in tables . . . . 14.11. Professional tables . . . . 14.12. Sideways tables . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

151 151 163 163 168 169 171 175 176 177 177 178 181

V

Contents 14.13. 14.14. 14.15. 14.16. 14.17. 14.18.

Table with legend . . . . . . . . . . . The eqparbox package . . . . . . . . . Floating with table . . . . . . . . . . Using spreadsheets and data analysis Need more complicated features? . . References . . . . . . . . . . . . . . .

15. Title creation 15.1. Standard Titles . . . . . . 15.2. Custom Title Pages . . . . 15.3. Packages for custom titles 15.4. Notes and References . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . . . . . . . tools . . . . . . . . . .

. . . .

. . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

16. Page Layout 16.1. Two-sided documents . . . . . . . . . . . . . . . . 16.2. Page dimensions . . . . . . . . . . . . . . . . . . 16.3. Page size . . . . . . . . . . . . . . . . . . . . . . . 16.4. Margins . . . . . . . . . . . . . . . . . . . . . . . 16.5. Page orientation . . . . . . . . . . . . . . . . . . 16.6. Margins, page size and rotation of a speciﬁc page 16.7. Page styles . . . . . . . . . . . . . . . . . . . . . 16.8. Page background . . . . . . . . . . . . . . . . . . 16.9. Multi-column pages . . . . . . . . . . . . . . . . . 16.10. Manual page formatting . . . . . . . . . . . . . . 16.11. Widows and orphans . . . . . . . . . . . . . . . . 16.12. Troubleshooting . . . . . . . . . . . . . . . . . . . 16.13. Notes and References . . . . . . . . . . . . . . . . 17. Importing Graphics 17.1. Raster graphics vs. vector graphics 17.2. The graphicx package . . . . . . . . 17.3. Document Options . . . . . . . . . 17.4. Supported image formats . . . . . 17.5. Including graphics . . . . . . . . . 17.6. Graphics storage . . . . . . . . . . 17.7. Images as ﬁgures . . . . . . . . . . 17.8. Text wrapping around pictures . . 17.9. Seamless text integration . . . . . . 17.10. Including full PDF pages . . . . . . 17.11. Converting graphics . . . . . . . . 17.12. Third-party graphics tools . . . . . 17.13. Notes and References . . . . . . . . 18. Floats, Figures and Captions 18.1. Floats . . . . . . . . . . . . 18.2. Keeping ﬂoats in their place 18.3. Captions . . . . . . . . . . . 18.4. Lists of ﬁgures and tables .

VI

. . . .

. . . .

. . . .

. . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . .

181 182 182 184 185 185

. . . .

187 187 188 192 192

. . . . . . . . . . . . .

193 193 193 195 197 199 201 201 207 208 209 209 210 210

. . . . . . . . . . . . .

211 211 211 212 212 213 220 221 221 221 222 224 226 230

. . . .

231 231 233 234 238

Contents 18.5. 18.6. 18.7. 18.8. 18.9. 18.10. 18.11. 18.12.

Labels and cross-referencing . . . . . . Wrapping text around ﬁgures . . . . . Subﬂoats . . . . . . . . . . . . . . . . Wide ﬁgures in two-column documents Custom ﬂoats . . . . . . . . . . . . . . Labels in the ﬁgures . . . . . . . . . . Summary . . . . . . . . . . . . . . . . Notes and references . . . . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

239 240 244 245 246 248 248 249

19. Footnotes and Margin Notes 251 19.1. Footnotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 19.2. Margin Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 19.3. Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 20. Hyperlinks 20.1. Hyperref . . . . . . . 20.2. Usage . . . . . . . . 20.3. Customization . . . . 20.4. Troubleshooting . . . 20.5. Notes and References

. . . . .

. . . . .

. . . . .

. . . . .

21. Labels and Cross-referencing 21.1. Introduction . . . . . . . . . 21.2. Examples . . . . . . . . . . 21.3. The varioref package . . . 21.4. The hyperref package . . . 21.5. The cleveref package . . . 21.6. Interpackage interactions for 21.7. See also . . . . . . . . . . . 21.8. Notes and References . . . . III.

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . varioref . . . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

257 257 257 260 263 268

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . , hyperref , and cleveref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

269 269 270 274 275 276 276 277 277

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

Mechanics

279

22. Errors and Warnings 22.1. Error messages . . . . . . . . . . 22.2. Warnings . . . . . . . . . . . . . 22.3. Examples . . . . . . . . . . . . . 22.4. Software that can check your .tex

. . . . . . . . . . . . Code

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

281 281 282 282 286

23. Lengths 23.1. Units . . . . . . . . . . . . 23.2. Box lengths . . . . . . . . 23.3. Length manipulation . . . 23.4. LaTeX default lengths . . 23.5. Fixed-length spaces . . . . 23.6. Rubber/Stretching lengths 23.7. Examples . . . . . . . . . 23.8. References . . . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

287 287 288 288 289 290 291 292 293

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

VII

Contents 23.9.

See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293

24. Counters 24.1. Counter manipulation . . . . 24.2. Counter access . . . . . . . . 24.3. Counter style . . . . . . . . . 24.4. LaTeX default counters . . . 24.5. Book with parts, sections, but 24.6. Custom enumerate . . . . . . 24.7. Custom sectioning . . . . . .

. . . . . . .

295 295 295 296 296 297 297 297

. . . . . . . . . . .

299 299 300 300 301 302 302 303 304 304 304 304

26. Rules and Struts 26.1. Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26.2. Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26.3. Stretched rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

305 305 305 306

IV.

307

25. Boxes 25.1. TeX character boxes . 25.2. makebox and mbox . . 25.3. framebox . . . . . . . 25.4. framed . . . . . . . . . 25.5. raisebox . . . . . . . . 25.6. minipage and parbox . 25.7. savebox . . . . . . . . 25.8. rotatebox . . . . . . . 25.9. colorbox and fcolorbox 25.10. resizebox and scalebox 25.11. fancybox . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . no chapters . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

Technical Texts

27. Mathematics 27.1. Mathematics environments . . . . 27.2. Symbols . . . . . . . . . . . . . . 27.3. Greek letters . . . . . . . . . . . 27.4. Operators . . . . . . . . . . . . . 27.5. Powers and indices . . . . . . . . 27.6. Fractions and Binomials . . . . . 27.7. Roots . . . . . . . . . . . . . . . 27.8. Sums and integrals . . . . . . . . 27.9. Brackets, braces and delimiters . 27.10. Matrices and arrays . . . . . . . 27.11. Adding text to equations . . . . . 27.12. Formatting mathematics symbols 27.13. Color . . . . . . . . . . . . . . . . 27.14. Plus and minus signs . . . . . . . 27.15. Controlling horizontal spacing . .

VIII

. . . . . . . . . . .

. . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

309 309 310 311 312 313 313 317 319 321 324 328 329 331 331 332

Contents 27.16. 27.17. 27.18. 27.19. 27.20. 27.21. 27.22.

Manually Specifying Formula Style . . . . . . Advanced Mathematics: AMS Math package List of Mathematical Symbols . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . Notes . . . . . . . . . . . . . . . . . . . . . . Further reading . . . . . . . . . . . . . . . . . External links . . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

335 336 338 339 339 339 340

28. Advanced Mathematics 28.1. Equation numbering . . . . . . . . . . . . . . . . . . . 28.2. Vertically aligning displayed mathematics . . . . . . . 28.3. Indented Equations . . . . . . . . . . . . . . . . . . . . 28.4. Page breaks in math environments . . . . . . . . . . . 28.5. Boxed Equations . . . . . . . . . . . . . . . . . . . . . 28.6. Custom operators . . . . . . . . . . . . . . . . . . . . . 28.7. Advanced formatting . . . . . . . . . . . . . . . . . . . 28.8. Text in aligned math display . . . . . . . . . . . . . . 28.9. Changing font size . . . . . . . . . . . . . . . . . . . . 28.10. Forcing \displaystyle for all math in a document . . . 28.11. Adjusting vertical white space around displayed math 28.12. Notes . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

341 341 343 353 354 355 357 357 360 361 363 363 363

29. Theorems 29.1. Basic theorems . . 29.2. Theorem counters . 29.3. Proofs . . . . . . . 29.4. Theorem styles . . 29.5. Conﬂicts . . . . . . 29.6. Notes . . . . . . . 29.7. External links . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

365 365 365 366 367 368 368 368

. . . . . . . . . . .

371 371 374 374 376 376 378 378 380 380 381 381

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

30. Chemical Graphics 30.1. Basic Usage . . . . . . . . . . . . 30.2. Skeletal Diagrams . . . . . . . . . 30.3. Rings . . . . . . . . . . . . . . . 30.4. Lewis Structures . . . . . . . . . 30.5. Ions . . . . . . . . . . . . . . . . 30.6. Resonance Structures and Formal 30.7. Chemical Reactions . . . . . . . . 30.8. Naming Chemical Graphics . . . 30.9. Advanced Graphics . . . . . . . . 30.10. mhchem Package . . . . . . . . . 30.11. XyMTeX package . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . Charges . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

31. Algorithms 383 31.1. Typesetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 31.2. The algorithm environment . . . . . . . . . . . . . . . . . . . . . . . . . . 390 31.3. References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392

IX

Contents 32. Source Code Listings 32.1. Using the listings package . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2. The minted package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.3. References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

393 393 399 399

33. Linguistics 33.1. Enumerated examples 33.2. Syntactic trees . . . . 33.3. Glosses . . . . . . . . . 33.4. IPA characters . . . . 33.5. Phonological rules . . 33.6. References . . . . . . . 33.7. External links . . . . .

401 401 405 413 414 416 417 417

V.

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

Special Pages

419

34. Indexing 34.1. Using makeidx . . . . . . . . . . 34.2. Abbreviation list . . . . . . . . . 34.3. Multiple indices . . . . . . . . . . 34.4. Adding index to table of contents 34.5. International indices . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

421 421 424 425 425 426

35. Glossary 35.1. Jump start . . . . . . . 35.2. Using glossaries . . . 35.3. Deﬁning glossary entries 35.4. Deﬁning terms . . . . . 35.5. Using deﬁned terms . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

429 429 429 430 430 432

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

36. Displaying the Glossary 435 36.1. Building your document . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 37. Example for use in windows with Texmaker 37.1. Compile glossary with xindy - In Windows with 37.2. Document preamble . . . . . . . . . . . . . . . 37.3. Glossary deﬁnitions . . . . . . . . . . . . . . . . 37.4. Include glossary deﬁnitions and print glossary . 37.5. References . . . . . . . . . . . . . . . . . . . . .

Texmaker . . . . . . . . . . . . . . . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

439 439 439 440 440 440

38. Bibliography Management 38.1. Embedded system . . . . . . . . . . 38.2. Citations . . . . . . . . . . . . . . . . 38.3. BibTeX . . . . . . . . . . . . . . . . 38.4. Bibliography in the table of contents 38.5. biblatex . . . . . . . . . . . . . . . . 38.6. Multiple bibliographies . . . . . . . . 38.7. Notes and references . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

441 441 442 447 464 466 470 471

X

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

Contents 39. More Bibliographies 39.1. The example data . 39.2. The limits of BibTeX 39.3. Natbib . . . . . . . . 39.4. Citation . . . . . . . VI.

. . . . styles . . . . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

Special Documents

473 473 473 473 475 477

40. Letters 40.1. The letter class . . . . . . . . . . . 40.2. Envelopes . . . . . . . . . . . . . . 40.3. Windowed envelopes . . . . . . . . 40.4. Reference: letter.cls commands 40.5. Sources . . . . . . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

479 479 480 482 483 484

41. Presentations 41.1. The Beamer package . 41.2. The powerdot package 41.3. References . . . . . . . 41.4. Links . . . . . . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

485 485 497 498 498

42. Teacher’s Corner 42.1. Intro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2. The exam class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.3. References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

499 499 499 500

43. Curriculum Vitae 43.1. curve . . . . . . . . . 43.2. europecv . . . . . . . 43.3. moderncv . . . . . . 43.4. Multilingual support 43.5. References . . . . . .

501 501 501 504 506 506

. . . . .

. . . .

. . . . .

. . . .

. . . . .

. . . .

. . . . .

. . . .

. . . . .

. . . .

. . . . .

. . . .

. . . . .

. . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

VII. Creating Graphics

507

44. Introducing Procedural Graphics 509 44.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509 45. MetaPost 46. Picture 46.1. Basic commands . . . . . . 46.2. Line segments . . . . . . . . 46.3. Arrows . . . . . . . . . . . . 46.4. Circles . . . . . . . . . . . . 46.5. Text and formulae . . . . . 46.6. \multiput and \linethickness

511 . . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

513 513 514 514 515 517 517

XI

Contents 46.7. 46.8. 46.9. 46.10. 46.11. 46.12.

Ovals . . . . . . . . . . . . . . . . . . . Multiple use of predeﬁned picture boxes Quadratic Bézier curves . . . . . . . . . Catenary . . . . . . . . . . . . . . . . . Plotting graphs . . . . . . . . . . . . . . The picture environment and gnuplot . .

47. PGF/TikZ 47.1. Loading Package, Libraries 47.2. Specifying Coordinates . . . 47.3. Syntax for Paths . . . . . . 47.4. Drawing straight lines . . . 47.5. Drawing curved paths . . . 47.6. User-deﬁned paths . . . . . 47.7. Circles, ellipses . . . . . . . 47.8. Arcs . . . . . . . . . . . . . 47.9. Special curves . . . . . . . . 47.10. Nodes . . . . . . . . . . . . 47.11. Examples . . . . . . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

tikzpicture environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

48. PSTricks 48.1. The pspicture environment . 48.2. Fundamental objects . . . . . 48.3. Text . . . . . . . . . . . . . . 48.4. Grids . . . . . . . . . . . . . . 48.5. Generic parameters . . . . . . 48.6. Object location . . . . . . . . 48.7. The PDFTricks extension . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

518 520 521 522 524 525

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

527 527 528 528 529 535 536 538 539 539 542 546

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

551 551 551 553 554 555 557 558

49. Xy-pic

559

50. Creating 3D graphics

565

VIII. Programming

567

51. Macros 51.1. New commands . . . . . . . . . . . . . . . . 51.2. New environments . . . . . . . . . . . . . . 51.3. Declare commands within new environment 51.4. Extending the number of arguments . . . . 51.5. Arithmetic . . . . . . . . . . . . . . . . . . . 51.6. Conditionals . . . . . . . . . . . . . . . . . . 51.7. Loops . . . . . . . . . . . . . . . . . . . . . 51.8. Strings . . . . . . . . . . . . . . . . . . . . . 51.9. LaTeX Hooks . . . . . . . . . . . . . . . . . 51.10. Command-line LaTeX . . . . . . . . . . . . 51.11. Notes and References . . . . . . . . . . . . .

569 569 571 573 573 574 575 575 575 575 576 576

XII

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

Contents 52. Plain TeX 52.1. Vocabulary . . . . . . . . 52.2. Catcodes . . . . . . . . . . 52.3. Plain TeX macros . . . . . 52.4. Registers . . . . . . . . . . 52.5. Arithmetic . . . . . . . . . 52.6. Conditionals . . . . . . . . 52.7. Loops . . . . . . . . . . . 52.8. Doing nothing . . . . . . . 52.9. TeX characters . . . . . . 52.10. Verbatim lines and spaces 52.11. Macros deﬁning macros . 52.12. Notes and References . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

577 577 577 580 583 584 584 586 586 587 587 588 589

53. Creating Packages 53.1. makeatletter and makeatother 53.2. Creating your own package . . . 53.3. Creating your own class . . . . . 53.4. Hooks . . . . . . . . . . . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

591 591 591 593 594

54. Themes 54.1. Introduction . . . . . . 54.2. Package conﬁguration 54.3. Header and footer . . 54.4. Table of contents . . . 54.5. Sectioning . . . . . . . 54.6. Notes and References .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

595 595 597 598 598 599 601

IX.

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

Miscellaneous

55. Modular Documents 55.1. Project structure . . . . . . . . . . . . . 55.2. Getting LaTeX to process multiple ﬁles 55.3. The ﬁle mystyle.sty . . . . . . . . . . . 55.4. The main document document.tex . . . 55.5. External Links . . . . . . . . . . . . . .

603 . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

605 605 605 611 611 612

56. Collaborative Writing of LaTeX Documents 56.1. Abstract . . . . . . . . . . . . . . . . . . . . 56.2. Introduction . . . . . . . . . . . . . . . . . . 56.3. Interchanging Documents . . . . . . . . . . 56.4. The Version Control System Subversion . . 56.5. Hosting LaTeX ﬁles in Subversion . . . . . 56.6. Subversion really makes the diﬀerence . . . 56.7. Managing collaborative bibliographies . . . 56.8. Conclusion . . . . . . . . . . . . . . . . . . . 56.9. Acknowledgements . . . . . . . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

615 615 616 616 617 618 619 622 625 625

. . . . .

XIII

Contents 56.10. References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626 57. Export To Other Formats 57.1. Tools installation . . . . . 57.2. Preview mode . . . . . . . 57.3. Convert to PDF . . . . . 57.4. Convert to PostScript . . 57.5. Convert to RTF . . . . . . 57.6. Convert to HTML . . . . 57.7. Convert to image formats 57.8. Convert to plain text . . . X.

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

Help and Recommendations

627 627 627 628 630 630 631 631 634 635

58. FAQ 58.1. Margins are too wide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58.2. Avoid excessive double line breaks in source code . . . . . . . . . . . . . . 58.3. Simpliﬁed special character input . . . . . . . . . . . . . . . . . . . . . . . 58.4. Writing the euro symbol directly . . . . . . . . . . . . . . . . . . . . . . . 58.5. LaTeX paragraph headings have title and content on the same line . . . . 58.6. Fonts are ugly/jagged/bitmaps or PDF search fails or Copy/paste from PDF is messy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58.7. Manual formatting: use of line breaks and page breaks . . . . . . . . . . . 58.8. Always ﬁnish commands with {} . . . . . . . . . . . . . . . . . . . . . . . 58.9. Avoid bold and underline . . . . . . . . . . . . . . . . . . . . . . . . . . . 58.10. The proper way to use ﬁgures . . . . . . . . . . . . . . . . . . . . . . . . . 58.11. Text stops justifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58.12. Rules of punctuation and spacing . . . . . . . . . . . . . . . . . . . . . . . 58.13. Compilation fails after a Babel language change . . . . . . . . . . . . . . . 58.14. Learning LaTeX quickly or correctly . . . . . . . . . . . . . . . . . . . . . 58.15. Non-breaking spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58.16. Smart mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58.17. Use vector graphics rather than raster images . . . . . . . . . . . . . . . . 58.18. Stretching tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58.19. Tables are easier than you think . . . . . . . . . . . . . . . . . . . . . . . . 58.20. Relieving cumbersome code (lists and long command names) . . . . . . . 58.21. Reducing the size of your LaTeX installation . . . . . . . . . . . . . . . .

637 637 637 637 638 638

59. Tips 59.1. 59.2. 59.3. 59.4. 59.5. 59.6. 59.7. 59.8.

643 643 643 643 644 647 648 648 649

XIV

and Tricks Always writing LaTeX in roman . . . . . . . . . id est and exempli gratia (i.e. and e.g.) . . . . . . Grouping Figure/Equation Numbering by Section Graphics and Graph editors . . . . . . . . . . . . Spell-checking and Word Counting . . . . . . . . New even page . . . . . . . . . . . . . . . . . . . Sidebar with information . . . . . . . . . . . . . . Hide auxiliary ﬁles . . . . . . . . . . . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

638 638 639 639 639 640 640 640 640 641 641 641 641 642 642 642

Contents XI.

Appendices

651

60. Authors 653 60.1. Included books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653 60.2. Wiki users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653 61. Links

655

62. Package Reference

659

63. Sample LaTeX documents 663 63.1. General examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663 63.2. Semantics of Programming Languages . . . . . . . . . . . . . . . . . . . . 663 64. Index 64.1. A . 64.2. B . 64.3. C . 64.4. D . 64.5. E . 64.6. F . 64.7. G . 64.8. H . 64.9. I . 64.10. L . 64.11. M 64.12. P . 64.13. Q . 64.14. R . 64.15. S . 64.16. T . 64.17. U . 64.18. V . 64.19. W 64.20. X .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

65. Command Glossary 65.1. # . . . . . . . . . 65.2. A . . . . . . . . . 65.3. B . . . . . . . . . 65.4. C . . . . . . . . . 65.5. D . . . . . . . . . 65.6. E . . . . . . . . . 65.7. F . . . . . . . . . 65.8. G . . . . . . . . . 65.9. H . . . . . . . . . 65.10. I . . . . . . . . . 65.11. K . . . . . . . . . 65.12. L . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

665 665 665 665 666 666 666 667 667 667 668 668 668 669 669 669 669 670 670 670 670

. . . . . . . . . . . .

671 671 672 672 673 674 674 674 675 675 675 676 676

XV

Contents 65.13. 65.14. 65.15. 65.16. 65.17. 65.18. 65.19. 65.20. 65.21. 65.22.

M N. O. P . Q. R . S . T . U. V.

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

677 677 678 678 679 679 680 681 682 682

66. Contributors

685

List of Figures

717

67. Licenses 731 67.1. GNU GENERAL PUBLIC LICENSE . . . . . . . . . . . . . . . . . . . . 731 67.2. GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . 732 67.3. GNU Lesser General Public License . . . . . . . . . . . . . . . . . . . . . 733

1

Part I.

Getting Started

3

1. Introduction 1.1. What is TeX? TeX1 is a low-level markup and programming language created by Donald Knuth2 to typeset documents attractively and consistently. Knuth started writing the TeX typesetting engine in 1977 to explore the potential of the digital printing equipment that was beginning to inﬁltrate the publishing industry at that time, especially in the hope that he could reverse the trend of deteriorating typographical quality that he saw aﬀecting his own books and articles. With the release of 8-bit character support in 1989, TeX development has been essentially frozen with only bug ﬁxes released periodically. TeX is a programming language in the sense that it supports the if-else construct: you can make calculations with it (that are performed while compiling the document), etc., but you would ﬁnd it very hard to do anything else but typesetting with it. The ﬁne control TeX oﬀers over document structure and formatting makes it a powerful—and formidable—tool. TeX is renowned for being extremely stable, for running on many diﬀerent kinds of computers, and for being virtually bug free. The version numbers of TeX are converging toward π, with a current version number of 3.1415926. The name TeX is intended by its developer to be /’tɛx/ , with the ﬁnal consonant of loch or Bach. (Donald E. Knuth, The TeXbook) The letters of the name are meant to represent the capital Greek letters tau, epsilon, and chi, as TeX is an abbreviation of τέχνη (ΤΕΧΝΗ – technē), Greek for both ”art” and ”craft”, which is also the root word of technical. English speakers often pronounce it /’tɛk/ , like the ﬁrst syllable of technical. Programming in TeX generally progresses along a very gradual learning curve, requiring a signiﬁcant investment of time to build custom macros for text formatting. Fortunately, document preparation systems based on TeX, consisting of collections of pre-built macros, do exist. These pre-built macros are time saving, and automate certain repetitive tasks and help reduce user introduced errors; however, this convenience comes at the cost of complete design ﬂexibility. One of the most popular macro packages is called LaTeX.

1.2. What is LaTeX? LaTeX (pronounced either ”Lah-tech” or ”Lay-tech”) is a macro package based on TeX created by Leslie Lamport3 . Its purpose is to simplify TeX typesetting, especially for

1 2 3

https://en.wikibooks.org/wiki/TeX https://en.wikipedia.org/wiki/Donald%20Knuth https://en.wikipedia.org/wiki/Leslie%20Lamport

5

Introduction documents containing mathematical formulae. Within the typesetting system, its name is formatted as LATEX. Many later authors have contributed extensions, called packages or styles, to LaTeX. Some of these are bundled with most TeX/LaTeX software distributions; more can be found in the Comprehensive TeX Archive Network (CTAN4 ). Since LaTeX comprises a group of TeX5 commands, LaTeX document processing is essentially programming. You create a text ﬁle in LaTeX markup, which LaTeX reads to produce the ﬁnal document. This approach has some disadvantages in comparison with a WYSIWYG6 (What You See Is What You Get) program such as Openoﬃce.org7 Writer or Microsoft Word8 . In LaTeX: • You don’t (usually) see the ﬁnal version of the document when editing it. • You generally need to know the necessary commands for LaTeX markup. • It can sometimes be diﬃcult to obtain a certain look for the document. On the other hand, there are certain advantages to the LaTeX approach: • Document sources can be read with any text editor and understood, unlike the complex binary and XML9 formats used with WYSIWYG programs. • You can concentrate purely on the structure and contents of the document, not get caught up with superﬁcial layout issues. • You don’t need to manually adjust fonts, text sizes, line heights, or text ﬂow for readability, as LaTeX takes care of them automatically. • In LaTeX the document structure is visible to the user, and can be easily copied to another document. In WYSIWYG applications it is often not obvious how a certain formatting was produced, and it might be impossible to copy it directly for use in another document. • The layout, fonts, tables and so on are consistent throughout the document. • Mathematical formulae can be easily typeset. • Indexes, footnotes, citations and references are generated easily. • Since the document source is plain text, tables, ﬁgures, equations, etc. can be generated programmatically with any language. • You are forced to structure your documents correctly. The LaTeX document is a plain text ﬁle containing the content of the document, with additional markup. When the source ﬁle is processed by the macro package, it can produce documents in several formats. LaTeX natively supports DVI10 and PDF, but by using other software you can easily create PostScript, PNG, JPEG, etc.

4 5 6 7 8 9 10

6

http://www.ctan.org https://en.wikibooks.org/wiki/TeX https://en.wikipedia.org/wiki/WYSIWYG https://en.wikipedia.org/wiki/Openoffice.org https://en.wikipedia.org/wiki/Microsoft%20Word https://en.wikipedia.org/wiki/XML https://en.wikipedia.org/wiki/DVI%20file%20format

Philosophy of use

1.3. Philosophy of use 1.3.1. Flexibility and modularity One of the most frustrating things beginners and even advanced users might encounter using LaTeX is the lack of ﬂexibility regarding the document design and layout. If you want to design your document in a very speciﬁc way, you may have trouble accomplishing this. Keep in mind that LaTeX does the formatting for you, and mostly the right way. If it is not exactly what you desired, then the LaTeX way is at least not worse, if not better. One way to look at it is that LaTeX is a bundle of macros for TeX that aims to carry out everything regarding document formatting, so that the writer only needs to care about content. If you really want ﬂexibility, use plain TeX instead. One solution to this dilemma is to make use of the modular possibilities of LaTeX. You can build your own macros, or use macros developed by others. You are likely not the ﬁrst person to face some particular formatting problem, and someone who encountered a similar problem before may have published their solution as a package. CTAN11 is a good place to ﬁnd many resources regarding TeX and derivative packages. It is the ﬁrst place where you should begin searching.

1.3.2. Questions and documentation Besides internet resources being plentiful, the best documentation source remains the oﬃcial manual for every speciﬁc package, and the reference documentation, i.e., the TeXbook by D. Knuth and LaTeX: A document preparation system by L. Lamport. Therefore before rushing on your favorite web search engine, we really urge you to have a look at the package documentation that causes troubles. This oﬃcial documentation is most commonly installed along your TeX distribution, or may be found on CTAN12 .

1.4. Terms regarding TeX Document preparation systems LaTeX is a document preparation system based on TeX. So the system is the combination of the language and the macros. Distributions TeX distributions are collections of packages and programs (compilers, fonts, and macro packages) that enable you to typeset without having to manually fetch ﬁles and conﬁgure things. Engines

11 12

http://www.ctan.org/ http://www.ctan.org/

7

Introduction An engine is an executable that can turn your source code into a printable output format. The engine by itself only handles the syntax, it also needs to load fonts and macros to fully understand the source code and generate output properly. The engine will determine what kind of source code it can read, and what format it can output (usually DVI or PDF). All in all, distributions are an easy way to install what you need to use the engines and the systems you want. Distributions usually target speciﬁc operating systems. You can use diﬀerent systems on diﬀerent engines, but sometimes there are restrictions. Code written for TeX, LaTeX or ConTeXt are (mostly) not compatible. Additionally, engine-speciﬁc code (like font for XeTeX) may not be compiled by every engine. When searching for information on LaTeX, you might also stumble upon XeTeX13 , ConTeXt14 , LuaTeX15 or other names with a -TeX suﬃx. Let’s recap most of the terms in this table. Systems ConTeXt

LaTeX

MetaFont MetaPost TeX

Descriptions A TeX-based document preparation system (as LaTeX is) with a very consistent and easy syntax and support for pdfTeX, XeTeX and LuaTeX engines.It does not have the same objective as LaTeX however. A TeX-based document preparation system designed by Leslie Lamport. It is actually a set of macros for TeX. It aims at taking care of the formatting process. A high-quality font system designed by Donald Knuth along TeX. A descriptive vector graphics language based on MetaFont. The original language designed by Donald Knuth.

Engines luatex, lualatex pdftex, pdflatex tex, latex xetex, xelatex

TeX Distributions MacTeX MiKTeX TeX Live

13 14 15 16

8

Descriptions A TeX engine with Lua scripting engine embedded aiming at making TeX internals more ﬂexible. The engines (PDF compilers). The engines (DVI compilers). a TeX engine which uses Unicode and supports widely popular .ttf and .otf fonts. See Fonts16 . Descriptions A TeX Live based distribution targetting Mac OS X. A TeX distribution for Windows. A cross-platform TeX distribution.

https://en.wikipedia.org/wiki/XeTeX https://en.wikipedia.org/wiki/ConTeXt https://en.wikipedia.org/wiki/LuaTeX Chapter 9 on page 93

What next?

1.5. What next? In the next chapter we will proceed to the installation17 . Then we will compile our ﬁrst LaTeX ﬁle18 . Throughout this book you should also utilise other means for learning about LaTeX. Good sources are: • • • •

the #latex19 IRC channel on Freenode, the TeX Stack Exchange20 Q&A, the TeX21 FAQ, and the TeXample.net22 Community.

de:LaTeX/_Einleitung23 sr:LaTeX/Увод24

17 18 19 20 21 22 23 24

Chapter 2 on page 11 Chapter 4 on page 37 http://webchat.freenode.net?channels=latex http://tex.stackexchange.com/ http://www.tex.ac.uk/ http://www.texample.net/ https://de.wikibooks.org/wiki/LaTeX%2F_Einleitung https://sr.wikibooks.org/wiki/LaTeX%2F%D0%A3%D0%B2%D0%BE%D0%B4

9

2. Installation If this is the ﬁrst time you are trying out LaTeX, you don’t even need to install anything. For quick testing purpose you may just create a user account with an online LaTeX editor1 and continue this tutorial in the next chapter. These websites oﬀer collaboration capabilities while allowing you to experiment with LaTeX syntax without having to bother with installing and conﬁguring a distribution and an editor. When you later feel that you would beneﬁt from having a standalone LaTeX installation, you can return to this chapter and follow the instructions below. LaTeX is not a program by itself; it is a language. Using LaTeX requires a bunch of tools. Acquiring them manually would result in downloading and installing multiple programs in order to have a suitable computer system that can be used to create LaTeX output, such as PDFs. TeX Distributions help the user in this way, in that it is a single step installation process that provides (almost) everything. At a minimum, you’ll need a TeX distribution, a good text editor and a DVI or PDF viewer. More speciﬁcally, the basic requirement is to have a TeX compiler (which is used to generate output ﬁles from source), fonts, and the LaTeX macro set. Optional, and recommended installations include an attractive editor to write LaTeX source documents (this is probably where you will spend most of your time), and a bibliographic management program to manage references if you use them a lot.

2.1. Distributions TeX and LaTeX are available for most computer platforms, since they were programmed to be very portable. They are most commonly installed using a distribution, such as teTeX, MiKTeX, or MacTeX. TeX distributions are collections of packages and programs (compilers, fonts, and macro packages) that enable you to typeset without having to manually fetch ﬁles and conﬁgure things. LaTeX is just a set of macro packages built for TeX. The recommended distributions for each of the major operating systems are: • TeX Live2 is a major TeX distribution for *BSD, GNU/Linux, Mac OS X and Windows. • MiKTeX3 is a Windows-speciﬁc distribution. • MacTeX4 is a Mac OS-speciﬁc distribution based on TeX Live.

1 2 3 4

Chapter 2.3.5 on page 23 http://www.tug.org/texlive/ http://www.miktex.org/ http://www.tug.org/mactex/

11

Installation These, however, do not necessarily include an editor. You might be interested in other programs that are not part of the distribution, which will help you in writing and preparing TeX and LaTeX ﬁles.

2.1.1. *BSD and GNU/Linux In the past, the most common distribution used to be teTeX. As of May 2006 teTeX is no longer actively maintained and its former maintainer Thomas Esser recommended TeX Live as the replacement.5 The easy way to get TeX Live is to use the package manager or portage tree coming with your operating system. Usually it comes as several packages, with some of them being essential, other optional. The core TeX Live packages should be around 200-300 MB. If your *BSD or GNU/Linux distribution does not have the TeX Live packages, you should report a wish to the bug tracking system. In that case you will need to download TeX Live6 yourself and run the installer by hand. You may wish to install the content of TeX Live more selectively. See below7 .

2.1.2. Mac OS X Mac OS X users may use MacTeX8 , a TeX Live-based distribution supporting TeX, LaTeX, AMSTeX, ConTeXt, XeTeX and many other core packages. Download MacTeX.mpkg.zip on the MacTeX page9 , unzip it and follow the instructions. Further information for Mac OS X users can be found on the TeX on Mac OS X Wiki10 . Since Mac OS X is also a Unix-based system, TeX Live is naturally available through MacPorts11 and Fink12 . Homebrew13 users should use the oﬃcial MacTeX installer14 because of the unique directory structure used by TeX Live15 . Further information for Mac OS X users can be found on the TeX on Mac OS X Wiki16 .

2.1.3. Microsoft Windows Microsoft Windows users can install MiKTeX17 onto their computer. It has an easy installer that takes care of setting up the environment and downloading core packages. This 5 6 7 8 9 10 11 12 13 14 15 16 17

12

teTeX Home Page ˆ{http://www.tug.org/tetex/} (Retrieved January 31, 2007) http://www.tug.org/texlive/acquire.html Chapter 2.2 on page 13 http://tug.org/mactex/ http://www.tug.org/mactex/ http://mactex-wiki.tug.org/ http://www.macports.org/ http://www.finkproject.org/ http://brew.sh/ http://www.tug.org/mactex/ https://github.com/Homebrew/homebrew/issues/1087 http://mactex-wiki.tug.org/ http://miktex.org/

Custom installation with TeX Live distribution has advanced features, such as automatic installation of packages, and simple interfaces to modify settings, such as default paper sizes. There is also a port of TeX Live available for Windows.

2.2. Custom installation with TeX Live This section targets users who want ﬁne-grained control over their TeX distribution, like an installation with a minimum of disk space usage. If it is none of your concern, you may want to jump to the next section18 . Picky users may wish to have more control over their installation. Common distributions might be tedious for the user caring about disk space. In fact, MikTeX and MacTeX and packaged TeX Live features hundreds of LaTeX packages, most of them which you will never use. Most Unix with a package manager will oﬀer TeX Live as a set of several big packages, and you often have to install 300–400 MB for a functional system. TeX Live features a manual installation with a lot of possible customizations. You can get the network installer at tug.org19 . This installer allows you to select precisely the packages you want to install. As a result, you may have everything you need for less than 100 MB. TeX Live is then managed through its own package manager, tlmgr. It will let you conﬁgure the distributions, install or remove extra packages and so on. You will need a Unix-based operating system for the following. Mac OS X, GNU/Linux or *BSD are ﬁne. It may work for Windows but the process must be quite diﬀerent. TeX Live groups features and packages into diﬀerent concepts: • Collections are groups of packages that can always be installed individually, except for the Essential programs and ﬁles collection. You can install collections at any time. • Installation Schemes group collections and packages. Schemes can only be used at installation time. You can select only one scheme at a time.

2.2.1. Minimal installation We will give you general guidelines to install a minimal TeX distribution (i.e., only for plain TeX). 1. Download the installer at http://mirror.ctan.org/systems/texlive/tlnet/ install-tl-unx.tar.gz and extract it to a temporary folder. 2. Open a terminal in the extracted folder and log in as root. 3. Change the umask20 permissions to 022 (user read/write/execute, group/others read/execute only) to make sure other users will have read-only access to the installed distribution.

18 19 20

Chapter 2.3 on page 17 http://www.tug.org/texlive/acquire-netinstall.html https://en.wikipedia.org/wiki/umask

13

Installation

B

Warning

All administration operations for TeX Live should be made with a 022 umask. Otherwise you will not be able to use TeX at all with an unprivileged user. 1. Launch install-tl. 2. Select the minimal scheme (plain only). 3. You may want to change the directory options. For example you may want to hide your personal macro folder which is located at TEXMFHOME. It is ˜/texmf by default. Replace it by ˜/.texmf to hide it. 4. Now the options: a) use letter size instead of A4 by default: mostly for users from the USA. b) execution of restricted list of programs: it is recommended to select it for security reasons. Otherwise it allows the TeX engines to call any external program. You may still conﬁgure the list afterwards. c) create format ﬁles: targetting a minimal disk space, the best choice depends on whether there is only one user on the system, then deselecting it is better, otherwise select it. From the help menu: ”If this option is set, format ﬁles are created for system-wide use by the installer. Otherwise they will be created automatically when needed. In the latter case format ﬁles are stored in user’s directory trees and in some cases have to be re-created when new packages are installed.” d) install font/macro doc tree: useful if you are a developer, but very space consuming. Turn it oﬀ if you want to save space. e) install font/macro source tree: same as above. f) Symlinks are ﬁne by default, change it if you know what you are doing. 5. Select portable installation if you install the distribution to an optical disc, or any kind of external media. Leave to default for a traditional installation on the system hard drive. At this point it should display 1 collections out of 85, disk space required: 40 MB

or a similar space usage. You can now proceed to installation: start installation to hard disk. Don’t forget to add the binaries to your PATH21 as it’s noticed at the end of the installation procedure.

21

14

https://en.wikipedia.org/wiki/PATH%20%28variable%29

Custom installation with TeX Live

2.2.2. First test In a terminal write $tex '\empty Hello world!\bye'$ pdftex '\empty Hello world!\bye'

You should get a DVI or a PDF ﬁle accordingly.

2.2.3. Conﬁguration Formerly, TeX distributions used to be conﬁgured with the texconfig tool from the teTeX distribution. TeX Live still features this tool, but recommends using its own tool instead: tlmgr. Note that as of January 2013 not all texconfig features are implemented by tlmgr. Only use texconfig when you cannot do what you want with tlmgr. List current installation options: tlmgr option

You can change the install options: tlmgr option src 1 tlmgr option doc 0 tlmgr option paper letter

See the TLMGR(1) man page for more details on its usage. If you did not install the documents as told previously, you can still access the tlmgr man page with tlmgr help

2.2.4. Installing LaTeX

B

Warning

Do not forget to set the root umask to 022 for all TeX Live administration operations. Now we have a running plain TeX environment, let’s install the base packages for LaTeX. # tlmgr install latex latex-bin latexconfig latex-fonts

15

Installation In this case you can omit latexconfig latex-fonts as they are auto-resolved dependencies to LaTeX. Note that tlmgr resolves some dependencies, but not all. You may need to install dependencies manually. Thankfully this is rarely too cumbersome. Other interesting packages: # tlmgr install amsmath babel carlisle ec geometry graphics hyperref lm marvosym oberdiek parskip pdftex-def url

amsmath babel carlisle ec geometry graphics hyperref lm marvosym oberdiek parskip pdftex-def url

The essentials for math typesetting. Internationalization support. Bundle package required for some babel features. Required for T1 encoding. For page layout. The essentials to import graphics. PDF bookmarks, PDF followable links, link style, TOC links, etc. One of the best Computer Modern style font available for several font encodings (such as T1). Several symbols, such as the oﬃcial euro. Bundle package required for some geometry features. Let you conﬁgure paragraph breaks and indents properly. Required for some graphics features. Required for some hyperref features.

If you installed a package you do not need anymore, use # tlmgr remove

2.2.5. Hyphenation If you are using Babel for non-English documents, you need to install the hyphenation patterns for every language you are going to use. They are all packaged individually. For instance, use # tlmgr install hyphen-{finnish,sanskrit}

for ﬁnnish and sanskrit hyphenation patterns. Note that if you have been using another TeX distribution beforehand, you may still have hyphenation cache stored in you home folder. You need to remove it so that the new packages are taken into account. The TeX Live cache is usually stored in the ˜/.texliveYYYY folder (YYYY stands for the year). You may safely remove this folder as it contains only generated data. TeX compilers will re-generate the cache accordingly on next compilation.

16

Editors

2.2.6. Uninstallation By default TeX Live will install in /usr/local/texlive. The distribution is quite proper as it will not write any ﬁle outside its folder, except for the cache (like font cache, hyphenation patters, etc.). By default, • the system cache goes in /var/lib/texmf; • the user cache goes in ˜/.texliveYYYY. Therefore TeX Live can be installed and uninstalled safely by removing the aforementioned folders. Still, TeX Live provides a more convenient way to do this: # tlmgr uninstall

You may still have to wipe out the folders if you put untracked ﬁles in them.

2.3. Editors TeX and LaTeX source documents (as well as related ﬁles) are all text ﬁles, and can be opened and modiﬁed in almost any text editor. You should use a text editor (e.g. Notepad), not a word processor (Word, OpenOﬃce). Dedicated LaTeX editors are more useful than generic plain text editors, because they usually have autocompletion of commands, spell and error checking and handy macros.

2.3.1. Cross-platform BaKoMa TeX BaKoMa TeX22 is an editor for Windows and Mac OS with WYSIWYG-like features. It takes care of compiling the LaTeX source and updating it constantly to view changes to document almost in real time. You can take an evaluation copy for 28 days. Emacs Emacs23 is a general purpose, extensible text processing system. Advanced users can program it (in elisp) to make Emacs the best LaTeX environment that will ﬁt their needs. In turn beginners may prefer using it in combination with AUCTeX24 and Reftex (extensions that may be installed into the Emacs program). Depending on your conﬁguration, Emacs can provide a complete LaTeX editing environment with auto-completion, spell-checking,

22 23 24

17

Installation a complete set of keyboard shortcuts, table of contents view, document preview and many other features. gedit-latex-plugin Gedit with gedit-latex-plugin25 is also worth trying out for users of GNOME. GEdit is a cross-platform application for Windows, Mac, and Linux Gummi

Figure 1 a

Screenshot of Gummia .

https://en.wikipedia.org/wiki/Gummi%20%28software%29

Gummi26 is a LaTeX editor for Linux, which compiles the output of pdﬂatex in realtime and shows it on the right half of the screen27 .

25 26 27

18

https://wiki.gnome.org/Apps/Gedit/LaTeXPlugin https://en.wikipedia.org/wiki/Gummi%20%28software%29 Gummi ˆ{http://gummi.midnightcoding.org/}

Editors LyX

Figure 2

LyX1.6.3

LyX28 is a popular document preparation system for Windows, Linux and Mac OS. It provides a graphical interface to LaTeX, including several popular packages. It contains formula and table editors and shows visual clues of the ﬁnal document on the screen enabling users to write LaTeX documents without worrying about the actual syntax. LyX calls this a What You See Is What You Mean (WYSIWYM) approach.29 LyX saves its documents in their own markup, and generates LaTeX code based on this. The user is mostly isolated from the LaTeX code and not in complete control of it, and as such LyX is not a normal LaTeX editor. However, as LaTeX is underlying system, knowledge of how that works is useful also for a LyX user. In addition, if one wants to do something that is not supported in the GUI, using LaTeX code may be required.

28 29

https://en.wikipedia.org/wiki/LyX LyX ˆ{http://www.lyx.org/}

19

Installation TeXmaker TeXmaker30 is a cross-platform editor very similar to Kile in features and user interface. In addition it has its own PDF viewer. TeXstudio TeXstudio31 is a cross-platform open source LaTeX editor forked from Texmaker. TeXworks

Figure 3

Screenshot of TeXworks on Ubuntu 12.10.

TeXworks32 is a dedicated TeX editor that is included in MiKTeX and TeX Live. It was developed with the idea that a simple interface is better than a cluttered one, and thus to make it easier for people in their early days with LaTeX to get to what they want to do: write their documents. TeXworks originally came about precisely because a math professor wanted his students to have a better initial experience with LaTeX. You can install TeXworks with the package manager of your Linux distribution or choose it as an install option in the Windows or Mac installer.

30 31 32

20

http://www.xm1math.net/texmaker/ http://texstudio.sourceforge.net/ https://en.wikipedia.org/wiki/TeXworks

Editors Vim Vim33 is another general purpose text editor for a wide variety of platforms including UNIX, Mac OS X and Windows. A variety of extensions exist including LaTeX Box34 and VimLaTeX35 .

2.3.2. *BSD and GNU/Linux-only Kile

Figure 4 a

Screenshot of Kilea .

https://en.wikipedia.org/wiki/Kile

Kile36 is a LaTeX editor for KDE37 (cross platform), providing a powerful GUI for editing multiple documents and compiling them with many diﬀerent TeX compilers. Kile is based

33 34 35 36 37

https://en.wikipedia.org/wiki/Vim%20%28text%20editor%29 http://www.vim.org/scripts/script.php?script_id=3109 http://vim-latex.sourceforge.net/ http://kile.sourceforge.net/ http://en.wikipedia.org/wiki/KDE_Software_Compilation_4

21

Installation on Kate editor, has a quick access toolbar for symbols, document structure viewer, a console and customizable build options. Kile can be run in all operating systems that can run KDE. LaTeXila LaTeXila38 is another text editor for Linux (Gnome).

2.3.3. Mac OS X-only TeXShop TeXShop39 is a TeXworks-like editor and previewer for Mac OS that is bundled with the MacTeX distribution. It uses multiple windows, one for editing the source, one for the preview, and one as a console for error messages. It oﬀers one-click updating of the preview and allows easy crossﬁnding between the code and the preview by using CMD-click. TeXnicle TeXnicle40 is a free editor for Mac OS that includes the ability to perform live updates. It includes a code library for the swift insertion of code and the ability to execute detailed word counts on documents. It also performs code highlighting and the editing window is customisable, permitting the user to select the font, colour, background colour of the editing environment. It is in active development. Archimedes Archimedes41 is an easy-to-use LaTeX and Markdown editor designed from the ground up for Mac OS X. It includes a built-in LaTeX library, code completion support, live previews, macro support, integration with sharing services, and PDF and HTML export options. Archimedes’s Magic Type feature lets users insert mathematical symbols just by drawing them on their MacBook’s trackpad or Magic Trackpad.

2.3.4. Windows-only LEd LEd42

38 39 40 41 42

22

http://projects.gnome.org/latexila/ http://www.uoregon.edu/~koch/texshop/ http://www.bobsoft-mac.de/texnicle/texnicle.html http://www.mattrajca.com/archimedes http://www.latexeditor.org/

Editors TeXnicCenter TeXnicCenter43 is a popular free and open source LaTeX editor for Windows. It also has a similar user interface to TeXmaker and Kile. WinEdt WinEdt44 is a powerful and versatile text editor with strong predisposition towards creation of LaTeX/TeX documents for Windows. It has been designed and conﬁgured to integrate with TeX Systems such as MiTeX or TeX Live. Its built-in macro helps in compiling the LaTeX source to the WYSIWYG-like DVI or PDF or PS and also in exporting the document to other mark-up languages as HTML or XML. WinShell WinShell45

2.3.5. Online solutions To get started without needing to install anything, you can use a web-hosted service featuring a full TeX distribution and a web LaTeX editor. • Authorea46 is an integrated online framework for the creation of technical documents in collaboration. Authorea’s frontend allows you to enter text in LaTeX or Markdown, as well as ﬁgures, and equations (in LaTeX or MathML). Authorea’s versioning control system is entirely based on Git (every article is a Git repository). • Overleaf47 is a secure, easy to use online LaTeX editor with integrated rapid preview like EtherPad48 for LaTeX. Start writing with one click (no signup required) and share the link. It supports real time preview, ﬁgures, bibliographies and custom styles. • publications.li49 is a real-time collaborative LaTeX editor running the open-source editor \BlueLatex50 . • ShareLaTeX.com51 is a secure cloud-based LaTeX editor oﬀering unlimited free project. Premium accounts are available for extra features such as version control and Dropbox integration.

43 44 45 46 47 48 49 50 51

http://www.texniccenter.org/ http://www.winedt.com/ http://www.winshell.de/ https://authorea.com https://www.overleaf.com http://en.wikipedia.org/wiki/Etherpad http://blue.publications.li https://github.com/gnieh/bluelatex https://www.sharelatex.com

23

Installation • SimpleLaTeX52 is an online editor and previewer for short LaTeX notes, which can be optionally cached or shared. Previews are available in SVG, PNG, and PDF. It also includes a simple GUI for editing tables. • Verbosus53 is a professional Online LaTeX Editor that supports collaboration with other users and is free to use. Merge conﬂicts can easily resolved by using a built-in merge tool that uses an implementation of the diﬀ-algorithm to generate information required for a successful merge.

2.4. Bibliography management Bibliography ﬁles (*.bib) are most easily edited and modiﬁed using a management system. These graphical user interfaces all feature a database form, where information is entered for each reference item, and the resulting text ﬁle can be used directly by BibTeX.

52 53

24

http://simplelatex.com http://www.verbosus.com

Bibliography management

2.4.1. Cross-platform

Figure 5 a

Screenshot of JabRefa .

https://en.wikipedia.org/wiki/JabRef

• JabRef54 • Mendeley55 • Zotero56

54 55 56

http://jabref.sourceforge.net/ http://www.mendeley.com// https://zotero.org/

25

Installation

2.4.2. Mac OS X-only

Figure 6

Screenshot of BibDesk

• BibDesk57 is a bibliography manager based on a BibTeX ﬁle. It imports references from the internet and makes it easy to organize references using tags and categories58 .

2.5. Viewers Finally, you will need a viewer for the ﬁles LaTeX outputs. Normally LaTeX saves the ﬁnal document as a .dvi (Device independent ﬁle format), but you will rarely want it to. DVI ﬁles do not contain embedded fonts and many document viewers are unable to open them. Usually you will use a LaTeX compiler like pdflatex to produce a PDF ﬁle directly, or a tool like dvi2pdf to convert the DVI ﬁle to PDF format. Then you can view the result with any PDF viewer. Practically all LaTeX distributions have a DVI viewer for viewing the default output of latex, and also tools such as dvi2pdf for converting the result automatically to PDF and PS formats. Here follows a list of various PDF viewers.

57 58

26

https://en.wikipedia.org/wiki/BibDesk BibDesk ˆ{http://bibdesk.sourceforge.net/}

Tables and graphics tools • • • • • • • • •

PDF.js (built-in modern browsers) Evince59 (Linux GNOME) Foxit60 (Windows) Okular61 (Linux KDE) Preview (built-in Mac OS X) Skim62 (Mac OS X) Sumatra PDF63 (Windows) Xpdf64 (Linux) Zathura65 (Linux)

2.6. Tables and graphics tools LaTeX is a document preparation system, it does not aim at being a spreadsheet tool nor a vector graphics tool. If LaTeX can render beautiful tables in a dynamic and ﬂexible manner, it will not handle the handy features you could get with a spreadsheet like dynamic cells and calculus. Other tools are better at that. The ideal solution is to combine the strength of both tools: build your dynamic table with a spreadsheet, and export it to LaTeX to get a beautiful table seamlessly integrated to your document. See Tables66 for more details. The graphics topic is a bit diﬀerent since it is possible to write procedural graphics67 from within your LaTeX document. Procedural graphics produce state-of-the-art results that integrates perfectly to LaTeX (e.g. no font change), but have a steep learning curve and require a lot of time to draw. For easier and quicker drawings, you may want to use a WYSIWYG tool and export the result to a vector format like PDF. The drawback is that it will contrast in style with the rest of your document (font, size, etc.). Some tools have the capability to export to LaTeX, which will partially solve this issue. See Importing Graphics68 for more details.

2.7. References de:LaTeX/_Installation69 sr:LaTeX/Инсталација70

59 60 61 62 63 64 65 66 67 68 69 70

https://wiki.gnome.org/Apps/Evince http://www.foxitsoftware.com/Secure_PDF_Reader/ https://okular.kde.org/ http://skim-app.sourceforge.net/ http://www.sumatrapdfreader.org/free-pdf-reader.html http://www.foolabs.com/xpdf/about.html https://pwmt.org/projects/zathura/ Chapter 14 on page 151 Chapter 44 on page 509 Chapter 17 on page 211 https://de.wikibooks.org/wiki/LaTeX%2F_Installation https://sr.wikibooks.org/wiki/LaTeX%2F%D0%98%D0%BD%D1%81%D1%82%D0%B0%D0%BB%D0%B0%D1%86%D0%B8%D1%98%D0%B0

27

3.1. Automatic installation If on an operating system with a package manager or a portage tree, you can often ﬁnd packages in repositories. With MikTeX there is a package manager that allows you to pick the package you want individually. As a convenient feature, upon the compilation of a ﬁle requiring non-installed packages, MikTeX will automatically prompt to install the missing ones. With TeX Live, it is common to have the distribution packed into a few big packages. For example, to install something related to internationalization, you might have to install 1 2

http://www.ctan.org/search.html http://www.ctan.org/

29

Installing Extra Packages a package like texlive-lang. With TeX Live manually installed, use tlmgr to manage packages individually. tlmgr install ... tlmgr remove ...

The use of tlmgr is covered in the Installation3 chapter. If you cannot ﬁnd the wanted package with any of the previous methods, see the manual installation.

3.2. Manual installation 3.2.1. Downloading packages What you need to look for is usually two ﬁles, one ending in .dtx and the other in .ins. The ﬁrst is a DOCTeX ﬁle, which combines the package program and its documentation in a single ﬁle. The second is the installation routine (much smaller). You must always download both ﬁles. If the two ﬁles are not there, it means one of two things: • Either the package is part of a much larger bundle which you shouldn’t normally update unless you change UNKNOWN TEMPLATE FULLBOOKNAME version of LaTeX; • or it’s an older or relatively simple package written by an author who did not use a .dtx ﬁle. Download the package ﬁles to a temporary directory. There will often be a readme.txt with a brief description of the package. You should of course read this ﬁle ﬁrst.

3.2.2. Installing a package There are ﬁve steps to installing a LaTeX package. (These steps can also be used on the pieces of a complicated package you wrote yourself; in this case, skip straight to Step 3.) 1. Extract the ﬁles Run LaTeX on the .ins ﬁle. That is, open the ﬁle in your editor and process it as if it were a LaTeX document (which it is), or if you prefer, type latex followed by the .ins ﬁlename in a command window in your temporary directory. This will extract all the ﬁles needed from the .dtx ﬁle (which is why you must have both of them present in the temporary directory). Note down or print the names of the ﬁles created if there are a lot of them (read the log ﬁle if you want to see their names again). 2. Create the documentation Run LaTeX on the .dtx ﬁle. You might need to run it twice or more, to get the cross-references right (just like any other LaTeX document). This will create a .dvi ﬁle of documentation explaining what the package is for and how

3

30

Chapter 2 on page 11

Manual installation to use it. If you prefer to create PDF then run pdfLaTeX instead. If you created a .idx as well, it means that the document contains an index, too. If you want the index to be created properly, follow the steps in the indexing4 section. Sometimes you will see that a .glo (glossary) ﬁle has been produced. Run the following command instead: makeindex -s gglo.ist -o name.gls name.glo

bibtex/bib/bibliography bibtex/bst/packagename tex/latex/base doc fonts/enc

Description Adobe Font Metrics for Type 1 fonts BibTeX bibliography BibTeX style Document class ﬁle package documentation Font encoding

Chapter 34 on page 421

31

Installing Extra Packages Where to put ﬁles from packages Type Directory (under texmf/ or texmflocal/) .fd tex/latex/mfnfss .fd

tex/latex/psnfss

.map .mf .pdf .pfb .sty

fonts/map fonts/source/public/typeface doc fonts/type1/foundry/typeface tex/latex/packagename

.tex

doc

.tex .tfm

tex/plain/packagename fonts/tfm/foundry/typeface

.ttf .vf others

fonts/truetype/foundry/typeface fonts/vf/foundry/typeface tex/latex/packagename

Description Font Deﬁnition ﬁles for METAFONT fonts Font Deﬁnition ﬁles for PostScript Type 1 fonts Font mapping ﬁles METAFONT outline package documentation PostScript Type 1 outline Style ﬁle: the normal package content TeX source for package documentation Plain TeX macro ﬁles TeX Font Metrics for METAFONT and Type 1 fonts TrueType font TeX virtual fonts other types of ﬁle unless instructed otherwise

For most fonts on CTAN, the foundry is public. 4. Update your index Finally, run your TeX indexer program to update the package database. This program comes with every modern version of TeX and has various names depending on the LaTeX distribution you use. (Read the documentation that came with your installation to ﬁnd out which it is, or consult http://www.tug.org/fonts/fontinstall. html#fndb): • • • • •

teTeX, TeX Live, fpTeX: texhash web2c: mktexlsr MacTeX: MacTeX appears to do this for you. MikTeX: initexmf --update-fndb (or use the GUI) MiKTeX 2.7 or later versions, installed on Windows XP through Windows 7: Start -> All Programs -> MikTex -> Settings. In Windows 8 use the keyword Settings and choose the option of Settings with the MiKTex logo. In Settings menu choose the ﬁrst tab and click on Refresh FNDB-button (MikTex will then check the Program Files directory and update the list of File Name DataBase). After that just verify by clicking ’OK’.

B

Warning

This step is utterly essential, otherwise nothing will work. 5. Update font maps If your package installed any TrueType or Type 1 fonts, you need to update the font mapping ﬁles in addition to updating the index. Your package author

32

Checking package status should have included a .map ﬁle for the fonts. The map updating program is usually some variant on updmap, depending on your distribution: • TeX Live and MacTeX: updmap --enable Map=mapfile.map (if you installed the ﬁles in a personal tree) or updmap-sys --enable Map=mapfile.map (if you installed the ﬁles in a system directory). • MikTeX: Run initexmf --edit-config-file updmap, add the line ”Map mapfile.map to the ﬁle that opens, then run initexmf --mkmaps. See http://www.tug.org/fonts/fontinstall.html. The reason this process has not been automated widely is that there are still thousands of installations which do not conform to the TDS, such as old shared Unix systems and some Microsoft Windows systems, so there is no way for an installation program to guess where to put the ﬁles: you have to know this. There are also systems where the owner, user, or installer has chosen not to follow the recommended TDS directory structure, or is unable to do so for political or security reasons (such as a shared system where the user cannot write to a protected directory). The reason for having the texmf-local directory (called texmf.local on some systems) is to provide a place for local modiﬁcations or personal updates, especially if you are a user on a shared or managed system (Unix, Linux, VMS, Windows NT/2000/XP, etc.) where you may not have write-access to the main TeX installation directory tree. You can also have a personal texmf subdirectory in your own login directory. Your installation must be conﬁgured to look in these directories ﬁrst, however, so that any updates to standard packages will be found there before the superseded copies in the main texmf tree. All modern TeX installations should do this anyway, but if not, you can edit texmf/web2c/texmf.cnf yourself.

3.3. Checking package status The universal way to check if a ﬁle is available to TeX compilers is the command-line tool kpsewhich. $kpsewhich tikz /usr/local/texlive/2012/texmf-dist/tex/plain/pgf/frontendlayer/tikz.tex kpsewhich will actually search for ﬁles only, not for packages. It returns the path to the ﬁle. For more details on a speciﬁc package use the command-line tool tlmgr (TeX Live only): tlmgr info The tlmgr tool has lot more options. To consult the documentation: tlmgr help 33 Installing Extra Packages 3.4. Package documentation To ﬁnd out what commands a package provides (and thus how to use it), you need to read the documentation. In the texmf/doc subdirectory of your installation there should be directories full of .dvi ﬁles, one for every package installed. This location is distributionspeciﬁc, but is typically found in: Distribution MacTeX MiKTeX TeX Live Path /Library/TeX/Documentation/texmf-doc/latex %MIKTEX_DIR%\doc\latex$TEXMFDIST/doc/latex

Generally, most of the packages are in the latex subdirectory, although other packages (such as BibTeX and font packages) are found in other subdirectories in doc. The documentation directories have the same name of the package (e.g. amsmath), which generally have one or more relevant documents in a variety of formats (dvi, txt, pdf, etc.). The documents generally have the same name as the package, but there are exceptions (for example, the documentation for amsmath is found at latex/amsmath/amsdoc.dvi). If your installation procedure has not installed the documentation, the DVI ﬁles can all be downloaded from CTAN. Before using a package, you should read the documentation carefully, especially the subsection usually called ”User Interface”, which describes the commands the package makes available. You cannot just guess and hope it will work: you have to read it and ﬁnd out. You can usually automatically open any installed package documentation with the texdoc command: texdoc

3.5. External resources The best way to look for LaTeX packages is the already mentioned CTAN: Search5 . Additional resources form The TeX Catalogue Online6 : • • • •

5 6 7 8 9 10

34

Alphabetic catalogue7 With brief descriptions8 Topical catalogue9 with packages sorted systematically Hierarchical10 mirroring the CTAN folder hierarchy

http://tug.ctan.org/search.html http://www.ctan.org/tex-archive/help/Catalogue/catalogue.html http://www.ctan.org/tex-archive/help/Catalogue/alpha.html http://www.ctan.org/tex-archive/help/Catalogue/brief.html http://www.ctan.org/tex-archive/help/Catalogue/bytopic.html http://www.ctan.org/tex-archive/help/Catalogue/hier.html

11 12

Chapter 62 on page 659 https://sr.wikibooks.org/wiki/LaTeX%2F%D0%98%D0%BD%D1%81%D1%82%D0%B0%D0%BB%D0%B0%D1%86%D0%B8%D1%98%D0%B0%2

35

4. Basics This tutorial is aimed at getting familiar with the bare bones of LaTeX1 . Before starting, ensure you have LaTeX installed on your computer (see Installation2 for instructions of what you will need). • We will ﬁrst have a look at the LaTeX syntax. • We will create our ﬁrst LaTeX document. • Then we will take you through how to feed this ﬁle through the LaTeX system to produce quality output, such as postscript or PDF. • Finally we will have a look at the ﬁle names and types.

4.1. The LaTeX syntax LaTeX uses a markup language in order to describe document structure and presentation. LaTeX converts your source text, combined with the markup, into a high quality document. For the purpose of analogy, web pages work in a similar way: the HTML is used to describe the document, but it is your browser that presents it in its full glory - with diﬀerent colours, fonts, sizes, etc. The input for LaTeX is a plain text3 ﬁle. You can create it with any text editor. It contains the text of the document, as well as the commands that tell LaTeX how to typeset the text. A minimal example looks something like the following (the commands will be explained later): \documentclass{article} \begin{document} Hello world! \end{document}

4.1.1. Spaces The LaTeX compiler normalises whitespace so that whitespace characters, such as [space] or [tab], are treated uniformly as ”space”: several consecutive ”spaces” are treated as one, ”space” opening a line is generally ignored, and a single line break also yields “space”. A double line break (an empty line), however, deﬁnes the end of a paragraph; multiple empty

1 2 3

Chapter 1 on page 5 Chapter 2 on page 11 https://en.wikipedia.org/wiki/plain%20text

37

Basics lines are also treated as the end of a paragraph. An example of applying these rules is presented below: the left-hand side shows the user’s input (.tex), while the right-hand side depicts the rendered output (.dvi/.pdf/.ps).

It does not matter whether you enter one or several after a word.

spaces

An empty line starts a new paragraph.

It does not matter whether you enter one or several spaces after a word. An empty line starts a new paragraph.

4.1.2. Reserved Characters The following symbols are reserved characters that either have a special meaning under LaTeX or are unavailable in all the fonts. If you enter them directly in your text, they will normally not print but rather make LaTeX do things you did not intend. # $% ˆ & _ { } ˜ \ As you will see, these characters can be used in your documents all the same by adding a preﬁx backslash: \# \$ \% \^{} \& \_ \{ \} \~{} \textbackslash{}

The backslash character \ cannot be entered by adding another backslash in front of it (\\); this sequence is used for line breaking. For introducing a backslash in math mode, you can use \backslash instead. The commands \˜ and \ˆ produce respectively a tilde and a hat which is placed over the next letter. For example \˜n gives ñ. That’s why you need braces to specify there is no letter as argument. You can also use \textasciitilde and \textasciicircum to enter these characters; or other commands 4 . If you want to insert text that might contain several particular symbols (such as URIs), you can consider using the \verb command, which will be discussed later in the section on formatting5 . For source code, see Source Code Listings6 The ’less than’ (<) and ’greater than’ (>) characters are the only visible ASCII characters (not reserved) that will not print correctly. See Special Characters7 for an explanation and a workaround.

4 5 6 7

38

http://tex.stackexchange.com/questions/9363/how-does-one-insert-a-backslash-or-a-tilde-into-latex https://en.wikibooks.org/wiki/LaTeX%2FFormatting Chapter 32 on page 393 Chapter 11.3 on page 123

The LaTeX syntax Non-ASCII characters (e.g. accents, diacritics) can be typed in directly for most cases. However you must conﬁgure the document appropriately. The other symbols and many more can be printed with special commands as in mathematical formulae or as accents. We will tackle this issue in Special Characters8 .

4.1.3. LaTeX groups Sometimes a certain state shall be kept local, i.e. limiting its scope. This can be done by enclosing the part to be changed locally in curly braces. In certain occasions, using braces won’t be possible. LaTeX provides \bgroup and \egroup to begin and end a group, respectively. \documentclass{article} \begin{document} normal text {\itshape walzing \bfseries Wombat} more normal text normal text \bgroup\itshape walzing \bfseries Wombat\egroup{} more normal text \end{document}

Environments form an implicit group.

4.1.4. LaTeX environments Environments in LaTeX have a role that is quite similar to commands, but they usually have eﬀect on a wider part of the document. Their syntax is: \begin{environmentname} text to be influenced \end{environmentname}

Between the \begin and the \end you can put other commands and nested environments. The internal mechanism of environments deﬁnes a group, which makes its usage safe (no inﬂuence on the other parts of the document). In general, environments can accept arguments as well, but this feature is not commonly used and so it will be discussed in more advanced parts of the document. Anything in LaTeX can be expressed in terms of commands and environments.

4.1.5. LaTeX commands LaTeX commands are case sensitive, and take one of the following two formats: • They start with a backslash \ and then have a name consisting of letters only. Command names are terminated by a space, a number or any other ”non-letter”. • They consist of a backslash \ and exactly one non-letter. Some commands need an argument, which has to be given between curly braces { } after the command name. Some commands support optional parameters, which are added after the command name in square brackets [ ]. The general syntax is:

8

Chapter 11 on page 119

39

Basics

\commandname[option1,option2,...]{argument1}{argument2}...

Most standard LaTeX commands have a switch equivalent. Switches have no arguments but apply on the rest of the scope, i.e. the current group or environment. A switch should (almost) never be called outside of any scope, otherwise it will apply on the rest of the document.

B

Warning

Commands with arguments and switches should not be confused. This is a very common error! Example: % \emph is a command with argument, \em is a switch. \emph{emphasized text}, this part is normal % Correct {\em emphasized text}, this part is normal % Correct \em emphasized text, this part is normal % Incorrect \em{emphasized text}, this part is normal % Incorrect

4.1.6. Comments When LaTeX encounters a % character while processing an input ﬁle, it ignores the rest of the current line, the line break, and all whitespace at the beginning of the next line. This can be used to write notes into the input ﬁle, which will not show up in the printed version. This is an % stupid % Better: instructive <---example: Supercal% ifragilist% icexpialidocious

This is an example: Supercalifragilisticexpialidocious

Note that the % character can be used to split long input lines that do not allow whitespace or line breaks, as with Supercalifragilisticexpialidocious above. The core LaTeX language does not have a predeﬁned syntax for commenting out regions spanning multiple lines. Refer to multiline comments9 for simple workarounds.

9

40

Chapter 7.6.2 on page 83

Our ﬁrst document

4.2. Our ﬁrst document Now we can create our ﬁrst document. We will produce the absolute bare minimum that is needed in order to get some output; the well known Hello World! approach will be suitable here. • Open your favorite text-editor. vim10 , emacs11 , Notepad++, and other text editors will have syntax highlighting that will help to write your ﬁles. • Reproduce the following text in your editor. This is the LaTeX source. % hello.tex - Our first LaTeX example! \documentclass{article} \begin{document} Hello World! \end{document}

• Save your ﬁle as hello.tex. When picking a name for your ﬁle, make sure it bears a .tex extension.

4.2.1. What does it all mean? % hello.tex - Our first LaTeX example!

\documentclass{article}

\begin{document}

Hello World! \end{document}

The ﬁrst line is a comment. This is because it begins with the percent symbol (%); when LaTeX sees this, it simply ignores the rest of the line. Comments are useful for people to annotate parts of the source ﬁle. For example, you could put information about the author and the date, or whatever you wish. This line is a command and tells LaTeX to use the article document class. A document class ﬁle deﬁnes the formatting, which in this case is a generic article format. The handy thing is that if you want to change the appearance of your document, substitute article for another class ﬁle that exists. This line is the beginning of the environment called document; it alerts LaTeX that content of the document is about to commence. Anything above this command is known generally to belong in the preamble. This was the only actual line containing real content the text that we wanted displayed on the page. The document environment ends here. It tells LaTeX that the document source is complete, anything after this line will be ignored.

As we have said before, each of the LaTeX commands begins with a backslash (\). This is LaTeX’s way of knowing that whenever it sees a backslash, to expect some commands. Comments are not classed as a command, since all they tell LaTeX is to ignore the line. Comments never aﬀect the output of the document.

10 11

https://en.wikibooks.org/wiki/Learning%20the%20vi%20Editor%2FVim https://en.wikibooks.org/wiki/emacs

41

Basics

42

https://en.wikibooks.org/wiki/Ghostscript

Compilation layer to hide the details of which compiler you’re using, while the compiler can handle the translation itself. The following diagram shows the relationships between the LaTeX source code and the formats you can create from it:

Figure 7

The boxed red text represents the ﬁle formats, the blue text on the arrows represents the commands you have to use, the small dark green text under the boxes represents the image formats that are supported. Any time you pass through an arrow you lose some information, which might decrease the features of your document. Therefore, you should choose the shortest route to reach your target format. This is probably the most convenient way to obtain an output in your desired format anyway. Starting from a LaTeX source, the best way is to use only latex for a DVI output or pdﬂatex for a PDF output, converting to PostScript only when it is necessary to print the document. Chapter ../Export To Other Formats/13 discusses more about exporting LaTeX source to other ﬁle formats.

13

Chapter 57 on page 627

43

Basics

4.3.2. Generating the document It is clearly not going to be the most exciting document you have ever seen, but we want to see it nonetheless. I am assuming that you are at a command prompt, already in the directory where hello.tex is stored. LaTeX itself does not have a GUI (graphical user interface), since it is just a program that crunches away at your input ﬁles, and produces either a DVI or PDF ﬁle. Some LaTeX installations feature a graphical front-end where you can click LaTeX into compiling your input ﬁle. On other systems there might be some typing involved, so here is how to coax LaTeX into compiling your input ﬁle on a text based system. Please note: this description assumes that you already have a working LaTeX installation on your computer. 1. Type the command: latex hello (the .tex extension is not required, although you can include it if you wish) 2. Various bits of info about LaTeX and its progress will be displayed. If all went well, the last two lines displayed in the console will be: Output written on hello.dvi (1 page, 232 bytes). Transcript written on hello.log.

This means that your source ﬁle has been processed and the resulting document is called hello.dvi, which takes up 1 page and 232 bytes of space. Now you may view the DVI ﬁle. On Unix with X11 you can type xdvi foo.dvi, on Windows you can use a program called yap (yet another previewer). (Now evince and okular, the standard document viewers for many Linux distributions are able to view DVI ﬁles.) This way you created the DVI ﬁle, but with the same source ﬁle you can create a PDF document. The steps are exactly the same as before, but you have to replace the command latex with pdflatex: 1. Type the command: pdflatex hello (as before, the .tex extension is not required) 2. Various bits of info about LaTeX and its progress will be displayed. If all went well, the last two lines displayed in the console will be: Output written on hello.pdf (1 page, 5548 bytes). Transcript written on hello.log.

you can notice that the PDF document is bigger than the DVI, even if it contains exactly the same information. The main diﬀerences between the DVI and PDF formats are: • DVI needs less disk space and it is faster to create. It does not include the fonts within the document, so if you want the document to be viewed properly on another computer, there must be all the necessary fonts installed. It does not support any interactivity such as hyperlinks or animated images. DVI viewers are not very common, so you can consider using it for previewing your document while typesetting. • PDF needs more disk space and it is slower to create, but it includes all the necessary fonts within the document, so you will not have any problem of portability. It supports internal and external hyperlinks. It also supports advanced typographic features: hanging punctuation14 , font expansion and margin kerning resulting in more ﬂexibility available 14

44

https://en.wikipedia.org/wiki/Hanging%20punctuation

Files to the TeX engine and better looking output. Nowadays it is the de facto standard for sharing and publishing documents, so you can consider using it for the ﬁnal version of your document. About now, you saw you can create both DVI and PDF document from the same source. This is true, but it gets a bit more complicated if you want to introduce images or links. This will be explained in detail in the next chapters, but for now assume you can compile in both DVI and PDF without any problem. Note, in this instance, due to the simplicity of the ﬁle, you only need to run the LaTeX command once. However, if you begin to create complex documents, including bibliographies and cross-references, etc, LaTeX needs to be executed multiple times to resolve the references. But this will be discussed in the future when it comes up.

4.3.3. Autobuild Systems Compiling using only the latex binary can be quite tricky as soon as you start working on more complex documents as previously stated. A number of programs exist to automatically read in a TeX document and run the appropriate compilers the appropriate number of times. For example, latexmk can generate a PDF from most TeX ﬁles simply: $latexmk -pdf file.tex Note that most editors15 will take care of it for you. 4.3.4. Compressed PDF For a PDF output, you may have noticed that the output PDF ﬁle is not always the same size depending on the engine you used to compile the ﬁle. So latex → dvips → ps2pdf will usually be much smaller than pdflatex. If you want pdflatex features along with a small output ﬁle size, you can use the Ghostscript command:$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="Compressed.pdf" "Original.pdf"

4.4. Files 4.4.1. Picking suitable ﬁlenames Never, ever use directories (folders) or ﬁle names that contain spaces. Although your operating system probably supports them, some don’t, and they will only cause grief and tears with TeX. Make ﬁlenames as short or as long as you wish, but strictly avoid spaces. Stick 15

Chapter 2.3 on page 17

45

Basics to lower-case letters without accents (a-z), the digits 0-9, the hyphen (−), and only one full point or period (.) to separate the ﬁle extension (somewhat similar to the conventions for a good Web URL): it will let you refer to TeX ﬁles over the Web more easily and make your ﬁles more portable. Some operating systems do not distinguish between upper-case and lower-case letters, others do. Therefore it’s best not to mix them.

B

Warning

The only important ﬁle types are .tex, .cls and .sty, .bib and .bst for BibTeX, these are not temporary and should not be deleted. When you work with various capabilities of LaTeX (index, glossaries, bibliographies, etc.) you will soon ﬁnd yourself in a maze of ﬁles with various extensions and probably no clue. The following list explains the most common ﬁle types you might encounter when working with TeX: Common ﬁle extensions in LaTeX .aux A ﬁle that transports information from one compiler run to the next. Among other things, the .aux ﬁle is used to store information associated with cross-references. .bbl Bibliography ﬁle output by BiBTeX and used by LaTeX .bib Bibliography database ﬁle. (where you can store a list of full bibliographic citations) .blg BiBTeX log ﬁle. (errors are logged here) .bst BiBTeX style ﬁle. .cls Class ﬁles deﬁne what your document looks like. They are selected with the \documentclass command.

46

4.5. And what now? 4.5.1. Common Elements See Document Structure16 and the Common Elements part for all the common features that belong to every type of document.

4.5.2. Non-English documents and special characters LaTeX has some nice features for most languages in the world. You can tell LaTeX to follow typography rules of the target language, ease special characters input, and so on. See Special Characters17 and Internationalization18 .

16 17 18

Chapter 5 on page 51 Chapter 11 on page 119 Chapter 12 on page 131

47

Basics

4.5.3. Modular document See Modular Documents19 for good recommendations about the way to organize big projects into multiple ﬁles.

4.5.4. Questions and Issues We highly urge you to read the FAQ20 if you have issues about basic features, or if you want to read essential recommendations. For the more speciﬁc questions and issues, refer to the Tips and Tricks21 page.

4.5.5. Macros for the utmost eﬃciency The full power of LaTeX resides in macros. They make your documents very dynamic and ﬂexible. See the dedicated part22 .

4.5.6. Working in a team See chapter ../Collaborative Writing of LaTeX Documents/23 . sr:LaTeX/Основе24

19 20 21 22 23 24

48

Chapter 55 on page 605 Chapter 58 on page 637 Chapter 59 on page 643 Chapter 51 on page 569 Chapter 56 on page 615 https://sr.wikibooks.org/wiki/LaTeX%2F%D0%9E%D1%81%D0%BD%D0%BE%D0%B2%D0%B5

Part II.

Common Elements

49

5. Document Structure The main point of writing a text is to convey ideas, information, or knowledge to the reader. The reader will understand the text better if these ideas are well-structured, and will see and feel this structure much better if the typographical form reﬂects the logical and semantic structure of the content. LaTeX is diﬀerent from other typesetting systems in that you just have to tell it the logical and semantical structure of a text. It then derives the typographical form of the text according to the “rules” given in the document class ﬁle and in various style ﬁles. LaTeX allows users to structure their documents with a variety of hierarchical constructs, including chapters, sections, subsections and paragraphs.

5.1. Global structure When LaTeX processes an input ﬁle, it expects it to follow a certain structure. Thus every input ﬁle must contain the commands \documentclass{...} \begin{document} ... \end{document}

The area between \documentclass{...} and \begin{document} is called the preamble. It normally contains commands that aﬀect the entire document. After the preamble, the text of your document is enclosed between two commands which identify the beginning and end of the actual document: \begin{document} ... \end{document}

You would put your text where the dots are. The reason for marking oﬀ the beginning of your text is that LaTeX allows you to insert extra setup speciﬁcations before it (where the blank line is in the example above: we’ll be using this soon). The reason for marking oﬀ the end of your text is to provide a place for LaTeX to be programmed to do extra stuﬀ automatically at the end of the document, like making an index. A useful side-eﬀect of marking the end of the document text is that you can store comments or temporary text underneath the \end{document} in the knowledge that LaTeX will never try to typeset them: \end{document}

51

Document Structure ...

5.2. Preamble 5.2.1. Document classes When processing an input ﬁle, LaTeX needs to know the type of document the author wants to create. This is speciﬁed with the \documentclass command. It is recommended to put this declaration at the very beginning. \documentclass[options]{class}

Here, class speciﬁes the type of document to be created. The LaTeX distribution provides additional classes for other documents, including letters and slides. It is also possible to create your own, as is often done by journal publishers, who simply provide you with their own class ﬁle, which tells LaTeX how to format your content. But we’ll be happy with the standard article class for now. The options parameter customizes the behavior of the document class. The options have to be separated by commas. Example: an input ﬁle for a LaTeX document could start with the line \documentclass[11pt,twoside,a4paper]{article}

which instructs LaTeX to typeset the document as an article with a base font size of 11 points, and to produce a layout suitable for double sided printing on A4 paper. Here are some document classes that can be used with LaTeX: Document Classes article For articles in scientiﬁc journals, presentations, short reports, program documentation, invitations, ... IEEEtran For articles with the IEEE Transactions format. proc A class for proceedings based on the article class. report For longer reports containing several chapters, small books, thesis, ... book For real books. slides For slides. The class uses big sans serif letters. memoir For changing sensibly the output of the document. It is based on the book class, but you can create any kind of document with it http:// www.ctan.org/tex-archive/macros/latex/contrib/memoir/memman. pdf letter For writing letters. beamer For writing presentations (see LaTeX/Presentations1 ). The standard document classes that are a part of LaTeX are built to be fairly generic, which is why they have a lot of options in common. Other classes may have diﬀerent options (or

1

52

Chapter 41 on page 485

Preamble none at all). Normally, third party classes come with some documentation to let you know. The most common options for the standard document classes are listed in the following table: Document Class Options 10pt, 11pt, 12pt a4paper, letterpaper,...

fleqn leqno titlepage, notitlepage

twocolumn twoside, oneside

landscape openright, openany

draft

Sets the size of the main font in the document. If no option is speciﬁed, 10pt is assumed. Deﬁnes the paper size. The default size is letterpaper; However, many European distributions of TeX now come pre-set for A4, not Letter, and this is also true of all distributions of pdfLaTeX. Besides that, a5paper, b5paper, executivepaper, and legalpaper can be speciﬁed. Typesets displayed formulas left-aligned instead of centered. Places the numbering of formulas on the left hand side instead of the right. Speciﬁes whether a new page should be started after the document title or not. The article class does not start a new page by default, while report and book do. Instructs LaTeX to typeset the document in two columns instead of one. Speciﬁes whether double or single sided output should be generated. The classes article and report are single sided and the book class is double sided by default. Note that this option concerns the style of the document only. The option twoside does not tell the printer you use that it should actually make a two-sided printout. Changes the layout of the document to print in landscape mode. Makes chapters begin either only on right hand pages or on the next page available. This does not work with the article class, as it does not know about chapters. The report class by default starts chapters on the next page available and the book class starts them on right hand pages. makes LaTeX indicate hyphenation and justiﬁcation problems with a small square in the right-hand margin of the problem line so they can be located quickly by a human. It also suppresses the inclusion of images and shows only a frame where they would normally occur.

For example, if you want a report to be in 12pt type on A4, but printed one-sided in draft mode, you would use:

53

Document Structure

\documentclass[12pt,a4paper,oneside,draft]{report}

5.2.2. Packages While writing your document, you will probably ﬁnd that there are some areas where basic LaTeX cannot solve your problem. If you want to include graphics, colored text or source code from a ﬁle into your document, you need to enhance the capabilities of LaTeX. Such enhancements are called packages. Some packages come with the LaTeX base distribution. Others are provided separately. Modern TeX distributions come with a large number of packages pre-installed. The command to use a package is pretty simple: \usepackage: \usepackage[options]{package}

command, where package is the name of the package and options is a list of keywords that trigger special features in the package. For example, to use the color package, which lets you typeset in colors, you would type: \documentclass{report} \usepackage{color} \begin{document} ... \end{document}

You can pass several options to a package, each separated by a comma. \usepackage[option1,option2,option3]{''package_name''}

5.3. The document environment 5.3.1. Top matter At the beginning of most documents there will be information about the document itself, such as the title and date, and also information about the authors, such as name, address, email etc. All of this type of information within LaTeX is collectively referred to as top matter. Although never explicitly speciﬁed (there is no \topmatter command) you are likely to encounter the term within LaTeX documentation. A simple example: \documentclass[11pt,a4paper]{report} \begin{document} \title{How to Structure a LaTeX Document} \author{Andrew Roberts} \date{December 2004} \maketitle \end{document}

The \title, \author, and \date commands are self-explanatory. You put the title, author name, and date in curly braces after the relevant command. The title and author are usually

54

The document environment compulsory (at least if you want LaTeX to write the title automatically); if you omit the \date command, LaTeX uses today’s date by default. You always ﬁnish the top matter with the \maketitle command, which tells LaTeX that it’s complete and it can typeset the title according to the information you have provided and the class (style) you are using. If you omit \maketitle, the titling will never be typeset (unless you write your own). Here is a more complicated example: \title{How to Structure a \LaTeX{} Document} \author{Joe Bloggs\\ School of Computing,\\ University of Study,\\ Books,\\ United Readdom,\\ RN 1234\\ \texttt{[email protected]}} \date{\today} \maketitle

As you can see, you can use commands as arguments of \title and the others. The double backslash (\\) is the LaTeX command for forced linebreaks in tabular material. If there are two authors separate them with the \and command: \title{Our Fun Document} \author{Jane Doe \and John Doe} \date{\today} \maketitle

Using this approach, you can create only basic output whose layout is very hard to change. If you want to create your title freely, see the Title Creation2 section.

5.3.2. Abstract As most research papers have an abstract, there are predeﬁned commands for telling LaTeX which part of the content makes up the abstract. This should appear in its logical order, therefore, after the top matter, but before the main sections of the body. This command is available for the document classes article and report, but not book. \documentclass{article} \begin{document} \begin{abstract} Your abstract goes here... ... \end{abstract} ... \end{document}

By default, LaTeX will use the word ”Abstract” as a title for your abstract. If you want to change it into anything else, e.g. ”Executive Summary”, add the following line before you begin the abstract environment:

2

Chapter 15 on page 187

55

Document Structure

\renewcommand{\abstractname}{Executive Summary}

5.3.3. Sectioning commands The commands for inserting sections are fairly intuitive. Of course, certain commands are appropriate to diﬀerent document classes. For example, a book has chapters but an article doesn’t. Here are some of the structure commands found in simple.tex. \chapter{Introduction} This chapter's content... \section{Structure} This section's content... \subsection{Top Matter} This subsection's content... \subsubsection{Article Information} This subsubsection's content...

Notice that you do not need to specify section numbers; LaTeX will sort that out for you. Also, for sections, you do not need to use \begin and \end commands to indicate which content belongs to a given block. LaTeX provides 7 levels of depth for deﬁning sections (see table below). Each section in this table is a subsection of the one above it. Command \part{''part''} \chapter{''chapter''} \section{''section''} \subsection{''subsection''} \subsubsection{''subsubsection''} \paragraph{''paragraph''} \subparagraph{''subparagraph''}

Level -1 0 1 2 3 4 5

Comment not in letters only books and reports not in letters not in letters not in letters not in letters not in letters

56

The document environment Section numbering Numbering of the sections is performed automatically by LaTeX, so don’t bother adding them explicitly, just insert the heading you want between the curly braces. Parts get roman numerals (Part I, Part II, etc.); chapters and sections get decimal numbering like this document, and appendices (which are just a special case of chapters, and share the same structure) are lettered (A, B, C, etc.). You can change the depth to which section numbering occurs, so you can turn it oﬀ selectively. By default it is set to 3. If you only want parts, chapters, and sections numbered, not subsections or subsubsections etc., you can change the value of the secnumdepth counter3 using the \setcounter command, giving the depth level you wish. For example, if you want to change it to ”1”: \setcounter{secnumdepth}{1}

A related counter is tocdepth, which speciﬁes what depth to take the Table of Contents to. It can be reset in exactly the same way as secnumdepth. For example: \setcounter{tocdepth}{3}

To get an unnumbered section heading which does not go into the Table of Contents, follow the command name with an asterisk before the opening curly brace: \subsection*{Introduction}

All the divisional commands from \part* to \subparagraph* have this ”starred” version which can be used on special occasions for an unnumbered heading when the setting of secnumdepth would normally mean it would be numbered. If you want the unnumbered section to be in the table of contents anyway, use the \addcontentsline command like this: \section*{Introduction} \addcontentsline{toc}{section}{Introduction}

Note that if you use PDF bookmarks you will need to add a phantom section so that bookmark will lead to the correct place in the document. The \phantomsection command is deﬁned in the hyperref package, and is implemented normally as follows: \phantomsection \addcontentsline{toc}{section}{Introduction} \section*{Introduction}

For chapters you will also need to clear the page (this will also correct page numbering in the ToC): \cleardoublepage \phantomsection \addcontentsline{toc}{chapter}{Bibliography} \bibliographystyle{unsrt} \bibliography{my_bib_file}

3

Chapter 24 on page 295

57

Document Structure The value where the section numbering starts from can be set with the following command: \setcounter{section}{4}

The next section after this command will now be numbered 5. For more details on counters, see the dedicated chapter4 . Section number style See Counters5 .

5.3.4. Ordinary paragraphs Paragraphs of text come after section headings. Simply type the text and leave a blank line between paragraphs. The blank line means ”start a new paragraph here”: it does not mean you get a blank line in the typeset output. For formatting paragraph indents and spacing between paragraphs, refer to the Paragraph Formatting6 section.

4 5 6

58

Chapter 24 on page 295 Chapter 24 on page 295 Chapter 7.6.1 on page 83

Book structure This will format an unnumbered ToC entry for ”Preface” in the ”subsection” style. You can use the same mechanism to add lines to the List of Figures or List of Tables by substituting lof or lot for toc. If the hyperref package is used and the link does not point to the correct chapter, the command \phantomsection in combination with \clearpage or \cleardoublepage can be used (see also Labels and Cross-referencing7 ): \cleardoublepage \phantomsection \addcontentsline{toc}{chapter}{List of Figures} \listoffigures

To change the title of the TOC, you have to paste this command \renewcommand{\contentsname}{} in your document preamble. The List of Figures (LoF) and List of Tables (LoT) names can be changed by replacing the \contentsname with \listfigurename for LoF and \listtablename for LoT. Depth The default ToC will list headings of level 3 and above. To change how deep the table of contents displays automatically the following command can be used in the preamble: \setcounter{tocdepth}{4}


In order to further tune the display or the numbering of the table of contents, for instance if the appendix should be less detailed, you can make use of the tocvsec2 package (CTAN8 , doc9 ).

5.4. Book structure The standard LaTeX book class follows the same layout described above with some additions. By default a book will be two-sided, i.e. left and right margins will change according

7 8 9

Chapter 21.5 on page 276 http://www.ctan.org/pkg/tocvsec2 http://mirror.ctan.org/macros/latex/contrib/tocvsec2/tocvsec2.pdf

59

Document Structure to the page number parity. Furthermore current chapter and section will be printed in the header. If you do not make use of chapters, it is barely useful to use the book class. Additionally the class provides macros to change the formatting of some places of the document. We will give you some advice on how to use them properly.10 \begin{document} \frontmatter \maketitle % Introductory chapters \chapter{Preface} % ... \mainmatter \chapter{First chapter} % ... \appendix \chapter{First Appendix} \backmatter \chapter{Last note}

• The frontmatter chapters will not be numbered. Page numbers will be printed in roman numerals. Frontmatter is not supposed to have sections, since they will be number 0.n because there is no chapter numbering. Check the Counters11 chapter for a ﬁx. • The mainmatter chapters works as usual. The command resets the page numbering. Page numbers will be printed in arabic numerals. • The \appendix macro can be used to indicate that following sections or chapters are to be numbered as appendices. Appendices can be used for the article class too: \appendix \section{First Appendix}

Only use the \appendix macro once for all appendices. • The backmatter behaves like the frontmatter. It has the same issue with section numbering. As a general rule you should avoid mixing the command order. Nonetheless all commands are optional, so you might consider using only a few. Note that the special content like the table of contents is considered as an unnumbered chapter.

5.4.1. Page order This is one traditional page order for books. Frontmatter 10 11

60

http://tex.stackexchange.com/questions/20538/what-is-the-right-order-when-using-frontmatter-tableofconte Chapter 24 on page 295

Special pages 1. 2. 3. 4. 5. 6. 7. 8.

Half-title Empty Title page Information (copyright notice, ISBN, etc.) Dedication if any, else empty Table of contents List of ﬁgures (can be in the backmatter too) Preface chapter

Mainmatter 1. Main topic Appendix 1. Some subordinate chapters Backmatter 1. Bibliography 2. Glossary / Index

5.5. Special pages Comprehensive papers often feature special pages at the end, like indices, glossaries and bibliographies. Since this is a quite complex topic, we will give you details in the dedicated part Special Pages.

5.5.1. Bibliography Any good research paper will have a complete list of references. LaTeX has two ways of inserting your references into a document: • you can embed them within the document itself. It’s simpler, but it can be timeconsuming if you are writing several papers about similar subjects so that you often have to cite the same books. • you can store them in an external BibTeX ﬁle 12 and then link them via a command to your current document and use a Bibtex style13 to deﬁne how they appear. This way you can create a small database of the references you might use and simply link them, letting LaTeX work for you. To learn how to add a bibliography to your document, see the Bibliography Management14 section.

12 13 14

http://www.bibtex.org http://www.cs.stir.ac.uk/~kjt/software/latex/showbst.html Chapter 38 on page 441

61

Document Structure

5.6. Notes and references ru:LaTeX/Структура документа15 sr:LaTeX/Структура документа16

15 16

62

https://ru.wikibooks.org/wiki/LaTeX%2F%D0%A1%D1%82%D1%80%D1%83%D0%BA%D1%82%D1%83%D1%80%D0%B0%20%D0%B4%D0 https://sr.wikibooks.org/wiki/LaTeX%2F%D0%A1%D1%82%D1%80%D1%83%D0%BA%D1%82%D1%83%D1%80%D0%B0%20%D0%B4%D0

6. Text Formatting This section will guide you through the formatting techniques of the text. Formatting tends to refer to most things to do with appearance, so it makes the list of possible topics quite eclectic: text style, spacing, etc. If formatting may also refer to paragraphs and to the page layout, we will focus on the customization of words and sentences for now. A lot of formatting techniques are required to diﬀerentiate certain elements from the rest of the text. It is often necessary to add emphasis to key words or phrases. Footnotes are useful for providing extra information or clariﬁcation without interrupting the main ﬂow of text. So, for these reasons, formatting is very important. However, it is also very easy to abuse, and a document that has been over-done can look and read worse than one with none at all. LaTeX is so ﬂexible that we will actually only skim the surface, as you can have much more control over the presentation of your document if you wish. Having said that, one of the purposes of LaTeX is to take away the stress of having to deal with the physical presentation yourself, so you need not get too carried away!

6.1. Spacing 6.1.1. Line Spacing If you want to use larger inter-line spacing in a document, you can change its value by putting the \linespread{factor}

command into the preamble of your document. Use \linespread{1.3} for ”one and a half” line spacing, and \linespread{1.6} for ”double” line spacing. Normally the lines are not spread, so the default line spread factor is 1. This may not be ideal in all situations: see http://tex.stackexchange.com/questions/30073/ why-is-the-linespread-factor-as-it-is . The setspace package allows more ﬁne-grained control over line spacing. To set ”one and a half” line spacing document-wide, but not where it is usually unnecessary (e.g. footnotes, captions): \usepackage{setspace} %\singlespacing \onehalfspacing %\doublespacing %\setstretch{1.1}

63

Text Formatting To change line spacing within the document, the setspace package provides the environments singlespace, onehalfspace, doublespace and spacing: This paragraph has \\ default \\ line spacing. \begin{doublespace} This paragraph has \\ double \\ line spacing. \end{doublespace} \begin{spacing}{2.5} This paragraph has \\ huge gaps \\ between lines. \end{spacing}

B

Warning

The line spacing value is contained in the \baselineskip length1 , but it is not recommended to change its value since it will have an impact on other types of content than paragraphs, which will result in an undesired eﬀect.

6.1.2. Non-breaking spaces This essential feature is a bit unknown to newcomers, although it is available on most WYSIWYG document processors. A non-breaking space between two tokens (e.g. words, punctuation marks) prevents the processors from inserting a line break between them. Besides a non-breaking space cannot be enlarged. It is very important for a consistent reading. LaTeX uses the ’˜’ symbol as a non-breaking space. You would usually use non-breaking spaces for punctuation marks in some languages, for units and currencies, for initials, etc. In French typography, you would put a non-breaking space before all two-parts punctuation marks. Examples: D.~\textsc{Knuth} 50~€

6.1.3. Space between words and sentences To get a straight right margin in the output, LaTeX inserts varying amounts of space between the words. By default, it also inserts slightly more space at the end of a sentence. However, the extra space added at the end of sentences is generally considered typographically old-fashioned in English language printing. (The practice is found in nineteenth century design and in twentieth century typewriter styles.) Most modern typesetters treat the end of sentence space the same as the interword space. (See for example, Bringhurst’s Elements of Typographic Style.) The additional space after periods can be disabled with the command \frenchspacing

64

Spacing which tells LaTeX not to insert more space after a period than after ordinary character. Frenchspacing can be turned oﬀ later in your document via the \nonfrenchspacing command. If an author wishes to use the wider end-of-sentence spacing, care must be exercised so that punctuation marks are not misinterpreted as ends of sentences. TeX assumes that sentences end with periods, question marks or exclamation marks. Although if a period follows an uppercase letter, this is not taken as a sentence ending, since periods after uppercase letters normally occur in abbreviations. Any exception from these assumptions has to be speciﬁed by the author. A backslash in front of a space generates a space that will not be enlarged. A tilde ‘˜’ character generates a non-breaking space. The command \@ in front of a period speciﬁes that this period terminates a sentence even when it follows an uppercase letter. (If you are using \frenchspacing, then none of these exceptions need be speciﬁed.)

6.1.4. Stretched spaces You can insert a horizontal stretched space with \hfill in a line so that the rest gets ”pushed” toward the right margin. For instance this may be useful in the header. Author Name \hfill \today

Similarly you can insert vertical stretched space with \vfill. It may be useful for special pages. \maketitle \vfill \tableofcontents \clearpage \section{My first section} % ...

See Lengths2 for more details.

6.1.5. Manual spacing The spaces between words and sentences, between paragraphs, sections, subsections, etc. is determined automatically by LaTeX. It is against LaTeX philosophy to insert spaces manually and will usually lead to bad formatting. Manual spacing is a matter of macro writing and package creation. See Lengths3 for more details.

2 3

Chapter 23 on page 287 Chapter 23 on page 287

65

Text Formatting

6.2. Hyphenation LaTeX hyphenates words whenever necessary. Hyphenation rules will vary for diﬀerent languages. LaTeX only supports English by default, so if you want to have correct hyphenation rules for your desired language, see Internationalization4 . If the hyphenation algorithm does not ﬁnd the correct hyphenation points, you can remedy the situation by using the following commands to tell TeX about the exception. The command \hyphenation{word list}

causes the words listed in the argument to be hyphenated only at the points marked by “-”. The argument of the command should only contain words built from normal letters, or rather characters that are considered to be normal letters by LaTeX. It is known that the hyphenation algorithm does not ﬁnd all correct American English hyphenation points for several words. A log of known exceptions is published periodically in the TUGboat journal. (2012 list: https://www.tug.org/TUGboat/tb33-1/tb103hyf.pdf) The hyphenation hints are stored for the language that is active when the hyphenation command occurs. This means that if you place a hyphenation command into the preamble of your document it will inﬂuence the English language hyphenation. If you place the command after the \begin{document} and you are using some package for national language support like babel, then the hyphenation hints will be active in the language activated through babel. The example below will allow “hyphenation” to be hyphenated as well as “Hyphenation”, and it prevents “FORTRAN”, “Fortran” and “fortran” from being hyphenated at all. No special characters or symbols are allowed in the argument. Example: \hyphenation{FORTRAN Hy-phen-a-tion}

The command \- inserts a discretionary hyphen into a word. This also becomes the only point where hyphenation is allowed in this word. This command is especially useful for words containing special characters (e.g., accented characters), because LaTeX does not automatically hyphenate words containing special characters.

\begin{minipage}{2in} I think this is: su\-per\-cal\-% i\-frag\-i\-lis\-tic\-ex\-pi\-% al\-i\-do\-cious \end{minipage}

I think this is: supercalifragilisticexpialidocious

LaTeX does not hyphenate compound words that contain a dash5 . There are two packages that can add back ﬂexibility. The hyphenat package supplies the \hyp command. This command typesets the dash and then subjects the constituent words to automatic hyphenation. After loading the package:

4 5

66

Chapter 12 on page 131 hyphenat package documentation, p3

Quote-marks

\usepackage{hyphenat}

one should write, instead of electromagnetic-endioscopy: electromagnetic\hyp{}endioscopy

The extdash package also oﬀers features for controlling the hyphenation of compound words containing dashes — as opposed to the words themselves which it leaves to LaTeX. The shortcuts option enables a more compressed syntax: \usepackage[shortcuts]{extdash}

Typical usage is as follows, assuming the compressed syntax. In both cases, LaTeX can break and hyphenate the constituent words, but in the latter case, it will not break after the L: electromagnetic\-/endioscopy L\=/approximation

One or more words can be kept together on the one line with the standard LaTeX command: \mbox{text}

This prevents hyphenation and causes its argument to be kept together under all circumstances. For example: My phone number will change soon. It will be \mbox{0116 291 2319}.

\fbox is similar to \mbox, but in addition there will be a visible box drawn around the content. To avoid hyphenation altogether, the penalty for hyphenation can be set to an extreme value: \hyphenpenalty=100000

You can change the degree to which LaTeX will hyphenate by changing the value of \tolerance=1000 and \hyphenpenalty=1000. You’ll have to experiment with the values to achieve the desired eﬀect. A document which has a low tolerance value will cause LaTeX not to tolerate uneven spacing between words, hyphenating words more frequently than in documents with higher tolerances. Also note that using a higher text width will decrease the probability of encountering badly hyphenated word. For example adding \usepackage{geometry}

will widen the text width and reduce the amount of margin overruns.

6.3. Quote-marks LaTeX treats left and right quotes as diﬀerent entities. For single quotes, a grave accent,  (on American keyboards, this symbol is found on the tilde key; adjacent to the number 1 key on most keyboards) gives a left quote mark, and an apostrophe, ' gives a right. For double quotes, simply double the symbols, and LaTeX will interpret them accordingly. (Don’t use the " for right double quotes: when the babel package is used for some languages

67

Text Formatting (e.g. German), the " is redeﬁned to produce an umlaut accent; using " for right double quotes will either lead to bad spacing or it being used to produce an umlaut). On British keyboards, ’  ’ is left of the ’ 1 ’ key and shares the key with ’ ¬ ’, and sometimes ’ ¦ ’ or ’ | ’. The apostrophe (’) key is to the right of the colon/semicolon key and shares it with the ’ @ ’ symbol.

To quote' in LaTeX Figure 8 To quote'' in LaTeX Figure 9 To quote" in LaTeX Figure 10 To ,,quote'' in LaTeX Figure 11 ,,German quotation marks Figure 12 <> Figure 13 Please press the x' key.'' ,,Proszę, naciśnij klawisz <>''. Figure 15

The right quote is also used for apostrophe in LaTeX without trouble. For left bottom quote and European quoting style you need to use T1 font encoding enabled by: \usepackage[T1]{fontenc}

See Fonts6 for more details on font encoding. The package csquotes oﬀers a multilingual solution to quotations, with integration to citation mechanisms oﬀered by BibTeX. This package allows one for example to switch languages and quotation styles according to babel language selections.

6.4. Diacritics and accents Most accents and diacritics may be inserted with direct keyboard input by conﬁguring the preamble properly. For symbols unavailable on your keyboard, diacritics may be added to letters by placing special escaped metacharacters before the letter that requires the diacritic. 6

68

Chapter 9 on page 93

Ligatures See Special Characters7 .

6.5. Margin misalignment and interword spacing Some very long words, numbers or URLs may not be hyphenated properly and move far beyond the side margin. One solution for this problem is to use sloppypar environment, which tells LaTeX to adjust word spacing less strictly. As a result, some spaces between words may be a bit too large, but long words will be placed properly.

This is a paragraph with a very long word ABCDEFGHIJKLMNOPRST; then we have another bad thing --- a long number 1234567890123456789. \begin{sloppypar} This is a paragraph with a very long word ABCDEFGHIJKLMNOPRST; then we have an another bad thing --- a long number 1234567890123456789. \end{sloppypar}

Figure 16

border

Another solution is to edit the text to avoid long words, numbers or URLs approaching the side margin.

6.6. Ligatures Some letter combinations are typeset not just by setting the diﬀerent letters one after the other, but by actually using special symbols (like ”ﬀ”), called ligatures8 . Ligatures can be prohibited by inserting {} or, if this does not work, {\kern0pt} between the two letters in question. This might be necessary with words built from two words. Here is an example:

\Large Not shelfful\\ but shelf{}ful

7 8

Chapter 11 on page 119 https://en.wikipedia.org/wiki/Typographical%20ligature

69

Text Formatting

Figure 17 Ligatures can interfere with some text-search tools (a search for "finally" wouldn’t ﬁnd the string "ﬁnally"). The \DisableLigatures from the microtype package9 can disable ligatures in the whole document to increase accessibility. \usepackage{microtype} \DisableLigatures{encoding = *, family = *}

Note that this will also disable ligatures such as ”--” to ”–”, ”---” to ”—”, etc. If you are using XeLaTeX and OpenType fonts, the fontspec package allows for standard ligatures to be turned oﬀ as well as fancy swash ligatures to be turned on. Another solution is to use the cmap package, which will help the reader to interpret the ligatures: \usepackage[resetfonts]{cmap}

6.7. Slash marks The normal typesetting of the / character in LaTeX does not allow following characters to be ”broken” onto new lines, which often create ”overfull” errors in output (where letters push oﬀ the margin). Words that use slash marks, such as ”input/output” should be typeset as ”input\slash output”, which allow the line to ”break” after the slash mark (if needed). The use of the / character in LaTeX should be restricted to units, such as ”mm/year”, which should not be broken over multiple lines. A word after / or \slash is not automatically hyphenated. This is a similar problem to non-hyphenation of words with a dash described under Hyphenation10 . One way to have both a line break and automatic hyphenation in both words is input\slash\hspace{0pt}output

Both / and \slash can be used with a zero \hspace like this. \slash includes a penalty to make a line break there less desirable. This combination can be made into a new slash macro if desired. The hyphenat package includes an \fshyp which will add a hyphen after the slash like ”input/- output” if the line breaks there.

9 10

70

http://www.ctan.org/tex-archive/macros/latex/contrib/microtype/ Chapter 6.2 on page 66

Text mode superscript and subscript

6.8. Fonts To change the font family, emphasize text, and other font-related issues, see Fonts11 .

6.9. Formatting macros Even if you can easily change the output of your fonts using those commands, you’re better oﬀ not using explicit commands like this, because they work in opposition to the basic idea of LaTeX, which is to separate the logical and visual markup of your document. This means that if you use the same font changing command in several places in order to typeset a special kind of information, you should use \newcommand to deﬁne a ”logical wrapper command” for the font changing command.

\newcommand{\oops}[1]{\textit{#1}} Do not \oops{enter} this room, it’s occupied by \oops{machines} of unknown origin and purpose.

Do not enter this room, it’s occupied by machines of unknown origin and purpose.

This approach has the advantage that you can decide at some later stage that you want to use some visual representation of danger other than \textit, without having to wade through your document, identifying all the occurrences of \textit and then ﬁguring out for each one whether it was used for pointing out danger or for some other reason. See Macros12 for more details.

6.10. Text mode superscript and subscript Sub and superscripting can be done quite easily using \textsubscript{} and \textsuperscript{}. \documentclass{article} \begin{document} Wombat\textsubscript{walzing} Michelangelo was born on March 6\textsuperscript{th}, 1475. \end{document}

11 12

Chapter 9 on page 93 Chapter 51 on page 569

71

Text Formatting

Figure 18

Note: A current LaTeX version is needed to use subscripts that way.

6.11. Text ﬁgures (”old style” numerals) Many typographers prefer to use titling ﬁgures, sometimes called lining ﬁgures, when numerals are interspersed with full caps, when they appear in tables, and when they appear in equations, using text ﬁgures13 elsewhere. LaTeX allows this usage through the \oldstylenums{} command: \oldstylenums{1234567890}


Should you use additional sectioning or paragraphing commands, you may adapt the previous code listing to include them as well. Note A subsequent use of the \pagenumbering command, e.g., \pagenumbering{arabic}, will reset the \thepage command back to the original. Thus, if you use the \pagenumbering

13

72

https://en.wikipedia.org/wiki/Text%20figures

Dashes and hyphens command in your document, be sure to reinstate your \myThePage definition from the code above: ... \tableofcontents \pagenumbering{roman} \chapter{Preface} ... \chapter{Introduction} ... \pagenumbering{arabic} % without this, the \thepage command will not be in oldstyle (e.g., in your Table of Contents} \renewcommand{\thepage}{ \oldstylenums{\myThePage} } \Chapter{Foo} ...

6.12. Dashes and hyphens LaTeX knows four kinds of dashes: a hyphen14 (-), en dash15 (–), em dash16 (—), or a minus sign17 (−). You can access three of them with diﬀerent numbers of consecutive dashes. The fourth sign is actually not a dash at all—it is the mathematical minus sign:

Hyphen: daughter-in-law, X-rated\\ En dash: pages 13--67\\ Em dash: yes---or no? \\ Minus sign: $0$, $1$ and $-1$

Figure 19 The names for these dashes are: ‘-’(-) hyphen , ‘--’(−) en-dash , ‘---’(—) em-dash and ‘−’(−) minus sign. They have diﬀerent purposes: Input ---$-$ 14 15 16 17

Output − — −

Purpose inter-word page range, 1−10 punctuation dash—like this minus sign

https://en.wikipedia.org/wiki/hyphen https://en.wikipedia.org/wiki/Dash%23En%20dash https://en.wikipedia.org/wiki/Dash%23Em%20dash https://en.wikipedia.org/wiki/Plus%20and%20minus%20signs%23Minus%20sign

73

Text Formatting Use \hyp{} macro from hyphenat package instead of hyphen if you want LaTeX to break compound words between lines. The commands \textendash and \textemdash are also used to produce en-dash (−), and em-dash (—), respectively.

6.13. Ellipsis (…) A sequence of three dots is known as an ellipsis18 , which is commonly used to indicate omitted text. On a typewriter, a comma or a period takes the same amount of space as any other letter. In book printing, these characters occupy only a little space and are set very close to the preceding letter. Therefore, you cannot enter ‘ellipsis’ by just typing three dots, as the spacing would be wrong. Instead, there is a special command for these dots. It is called \ldots:

Not like this ... but like this:\\ New York, Tokyo, Budapest, \ldots

Figure 20

Alternatively, you can use the \textellipsis command which allows the spacing between the dots to vary.

6.14. Ready-made strings There are some very simple LaTeX commands for typesetting special text strings:

Figure 21

18

74

https://en.wikipedia.org/wiki/Ellipsis

Notes and References

6.15. Notes and References This page uses material from Andy Roberts’ Getting to grips with LaTeX with permission from the author. ru:LaTeX/Форматирование текста19 sr:LateX/Форматирање текста20

19 20

https://ru.wikibooks.org/wiki/LaTeX%2F%D0%A4%D0%BE%D1%80%D0%BC%D0%B0%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D https://sr.wikibooks.org/wiki/LateX%2F%D0%A4%D0%BE%D1%80%D0%BC%D0%B0%D1%82%D0%B8%D1%80%D0%B0%D1%9A%D0%B5%2

75

7. Paragraph Formatting Altering the paragraph formatting is rarely necessary in academic writing. It is primarily used for formatting text in ﬂoats or for more exotic documents.

7.1. Paragraph alignment Paragraphs in LaTeX are usually fully justiﬁed, i.e. ﬂush with both the left and right margins. For whatever reason, should you wish to alter the justiﬁcation of a paragraph, there are three environments at hand, and also LaTeX command equivalents. Alignment Left justiﬁed Right justiﬁed Center

Environment flushleft flushright center

Command \raggedright \raggedleft \centering

All text between the \begin and \end of the speciﬁed environment will be justiﬁed appropriately. The commands listed are for use within other environments. For example, p (paragraph) columns in tabular.

B

Warning

There is no way (in standard LaTeX) to set full justiﬁcation explicitly. It means that if you do not enclose the previous 3 commands into a group, the rest of the document will be aﬀected. So the right way of doing this with commands is {\raggedleft{}Some text flushed right.}

However, if you really need to disable one of the above commands locally (for example because you have to use some broken package), you can use the command \justifying from package ragged2e.

7.2. Paragraph indent and break By default, the ﬁrst paragraph after a heading follows the standard Anglo-American publishers’ practice of no indentation. The size of subsequent paragraph indents is determined by a parameter called \parindent. The default length that this constant holds is set by the document class that you use. It is possible to override it by using the \setlength command. This will set paragraph indents to 1cm:

77

Paragraph Formatting

\setlength{\parindent}{1cm} % Default is 15pt.

Whitespace in LaTeX can also be made ﬂexible (what Lamport calls ”rubber” lengths). This means that values such as extra vertical space inserted before a paragraph \parskip can have a default dimension plus an amount of expansion minus an amount of contraction. This is useful on pages in complex documents where not every page may be an exact number of ﬁxed-height lines long, so some give-and-take in vertical space is useful. You specify this in a \setlength command like this: \setlength{\parskip}{1cm plus4mm minus3mm}

If you want to indent a paragraph that is not indented, you can use \indent

at the beginning of the paragraph. Obviously, this will only have an eﬀect when \parindent is not set to zero. If you want to indent the beginning of every section, you can use the indentfirst package: once loaded, the beginning of any chapter/section is indented by the usual paragraph indentation. To create a non-indented paragraph, you can use \noindent

as the ﬁrst command of the paragraph. This might come in handy when you start a document with body text and not with a sectioning command. Be careful, however, if you decide to set the indent to zero, then it means you will need a vertical space between paragraphs in order to make them clear. The space between paragraphs is held in \parskip, which could be altered in a similar fashion as above. However, this parameter is used elsewhere too, such as in lists, which means you run the risk of making various parts of your document look very untidy by changing this setting. If you want to use the style of having no indentation with a space between paragraphs, use the parskip package, which does this for you, while making adjustments to the spacing of lists and other structures which use paragraph spacing, so they don’t get too far apart. If you want both indent and break, use \usepackage{parskip} \setlength{\parindent}{15pt}

To indent subsequent lines of a paragraph, use the TeX command \hangindent. (While the default behaviour is to apply the hanging indent after the ﬁrst line, this may be changed with the \hangafter command.) An example follows. \hangindent=0.7cm This paragraph has an extra indentation at the left.

The TeX commands \leftskip and \rightskip add additional space to the left and right sides of each line, allowing the formatting for subsequent paragraphs to diﬀer from the overall document margins. This space is in addition to the indentation added by \parindent and \hangindent. To change the indentation of the last line in a paragraph, use the TeX command \parfillskip.

78

\paragraph line break

7.3. \paragraph line break Default style for \paragraph may seem odd in the ﬁrst place, as it writes the following text next to the title. If you do not like it, use a class other than the traditional article/book, or use ConTeXt or PlainTeX. Hacking of the class in use is really not the way LaTeX is intended to be used, and you may encounter a lot of frustrating issues. Anyway, let’s analyse the problem. If you add a manual line break with \\, LaTeX will complain that There's no line here to end.

Simply adding an empty space will do it: \paragraph{Title} \hspace{0pt} \\ Text...

Alternatively you can use the shorter, yet not completely equivalent syntax: \paragraph{Title} ~\\ Text...

7.4. Line spacing To change line spacing in the whole document use the command \linespread covered in Text Formatting1 . Alternatively, you can use the \usepackage{setspace} package, which is also covered in Text Formatting2 . This package provides the commands \doublespacing, \onehalfspacing, \singlespacing and \setstretch{baselinestretch}, which will specify the line spacing for all sections and paragraphs until another command is used. Furthermore, the package provides the following environments in order to change line spacing within the document but not document-wide: • • • •

doublespace: lines are double spaced; onehalfspace: line spacing set to one-and-half spacing; singlespace: normal line spacing; spacing: customizable line spacing, e.g. \begin{spacing}{\baselinestretch} ... \end{spacing}.

See the section on customizing lists3 for information on how to change the line spacing in lists.

1 2 3

Chapter 6.1.1 on page 63 Chapter 6.1.1 on page 63 Chapter 10.3 on page 113

79

Paragraph Formatting

7.5. Manual breaks LaTeX takes care of formatting, breaks included. You should avoid manual breaking as much as possible, for it could lead to very bad formatting. Controlling the breaks should be reserved to macro and package writers. Here follows a quick reference. \newline \\

\\*

\\[extra-space]

\linebreak[number]

\break (TeX)

\par (TeX)

Breaks the line at the point of the command. Breaks the line at the point of the command; it is usually a shorter version of the previous command, but LaTeX sometimes redeﬁnes it for several environments. This command also features the vertical space as optional parameter. Breaks the line at the point of the command and additionally prohibits a page break after the forced line break. This command also features the vertical space as optional parameter. Command \\ has an optional argument that speciﬁes the amount of extra vertical space to be inserted before the next line. This amount can be negative. Breaks the line at the point of the command. The number you provide as an argument represents the priority of the command in a range from 0 (it will be easily ignored) to 4 (do it anyway). LaTeX will try to produce the best line breaks possible. If it cannot, it will decide whether including the linebreak or not according to the priority you have provided. Breaks the line without ﬁlling the current line. This will result in an underful badness if you do not ﬁll the line yourself, i.e. ...\hfill\break .... Actually \hfill\break produces the same as \newline and \\. Starts a new paragraph. It is a horizontal mode command, so you can only use it in a paragraph.

The page breaks are covered in Page Layout4 . More details on manual spaces between paragraphs (such as \bigskip) can be found in Lengths5 .

4 5

80

Chapter 16.10 on page 209 Chapter 23 on page 287

Special paragraphs

7.6. Special paragraphs 7.6.1. Verbatim text There are several ways to introduce text that won’t be interpreted by the compiler. If you use the verbatim environment, everything input between the begin and end commands are processed as if by a typewriter. All spaces and new lines are reproduced as given, and the text is displayed in an appropriate ﬁxed-width font. Any LaTeX command will be ignored and handled as plain text. This is ideal for typesetting program source code. Here is an example:

\begin{verbatim} The verbatim environment simply reproduces every character you input, including all s p a c e s! \end{verbatim}

Figure 22 Note: once in the verbatim environment, the only command that will be recognized is \end{verbatim}. Any others will be output. The font size in the verbatim environment can be adjusted by placing a font size command6 before \begin{verbatim}. If this is a problem, you can use the alltt package instead, providing an environment with the same name:

\begin{alltt} Verbatim extended with the ability to use normal commands. Therefore, it is possible to \emph{emphasize} words in this environment, for example. \end{alltt}

6

Chapter 7.6.1 on page 83

81

Paragraph Formatting

Figure 23


Sample % ${ _ Character %$ { _

http://ctan.org/pkg/siunitx

125

Special Characters Command \P \ddag \textbar \textgreater \textendash \texttrademark \textexclamdown \textsuperscript{a} \pounds \# \& \} \S \dag \textbackslash \textless \textemdash \textregistered \textquestiondown \textcircled{a} \copyright

Sample ¶ n/a n/a > n/a n/a n/a Xa n/a # & } § n/a n/a < n/a n/a n/a n/a n/a

Character ¶ ‡ | > – ™ ¡ a

£ # & } § † \ < — ® ¿ ⓐ ©

Not mentioned in above table, tilde (˜) is used in LaTeX code to produce non-breakable space13 . To get printed tilde sign, either write \˜{} or \textasciitilde{}. And a visible space ␣ can be created with \textvisiblespace. For some more interesting symbols, the Postscript ZipfDingbats font is available thanks to the pifont package. Add the declaration to your preamble: \usepackage{pifont}. Next, the command \ding{number}, will print the speciﬁed symbol. Here is a table of the available symbols:

13

126

Chapter 6.1.3 on page 64

In special environments

Figure 34

ZapfDingbats symbols

.

11.7. In special environments 11.7.1. Math mode Several of the above and some similar accents can also be produced in math mode. The following commands may be used only in math mode. LaTeX command

Sample

\hat{o} \widehat{oo}

oˆ oco

\check{o} \tilde{o} \widetilde{oo}

oˇ o˜ ofo

\acute{o} \grave{o} \dot{o}

o´ o o˙

Description circumﬂex wide version of \hat over several letters vee or check tilde wide version of \tilde over several letters acute accent grave accent dot over the letter

Text-mode equivalence \ˆ

\v \˜

\' \ \.

127

Special Characters LaTeX command

Sample

\ddot{o}

\breve{o} \bar{o} \vec{o}

o˘ o¯ ⃗o

Description two dots over the letter (umlaut in text-mode) breve macron vector (arrow) over the letter

Text-mode equivalence \" \u \=

When applying accents to letters i and j, you can use \imath and \jmath to keep the dots from interfering with the accents: LaTeX command \hat{\imath}

Sample ˆı

\vec{\jmath}

Description circumﬂex on letter i without upper dot vector (arrow) on letter j without upper dot

Sample with upper dot ˆi ⃗j

11.7.2. Tabbing environment Some of the accent marks used in running text have other uses in the tabbing environment. In that case they can be created with the following command: • \a' for an acute accent • \a for a grave accent • \a= for a macron accent

11.8. Unicode keyboard input w:Unicode input14 Some operating systems provide a keyboard combination to input any Unicode code point, the so-called unicode compose key. Many X applications (*BSD and GNU/Linux) support the Ctrl+Shift+u combination. A ’u’ symbol should appear. Type the code point and press enter or space to actually print the character. Example: 20AC

will print the euro character. Desktop environments like GNOME and KDE may feature a customizable compose key for more memorizable sequences.

14

128

https://en.wikipedia.org/wiki/Unicode%20input

External links Xorg features advanced keyboard layouts with variants that let you enter a lot of characters easily with combination using the aprioriate modiﬁer, like Alt Gr. It highly depends on the selected layout+variant, so we suggest you to play a bit with your keyboard, preceeding every key and dead key with the Alt Gr modiﬁer.

11.9. External links • A few other LaTeX accents and symbols15 • NASA GISS: Accents16 • [ftp://sunsite.icm.edu.pl/pub/CTAN/info/symbols/comprehensive/symbols-a4.pdf The Comprehensive LATEX Symbol List] • PDF document with a lengthy list of symbols provided by various packages17

11.10. Notes and References sr:LaTeX/Посебни знакови18

15 16 17 18

http://spectroscopy.mps.ohio-state.edu/symposium_53/latexinstruct.html http://www.giss.nasa.gov/tools/latex/ltx-401.html http://www.rpi.edu/dept/arc/training/latex/LaTeX_symbols.pdf https://sr.wikibooks.org/wiki/LaTeX%2F%D0%9F%D0%BE%D1%81%D0%B5%D0%B1%D0%BD%D0%B8%20%D0%B7%D0%BD%D0%B0%D0%B

129

12. Internationalization LaTeX has to be conﬁgured and used appropriately when it is used to write documents in languages other than English. This has to address three main areas: 1. LaTeX needs to know how to hyphenate the language(s) to be used. 2. The user needs to use language-speciﬁc typographic rules. In French for example, there is a mandatory space before each colon character (:). 3. The input of special characters, especially for languages using an input system (Arab, Chinese, Japanese, Korean). It is convenient to be able to insert language-speciﬁc special characters directly from the keyboard instead of using cumbersome coding (for example, by typing ä instead of \"{a}). This can be done by conﬁguring input encoding properly. We will not tackle this issue here: see the Special Characters1 chapter. Some languages require special fonts with the proper font encoding set. See Font encoding2 . Some of the methods described in this chapter may be useful when dealing with non-English author names in bibliographies. Here is a collection of suggestions about writing a LaTeX document in a language other than English. If you have experience in a language not listed below, please add some notes about it.

12.1. Prerequisites Most non-english language will need to input special characters very often. For a convenient writing you will need to set the input encoding and the font encoding properly. The following conﬁguration is optimal for many languages (most latin languages). Make sure your document is saved using the UTF-8 encoding. \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}

B

Warning

In the following document we will assume you are using this conﬁguration unless otherwise speciﬁed.

1 2

Chapter 11 on page 119 Chapter 9.5 on page 97

131

Internationalization For more details check Font encoding3 and Special Characters4 .

12.2. Babel The babel package by Johannes Braams and Javier Bezos will take care of everything (with XeTeX and LuaTeX you should consider polyglossia). You can load it in your preamble, providing as an argument name of the language you want to use (usually its English name, but not always): \usepackage[language]{babel}

You should place it soon after the \documentclass command, so that all the other packages you load afterwards will know the language you are using. Babel will automatically activate the appropriate hyphenation rules for the language you choose. If your LaTeX format does not support hyphenation in the language of your choice, babel will still work but will disable hyphenation, which has quite a negative eﬀect on the appearance of the typeset document. Babel also speciﬁes new commands for some languages, which simplify the input of special characters. See the sections about languages below for more information. If you call babel with multiple languages: \usepackage[languageA,languageB]{babel}

then the last language in the option list will be active (i.e. languageB), and you can use the command \selectlanguage{languageA}

to change the active language. You can also add short pieces of text in another language using the command \foreignlanguage{languageB}{Text in another language}

Babel also oﬀers various environments for entering larger pieces of text in another language: \begin{otherlanguage}{languageB} Text in language B. This environment switches all language-related definitions, like the language specific names for figures, tables etc. to the other language. \end{otherlanguage}

The starred version of this environment typesets the main text according to the rules of the other language, but keeps the language speciﬁc string for ancillary things like ﬁgures, in the main language of the document. The environment hyphenrules switches only the hyphenation patterns used; it can also be used to disallow hyphenation by using the language name ’nohyphenation’ (but note selectlanguage* is preferred). The babel manual5 provides much more information on these and many other options.

3 4 5

132

Chapter 9.5 on page 97 Chapter 11 on page 119 http://ftp.snt.utwente.nl/pub/software/tex/macros/latex/required/babel/base/babel.pdf

Multilingual versions

12.3. Multilingual versions It is possible in LaTeX to typeset the content of one document in several languages and to choose upon compilation which language to output. This might be convenient to keep a consistent sectioning and formatting across the diﬀerent languages. It is also useful if you make use of multiple proper nouns and other untranslated content. Using the commands above in multilingual documents can be cumbersome, and therefore babel provides a way to deﬁne shorter names. With \babeltags{de = german}

You can write: text \textde{German text} text text \begin{de} German text \end{de} text

12.3.1. Alternative choice using iﬂang The current language can also be tested by using the iflang package by Heiko Oberdiek (the built-in feature from the babel package is not reliable). Here comes a simple example: \IfLanguageName{ngerman}{Hallo}{Hello}

This allows to easily distinguish between two languages without the need of deﬁning own commands. The babel language is changed by setting \selectlanguage{english}

12.4. Speciﬁc languages 12.4.1. Arabic script For languages which use the Arabic script, including Arabic, Persian, Urdu, Pashto, Kurdish, Uyghur, etc., add the following code to your preamble: \usepackage{arabtex}

You can input text in either romanized characters or native Arabic script encodings. Use any of the following commands and environments to enter in text: \< ... > \RL{ ... } \begin{arabtext} ... \end{arabtext}.

133

Internationalization See the ArabTeX6 Wikipedia article for further details. You may also use the Arabi package within Babel to typeset Arabic and Persian \usepackage{cmap} \usepackage[LAE,LFE]{fontenc} \usepackage[utf8]{inputenc} \usepackage[arabic,farsi]{babel}

You may also copy and paste from PDF ﬁles produced with Arabi thanks to the support of the cmap package. You may use Arabi with LyX, or with tex4ht to produce HTML. See Arabi page on CTAN7

12.4.2. Armenian The Armenian script uses its own characters, which will require you to install a text editor that supports Unicode8 and will allow you to enter UTF-8 text, such as Texmaker9 or WinEdt10 . These text editors should then be conﬁgured to compile using XeLaTeX. Once the text editor is set up to compile with XeLaTeX, the fontspec package can be used to write in Armenian: \usepackage{fontspec} \setmainfont{DejaVu Serif}

or \usepackage{fontspec} \setmainfont{Sylfaen}

The Sylfaen font lacks italic and bold, but DejaVu Serif supports them. See Armenian Wikibooks11 for further details, especially on how to conﬁgure the Unicode supporting text editors to compile with XeLaTeX.

12.4.3. Cyrillic script Version 3.7h of babel includes support for the T2* encodings and for typesetting Bulgarian, Russian and Ukrainian texts using Cyrillic letters12 . Support for Cyrillic is based on standard LaTeX mechanisms plus the fontenc and inputenc packages. AMS-LaTeX packages should be loaded before fontenc and babel(Why?) . If you are going to use Cyrillics in mathmode, you also need to load mathtext package before fontenc:

6 7 8 9 10 11 12

134

https://en.wikipedia.org/wiki/ArabTeX http://www.ctan.org/tex-archive/language/arabic/arabi/ https://en.wikipedia.org/wiki/Unicode http://www.xm1math.net/texmaker/ http://www.winedt.com/ https://en.wikibooks.org/wiki/%3Ahy%3A%D4%BC%D5%A1%D5%8F%D5%A5%D4%BD%2F%D4%B2%D5%A1%D6%80%D6%87%20%D5%A1 The Not So Short Introduction to LaTeX ˆ{http://www.ctan.org/tex-archive/info/lshort/ english/lshort.pdf} , 2.5.6 Support for Cyrillic, Maksym Polyakov

Speciﬁc languages

\usepackage{amsmath,amsthm,amssymb} \usepackage{mathtext} \usepackage[T1,T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage[english,bulgarian,russian,ukrainian]{babel}

Generally, babel will automatically choose the default font encoding, for the above three languages this is T2A. However, documents are not restricted to a single font encoding. For multilingual documents using Cyrillic and Latin-based languages it makes sense to include Latin font encoding explicitly. Babel will take care of switching to the appropriate font encoding when a diﬀerent language is selected within the document. On modern operating systems it is beneﬁcial to use Unicode (utf8 or utf8x) instead of KOI8-RU (koi8-ru) as an input encoding for Cyrillic text. In addition to enabling hyphenations, translating automatically generated text strings, and activating some language speciﬁc typographic rules (like \frenchspacing), babel provides some commands allowing typesetting according to the standards of Bulgarian, Russian, or Ukrainian languages. For all three languages, language speciﬁc punctuation is provided: the Cyrillic dash for the text (it is little narrower than Latin dash and surrounded by tiny spaces), a dash for direct speech, quotes, and commands to facilitate hyphenation: Key combination "| ""--"--˜ "--* ""

"˜ "= ", "‘ "’ "< ">

Action No ligature at this position. Explicit hyphen sign, allowing hyphenation in the rest of the word. Cyrillic emdash in plain text. Cyrillic emdash in compound names (surnames). Cyrillic emdash for denoting direct speech. Similar to "-, but it produces no hyphen sign (used for compound words with hyphen, e.g. x-""y or some other signs as “disable/enable”). Compound word mark without a breakpoint. Compound word mark with a breakpoint, allowing hyphenation in the composing words. Thinspace for initials with a breakpoint in a following surname. German opening double quote („). German closing double quote (“). French opening double quote (<<). French closing double quote (>>).

The Russian and Ukrainian options of babel deﬁne the commands \Asbuk \asbuk

135

Internationalization which act like \Alph and \alph (commands for turning counters into letters, e.g. a, b, c...), but produce capital and small letters of Russian or Ukrainian alphabets (whichever is the active language of the document). The Bulgarian option of babel provides the commands \enumBul \enumLat \enumEng

which make \Alph and \alph produce letters of either Bulgarian or Latin (English) alphabets. The default behaviour of \Alph and \alph for the Bulgarian language option is to produce letters from the Bulgarian alphabet. See the Bulgarian translation of ”The Not So Short Introduction to LaTeX” 13 for a method to type Cyrillic letters directly from the keyboard using a diﬀerent distribution.

12.4.4. Chinese One possible Chinese support is made available thanks to the CJK package collection. If you are using a package manager or a portage tree, the CJK collection is usually in a separate package because of its size (mainly due to fonts). Make sure your document is saved using the UTF-8 character encoding. See Special Characters14 for more details. Put the parts where you want to write chinese characters in a CJK environment. \documentclass{article} \usepackage{CJK} \begin{document} \begin{CJK}{UTF8}{gbsn} You can mix latin letters and chinese. \end{CJK} \end{document}

The last argument speciﬁes the font. It must ﬁt the desired language, since fonts are diﬀerent for Chinese, Japanese and Korean. Possible choices for Chinese include: • • • •

gbsn (简体宋体, simpliﬁed Chinese) gkai (简体楷体, simpliﬁed Chinese) bsmi (繁体细上海宋体, traditional Chinese) bkai (繁体标楷体, traditional Chinese)

12.4.5. Czech Czech is ﬁne using 13 14

136

The Not So Short Introduction to LaTeX ˆ{http://www.ctan.org/tex-archive/info/lshort/ bulgarian/lshort-bg.pdf} , Bulgarian translation Chapter 11 on page 119

Speciﬁc languages

\usepackage[czech]{babel}

UTF-8 allows you to have „czech quotation marks“ directly in your text. Otherwise, there are macros \clqq and \crqq to produce left and right quote. You can place quotated text inside \uv.

12.4.6. Finnish Finnish language hyphenation is enabled with: \usepackage[finnish]{babel}

This will also automatically change document language (section names, etc.) to Finnish.

12.4.7. French You can load French language support with the following command: \usepackage[frenchb]{babel}

There are multiple options for typesetting French documents, depending on the ﬂavor of French: french, frenchb, and francais for Parisian French, and acadian and canadien for new-world French. If you do not know or do not really care, we would recommend using frenchb. However, as of version 3.0 of babel-french, it is advised to choose the language as a global option with the following command15 : \documentclass[french]{article} \usepackage{babel}

All enable French hyphenation, if you have conﬁgured your LaTeX system accordingly. All of these also change all automatic text into French: \chapter prints Chapitre, \today prints the current date in French and so on. A set of new commands also becomes available, which allows you to write French input ﬁles more easily. Check out the following table for inspiration: input code \og guillemets \fg{} M\up{me}, D\up{r} 1\ier{}, 1\iere{}, 1\ieres{} 2\ieme{} 4\iemes{} \No 1, \no 2 20˜\degres C, 45\degres

15

rendered output « guillemets » Mme , Dr 1er , 1re , 1res 2e 4es N° 1, n° 2 20 °C, 45°

babel-french documentation ˆ{http://mirrors.ctan.org/macros/latex/contrib/babel-contrib/ french/frenchb.pdf} : ”the French language should now be loaded as french, not as frenchb or francais and preferably as a global option of \documentclass. Some tolerance still exists in v3.0, but do not rely on it.”

137

Internationalization input code M. \bsc{Durand} \nombre{1234,56789}

rendered output M. Durand 1 234,567 89

You may want to typeset guillemets and other French characters directly if your keyboard have them. Running Xorg (*BSD and GNU/Linux), you may want to use the oss variant which features some nice shortcuts, like Key combination Alt Gr + w Alt Gr + x Alt Gr + Shift + é Alt Gr + Shift + è Alt Gr + Shift + ç

Character « » É È Ç

You will need the T1 font encoding for guillemets to print properly. For the degree character you will get an error like ! Package inputenc Error: Unicode char \u8:° not set up for use with LaTeX.

The textcomp package will ﬁx it for you. The great advantage of Babel for French is that it will handle some elements of French typography for you, especially non-breaking spaces before all two-parts punctuation marks. So now you can write: Il répondit: «Ce pain coûte-t-il 2~€?»

The non-breaking space before the euro symbol is still necessary because currency symbols and other units or not supported in general (that’s not speciﬁc to French). You can use the numprint package along Babel. It will let you print numbers the French way.

\usepackage[frenchb]{babel} \usepackage[autolanguage]{numprint} % Must be loaded *after* babel. % ... \nombre{123456.123456 e-17}

123 456, 123 456 · 10−17

You will also notice that the layout of lists changes when switching to the French language. This is customizable using the \frenchbsetup command. For more information on what the frenchb option of babel does and how you can customize its behavior, run LaTeX on

138

Speciﬁc languages ﬁle frenchb.dtx and read the produced ﬁle frenchb.pdf or frenchb.dvi. You can get the PDF version on CTAN16 .

12.4.8. German You can load German language support using either one of the two following commands. For traditional (”old”) German orthography use \usepackage[german]{babel}

or for reform (”new”) German orthography use \usepackage[ngerman]{babel}

This enables German hyphenation, if you have conﬁgured your LaTeX system accordingly. It also changes all automatic text into German, e.g. “Chapter” becomes “Kapitel”. A set of new commands also becomes available, which allows you to write German input ﬁles more quickly even when you don’t use the inputenc package. Check out the table below for inspiration. With inputenc, all this becomes moot, but your text also is locked in a particular encoding world. German Special Characters. "A "O "U "a "o "u "s " or \glqq "' or \grqq \glq \grq "< or \flqq "> or \frqq \flq \frq \dq

ÄÖÜ äöüß „ “ « » ‹› ”

In German books you sometimes ﬁnd French quotation marks («guillemets»). German typesetters, however, use them diﬀerently. A quote in a German book would look like »this«. In the German speaking part of Switzerland, typesetters use «guillemets» the same way the French do. A major problem arises from the use of commands like \flq: If you use the OT1 font encoding (which is the default) the guillemets will look like the math symbol ”≪”, which turns a typesetter’s stomach. T1 encoded fonts, on the other hand, do contain the required symbols. So if you are using this type of quote, make sure you use the T1 encoding. Decimal numbers usually have to be written like 0{,}5 (not just 0,5). Packages like ziffer enable input like 0,5. Alternatively, one can use the \num command from the babel and (globally) set the decimal marker using

16

http://mirrors.ctan.org/macros/latex/contrib/babel-contrib/frenchb/frenchb.pdf

139

Internationalization

\usepackage[output-decimal-marker={,}]{siunitx} % ... \num{0,5}

0,5

12.4.9. Greek This is the preamble you need to write in the Greek language. Note the particular input encoding. \usepackage[english,greek]{babel} \usepackage[iso-8859-7]{inputenc}

This preamble enables hyphenation and changes all automatic text to Greek. A set of new commands also becomes available, which allows you to write Greek input ﬁles more easily. In order to temporarily switch to English and vice versa, one can use the commands \textlatin{english text} and \textgreek{greek text} that both take one argument which is then typeset using the requested font encoding. Otherwise you can use the command \selectlanguage{...} described in a previous section. Use \euro for the Euro symbol.

12.4.10. Hungarian Use the following lines: \usepackage[magyar]{babel}

12.4.11. Icelandic and Faroese The following lines can be added to write Icelandic text: \usepackage[icelandic]{babel}

This changes text like Part into Hluti. It makes additional commands available: Icelandic special commands "` or \glqq \grqq \TH \th \DH \dh 17

140

http://www.math.bme.hu/latex/

„ “ Þ þ Ð ð

Speciﬁc languages To make special characters such as Þ and Æ become available just add: \usepackage[T1]{fontenc}

The default LATEX font encoding is OT1, but it contains only the 128 characters. The T1 encoding contains letters and punctuation characters for most of the European languages using Latin script.

12.4.12. Italian Italian is well supported by LaTeX. Just add \usepackage[italian]{babel}

at the beginning of your document and the output of all the commands will be translated properly.

12.4.13. Japanese There is a variant of TeX intended for Japanese named pTeX18 , which supports vertical typesetting. Another possible way to write in japanese is to use Lualatex and the luatex-ja package. Adapted example from the Luatexja documentation : \documentclass{ltjsarticle} \usepackage{luatexja} % This line is unnecessary when using ltjclasses or ltjsclasses. \begin{document} \section{ Lua\TeX-ja} \subsection{

}

\end{document}

You can also use capabilities provided by the Fontspec package and those provided by Luatexja-fontspec to declare the font you want to use in your paper. Let us take an example : % ********************************** % Basic setup \documentclass[10pt,a4paper]{article} \usepackage{luatextra}%this package calls fontspec, luatexbase, lualibs, metalogo, luacode and fixltx2e \setmainfont[Ligatures=Rare,Numbers=OldStyle]{Arno Pro} %setup of western font \usepackage{luatexja} \usepackage{luatexja-fontspec}%needed to call \setmainjfont bellow \setmainjfont[BoldFont=KozGoPr6N-Bold]{KozGoPr6N-Regular} %setup of japanese font %*********************************** \begin{document} It is a test to show japanese and english mix. \end{document}

18

http://ascii.asciimw.jp/pb/ptex/

141

Internationalization Use UTF-8 as your encoding. In case you don’t know how to do this, take a look at Texmaker, a LaTeX editor which use UTF-8 by default. Another (but old) possible Japanese support is made available thanks to the CJK package collection. If you are using a package manager or a portage tree, the CJK collection is usually in a separate package because of its size (mainly due to fonts). Make sure your document is saved using the UTF-8 character encoding. See Special Characters19 for more details. Put the parts where you want to write japanese characters in a CJK environment. \documentclass{article} \usepackage{CJK} \begin{document} \begin{CJK}{UTF8}{min} You can mix latin letters as well as hiragana, katakana and kanji. \end{CJK} \end{document}

The last argument speciﬁes the font. It must ﬁt the desired language, since fonts are diﬀerent for Chinese, Japanese and Korean. min is an example for Japanese.

12.4.14. Korean The two most widely used encodings for Korean text ﬁles are EUC-KR and its upward compatible extension used in Korean MS-Windows, CP949/Windows-949/UHC. In these encodings each US-ASCII character represents its normal ASCII character similar to other ASCII compatible encodings such as ISO-8859-x, EUC-JP, Big5, or Shift_JIS. On the other hand, Hangul syllables, Hanjas (Chinese characters as used in Korea), Hangul Jamos, Hiraganas, Katakanas, Greek and Cyrillic characters and other symbols and letters drawn from KS X 1001 are represented by two consecutive octets. The ﬁrst has its MSB set. Until the mid-1990’s, it took a considerable amount of time and eﬀort to set up a Korean-capable environment under a non-localized (non-Korean) operating system. You can skim through the now much-outdated http://jshin.net/faq to get a glimpse of what it was like to use Korean under non-Korean OS in mid-1990’s. TeX and LaTeX were originally written for scripts with no more than 256 characters in their alphabet. To make them work for languages with considerably more characters such as Korean or Chinese, a subfont mechanism was developed. It divides a single CJK font with thousands or tens of thousands of glyphs into a set of subfonts with 256 glyphs each. For Korean, there are three widely used packages. • HLATEX by UN Koaunghi • hLATEXp by CHA Jaechoon • the CJK package by Werner Lemberg

19

142

Chapter 11 on page 119

Speciﬁc languages HLATEX and hLATEXp are speciﬁc to Korean and provide Korean localization on top of the font support. They both can process Korean input text ﬁles encoded in EUC-KR. HLATEX can even process input ﬁles encoded in CP949/Windows-949/UHC and UTF-8 when used along with Λ, Ω. The CJK package is not speciﬁc to Korean. It can process input ﬁles in UTF-8 as well as in various CJK encodings including EUC-KR and CP949/Windows-949/UHC, it can be used to typeset documents with multilingual content (especially Chinese, Japanese and Korean). The CJK package has no Korean localization such as the one oﬀered by HLATEX and it does not come with as many special Korean fonts as HLATEX. The ultimate purpose of using typesetting programs like TeX and LaTeX is to get documents typeset in an aesthetically satisfying way. Arguably the most important element in typesetting is a set of welldesigned fonts. The HLATEX distribution includes UHC PostScript fonts of 10 diﬀerent families and Munhwabu fonts (TrueType) of 5 diﬀerent families. The CJK package works with a set of fonts used by earlier versions of HLATEX and it can use Bitstream’s cyberbit True-Type font. To use the HLATEX package for typesetting your Korean text, put the following declaration into the preamble of your document: \usepackage{hangul}

This command turns the Korean localization on. The headings of chapters, sections, subsections, table of content and table of ﬁgures are all translated into Korean and the formatting of the document is changed to follow Korean conventions. The package also provides automatic particle selection. In Korean, there are pairs of post-ﬁx particles grammatically equivalent but diﬀerent in form. Which of any given pair is correct depends on whether the preceding syllable ends with a vowel or a consonant. (It is a bit more complex than this, but this should give you a good picture.) Native Korean speakers have no problem picking the right particle, but it cannot be determined which particle to use for references and other automatic text that will change while you edit the document. It takes a painstaking eﬀort to place appropriate particles manually every time you add/remove references or simply shuﬄe parts of your document around. HLATEX relieves its users from this boring and error-prone process. In case you don’t need Korean localization features but just want to typeset Korean text, you can put the following line in the preamble, instead. \usepackage{hfont}

For more details on typesetting Korean with HLATEX, refer to the HLATEX Guide. Check out the web site of the Korean TeX User Group (KTUG)20 . In the FAQ section of KTUG it is recommended to use the kotex package \usepackage{kotex}

20

http://www.ktug.or.kr/

143

Internationalization

12.4.15. Persian script For Persian language, there is a dedicated package called XePersian which uses XeLaTeX as the typesetting engine. Just add the following code to your preamble: \usepackage{xepersian}

See XePersian page on CTAN21 Moreover, Arabic script can be used to type Persian as illustrated in the corresponding section22 .

12.4.16. Polish If you plan to use Polish in your UTF-8 encoded document, use the following code \usepackage[utf8]{inputenc} \usepackage{polski} \usepackage[polish]{babel}

The above code merely allows to use Polish letters and translates the automatic text to Polish, so that ”chapter” becomes ”rozdział”. There are a few additional things one must remember about. Connectives Polish has many single letter connectives: ”a”, ”o”, ”w”, ”i”, ”u”, ”z”, etc., grammar and typography rules don’t allow for them to end a printed line. To ensure that LaTeX won’t set them as last letter in the line, you have to use non breakable space: Noc była sierpniowa, ciepła i~słodka, Księżyc oświecał srebrnem światłem wgłębienie, tak, że twarze małego rycerza i~Basi były skąpane w blasku. Poniżej, na podwórzu zamkowem, widać było uśpione kupy żołnierzy, a~także i~ciała zabitych podczas dziennej strzelaniny, bo nie znaleziono dotąd czasu na ich pogrzebanie.


21 22

144

http://www.ctan.org/tex-archive/macros/xetex/latex/xepersian/ Chapter 12.4.20 on page 148



Alternatively you can use dedicated document classes: • the mwart class instead of article, • mwbk instead of book • and mwrep instead of report. Those classes have much more European typography settings but do not require the use of Polish babel settings or character encoding. Simple usage: \documentclass{mwart} \usepackage[polish]{babel} \usepackage{polski} \begin{document} Pójdź kińże tę chmurność w głąb flaszy. \end{document}

Full documentation for those classes is available at http://web.archive.org/web/ 20040609034031/http://www.ci.pwr.wroc.pl/~pmazur/LaTeX/mwclsdoc.pdf (Polish). Indentation It may be customary (depending on publisher) to indent the ﬁrst paragraph in sections and chapters: \usepackage{indentfirst}

Hyphenation and typography It’s much more frowned upon to set pages with hyphenation between pages than it is customary in American typesetting. To adjust penalties for hyphenation spanning pages, use this command: \brokenpenalty=1000

To adjust penalties for leaving widows and orphans (clubs in TeX nomenclature) use those commands: \clubpenalty=1000 \widowpenalty=1000

145

Internationalization Commas in math According to Polish typography rules, fractional parts of numbers should be delimited by a comma, not a dot. To make LaTeX not insert additional space in math mode after a comma (unless there is a space after the comma), use the icomma package. \usepackage{icomma}

Unfortunately, it is partially incompatible with the dcolumn package. One needs to either use dots in columns with numerical data in the source ﬁle and make dcolumn switch them to commas for display or deﬁne the column as follows: \begin{tabular}{... D{,}{\mathord\mathcomma}{2} ...}

The alternative is to use the numprint package, but it is much less convenient. Further information Refer the Słownik Ortograﬁczny23 (in Polish) for additional information on Polish grammar and typography rules. Good extract is available at Zasady Typograﬁczne Składania Tekstu24 (in Polish).

You can substitute the language for brazilian portuguese by choosing brazilian or brazil.

12.4.18. Slovak Basic settings are ﬁne when left the same as Czech, but Slovak needs special signs for ’ď’, ’ť’, ’ľ’. To be able to type them from keyboard use the following settings: \usepackage[slovak]{babel} \usepackage[IL2]{fontenc}

12.4.19. Spanish Include the appropriate Babel option: \usepackage[spanish]{babel}

23 24

146

Speciﬁc languages The trick is that Spanish has several options and commands to control the layout. The options may be loaded either at the call to Babel, or before, by deﬁning the command \spanishoptions. Therefore, the following commands are roughly equivalent: \def\spanishoptions{mexico} \usepackage[spanish]{babel} \usepackage[spanish,mexico]{babel}

On average, the former syntax should be preferred, as the latter is a deviation from standard Babel behavior, and thus may break other programs (LyX, latex2rtf) interacting with LaTeX. Spanish also deﬁnes shorthands for the dot and << >> so that they are used as logical markup: the former is used as decimal marker in math mode, and the output is typically either a comma or a dot; the latter is used for quoted text, and the output is typically either «» or “”. This allows diﬀerent typographical conventions with the same input, as preferences may be quite diﬀerent from, say, Spain and Mexico. Two particularly useful options are es-noquoting,es-nolists: some packages and classes are known to collide with Spanish in the way they handle active characters, and these options disable the internal workings of Spanish to allow you to overcome these common pitfalls. Moreover, these options may simplify the way LyX customizes some features of the Spanish layout from inside the GUI. The options mexico,mexico-com provide support for local custom in Mexico: the former using decimal dot, as customary, and the latter allowing decimal comma, as required by the Mexican Oﬃcial Norm (NOM) of the Department of Economy for labels in foods and goods. More localizations are in the making. The other commands modify the spanish layout after loading Babel. Two particularly useful commands are \spanishoperators and \spanishdeactivate. The macro \spanishoperators{}{ contains a list of spanish mathematical operators, and may be redeﬁned at will. For instance, the command \def\spanishoperators{sen}

only deﬁnes sen, overriding all other deﬁnitions; the command \let\spanishoperators\relax disables them all. This command supports accented or spaced operators: the \acute{} command puts an accent, and the \, command adds a small space. For instance, the following operators are deﬁned by default. l\acute{i}m l\acute{i}m\,sup l\acute{i}m\,inf m\acute{a}x \acute{i}nf m\acute{i}n sen tg arc\,sen arc\,cos arc\,tg cotg cosec senh tgh

Finally, the macro \spanishdeactivate{} disables some active characters, to keep you out of trouble if they are redeﬁned by other packages. The candidates for deactivation are the set {<>.” ’}. Please, beware that some option preempt the availability of some active characters. In particular, you should not combine the es-noquoting option with \spanishdeactivate{<>}, or the es-noshorthands with \spanishdeactivate{<>."}.

147

Internationalization Please check the documentation for Babel or spanish.dtx for further details.

12.4.20. Tibetan One option to use Tibetan script in LaTeX is to add \usepackage{ctib}

to your preamble and use a slightly modiﬁed Wylie transliteration for input. Refer to the excellent package documentation for details. More information can be found on http: //www.thlib.org/tools/scripts/wiki/latex.html

12.5. References

148

13. Rotations B

Warning

Many DVI viewers do not support rotating of text and tables. The text will be displayed normally. You must convert your DVI ﬁle to a PDF document and view it in a PDF viewer to see the rotation in eﬀect. Take care however that printing from those PDF ﬁles may rotate the respective page again in the same direction under certain circumstances. This behaviour can be inﬂuenced by the settings of your dvi2pdf converter, look at your manual for further information.

13.1. The rotating package The package rotating gives you the possibility to rotate any object of an arbitrary angle. Once you have loaded it with the standard command in the preamble: \usepackage{rotating}

you can use three new environments: \begin{sideways}

it will rotate the whole argument by 90 degrees counterclockwise. Moreover: \begin{turn}{30}

it will turn the argument of 30 degrees. You can give any angle as an argument, whether it is positive or negative. It will leave the necessary space to avoid any overlapping of text. \begin{rotate}{30}

like turn, but it will not add any extra space. If you want to make a ﬂoat sideways so that the caption is also rotated, you can use \begin{sidewaysfigure}

or \begin{sidewaystable}

Note, though, they will be placed on a separate page. If you would like to rotate a TikZ picture you could use sideways together with minipage.

149

Rotations

\begin{figure} \begin{sideways} \begin{minipage}{17.5cm} \input{../path/to/picture} \end{minipage} \end{sideways} \centering \caption[Caption]{Caption.} \label{pic:picture} \end{figure}

You can also use the \rotatebox command. Let’s rotate a tabular inside a table for example: \begin{table}[p] \centering \rotatebox{90}{ \begin{minipage}{\textheight} \begin{tabular}{

13.1.1. Options Default is sidewaysﬁgures/sidewaystables are oriented depending on page number in two sided documents (takes two passes). The rotating package takes the following options. counterclockwise/anticlockwise In single sided documents turn sidewaysﬁgures/sidewaystables counterclockwise. clockwise In single sided documents turn sidewaysﬁgures/sidewaystables clockwise (default). ﬁguresright In two sided documents all sidewaysﬁgures/sidewaystables are same orientation (left of ﬁgure, table now bottom of page). This is the style preferred by the Chicago Manual of Style (broadside). ﬁguresleft In two sided documents all sidewaysﬁgures/sidewaystables are same orientation (left of ﬁgure, table now at top of page).

13.2. The rotﬂoat package When it is desirable to place the rotated table at the exact location where it appears in the source (.tex) ﬁle, rotfloat package may be used. Then one can use \begin{sidewaystable}[H]

just like for normal tables. The H option can not be used without this package.

150

14. Tables Tables are a common feature in academic writing, often used to summarize research results. Mastering the art of table construction in LaTeX is therefore necessary to produce quality papers and with suﬃcient practice one can print beautiful tables of any kind. Keeping in mind that LaTeX is not a spreadsheet, it makes sense to use a dedicated tool to build tables and then to export these tables into the document. Basic tables are not too taxing, but anything more advanced can take a fair bit of construction; in these cases, more advanced packages can be very useful. However, ﬁrst it is important to know the basics. Once you are comfortable with basic LaTeX tables, you might have a look at more advanced packages or the export options of your favorite spreadsheet1 . Thanks to the modular nature of LaTeX, the whole process can be automated in a fairly comfortable way. For a long time, LaTeX tables were quite a chaotic topic, with dozens of packages doing similar things, while not always being compatible with one another. Sometimes you had to make trade-oﬀs. The situation changed recently (2010) with the release of the tabu package which combines the power of longtable, tabularx and much more. The tabu environment is far less fragile and restricted than the older alternatives. Nonetheless, before attempting to use this package for the ﬁrst time it will be beneﬁcial to understand how the classic environment works, since tabu works the same way. Note however that the author of tabu will not ﬁx bugs to the current version, and that the next version introduces new syntax that will likely break existing documents.2

14.1. The tabular environment The tabular environment can be used to typeset tables with optional horizontal and vertical lines. LaTeX determines the width of the columns automatically. The ﬁrst line of the environment has the form: \begin{tabular}[pos]{table spec}

The table spec argument tells LaTeX the alignment to be used in each column and the vertical lines to insert. The number of columns does not need to be speciﬁed as it is inferred by looking at the number of arguments provided. It is also possible to add vertical lines between the columns here. The following symbols are available to describe the table columns (some of them require that the package array has been loaded):

1 2

Chapter 14.16 on page 184 http://tex.stackexchange.com/questions/121841/is-the-tabu-package-obsolete

151

Tables

l c r p{'width'} m{'width'} b{'width'} | ||

left-justiﬁed column centered column right-justiﬁed column paragraph column with text vertically aligned at the top paragraph column with text vertically aligned in the middle (requires array package) paragraph column with text vertically aligned at the bottom (requires array package) vertical line double vertical line

By default, if the text in a column is too wide for the page, LaTeX won’t automatically wrap it. Using p{'width'} you can deﬁne a special type of column which will wrap-around the text as in a normal paragraph. You can pass the width using any unit supported by LaTeX, such as ’pt’ and ’cm’, or command lengths, such as \textwidth. You can ﬁnd a list in chapter Lengths3 . The optional parameter pos can be used to specify the vertical position of the table relative to the baseline of the surrounding text. In most cases, you will not need this option. It becomes relevant only if your table is not in a paragraph of its own. You can use the following letters: bottom center (default) top

b c t

To specify a font format (such as bold, italic, etc.) for an entire column, you can add >{\format} before you declare the alignment. For example \begin{tabular}{ >{\bfseries}l c >{\itshape}r } will indicate a three column table with the ﬁrst one aligned to the left and in bold font, the second one aligned in the center and with normal font, and the third aligned to the right and in italic. The ”array” package needs to be activated in the preamble for this to work. In the ﬁrst line you have pointed out how many columns you want, their alignment and the vertical lines to separate them. Once in the environment, you have to introduce the text you want, separating between cells and introducing new lines. The commands you have to use are the following: & \\ \hline \newline \cline{i-j}

3

152

column separator start new row (additional space may be speciﬁed after \\ using square brackets, such as \\[6pt]) horizontal line start a new line within a cell (in a paragraph column) partial horizontal line beginning in column i and ending in column j

Chapter 23 on page 287

The tabular environment Note, any white space inserted between these commands is purely down to ones’ preferences. I personally add spaces between to make it easier to read.

14.1.1. Basic examples This example shows how to create a simple table in LaTeX. It is a three-by-three table, but without any lines.

\begin{tabular}{ l c r } 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ \end{tabular}

1 2 3 4 5 6 7 8 9

Expanding upon that by including some vertical lines:

\begin{tabular}{ l 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ \end{tabular}

1 2 4 5 7 8

c

r }

3 6 9

To add horizontal lines to the very top and bottom edges of the table:

\begin{tabular}{ l \hline 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ \hline \end{tabular}

1 2 4 5 7 8

c

r }

3 6 9

153

Tables And ﬁnally, to add lines between all rows, as well as centering (notice the use of the center environment - of course, the result of this is not obvious from the preview on this web page):

\begin{center} \begin{tabular}{ l c \hline 1 & 2 & 3 \\ \hline 4 & 5 & 6 \\ \hline 7 & 8 & 9 \\ \hline \end{tabular} \end{center}

1 2 4 5 7 8

r }

3 6 9

\begin{center} \begin{tabular}{ l c r } \hline 1 & 2 & 3 \\ \hline 4 & 5 & 6 \\ \hline \hline 7 & 8 & 9 \\ \hline \end{tabular} \end{center}

1 4 7

2 5 8

3 6 9

\begin{tabular} \hline 7C0 & hexadecimal \\ 3700 & octal \\ \cline{2-2} 11111000000 & binary \\ \hline \hline 1984 & decimal \\ \hline \end{tabular}

154

The tabular environment

Figure 35

14.1.2. Text wrapping in tables LaTeX’s algorithms for formatting tables have a few shortcomings. One is that it will not automatically wrap text in cells, even if it overruns the width of the page. For columns that will contain text whose length exceeds the column’s width, it is recommended that you use the p attribute and specify the desired width of the column (although it may take some trial-and-error to get the result you want). For a more convenient method, have a look at The tabularx package4 , or The tabulary package5 . Instead of p, use the m attribute to have the lines aligned toward the middle of the box or the b attribute to align along the bottom of the box. Here is a simple example. The following code creates two tables with the same code; the only diﬀerence is that the last column of the second one has a deﬁned width of 5 centimeters, while in the ﬁrst one we didn’t specify any width. Compiling this code: \documentclass{article} \usepackage[english]{babel} \begin{document} Without specifying width for last column: \begin{center} \begin{tabular} l l l l } \hline Day & Min Temp & Max Temp & Summary \\ \hline Monday & 11C & 22C & A clear day with lots of sunshine. However, the strong breeze will bring down the temperatures. \\ \hline Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells across most of Scotland and Northern Ireland, but rain reaching the far northwest. \\ \hline Wednesday & 10C & 21C & Rain will still linger for the morning. Conditions will improve by early afternoon and continue throughout the evening. \\ \hline \end{tabular} \end{center} With width specified: \begin{center} \begin{tabular}{ l

4 5

l

l

p{5cm} }

Chapter 14.6 on page 171 Chapter 14.6 on page 171

155

Tables \hline Day & Min Temp & Max Temp & Summary \\ \hline Monday & 11C & 22C & A clear day with lots of sunshine. However, the strong breeze will bring down the temperatures. \\ \hline Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells across most of Scotland and Northern Ireland, but rain reaching the far northwest. \\ \hline Wednesday & 10C & 21C & Rain will still linger for the morning. Conditions will improve by early afternoon and continue throughout the evening. \\ \hline \end{tabular} \end{center} \end{document}

You get the following output:

Figure 36

Note that the ﬁrst table has been cropped, since the output is wider than the page width.

14.1.3. Manually broken paragraphs in table cells Sometimes it is necessary to not rely on the breaking algorithm when using the p speciﬁer, but rather specify the line breaks by hand. In this case it is easiest to use a \parbox: \begin{tabular}{cc} boring cell content & \parbox[t]{5cm}{rather long par\\new par} \end{tabular}

156

The tabular environment

14.1.4. Space between columns To tweak the space between columns (LaTeX will by default choose very tight columns), one can alter the column separation: \setlength{\tabcolsep}{5pt}. The default value is 6pt.

14.1.5. Space between rows Re-deﬁne the \arraystretch command to set the space between rows: \renewcommand{\arraystretch}{1.5}


16 17

178

http://www.ctan.org/tex-archive/macros/latex/contrib/booktabs/ http://mirrors.ctan.org/macros/latex/contrib/booktabs/booktabs.pdf

Professional tables

Figure 56

14.11.2. Using array

\usepackage{array} %or \usepackage{dcolumn} ... \begin{tabular}{llr} \firsthline \multicolumn{2}{c}{Item} \\ \cline{1-2} Animal & Description & Price (\$) \\ \hline Gnat & per gram & 13.65 \\ & each & 0.01 \\ Gnu & stuffed & 92.50 \\ Emu & stuffed & 33.33 \\ Armadillo & frozen & 8.99 \\ \lasthline \end{tabular} 179 Tables Figure 57 14.11.3. Using booktabs \usepackage{booktabs}\\ \begin{tabular}{llr} \toprule \multicolumn{2}{c}{Item} \\ \cmidrule(r){1-2} Animal & Description & Price (\$) \\ \midrule Gnat & per gram & 13.65 \\ & each & 0.01 \\ Gnu & stuffed & 92.50 \\ Emu & stuffed & 33.33 \\ Armadillo & frozen & 8.99 \\ \bottomrule \end{tabular}

180

Sideways tables

Figure 58 Usually the need arises for footnotes under a table (and not at the bottom of the page), with a caption properly spaced above the table. These are addressed by the ctable18 package. It provides the option of a short caption given to be inserted in the list of tables, instead of the actual caption (which may be quite long and inappropriate for the list of tables). The ctable uses the booktabs package.

14.12. Sideways tables Tables can also be put on their side within a document using the rotating or the rotfloat package. See the Rotations19 chapter.

14.13. Table with legend To add a legend to a table the caption20 package can be used. With the caption package a \caption*{...} statement can be added besides the normal \caption{...}. Example: \begin{table} \begin{tabular} r

r

c

c

c }

...

18 19 20

http://www.ctan.org/tex-archive/macros/latex/contrib/ctable/ Chapter 13 on page 149 http://www.ctan.org/tex-archive/macros/latex/contrib/caption/

181

Tables

\end{tabular} \caption{A normal caption} \caption*{ A legend, even a table can be used \begin{tabular}{l l} item 1 & explanation 1 \\ \end{tabular} } \end{table}

The normal caption is needed for labels and references.

14.14. The eqparbox package On rare occasions, it might be necessary to stretch every row in a table to the natural width of its longest line, for instance when one has the same text in two languages and wishes to present these next to each other with lines synching up. A tabular environment helps control where lines should break, but cannot justify the text, which leads to ragged right edges. The eqparbox package provides the command \eqmakebox which is like \makebox but instead of a width argument, it takes a tag. During compilation it bookkeeps which \eqmakebox with a certain tag contains the widest text and can stretch all \eqmakeboxes with the same tag to that width. Combined with the array package, one can deﬁne a column speciﬁer that justiﬁes the text in all lines: \newsavebox{\tstretchbox} \newcolumntype{S}[1]{% >{\begin{lrbox}{\tstretchbox} }% l% <{\end{lrbox}% \eqmakebox[#1][s]{\unhcopy\tstretchbox} }% }

See the documentation of the eqparbox package for more details.

14.15. Floating with table In WYSIWYG document processors, it is common to put tables in the middle of the text. This is what we have been doing until now. Professional documents, however, often make it a point to print tables on a dedicated page so that they do not disrupt the ﬂow. From the point of view of the source code, one has no idea on which page the current text is going to lie, so it is hardly possible to guess which page may be appropriate for our table. LaTeX can automate this task by abstracting objects such as tables, pictures, etc., and deciding for us where they might ﬁt best. This abstraction is called a ﬂoat. Generally, an object that is ﬂoated will appear in the vicinity of its introduction in the source ﬁle, but one can choose to control its position also. To tell LaTeX we want to use our table as a ﬂoat, we need to put a table environment around the tabular environment, which is able to ﬂoat and add a label and caption.

182

Floating with table

B

Warning

Please understand: you do not have to use ﬂoating tables. If you want to place your tables where they lie in your source code and you do not need any label, do not use table at all! This is a very common misunderstanding among newcomers. The table environment initiates a type of ﬂoat just as the environment figure. In fact, the two bear a lot of similarities (positioning, captions, etc.). More information about ﬂoating environments, captions etc. can be found in Floats, Figures and Captions21 . The environment names may now seem quite confusing. Let’s sum it up: • tabular is for the content itself (columns, lines, etc.). • table is for the location of the table on the document, plus caption and label support. \begin{table}[position specifier] \centering \begin{tabular}l} ... your table ... \end{tabular} \caption{This table shows some data} \label{tab:myfirsttable} \end{table}

In the table, we used a label, so now we can refer to it just like any other reference: \ref{tab:myfirsttable}

The table environment is also useful when you want to have a list of tables at the beginning or end of your document with the command \listoftables

The captions now show up in the list of tables, if displayed. You can set the optional parameter position specifier to deﬁne the position of the table, where it should be placed. The following characters are all possible placements. Using sequences of it deﬁne your ”wishlist” to LaTeX. h t b p !

where the table is declared (here) at the top of the page at the bottom of the page on a dedicated page of ﬂoats override the default ﬂoat restrictions. E.g., the maximum size allowed of a b ﬂoat is normally quite small; if you want a large one, you need this ! parameter as well.

Default is tbp, which means that it is by default placed on the top of the page. If that’s not possible, it’s placed at the bottom if possible, or ﬁnally with other ﬂoating environments on an extra page. 21

Chapter 18 on page 231

183

Tables You can force LaTeX to use one given position. E.g. [!h] forces LaTeX to place it exactly where you place it (Except when it’s really impossible, e.g you place a table here and this place would be the last line on a page). Again, understand it correctly: it urges LaTeX to put the table at a speciﬁc place, but it will not be placed there if LaTeX thinks it will not look great. If you really want to place your table manually, do not use the table environment. Centering the table horizontally works like everything else, using the \centering command just after opening the table environment, or by enclosing it with a center environment.

14.16. Using spreadsheets and data analysis tools For complex or dynamic tables, you may want to use a spreadsheet. You might save lots of time by building tables using specialized software and exporting them in LaTeX format. The following plugins and libraries are available for some popular software: calc2latex22 : for OpenOﬃce.org Calc spreadsheets, excel2latex23 : for Microsoft Oﬃce Excel, matrix2latex24 : for MATLAB, matrix2latex25 : for Python and MATLAB, pandas26 : pandas DataFrame’s have a method to convert data they contain to latex, latex-tools27 : a Ruby library, xtable28 : a library for R, org-mode29 : for Emacs users, org-mode tables can be used inline in LaTeX documents, see https://www.gnu.org/software/emacs/manual/html_node/org/ A-LaTeX-example.html for a tutorial. • Emacs align commands30 : the align commands can clean up a messy LaTeX table. • Online Table generator for LATeX31 : An online tool for creating simple tables within the browser. LaTeX format is directly generated as you type. • Create LaTeX tables online 32 : Online tool. • • • • • • • •

However, copying the generated source code to your document is not convenient at all. For maximum ﬂexibility, generate the source code to a separate ﬁle which you can input from your main document ﬁle with the \input command. If your speadsheet supports commandline, you can generate your complete document (table included) in one command, using a Makeﬁle for example.

22 23 24 25 26 27 28 29 30 31 32

184

http://calc2latex.sourceforge.net/ http://www.ctan.org/tex-archive/support/excel2latex/ http://www.mathworks.com/matlabcentral/fileexchange/4894-matrix2latex https://github.com/TheChymera/matrix2latex http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_latex.html http://rubygems.org/gems/latex-tools http://cran.r-project.org/web/packages/xtable/index.html http://orgmode.org/ http://emacswiki.org/emacs/AlignCommands http://truben.no/latex/table/ http://www.tablesgenerator.com/

Need more complicated features? See Modular Documents33 for more details.

14.17. Need more complicated features? Have a look at one of the following packages: • • • • • • • • • • •

• • •

hhline34 : do whatever you want with horizontal lines array35 : gives you more freedom on how to deﬁne columns colortbl36 : make your table more colorful threeparttable37 makes it possible to put footnotes both within the table and its caption arydshln38 : creates dashed horizontal and vertical lines ctable39 : allows for footnotes under table and properly spaced caption above (incorporates booktabs package) slashbox40 : create 2D tables with the ﬁrst cell containing a description for both axes. Not available in Tex Live 2011 or later. diagbox41 : compatible to slashbox, come with Tex Live 2011 or later dcolumn42 : decimal point alignment of numeric cells rccol43 : advanced decimal point alignment of numeric cells with rounding numprint44 : print numbers, in the current mode (text or math) in order to use the correct font, with separators, exponent and/or rounded to a given number of digits. tabular(*), array, tabularx, and longtable environments is supported using all features of numprint spreadtab45 : spread sheets allowing the use of formulae siunitx46 : alignment of tabular entries pgfplotstable47 : Loads, rounds, formats and postprocesses numerical tables.

14.18. References fr:LaTeX/Faire_des_tableaux48 nl:LaTeX/Tabellen49 pl:LaTeX/Tabele50

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

Chapter 55 on page 605 http://www.ctan.org/pkg/hhline http://www.ctan.org/pkg/array http://www.ctan.org/pkg/colortbl http://ctan.org/tex-archive/macros/latex/contrib/threeparttable http://www.ctan.org/pkg/arydshln http://www.ctan.org/pkg/ctable http://www.ctan.org/pkg/slashbox http://mirror.jmu.edu/pub/CTAN/macros/latex/contrib/diagbox/ http://www.ctan.org/pkg/dcolumn http://www.ctan.org/pkg/rccol http://www.ctan.org/pkg/numprint http://www.ctan.org/pkg/spreadtab http://ctan.org/tex-archive/macros/latex/contrib/siunitx http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots https://fr.wikibooks.org/wiki/LaTeX%2FFaire_des_tableaux https://nl.wikibooks.org/wiki/LaTeX%2FTabellen https://pl.wikibooks.org/wiki/LaTeX%2FTabele

185

15. Title creation For documents such as basic articles, the output of \maketitle is often adequate, but longer documents (such as books and reports) often require more involved formatting. We will detail the process here. There are several situations where you might want to create a title in a custom format, rather than in the format natively supported by LaTeX classes. While it is possible to change the output of \maketitle, it can be complicated even with minor changes to the title. In such cases it is often better to create the title from scratch, and this section will show you how to accomplish this.

15.1. Standard Titles Many document classes will form a title or a title page for you. One must specify what to ﬁll it with using these commands placed in the top matter1 : \title{The Triangulation of Titling Data in Non-Linear Gaussian Fashion via $\rho$ Series} \date{October 31, 2014} \author{John Doe\\ Magic Department, Richard Miles University \and Richard Row, \LaTeX\ Academy}

Commonly the date is excluded from the title page by using \date{}. It defaults to \today if omitted in the source ﬁle. To form a title, use \maketitle

This should go after the preceding commands. For most document classes, this will form a separate page, while the article document class will place the title on the top of the ﬁrst page. If you want to have a separate title page for articles as well, use the documentclass option titlepage. Footnotes within the title page can be speciﬁed with the \thanks command. For example, one may add \author{John Doe\thanks{Funded by NASA Grant \#42}}

The \thanks command can also be used in the \title.

1

Chapter 5.3.1 on page 54

187

Title creation It is dependent on the document class which commands are used in the title generated by \maketitle. Referring to the documentation will lead to trusted information.

15.2.1. Create the title for a report or book A title page for reports to get a university degree is quite static, it doesn’t really change over time. You can prepare the titlepage in its own little document and prepare a one page pdf that you later include into your real document. This is really useful, if the title page is required to have completely diﬀerent margins as the rest of the document. It also saves compile time, though it is not much. You need to know very basic LaTeX layout commands in order to get your own title page perfect. Usually a custom titlepage does not contain any semantic markup, everything is hand crafted. Here are some of the most often needed things: Alignment if you want to center some text just use \centering. If you want to align it diﬀerently you can use the environment \raggedleft for right-alignment and \raggedright for leftalignment. Images the command for including images (a logo for example) is the following : \includegraphics[width=0.15\textwidth]{./logo}. There is no \begin{figure} as you would usually use since you don’t want it to be ﬂoating2 , you just want it exactly where want it to be. When handling it, remember that it is considered like a big box by the TeX engine.

2

188

Chapter 18 on page 231

Custom Title Pages Text size

If you want to change the size of some text just place it within braces, {like this}, and you can use the following commands (in order of size): \Huge, \huge, \LARGE, \Large, \large, \normalsize, \small, \footnotesize, \tiny. So for example: {\large this text is slightly bigger than normal}, this one is not.

Remember, if you have a block of text in a diﬀerent size, even if it is a bit of text on a single line, end it with \par. Filling the page the command \vfill as the last item of your content will add empty space until the page is full. If you put it within the page, you will ensure that all the following text will be placed at the bottom of the page. A practical example All these tips might have made you confused. Here is a practical and compilable example. The picture in use comes with package mwe and should be available with every complete LaTeX installation. You can start testing right away. \documentclass[12pt,a4paper]{report} \usepackage{graphicx} \begin{document} \begin{titlepage} \centering \includegraphics[width=0.15\textwidth]{example-image-1x1}\par\vspace{1cm} {\scshape\LARGE Columbidae University \par} \vspace{1cm} {\scshape\Large Final year project\par} \vspace{1.5cm} {\huge\bfseries Pigeons love doves\par} \vspace{2cm} {\Large\itshape John Birdwatch\par} \vfill supervised by\par Dr.~Mark \textsc{Brown} \vfill % Bottom of the page {\large \today\par} \end{titlepage} \end{document}

As you can see, the code looks ”dirtier” than standard LaTeX source because you have to take care of the output as well. If you start changing fonts it gets even more complicated, but you can do it: it’s only for the title and your complicated code will be isolated from all the rest within its own ﬁle. The result is shown below

189

Title creation

Figure 59

TitlepageWikibook

Integrating the title page Assuming you have done the title page of your report in an extra document, let’s pretend it is called reportTitlepage2015.pdf, you can include it quite simply. Here is a short document setup. \documentclass{report} \usepackage{pdfpages} \begin{document} \includepdf{reportTitlepage2015}

190

Custom Title Pages \tableofcontents \chapter{Introducing birds} \end{document}


This package can be loaded within a usual document. The user can set the variables for title and the like. Which commands are actually available, and which might be omissible should be written in a documentation that is bundled with the package. Look around what happens if you leave one or the other command out.

191

Title creation

\documentclass{book} \usepackage{columbidaeTitle} %\supervisor{Dr. James Miller} \project{Bachelor Thesis} \author{A LaTeX enthusiast} \title{Why i want to be a duck} \begin{document} \maketitle \tableofcontents \chapter{Ducks are awesome} \end{document}

15.3. Packages for custom titles The titling package3 provides control over the typesetting of the \maketitle and \thanks commands. The titlepages package presents many styles of designs for title pages. Italian users may also want to use the frontespizio package4 .

15.4. Notes and References pt:Latex/Título5

3 4 5

192

[http://www.ctan.org/tex-archive/macros/latex/contrib/titling Titling package webpage in CTAN] [http://www.ctan.org/tex-archive/macros/latex/contrib/frontespizio Frontespizio package webpage in CTAN] https://pt.wikibooks.org/wiki/Latex%2FT%C3%ADtulo

16. Page Layout LaTeX and the document class will normally take care of page layout issues for you. For submission to an academic publication, this entire topic will be out of your hands, as the publishers want to control the presentation. However, for your own documents, there are some obvious settings that you may wish to change: margins, page orientation and columns, to name but three. The purpose of this tutorial is to show you how to conﬁgure your pages. We will often have to deal with TeX lengths in this chapter. You should have a look at Lengths1 for comprehensive details on the topic.

16.1. Two-sided documents Documents can be either one- or two-sided. Articles are by default one-sided, books are two-sided. Two-sided documents diﬀerentiate the left (even) and right (odd) pages, whereas one-sided do not. The most notable eﬀect can be seen in page margins. If you want to make the article class two-sided, use \documentclass[twoside]{article}. Many commands and variables in LaTeX take this concept into account. They are referred to as even and odd. For one-sided document, only the odd commands and variables will be in eﬀect.

16.2. Page dimensions A page in LaTeX is deﬁned by many internal parameters. Each parameter corresponds to the length of an element of the page, for example, \paperheight is the physical height of the page. Here you can see a diagram showing all the variables deﬁning the page. All sizes are given in TeX points (pt), there are 72.27pt in an inch or 1pt ≈0.3515mm.

1

Chapter 23 on page 287

193

Page Layout

Figure 60

1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

194

one inch + \hoffset one inch + \voffset \oddsidemargin = 31pt \topmargin = 20pt \headheight = 12pt \headsep = 25pt \textheight = 592pt \textwidth = 390pt \marginparsep = 10pt \marginparwidth = 35pt

Page size 11. \footskip = 30pt • • • • •

\marginparpush = 7pt (not shown) \hoffset = 0pt \voffset = 0pt \paperwidth = 597pt \paperheight = 845pt

The current details plus the layout shape can be printed from a LaTeX document itself. Use the layout package and the command of the same name: \usepackage{layout} ... \layout{}

To render a frame marking the margins of a document you are currently working on, add \usepackage{showframe}

to the document.

16.3. Page size It will not have been immediately obvious - because it doesn’t really cause any serious problems - that the default page size for all standard document classes is US letter. This is shorter by 18 mm (about 3/4 inch), and slightly wider by 8 mm (about 1/4 inch), compared to A4 (which is the standard in almost all the rest of the world). While this is not a serious issue (most printers will print the document without any problems), it is possible to specify alternative sizes as class option2 . For A4 format: \documentclass[a4paper]{article}

B

Warning

Note that the standard LaTeX classes use US Letter by default regardless of your TeX distribution conﬁguration. If you have TeX Live conﬁgured to use A4 paper, it will be the default only for plainTeX and classes not specifying the paper dimension.

B

Warning

The a4paper option with the article document class by itself has no eﬀect. It will only aﬀect the page size in connection with some appropriate package, like the geometry package or the hyperref package.

2

Chapter 5.2.1 on page 52

195

Page Layout

16.3.1. More size options with geometry One of the most versatile packages for page layout is the geometry package. The immediate advantage of this package is that it lets you customize the page size even with classes that do not support the options. For instance, to set the page size, add the following to your preamble: \usepackage[a4paper]{geometry}

The geometry package has many pre-deﬁned page sizes, like a4paper, built in. Others include: • • • • •

a0paper, a1paper, ..., a6paper, b0paper, b1paper, ..., b6paper, letterpaper, legalpaper, executivepaper.

To explicitly change the paper dimensions using the geometry package, the paperwidth and paperheight options can be used. For example: \usepackage[paperwidth=5.5in, paperheight=8.5in]{geometry}

16.3.2. Page size issues If you intend to get a PDF in the end, there are basically three ways: • TeX → PDF pdflatex myfile

# TeX → PDF

• TeX → DVI → PDF latex myfile dvipdf myfile

# TeX → DVI # DVI → PDF

• TeX → DVI → PS → PDF latex myfile dvips myfile -o myfile.ps ps2pdf myfile.ps myfile.pdf

# TeX → DVI # DVI → PS # PS → PDF

Sadly the PDF output page size may not be completely respectful of your settings. Some of these tools do not have the same interpretation of the DVI, PS and PDF speciﬁcations, and you may end up with a PDF which has not exactly the right size. Thankfully there is a solution to that: the \special command lets the user pass PostScript or PDF parameters, which can be used here to set the page size appropriately. • For pdflatex to work ﬁne, using the package geometry usually works. • For the DVI and PS ways, the safest way to always get the right paper size in the end is to add

196

Margins

\documentclass[...,a4paper,...]{...} \special{papersize=210mm,297mm}

to the tex ﬁle, and to append the appropriate parameters to the processors used during output generation: dvips -t a4 ... ps2pdf -sPAPERSIZE=a4 ... # On Windows: ps2pdf -sPAPERSIZE#a4 ...

3

If you want US Letter instead, replace 210mm,297mm by 8.5in,11in and a4paper by letter. Also replace a4 by letter in command-line parameters.

16.3.3. Page size for tablets Those who want to read on tablets or other handheld digital devices need to create documents without the extra whitespace. In order to create PDF documents with optimal handheld viewing, not only must the text ﬁeld and margins be adjusted, so must the page size. If you are looking for a sensible dimension, consider following the paper size used by the Supreme Court of the United States, 441pt by 666pt (or 6.125 inches by 9.25 inches), which looks great on tablets. You could also use the Supreme Court’s text ﬁeld size of 297 pt by 513 pt, but this is too wide for fonts other than Century Schoolbook, the font required by the Supreme Court.

16.4. Margins Readers used to perusing typical physical literature are probably wondering why there is so much white space surrounding the text. For example, on A4 paper a document will typically have 44 mm margin widths on the left and right of the page, leaving about 60% of the page width for text. The reason is improved readability. Studies have shown45 that it’s easier to read text when there are 60−70 characters per line—and it would seem that 66 is the optimal number. Therefore, the page margins are set to ensure optimal readability, and excessive margin white space is tolerated as a consequence. Sometimes, this white space is left in the inner margin with the assumption that the document will be bound. If you wish to avoid excessive white space, rather than changing the margins, consider instead using a two-column (or more) layout. This approach is the one usually taken by print magazines because it provides both readable line lengths and good use of the page. Another option for reducing the amount of whitespace on the page without changing the margins is to increase the font size using the 12pt option to the document class. If you wish to change the margins of your document, there are many ways to do so:

4 5

197

Page Layout • One older approach is to use the fullpage package for somewhat standardized smaller margins (around an inch), but it creates lines of more than 100 characters per line at with the 10pt default font size (and about 90 if the 12pt documentclass option is used): \usepackage{fullpage}

For even narrower margins, the fullpage package has a cm option (around 1.5cm), which results in about 120 characters per line at the 10pt default font size, about double what is considered readable: \usepackage[cm]{fullpage}

• A more modern and ﬂexible approach is to use the geometry package. This package allows you to specify the 4 margins without needing to remember the particular page dimensions commands. You can enter the measures in centimeters and inches as well. Use cm for centimeters and in for inches after each value (e.g. 1.0in or 2.54cm). Note that by default (i.e. without any options) this package already reduces the margins, so for a ’standard layout’ you may not need to specify anything. These values are relative to the edge of paper (0in) and go inward. For example, this command provides more conventional margins, better using the vertical space of the page, without creating the dramatically long lines of the fullpage package (if the 11pt documentclass option is used, the line lengths are about 88 characters for letter-sized paper and slightly less when using a4paper). \usepackage[top=1in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}

It can also recreate the behavior of the fullpage package using \usepackage[margin=1in]{geometry}

You can combine the margin options with the page size options seen in this paragraph6 . • You should not use the a4wide package for a page with A4 document size with smaller margins. It is obsolete and buggy. Use geometry package instead like this: \usepackage[a4paper,includeheadfoot,margin=2.54cm]{geometry}

• Edit individual page dimension variables described above, using the \addtolength and \setlength commands. See the Lengths7 chapter. For instance, \setlength{\textwidth}{6.5in} \addtolength{\voffset}{-5pt}

16.4.1. Odd and even margins Using the geometry package, the options left and right are used for the inside and outside margins respectively. They also have aliases inner and outer. Thus, the easiest way to handle

6 7

198

Chapter 16.11 on page 209 Chapter 23 on page 287

Page orientation diﬀerent margins for odd and even pages is to give the twoside option in the document class command and specify the margins as usually. \documentclass[twoside]{report} \usepackage[inner=4cm,outer=2cm]{geometry} %left=4cm,right=2cm would be equivalent

This will result in a value of 4cm on all inner margins (left margin for odd number pages and right margin for even pages) and 2cm margin on outer margins. Setting the same value for the inner and outer for geometry will remove the diﬀerence between the margins. Another quick way to eliminate the diﬀerence in position between even and odd numbered pages would be setting the values to evensidemargin and oddsidemargin to the half of odd’s default: \setlength{\oddsidemargin}{15.5pt} \setlength{\evensidemargin}{15.5pt}

By default, the value of evensidemargin is larger than oddsidemargin in the two-sided layout, as one could wish to write notes on the side of the page. The side for the large margin is chosen opposite to the side where pages are joined together. See the Lengths8 .

16.4.2. Top margin above Chapter The top margin above a chapter can be changed using the titlesec package. Example: http://www.ctex.org/documents/packages/layout/titlesec.pdf \usepackage{titlesec} \titlespacing*{\chapter}{0pt}{-50pt}{20pt} \titleformat{\chapter}[display]{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}

The command \titleformat must be used when the spacing of a chapter is changed. In case of a section this command can be omitted.

16.5. Page orientation When you talk about changing page orientation, it usually means changing to landscape mode, since portrait is the default. We shall introduce two slightly diﬀerent styles of changing orientation.

16.5.1. Change orientation of the whole document The ﬁrst is for when you want all of your document to be in landscape from the very beginning. There are various packages available to achieve this, but the one we prefer is the geometry package. All you need to do is call the package, with landscape as an option: 8

Chapter 23 on page 287

199

Page Layout

\usepackage[landscape]{geometry}

Although, if you intend to use geometry to set your paper size, don’t add the \usepackage commands twice, simply string all the options together, separating with a comma: \usepackage[a4paper,landscape]{geometry}

Using standard LaTeX classes, you can use the same class options: \documentclass[a4paper,landscape]{article}

16.5.2. Change orientation of speciﬁc part The second method is for when you are writing a document in portrait, but you have some contents, like a large diagram or table that would be displayed better on a landscape page. However, you still want the consistency of your headers and footers appearing the same place as the other pages. The lscape package is for this very purpose. It supplies a landscape environment, and anything inside is basically rotated. No actual page dimensions are changed. This approach is more applicable to books or reports than to typical academic publications. Using pdflscape instead of lscape when generating a PDF document will make the page appear right side up when viewed: the single page that is in landscape format will be rotated, while the rest will be left in portrait orientation. Also, to get a table to appear correctly centered on a landscaped page, one must place the tabular environment inside a table environment, which is itself inside the landscape environment. For instance it should look like this: \usepackage{pdflscape} % ... \begin{landscape} \begin{table} \centering % optional, probably makes it look better to have it centered on the page \begin{tabular}{....} % ... \end{tabular} \end{table} \end{landscape}

For books (and in general documents using the twoside option), the landscapeenvironment unfortunately does not pay attention to the diﬀerent layout of even and odd pages. The macro can be ﬁxed using a few lines of extra code in the preamble9 .

9

200

https://stackoverflow.com/questions/4982219/how-to-make-landscape-mode-rotate-properly-in-a-twoside-boo 5320962#5320962

Margins, page size and rotation of a speciﬁc page

16.5.3. Change orientation of ﬂoating environment If you use the above code, you will see that the table is inserted where it is in the code. It will not be ﬂoated! To ﬁx this you need the package rotating. See the Rotations10 chapter.

16.6. Margins, page size and rotation of a speciﬁc page If you need to rotate the page so that the ﬁgure ﬁts, the chances are good that you need to scale the margins and the font size too. Again, the geometry package comes in handy for specifying new margins for a single page only. \usepackage{geometry} \usepackage{pdflscape} % ... \newgeometry{margin=1cm} \begin{landscape} \thispagestyle{empty} %% Remove header and footer. \begin{table} \begin{center} \footnotesize %% Smaller font size. \begin{tabular}{....} % ... \end{tabular} \end{center} \end{table} \end{landscape} \restoregeometry

Note that order matters!

16.7. Page styles Page styles in Latex terms refers not to page dimensions, but to the running headers and footers of a document. These headers typically contain document titles, chapter or section numbers/names, and page numbers.

16.7.1. Standard page styles The possibilities of changing the headers in plain Latex are actually quite limited. There are two commands available: \pagestyle{''style''} will apply the speciﬁed style to the current and all subsequent pages, and \thispagestyle{''style''} will only aﬀect the current page. The possible styles are: empty 10

Both header and footer are cleared

Chapter 13 on page 149

201

Header is clear, but the footer contains the page number in the center. Footer is blank, header displays information according to document class (e.g., section name) and page number top right. Page number is top right, and it is possible to control the rest of the header.

The commands \markright and \markboth can be used to set the content of the headings by hand. The following commands placed at the beginning of an article document will set the header of all pages (one-sided) to contain ”John Smith” top left, ”On page styles” centered and the page number top right: \pagestyle{headings} \markright{John Smith\hfill On page styles\hfill}

There are special commands containing details on the running page of the document. \thepage \leftmark \rightmark \chaptername \thechapter \thesection

number of the current page current chapter name printed like ”CHAPTER 3. THIS IS THE CHAPTER TITLE” current section name printed like ”1.6. THIS IS THE SECTION TITLE” the name chapter in the current language. If this is English, it will display ”Chapter” current chapter number current section number


Now \leftmark and \rightmark will just print the name of the chapter and section, without number and without aﬀecting the formatting. Note that these redeﬁnitions must be inserted after the ﬁrst call of \pagestyle{fancy}. The standard book formatting of the \chaptermark is: \renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{\chaptername\ \thechapter.\ #1}}{}}


202

Page styles The ﬁrst line for the header, the second for the footer. Setting it to zero means that there will be no line. Plain pages issue An issue to look out for is that the major sectioning commands (\part, \chapter or \maketitle) specify a \thispagestyle{plain}. So, if you wish to suppress all styles by inserting a \pagestyle{empty} at the beginning of your document, then the style command at each section will override your initial rule, for those pages only. To achieve the intended result one can follow the new section commands with \thispagestyle{empty}. The \part command, however, cannot be ﬁxed this way, because it sets the page style, but also advances to the next page, so that \thispagestyle{} cannot be applied to that page. Two solutions: • simply write \usepackage{nopageno} in the preamble. This package will make \pagestyle{plain} have the same eﬀect as \pagestyle{empty}, eﬀectively suppressing page numbering when it is used. • Use fancyhdr as described below. The tricky problem when customizing headers and footers is to get things like running section and chapter names in there. Standard LaTeX accomplishes this with a two-stage approach. In the header and footer deﬁnition, you use the commands \rightmark and \leftmark to represent the current section and chapter heading, respectively. The values of these two commands are overwritten whenever a chapter or section command is processed. For ultimate ﬂexibility, the \chapter command and its friends do not redeﬁne \rightmark and \leftmark themselves. They call yet another command (\chaptermark, \sectionmark, or \subsectionmark) that is responsible for redeﬁning \rightmark and \leftmark, except if they are starred -- in such a case, \markboth{Chapter/Section name}{} must be used inside the sectioning command if header and footer lines are to be updated. Again, several packages provide a solution: • an alternative one-stage mechanism is provided by the package titleps); • fancyhdr will handle the process its own way.

16.7.2. Customizing with fancyhdr To get better control over the headers, one can use the package fancyhdr written by Piet van Oostrum. It provides several commands that allow you to customize the header and footer lines of your document. For a more complete guide, the author of the package produced this documentation11 . To begin, add the following lines to your preamble: \usepackage{fancyhdr} \setlength{\headheight}{15.2pt} \pagestyle{fancy}

11

http://www.ctan.org/tex-archive/macros/latex/contrib/fancyhdr/fancyhdr.pdf

203

Page Layout You can now observe a new style in your document. The \headheight needs to be 13.6pt or more, otherwise you will get a warning and possibly formatting issues. Both the header and footer comprise three elements each according to its horizontal position (left, centre or right). The styles supported by fancyhdr: • the four LaTeX styles; • fancy deﬁnes a new header for all pages but plain-style pages such as chapters and titlepage; • fancyplain is the same, but for absolutely all pages. Style customization The styles can be customized with fancyhdr speciﬁc commands. Those two styles may be conﬁgured directly, whereas for LaTeX styles you need to make a call to the \fancypagestyle command. To set header and footer style, fancyhdr provides three interfaces. They all provide the same features, you just use them diﬀerently. Choose the one you like most. • You can use the following six commands. \lhead[]{} \chead[]{} \rhead[]{} \lfoot[]{} \cfoot[]{} \rfoot[]{}

Hopefully, the behaviour of the above commands is fairly intuitive: if it has head in it, it aﬀects the head etc, and obviously, l, c and r means left, centre and right respectively. • You can also use the command \fancyhead for header and \fancyfoot for footer. They work in the same way, so we’ll explain only the ﬁrst one. The syntax is: \fancyhead[selectors]{output you want}

You can use multiple selectors optionally separated by a comma. The selectors are the following: E O L C R

even page odd page left side centered right side

so CE,RO will refer to the center of the even pages and to the right side of the odd pages.

204

Page styles • \fancyhf is a merge of \fancyhead and \fancyfoot, hence the name. There are two additional selectors H and F to specify the header or the footer, respectively. If you omit the H and the F, it will set the ﬁelds for both. These commands will only work for fancy and fancyplain. To customize LaTeX default style you need the \fancyplainstyle command. See below for examples. For a clean customization, we recommend you start from scratch. To do so you should erase the current pagestyle. Providing empty values will make the ﬁeld blank. So \fancyhf{}

will just delete the current heading/footer conﬁguration, so you can make your own. Plain pages There are two ways to change the style of plain pages like chapters and titlepage. First you can use the fancyplain style. If you do so, you can use the command \fancyplain{...}{...} inside fancyhdr commands like \lhead{...}, etc. When LaTeX wants to create a page with an empty style, it will insert the ﬁrst argument of \fancyplain, in all the other cases it will use the second argument. For instance: \pagestyle{fancyplain} \fancyhf{} \lhead{ \fancyplain{}{Author Name} } \rhead{ \fancyplain{}{\today} } \rfoot{ \fancyplain{}{\thepage} }


In that case you can use any style but fancyplain because it would override your redeﬁnition. Examples For two-sided, it’s common to mirror the style of opposite pages, you tend to think in terms of inner and outer. So, the same example as above for two-sided is:

205

Page Layout

This is eﬀectively saying author name is top outer, today’s date is top inner, and current page number is bottom outer. Using \fancyhf can make it shorter: \fancyhf[HLE,HRO]{Author's Name} \fancyhf[HRE,HLO]{\today} \fancyhf[FLE,FRO]{\thepage}



206

Page background

16.7.3. Page n of m Some people like to put the current page number in context with the whole document. LaTeX only provides access to the current page number. However, you can use the lastpage package to ﬁnd the total number of pages, like this: \usepackage{lastpage} ... \cfoot{\thepage\ of \pageref{LastPage} }

Note the capital letters. Also, add a backslash after \thepage to ensure adequate space between the page number and ’of’. And recall, when using references, that you have to run LaTeX an extra time to resolve the cross-references.

16.7.4. Alternative packages Other packages for page styles are scrpage2, very similar to fancyhdr, and titleps, which takes a one-stage approach, without having to use \leftmark or \rightmark.

16.8. Page background The eso-pic package will let you print content in the background of every page or individual pages. \usepackage{tikz} % for \gradientbox below. \usepackage{eso-pic} \newcommand{\gradientbox}[3]{% \begin{tikzpicture} \node[left color=#1,right color=#2] {#3}; \end{tikzpicture}% } \AddToShipoutPicture*{% \AtPageLowerLeft{% \rotatebox{90}{ \gradientbox{blue!20}{white}{% \begin{minipage}{\paperheight}% \hspace*{ \stretch{1} }\textcopyright~2013 \makeatletter\@author\makeatother.\hspace*{ \stretch{1} } \end{minipage}% } }% }% }

The starred-version of the \AddToShipoutPicture command applies to the current page only.

207

Page Layout

16.9. Multi-column pages 16.9.1. Using the twocolumn optional class argument Using a standard Latex document class, like article, you can simply pass the optional argument twocolumn to the document class: \documentclass[twocolumn]{article} which will give the desired eﬀect. While this approach is useful, it has limitations. The multicol package provides the following advantages: • Can support up to ten columns. • Implements a multicols environment, therefore, it is possible to mix the number of columns within a document. • Additionally, the environment can be nested inside other environments, such as figure. • multicol outputs balanced columns, whereby the columns on the ﬁnal page will be of roughly equal length. • Vertical rules between columns can be customised. • Column environments can be easily customised locally or globally.

16.9.2. Using multicol package The multicol package overcomes some of the shortcomings of twocolumn and provides the multicol environment. To create a typical two-column layout: \begin{multicols}{2} lots of text \end{multicols}

Floats are not fully supported by this environment. It can only cope if you use the starred forms of the ﬂoat commands (e.g., \begin{figure*} ) which makes the ﬂoat span all columns. This is not hugely problematic, since ﬂoats of the same width as a column may be too small, and you would probably want to span them anyway. See this section12 for a more detailed discussion. The multicol package has two important parameters which can be set13 using \setlength: • \columnseprule, sets the width of the vertical rule between columns and defaults to 0pt • \columnsep, sets the horizontal space between columns and the defaults to 10pt, which is quite narrow To force a break in a column, the command \columnbreak is used.

12 13

208

Chapter 18.6 on page 240 Chapter 23.3 on page 288

Widows and orphans

16.10. Manual page formatting There may be instances, especially in very long documents, such as books, that LaTeX will not get all page breaks looking as good as it could. It may, therefore, be necessary to manually tweak the page formatting. Of course, you should only do this at the very ﬁnal stage of producing your document, once all the content is complete. LaTeX oﬀers the following: \newpage \pagebreak[number]

\nopagebreak[number]

\clearpage

Ends the current page and starts a new one. Breaks the current page at the point of the command. The optional number argument sets the priority in a scale from 0 to 4. Stops the page being broken at the point of the command. The optional number argument sets the priority in a scale from 0 to 4. Ends the current page and causes any ﬂoats encountered in the input, but yet to appear, to be printed.

16.11. Widows and orphans w:Widows and orphans14 In professional books, it’s not desirable to have single lines at the beginning or end of a page. In typesetting such situations are called ’widows’ and ’orphans’. Normally it is possible that widows and orphans appear in LaTeX documents. You can try to deal with them using manual page formatting, but there’s also an automatic solution. LaTeX has a parameter for ’penalty’ for widows and orphans (’club lines’ in LaTeX terminology). With the greater penalty LaTeX will try more to avoid widows and orphans. You can try to increase these penalties by putting following commands in your document preamble: \widowpenalty=300 \clubpenalty=300

If this does not help, you can try increasing these values even more, to a maximum of 10000. However, it is not recommended to set this value too high, as setting it to 10000 forbids LaTeX from doing this altogether, which might result in strange behavior. It also helps to have rubber band values for the space between paragraphs: \setlength{\parskip}{3ex plus 2ex minus 2ex}

Alternatively, you can use the needspace package to reserve some lines and thus to prevent page breaking for those lines. \needspace{5\baselineskip} Some text

14

https://en.wikipedia.org/wiki/Widows%20and%20orphans

209

Page Layout on 5 lines.

16.12. Troubleshooting A very useful troubleshooting and designing technique is to turn on the showframe option in the geometry package (which has the same eﬀect as the showframe package described above). It draws bounding boxes around the major page elements, which can be helpful because the boundaries of various regions are usually invisible, and complicated by padding whitespace. \usepackage[showframe]{geometry}

16.13. Notes and References This page uses material from Andy Roberts’ Getting to grips with LaTeX with permission from the author.

210

17. Importing Graphics There are two possibilities to include graphics in your document. Either create them with some special code, a topic which will be discussed in the Creating Graphics part, (see Introducing Procedural Graphics1 ) or import productions from third party tools2 , which is what we will be discussing here. Strictly speaking, LaTeX cannot manage pictures directly: in order to introduce graphics within documents, LaTeX just creates a box with the same size as the image you want to include and embeds the picture, without any other processing. This means you will have to take care that the images you want to include are in the right format to be included. This is not such a hard task because LaTeX supports the most common picture formats around.

17.1. Raster graphics vs. vector graphics Raster graphics will highly contrast with the quality of the document if they are not in a high resolution, which is the case with most graphics. The result may be even worse once printed. Most drawing tools (e.g. for diagrams) can export in vector format. So you should always prefer PDF or EPS to PNG or JPG.

17.2. The graphicx package As stated before, LaTeX can’t manage pictures directly, so we will need some extra help: we have to load the graphicx packagehttp://ctan.org/pkg/graphicx/ in the preamble of our document: \usepackage{graphicx}

This package accepts as an argument the external driver to be used to manage pictures; however, the latest version of this package takes care of everything by itself, changing the driver according to the compiler you are using, so you don’t have to worry about this. Still, just in case you want to understand better how it works, here are the possible options you can pass to the package: • dvips (default if compiling with latex), if you are compiling with latex to get a DVI and you want to see your document with a DVI or PS viewer.

1 2

Chapter 44 on page 509 Chapter 17.12 on page 226

211

Importing Graphics • dvipdfm, if you are compiling with latex to get a DVI that you want to convert to PDF using dvipdfm, to see your document with any PDF viewer. • pdftex (default if compiling with pdflatex), if you are compiling with pdftex to get a PDF that you will see with any PDF viewer. But, again, you don’t need to pass any option to the package because the default settings are ﬁne in most of the cases. In many respects, importing your images into your document using LaTeX is fairly simple... once you have your images in the right format that is! Therefore, I fear for many people the biggest eﬀort will be the process of converting their graphics ﬁles. Now we will see which formats we can include and then we will see how to do it.

17.3. Document Options The graphics and graphicx packages recognize the draft and final options given in the \documentclass[...]{...} command at the start of the ﬁle. (See Document Classes3 .) Using draft as the option will suppress the inclusion of the image in the output ﬁle and will replace the contents with the name of the image ﬁle that would have been seen. Using final will result in the image being placed in the output ﬁle. The default is final.

17.4. Supported image formats As explained before, the image formats you can use depend on the driver that graphicx is using but, since the driver is automatically chosen according to the compiler, then the allowed image formats will depend on the compiler you are using.

B

Warning

Using pdflatex will be usually much more simple for graphics inclusion as it supports widespread formats such as PDF, PNG and JPG. Read this chapter carefully if you are using the DVI compiler (latex), otherwise you might encounter a lot of errors at compile time. Consider the following situation: you have added some pictures to your document in JPG and you have successfully compiled it in PDF. Now you want to compile it in DVI, you run latex and you get a lot of errors... because you forgot to provide the EPS versions of the pictures you want to insert. At the beginning of this book, we had stated that the same LaTeX source can be compiled in both DVI and PDF without any change. This is true, as long as you don’t use particular packages, and graphicx is one of those. In any case, you can still use both compilers with documents with pictures as well, as long as you always remember to provide the pictures in two formats (EPS and one of JPG, PNG or PDF). 3

212

Chapter 5.2.1 on page 52

Including graphics

17.4.1. Compiling with latex The only format you can include while compiling with latex is Encapsulated PostScript4 (EPS). The EPS format was deﬁned by Adobe Systems for making it easy for applications to import postscript-based graphics into documents. Because an EPS ﬁle declares the size of the image, it makes it easy for systems like LaTeX to arrange the text and the graphics in the best way. EPS is a vector format5 —this means that it can have very high quality if it is created properly, with programs that are able to manage vector graphics. It is also possible to store bit-map pictures within EPS, but they will need a lot of disk space.

17.4.2. Compiling with pdﬂatex If you are compiling with pdflatex to produce a PDF, you have a wider choice. You can insert: • JPG, widely used on Internet, digital cameras, etc. They are the best choice if you want to insert photos. • PNG, a very common format (even if not as much as JPG); it’s a lossless6 format and it’s the best choice for diagrams (if you were not able to generate a vector7 version) and screenshots. • PDF, it is widely used for documents but can be used to store images as well. It supports both vector and bit-map8 images, but it’s not recommended for the latter, as JPG or PNG will provide the same result using less disk space. • EPS can be used with the help of the epstopdf package. Depending on your installation, • you may just need to have it installed, there is no need to load it in your document; • if it does not work, you need to load it just after the graphicx package. Additionally, since epstopdf will need to convert the EPS ﬁle into a PDF ﬁle and store it, you need to give ”writing permissions” to your compiler. This is done by adding an option to the compiling command, e.g. pdflatex -shell-escape file.tex (if you use a LaTeX editor, they usually allow to modify the command in the conﬁguration options). Check the epstopdf documentation for other compilers.

17.5. Including graphics Now that we have seen which formats we can include and how we could manage those formats, it’s time to learn how to include them in our document. After you have loaded the graphicx package in your preamble, you can include images with \includegraphics, whose syntax is the following:

4 5 6 7 8

https://en.wikipedia.org/wiki/Encapsulated%20PostScript https://en.wikipedia.org/wiki/Vector%20graphics https://en.wikipedia.org/wiki/lossless https://en.wikipedia.org/wiki/Vector%20graphics https://en.wikipedia.org/wiki/Raster%20graphics

213

Importing Graphics

\includegraphics[attr1=val1, attr2=val2, ..., attrn=valn]{imagename}

As usual, arguments in square brackets are optional, whereas arguments in curly braces are compulsory. The argument in the curly braces is the name of the image. Write it without the extension. This way the LaTeX compiler will look for any supported image format in that directory and will take the best one (EPS if the output is DVI; JPEG, PNG or PDF if the output is PDF). Images can be saved in multiple formats for diﬀerent purposes. For example, a directory can have ”diagram.pdf” for high-resolution printing, while ”diagram.png” can be used for previewing on the monitor. You can specify which image ﬁle is to be used by pdflatex through the preamble command: \DeclareGraphicsExtensions{.pdf,.png,.jpg}

which speciﬁes the ﬁles to include in the document (in order of preference), if ﬁles with the same basename exist, but with diﬀerent extensions. The variety of possible attributes that can be set is fairly large, so only the most common are covered below: width=xx height=xx keepaspectratio

scale=xx angle=xx trim=l b r t

clip page=x resolution=x

Specify the preferred width NB. Only specifying either of the imported image to xx. width or height will scale the Specify the preferred height image while maintaining the of the imported image to xx. aspect ratio. This can be set to either true or false. When true, it will scale the image according to both height and width, but will not distort the image, so that neither width nor height are exceeded. Scales the image by the desired scale factor. e.g, 0.5 to reduce by half, or 2 to double. This option can rotate the image by xx degrees (counterclockwise) This option will crop the imported image by l from the left, b from the bottom, r from the right, and t from the top. Where l, b, r and t are lengths. For the trim option to work, you must set clip=true. If the image ﬁle is a pdf ﬁle with multiple pages, this parameter allows you to use a diﬀerent page than the ﬁrst. Specify image resolution in dpi

In order to use more than one option at a time, simply separate each with a comma. The order you give the options matters. E.g you should ﬁrst rotate your graphic (with angle) and then specify its width. Included graphics will be inserted just there, where you placed the code, and the compiler will handle them as ”big boxes”. As we will see in the ﬂoats section9 , this can disrupt the layout; you’ll probably want to place graphics inside ﬂoating objects. 9

214

Chapter 18 on page 231

Including graphics Also note that the trim option does not work with XeLaTex. Be careful using any options, if you are working with the chemnum-package. The labels deﬁned by \cmpdref{