0% found this document useful (0 votes)
324 views216 pages

LaTeX Wikibook

Uploaded by

Josh Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
324 views216 pages

LaTeX Wikibook

Uploaded by

Josh Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 216

LaTeX Wikibook

Contents

1 Getting Started 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 What is TeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.2 What is LaTeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.3 Philosophy of use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.4 Terms regarding TeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.5 What next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.1 Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.2 Custom installation with TeX Live . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.3 Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.4 Bibliography management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.5 Viewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.6 Tables and graphics tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.7 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 Installing Extra Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3.1 Automatic installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3.2 Manual installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3.3 Checking package status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.4 Package documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.5 External resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.6 See Also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.4 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.4.1 The LaTeX syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.4.2 Our first document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.3 Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.4 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.4.5 And what now? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2 Common Elements 16
2.1 Document Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.1.1 Global structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.1.2 Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

i
ii CONTENTS

2.1.3 The document environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17


2.1.4 Book structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.1.5 Special pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.1.6 Notes and references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.2 Text Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.2.1 Spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.2.2 Hyphenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.2.3 Quote-marks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.2.4 Diacritics and accents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2.5 Margin misalignment and interword spacing . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2.6 Ligatures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2.7 Slash marks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2.8 Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2.9 Formatting macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2.10 Text mode superscript and subscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2.11 Text figures (“old style” numerals) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2.12 Dashes and hyphens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2.13 Ellipsis (…) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2.14 Ready-made strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.2.15 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.3 Paragraph Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.3.1 Paragraph alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.3.2 Paragraph indent and break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.3.3 \paragraph line break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.3.4 Line spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.3.5 Manual breaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.3.6 Special paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.3.7 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.4 Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.4.1 Adding the color package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.4.2 Entering colored text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.4.3 Entering colored background for the text . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.4.4 Predefined colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.4.5 Defining new colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.4.6 Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.5 Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.5.2 Font families . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
[2]
2.5.3 Available LaTeX Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.5.4 Emphasizing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.5.5 Font encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
CONTENTS iii

2.5.6 Font styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30


2.5.7 Local font selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.5.8 Arbitrary font size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.5.9 Finding fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.5.10 Using arbitrary system fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.5.11 PDF fonts and properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.5.12 Useful websites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.5.13 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.6 List Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.6.1 List structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.6.2 Nested lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.6.3 Customizing lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.6.4 Inline lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.6.5 Easylist package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.6.6 Notes and references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.7 Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.7.1 Input encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.7.2 Escaped codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.7.3 Less than < and greater than > . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.7.4 Euro € currency symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.7.5 Degree symbol for temperature and math . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.7.6 Other symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.7.7 In special environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.7.8 Unicode keyboard input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.7.9 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.7.10 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.8 Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.8.1 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.8.2 Babel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.8.3 Multilingual versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.8.4 Specific languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.8.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.9 Rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.9.1 The rotating package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.9.2 The rotfloat package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.10 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.10.1 The tabular environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.10.2 Row specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.10.3 Spanning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.10.4 Controlling table size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.10.5 Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
iv CONTENTS

2.10.6 Width and stretching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48


2.10.7 Table across several pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
2.10.8 Partial vertical lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.10.9 Vertically centered images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.10.10 Footnotes in tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.10.11 Professional tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.10.12 Sideways tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.10.13 Table with legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.10.14 The eqparbox package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.10.15 Floating with table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.10.16 Using spreadsheets and data analysis tools . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.10.17 Need more complicated features? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.10.18 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.11 Title Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.11.1 Standard Titles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.11.2 Custom Title Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.11.3 Packages for custom titles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
2.11.4 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
2.12 Page Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
2.12.1 Two-sided documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
2.12.2 Page dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
2.12.3 Page size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
2.12.4 Margins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
2.12.5 Page orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.12.6 Margins, page size and rotation of a specific page . . . . . . . . . . . . . . . . . . . . . . 56
2.12.7 Page styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.12.8 Page background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.12.9 Multi-column pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.12.10 Manual page formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.12.11 Widows and orphans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.12.12 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.12.13 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.13 Importing Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.13.1 Raster graphics vs. vector graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.13.2 The graphicx package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.13.3 Document Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.13.4 Supported image formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
2.13.5 Including graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
2.13.6 Graphics storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
2.13.7 Images as figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
2.13.8 Text wrapping around pictures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
CONTENTS v

2.13.9 Seamless text integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62


2.13.10 Including full PDF pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.13.11 Converting graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.13.12 Third-party graphics tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.13.13 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.14 Floats, Figures and Captions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.14.1 Floats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.14.2 Keeping floats in their place . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.14.3 Captions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.14.4 Lists of figures and tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2.14.5 Labels and cross-referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2.14.6 Wrapping text around figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2.14.7 Subfloats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.14.8 Wide figures in two column documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.14.9 Custom floats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.14.10 Labels in the figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.14.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.14.12 Notes and references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.15 Hyperlinks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.15.1 Hyperref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.15.2 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.15.3 Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.15.4 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
2.15.5 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
2.16 Labels and Cross-referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
2.16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
2.16.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
2.16.3 The varioref package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
2.16.4 The hyperref package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
2.16.5 The cleveref package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
2.16.6 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
2.16.7 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

3 Mechanics 77
3.1 Errors and Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.1.1 Error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.1.2 Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.1.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.1.4 Software that can check your .tex Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.2 Lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.2.1 Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.2.2 Box lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
vi CONTENTS

3.2.3 Length manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80


3.2.4 LaTeX default lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.2.5 Fixed-length spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.2.6 Rubber/Stretching lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.2.7 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.2.8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.2.9 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.3 Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.3.1 Counter manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.3.2 Counter access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.3.3 Counter style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.3.4 LaTeX default counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.3.5 Book with parts, sections, but no chapters . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.3.6 Custom enumerate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.3.7 Custom sectioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.4 Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.4.1 TeX character boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.4.2 makebox and mbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.4.3 framebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.4.4 framed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.4.5 raisebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.4.6 minipage and parbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.4.7 savebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.4.8 rotatebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.4.9 colorbox and fcolorbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.4.10 resizebox and scalebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.4.11 fancybox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.5 Rules and Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.5.1 Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.5.2 Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.5.3 Stretched rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

4 Technical Texts 85
4.1 Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.1 Mathematics environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.2 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.3 Greek letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.4 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.5 Powers and indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.6 Fractions and Binomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.7 Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
4.1.8 Sums and integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
CONTENTS vii

4.1.9 Brackets, braces and delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87


4.1.10 Matrices and arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.1.11 Adding text to equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.1.12 Formatting mathematics symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.1.13 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.1.14 Plus and minus signs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.1.15 Controlling horizontal spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.1.16 Manually Specifying Formula Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.1.17 Advanced Mathematics: AMS Math package . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.1.18 List of Mathematical Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.1.19 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.1.20 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.1.21 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.1.22 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.2 Advanced Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.2.1 Equation numbering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.2.2 Vertically aligning displayed mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.2.3 Indented Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.2.4 Page breaks in math environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.2.5 Boxed Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.2.6 Custom operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.2.7 Advanced formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.2.8 Text in aligned math display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.2.9 Changing font size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.2.10 Forcing \displaystyle for all math in a document . . . . . . . . . . . . . . . . . . . . . . . 94
4.2.11 Adjusting vertical whitespace around displayed math . . . . . . . . . . . . . . . . . . . . 94
4.2.12 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.3 Theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.3.1 Basic theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.3.2 Theorem counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.3.3 Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.3.4 Theorem styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.3.5 Conflicts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.3.6 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.3.7 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.4 Chemical Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.4.1 Basic Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.4.2 Skeletal Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.4.3 Rings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.4.4 Lewis Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.4.5 Ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
viii CONTENTS

4.4.6 Resonance Structures and Formal Charges . . . . . . . . . . . . . . . . . . . . . . . . . . 97


4.4.7 Chemical Reactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
4.4.8 Naming Chemical Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
4.4.9 Advanced Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
4.4.10 mhchem Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
4.4.11 XyMTeX package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.5 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.5.1 Typesetting using the algorithmic package . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.5.2 Typesetting using the algorithm2e package . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.5.3 Typesetting using the algorithmicx package . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.5.4 The algorithm environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
4.5.5 Typesetting using the program package . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
4.5.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
4.6 Source Code Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
4.6.1 Using the listings package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
4.6.2 The minted package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
4.6.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
4.7 Linguistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
4.7.1 Enumerated examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
4.7.2 Syntactic trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
4.7.3 Glosses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
4.7.4 IPA characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
4.7.5 Phonological rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
4.7.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
4.7.7 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

5 Special Pages 110


5.1 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
5.1.1 Using makeidx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
5.1.2 Abbreviation list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.1.3 Multiple indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.1.4 Adding index to table of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.1.5 International indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.2 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
5.2.1 Jump start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
5.2.2 Using glossaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
5.2.3 Defining glossary entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.2.4 Defining terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.2.5 Using defined terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.3 Displaying the Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
5.3.1 Building your document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
5.4 Example for use in windows with Texmaker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
CONTENTS ix

5.4.1 Compile glossary with xindy - In Windows with Texmaker . . . . . . . . . . . . . . . . . . 115


5.4.2 Document preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
5.4.3 Glossary definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
5.4.4 Include glossary definitions and print glossary . . . . . . . . . . . . . . . . . . . . . . . . 115
5.4.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
5.5 Bibliography Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
5.5.1 Embedded system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
5.5.2 Citations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
5.5.3 BibTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
5.5.4 Bibliography in the table of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
5.5.5 biblatex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
5.5.6 Multiple bibliographies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
5.5.7 Notes and references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
5.6 More Bibliographies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
5.6.1 The example data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
5.6.2 The limits of BibTeX styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
5.6.3 Natbib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
5.6.4 Citation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

6 Special Documents 130


6.1 Letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
6.1.1 The letter class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
6.1.2 Envelopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
6.1.3 Windowed envelopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
6.1.4 Reference: letter.cls commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
6.1.5 Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
6.2 Presentations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
6.2.1 The Beamer package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
6.2.2 The powerdot package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
6.2.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
6.2.4 Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
6.3 Teacher’s Corner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
6.3.1 Intro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
6.3.2 The exam class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
6.3.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
6.4 Curriculum Vitae . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
6.4.1 curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
6.4.2 europecv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
6.4.3 moderncv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
6.4.4 Multilingual support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
6.4.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
x CONTENTS

7 Creating Graphics 140


7.1 Introducing Procedural Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
7.1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
7.2 MetaPost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
7.3 Picture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
7.3.1 Basic commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
7.3.2 Line segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
7.3.3 Arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
7.3.4 Circles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
7.3.5 Text and formulae . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
7.3.6 \multiput and \linethickness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
7.3.7 Ovals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
7.3.8 Multiple use of predefined picture boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
7.3.9 Quadratic Bézier curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
7.3.10 Catenary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
7.3.11 Plotting graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
7.3.12 The picture environment and gnuplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
7.4 PGF/TikZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
7.4.1 Loading Package, Libraries - tikzpicture environment . . . . . . . . . . . . . . . . . . . . 143
7.4.2 Specifying Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
7.4.3 Syntax for Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
7.4.4 Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
7.4.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
7.5 PSTricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
7.5.1 The pspicture environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
7.5.2 Fundamental objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
7.5.3 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
7.5.4 Grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
7.5.5 Generic parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
7.5.6 Object location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
7.5.7 The PDFTricks extension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
7.6 Xy-pic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
7.7 Creating 3D graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

8 Programming 151
8.1 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
8.1.1 New commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
8.1.2 New environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
8.1.3 Declare commands within newenvironment . . . . . . . . . . . . . . . . . . . . . . . . . . 152
8.1.4 Extending the number of arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
8.1.5 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
8.1.6 Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
CONTENTS xi

8.1.7 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152


8.1.8 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
8.1.9 LaTeX Hooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
8.1.10 Command-line LaTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
8.1.11 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
8.2 Plain TeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
8.2.1 Vocabulary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
8.2.2 Catcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
8.2.3 Plain TeX macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
8.2.4 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
8.2.5 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
8.2.6 Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
8.2.7 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
8.2.8 Doing nothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
8.2.9 TeX characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
8.2.10 Verbatim lines and spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
8.2.11 Macros defining macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
8.2.12 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
8.3 Creating Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
8.3.1 makeatletter and makeatother . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
8.3.2 Creating your own package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
8.3.3 Creating your own class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
8.3.4 Hooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
8.4 Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
8.4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
8.4.2 Package configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
8.4.3 Header and footer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
8.4.4 Table of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
8.4.5 Sectioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
8.4.6 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

9 Miscellaneous 160
9.1 Modular Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
9.1.1 Project structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
9.1.2 Getting LaTeX to process multiple files . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
9.1.3 The file mystyle.sty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.1.4 The main document document.tex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.1.5 External Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.2 Collaborative Writing of LaTeX Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.2.1 Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.2.2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.2.3 Interchanging Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
xii CONTENTS

9.2.4 The Version Control System Subversion . . . . . . . . . . . . . . . . . . . . . . . . . . . 165


9.2.5 Hosting LaTeX files in Subversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
9.2.6 Subversion really makes the difference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
9.2.7 Managing collaborative bibliographies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
9.2.8 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
9.2.9 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
9.2.10 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
9.3 Export To Other Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
9.3.1 Tools installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
9.3.2 Preview mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
9.3.3 Convert to PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
9.3.4 Convert to PostScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
9.3.5 Convert to RTF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
9.3.6 Convert to HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
9.3.7 Convert to image formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
9.3.8 Convert to plain text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

10 Help and Recommendations 174


10.1 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.1.1 Margins are too wide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.1.2 Avoid excessive double line breaks in source code . . . . . . . . . . . . . . . . . . . . . . 174
10.1.3 Simplified special character input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.1.4 Writing the euro symbol directly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.1.5 LaTeX paragraph headings have title and content on the same line . . . . . . . . . . . . . . 174
10.1.6 Fonts are ugly/jagged/bitmaps or PDF search fails or Copy/paste from PDF is messy . . . . . 174
10.1.7 Manual formatting: use of line breaks and page breaks . . . . . . . . . . . . . . . . . . . . 174
10.1.8 Always finish commands with {} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
10.1.9 Avoid bold and underline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
10.1.10 The proper way to use figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
10.1.11 Text stops justifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
10.1.12 Rules of punctuation and spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
10.1.13 Compilation fails after a Babel language change . . . . . . . . . . . . . . . . . . . . . . . 175
10.1.14 Learning LaTeX quickly or correctly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
10.1.15 Non-breaking spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
10.1.16 Smart mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
10.1.17 Use vector graphics rather than raster images . . . . . . . . . . . . . . . . . . . . . . . . . 176
10.1.18 Stretching tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
10.1.19 Tables are easier than you think . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
10.1.20 Relieving cumbersome code (lists and long command names) . . . . . . . . . . . . . . . . 176
10.1.21 Reducing the size of your LaTeX installation . . . . . . . . . . . . . . . . . . . . . . . . . 176
10.2 Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
10.2.1 Always writing LaTeX in roman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
CONTENTS xiii

10.2.2 id est and exempli gratia (i.e. and e.g.) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177


10.2.3 Grouping Figure/Equation Numbering by Section . . . . . . . . . . . . . . . . . . . . . . 177
10.2.4 Generic header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
10.2.5 Graphics and Graph editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
10.2.6 Spell-checking and Word Counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
10.2.7 New even page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
10.2.8 Sidebar with information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
10.2.9 Hide auxiliary files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

11 Appendix 181
11.1 Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.1.1 Included books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.1.2 Wiki users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.2 Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.3 Package Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.4 Sample LaTeX documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.4.1 General examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.4.2 Semantics of Programming Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.1 A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.2 B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.3 C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.4 D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.5 E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.6 F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.5.7 G . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.5.8 H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.5.9 I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.5.10 L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.5.11 M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.5.12 P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.5.13 Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.5.14 R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.5.15 S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.5.16 T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.5.17 U . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.5.18 V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.5.19 W . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.5.20 X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6 Command Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.1 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.2 A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
xiv CONTENTS

11.6.3 B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.4 C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.5 D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.6 E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.7 F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.8 G . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.9 H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.10 I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.11 K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.12 L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.13 M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.14 N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.15 O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
11.6.16 P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
11.6.17 Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
11.6.18 R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
11.6.19 S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
11.6.20 T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
11.6.21 U . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
11.6.22 V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

12 Text and image sources, contributors, and licenses 190


12.1 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
12.2 Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
12.3 Content license . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Chapter 1

Getting Started

1.1 Introduction ages is called LaTeX.

1.1.1 What is TeX? 1.1.2 What is LaTeX?


LaTeX (pronounced either “Lah-tech” or “Lay-tech”) is
TeX is a low-level markup and programming language a macro package based on TeX created by Leslie Lam-
created by Donald Knuth to typeset documents attrac- port. Its purpose is to simplify TeX typesetting, espe-
tively and consistently. Knuth started writing the TeX cially for documents containing mathematical formulae.
typesetting engine in 1977 to explore the potential of Within the typesetting system, its name is formatted as
the digital printing equipment that was beginning to in- LaTeX.
filtrate the publishing industry at that time, especially in
the hope that he could reverse the trend of deteriorat- Many later authors have contributed extensions, called
ing typographical quality that he saw affecting his own packages or styles, to LaTeX. Some of these are bundled
books and articles. With the release of 8-bit character with most TeX/LaTeX software distributions; more can
support in 1989, TeX development has been essentially be found in the Comprehensive TeX Archive Network
frozen with only bug fixes released periodically. TeX is (CTAN).
a programming language in the sense that it supports the Since LaTeX comprises a group of TeX commands, La-
if-else construct: you can make calculations with it (that TeX document processing is essentially programming.
are performed while compiling the document), etc., but You create a text file in LaTeX markup, which LaTeX
you would find it very hard to do anything else but type- reads to produce the final document.
setting with it. The fine control TeX offers over docu-
ment structure and formatting makes it a powerful—and This approach has some disadvantages in comparison
formidable—tool. TeX is renowned for being extremely with a WYSIWYG (What You See Is What You Get) pro-
stable, for running on many different kinds of comput- gram such as Openoffice.org Writer or Microsoft Word.
ers, and for being virtually bug free. The version numbers In LaTeX:
of TeX are converging toward π , with a current version
number of 3.1415926. • You don't (usually) see the final version of the doc-
The name TeX is intended by its developer to be /'tɛx/, ument when editing it.
with the final consonant of loch or Bach. (Donald E.
• You generally need to know the necessary com-
Knuth, The TeXbook) The letters of the name are meant
mands for LaTeX markup.
to represent the capital Greek letters tau, epsilon, and chi,
as TeX is an abbreviation of τέχνη (ΤΕΧΝΗ – technē), • It can sometimes be difficult to obtain a certain look
Greek for both “art” and “craft”, which is also the root for the document.
word of technical. English speakers often pronounce it
/'tɛk/, like the first syllable of technical.
On the other hand, there are certain advantages to the La-
Programming in TeX generally progresses along a very TeX approach:
gradual learning curve, requiring a significant investment
of time to build custom macros for text formatting. Fortu- • Document sources can be read with any text edi-
nately, document preparation systems based on TeX, con- tor and understood, unlike the complex binary and
sisting of collections of pre-built macros, do exist. These XML formats used with WYSIWYG programs.
pre-built macros are time saving, and automate certain
repetitive tasks and help reduce user introduced errors; • You can concentrate purely on the structure and con-
however, this convenience comes at the cost of complete tents of the document, not get caught up with super-
design flexibility. One of the most popular macro pack- ficial layout issues.

1
2 CHAPTER 1. GETTING STARTED

• You don't need to manually adjust fonts, text sizes, Questions and documentation
line heights, or text flow for readability, as LaTeX
takes care of them automatically. Besides internet resources being plentiful, the best doc-
umentation source remains the official manual for every
• In LaTeX the document structure is visible to the specific package, and the reference documentation, i.e.,
user, and can be easily copied to another document. the TeXbook by D. Knuth and LaTeX: A document prepa-
In WYSIWYG applications it is often not obvious ration system by L. Lamport.
how a certain formatting was produced, and it might
be impossible to copy it directly for use in another Therefore before rushing on your favorite web search en-
document. gine, we really urge you to have a look at the package
documentation that causes troubles. This official docu-
• The layout, fonts, tables and so on are consistent mentation is most commonly installed along your TeX
throughout the document. distribution, or may be found on CTAN.
• Mathematical formulae can be easily typeset.
• Indexes, footnotes, citations and references are gen- 1.1.4 Terms regarding TeX
erated easily.
Document preparation systems
• Since the document source is plain text, tables, fig-
ures, equations, etc. can be generated programmat- LaTeX is a document preparation system based on TeX.
ically with any language. So the system is the combination of the language and the
macros.
• You are forced to structure your documents cor-
rectly. Distributions

The LaTeX document is a plain text file containing the TeX distributions are collections of packages and pro-
content of the document, with additional markup. When grams (compilers, fonts, and macro packages) that enable
the source file is processed by the macro package, it can you to typeset without having to manually fetch files and
produce documents in several formats. LaTeX natively configure things.
supports DVI and PDF, but by using other software you
can easily create PostScript, PNG, JPEG, etc. Engines

An engine is an executable that can turn your source code


1.1.3 Philosophy of use into a printable output format. The engine by itself only
handles the syntax, it also needs to load fonts and macros
Flexibility and modularity to fully understand the source code and generate output
properly. The engine will determine what kind of source
One of the most frustrating things beginners and even ad- code it can read, and what format it can output (usually
vanced users might encounter using LaTeX is the lack of DVI or PDF).
flexibility regarding the document design and layout. If All in all, distributions are an easy way to install what you
you want to design your document in a very specific way, need to use the engines and the systems you want. Dis-
you may have trouble accomplishing this. Keep in mind tributions usually target specific operating systems. You
that LaTeX does the formatting for you, and mostly the can use different systems on different engines, but some-
right way. If it is not exactly what you desired, then the times there are restrictions. Code written for TeX, La-
LaTeX way is at least not worse, if not better. One way to TeX or ConTeXt are (mostly) not compatible. Addition-
look at it is that LaTeX is a bundle of macros for TeX that ally, engine-specific code (like font for XeTeX) may not
aims to carry out everything regarding document format- be compiled by every engine.
ting, so that the writer only needs to care about content.
If you really want flexibility, use plain TeX instead. When searching for information on LaTeX, you might
also stumble upon XeTeX, ConTeXt, LuaTeX or other
One solution to this dilemma is to make use of the mod- names with a -TeX suffix. Let’s recap most of the terms
ular possibilities of LaTeX. You can build your own in this table.
macros, or use macros developed by others. You are
likely not the first person to face some particular format-
ting problem, and someone who encountered a similar 1.1.5 What next?
problem before may have published their solution as a
package. In the next chapter we will proceed to the installation.
CTAN is a good place to find many resources regarding Then we will compile our first LaTeX file.
TeX and derivative packages. It is the first place where Throughout this book you should also utilise other means
you should begin searching. for learning about LaTeX. Good sources are:
1.2. INSTALLATION 3

• the #latex IRC channel on Freenode, • MiKTeX is a Windows-specific distribution.

• the TeX Stack Exchange Q&A, • MacTeX is a Mac OS-specific distribution based on
TeX Live.
• the TeX FAQ,

• and the TeXample.net Community. 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
1.2 Installation preparing TeX and LaTeX files.

If this is the first time you are trying out LaTeX, you don't
even need to install anything. For quick testing purpose *BSD and GNU/Linux
you may just create a user account with an online La-
TeX editor and continue this tutorial in the next chap- In the past, the most common distribution used to be
ter. These websites offer collaboration capabilities while teTeX. As of May 2006 teTeX is no longer actively main-
allowing you to experiment with LaTeX syntax without tained and its former maintainer Thomas Esser recom-
having to bother with installing and configuring a distri- mended TeX Live as the replacement.[1]
bution and an editor. When you later feel that you would The easy way to get TeX Live is to use the package man-
benefit from having a standalone LaTeX installation, you ager or portage tree coming with your operating system.
can return to this chapter and follow the instructions be- Usually it comes as several packages, with some of them
low. being essential, other optional. The core TeX Live pack-
LaTeX is not a program by itself; it is a language. Using ages should be around 200-300 MB.
LaTeX requires a bunch of tools. Acquiring them man- If your *BSD or GNU/Linux distribution does not have
ually would result in downloading and installing multiple the TeX Live packages, you should report a wish to
programs in order to have a suitable computer system that the bug tracking system. In that case you will need to
can be used to create LaTeX output, such as PDFs. TeX download TeX Live yourself and run the installer by hand.
Distributions help the user in this way, in that it is a sin-
gle step installation process that provides (almost) every- You may wish to install the content of TeX Live more
thing. selectively. See below.
At a minimum, you'll need a TeX distribution, a good
text editor and a DVI or PDF viewer. More specifically,
Mac OS X
the basic requirement is to have a TeX compiler (which is
used to generate output files from source), fonts, and the
LaTeX macro set. Optional, and recommended installa- Mac OS X users may use MacTeX, a TeX Live-based dis-
tions include an attractive editor to write LaTeX source tribution supporting TeX, LaTeX, AMSTeX, ConTeXt,
documents (this is probably where you will spend most of XeTeX and many other core packages. Download Mac-
your time), and a bibliographic management program to TeX.mpkg.zip on the MacTeX page, unzip it and follow
manage references if you use them a lot. the instructions. Further information for Mac OS X users
can be found on the TeX on Mac OS X Wiki.
Since Mac OS X is also a Unix-based system, TeX
1.2.1 Distributions Live is naturally available through MacPorts and Fink.
Homebrew users should use the official MacTeX installer
TeX and LaTeX are available for most computer plat- because of the unique directory structure used by TeX
forms, since they were programmed to be very portable. Live. Further information for Mac OS X users can be
They are most commonly installed using a distribution, found on the TeX on Mac OS X Wiki.
such as teTeX, MiKTeX, or MacTeX. TeX distribu-
tions are collections of packages and programs (compil-
ers, fonts, and macro packages) that enable you to type- Microsoft Windows
set without having to manually fetch files and configure
things. LaTeX is just a set of macro packages built for Microsoft Windows users can install MiKTeX onto their
TeX. computer. It has an easy installer that takes care of setting
The recommended distributions for each of the major op- up the environment and downloading core packages. This
erating systems are: distribution has advanced features, such as automatic in-
stallation of packages, and simple interfaces to modify
• TeX Live is a major TeX distribution for *BSD, settings, such as default paper sizes.
GNU/Linux, Mac OS X and Windows. There is also a port of TeX Live available for Windows.
4 CHAPTER 1. GETTING STARTED

1.2.2 Custom installation with TeX Live 1. Launch install-tl.


2. Select the minimal scheme (plain only).
This section targets users who want fine-grained control
over their TeX distribution, like an installation with a 3. You may want to change the directory options. For
minimum of disk space usage. If it is none of your con- example you may want to hide your personal macro
cern, you may want to jump to the next section. folder which is located at TEXMFHOME. It is
Picky users may wish to have more control over their in- ~/texmf by default. Replace it by ~/.texmf to hide
stallation. Common distributions might be tedious for the it.
user caring about disk space. In fact, MikTeX and Mac- 4. Now the options:
TeX and packaged TeX Live features hundreds of LaTeX
packages, most of them which you will never use. Most (a) use letter size instead of A4 by default:
Unix with a package manager will offer TeX Live as a mostly for users from the USA.
set of several big packages, and you often have to install (b) execution of restricted list of programs: it
300–400 MB for a functional system. is recommended to select it for security rea-
sons. Otherwise it allows the TeX engines to
TeX Live features a manual installation with a lot of pos-
call any external program. You may still con-
sible customizations. You can get the network installer at
figure the list afterwards.
tug.org. This installer allows you to select precisely the
packages you want to install. As a result, you may have (c) create format files: targetting a minimal disk
everything you need for less than 100 MB. TeX Live is space, the best choice depends on whether
then managed through its own package manager, tlmgr. It there is only one user on the system, then de-
will let you configure the distributions, install or remove selecting it is better, otherwise select it. From
extra packages and so on. the help menu: “If this option is set, format
files are created for system-wide use by the in-
You will need a Unix-based operating system for the fol- staller. Otherwise they will be created auto-
lowing. Mac OS X, GNU/Linux or *BSD are fine. It may matically when needed. In the latter case for-
work for Windows but the process must be quite differ- mat files are stored in user’s directory trees and
ent. in some cases have to be re-created when new
TeX Live groups features and packages into different packages are installed.”
concepts: (d) install font/macro doc tree: useful if you are
a developer, but very space consuming. Turn
• Collections are groups of packages that can always be it off if you want to save space.
installed individually, except for the Essential pro- (e) install font/macro source tree: same as
grams and files collection. You can install collec- above.
tions at any time. (f) Symlinks are fine by default, change it if you
know what you are doing.
• Installation Schemes group collections and packages.
Schemes can only be used at installation time. You 5. Select portable installation if you install the distribu-
can select only one scheme at a time. tion to an optical disc, or any kind of external media.
Leave to default for a traditional installation on the
system hard drive.
Minimal installation
At this point it should display
We will give you general guidelines to install a minimal
1 collections out of 85, disk space required: 40 MB
TeX distribution (i.e., only for plain TeX).
or a similar space usage.
1. Download the installer at http://mirror.ctan.org/ You can now proceed to installation: start installation to
systems/texlive/tlnet/install-tl-unx.tar.gz and ex- hard disk.
tract it to a temporary folder. Don't forget to add the binaries to your PATH as it’s no-
2. Open a terminal in the extracted folder and log in as ticed at the end of the installation procedure.
root.
First test
3. Change the umask permissions to 022 (user
read/write/execute, group/others read/execute only)
In a terminal write
to make sure other users will have read-only access
to the installed distribution. $ tex '\empty Hello world!\bye' $ pdftex '\empty Hello
world!\bye'
# umask 022 You should get a DVI or a PDF file accordingly.
1.2. INSTALLATION 5

Configuration Uninstallation

Formerly, TeX distributions used to be configured with By default TeX Live will install in /usr/local/texlive. The
the texconfig tool from the teTeX distribution. TeX Live distribution is quite proper as it will not write any file out-
still features this tool, but recommends using its own tool side its folder, except for the cache (like font cache, hy-
instead: tlmgr. Note that as of January 2013 not all tex- phenation patters, etc.). By default,
config features are implemented by tlmgr. Only use tex-
config when you cannot do what you want with tlmgr. • the system cache goes in /var/lib/texmf;
List current installation options: • the user cache goes in ~/.texliveYYYY.
tlmgr option
Therefore TeX Live can be installed and uninstalled safely
You can change the install options: by removing the aforementioned folders.
tlmgr option src 1 tlmgr option doc 0 tlmgr option paper Still, TeX Live provides a more convenient way to do this:
letter
# tlmgr uninstall
See the TLMGR(1) man page for more details on its us-
You may still have to wipe out the folders if you put un-
age. If you did not install the documents as told previ-
tracked files in them.
ously, you can still access the tlmgr man page with
tlmgr help
1.2.3 Editors
Installing LaTeX TeX and LaTeX source documents (as well as related
files) are all text files, and can be opened and modified
Now we have a running plain TeX environment, let’s in- in almost any text editor. You should use a text editor
stall the base packages for LaTeX. (e.g. Notepad), not a word processor (Word, OpenOf-
# tlmgr install latex latex-bin latexconfig latex-fonts fice). Dedicated LaTeX editors are more useful than
generic plain text editors, because they usually have au-
In this case you can omit latexconfig latex-fonts as they tocompletion of commands, spell and error checking and
are auto-resolved dependencies to LaTeX. Note that handy macros.
tlmgr resolves some dependencies, but not all. You may
need to install dependencies manually. Thankfully this is
rarely too cumbersome. Cross-platform
Other interesting packages:
BaKoMa TeX BaKoMa TeX is an editor for Windows
# tlmgr install amsmath babel carlisle ec geometry graph- and Mac OS with WYSIWYG-like features. It takes care
ics hyperref lm marvosym oberdiek parskip pdftex-def of compiling the LaTeX source and updating it constantly
url to view changes to document almost in real time. You can
If you installed a package you do not need anymore, use take an evaluation copy for 28 days.
# tlmgr remove <package>
Emacs Emacs is a general purpose, extensible text pro-
cessing system. Advanced users can program it (in elisp)
Hyphenation to make Emacs the best LaTeX environment that will fit
their needs. In turn beginners may prefer using it in com-
If you are using Babel for non-English documents, you bination with AUCTeX and Reftex (extensions that may
need to install the hyphenation patterns for every language be installed into the Emacs program). Depending on your
you are going to use. They are all packaged individually. configuration, Emacs can provide a complete LaTeX edit-
For instance, use ing environment with auto-completion, spell-checking,
# tlmgr install hyphen-{finnish,sanskrit} a complete set of keyboard shortcuts, table of contents
view, document preview and many other features.
for finnish and sanskrit hyphenation patterns.
Note that if you have been using another TeX distribution
gedit-latex-plugin Gedit with gedit-latex-plugin is
beforehand, you may still have hyphenation cache stored
also worth trying out for users of GNOME. GEdit is a
in you home folder. You need to remove it so that the new
cross-platform application for Windows, Mac, and Linux
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 Gummi Gummi is a LaTeX editor for Linux, which
as it contains only generated data. TeX compilers will compiles the output of pdflatex in realtime and shows it
re-generate the cache accordingly on next compilation. on the right half of the screen[2] .
6 CHAPTER 1. GETTING STARTED

Screenshot of Gummi. Screenshot of TeXworks on Ubuntu 12.10.

with the idea that a simple interface is better than a clut-


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

Vim Vim 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
Box and Vim-LaTeX.
LyX1.6.3

LyX LyX is a popular document preparation system *BSD and GNU/Linux-only


for Windows, Linux and Mac OS. It provides a graphi-
cal interface to LaTeX, including several popular pack-
ages. It contains formula and table editors and shows vi-
sual clues of the final 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.[3]
LyX saves its documents in their own markup, and gen-
erates LaTeX code based on this. The user is mostly iso-
lated from the LaTeX code and not in complete control of
it, and as such LyX is not a normal LaTeX editor. How-
ever, 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.
Screenshot of Kile.
TeXmaker TeXmaker is a cross-platform editor very
Kile Kile is a LaTeX editor for KDE (cross platform),
similar to Kile in features and user interface. In addition
providing a powerful GUI for editing multiple documents
it has its own PDF viewer.
and compiling them with many different TeX compilers.
Kile is based on Kate editor, has a quick access toolbar for
TeXstudio TeXstudio is a cross-platform open source symbols, document structure viewer, a console and cus-
LaTeX editor forked from Texmaker. tomizable build options. Kile can be run in all operating
systems that can run KDE.

TeXworks TeXworks is a dedicated TeX editor that


is included in MiKTeX and TeX Live. It was developed LaTeXila LaTeXila is another text editor for Linux
1.2. INSTALLATION 7

(Gnome). • Authorea is an integrated online framework for the


creation of technical documents in collaboration.
Authorea’s frontend allows you to enter text in La-
Mac OS X-only
TeX or Markdown, as well as figures, and equations
(in LaTeX or MathML). Authorea’s versioning con-
TeXShop TeXShop is a TeXworks-like editor and pre-
trol system is entirely based on Git (every article is
viewer for Mac OS that is bundled with the MacTeX dis-
a Git repository).
tribution. It uses multiple windows, one for editing the
source, one for the preview, and one as a console for er-
• Google Documents or LaTeX Lab allows real-time
ror messages. It offers one-click updating of the preview
simultaneous collaborative editing of text files for
and allows easy crossfinding between the code and the
anyone with a Google account (and its option to
preview by using CMD-click.
make the document available through a URL makes
local download and compilation easily scriptable).
TeXnicle TeXnicle is a free editor for Mac OS that in-
cludes the ability to perform live updates. It includes a • LIMSUP is an online LaTeX editor allowing
code library for the swift insertion of code and the abil- real time collaboration of LaTeX documents
ity to execute detailed word counts on documents. It also (announcement)
performs code highlighting and the editing window is cus-
tomisable, permitting the user to select the font, colour, • Monkey TeX is free and allows team sharing.
background colour of the editing environment. It is in
active development. • Overleaf is a secure, easy to use online LaTeX ed-
itor with integrated rapid preview - like EtherPad
for LaTeX. Start writing with one click (no signup
Archimedes Archimedes is an easy-to-use LaTeX and
required) and share the link. It supports real time
Markdown editor designed from the ground up for Mac
preview, figures, bibliographies and custom styles.
OS X. It includes a built-in LaTeX library, code com-
pletion support, live previews, macro support, integra-
• publications.li is a real-time collaborative LaTeX
tion with sharing services, and PDF and HTML export
editor running the open-source editor \BlueLatex.
options. Archimedes’s Magic Type feature lets users in-
sert mathematical symbols just by drawing them on their
MacBook’s trackpad or Magic Trackpad. • ScribTeX.com is one of the most mature systems
available, with git push and pull access it allows for
powerful version control. The new sign ups are now
Windows-only directed to use ShareLatex.com however accounts
are still available upon request.
LEd LEd
• ShareLaTeX.com is a secure cloud-based LaTeX
editor offering unlimited free project. Premium ac-
TeXnicCenter TeXnicCenter is a popular free and
counts are available for extra features such as version
open source LaTeX editor for Windows. It also has a
control and Dropbox integration.
similar user interface to TeXmaker and Kile.
• SimpleLaTeX is an online editor and previewer for
WinEdt WinEdt is a powerful and versatile text ed- short LaTeX notes, which can be optionally cached
itor with strong predisposition towards creation of La- or shared. Previews are available in SVG, PNG, and
TeX/TeX documents for Windows. It has been designed PDF. It also includes a simple GUI for editing tables.
and configured to integrate with TeX Systems such as Mi-
TeX or TeX Live. Its built-in macro helps in compiling • SpanDeX is a cloud-based LaTeX collaboration
the LaTeX source to the WYSIWYG-like DVI or PDF or platform designed to make collaborating with La-
PS and also in exporting the document to other mark-up TeX seamless and to reduce the learning curve to
languages as HTML or XML. LaTeX. It offers simultaneous real-time editing and
collaboration, live document preview, Dropbox in-
tegration, and a built-in LaTeX resource system.
WinShell WinShell
• Verbosus is a professional Online LaTeX Editor that
Online solutions supports collaboration with other users and is free to
use. Merge conflicts can easily resolved by using a
To get started without needing to install anything, you can built-in merge tool that uses an implementation of
use a web-hosted service featuring a full TeX distribution the diff-algorithm to generate information required
and a web LaTeX editor. for a successful merge.
8 CHAPTER 1. GETTING STARTED

1.2.4 Bibliography management (Device independent file format), but you will rarely want
it to. DVI files do not contain embedded fonts and many
Bibliography files (*.bib) are most easily edited and mod- document viewers are unable to open them.
ified using a management system. These graphical user
Usually you will use a LaTeX compiler like pdflatex to
interfaces all feature a database form, where information
produce a PDF file directly, or a tool like dvi2pdf to con-
is entered for each reference item, and the resulting text
vert the DVI file to PDF format. Then you can view the
file can be used directly by BibTeX.
result with any PDF viewer.
Practically all LaTeX distributions have a DVI viewer for
Cross-platform 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.

• PDF.js (built-in modern browsers)

• Evince (Linux GNOME)

• Foxit (Windows)

• Okular (Linux KDE)

• Preview (built-in Mac OS X)

• Skim (Mac OS X)
Screenshot of JabRef. • Sumatra PDF (Windows)

• JabRef • Xpdf (Linux)

• Mendeley • Zathura (Linux)

Mac OS X-only
1.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
flexible manner, it will not handle the handy features you
could get with a spreadsheet like dynamic cells and calcu-
lus. 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 Tables for more details.
The graphics topic is a bit different since it is possible
Screenshot of BibDesk to write procedural graphics from within your LaTeX
document. Procedural graphics produce state-of-the-art
results that integrates perfectly to LaTeX (e.g. no font
• BibDesk is a bibliography manager based on a Bib- change), but have a steep learning curve and require a lot
TeX file. It imports references from the internet and of time to draw.
makes it easy to organize references using tags and
categories[4] . For easier and quicker drawings, you may want to use a
WYSIWYG tool and export the result to a vector for-
mat like PDF. The drawback is that it will contrast in
1.2.5 Viewers style with the rest of your document (font, size, etc.).
Some tools have the capability to export to LaTeX, which
Finally, you will need a viewer for the files LaTeX out- will partially solve this issue. See Importing Graphics for
puts. Normally LaTeX saves the final document as a .dvi more details.
1.3. INSTALLING EXTRA PACKAGES 9

1.2.7 References nient feature, upon the compilation of a file requiring non-
installed packages, MikTeX will automatically prompt to
[1] teTeX Home Page (Retrieved January 31, 2007) install the missing ones.
[2] Gummi With TeX Live, it is common to have the distribution
packed into a few big packages. For example, to install
[3] LyX something related to internationalization, you might have
[4] BibDesk
to install a package like texlive-lang. With TeX Live man-
ually installed, use tlmgr to manage packages individu-
ally.

1.3 Installing Extra Packages tlmgr install <package1> <package2> ... tlmgr remove
<package1> <package2> ...
Add-on features for LaTeX are known as packages. The use of tlmgr is covered in the Installation chapter.
Dozens of these are pre-installed with LaTeX and can If you cannot find the wanted package with any of the
be used in your documents immediately. They should previous methods, see the manual installation.
all be stored in subdirectories of texmf/tex/latex named
after each package. The directory name “texmf” stands
for “TEX and METAFONT”. To find out what other 1.3.2 Manual installation
packages are available and what they do, you should use
the CTAN search page which includes a link to Graham Downloading packages
Williams’ comprehensive package catalogue.
What you need to look for is usually two files, one ending
A package is a file or collection of files containing ex-
in .dtx and the other in .ins. The first is a DOCTeX file,
tra LaTeX commands and programming which add new
which combines the package program and its documenta-
styling features or modify those already existing. There
tion in a single file. The second is the installation routine
are two main file types: class files with .cls extension, and
(much smaller). You must always download both files. If
style files with .sty extension. There may be ancillary files
the two files are not there, it means one of two things:
as well. When you try to typeset a document which re-
quires a package which is not installed on your system,
LaTeX will warn you with an error message that it is miss- • Either the package is part of a much larger bun-
ing. You can download updates to packages you already dle which you shouldn't normally update unless you
have (both the ones that were installed along with your change LaTeXversion of LaTeX;
version of LaTeX as well as ones you added). There is no • or it’s an older or relatively simple package written
limit to the number of packages you can have installed by an author who did not use a .dtx file.
on your computer (apart from disk space!), but there is a
configurable limit to the number that can be used inside Download the package files to a temporary directory.
any one LaTeX document at the same time, although it There will often be a readme.txt with a brief description
depends on how big each package is. In practice there is of the package. You should of course read this file first.
no problem in having even a couple of dozen packages
active.
Installing a package
Most LaTeX installations come with a large set of pre-
installed style packages, so you can use the package man-
There are five steps to installing a LaTeX package.
ager of the TeX distribution or the one on your system to
(These steps can also be used on the pieces of a com-
manage them. See the automatic installation. But many
plicated package you wrote yourself; in this case, skip
more are available on the net. The main place to look for
straight to Step 3.)
style packages on the Internet is CTAN. Once you have
identified a package you need that is not in your distri- 1. Extract the files Run LaTeX on the .ins file. That
bution, use the indexes on any CTAN server to find the is, open the file in your editor and process it as if it were
package you need and the directory where it can be down- a LaTeX document (which it is), or if you prefer, type
loaded from. See the manual installation. latex followed by the .ins filename in a command window
in your temporary directory. This will extract all the files
needed from the .dtx file (which is why you must have
1.3.1 Automatic installation both of them present in the temporary directory). Note
down or print the names of the files created if there are
If on an operating system with a package manager or a a lot of them (read the log file if you want to see their
portage tree, you can often find packages in repositories. names again).
With MikTeX there is a package manager that allows you 2. Create the documentation Run LaTeX on the .dtx
to pick the package you want individually. As a conve- file. You might need to run it twice or more, to get the
10 CHAPTER 1. GETTING STARTED

cross-references right (just like any other LaTeX docu- comes with every modern version of TeX and has vari-
ment). This will create a .dvi file of documentation ex- ous names depending on the LaTeX distribution you use.
plaining what the package is for and how to use it. If you (Read the documentation that came with your installa-
prefer to create PDF then run pdfLaTeX instead. If you tion to find out which it is, or consult http://www.tug.org/
created a .idx as well, it means that the document contains fonts/fontinstall.html#fndb):
an index, too. If you want the index to be created prop-
erly, follow the steps in the indexing section. Sometimes • teTeX, TeX Live, fpTeX: texhash
you will see that a .glo (glossary) file has been produced.
• web2c: mktexlsr
Run the following command instead:
• MacTeX: MacTeX appears to do this for
makeindex -s gglo.ist -o name.gls name.glo you.
3. Install the files While the documentation is printing, • MikTeX: initexmf --update-fndb (or use
move or copy the package files from your temporary di- the GUI)
rectory to the right place[s] in your TeX local installa-
• MiKTeX 2.7 or later versions, installed
tion directory tree. Packages installed by hand should al-
on Windows XP through Windows 7:
ways be placed in your “local” directory tree, not in the
Start -> All Programs -> MikTex -> Set-
directory tree containing all the pre-installed packages.
tings. In Windows 8 use the keyword
This is done to a) prevent your new package acciden-
Settings and choose the option of Settings
tally overwriting files in the main TeX directories; and b)
with the MiKTex logo. In Settings menu
avoid your newly-installed files being overwritten when
choose the first tab and click on Refresh
you next update your version of TeX.
FNDB-button (MikTex will then check
For a TDS(TeX Directory Structure)-conformant system, the Program Files directory and update
your “local installation directory tree” is a folder and the list of File Name DataBase). After
its subfolders. The outermost folder should probably be that just verify by clicking 'OK'.
called texmf-local/ or texmf/. Its location depends on
your system: 5. Update font maps If your package installed any True-
Type or Type 1 fonts, you need to update the font map-
• MacTeX: ping files in addition to updating the index. Your pack-
Users/username/Library/texmf/. age author should have included a .map file for the fonts.
• Unix-type systems: Usually ~/texmf/. The map updating program is usually some variant on up-
dmap, depending on your distribution:
• MikTeX: Your local directory tree can be
any folder you like, as long as you then
• TeX Live and MacTeX: updmap --enable
register it as a user-managed texmf direc-
Map=mapfile.map (if you installed the
tory (see http://docs.miktex.org/manual/
files in a personal tree) or updmap-sys
localadditions.html#id573803)
--enable Map=mapfile.map (if you in-
stalled the files in a system directory).
The “right place” sometimes causes confusion, espe-
cially if your TeX installation is old or does not con- • MikTeX: Run initexmf --edit-config-file
form to the TeX Directory Structure(TDS). For a TDS- updmap, add the line “Map mapfile.map
conformant system, the “right place” for a LaTeX .sty to the file that opens, then run initexmf
file is a suitably-named subdirectory of texmf/tex/latex/. --mkmaps.
“Suitably-named” means sensible and meaningful (and
probably short). For a package like paralist, for exam- See http://www.tug.org/fonts/fontinstall.html.
ple, I'd call the directory texmf/tex/latex/paralist. The reason this process has not been automated widely
is that there are still thousands of installations which do
Often there is just a .sty file to move, but in the case of
complex packages there may be more, and they may be- not conform to the TDS, such as old shared Unix systems
long in different locations. For example, new BibTeX and some Microsoft Windows systems, so there is no way
for an installation program to guess where to put the files:
packages or font packages will typically have several files
you have to know this. There are also systems where the
to install. This is why it is a good idea to create a sub-
owner, user, or installer has chosen not to follow the rec-
directory for the package rather than dump the files into
ommended TDS directory structure, or is unable to do
misc along with other unrelated stuff. If there are config-
so for political or security reasons (such as a shared sys-
uration or other files, read the documentation to find out
tem where the user cannot write to a protected directory).
if there is a special or preferred location to move them to.
The reason for having the texmf-local directory (called
For most fonts on CTAN, the foundry is public. texmf.local on some systems) is to provide a place for lo-
4. Update your index Finally, run your TeX indexer cal modifications or personal updates, especially if you
program to update the package database. This program are a user on a shared or managed system (Unix, Linux,
1.4. BASICS 11

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- 1.3.5 External resources
figured to look in these directories first, however, so that
any updates to standard packages will be found there be- The best way to look for LaTeX packages is the already
fore the superseded copies in the main texmf tree. All mentioned CTAN: Search. Additional resources form
modern TeX installations should do this anyway, but if The TeX Catalogue Online:
not, you can edit texmf/web2c/texmf.cnf yourself.
• Alphabetic catalogue

1.3.3 Checking package status • With brief descriptions

• Topical catalogue with packages sorted systemati-


The universal way to check if a file is available to TeX cally
compilers is the command-line tool kpsewhich.
• Hierarchical mirroring the CTAN folder hierarchy
$ kpsewhich tikz /usr/local/texlive/2012/texmf-
dist/tex/plain/pgf/frontendlayer/tikz.tex
kpsewhich will actually search for files only, not for pack- 1.3.6 See Also
ages. It returns the path to the file. For more details on a
specific package use the command-line tool tlmgr (TeX • LaTeX/Package Reference
Live only):
tlmgr info <package>
1.4 Basics
The tlmgr tool has lot more options. To consult the doc-
umentation:
This tutorial is aimed at getting familiar with the bare
tlmgr help bones of LaTeX.
Before starting, ensure you have LaTeX installed on your
computer (see Installation for instructions of what you
1.3.4 Package documentation will need).
To find out what commands a package provides (and thus
how to use it), you need to read the documentation. In the • We will first have a look at the LaTeX syntax.
texmf/doc subdirectory of your installation there should • We will create our first LaTeX document.
be directories full of .dvi files, one for every package in-
stalled. This location is distribution-specific, but is typi- • Then we will take you through how to feed this file
cally found in: through the LaTeX system to produce quality out-
put, such as postscript or PDF.
Generally, most of the packages are in the latex subdi-
rectory, although other packages (such as BibTeX and • Finally we will have a look at the file names and
font packages) are found in other subdirectories in doc. types.
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, 1.4.1 The LaTeX syntax
txt, pdf, etc.). The documents generally have the same
name as the package, but there are exceptions (for ex- LaTeX uses a markup language in order to describe doc-
ample, the documentation for amsmath is found at la- ument structure and presentation. LaTeX converts your
tex/amsmath/amsdoc.dvi). If your installation procedure source text, combined with the markup, into a high qual-
has not installed the documentation, the DVI files can ity document. For the purpose of analogy, web pages
all be downloaded from CTAN. Before using a package, work in a similar way: the HTML is used to describe the
you should read the documentation carefully, especially document, but it is your browser that presents it in its full
the subsection usually called “User Interface”, which de- glory - with different colours, fonts, sizes, etc.
scribes the commands the package makes available. You The input for LaTeX is a plain text file. You can create it
cannot just guess and hope it will work: you have to readwith any text editor. It contains the text of the document,
it and find out. as well as the commands that tell LaTeX how to typeset
You can usually automatically open any installed package the text.
documentation with the texdoc command: A minimal example looks something like the following
texdoc <package-name> (the commands will be explained later):
12 CHAPTER 1. GETTING STARTED

Spaces \begingroup and \endgroup commands are equivalent to


opening brace and closing brace.
The LaTeX compiler normalises whitespace so that Example:
whitespace characters, such as [space] or [tab], are
treated uniformly as “space": several consecutive For some commands it is important to restrict their range
“spaces” are treated as one, “space” opening a line is gen- of action, and that’s where groups come to be very useful.
erally ignored, and a single line break also yields “space”.
A double line break (an empty line), however, defines the
LaTeX environments
end of a paragraph; multiple empty lines are also treated
as the end of a paragraph. An example of applying these
Environments in LaTeX have a role that is quite similar
rules is presented below: the left-hand side shows the
to commands, but they usually have effect on a wider part
user’s input (.tex), while the right-hand side depicts the
of the document. Their syntax is:
rendered output (.dvi/.pdf/.ps).
Between the \begin and the \end you can put other com-
mands and nested environments. The internal mechanism
Reserved Characters of environments defines a group, which makes its usage
safe (no influence on the other parts of the document).
The following symbols are reserved characters that either In general, environments can accept arguments as well,
have a special meaning under LaTeX or are unavailable but this feature is not commonly used and so it will be
in all the fonts. If you enter them directly in your text, discussed in more advanced parts of the document.
they will normally not print but rather make LaTeX do
things you did not intend. Anything in LaTeX can be expressed in terms of com-
mands and environments.
#$%^&_{}~\
As you will see, these characters can be used in your doc-
LaTeX commands
uments all the same by adding a prefix backslash:
The backslash character \ cannot be entered by adding LaTeX commands are case sensitive, and take one of the
another backslash in front of it (\\); this sequence is used following two formats:
for line breaking. For introducing a backslash in math
mode, you can use \backslash instead. • They start with a backslash \ and then have a name
The commands \~ and \^ produce respectively a tilde and consisting of letters only. Command names are ter-
a hat which is placed over the next letter. For example minated by a space, a number or any other “non-
\~n gives ñ. That’s why you need braces to specify there letter”.
is no letter as argument. You can also use \textasciitilde
and \textasciicircum to enter these characters; or other • They consist of a backslash \ and exactly one non-
commands . letter.

If you want to insert text that might contain several par-


ticular symbols (such as URIs), you can consider using Some commands need an argument, which has to be
the \verb command, which will be discussed later in the given between curly braces { } after the command name.
section on formatting. For source code, see Source Code Some commands support optional parameters, which are
Listings added after the command name in square brackets [ ].
The general syntax is:
The 'less than' (<) and 'greater than' (>) characters are the
only visible ASCII characters (not reserved) that will not Most standard LaTeX commands have a switch equiva-
print correctly. See Special Characters for an explanation lent. Switches have no arguments but apply on the rest of
and a workaround. the scope, i.e. the current group or environment. A switch
should (almost) never be called outside of any scope, oth-
Non-ASCII characters (e.g. accents, diacritics) can be erwise it will apply on the rest of the document.
typed in directly for most cases. However you must con-
figure the document appropriately. The other symbols Example:
and many more can be printed with special commands
in mathematical formulae or as accents. We will tackle Comments
this issue in Special Characters.
When LaTeX encounters a % character while processing
LaTeX groups an input file, it ignores the rest of the current line, the line
break, and all whitespace at the beginning of the next line.
A group is basically defined by a pair of braces. The range This can be used to write notes into the input file, which
of commands put between braces is limited to them. The will not show up in the printed version.
1.4. BASICS 13

Note that the % character can be used to split long input • latex executable calls tex with LaTeX initialization
lines that do not allow whitespace or line breaks, as with files, reads a LaTeX .tex file and creates a .dvi
Supercalifragilisticexpialidocious above.
• pdflatex executable calls pdftex with LaTeX initial-
The core LaTeX language does not have a predefined syn- ization files, reads a LaTeX .tex file and creates a
tax for commenting out regions spanning multiple lines. .pdf
Refer to multiline comments for simple workarounds.
If you compile a Plain TeX document with a LaTeX com-
piler (such as pdflatex) it will work while the opposite is
1.4.2 Our first document
not true: if you try to compile a LaTeX source with a TeX
compiler you will get many errors.
Now we can create our first document. We will produce
the absolute bare minimum that is needed in order to get As a matter of fact, following your operating system latex
some output; the well known Hello World! approach will and pdflatex are simple scripts or symbolic links.
be suitable here. Most of the programs should be already within your
LaTeX distribution; the others come with Ghostscript,
• Open your favorite text-editor. vim, emacs, which is a free and multi-platform software as well. Here
Notepad++, and other text editors will have syntax are common programs you expect to find in any LaTeX
highlighting that will help to write your files. distribution:

• Reproduce the following text in your editor. This is


• dvi2ps converts the .dvi file to .ps (postscript).
the LaTeX source.
• dvi2pdf converts the .dvi file to .pdf (dvi2pdfm is an
• Save your file as hello.tex. improved version).

When picking a name for your file, make sure it bears a and with Ghostscript:
.tex extension.
• ps2pdf and pdf2ps converts the .ps file to .pdf and
vice-versa.
What does it all mean?
When LaTeX was created, the only format it could cre-
As we have said before, each of the LaTeX commands be-
ate was DVI; later PDF support was added by pdflatex.
gins with a backslash (\). This is LaTeX’s way of knowing
PDF files can be created with both pdflatex and dvipdfm.
that whenever it sees a backslash, to expect some com-
The output of pdflatex takes direct advantage of modern
mands. Comments are not classed as a command, since
features of PDF such as hyperlinks and embedded fonts,
all they tell LaTeX is to ignore the line. Comments never
which are not part of DVI. Passing through DVI imposes
affect the output of the document.
limitations of its older format. On the other hand, some
packages, such as PSTricks, exploit the process of con-
version to DVI, and therefore will not work with pdfla-
1.4.3 Compilation
tex. Some of those packages embed information in the
DVI that doesn't appear when the DVI is viewed, but
Compilation process
reemerges when the DVI is converted to another, newer
format.
The general concept is to transform a plain text document
into a publishable format, mosty a DVI, PS or PDF file. You would write your document slightly differently de-
This process is called compilation, which is done by an pending on the compiler you are using (latex or pdflatex).
executable file called a compiler. But as we will see later it is possible to add a sort of ab-
straction layer to hide the details of which compiler you're
There are two main compilers.
using, while the compiler can handle the translation itself.

• tex compiler reads a TeX .tex file and creates a .dvi. The following diagram shows the relationships between
the LaTeX source code and the formats you can create
• pdftex compiler reads a TeX .tex file and creates a from it:
.pdf. The boxed red text represents the file formats, the blue
text on the arrows represents the commands you have to
These compilers are basically used to compile Plain TeX, use, the small dark green text under the boxes represents
not LaTeX. There is no such LaTeX compiler since La- the image formats that are supported. Any time you pass
TeX is just a bunch of macros for TeX. However, there through an arrow you lose some information, which might
are two executables related to the previous compilers: decrease the features of your document. Therefore, you
14 CHAPTER 1. GETTING STARTED

on Windows you can use a program called yap (yet an-


pdftex tex other previewer). (Now evince and okular, the standard
document viewers for many Linux distributions are able
to view DVI files.)
pdflatex latex This way you created the DVI file, but with the same
source file you can create a PDF document. The steps
Source formats are exactly the same as before, but you have to replace
the command latex with pdflatex:
Output formats

ps2pdf dvi2ps
PDF pdf2ps
PostScript DVI 1. Type the command: pdflatex hello (as before, the
(pdf, (eps)
png,
jpg) dvipdfm .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:
should choose the shortest route to reach your target for-
mat. This is probably the most convenient way to obtain
an output in your desired format anyway. Starting from Output written on hello.pdf (1 page, 5548 bytes). Tran-
a LaTeX source, the best way is to use only latex for a script written on hello.log.
DVI output or pdflatex for a PDF output, converting to you can notice that the PDF document is bigger than the
PostScript only when it is necessary to print the docu- DVI, even if it contains exactly the same information.
ment. The main differences between the DVI and PDF formats
Chapter Export To Other Formats discusses more about are:
exporting LaTeX source to other file formats.
• DVI needs less disk space and it is faster to create.
It does not include the fonts within the document, so
Generating the document if you want the document to be viewed properly on
another computer, there must be all the necessary
It is clearly not going to be the most exciting document fonts installed. It does not support any interactivity
you have ever seen, but we want to see it nonetheless. I such as hyperlinks or animated images. DVI viewers
am assuming that you are at a command prompt, already are not very common, so you can consider using it
in the directory where hello.tex is stored. LaTeX itself for previewing your document while typesetting.
does not have a GUI (graphical user interface), since it
is just a program that crunches away at your input files, • PDF needs more disk space and it is slower to cre-
and produces either a DVI or PDF file. Some LaTeX ate, but it includes all the necessary fonts within
installations feature a graphical front-end where you can the document, so you will not have any problem of
click LaTeX into compiling your input file. On other sys- portability. It supports internal and external hyper-
tems there might be some typing involved, so here is how links. It also supports advanced typographic fea-
to coax LaTeX into compiling your input file on a text tures: hanging punctuation, font expansion and mar-
based system. Please note: this description assumes that gin kerning resulting in more flexibility available to
you already have a working LaTeX installation on your the TeX engine and better looking output. Nowa-
computer. days it is the de facto standard for sharing and pub-
lishing documents, so you can consider using it for
1. Type the command: latex hello (the .tex extension the final version of your document.
is not required, although you can include it if you
wish) About now, you saw you can create both DVI and PDF
document from the same source. This is true, but it gets a
2. Various bits of info about LaTeX and its progress bit more complicated if you want to introduce images or
will be displayed. If all went well, the last two lines links. This will be explained in detail in the next chapters,
displayed in the console will be: but for now assume you can compile in both DVI and
PDF without any problem.
Output written on hello.dvi (1 page, 232 bytes). Tran- Note, in this instance, due to the simplicity of the file, you
script written on hello.log. only need to run the LaTeX command once. However, if
This means that your source file has been processed and you begin to create complex documents, including bibli-
the resulting document is called hello.dvi, which takes up ographies and cross-references, etc, LaTeX needs to be
1 page and 232 bytes of space. Now you may view the executed multiple times to resolve the references. But
DVI file. On Unix with X11 you can type xdvi foo.dvi, this will be discussed in the future when it comes up.
1.4. BASICS 15

Autobuild Systems ment twice. There is no need to re-compile if no section


moved.
Compiling using only the latex binary can be quite tricky
For example, the temporary file for the table of contents
as soon as you start working on more complex documents
data is filename.toc.
as previously stated. A number of programs exist to auto-
matically read in a TeX document and run the appropriate None of these files contains unrecoverable information.
compilers the appropriate number of times. For example, It means you can delete them safely, compiling will re-
latexmk can generate a PDF from most TeX files simply: generate them automatically.
$ latexmk -pdf file.tex When you work with various capabilities of LaTeX (in-
dex, glossaries, bibliographies, etc.) you will soon find
Note that most editors will take care of it for you.
yourself in a maze of files with various extensions and
probably no clue. The following list explains the most
Compressed PDF common file types you might encounter when working
with TeX:
For a PDF output, you may have noticed that the output
PDF file is not always the same size depending on the
engine you used to compile the file. So latex → dvips → 1.4.5 And what now?
ps2pdf will usually be much smaller than pdflatex. If you
want pdflatex features along with a small output file size, Common Elements
you can use the Ghostscript command:
See Document Structure and the Common Elements
$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite - part for all the common features that belong to every type
sOutputFile="Compressed.pdf” “Original.pdf” of document.

1.4.4 Files Non-English documents and special characters

Picking suitable filenames LaTeX has some nice features for most languages in the
world. You can tell LaTeX to follow typography rules of
Never, ever use directories (folders) or file names that the target language, ease special characters input, and so
contain spaces. Although your operating system probably on. See Special Characters and Internationalization.
supports them, some don't, and they will only cause grief
and tears with TeX. Make filenames as short or as long as
you wish, but strictly avoid spaces. Stick to lower-case let- Modular document
ters without accents (a-z), the digits 0-9, the hyphen (–),
and only one full point or period (.) to separate the file ex- See Modular Documents for good recommendations
tension (somewhat similar to the conventions for a good about the way to organize big projects into multiple files.
Web URL): it will let you refer to TeX files over the Web
more easily and make your files more portable. Some Questions and Issues
operating systems do not distinguish between upper-case
and lower-case letters, others do. Therefore it’s best not We highly urge you to read the FAQ if you have issues
to mix them. about basic features, or if you want to read essential rec-
ommendations. For the more specific questions and is-
Ancillary files sues, refer to the Tips and Tricks page. If you cannot find
what you want here, use the Q&A page.
The TeX compilers are single-pass processes. It means
that there is no way for a compiler to jump around the Macros for the utmost efficiency
document, which would be useful for the table of con-
tents and references. Indeed the compiler cannot guess The full power of LaTeX resides in macros. They make
at which page a specific section is going to be printed, so your documents very dynamic and flexible. See the
when the table of contents is printed before the upcoming dedicated part.
sections, it cannot set the page numbers.
To circumvent this issue, many LaTeX commands which
Working in a team
need to jump use ancillary files which usually have the
same file name as the current document but a different
See chapter Collaborative Writing of LaTeX Documents.
extension. It stores temporary data into these files and
use them for the next compilation. So to have an up-
to-date table of contents, you need to compile the docu-
Chapter 2

Common Elements

2.1 Document Structure Document classes

The main point of writing a text is to convey ideas, infor- When processing an input file, LaTeX needs to know the
mation, or knowledge to the reader. The reader will un- type of document the author wants to create. This is
derstand the text better if these ideas are well-structured, specified with the \documentclass command. It is rec-
and will see and feel this structure much better if the typo- ommended to put this declaration at the very beginning.
graphical form reflects the logical and semantic structure Here, class specifies the type of document to be created.
of the content. The LaTeX distribution provides additional classes for
LaTeX is different from other typesetting systems in that other documents, including letters and slides. It is also
you just have to tell it the logical and semantical structure possible to create your own, as is often done by journal
of a text. It then derives the typographical form of the text publishers, who simply provide you with their own class
according to the “rules” given in the document class file file, which tells LaTeX how to format your content. But
and in various style files. LaTeX allows users to structure we'll be happy with the standard article class for now. The
their documents with a variety of hierarchical constructs, options parameter customizes the behavior of the docu-
including chapters, sections, subsections and paragraphs. ment class. The options have to be separated by commas.
Example: an input file for a LaTeX document could start
with the line
2.1.1 Global structure
which instructs LaTeX to typeset the document as an ar-
When LaTeX processes an input file, it expects it to fol- ticle with a base font size of 11 points, and to produce a
low a certain structure. Thus every input file must contain layout suitable for double sided printing on A4 paper.
the commands Here are some document classes that can be used with
The area between \documentclass{...} and \be- LaTeX:
gin{document} is called the preamble. It normally The standard document classes that are a part of LaTeX
contains commands that affect the entire document. are built to be fairly generic, which is why they have a
After the preamble, the text of your document is enclosed lot of options in common. Other classes may have differ-
between two commands which identify the beginning and ent options (or none at all). Normally, third party classes
end of the actual document: come with some documentation to let you know. The
most common options for the standard document classes
You would put your text where the dots are. The reason are listed in the following table:
for marking off the beginning of your text is that LaTeX
allows you to insert extra setup specifications before it For example, if you want a report to be in 12pt type on
(where the blank line is in the example above: we'll be us- A4, but printed one-sided in draft mode, you would use:
ing this soon). The reason for marking off the end of your
text is to provide a place for LaTeX to be programmed to
do extra stuff automatically at the end of the document, Packages
like making an index.
While writing your document, you will probably find that
A useful side-effect of marking the end of the document
there are some areas where basic LaTeX cannot solve
text is that you can store comments or temporary text un-
your problem. If you want to include graphics, colored
derneath the \end{document} in the knowledge that La-
text or source code from a file into your document, you
TeX will never try to typeset them:
need to enhance the capabilities of LaTeX. Such en-
hancements are called packages. Some packages come
2.1.2 Preamble with the LaTeX base distribution. Others are provided
separately. Modern TeX distributions come with a large

16
2.1. DOCUMENT STRUCTURE 17

number of packages pre-installed. Packages are activated you use the AMS article class (amsart), then you can use
with the several different commands to enter author information.
command, where package is the name of the package and The email address is at the end, and the \texttt commands
options is a list of keywords that trigger special features formats the email address using a mono-spaced font. The
in the package. For example, to use the color package, built-in command called \today will be replaced with the
which lets you typeset in colors, you would type: current date when processed by LaTeX. But you are free
to put whatever you want as a date, in no set order. If
You can include several package names in one \usepack- braces are left empty, then the date is omitted.
age command by separating the names with commas, like
this: Using this approach, you can create only basic output
whose layout is very hard to change. If you want to create
and you can have more than one \usepackage command. your title freely, see the Title Creation section.
Some packages allow optional settings in square brackets.
If you use these, you must give the package its own sepa-
rate \usepackage command, like geometry shown below: Abstract
Many packages can have additional formatting specifi-
As most research papers have an abstract, there are pre-
cations in optional arguments in square brackets, in the
defined commands for telling LaTeX which part of the
same way as geometry does. Read the documentation for
content makes up the abstract. This should appear in its
the package concerned to find out what can be done. You
logical order, therefore, after the top matter, but before
can pass several options together separated by a comma:
the main sections of the body. This command is available
for the document classes article and report, but not book.

2.1.3 The document environment By default, LaTeX will use the word “Abstract” as a title
for your abstract. If you want to change it into anything
Top matter else, e.g. “Executive Summary”, add the following line
before you begin the abstract environment:
At the beginning of most documents there will be infor-
mation about the document itself, such as the title and
Sectioning commands
date, and also information about the authors, such as
name, address, email etc. All of this type of informa-
The commands for inserting sections are fairly intuitive.
tion within LaTeX is collectively referred to as top matter.
Of course, certain commands are appropriate to different
Although never explicitly specified (there is no \topmat-
document classes. For example, a book has chapters but
ter command) you are likely to encounter the term within
an article doesn't. Here are some of the structure com-
LaTeX documentation.
mands found in simple.tex.
A simple example:
Notice that you do not need to specify section numbers;
The \title, \author, and \date commands are self- LaTeX will sort that out for you. Also, for sections, you
explanatory. You put the title, author name, and date in do not need to use \begin and \end commands to indicate
curly braces after the relevant command. The title and which content belongs to a given block.
author are usually compulsory (at least if you want La-
LaTeX provides 7 levels of depth for defining sections
TeX to write the title automatically); if you omit the \date
(see table below). Each section in this table is a subsection
command, LaTeX uses today’s date by default. You al-
of the one above it.
ways finish the top matter with the \maketitle command,
which tells LaTeX that it’s complete and it can typeset the All the titles of the sections are added automatically to
title according to the information you have provided and the table of contents (if you decide to insert one). But
the class (style) you are using. If you omit \maketitle, the if you make manual styling changes to your heading, for
titling will never be typeset (unless you write your own). example a very long title, or some special line-breaks or
unusual font-play, this would appear in the Table of Con-
Here is a more complicated example:
tents as well, which you almost certainly don't want. La-
as you can see, you can use commands as arguments of TeX allows you to give an optional extra version of the
\title and the others. The double backslash (\\) is the La- heading text which only gets used in the Table of Con-
TeX command for forced linebreak. LaTeX normally de- tents and any running heads, if they are in effect. This
cides by itself where to break lines, and it’s usually right, optional alternative heading goes in [square brackets] be-
but sometimes you need to cut a line short, like here, and fore the curly braces:
start a new one.
If there are two authors separate them with the \and com- Section numbering Numbering of the sections is per-
mand: formed automatically by LaTeX, so don't bother adding
If you are provided with a class file from a publisher, or if them explicitly, just insert the heading you want between
18 CHAPTER 2. COMMON ELEMENTS

the curly braces. Parts get roman numerals (Part I, Part Table of contents
II, etc.); chapters and sections get decimal numbering like
this document, and appendices (which are just a special All auto-numbered headings get entered in the Table of
case of chapters, and share the same structure) are let- Contents (ToC) automatically. You don't have to print a
tered (A, B, C, etc.). ToC, but if you want to, just add the command \tableof-
contents at the point where you want it printed (usually
You can change the depth to which section numbering
after the Abstract or Summary).
occurs, so you can turn it off selectively. By default it
is set to 2. If you only want parts, chapters, and sections Entries for the ToC are recorded each time you process
numbered, not subsections or subsubsections etc., you can your document, and reproduced the next time you pro-
change the value of the secnumdepth counter using the cess it, so you need to re-run LaTeX one extra time to
\setcounter command, giving the depth level you wish. ensure that all ToC pagenumber references are correctly
For example, if you want to change it to “1": calculated. We've already seen how to use the optional
argument to the sectioning commands to add text to the
A related counter is tocdepth, which specifies what depth
ToC which is slightly different from the one printed in
to take the Table of Contents to. It can be reset in exactly
the body of the document. It is also possible to add extra
the same way as secnumdepth. For example:
lines to the ToC, to force extra or unnumbered section
To get an unnumbered section heading which does not headings to be included.
go into the Table of Contents, follow the command name
The commands \listoffigures and \listoftables work in ex-
with an asterisk before the opening curly brace:
actly the same way as \tableofcontents to automatically
All the divisional commands from \part* to \subpara- list all your tables and figures. If you use them, they nor-
graph* have this “starred” version which can be used on mally go after the \tableofcontents command. The \table-
special occasions for an unnumbered heading when the ofcontents command normally shows only numbered sec-
setting of secnumdepth would normally mean it would be tion headings, and only down to the level defined by the
numbered. tocdepth counter, but you can add extra entries with the
If you want the unnumbered section to be in the table of \addcontentsline command. For example if you use an
contents anyway, use the \addcontentsline command like unnumbered section heading command to start a prelim-
this: inary piece of text like a Foreword or Preface, you can
write:
Note that if you use PDF bookmarks you will need to add
a phantom section so that bookmark will lead to the cor- This will format an unnumbered ToC entry for “Preface”
rect place in the document. The \phantomsection com- in the “subsection” style. You can use the same mecha-
mand is defined in the hyperref package, and is imple- nism to add lines to the List of Figures or List of Tables
mented normally as follows: by substituting lof or lot for toc. If the hyperref pack-
age is used and the link does not point to the correct
For chapters you will also need to clear the page (this will chapter, the command \phantomsection in combination
also correct page numbering in the ToC): with \clearpage or \cleardoublepage can be used (see also
The value where the section numbering starts from can Labels and Cross-referencing):
be set with the following command: To change the title of the TOC, you have to paste this
The next section after this command will now be num- command \renewcommand{\contentsname}{<New table
bered 5. of contents title>} in your document preamble. The List
of Figures (LoF) and List of Tables (LoT) names can be
For more details on counters, see the dedicated chapter.
changed by replacing the \contentsname with \listfigure-
name for LoF and \listtablename for LoT.

Section number style See Counters. 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:
This will make the table of contents include everything
Ordinary paragraphs
down to paragraphs. The levels are defined above on this
page. Note that this solution does not permit changing
Paragraphs of text come after section headings. Simply the depth dynamically.
type the text and leave a blank line between paragraphs.
The blank line means “start a new paragraph here": it You can change the depth of specific section type, which
does not mean you get a blank line in the typeset output. could be useful for PDF bookmarks (if you are using the
For formatting paragraph indents and spacing between hyperref package) :
paragraphs, refer to the Paragraph Formatting section. In order to further tune the display or the numbering of
2.1. DOCUMENT STRUCTURE 19

the table of contents, for instance if the appendix should 5. Dedication if any, else empty
be less detailed, you can make use of the tocvsec2 pack-
age (CTAN, doc). 6. Table of contents

7. List of figures (can be in the backmatter too)


2.1.4 Book structure
8. Preface chapter
The standard LaTeX book class follows the same layout
described above with some additions. By default a book Mainmatter
will be two-sided, i.e. left and right margins will change
according to the page number parity. Furthermore cur-
rent chapter and section will be printed in the header. 1. Main topic

If you do not make use of chapters, it is barely useful to


use the book class. Appendix

Additionally the class provides macros to change the for-


matting of some places of the document. We will give 1. Some subordinate chapters
you some advice on how to use them properly.[1]
Backmatter
• The frontmatter chapters will not be numbered.
Page numbers will be printed in roman numerals. 1. Bibliography
Frontmatter is not supposed to have sections, since
they will be number 0.n because there is no chapter 2. Glossary / Index
numbering. Check the Counters chapter for a fix.

• The mainmatter chapters works as usual. The com- Introductory chapters with main page numbering
mand resets the page numbering. Page numbers will
be printed in arabic numerals. You may be tempted to put your introductory chapters in
• The \appendix macro can be used to indicate that the main matter so that it follows the same numbering as
following sections or chapters are to be numbered as the main chapters. This is not how the class was meant
appendices. Appendices can be used for the article to be used, so you will run into an issue if you don't want
class too: the chapter to be numbered.
In the above code sample, the second page of the intro-
Only use the \appendix macro once for all appendices. duction will have TABLE OF CONTENTS printed in the
header. This is because the starred \chapter* command
• The backmatter behaves like the frontmatter. It has does not set the leftmark -- see Page Layout. And it will
the same issue with section numbering. not be printed in the table of contents either.
The trick is to set the leftmark and the TOC manually:
As a general rule you should avoid mixing the command TABLE OF CONTENTS is traditionally printed both left
order. Nonetheless all commands are optional, so you and right, but here we print it like other chapters, only
might consider using only a few. right on even pages.
Note that the special content like the table of contents is To make it more convenient, you might use a macro:
considered as an unnumbered chapter.

Page order
2.1.5 Special pages

This is one traditional page order for books. 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
Frontmatter dedicated part Special Pages.

1. Half-title
Bibliography
2. Empty

3. Title page Any good research paper will have a complete list of ref-
erences. LaTeX has two ways of inserting your refer-
4. Information (copyright notice, ISBN, etc.) ences into a document:
20 CHAPTER 2. COMMON ELEMENTS

• you can embed them within the document itself. It’s The setspace package allows more fine-grained control
simpler, but it can be time-consuming if you are over line spacing. To set “one and a half” line spacing
writing several papers about similar subjects so that document-wide, but not where it is usually unnecessary
you often have to cite the same books. (e.g. footnotes, captions):
• you can store them in an external BibTeX file and To change line spacing within the document, the setspace
then link them via a command to your current doc- package provides the environments singlespace, onehalf-
ument and use a Bibtex style to define how they ap- space, doublespace and spacing:
pear. This way you can create a small database of
the references you might use and simply link them,
Non-breaking spaces
letting LaTeX work for you.
This essential feature is a bit unknown to newcomers,
To learn how to add a bibliography to your document, see
although it is available on most WYSIWYG document
the Bibliography Management section.
processors. A non-breaking space between two tokens
(e.g. words, punctuation marks) prevents the processors
2.1.6 Notes and references from inserting a line break between them. Besides a non-
breaking space cannot be enlarged. It is very important
[1] http://tex.stackexchange.com/questions/20538/ for a consistent reading.
what-is-the-right-order-when-using-frontmatter-tableofcontents-mainmatter
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
2.2 Text Formatting initials, etc. In French typography, you would put a non-
breaking space before all two-parts punctuation marks.
This section will guide you through the formatting tech- Examples:
niques of the text. Formatting tends to refer to most things
to do with appearance, so it makes the list of possible top-
ics quite eclectic: text style, spacing, etc. If formatting Space between words and sentences
may also refer to paragraphs and to the page layout, we
will focus on the customization of words and sentences To get a straight right margin in the output, LaTeX in-
for now. serts varying amounts of space between the words. By
A lot of formatting techniques are required to differenti- default, it also inserts slightly more space at the end of
ate certain elements from the rest of the text. It is often a sentence. However, the extra space added at the end
necessary to add emphasis to key words or phrases. Foot- of sentences is generally considered typographically old-
notes are useful for providing extra information or clarifi- fashioned in English language printing. (The practice is
cation without interrupting the main flow of text. So, for found in nineteenth century design and in twentieth cen-
these reasons, formatting is very important. However, it tury typewriter styles.) Most modern typesetters treat the
is also very easy to abuse, and a document that has been end of sentence space the same as the interword space.
over-done can look and read worse than one with none at (See for example, Bringhurst’s Elements of Typographic
all. Style.) The additional space after periods can be disabled
with the command
LaTeX is so flexible that we will actually only skim the
surface, as you can have much more control over the pre- which tells LaTeX not to insert more space after a pe-
sentation of your document if you wish. Having said that, riod than after ordinary character. Frenchspacing can be
one of the purposes of LaTeX is to take away the stress turned off later in your document via the \nonfrenchspac-
of having to deal with the physical presentation yourself, ing command.
so you need not get too carried away! If an author wishes to use the wider end-of-sentence spac-
ing, care must be exercised so that punctuation marks are
not misinterpreted as ends of sentences. TeX assumes
2.2.1 Spacing that sentences end with periods, question marks or excla-
mation marks. Although if a period follows an uppercase
Line Spacing letter, this is not taken as a sentence ending, since periods
after uppercase letters normally occur in abbreviations.
If you want to use larger inter-line spacing in a document, Any exception from these assumptions has to be specified
you can change its value by putting the by the author. A backslash in front of a space generates a
command into the preamble of your document. Use \line- space that will not be enlarged. A tilde ‘~’ character gen-
spread{1.3} for “one and a half” line spacing, and \line- erates a non-breaking space. The command \@ in front
spread{1.6} for “double” line spacing. Normally the lines of a period specifies that this period terminates a sentence
are not spread, so the default line spread factor is 1. even when it follows an uppercase letter. (If you are us-
2.2. TEXT FORMATTING 21

ing \frenchspacing, then none of these exceptions need be prevents “FORTRAN”, “Fortran” and “fortran” from be-
specified.) ing hyphenated at all. No special characters or symbols
are allowed in the argument. Example:
The command \- inserts a discretionary hyphen into a
Stretched spaces
word. This also becomes the only point where hyphen-
ation is allowed in this word. This command is especially
You can insert a horizontal stretched space with \hfill in a
useful for words containing special characters (e.g., ac-
line so that the rest gets “pushed” toward the right margin.
cented characters), because LaTeX does not automati-
For instance this may be useful in the header.
cally hyphenate words containing special characters.
Similarly you can insert vertical stretched space with
LaTeX does not hyphenate compound words that contain
\vfill. It may be useful for special pages.
a dash[1] . There are two packages that can add back flexi-
See Lengths for more details. bility. The hyphenat package supplies the \hyp command.
This command typesets the dash and then subjects the
constituent words to automatic hyphenation. After load-
Manual spacing ing the package:
one should write, instead of electromagnetic-endioscopy:
The spaces between words and sentences, between para-
graphs, sections, subsections, etc. is determined automat- The extdash package also offers features for controlling
ically by LaTeX. It is against LaTeX philosophy to insert the hyphenation of compound words containing dashes
spaces manually and will usually lead to bad formatting. — as opposed to the words themselves which it leaves to
Manual spacing is a matter of macro writing and package LaTeX. The shortcuts option enables a more compressed
creation. syntax:
See Lengths for more details. Typical usage is as follows, assuming the compressed syn-
tax. In both cases, LaTeX can break and hyphenate the
constituent words, but in the latter case, it will not break
2.2.2 Hyphenation after the L:
One or more words can be kept together on the one line
LaTeX hyphenates words whenever necessary. Hyphen- with the standard LaTeX command:
ation rules will vary for different languages. LaTeX
only supports English by default, so if you want to have This prevents hyphenation and causes its argument to be
correct hyphenation rules for your desired language, see kept together under all circumstances. For example:
Internationalization. \fbox is similar to \mbox, but in addition there will be a
If the hyphenation algorithm does not find the correct hy- visible box drawn around the content.
phenation points, you can remedy the situation by using To avoid hyphenation altogether, the penalty for hyphen-
the following commands to tell TeX about the exception. ation can be set to an extreme value:
The command
You can change the degree to which LaTeX will hyphen-
causes the words listed in the argument to be hyphenated ate by changing the value of \tolerance=1000 and \hy-
only at the points marked by “-”. The argument of the phenpenalty=1000. You'll have to experiment with the
command should only contain words built from normal values to achieve the desired effect. A document which
letters, or rather characters that are considered to be nor- has a low tolerance value will cause LaTeX not to tol-
mal letters by LaTeX. It is known that the hyphenation erate uneven spacing between words, hyphenating words
algorithm does not find all correct American English hy- more frequently than in documents with higher toler-
phenation points for several words. A log of known ex- ances. Also note that using a higher text width will de-
ceptions is published periodically in the TUGboat jour- crease the probability of encountering badly hyphenated
nal. (2012 list: https://www.tug.org/TUGboat/tb33-1/ word. For example adding
tb103hyf.pdf)
will widen the text width and reduce the amount of mar-
The hyphenation hints are stored for the language that gin overruns.
is active when the hyphenation command occurs. This
means that if you place a hyphenation command into the
preamble of your document it will influence the English 2.2.3 Quote-marks
language hyphenation. If you place the command af-
ter the \begin{document} and you are using some pack- LaTeX treats left and right quotes as different entities.
age for national language support like babel, then the hy- For single quotes, ` (on American keyboards, this symbol
phenation hints will be active in the language activated is found on the tilde key (adjacent to the number 1 key
through babel. The example below will allow “hyphen- on most keyboards) gives a left quote mark, and ' is the
ation” to be hyphenated as well as “Hyphenation”, and it right. For double quotes, simply double the symbols, and
22 CHAPTER 2. COMMON ELEMENTS

LaTeX will interpret them accordingly. (Don't use the " \DisableLigatures from the microtype package can dis-
for right double quotes: when the babel package is used able ligatures in the whole document to increase accessi-
for some languages (e.g. German), the " is redefined to bility.
produce an umlaut accent; using " for right double quotes Note that this will also disable ligatures such as "--" to
will either lead to bad spacing or it being used to produce "–", "---" to "—", etc.
an umlaut). On British keyboards, ' ` ' is left of the ' 1 ' key
and shares the key with ' ¬ ', and sometimes ' ¦ ' or ' | '. The If you are using XeLaTeX and OpenType fonts, the
apostrophe (') key is to the right of the colon/semicolon fontspec package allows for standard ligatures to be
key and shares it with the ' @ ' symbol. turned off as well as fancy swash ligatures to be turned
on.
The right quote is also used for apostrophe in LaTeX
without trouble. Another solution is to use the cmap package, which will
help the reader to interpret the ligatures:
For left bottom quote and European quoting style you
need to use T1 font encoding enabled by:
See Fonts for more details on font encoding. 2.2.7 Slash marks
The package csquotes offers a multilingual solution to
quotations, with integration to citation mechanisms of- The normal typesetting of the / character in LaTeX
fered by BibTeX. This package allows one for example does not allow following characters to be “broken” onto
to switch languages and quotation styles according to ba- new lines, which often create “overfull” errors in output
bel language selections. (where letters push off the margin). Words that use slash
marks, such as “input/output” should be typeset as “in-
put\slash output”, which allow the line to “break” after
the slash mark (if needed). The use of the / character in
2.2.4 Diacritics and accents LaTeX should be restricted to units, such as “mm/year”,
which should not be broken over multiple lines.
Most accents and diacritics may be inserted with direct
keyboard input by configuring the preamble properly. For A word after / or \slash is not automatically hyphenated.
symbols unavailable on your keyboard, diacritics may be This is a similar problem to non-hyphenation of words
added to letters by placing special escaped metacharacters with a dash described under Hyphenation. One way to
before the letter that requires the diacritic. have both a line break and automatic hyphenation in both
words is
See Special Characters.
Both / and \slash can be used with a zero \hspace like
this. \slash includes a penalty to make a line break there
2.2.5 Margin misalignment and interword less desirable. This combination can be made into a new
slash macro if desired. The hyphenat package includes an
spacing
\fshyp which will add a hyphen after the slash like “input/-
output” if the line breaks there.
Some very long words, numbers or URLs may not be hy-
phenated properly and move far beyond the side margin.
One solution for this problem is to use sloppypar envi-
ronment, which tells LaTeX to adjust word spacing less
2.2.8 Fonts
strictly. As a result, some spaces between words may be
To change the font family, emphasize text, and other font-
a bit too large, but long words will be placed properly.
related issues, see Fonts.
Another solution is to edit the text to avoid long words,
numbers or URLs approaching the side margin.
2.2.9 Formatting macros
2.2.6 Ligatures Even if you can easily change the output of your fonts
using those commands, you're better off not using explicit
Some letter combinations are typeset not just by setting commands like this, because they work in opposition to
the different letters one after the other, but by actually the basic idea of LaTeX, which is to separate the logical
using special symbols (like "ff"), called ligatures. Liga- and visual markup of your document. This means that
tures can be prohibited by inserting {} or, if this does if you use the same font changing command in several
not work, {\kern0pt} between the two letters in question. places in order to typeset a special kind of information,
This might be necessary with words built from two words. you should use \newcommand to define a “logical wrapper
Here is an example: command” for the font changing command.
Ligatures can interfere with some text-search tools (a This approach has the advantage that you can decide at
search for "finally” wouldn't find the string "finally”). The some later stage that you want to use some visual rep-
2.2. TEXT FORMATTING 23

resentation of danger other than \textit, without having Some fonts do not have text figures built in; the textcomp
to wade through your document, identifying all the oc- package attempts to remedy this by effectively generating
currences of \textit and then figuring out for each one text figures from the currently-selected font. Put \usep-
whether it was used for pointing out danger or for some ackage{textcomp} in your preamble. textcomp also al-
other reason. lows you to use decimal points, properly formatted dollar
See Macros for more details. signs, etc. within \oldstylenums{}.
One common use for text figures is in section, paragraph,
and page numbers. These can be set to use text figures by
2.2.10 Text mode superscript and sub- placing some code in your preamble:
script Should you use additional sectioning or paragraphing
commands, you may adapt the previous code listing to
To superscript text in text-mode, you can use the \textsu-
include them as well.
perscript{} command. This allows you to, for instance,
typeset 6th as 6th :
Note
Subscripting in text-mode is not supported by LaTeX
alone; however, several packages allow the use of A subsequent use of the \pagenumbering command, e.g.,
the \textsubscript{} command. For instance, bpchem, \pagenumbering{arabic}, will reset the \thepage com-
KOMA-Script2, and fixltx2e all support this command. mand back to the original. Thus, if you use the \pagenum-
Of these, fixltx2e is perhaps the most universal option bering command in your document, be sure to reinstate
since it is distributed with LaTeX and requires no ad- your \myThePage definition from the code above:
ditional packages to be implemented. Note that as of
April 2015, fixltx2e has been declared obsolete, and
the \textsubscript{} command can no longer be used. 2.2.12 Dashes and hyphens
changes can be used to restore the \textsubscript{} com-
mand. LaTeX knows four kinds of dashes: a hyphen (-), en dash
(–), em dash (—), or a minus sign (−). You can ac-
If you do not load a package that supports \textsub- cess three of them with different numbers of consecutive
script{}, the math mode must be used. This is easily ac- dashes. The fourth sign is actually not a dash at all—it is
complished in running text by bracketing your text with the mathematical minus sign:
the $ symbol. In math mode subscripting is done using
the underscore: _{}. The names for these dashes are: ‘-’(-) hyphen , ‘--’(–) en-
dash , ‘---’(—) em-dash and ‘ − ’(−) minus sign. They
For example, the formula for water is written as: have different purposes:
Note that in math mode text will appear in a font suit-
able for mathematical variables. In math mode, to gener-
ate Roman text, for example, one would use the \mathrm
command:
Note the use of \<space> to insert a space in math mode.
Similarly, you can superscript using: Use \hyp{} macro from hyphenat package instead of hy-
A very common use of subscripts within the text environ- phen if you want LaTeX to break compound words be-
ment is to typeset chemical formulas. For these purposes, tween lines.
a highly recommended package is mhchem. This pack- The commands \textendash and \textemdash are also used
age is easy to use and works with your text fonts (rather to produce en-dash (–), and em-dash (—), respectively.
than math fonts). To insert a chemical formula, use \ce{}
with the text-equivalent formula, for example:
2.2.13 Ellipsis (…)
See also Chemical Graphics for chemical symbols and
formulas. A sequence of three dots is known as an ellipsis, which is
commonly used to indicate omitted text. On a typewriter,
2.2.11 Text figures (“old style” numerals) a comma or a period takes the same amount of space as
any other letter. In book printing, these characters occupy
Many typographers prefer to use titling figures, some- only a little space and are set very close to the preceding
times called lining figures, when numerals are inter- letter. Therefore, you cannot enter ‘ellipsis’ by just typing
spersed with full caps, when they appear in tables, and three dots, as the spacing would be wrong. Instead, there
when they appear in equations, using text figures else- is a special command for these dots. It is called \ldots:
where. LaTeX allows this usage through the \old- Alternatively, you can use the \textellipsis command
stylenums{} command: which allows the spacing between the dots to vary.
24 CHAPTER 2. COMMON ELEMENTS

2.2.14 Ready-made strings such as extra vertical space inserted before a paragraph
\parskip can have a default dimension plus an amount
There are some very simple LaTeX commands for type- of expansion minus an amount of contraction. This is
setting special text strings: useful on pages in complex documents where not every
page may be an exact number of fixed-height lines long,
so some give-and-take in vertical space is useful. You
specify this in a \setlength command like this:
If you want to indent a paragraph that is not indented, you
can use
at the beginning of the paragraph. Obviously, this will
only have an effect when \parindent is not set to zero. If
you want to indent the beginning of every section, you can
2.2.15 Notes and References use the indentfirst package: once loaded, the beginning
of any chapter/section is indented by the usual paragraph
[1] hyphenat package documentation, p3 indentation.
To create a non-indented paragraph, you can use
This page uses material from Andy Roberts’ Getting to grips
as the first command of the paragraph. This might come
with LaTeX with permission from the author.
in handy when you start a document with body text and
not with a sectioning command.

2.3 Paragraph Formatting 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 be-
Altering the paragraph formatting is rarely necessary in
tween paragraphs is held in \parskip, which could be al-
academic writing. It is primarily used for formatting text
tered in a similar fashion as above. However, this param-
in floats or for more exotic documents.
eter is used elsewhere too, such as in lists, which means
you run the risk of making various parts of your docu-
2.3.1 Paragraph alignment ment look very untidy by changing this setting. If you
want to use the style of having no indentation with a space
Paragraphs in LaTeX are usually fully justified, i.e. flush between paragraphs, use the parskip package, which does
with both the left and right margins. For whatever rea- this for you, while making adjustments to the spacing of
son, should you wish to alter the justification of a para- lists and other structures which use paragraph spacing, so
graph, there are three environments at hand, and also La- they don't get too far apart. If you want both indent and
TeX command equivalents. break, use

All text between the \begin and \end of the specified en- To indent subsequent lines of a paragraph, use the TeX
vironment will be justified appropriately. The commands command \hangindent. (While the default behaviour is
listed are for use within other environments. For exam- to apply the hanging indent after the first line, this may
ple, p (paragraph) columns in tabular. be changed with the \hangafter command.) An example
follows.
However, if you really need to disable one of the above
commands locally (for example because you have to use The TeX commands \leftskip and \rightskip add addi-
some broken package), you can use the command \justi- tional space to the left and right sides of each line, al-
fying from package ragged2e. lowing the formatting for subsequent paragraphs to differ
from the overall document margins. This space is in ad-
dition to the indentation added by \parindent and \hangin-
2.3.2 Paragraph indent and break dent.
To change the indentation of the last line in a paragraph,
By default, the first paragraph after a heading follows the use the TeX command \parfillskip.
standard Anglo-American publishers’ practice of no in-
dentation. The size of subsequent paragraph indents is
determined by a parameter called \parindent. The de- 2.3.3 \paragraph line break
fault length that this constant holds is set by the document
class that you use. It is possible to override it by using the
Default style for \paragraph may seem odd in the first
\setlength command. This will set paragraph indents to place, as it writes the following text next to the title. If
1cm: you do not like it, use a class other than the traditional ar-
Whitespace in LaTeX can also be made flexible (what ticle/book, or use ConTeXt or PlainTeX. Hacking of the
Lamport calls “rubber” lengths). This means that values class in use is really not the way LaTeX is intended to be
2.3. PARAGRAPH FORMATTING 25

used, and you may encounter a lot of frustrating issues.


and new lines are reproduced as given, and the text is dis-
Anyway, let’s analyse the problem. If you add a manual played in an appropriate fixed-width font. Any LaTeX
line break with \\, LaTeX will complain that command will be ignored and handled as plain text. This
is ideal for typesetting program source code. Here is an
There’s no line here to end. example:
Simply adding an empty space will do it: Note: once in the verbatim environment, the only com-
Alternatively you can use the shorter, yet not completely mand that will be recognized is \end{verbatim}. Any oth-
equivalent syntax: ers will be output. The font size in the verbatim environ-
ment can be adjusted by placing a font size command be-
fore \begin{verbatim}. If this is a problem, you can use
2.3.4 Line spacing the alltt package instead, providing an environment with
the same name:
To change line spacing in the whole document use the Remember to add \usepackage{alltt} to your preamble to
command \linespread covered in Text Formatting. use it though! Within the alltt environment, you can use
Alternatively, you can use the \usepackage{setspace} the command \normalfont to get back the normal font. To
package, which is also covered in Text Format- write equations within the alltt enviroment, you can use
ting. This package provides the commands \dou- \( and \) to enclose them, instead of the usual $.
blespacing, \onehalfspacing, \singlespacing and \set- When using \textbf{} inside the alltt enviroment, note
stretch{baselinestretch}, which will specify the line spac- that the standard font has no bold TT font. Txtfonts has
ing for all sections and paragraphs until another command bold fonts: just add \renewcommand{\ttdefault}{txtt}
is used. Furthermore, the package provides the following after \usepackage{alltt}.
environments in order to change line spacing within the
document but not document-wide: If you just want to introduce a short verbatim phrase, you
don't need to use the whole environment, but you have
• doublespace: lines are double spaced; the \verb command:
The first character following \verb is the delimiter: here
• onehalfspace: line spacing set to one-and-half spac- we have used "+", but you can use any character you like
ing; except *; \verb will print verbatim all the text after it until
• singlespace: normal line spacing; it finds the next delimiter. For example, the code:
will print \textbf{Hi mate!}, ignoring the effect \textbf
• spacing: customizable line spacing, e.g. \be-
should have on text.
gin{spacing}{\baselinestretch} ... \end{spacing}.
For more control over formatting, however, you can try
See the section on customizing lists for information on the fancyvrb package, which provides a Verbatim envi-
how to change the line spacing in lists. ronment (note the capital letter) which lets you draw a
rule round the verbatim text, change the font size, and
even have typographic effects inside the Verbatim en-
2.3.5 Manual breaks vironment. It can also be used in conjunction with the
fancybox package and it can add reference line numbers
LaTeX takes care of formatting, breaks included. You (useful for chunks of data or programming), and it can
should avoid manual breaking as much as possible, for it even include entire external files.
could lead to very bad formatting. To use verbatim in beamer, the frame needs to be make
Controlling the breaks should be reserved to macro and fragile: \begin{frame}[fragile] .
package writers. Here follows a quick reference.
The page breaks are covered in Page Layout. More details Typesetting URLs One of either the hyperref or url
on manual spaces between paragraphs (such as \bigskip) packages provides the \url command, which properly
can be found in Lengths. typesets URLs, for example:
will show this URL exactly as typed (similar to the \verb
2.3.6 Special paragraphs command), but the \url command also performs a hy-
phenless break at punctuation characters (only in PDFLa-
Verbatim text TeX, not in plain LaTeX+ dvips). It was designed for
Web URLs, so it understands their syntax and will never
There are several ways to introduce text that won't be in- break midway through an unpunctuated word, only at
terpreted by the compiler. If you use the verbatim en- slashes and full stops. Bear in mind, however, that spaces
vironment, everything input between the begin and end are forbidden in URLs, so using spaces in \url arguments
commands are processed as if by a typewriter. All spaces will fail, as will using other non-URL-valid characters.
26 CHAPTER 2. COMMON ELEMENTS

When using this command through the hyperref package, Another drawback is that content is still parsed and pos-
the URL is “clickable” in the PDF document, whereas it sibly expanded, so you cannot put anything you want in it
is not linked to the web when using only the url pack- (such as LaTeX commands).
age. Also when using the hyperref package, to remove
the border placed around a URL, insert pdfborder = {0 0
0 0} inside the \hypersetup{}. (Alternately pdfborder = Skipping parts of the source
{0 0 0} might work if the four zeroes do not.)
A more robust way of making the TeX engine skip some
You can put the following code into your preamble to part of the source is to use the TeX \iffalse-conditional.
change the style, how URLs are displayed to the normal The typical use is
font:
The \iffalse-conditional is always false.
See also Hyperlinks

Quoting text
Listing environment This is also an extension of the
verbatim environment provided by the moreverb pack- LaTeX provides several environments for quoting text;
age. The extra functionality it provides is that it can add they have small differences and they are aimed for dif-
line numbers along side the text. The command: \be- ferent types of quotations. All of them are indented on
gin{listing}[step]{first line}. The mandatory first line ar- either margin, and you will need to add your own quota-
gument is for specifying which line the numbering shall tion marks if you want them. The provided environments
commence. The optional step is the step between num- are:
bered lines (the default is 1, which means every line will
be numbered). quote for a short quotation, or a series of small quotes,
To use this environment, remember to add \usepack- separated by blank lines.
age{moreverb} to the document preamble.
quotation for use with longer quotations, of more than
one paragraph, because it indents the first line of
Multiline comments each paragraph.

verse is for quotations where line breaks are important,


As we have seen, the only way LaTeX allows you to add
such as poetry. Once in, new stanzas are created
comments is by using the special character %, that will
with a blank line, and new lines within a stanza are
comment out all the rest of the line after itself. This
indicated using the newline command, \\. If a line
approach is really time-consuming if you want to insert
takes up more than one line on the page, then all sub-
long comments or just comment out a part of your docu-
sequent lines are indented until explicitly separated
ment that you want to improve later, unless you're using
with \\.
an editor that automates this process. Alternatively, you
can use the verbatim package, to be loaded in the pream-
ble as usual: Abstracts
(you can also use the comment package instead) you can
use an environment called comment that will comment In scientific publications it is customary to start with an
out everything within itself. Here is an example: abstract which gives the reader a quick overview of what
to expect. See Document Structure.
Note that this won’t work inside complex environments,
like math for example. You may be wondering, why
should I load a package called verbatim to have the pos- 2.3.7 Notes and References
sibility to add comments? The answer is straightforward:
commented text is interpreted by the compiler just like This page uses material from Andy Roberts’ Getting to grips
verbatim text, the only difference is that verbatim text is with LaTeX with permission from the author.
introduced within the document, while the comment is
just dropped.
Alternatively, you can define a \comment{} command, by 2.4 Colors
adding the following to the document’s preamble:
Then, to comment out text, simply do something like this: Adding colors to your text is supported by the color pack-
age. Using this package, you can set the font color, text
This approach can, however, produce unwanted spaces in background, or page background. You can choose from
the document, so it may work better to use 230 predefined colors or can define your own colors using
Then if you supply only one argument to \comment{}, RGB, Hex, or CMYK codes. Mathematical formulas can
this has the desired effect without producing extra spaces. also be colored.
2.4. COLORS 27

2.4.1 Adding the color package If you would like a color not pre-defined, you can use one
of the 68 dvips colors, or define your own. These options
To make use of these color features the color package are discussed in the following sections
must be inserted into the preamble.
Alternatively, one can write: The 68 standard colors known to dvips
The \usepackage is obvious, but the initialization of addi-
tional commands like usenames allows you to use names Invoke the package with the usenames and dvipsnames
of the default colors, the same 16 base colors as used in option. If you are using tikz or pstricks package you must
HTML. The dvipsnames allows you access to more col- declare the xcolor package before that, otherwise it will
ors, another 64, and svgnames allows access to about 150 not work.
colors. The initialization of “table” allows colors to be
added to tables by placing the color command just before
the table. The package loaded here is the xcolor package. 2.4.5 Defining new colors
If you need more colors, then you may also want to look at
If the predefined colors are not adequate, you may wish
adding the x11names to the initialization section as well,
to define your own.
this offers more than 300 colors, but you need to make
sure your xcolor package is the most recent you can down-
load. Place

Define the colors in the preamble of your document.


2.4.2 Entering colored text (Reason: do so in the preamble, so that you can already
refer to them in the preamble, which is useful, for in-
The simplest way to type colored text is by: stance, in an argument of another package that supports
where declared-color is a color that was defined before by colors as arguments, such as the listings package.)
\definecolor.
Another possible way by Method
that will switch the standard text color to the color you
want. It will work until the end of the current TeX group. You need to include the xcolor package in your preamble
For example: to define new colors. In the abstract, the colors are defined
following this scheme:
The difference between \textcolor and \color is the same
as that between \texttt and \ttfamily, you can use the one where:
you prefer. The \color environment allows the text to run
over multiple lines and other text environments whereas • name is the name of the color; you can call it as you
the text in \textcolor must all be one paragraph and not like
contain other environments.
• model is the way you describe the color, and is one
You can change the background color of the whole page
of gray, rgb, RGB, HTML, and cmyk.
by:
• color-spec is the description of the color
2.4.3 Entering colored background for the
text Color Models

If the background color and the text color is changed, Among the models you can use to describe the color are
then: the following (several more are described in the xcolor
manual):
There is also \fcolorbox to make framed background
color in yet another color:
Examples
2.4.4 Predefined colors To define a new color, follow the following example,
which defines orange for you, by setting the red to the
The predefined color names are maximum, the green to one half (0.5), and the blue to the
white, black, red, green, blue, cyan, magenta, yellow. minimum:
There may be other pre-defined colors on your system, The following code should give a similar results to the last
but these should be available on all systems. code chunk.
28 CHAPTER 2. COMMON ELEMENTS

If you loaded the xcolor package, you can define colors • The color package documentation
upon previously defined ones.
The first specifies 20 percent blue and 80 percent white;
the second is a mixture of 20 percent blue and 80 percent 2.5 Fonts
black; and the last one is a mixture of (20*0.3) percent
blue, ((100-20)*0.3) percent black and (100-30) percent Fonts are a complex topic. For common documents, only
green. Font families, Emphasizing text, and Font encoding are
xcolor also feature a handy command to define colors really needed. The other sections are more useful to
from color mixes: macro writers or for very specific needs.

Using color specifications directly 2.5.1 Introduction


Normally one would predeclare all the colors as above, The digital fonts have a long and intricate history. See
but sometimes it is convenient to directly use a color with- Adobe Font Metrics for some more details.
out naming it first. To achieve this, \color and \textcolor
Originally TeX was conceived to use its own font system,
have an alternative syntax specifying the model in square
MetaFont, designed by D. Knuth. The default font family
brackets, and the color specification in curly braces. For
for TeX and friends is called Computer Modern. These
example:
high quality fonts are scalable, and have a wide range of
typographical fine tuning capabilities.
Creating / Capturing colors Standard tex compilers will let you use other fonts.
There are many different font types, such as PostScript
You may want to use colors that appear on another doc- Type1/Type3 fonts and bitmap fonts. Type1 are outline
ument, web pages, pictures, etc. Alternatively, you may fonts (vector graphics) which are commonly used by pdf-
want to play around with rgb values to create your own tex. Bitmap fonts are raster graphics, and usually have
custom colors. very poor quality, which can easily be seen when zoom-
Image processing suites like the free GIMP suite for ing or printing a document. Type3 is a superset of Type1
Linux/Windows/Mac offer color picker facilities to cap- and has more functionalities from Postscript, such as em-
ture any color on your screen or synthesize colors directly bedding raster graphics. In the TeX world, Type3 fonts
from their respective rgb / hsv / hexadecimal values. are often used to embed bitmap fonts.
Smaller, free utilities also exist: It should be noticed that fonts get generated the first time
they are required, hence the long compilation time.
• Linux/BSD: The gcolor2 tool (usually also available However, MetaFont is internally a quite complex font sys-
in repositories) tem, and the most popular font systems as of this day are
Truetype font (ttf) and OpenType font (otf). With mod-
• Microsoft Windows: The open-source Color Selec- ern TeX compilers such as xetex and luatex it is possible
tor tool. to make use of such fonts in LaTeX documents. If you
• Apple Macs: Hex Color Picker for creating custom want/have to stick with the standard compilers, the afore-
colors and the built-in DigitalColor Meter for cap- mentioned font types must first be converted and made
turing colors on screen. available to LaTeX (e.g. converted to Type1 fonts). The
external links section below has some useful resources.
• Online utilities: See here for a Wikipedia article
In LaTeX, there are many ways to specify and control
with several external links
fonts. It is a very complex matter in typography.

Spot colors
2.5.2 Font families
Spot colors are customary in printing. They usually re-
fer to pre-mixed inks based on a swatchbook (like Pan- There are many font families e.g. Computer Modern,
tone, TruMatch or Toyo). The package colorspace ex- Times, Arial and Courier. Those families can be grouped
tends xcolor to provide real spot colors. They are defined into three main categories: roman (rm) or serif, sans serif
with, say: (sf) and monospace (tt) (see Typeface for more details).
Each font family comes with the default design which falls
into one of those categories; however, it is interchange-
2.4.6 Sources able among them. Computer Modern Roman is the de-
fault font family for LaTeX. Fonts in each family also have
• The xcolor manual different properties (size, shape, weight, etc.). Families
2.5. FONTS 29

are meant to be consistent, so it is highly discouraged to Typewriter Fonts Furthermore, the Bera Mono (Bit-
change fonts individually rather than the whole family. Stream Vera Mono) and LuxiMono fonts were designed
The three families are defined by their respective vari- to look good when used in conjunction with the Com-
ables: puter Modern serif font.
\usepackage[scaled=0.85]{beramono}
• \rmdefault

• \sfdefault Cursive Fonts Since LaTeX has no generic family


group for cursive fonts, these fonts are usually assigned
• \ttdefault to the roman family.

The default family is contained in the \familydefault vari- Mathematical Formula Fonts
able, and it is meant to have one of the three aforemen-
tioned variables as value. The default is defined like the
following assignment: 2.5.4 Emphasizing text
This will turn all the part of the document using the de-
fault font to the default sans serif, which is Computer In order to add some emphasis to a word or a phrase, the
Modern Sans Serif if you did not change the default font. simplest way is to use the \emph{text} command, which
usually italicizes the text. Italics may be specified explic-
Changing font families usually works in two steps:
itly with \textit{text}.

1. First specify which family you want to change (rm, Note that the \emph command is dynamic: if you empha-
sf or tt). size a word which is already in an emphasized sentence,
it will be reverted to the upright font.
2. Second specify the new default family if it is not rm. Text may be emphasized more heavily through the use
of boldface, particularly for keywords the reader may be
Mathematical fonts is a more complex matter. Fonts may trying to find when reading the text. As bold text is gen-
come with a package that will take care of defining all erally read before any other text in a paragraph or even on
three families plus the math fonts. You can do it by your- a page, it should be used sparingly. It may also be used in
self, in which case you do not have to load any package. place of italics when using sans-serif typefaces to provide
a greater contrast with unemphasized text. Bold text can
Below is an example[1] that demonstrates how to change
be generated with the \textbf{text} command.
a specific family.
The three default family font variables and the \familyde-
fault variable should not be confused with their respective 2.5.5 Font encoding
switch:
A character is a sequence of bytes, and should not be con-
• \normalfont fused with its representation, the glyph, which is what the
reader sees. So the character 'a' has different represen-
• \rmfamily tations following the used font, for example the upright
version, the italic version, various weights and heights,
• \sffamily and so on.

• \ttfamily Upon compilation, tex will have to choose the right font
glyph for every character. This is what is called font en-
coding. The default LaTeX font encoding is OT1, the en-
2.5.3 Available LaTeX Fonts [2] coding of the original Computer Modern TeX text fonts.
It contains only 128 characters, many from ASCII, but
To choose a font of your liking, please visit http://www. leaving out some others and including a number that are
tug.dk/FontCatalogue/. Here are some common exam- not in ASCII. When accented characters are required,
ples. TeX creates them by combining a normal character with
an accent. While the resulting output looks perfect, this
Below are some fonts which are installed by default. approach has some caveats.

Serif Fonts • It stops the automatic hyphenation from working in-


side words containing accented characters.

Sans Serif Fonts • Searches for words with accents in PDFs will fail.
30 CHAPTER 2. COMMON ELEMENTS

• Extracting ('e.g.' copy paste) the umlaut 'Ä' via a files. So it is possible to build a new font family by spec-
PDF viewer actually extracts the two characters '"A'. ifying the font styles of different font families.

• Besides, some of Latin letters could not be created


by combining a normal character with an accent, Shapes
to say nothing about letters of non-Latin alphabets,
such as Greek or Cyrillic. The following table lists the commands you will need to
access the typical font shapes:

To overcome these shortcomings, several 8-bit CM-like The commands in column two are not entirely equiva-
font sets were created. Extended Cork (EC) fonts in T1 lent to the commands in column one: They do not cor-
encoding contains letters and punctuation characters for rect spacing after the selected font style has ended. The
most of the European languages based on Latin script. commands in column one are therefore in general recom-
The LH font set contains letters necessary to typeset doc- mended.
uments in languages using Cyrillic script. Because of You may have noticed the absence of underline. This is
the large number of Cyrillic glyphs, they are arranged because underlining is not recommended for typographic
into four font encodings—T2A, T2B, T2C, and X2. The reasons (it weighs the text down). You should use emph
CB bundle contains fonts in LGR encoding for the com- instead. However underlining text provides a useful extra
position of Greek text. By using these fonts you can form of emphasis during the editing process, for exam-
improve/enable hyphenation in non-English documents. ple to draw attention to changes. Although underlining
Another advantage of using new CM-like fonts is that is available via the \underline{...} command, text under-
they provide fonts of CM families in all weights, shapes, lined in this way will not break properly. This function-
and optically scaled font sizes. ality has to be added with the ulem (underline empha-
All this is not possible with OT1; that’s why you may want sis) package. Stick \usepackage{ulem} in your pream-
to change the font encoding of your document. ble. By default, this overrides the \emph command with
the underline rather than the italic style. It is unlikely
Note that changing the font encoding will have some re- that you wish this to be the desired effect, so it is better
quirements over the fonts being used. The default Com- to stop ulem taking over \emph and simply call the under-
puter Modern font does not support T1. You will need line command as and when it is needed.
Computer Modern Super (cm-super) or Latin Modern
(lmodern), which are Computer Modern-like fonts with
T1 support. If you have none of these, it is quite frequent • To restore the usual \emph formatting, add
(depends on your TeX installation) that tex chooses a \normalem straight after the document envi-
Type3 font such as the Type3 EC, which is a bitmap font. ronment begins. Alternatively, use \usepack-
Bitmap fonts look rather ugly when zoomed or printed. age[normalem]{ulem}.

The fontenc package tells LaTeX what font encoding to • To underline, use \uline{...} along with \usepack-
use. Font encoding is set with: age[normalem]{ulem}..
where encoding is the font encoding. It is possible to load • To add a wavy underline, use \uwave{...} along with
several encodings simultaneously. \usepackage[normalem]{ulem}..
There is nothing to change in your document to use CM
Super fonts (assuming they are installed), they will get • For a strike-out (strikethrough), use \sout{...} along
loaded automatically if you use T1 encoding. For lmod- with \usepackage[normalem]{ulem}..
ern, you will need to load the package after the T1 en-
• For a slash through each individual char-
coding has been set:
acter \xout{...} along with \usepack-
The package ae (almost European) is obsolete. It pro- age[normalem]{ulem}.
vided some workarounds for hyphenation of words with
special characters. These are not necessary any more with
Some font styles are not compatible one with the other.
fonts like lmodern. Using the ae package leads to text en-
But some extra packages will fill this hole. For bold small
coding problems in PDF files generated via pdflatex (e.g.
capitals, you might want to use:
text extraction and searching), besides typographic issues.

Sizing text
2.5.6 Font styles
To apply different font sizes, simply follow the commands
Each family has its own font characteristics (such as italic on this table:
and bold), also known as font styles, or font properties. These commands change the size within a given scope, so
Font styles are usually implemented with different font for instance {\Large some words} will change the size of
2.5. FONTS 31

only some words, and does not affect the font in the rest 2.5.8 Arbitrary font size
of the document. It will work for most parts of the text.
These commands cannot be used in math mode. How- The \tiny...\Huge commands are often enough for most
ever, part of a formula may be set in a different size by contents. These are fixed sizes however. In most docu-
using an \mbox command containing the size command. ment processors, you can usually choose any size for any
The new size takes effect immediately after the size com- font. This is because the characters actually get magni-
mand; if an entire paragraph or unit is set in a certain fied. If it usually looks correct for medium sizes, it will
size, the size command should include the blank line or look odd at extreme sizes because of an unbalanced thick-
the \end{...} which delimits the unit. ness. In TeX it is possible to change the magnification of
anything, but highly discouraged for the aforementioned
The default for \normalsize is 10 point (option 10pt), but reason. Changing the font size is made by changing the
it may differ for some Document Styles or their options. font file. Yes, there is a file for every size: cmr10 for
The actual size produced by these commands also de- Computer Modern Roman 10pt, cmr12 for Computer
pends on the Document Style and, in some styles, more Modern Roman 12pt, etc. This ensure the characters
than one of these size commands may produce the same are correctly balanced and remain readable at all defined
actual size. sizes.
Note that the font size definitions are set by the docu- You may choose a particular font size with the \font-
ment class. Depending on the document style the actual size{<size>}{<line space>} command. Example:
font size may differ from that listed above. And not every
document class has unique sizes for all 10 size commands. If you are using the default Computer Modern font with
OT1 encoding, you may get the following message:
As a technical note, points in TeX follow the standard
American point size in which 1 pt is approximately LaTeX Font Warning: Font shape `OT1/cmr/m/n' in size
0.35136 mm. The standard point size used in most mod- <142.26378> not available (Font) size <24.88> substi-
ern computer programs (known as the desktop publish- tuted on input line 103.
ing point or PostScript point) has 1 pt equal to approx- In that case you will notice that the font size cannot be
imately 0.3527 mm while the standard European point changed beyond \tiny and \Huge. You must switch to a
size (known as the Didot point) had 1 pt equal to approx- more sizable font, e.g.
imately 0.37597151 mm (see: point (typography)).

2.5.9 Finding fonts


2.5.7 Local font selection
You will find a huge font directory along examples and
You can change font for a specific part of the text. There configurations at TUG Font Catalogue.
are four font properties you can change.

\fontencoding The font encoding, such as OT1 (TeX 2.5.10 Using arbitrary system fonts
default) or T1 (extended characters support, better
PDF support, widely used). If you use the XeTeX or LuaTeX engine and the fontspec
\fontfamily The font family. package, you'll be able to use any font installed in the
system effortlessly. XeTeX also allows using OpenType
\fontseries The series: l=light, m=medium, b=bold, technology of modern fonts like specifying alternate
bx=very bold. glyphs and optical size variants. XeTeX also uses
Unicode by default, which might be helpful for font is-
\fontshape The shape: it=italic, n=normal, sl=slanted,
sues.
sc=small capitals.
To use the fonts, simply load the fontspec package and set
The \selectfont command is mandatory, otherwise the the font:
font will not be changed. It is highly recommended to Then compile the document with xelatex or lualatex.
enclose the command in a group to cleanly return to the Note that you can only generate .pdf files, and that you
previous font selection when desired. need a sufficiently new TeX distribution (TeX Live 2009
You can use all these commands in a row: should work for XeTeX and Tex Live 2010 for LuaTeX).
Also you should not load the inputenc or fontenc pack-
The default values are stored in \encodingdefault, \fam- age. Instead make sure that your document is encoded as
ilydefault, \seriesdefault and \shapedefault. Setting back UTF-8 and load fontspec, which will take care of the font
the default font properties can be done with encoding. To make your document support both pdfla-
For short, you can use the \use- tex and xelatex/lualatex you can use the \ifxetex/ \ifluatex
font{<encoding>}{<family>}{<series>}{<shape>} macro from the ifxetex/ ifluatex package. For example
command. for xelatex
32 CHAPTER 2. COMMON ELEMENTS

2.5.11 PDF fonts and properties 2.6 List Structures


PDF documents have the capability to embed font files. It Convenient and predictable list formatting is one of the
makes them portable, hence the name Portable Document many advantages of using LaTeX. Users of WYSIWYG
Format. word processors can sometimes be frustrated by the soft-
Many PDF viewers have a Properties feature to list em- ware’s attempts to determine when they intend lists to be-
bedded fonts and document metadata. gin and end. As a mark-up language, LaTeX gives more
control over the structure and content of lists.
Many Unix systems make use of the poppler tool set
which features pdfinfo to list PDF metadata, and pdffonts
to list embedded fonts. 2.6.1 List structures
Lists often appear in documents, especially academic, as
2.5.12 Useful websites their purpose is often to present information in a clear
and concise fashion. List structures in LaTeX are sim-
• The Latex Font Catalogue ply environments which essentially come in three flavors:
itemize, enumerate and description.
• LaTeX font commands All lists follow the basic format:
All three of these types of lists can have multiple para-
• How to change fonts in Latex
graphs per item: just type the additional paragraphs in the
normal way, with a blank line between each. So long as
• Understanding the world of TEX fonts and master-
they are still contained within the enclosing environment,
ing the basics of fontinst
they will automatically be indented to follow underneath
their item.
• Font installation the shallow way “For one-off
projects, you can cut corners with font installation
(i.e. fontinst) and end up with a more manageable set Itemize
of files and a cleaner TEX installation. This article
shows how and why” This environment is for your standard bulleted list of
items.

TrueType (ttf) fonts


Enumerate
• Step-by-step guide to manually install a ttf-font for
The enumerate environment is for ordered lists, where by
PdfTeX
default, each item is numbered sequentially.
• A bash script for installing a LaTeX font family
(MikTeX / TeXLive) Description

• LaTeX And TrueType Font The description environment is slightly different. You
can specify the item label by passing it as an optional ar-
• True Type Fonts with LaTeX under Linux + MiK- gument (although optional, it would look odd if you didn't
TeX 2.5 include it!). Ideal for a series of definitions, such as a
glossary.
• Unicode Truetype font installer for LaTeX under
Sometimes you want a description where the text begins
Windows + MikTeX
on a new line. This cannot easily be done with \\. The
trick is to use \hfill[1] .
• Using TrueType fonts with TeX (LaTeX) and pdf-
TeX (pdfLaTeX) (for MikTeX)
2.6.2 Nested lists
2.5.13 References LaTeX will happily allow you to insert a list environment
into an existing one (up to a depth of four—if you need
[1] found at the Google discussion group latexlovers more than four, use the easylist package). Simply begin
the appropriate environment at the desired point within
[2] Taken from http://www.macfreek.nl/memory/Fonts_in_ the current list. Latex will sort out the layout and any
LaTeX numbering for you.
2.6. LIST STRUCTURES 33

2.6.3 Customizing lists use any of the style tokens as text they can be en-
closed in braces, e.g. {A} will give a literal A.
Customizing LaTeX is outside the beginners’ domain. <ref ftp://tug.ctan.org/ctan/macros/latex/required/tools/
While not necessarily difficult in itself, because beginners enumerate.pdf> CTAN documentation for enumer-
are already overwhelmed with the array of commands and ate</ref>
environments, moving on to more advanced topics runs Sometimes you may want to place some short text in front
the risk of confusion. of the enumeration for example: “Exercise 1, Exercise 2,
However, since the tutorial aims at being complete, we Execise 3, ...”. This is possible with the enumitem pack-
shall still include a brief guide on customizing lists. Feel age:
free to skip! \bfseries makes it bold, Exercise is the text and \arabic*
Note that in the following when \renewcommand is used inserts the counter followed by a colon (:) which is treated
it must appear after the \begin{document} instruction so as text again.
the changes made are taken into account. This is needed
for both enumerated and itemized lists.
Manually To go any further and do it yourself instead,
Also beware of the spaces in the label definitions. It is a a brief introduction to LaTeX counters is required. You
common error! should check the dedicated chapter as we will not delve
into the details for now.
Line spacing There are four individual counters that are associated with
itemized lists, each one represents the four possible levels
As you may have noticed, in standard LaTeX document of nesting, which are called:
classes, the vertical spacing between items, and above and The counter is incremented by \item before it is printed.
below the lists as a whole, is more than between para- For example to reset enumi use:
graphs: it may look odd if the descriptions are too short.
The command responsible for formatting the various lev-
els of nesting are
Using packages If you want tightly-packed lists, use Example:
the mdwlist package (included in the mdwtools bundle),
This simply redefines the appearance of the label, which is
which provides compact, “starred” versions of the previ-
fine, providing that you do not intend to cross-reference to
ous environments, i.e. itemize*, enumerate* and descrip-
a specific item within the list, in which case the reference
tion*. They work exactly in the same way, but the output
will be printed in the original format. This issue does not
is more compact. Other packages providing compacted
arise if you redefine the counter printer:
lists are paralist and enumitem.
Alternatively, use the memoir class and with \tightlists.
Customizing itemized lists

Customizing manually Inside lists you can redefine Itemized lists are not as complex as they do not need
some length/dimension variables of LaTeX, for example to count. Therefore, to customize, you simply change
using: the labels. It can be done manually for each entry with
Alternatively, to create a unified look in your document \item[new symbol], eg \item[$\star$].
you can redefine the enumerate environment: The itemize labels are accessed via \labelitemi, \la-
Another approach is to redefine the \item command glob- belitemii, \labelitemiii, \labelitemiv, for the four respec-
ally. tive levels.
The above example would set the labels for the first level
to a greater than (>) symbol. Of course, the text symbols
Customizing enumerated lists available in Latex are not very exciting. Why not use one
of the ZapfDingbat symbols, as described in the Symbols
Using packages The thing people want to change most section. Or use a mathematical symbol:
often with Enumerated lists are the counters. A quick so-
Itemized list with tightly set items, that is with no vertical
lution to this problem is provided by the enumerate pack-
space between two consecutive items, can be created as
age of David Carlisle[2] , or the more sophisticated pack-
follows.
age enumitem by Javier Bezos[3] . When using enumerate,
it is possible to specify the style of the numbering: \be-
gin{enumerate}[style].
2.6.4 Inline lists
The options A, a, I, i and 1 define the style and are
self-explanatory, anything else is treated as text. To Inline lists can be achieved as follows.
34 CHAPTER 2. COMMON ELEMENTS

With package paralist The FinalMark parameter sets the punctuation of the fi-
nal counter (Ex: FinalMark3={)}) while FinalSpace sets
The paralist package provides the inparaenum environ- the amount of space between the item and the item’s text.
ment (with an optional formatting specification in square The Margin parameter sets the distance from the left mar-
brackets): gin (Ex: FinalSpace2=1cm). The Progressive parameter
To change the styles of the counter, tokens A, a, I, i, and sets the distance from the left margin of all items in pro-
1 can be used in the optional argument to produce the portion to their level.
counter with one of the styles \Alph, \alph, \Roman, \ro- The {{{1}}} parameter prevents the first n counters from
man and \arabic. For example: \begin{inparaenum}[(i)] appearing in all levels. If there is a number after a param-
produces the labels (i), (ii), (iii) ... eter (Ex: Style3*) then this numbers indicates the level
that it will affect (Ex: Style3=\color{red}).

With package enumitem Example of custom enumerate:


Note that we put the FinalMark argument between {} to
Package shortlst also provides inline lists. avoid LaTeX understanding it as the end of the proper-
ties list. Now we change the default properties to print a
custom itemize:
2.6.5 Easylist package
Spaces in Style parameters are important. The Style*
The easylist package <ref ftp://ctan.tug.org/tex-archive/ parameter acts as a default value and easylist will use a
macros/latex/contrib/easylist/easylist-doc.pdf>easylist medium dash for level 1, 5 and onward.
documentation</ref> allows you to create list using a You can also define custom styles using LaTeX macros:
more convenient syntax and with infinite nested levels. It
Important note: easylist has some drawbacks. First if you
is also very customizable.
need to put an easylist inside an environment using the
Load the package with the control character as optional same control character as the one specified for easylist,
argument: you may get an error. To circumvent it, use the following
The easylist environment will default to enumerations. commands provided by easylist:

It features predefined styles which you can set as optional Besides using easylist along with figures may cause some
argument. trouble to the layout and the indentation. LaTeX lists do
not have this problem.
Available styles:
To use easylist with Beamer, each frame that uses easylist
must be marked as fragile:
• tractatus

• checklist - All items have empty check boxes next


2.6.6 Notes and references
to them

• booktoc - Approximately the format used by the ta- [1] http://www.tex.ac.uk/cgi-bin/texfaq2html?label=noline


ble of contents of the book class [2] The enumerate package, David Carlisle 1999
• articletoc - Approximately the format used by the [3] The enumitem package, Javier Bezos 2011
table of contents of the article class

• enumerate - The default


2.7 Special Characters
• itemize
In this chapter we will tackle matters related to input en-
You can customize lists with the \ListProperties(...) com- coding, typesetting diacritics and special characters.
mand and revert back the customization with \newlist{}.
Yes, that’s parentheses for \ListProperties parameters. In the following document, we will refer to special char-
acters for all symbols other than A-Za-z0-9 and English
The Style parameter sets the style of counters and text, punctuation marks.
the Style* parameter sets the sytle of counters, and the
Style** parameter sets the style of text. The parameter This chapter is tightly linked with the font encoding issue.
Numbers determines the way that the numbers are dis- You should have a look at Fonts on the topic.
played and the possible values are r or R (for lower and Some languages usually need a dedicated input system to
upper case Roman numerals), l or L (for lower and upper ease document writing. This is the case for Arabic, Chi-
case letters), a (for Arabic numbers, the default), and z nese, Japanese, Korean and others. This specific matter
(for Zapf’s Dingbats). will be tackled in Internationalization.
2.7. SPECIAL CHARACTERS 35

The rules for producing characters with diacritical marks, cents in it, since both encoding are ASCII superset they
such as accents, differ somewhat depending whether you encode the classic letters the same way. There aren't
are in text mode, math mode, or the tabbing environment. many advantages in using Latin1 over UTF-8, which is
technically superior. UTF-8 is also becoming the most
widely used encoding (on the Web, in modern Unices,
2.7.1 Input encoding etc.).

A technical matter
Dealing with LaTeX
Most of the modern computer systems allow you to input
TeX uses ASCII by default. But 128 characters is not
letters of national alphabets directly from the keyboard. If
enough to support non-english languages. TeX has its
you tried to input these special characters in your LaTeX
own way to do that with commands for every diacritical
source file and compiled it, you may have noticed that
marking (see Escaped codes). But if we want accents and
they do not get printed at all.
other special characters to appear directly in the source
A LaTeX source document is a plain text file. A computer file, we have to tell TeX that we want to use a different
stores data in a binary format, that is a sequence of bits encoding.
(0 and 1). To display a plain text file, we need a code
There are several encodings available to LaTeX:
which tells which sequence of bits corresponds to which
sequence of characters. This association is called input
encoding, character encoding, or more informally charset. • ASCII: the default. Only bare english characters are
supported in the source file.
For historical reasons, there are many different input en-
codings. There is an attempt to unify all the encoding • ISO-8859-1 (a.k.a. Latin 1): 8-bits encoding. It
with a specification that contains all existent symbols that supports most characters for latin languages, but
are known from human history. This specification is Uni- that’s it.
code. It only defines code points, which is a number for a
symbol, but not the way symbols are represented in binary • UTF-8: a Unicode multi-byte encoding. Supports
value. For that, unicode encodings are in charge. There the complete Unicode specification.
are also several unicode encodings available, UTF-8 be-
• Others...
ing one of them.
The ASCII encoding is an encoding which defines 128 In the following we will assume you want to use UTF-8.
characters on 7 bits. Its widespread use has led the vast
majority of encodings to have backward compatibility There are some important steps to specify encoding.
with ASCII, by defining the first 128 characters the same
way. The other characters are added using more bits (8 • Make sure your text editor decodes the file in UTF-
or more). 8.
This is actually a big issue, since if you do not use the • Make sure it saves your file in UTF-8. Most text
right encoding to display a file, it will show weird charac- editors do not make the distinction, but some do,
ters. What most programs try to do is guess statistically such as Notepad++.
the encoding by analyzing the frequent sequences of bits.
Sadly, it is not 100% safe. Some text editors may not • If you are working in a terminal, make sure it is set
bother guessing the encoding and will just use the OS to support UTF-8 input and output. Some old Unix
default encoding. You should consider that other people terminals may not support UTF-8. PuTTY is not set
might not be able to display directly your input files on to use UTF-8 by default, you have to configure it.
their computer, because the default encoding for text file
• Tell LaTeX that the source file is UTF-8 encoded.
is different. It does not mean that the user cannot use an-
other encoding, besides the default one, only that it has
to be configured. For example, the German umlaut ä on inputenc [2] package tells LaTeX what the text encoding
OS/2 is encoded as 132, with Latin1 it is encoded as 228, format of your .tex files is.
while in Cyrillic encoding cp1251 this letter does not ex- The inputenc package allows as well the user to change
ist at all. Therefore you should consider encoding with the encoding within the document by means of the com-
care. mand \inputencoding{'encoding name'}.
The following table shows the default encodings for some
operating systems.
Extending the support
UTF-8 and Latin1 are not compatible. It means that if
you try to open a Latin1-encoded file using a UTF-8 de- The LaTeX support of UTF-8 is fairly specific: it includes
coding, it will display odd symbols only if you used ac- only a limited range of unicode input characters. It only
36 CHAPTER 2. COMMON ELEMENTS

defines those symbols that are known to be available with ier coding of umlauts, the babel package can be config-
the current font encoding. You might encounter a situa- ured as \usepackage[german]{babel}. This provides the
tion where using UTF-8 might result in error: short hand “o for \"o. This is very useful if one needs to
! Package inputenc Error: Unicode char \u8:ũ not set up use some text accents in a label, since no backslash will
for use with LaTeX. be accepted otherwise.

This is due to the utf8 definition not necessarily having a More information regarding language configuration can
be found in the Internationalization section.
mapping of all the character glyphs you are able to enter
on your keyboard. Such characters are for example
ŷŶũŨẽẼĩĨ 2.7.3 Less than < and greater than >
In such case, you may try need to use the utf8x option
to define more character combinations. utf8x is not offi- The two symbols '<' and '>' are actually ASCII charac-
cially supported, but can be viable in some cases. How- ters, but you may have noticed that they will print '¡' and
ever it might break up compatibility with some packages '¿' respectively. This is a font encoding issue. If you want
like csquotes. them to print their real symbol, you will have to use an-
other font encoding such as T1, loaded with the fontenc
Another possiblity is to stick with utf8 and to define the
package. See Fonts for more details on font encoding.
characters yourself. This is easy:
Alternatively, they can be printed with dedicated com-
where codepoint is the unicode codepoint of the desired
mands:
character. TeX sequence is what to print when the char-
acter matching the codepoint is met. You may find code-
points on this site. Codepoints are easy to find on the web.
Example: 2.7.4 Euro € currency symbol
Now inputting 'ŷ' will effectively print 'ŷ'. When writing about money these days, you need the euro
With XeTeX and LuaTeX the inputenc package is no sign. The textcomp package features a \texteuro com-
longer needed. Both engines support UTF-8 directly and mand which gives you the euro symbol as supplied by
allow the use of TTF and OpenType fonts to support Uni- your current text font. Depending on your chosen font
code characters. See the Fonts section for more informa- this may be quite far from the official symbol.
tion. An official version of the euro symbol is provided by eu-
rosym. Load it in the preamble (optionally with the offi-
cial option):
2.7.2 Escaped codes
then you can insert it with the \euro{} command. Finally,
In addition to direct UTF-8 input, LaTeX supports the if you want a euro symbol that matches with the current
composition of special characters. This is convenient if font style (e.g., bold, italics, etc.) you can use a different
your keyboard lacks some desired accents and other dia- option:
critics. again you can insert the euro symbol with \euro{}.
The following accents may be placed on letters. Although Alternatively you can use the marvosym package which
'o' letter is used in most of the examples, the accents may also provides the official euro symbol.
be placed on any letter. Accents may even be placed
above a “missing” letter; for example, \~{} produces a Now that you have succeeded in printing a euro sign, you
tilde over a blank space. may want the '€' on your keyboard to actually print the
euro sign as above. There is a simple method to do that.
The following commands may be used only in paragraph You must make sure you are using UTF-8 encoding along
(default) or LR (left-right) mode. with a working \euro{} or \EUR{}command.
To place a diacritic on top of an i or a j, its dot has to be Complete example:
removed. The dotless version of these letters is accom-
plished by typing \i and \j. For example:
2.7.5 Degree symbol for temperature and
• \^\i should be used for i circumflex 'î';
math
• \"\i should be used for i umlaut 'ï'.
The easiest way to print temperature and angle values is
If a document is to be written completely in a language to use the \SI{value}{unit} command from the siunitx
that requires particular diacritics several times, then using package, which works both in text and math mode:
the right configuration allows those characters to be writ- For more information, see the documentation of the siu-
ten directly in the document. For example, to achieve eas- nitx package.
2.7. SPECIAL CHARACTERS 37

A common mistake is to use the \circ command. It will 2.7.7 In special environments
not print the correct character (though $^\circ$ will). Use
the textcomp package instead, which provides a \textde- Math mode
gree command.
For temperature, you can use the same command or opt Several of the above and some similar accents can also be
for the gensymb package and write produced in math mode. The following commands may
be used only in math mode.
Some keyboard layouts feature the degree symbol, you
can use it directly if you are using UTF-8 and textcomp. When applying accents to letters i and j, you can use
For better results (font quality) we recommend the use of \imath and \jmath to keep the dots from interfering with
an appropriate font, like lmodern: the accents:

Tabbing environment
2.7.6 Other symbols
Some of the accent marks used in running text have other
LaTeX has many symbols at its disposal. The majority of uses in the tabbing environment. In that case they can be
them are within the mathematical domain, and later chap- created with the following command:
ters will cover how to get access to them. For the more
common text symbols, use the following commands: • \a' for an acute accent
Not mentioned in above table, tilde (~) is used in LaTeX
• \a` for a grave accent
code to produce non-breakable space. To get printed tilde
sign, either write \~{} or \textasciitilde{}. And a visible • \a= for a macron accent
space ␣ can be created with \textvisiblespace.
For some more interesting symbols, the Postscript ZipfD-
ingbats font is available thanks to the pifont package. Add 2.7.8 Unicode keyboard input
the declaration to your preamble: \usepackage{pifont}.
Next, the command \ding{number}, will print the speci- Some operating systems provide a keyboard combination
fied symbol. Here is a table of the available symbols: 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 ap-
pear. Type the code point and press enter or space to
actually print the character. Example:
<Ctrl+Shift+u> 20AC <space>
will print the euro character.
Desktop environments like GNOME and KDE may fea-
ture a customizable compose key for more memorizable
sequences.
Xorg features advanced keyboard layouts with variants
that let you enter a lot of characters easily with combina-
tion using the aprioriate modifier, 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 modifier.

2.7.9 External links


• A few other LaTeX accents and symbols

• NASA GISS: Accents

• The Comprehensive LATEX Symbol List

• PDF document with a lengthy list of symbols pro-


vided by various packages .
38 CHAPTER 2. COMMON ELEMENTS

2.7.10 Notes and References 2.8.2 Babel

[1] For a quick explanation on character sets, see this article


on Joel Spolski’s blog. The babel package by Johannes Braams and Javier Bezos
will take care of everything (with XeTeX and LuaTeX
[2] For a detailed information on the package, see complete you should consider polyglossia). You can load it in your
specifications written by the package’s authors. preamble, providing as an argument name of the language
you want to use (usually its English name, but not always):
You should place it soon after the \documentclass com-
2.8 Internationalization mand, so that all the other packages you load afterwards
will know the language you are using. Babel will auto-
matically activate the appropriate hyphenation rules for
LaTeX has to be configured and used appropriately when the language you choose. If your LaTeX format does not
it is used to write documents in languages other than En- support hyphenation in the language of your choice, ba-
glish. This has to address three main areas: bel will still work but will disable hyphenation, which has
quite a negative effect on the appearance of the typeset
1. LaTeX needs to know how to hyphenate the lan- document. Babel also specifies new commands for some
guage(s) to be used. languages, which simplify the input of special characters.
See the sections about languages below for more infor-
2. The user needs to use language-specific typographic mation.
rules. In French for example, there is a mandatory If you call babel with multiple languages:
space before each colon character (:).
then the last language in the option list will be active (i.e.
languageB), and you can use the command
3. The input of special characters, especially for lan-
guages using an input system (Arab, Chinese, to change the active language. You can also add short
Japanese, Korean). pieces of text in another language using the command
Babel also offers various environments for entering larger
It is convenient to be able to insert language-specific spe- pieces of text in another language:
cial characters directly from the keyboard instead of us- The starred version of this environment typesets the main
ing cumbersome coding (for example, by typing ä instead text according to the rules of the other language, but
of \"{a}). This can be done by configuring input encod- keeps the language specific string for ancillary things like
ing properly. We will not tackle this issue here: see the figures, in the main language of the document. The envi-
Special Characters chapter. ronment hyphenrules switches only the hyphenation pat-
Some languages require special fonts with the proper font terns used; it can also be used to disallow hyphenation by
encoding set. See Font encoding. using the language name 'nohyphenation' (but note select-
language* is preferred).
Some of the methods described in this chapter may be
useful when dealing with non-English author names in The babel manual provides much more information on
bibliographies. these and many other options.

Here is a collection of suggestions about writing a La-


TeX document in a language other than English. If you
have experience in a language not listed below, please add
some notes about it.

2.8.3 Multilingual versions


2.8.1 Prerequisites
It is possible in LaTeX to typeset the content of one docu-
Most non-english language will need to input special ment in several languages and to choose upon compilation
characters very often. For a convenient writing you will
which language to output. This might be convenient to
need to set the input encoding and the font encoding prop-
keep a consistent sectioning and formatting across the dif-
erly. ferent languages. It is also useful if you make use of mul-
The following configuration is optimal for many lan- tiple proper nouns and other untranslated content. Using
guages (most latin languages). Make sure your document the commands above in multilingual documents can be
is saved using the UTF-8 encoding. cumbersome, and therefore babel provides a way to de-
For more details check Font encoding and Special Char- fine shorter names. With
acters. You can write:
2.8. INTERNATIONALIZATION 39

Alternative choice using iflang texts using Cyrillic letters[1] . Support for Cyrillic is based
on standard LaTeX mechanisms plus the fontenc and
The current language can also be tested by using the iflang inputenc packages. AMS-LaTeX packages should be
package by Heiko Oberdiek (the built-in feature from the loaded before fontenc and babel. If you are going to use
babel package is not reliable). Here comes a simple ex- Cyrillics in mathmode, you also need to load mathtext
ample: package before fontenc:
\IfLanguageName{ngerman}{Hallo}{Hello} Generally, babel will automatically choose the default
font encoding, for the above three languages this is T2A.
This allows to easily distinguish between two languages
However, documents are not restricted to a single font
without the need of defining own commands. The babel
encoding. For multilingual documents using Cyrillic and
language is changed by setting
Latin-based languages it makes sense to include Latin
\selectlanguage{english} font encoding explicitly. Babel will take care of switch-
ing to the appropriate font encoding when a different lan-
guage is selected within the document.
2.8.4 Specific languages
On modern operating systems it is beneficial to use Uni-
Arabic script code (utf8 or utf8x) instead of KOI8-RU (koi8-ru) as an
input encoding for Cyrillic text.
For languages which use the Arabic script, including Ara- In addition to enabling hyphenations, translating automat-
bic, Persian, Urdu, Pashto, Kurdish, Uyghur, etc., add the ically generated text strings, and activating some language
following code to your preamble: specific typographic rules (like \frenchspacing), babel
You can input text in either romanized characters or na- provides some commands allowing typesetting according
tive Arabic script encodings. Use any of the following to the standards of Bulgarian, Russian, or Ukrainian lan-
commands and environments to enter in text: guages.

See the ArabTeX Wikipedia article for further details. For all three languages, language specific punctuation is
provided: the Cyrillic dash for the text (it is little nar-
You may also use the Arabi package within Babel to type- rower than Latin dash and surrounded by tiny spaces), a
set Arabic and Persian dash for direct speech, quotes, and commands to facilitate
You may also copy and paste from PDF files produced hyphenation:
with Arabi thanks to the support of the cmap package. The Russian and Ukrainian options of babel define the
You may use Arabi with LyX, or with tex4ht to produce commands
HTML.
which act like \Alph and \alph (commands for turning
See Arabi page on CTAN counters into letters, e.g. a, b, c...), but produce capi-
tal and small letters of Russian or Ukrainian alphabets
(whichever is the active language of the document).
Armenian
The Bulgarian option of babel provides the commands
The Armenian script uses its own characters, which will which make \Alph and \alph produce letters of either
require you to install a text editor that supports Unicode Bulgarian or Latin (English) alphabets. The default be-
and will allow you to enter UTF-8 text, such as Texmaker haviour of \Alph and \alph for the Bulgarian language op-
or WinEdt. These text editors should then be configured tion is to produce letters from the Bulgarian alphabet.
to compile using XeLaTeX.
See the Bulgarian translation of “The Not So Short Intro-
Once the text editor is set up to compile with XeLaTeX, duction to LaTeX” [2] for a method to type Cyrillic letters
the fontspec package can be used to write in Armenian: directly from the keyboard using a different distribution.
or
The Sylfaen font lacks italic and bold, but DejaVu Serif
supports them. Chinese

See Armenian Wikibooks for further details, especially One possible Chinese support is made available thanks to
on how to configure the Unicode supporting text editors the CJK package collection. If you are using a package
to compile with XeLaTeX. manager or a portage tree, the CJK collection is usually
in a separate package because of its size (mainly due to
Cyrillic script fonts).
Make sure your document is saved using the UTF-8 char-
Version 3.7h of babel includes support for the T2* encod- acter encoding. See Special Characters for more details.
ings and for typesetting Bulgarian, Russian and Ukrainian Put the parts where you want to write chinese characters
40 CHAPTER 2. COMMON ELEMENTS

in a CJK environment. ! Package inputenc Error: Unicode char \u8:° not set up
The last argument specifies the font. It must fit the desired for use with LaTeX.
language, since fonts are different for Chinese, Japanese The textcomp package will fix it for you.
and Korean. Possible choices for Chinese include: The great advantage of Babel for French is that it will
handle some elements of French typography for you, es-
• gbsn ( , simplified Chinese) pecially non-breaking spaces before all two-parts punctu-
ation marks. So now you can write:
• gkai ( , simplified Chinese)
The non-breaking space before the euro symbol is still
• bsmi ( , traditional Chinese) necessary because currency symbols and other units or
not supported in general (that’s not specific to French).
• bkai ( , traditional Chinese)
You can use the numprint package along Babel. It will let
you print numbers the French way.
Czech You will also notice that the layout of lists changes when
switching to the French language. This is customizable
Czech is fine using using the \frenchbsetup command. For more information
UTF-8 allows you to have „czech quotation marks“ di- on what the frenchb option of babel does and how you can
rectly in your text. Otherwise, there are macros \clqq customize its behavior, run LaTeX on file frenchb.dtx and
and \crqq to produce left and right quote. You can place read the produced file frenchb.pdf or frenchb.dvi. You
quotated text inside \uv. can get the PDF version on CTAN.

Finnish

Finnish language hyphenation is enabled with:


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

You can load German language support using either one


French of the two following commands.
You can load French language support with the following For traditional (“old”) German orthography use
command: or for reform (“new”) German orthography use
There are multiple options for typesetting French doc- This enables German hyphenation, if you have config-
uments, depending on the flavor of French: french, ured your LaTeX system accordingly. It also changes
frenchb, and francais for Parisian French, and acadian and all automatic text into German, e.g. “Chapter” becomes
canadien for new-world French. If you do not know or do “Kapitel”. A set of new commands also becomes avail-
not really care, we would recommend using frenchb. able, which allows you to write German input files more
However, as of version 3.0 of babel-french, it is advised to quickly even when you don't use the inputenc package.
choose the language as a global option with the following Check out the table below for inspiration. With inpu-
command[3] : tenc, all this becomes moot, but your text also is locked
in a particular encoding world.
All enable French hyphenation, if you have configured
your LaTeX system accordingly. All of these also change In German books you sometimes find French quotation
all automatic text into French: \chapter prints Chapitre, marks («guillemets»). German typesetters, however, use
\today prints the current date in French and so on. A set them differently. A quote in a German book would look
of new commands also becomes available, which allows like »this«. In the German speaking part of Switzerland,
you to write French input files more easily. Check out the typesetters use «guillemets» the same way the French do.
following table for inspiration: A major problem arises from the use of commands like
\flq: If you use the OT1 font encoding (which is the de-
You may want to typeset guillemets and other French fault) the guillemets will look like the math symbol " ≪
characters directly if your keyboard have them. Running ", which turns a typesetter’s stomach. T1 encoded fonts,
Xorg (*BSD and GNU/Linux), you may want to use the on the other hand, do contain the required symbols. So
oss variant which features some nice shortcuts, like if you are using this type of quote, make sure you use the
You will need the T1 font encoding for guillemets to print T1 encoding.
properly. Decimal numbers usually have to be written like 0{,}5
For the degree character you will get an error like (not just 0,5). Packages like ziffer enable input like 0,5.
2.8. INTERNATIONALIZATION 41

Greek Another (but old) possible Japanese support is made


available thanks to the CJK package collection. If you
This is the preamble you need to write in the Greek lan- are using a package manager or a portage tree, the CJK
guage. Note the particular input encoding. collection is usually in a separate package because of its
This preamble enables hyphenation and changes all au- size (mainly due to fonts).
tomatic text to Greek. A set of new commands also be- Make sure your document is saved using the UTF-8 char-
comes available, which allows you to write Greek input acter encoding. See Special Characters for more details.
files more easily. In order to temporarily switch to En- Put the parts where you want to write japanese characters
glish and vice versa, one can use the commands \text- in a CJK environment.
latin{english text} and \textgreek{greek text} that both
The last argument specifies the font. It must fit the desired
take one argument which is then typeset using the re-
language, since fonts are different for Chinese, Japanese
quested font encoding. Otherwise you can use the com-
and Korean. min is an example for Japanese.
mand \selectlanguage{...} described in a previous sec-
tion. Use \euro for the Euro symbol.
Korean
Hungarian The two most widely used encodings for Korean text files
are EUC-KR and its upward compatible extension used
Use the following lines: in Korean MS-Windows, CP949/Windows-949/UHC. In
More information in hungarian. these encodings each US-ASCII character represents its
normal ASCII character similar to other ASCII compat-
ible encodings such as ISO-8859-x, EUC-JP, Big5, or
Icelandic and Faroese Shift_JIS. On the other hand, Hangul syllables, Hanjas
(Chinese characters as used in Korea), Hangul Jamos,
The following lines can be added to write Icelandic text: Hiraganas, Katakanas, Greek and Cyrillic characters and
This changes text like Part into Hluti. It makes additional other symbols and letters drawn from KS X 1001 are
commands available: represented by two consecutive octets. The first has its
MSB set. Until the mid-1990’s, it took a considerable
To make special characters such as Þ and Æ become amount of time and effort to set up a Korean-capable en-
available just add: vironment under a non-localized (non-Korean) operating
The default LATEX font encoding is OT1, but it contains system. You can skim through the now much-outdated
only the 128 characters. The T1 encoding contains letters http://jshin.net/faq to get a glimpse of what it was like to
and punctuation characters for most of the European lan- use Korean under non-Korean OS in mid-1990’s.
guages using Latin script. TeX and LaTeX were originally written for scripts with
no more than 256 characters in their alphabet. To make
Italian them work for languages with considerably more charac-
ters such as Korean or Chinese, a subfont mechanism was
Italian is well supported by LaTeX. Just add developed. It divides a single CJK font with thousands or
tens of thousands of glyphs into a set of subfonts with 256
at the beginning of your document and the output of all glyphs each.
the commands will be translated properly.
For Korean, there are three widely used packages.

Japanese • HLATEX by UN Koaunghi

There is a variant of TeX intended for Japanese named • hLATEXp by CHA Jaechoon
pTeX, which supports vertical typesetting.
• the CJK package by Werner Lemberg
Another possible way to write in japanese is to use Lu-
alatex and the luatex-ja package. Adapted example from HLATEX and hLATEXp are specific to Korean and pro-
the Luatexja documentation : vide Korean localization on top of the font support. They
You can also use capabilities provided by the Fontspec both can process Korean input text files encoded in EUC-
package and those provided by Luatexja-fontspec to de- KR. HLATEX can even process input files encoded in
clare the font you want to use in your paper. Let us take CP949/Windows-949/UHC and UTF-8 when used along
an example : with Λ, Ω.
Use UTF-8 as your encoding. In case you don't know The CJK package is not specific to Korean. It can process
how to do this, take a look at Texmaker, a LaTeX editor input files in UTF-8 as well as in various CJK encodings
which use UTF-8 by default. including EUC-KR and CP949/Windows-949/UHC, it
42 CHAPTER 2. COMMON ELEMENTS

can be used to typeset documents with multilingual con- Polish


tent (especially Chinese, Japanese and Korean). The CJK
package has no Korean localization such as the one of- If you plan to use Polish in your UTF-8 encoded docu-
fered by HLATEX and it does not come with as many ment, use the following code
special Korean fonts as HLATEX.
The above code merely allows to use Polish letters and
The ultimate purpose of using typesetting programs like translates the automatic text to Polish, so that “chapter”
TeX and LaTeX is to get documents typeset in an aes- becomes “rozdział". There are a few additional things one
thetically satisfying way. Arguably the most important must remember about.
element in typesetting is a set of welldesigned fonts. The
HLATEX distribution includes UHC PostScript fonts of
10 different families and Munhwabu fonts (TrueType) of Connectives Polish has many single letter connectives:
5 different families. The CJK package works with a set “a”, “o”, “w”, “i”, “u”, “z”, etc., grammar and typography
of fonts used by earlier versions of HLATEX and it can rules don't allow for them to end a printed line. To ensure
use Bitstream’s cyberbit True-Type font. that LaTeX won't set them as last letter in the line, you
To use the HLATEX package for typesetting your Korean have to use non breakable space:
text, put the following declaration into the preamble of
your document:
Numerals According to Polish grammar rules, you
This command turns the Korean localization on. The
have to put dots after numerals in chapter, section, sub-
headings of chapters, sections, subsections, table of con-
section, etc. headers.
tent and table of figures are all translated into Korean and
the formatting of the document is changed to follow Ko- This is achieved by redefining few LaTeX macros.
rean conventions. The package also provides automatic For books:
particle selection. In Korean, there are pairs of post-fix
particles grammatically equivalent but different in form. For articles:
Which of any given pair is correct depends on whether Alternatively you can use dedicated document classes:
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 • the mwart class instead of article,
problem picking the right particle, but it cannot be de-
termined which particle to use for references and other • mwbk instead of book
automatic text that will change while you edit the docu-
ment. It takes a painstaking effort to place appropriate • and mwrep instead of report.
particles manually every time you add/remove references
or simply shuffle parts of your document around. HLA- Those classes have much more European typography set-
TEX relieves its users from this boring and error-prone tings but do not require the use of Polish babel settings or
process. character encoding.
In case you don't need Korean localization features but Simple usage:
just want to typeset Korean text, you can put the following
line in the preamble, instead. Full documentation for those classes is available at
http://web.archive.org/web/20040609034031/http://
For more details on typesetting Korean with HLATEX, www.ci.pwr.wroc.pl/~{}pmazur/LaTeX/mwclsdoc.pdf
refer to the HLATEX Guide. Check out the web site of (Polish).
the Korean TeX User Group (KTUG).
In the FAQ section of KTUG it is recommended to use
the kotex package Indentation It may be customary (depending on pub-
lisher) to indent the first paragraph in sections and chap-
ters:

Persian script
Hyphenation and typography It’s much more
For Persian language, there is a dedicated package called frowned upon to set pages with hyphenation between
XePersian which uses XeLaTeX as the typesetting en- pages than it is customary in American typesetting.
gine. Just add the following code to your preamble: To adjust penalties for hyphenation spanning pages, use
See XePersian page on CTAN this command:
Moreover, Arabic script can be used to type Persian as To adjust penalties for leaving widows and orphans (clubs
illustrated in the corresponding section. in TeX nomenclature) use those commands:
2.8. INTERNATIONALIZATION 43

Commas in math According to Polish typography with Spanish in the way they handle active characters, and
rules, fractional parts of numbers should be delimited by these options disable the internal workings of Spanish to
a comma, not a dot. To make LaTeX not insert addi- allow you to overcome these common pitfalls. Moreover,
tional space in math mode after a comma (unless there is these options may simplify the way LyX customizes some
a space after the comma), use the icomma package. features of the Spanish layout from inside the GUI.
Unfortunately, it is partially incompatible with the dcol-The options mexico,mexico-com provide support for lo-
umn package. One needs to either use dots in columns cal custom in Mexico: the former using decimal dot, as
with numerical data in the source file and make dcolumn customary, and the latter allowing decimal comma, as re-
switch them to commas for display or define the column quired by the Mexican Official Norm (NOM) of the De-
as follows: partment of Economy for labels in foods and goods. More
The alternative is to use the numprint package, but it is localizations are in the making.
much less convenient. The other commands modify the spanish layout after
loading Babel. Two particularly useful commands are
\spanishoperators and \spanishdeactivate.
Further information Refer the Słownik Or-
tograficzny (in Polish) for additional information on The macro \spanishoperators{<list of operators>}{ con-
Polish grammar and typography rules. tains a list of spanish mathematical operators, and may
be redefined at will. For instance, the command
Good extract is available at Zasady Typograficzne
Składania Tekstu (in Polish). only defines sen, overriding all other definitions; the com-
mand \let\spanishoperators\relax disables them all. This
command supports accented or spaced operators: the
Portuguese \acute{<letter>} command puts an accent, and the \,
command adds a small space. For instance, the follow-
Add the following code to your preamble: ing operators are defined by default.
You can substitute the language for brazilian portuguese Finally, the macro \spanishdeactivate{<list of charac-
by choosing brazilian or brazil. ters>} disables some active characters, to keep you out
of trouble if they are redefined by other packages. The
Slovak candidates for deactivation are the set {<>."'}. Please,
beware that some option preempt the availability of some
Basic settings are fine when left the same as Czech, but active characters. In particular, you should not combine
Slovak needs special signs for 'ď', 'ť', 'ľ'. To be able to the es-noquoting option with \spanishdeactivate{<>}, or
type them from keyboard use the following settings: the es-noshorthands with \spanishdeactivate{<>."}.
Please check the documentation for Babel or spanish.dtx
Spanish for further details.

Include the appropriate Babel option:


Tibetan
The trick is that Spanish has several options and com-
mands to control the layout. The options may be loaded One option to use Tibetan script in LaTeX is to add
either at the call to Babel, or before, by defining the com-
mand \spanishoptions. Therefore, the following com- to your preamble and use a slightly modified Wylie
mands are roughly equivalent: transliteration for input. Refer to the excellent pack-
age documentation for details. More information can be
On average, the former syntax should be preferred, as the found on
latter is a deviation from standard Babel behavior, and
thus may break other programs (LyX, latex2rtf) interact-
ing with LaTeX. 2.8.5 References
Spanish also defines shorthands for the dot and << >> so
that they are used as logical markup: the former is used as [1] The Not So Short Introduction to LaTeX, 2.5.6 Support
decimal marker in math mode, and the output is typically for Cyrillic, Maksym Polyakov
either a comma or a dot; the latter is used for quoted text,
and the output is typically either «» or “”. This allows [2] The Not So Short Introduction to LaTeX, Bulgarian trans-
different typographical conventions with the same input, lation
as preferences may be quite different from, say, Spain and
Mexico. [3] babel-french documentation: “the French language should
now be loaded as french, not as frenchb or francais and
Two particularly useful options are es-noquoting,es- preferably as a global option of \documentclass. Some tol-
nolists: some packages and classes are known to collide erance still exists in v3.0, but do not rely on it.”
44 CHAPTER 2. COMMON ELEMENTS

2.9 Rotations just like for normal tables. The H option can not be used
without this package.
2.9.1 The rotating package
The package rotating gives you the possibility to rotate 2.10 Tables
any object of an arbitrary angle. Once you have loaded it
with the standard command in the preamble:
Tables are a common feature in academic writing, often
you can use three new environments: used to summarize research results. Mastering the art of
it will rotate the whole argument by 90 degrees counter- table construction in LaTeX is therefore necessary to pro-
clockwise. Moreover: duce quality papers and with sufficient practice one can
print beautiful tables of any kind.
it will turn the argument of 30 degrees. You can give any
angle as an argument, whether it is positive or negative. Keeping in mind that LaTeX is not a spreadsheet, it makes
It will leave the necessary space to avoid any overlapping sense to use a dedicated tool to build tables and then to
of text. export these tables into the document. Basic tables are not
too taxing, but anything more advanced can take a fair bit
like turn, but it will not add any extra space. of construction; in these cases, more advanced packages
If you want to make a float sideways so that the caption is can be very useful. However, first it is important to know
also rotated, you can use the basics. Once you are comfortable with basic LaTeX
tables, you might have a look at more advanced packages
or or the export options of your favorite spreadsheet. Thanks
Note, though, they will be placed on a separate page. to the modular nature of LaTeX, the whole process can
be automated in a fairly comfortable way.
If you would like to rotate a TikZ picture you could use
sideways together with minipage. For a long time, LaTeX tables were quite a chaotic topic,
with dozens of packages doing similar things, while not
You can also use the \rotatebox command. Let’s rotate a
always being compatible with one another. Sometimes
tabular inside a table for example:
you had to make trade-offs. The situation changed re-
cently (2010) with the release of the tabu package which
Options combines the power of longtable, tabularx and much
more. The tabu environment is far less fragile and re-
Default is sidewaysfigures/sidewaystables are oriented de- stricted than the older alternatives. Nonetheless, before
pending on page number in two sided documents (takes attempting to use this package for the first time it will
two passes). be beneficial to understand how the classic environment
works, since tabu works the same way. Note however that
The rotating package takes the following options.
the author of tabu will not fix bugs to the current version,
and that the next version introduces new syntax that will
counterclockwise/anticlockwise In single sided docu- likely break existing documents.[1]
ments turn sidewaysfigures/sidewaystables counter-
clockwise.

clockwise In single sided documents turn sidewaysfig-


2.10.1 The tabular environment
ures/sidewaystables clockwise (default).
The tabular environment can be used to typeset tables
figuresright In two sided documents all sidewaysfig- with optional horizontal and vertical lines. LaTeX de-
ures/sidewaystables are same orientation (left of fig- termines the width of the columns automatically.
ure, table now bottom of page). This is the style The first line of the environment has the form:
preferred by the Chicago Manual of Style (broad-
side). The table spec argument tells LaTeX the alignment to be
used in each column and the vertical lines to insert.
figuresleft In two sided documents all sidewaysfig-
The number of columns does not need to be specified as
ures/sidewaystables are same orientation (left of fig-
it is inferred by looking at the number of arguments pro-
ure, table now at top of page).
vided. It is also possible to add vertical lines between the
columns here. The following symbols are available to de-
scribe the table columns (some of them require that the
2.9.2 The rotfloat package
package array has been loaded):
When it is desirable to place the rotated table at the exact By default, if the text in a column is too wide for the page,
location where it appears in the source (.tex) file, rotfloat LaTeX won’t automatically wrap it. Using p{'width'}
package may be used. Then one can use you can define a special type of column which will wrap-
2.10. TABLES 45

around the text as in a normal paragraph. You can pass Here is a simple example. The following code creates two
the width using any unit supported by LaTeX, such as 'pt' tables with the same code; the only difference is that the
and 'cm', or command lengths, such as \textwidth. You last column of the second one has a defined width of 5
can find a list in chapter Lengths. centimeters, while in the first one we didn't specify any
The optional parameter pos can be used to specify the width. Compiling this code:
vertical position of the table relative to the baseline of the You get the following output:
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:
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 col-
umn table with the first 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 first line you have pointed out how many columns Note that the first table has been cropped, since the output
you want, their alignment and the vertical lines to separate is wider than the page width.
them. Once in the environment, you have to introduce
the text you want, separating between cells and introduc-
Manually broken paragraphs in table cells
ing new lines. The commands you have to use are the
following:
Sometimes it is necessary to not rely on the breaking al-
Note, any white space inserted between these commands gorithm when using the p specifier, but rather specify the
is purely down to ones’ preferences. I personally add line breaks by hand. In this case it is easiest to use a \par-
spaces between to make it easier to read. box:

Basic examples Space between columns

This example shows how to create a simple table in La- To tweak the space between columns (LaTeX will by de-
TeX. It is a three-by-three table, but without any lines. fault choose very tight columns), one can alter the col-
Expanding upon that by including some vertical lines: umn separation: \setlength{\tabcolsep}{5pt}. The de-
fault value is 6pt.
To add horizontal lines to the very top and bottom edges
of the table:
Space between rows
And finally, to add lines between all rows, as well as
centering (notice the use of the center environment - of Re-define the \arraystretch command to set the space be-
course, the result of this is not obvious from the preview tween rows:
on this web page):
Default value is 1.0.
An alternative way to adjust the rule spacing is to
Text wrapping in tables
add \noalign{\smallskip} before or after the \hline and
LaTeX’s algorithms for formatting tables have a few \cline{i-j} commands:
shortcomings. One is that it will not automatically wrap You may also specify the skip after a line explicitly using
text in cells, even if it overruns the width of the page. glue after the line terminator
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 (al- Other environments inside tables
though it may take some trial-and-error to get the result
you want). For a more convenient method, have a look at If you use some LaTeX environments inside table cells,
The tabularx package, or The tabulary package. like verbatim or enumerate:

Instead of p, use the m attribute to have the lines aligned you might encounter errors similar to
toward the middle of the box or the b attribute to align ! LaTeX Error: Something’s wrong--perhaps a missing
along the bottom of the box. \item.
46 CHAPTER 2. COMMON ELEMENTS

To solve this problem, change column specifier to “para- It typically takes some text as its argument, and when ap-
graph” (p, m or b). pended to a column, it will automatically insert that text
into each cell in that column before the actual data for
that cell. This command kills the inter-column space and
Defining multiple columns replaces it with whatever is between the curly braces. To
add space, use @{\hspace{''width''}}.
It is possible to define many identical columns at once Admittedly, this is not that clear, and so will require a few
using the *{''num''}{''str''} syntax. This is particularly examples to clarify. Sometimes, it is desirable in scien-
useful when your table has many columns. tific tables to have the numbers aligned on the decimal
Here is a table with six centered columns flanked by a point. This can be achieved by doing the following:
single column on each side: The space-suppressing qualities of the @-expression ac-
tually make it quite useful for manipulating the horizontal
spacing between columns. Given a basic table, and vary-
Column specification using >{\cmd} and <{\cmd}
ing the column descriptions:
The column specification can be altered using the array
package. This is done in the argument of the tabular en-
vironment using >{\command} for commands executed Aligning columns at decimal points using dcolumn
right before each column element and <{\command} for
commands to be executed right after each column ele-
ment. As an example: to get a column in math mode en- Instead of using @-expressions to build columns of deci-
ter: \begin{tabular}{>{$}c<{$}}. Another example is mals aligned to the decimal point (or equivalent symbol),
changing the font: \begin{tabular}{>{\small}c} to print it is possible to center a column on the decimal separator
the column in a small font. using the dcolumn package, which provides a new column
specifier for floating point data. See the dcolumn package
The argument of the > and < specifications must be cor- documentation for more information, but a simple way to
rectly balanced when it comes to { and } characters. use dcolumn is as follows.
This means that >{\bfseries} is valid, while >{\textbf}
will not work and >{\textbf{} is not valid. If there A negative argument provided for the number of decimal
is the need to use the text of the table as an argu- places in the new column type allows unlimited decimal
ment (for instance, using the \textbf to produce bold places, but may result in rather wide columns. Round-
text), one should use the \bgroup and \egroup commands: ing is not applied, so the data to be tabulated should
>{\textbf\bgroup}c<{\egroup} produces the intended ef- be adjusted to the number of decimal places specified.
fect. This works only for some basic LaTeX commands. Note that a decimal aligned column is typeset in math
For other commands, such as \underline to underline text, mode, hence the use of \mathrm for the column head-
it is necessary to temporarily store the column text in a ing in the example above. Also, text in a decimal aligned
box using lrbox. First, you must define such a box with column (for example the header) will be right-aligned be-
\newsavebox{\boxname} and then you can define: fore the decimal separator (assuming there’s no decimal
separator in the text). While this may be fine for very
This stores the text in a box and afterwards, takes the text short text, or numeric column headings, it looks cum-
out of the box with \unhbox (this destroys the box, if the bersome in the example above. A solution to this is to
box is needed again one should use \unhcopy instead) and use the \multicolumn command described below, spec-
passing it to \underline. (For LaTeX2e, you may want to ifying a single column and its alignment. For exam-
use \usebox{\boxname} instead of \unhbox\boxname.) ple to center the header Decimal over its column in the
This same trick done with \raisebox instead of \underline above example, the first line of the table itself would be
can force all lines in a table to have equal height, instead of Left&Right&Center&\multicolumn{1}{c}{Decimal}\\
the natural varying height that can occur when e.g. math
terms or superscripts occur in the text.
Here is an example showing the use of both p{...} and
Bold text and dcolumn To draw attention to particular
>{\centering} :
entries in a table, it may be nice to use bold text. Ordi-
Note the use of \tabularnewline instead of \\ to avoid a narily this is easy, but as dcolumn needs to see the deci-
Misplaced \noalign error. mal point it is rather harder to do. In addition, the usual
bold characters are wider than their normal counterparts,
meaning that although the decimals may align nicely, the
@-expressions figures (for more than 2-−3 digits on one side of the deci-
mal point) will be visibly misaligned. It is however possi-
The column separator can be specified with the @{...} ble to use normal width bold characters and define a new
construct. bold column type, as shown below.[2]
2.10. TABLES 47

2.10.2 Row specification and opt out the first column that contains the text “Pow-
ers”.
It might be convenient to apply the same command over Here is another example exploiting the same ideas to
every cell of a row, just as for column. Unfortunately the make the familiar and popular “2x2” or double di-
tabular environment cannot do that by default. We will chotomy:
need tabu instead, which provides the \rowfont option.

2.10.3 Spanning 2.10.4 Controlling table size

To complete this tutorial, we take a quick look at how Resize tables


to generate slightly more complex tables. Unsurprisingly,
the commands necessary have to be embedded within the The graphicx packages features the command \resize-
table data itself. box{width}{height}{object} which can be used with tab-
ular to specify the height and width of a table. The fol-
lowing example shows how to resize a table to 8cm width
Rows spanning multiple columns while maintaining the original width/height ratio.

The command for this looks like this: \multicol- Resizing table including the caption
umn{'num_cols’}{'alignment'}{'contents’}. num_cols is Alternatively you can use \scalebox{ratio}{object} in the
the number of subsequent columns to merge; alignment same way but with ratios rather than fixed sizes:
is either l, c, r, or to have text wrapping specify a width
p{5.0cm} . And contents is simply the actual data you
want to be contained within that cell. A simple example: Changing font size

Columns spanning multiple rows A table can be globally switched to a different font size
by simply adding the desired size command (here: \foot-
The first thing you need to do is add \usepack- notesize) in the table scope, which may be after the \be-
age{multirow} to the preamble[3] . This then pro- gin{table} statement if you use floats, otherwise you need
vides the command needed for spanning rows: \mul- to add a group delimiter.
tirow{''num_rows’'}{''width''}{''contents’'}. The argu- Alternatively, you can change the default font for all the
ments are pretty simple to deduce (* for the width means tables in your document by placing the following code in
the content’s natural width). the preamble:
The main thing to note when using \multirow is that a See Fonts for named font sizes. The table caption font
blank entry must be inserted for each appropriate cell in size is not affected. To control the caption font size, see
each subsequent row to be spanned. Caption Styles.
If there is no data for a cell, just don't type anything, but
you still need the "&" separating it from the next column’s
data. The astute reader will already have deduced that for 2.10.5 Colors
a table of n columns, there must always be n − 1 amper-
sands in each row (unless \multicolumn is also used). Alternate row colors in tables

Spanning in both directions simultaneously The xcolor package provides the necessary commands
to produce tables with alternate row colors, when
Here is a nontrivial example of how to use spanning in loaded with the table option. The command \rowcol-
both directions simultaneously and have the borders of ors{<''starting row''>}{<''odd color''>}{<''even color''>}
the cells drawn correctly: has to be specified right before the tabular environment
starts.
The command \multicolumn{1}{ is just used to draw
vertical borders both on the left and on the right of the The command \hiderowcolors is available to deactivate
cell. Even when combined with \multirow{2}{*}{...}, it highlighting from a specified row until the end of the ta-
still draws vertical borders that only span the first row. ble. Highlighting can be reactivated within the table via
To compensate for that, we add \multicolumn{1}{ in the the \showrowcolors command. If while using these com-
following rows spanned by the multirow. Note that we mands you experience “misplaced \noalign errors” then
cannot just use \hline to draw horizontal lines, since we use the commands at the very beginning or end of a row
do not want the line to be drawn over the text that spans in your tabular.
several rows. Instead we use the command \cline{2-6} or
48 CHAPTER 2. COMMON ELEMENTS

Colors of individual cells by using the X@{} option. Note that the \multicolumn
width (which in this example is 2) should equal the (in
As above this uses the xcolor package. this example 1+1) width of the spanned columns:
In a way analogous to how new commands with argu-
ments can be created with \newcommand, new column
2.10.6 Width and stretching types with arguments can be created with \newcolumn-
type as follows:
We keep providing documentation for tabular* and tab-
ularx although they are completely eclipsed by the much where since there are 4 columns, the sum of the \hsize’s
more powerful and flexible tabu environment. Actually (1 + 0.5 + 0.5 + 2) must be equal to 4. The default value
tabu is greatly inspired by those environments, so it may used by tabularx for \hsize is 1.
be worth it to have an idea how they work, particularly
for tabularx.
The tabulary package

The tabular* environment tabulary is a modified tabular* allowing width of columns


set for equal heights. tabulary allows easy and convenient
This is basically a slight extension on the original tabular writing of well balanced tables.
version, although it requires an extra argument (before the The problem with tabularx is that it leaves much blank if
column descriptions) to specify the preferred width of the your cells are almost empty. Besides, it is not easy to have
table. different column sizes.
However, that may not look quite as intended. The tabulary tries to balance the column widths so that each
columns are still at their natural width (just wide enough column has at least its natural width, without exceeding
to fit their contents) while the rows are as wide as the table the maximum length.
width specified. If you do not like this default, you must
also explicitly insert extra column space. LaTeX has rub- The first parameter is the maximum width. tabulary will
ber lengths, which, unlike others, are not fixed. LaTeX try not to exceed it, but it will not stretch to it if there is
can dynamically decide how long the lengths should be. not enough content, contrary to tabularx.
So, an example of this is the following. The second parameter is the column disposition. Possible
You will notice the @{...} construct added at the begin- values are those from the tabular environment, plus
ning of the column description. Within it is the \extra- These are all capitals.
colsep command, which requires a width. A fixed width
could have been used. However, by using a rubber length,
such as \fill, the columns are automatically spaced evenly. The tabu environment

It works pretty much like tabularx.


The tabularx package
'to \linewidth' specifies the target width. The X parameter
This package provides a table environment called tabu- can have an optional span factor.
larx, which is similar to the tabular* environment except
that it has a new column specifier X (in uppercase). The
column(s) specified with this specifier will be stretched
2.10.7 Table across several pages
to make the table as wide as specified, greatly simplify-
ing the creation of tables. Long tables are natively supported by LaTeX thanks to
the longtable environment. Unfortunately this environ-
The content provided for the boxes is treated as for a ment does not support stretching (X columns).
p column, except that the width is calculated automati-
The tabu packages provides the longtabu environment. It
cally. If you use the package array, you may also apply
any >{\cmd} or <{\cmd} command to achieve specific has most of the features of tabu, with the additional ca-
pability to span multiple pages.
behavior (like \centering, or \raggedright\arraybackslash)
as described previously. LaTeX can do well with long tables: you can specify a
Another option is to use \newcolumntype to format se- header that will repeat on every page, a header for the
lected columns in a different way. It defines a new col- first page only, and the same for the footer.
umn specifier, e.g. R (in uppercase). In this example, the It uses syntax similar to longtable, so you should have a
second and fourth column is adjusted in a different way look at its documentation if you want to know more.
(\raggedleft): Alternatively you can try one of the following packages
Tabularx with rows spanning multiple columns using supertabular or xtab, an extended and somewhat im-
\multicolumn. The two central columns are posing as one proved version of supertabular.
2.10. TABLES 49

2.10.8 Partial vertical lines Normal LaTeX

Adding a partial vertical line to an individual cell: Using array


Removing part of a vertical line in a particular cell:
\usepackage{array} %or \usepackage{dcolumn} ... \be-
gin{tabular}{llr} \firsthline \multicolumn{2}{c}{Item}
\\ \cline{1-2} Animal & Description & Price (\$) \\
\hline Gnat & per gram & 13.65 \\ & each & 0.01 \\
2.10.9 Vertically centered images Gnu & stuffed & 92.50 \\ Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\ \lasthline \end{tabular}
Inserting images into a table row will align it at the top of
the cell. By using the array package this problem can be
solved. Defining a new columntype will keep the image
vertically centered.
Using booktabs
Or use a parbox to center the image.
A raisebox works as well, also allowing to manually fine- \usepackage{booktabs}\\ \begin{tabular}{llr} \toprule
tune the alignment with its first parameter. \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}
2.10.10 Footnotes in tables

The tabular environment does not handle footnotes prop-


erly. The longtabular fixes that.
Instead of using longtabular we recommend tabu which
handles footnotes properly, both in normal and long ta-
bles.

Usually the need arises for footnotes under a table (and


2.10.11 Professional tables not at the bottom of the page), with a caption properly
spaced above the table. These are addressed by the ctable
package. It provides the option of a short caption given
Many professionally typeset books and journals feature to be inserted in the list of tables, instead of the actual
simple tables, which have appropriate spacing above and caption (which may be quite long and inappropriate for
below lines, and almost never use vertical rules. Many ex- the list of tables). The ctable uses the booktabs package.
amples of LaTeX tables (including this Wikibook) show-
case the use of vertical rules (using "|"), and double-rules
(using \hline\hline or "||"), which are regarded as unnec-
essary and distracting in a professionally published form.
2.10.12 Sideways tables
The booktabs package is useful for easily providing this
professionalism in LaTeX tables, and the documentation
also provides guidelines on what constitutes a “good” ta- Tables can also be put on their side within a document us-
ble. ing the rotating or the rotfloat package. See the Rotations
chapter.
In brief, the package uses \toprule for the uppermost rule
(or line), \midrule for the rules appearing in the middle
of the table (such as under the header), and \bottom-
rule for the lowermost rule. This ensures that the rule 2.10.13 Table with legend
weight and spacing are acceptable. In addition, \cmidrule
can be used for mid-rules that span specified columns.
The following example contrasts the use of booktabs and To add a legend to a table the caption package can be
two equivalent normal LaTeX implementations (the sec- used. With the caption package a \caption*{...} state-
ond example requires \usepackage{array} or \usepack- ment can be added besides the normal \caption{...}. Ex-
age{dcolumn}, and the third example requires \usepack- ample:
age{booktabs} in the preamble). The normal caption is needed for labels and references.
50 CHAPTER 2. COMMON ELEMENTS

2.10.14 The eqparbox package The captions show now up in the list of tables, if dis-
played.
On rare occasions, it might be necessary to stretch ev-
You can set the optional parameter position specifier to
ery row in a table to the natural width of its longest line,
define the position of the table, where it should be placed.
for instance when one has the same text in two languages
The following characters are all possible placements. Us-
and wishes to present these next to each other with lines
ing sequences of it define your “wishlist” to LaTeX.
synching up. A tabular environment helps control where
lines should break, but cannot justify the text, which leads Default is tbp, which means that it is by default placed on
to ragged right edges. The eqparbox package provides the top of the page. If that’s not possible, it’s placed at
the command \eqmakebox which is like \makebox but in- the bottom if possible, or finally with other floating envi-
stead of a width argument, it takes a tag. During compi- ronments on an extra page.
lation it bookkeeps which \eqmakebox with a certain tagYou can force LaTeX to use one given position. E.g. [!h]
contains the widest text and can stretch all \eqmakeboxes
forces LaTeX to place it exactly where you place it (Ex-
with the same tag to that width. Combined with the array
cept when it’s really impossible, e.g you place a table here
package, one can define a column specifier that justifies and this place would be the last line on a page). Again,
the text in all lines: understand it correctly: it urges LaTeX to put the table at
See the documentation of the eqparbox package for more a specific place, but it will not be placed there if LaTeX
details. 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
2.10.15 Floating with table
else, using the \centering command just after opening the
table environment, or by enclosing it with a center envi-
In WYSIWYG document processors, it is common to put
ronment.
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
2.10.16 Using spreadsheets and data anal-
so that they do not disrupt the flow. From the point of
view of the source code, one has no idea on which page ysis tools
the current text is going to lie, so it is hardly possible to
For complex or dynamic tables, you may want to use a
guess which page may be appropriate for our table. La-
TeX can automate this task by abstracting objects such spreadsheet. You might save lots of time by building ta-
bles using specialized software and exporting them in La-
as tables, pictures, etc., and deciding for us where they
might fit best. This abstraction is called a float. Gener- TeX format. The following plugins and libraries are avail-
able for some popular software:
ally, an object that is floated will appear in the vicinity of
its introduction in the source file, but one can choose to
control its position also. • calc2latex: for OpenOffice.org Calc spreadsheets,
To tell LaTeX we want to use our table as a float, we need • excel2latex: for Microsoft Office Excel,
to place a tabular environment in a table environment,
which is able to float and add a label and caption. • matrix2latex: for MATLAB,
The table environment initiates a type of float just as the • matrix2latex: for Python and MATLAB,
environment figure. In fact, the two bear a lot of sim-
ilarities (positioning, captions, etc.). More information • pandas: pandas DataFrame’s have a method to con-
about floating environments, captions etc. can be found vert data they contain to latex,
in Floats, Figures and Captions.
• latex-tools: a Ruby library,
The environment names may now seem quite confusing.
Let’s sum it up: • xtable: a library for R,

• tabular is for the content itself (columns, lines, etc.). • org-mode: for Emacs users, org-mode tables can be
used inline in LaTeX documents, see for a tutorial.
• table is for the location of the table on the document,
plus caption and label support. • Emacs align commands: the align commands can
clean up a messy LaTeX table.
In the table, we used a label, so now we can refer to it just
like any other reference: • Online Table generator for LATeX: An online tool
for creating simple tables within the browser. La-
The table environment is also useful when you want to TeX format is directly generated as you type.
have a list of tables at the beginning or end of your doc-
ument with the command • Create LaTeX tables online : Online tool.
2.11. TITLE CREATION 51

However, copying the generated source code to your doc- 2.10.18 References
ument is not convenient at all. For maximum flexibility,
generate the source code to a separate file which you can [1] http://tex.stackexchange.com/questions/121841/
input from your main document file with the \input com- is-the-tabu-package-obsolete
mand. If your speadsheet supports command-line, you [2] D Carlisle. “Decimals in table don't align
can generate your complete document (table included) in with dcolumn when bolded”. Stackexchange.
one command, using a Makefile for example. http://tex.stackexchange.com/questions/118458/
decimals-in-table-dont-align-with-dcolumn-when-bolded.
See Modular Documents for more details.
[3] Package multirow on CTAN

2.10.17 Need more complicated features?


2.11 Title Creation
Have a look at one of the following packages:
For documents such as basic articles, the output of
• hhline: do whatever you want with horizontal lines
\maketitle is often adequate, but longer documents (such
as books and reports) often require more involved for-
• array: gives you more freedom on how to define matting. We will detail the process here.
columns There are several situations where you might want to cre-
ate a title in a custom format, rather than in the format
• colortbl: make your table more colorful natively supported by LaTeX classes. While it is possible
to change the output of \maketitle, it can be complicated
• threeparttable makes it possible to put footnotes even with minor changes to the title. In such cases it is of-
both within the table and its caption ten better to create the title from scratch, and this section
will show you how to accomplish this.
• arydshln: creates dashed horizontal and vertical
lines
2.11.1 Standard Titles
• ctable: allows for footnotes under table and properly
spaced caption above (incorporates booktabs pack- Many document classes will form a title or a title page
age) for you. One must specify what to fill it with using these
commands placed in the top matter:
• slashbox: create 2D tables with the first cell contain- Commonly the date is excluded from the title page by us-
ing a description for both axes. Not available in Tex ing \date{}. It defaults to \today if omitted in the source
Live 2011 or later. file.

• diagbox: compatible to slashbox, come with Tex To form a title, use


Live 2011 or later This should go after the preceding commands. For most
document classes, this will form a separate page, while
• dcolumn: decimal point alignment of numeric cells the article document class will place the title on the top of
the first page. If you want to have a separate title page for
• rccol: advanced decimal point alignment of numeric articles as well, use the documentclass option titlepage.
cells with rounding
Footnotes within the title page can be specified with the
\thanks command. For example, one may add
• numprint: print numbers, in the current mode (text
or math) in order to use the correct font, with The \thanks command can also be used in the \title.
separators, exponent and/or rounded to a given It is dependent on the document class which commands
number of digits. tabular(*), array, tabularx, and are used in the title generated by \maketitle. Referring to
longtable environments is supported using all fea- the documentation will lead to trusted information.
tures of numprint

• spreadtab: spread sheets allowing the use of formu- 2.11.2 Custom Title Pages
lae
Normally, the benefit of using LaTeX instead of tradi-
• siunitx: alignment of tabular entries tional word processing programs is that LaTeX frees you
to concentrate on content by handling margins, justifica-
• pgfplotstable: Loads, rounds, formats and postpro- tion, and other typesetting concerns. On the other hand,
cesses numerical tables. if you want to write your own title format, it is exactly
52 CHAPTER 2. COMMON ELEMENTS

the opposite: you have to take care of everything — this Remember, if you have a block of text in a different size,
time LaTeX will do nothing to help you. It can be chal- even if it is a bit of text on a single line, end it with \par.
lenging to create your own title format since LaTeX was
not designed to be graphically interactive in the adjust- Filling the page
ment of layout. The process is similar to working with
raw HTML with the added step that each time you want the command \vfill as the last item of your content will
to see how your changes look, you have to re-compile the add empty space until the page is full. If you put it within
source. While this may seem like a major inconvenience, the page, you will ensure that all the following text will be
the benefit is that once the customized title format has placed at the bottom of the page.
been written, it serves as a template for all other docu-
ments that would use the title format you have just made.
A practical example All these tips might have made
In other words, once you have a layout you like, you can
you confused. Here is a practical and compilable exam-
use it for any other documents where you would like the
ple. The picture in use comes with package mwe and
same layout without any additional fiddling with layout.
should be available with every complete LaTeX installa-
The title page of a book or a report is the first a reader will tion. You can start testing right away.
see. Keep that in mind when preparing your title page.
As you can see, the code looks “dirtier” than standard La-
TeX source because you have to take care of the output
Create the title for a report or book as well. If you start changing fonts it gets even more com-
plicated, but you can do it: it’s only for the title and your
A title page for reports to get a university degree is quite complicated code will be isolated from all the rest within
static, it doesn't really change over time. You can prepare its own file.
the titlepage in its own little document and prepare a one
page pdf that you later include into your real document.
Integrating the title page Assuming you have done
This is really useful, if the title page is required to have
the title page of your report in an extra document, let’s
completelyy different margins as the rest of the document.
pretend it is called reportTitlepage2015.pdf, you can in-
It also saves compile time, though it is not much.
clude it quite simply. Here is a short document setup.
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, every- A title to be re-used multiple times
thing is hand crafted. Here are some of the most often
needed things: Some universities, departments and companies have strict
rules how a title page of a report should look like. To
ensure the very same output for all reports, a redefiniton
Alignment
of the \maketitle command is recommended.
if you want to center some text just use \centering. If you This is best done by an experienced LaTeX user. A sim-
want to align it differently you can use the environment ple example follows, as usual there is no real limit with
\raggedleft for right-alignment and \raggedright for left- respect to complexity.
alignment. As a starting point, a LaTeX package called
columbidaeTitle.sty is generated that defines the
Images complete title matter. It will later be hidden from the
end user. Ideally, the person creating the package should
the command for including images (a logo maintain it for a long time, create an accompanying
for example) is the following : \includegraph- documentation and ensure user support.
ics[width=0.15\textwidth]{./logo}. There is no \be- This package can be loaded within a usual document. The
gin{figure} as you would usually use since you don't want user can set the variables for title and the like. Which
it to be floating, you just want it exactly where want it commands are actually available, and which might be
to be. When handling it, remember that it is considered omissible should be written in a documentation that is
like a big box by the TeX engine. bundled with the package.
Look around what happens if you leave one or the other
Text size
command out.

If you want to change the size of some text just place it


within braces, {like this}, and you can use the following 2.11.3 Packages for custom titles
commands (in order of size): \Huge, \huge, \LARGE,
\Large, \large, \normalsize, \small, \footnotesize, \tiny. The titling package[1] provides control over the typeset-
So for example: ting of the \maketitle and \thanks commands. The ti-
2.12. PAGE LAYOUT 53

tlepages package presents many styles of designs for title


2
pages. Italian users may also want to use the frontespizio 4
5
package[2] . Header

2.11.4 Notes and References


[1] [http://www.ctan.org/tex-archive/macros/latex/contrib/
titling Titling package webpage in CTAN]

[2] [http://www.ctan.org/tex-archive/macros/latex/contrib/
frontespizio Frontespizio package webpage in CTAN]
Margin notes Body
7

2.12 Page Layout


9

10
LaTeX and the document class will normally take care of 3
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, 8
11
for your own documents, there are some obvious settings
that you may wish to change: margins, page orientation Footer

and columns, to name but three. The purpose of this tu-


1
torial is to show you how to configure your pages.
We will often have to deal with TeX lengths in this chap-
ter. You should have a look at Lengths for comprehensive
details on the topic.
4. \topmargin = 20pt
5. \headheight = 12pt
2.12.1 Two-sided documents
6. \headsep = 25pt
Documents can be either one- or two-sided. Articles
are by default one-sided, books are two-sided. Two- 7. \textheight = 592pt
sided documents differentiate the left (even) and right 8. \textwidth = 390pt
(odd) pages, whereas one-sided do not. The most no-
table effect can be seen in page margins. If you want 9. \marginparsep = 10pt
to make the article class two-sided, use \document-
10. \marginparwidth = 35pt
class[twoside]{article}.
Many commands and variables in LaTeX take this con- 11. \footskip = 30pt
cept into account. They are referred to as even and odd.
For one-sided document, only the odd commands and • \marginparpush = 7pt (not shown)
variables will be in effect. • \hoffset = 0pt
• \voffset = 0pt
2.12.2 Page dimensions
• \paperwidth = 597pt
A page in LaTeX is defined by many internal parame- • \paperheight = 845pt
ters. Each parameter corresponds to the length of an ele-
ment of the page, for example, \paperheight is the physi- The current details plus the layout shape can be printed
cal height of the page. Here you can see a diagram show- from a LaTeX document itself. Use the layout pack-
ing all the variables defining the page. All sizes are given age and the command of the same name: \usepack-
in TeX points (pt), there are 72.27pt in an inch or 1pt ≈ age{layout} ... \layout{}
0.3515mm.
To render a frame marking the margins of a document
you are currently working on, add
1. one inch + \hoffset
\usepackage{showframe}
2. one inch + \voffset

3. \oddsidemargin = 31pt to the document.


54 CHAPTER 2. COMMON ELEMENTS

2.12.3 Page size pdflatex myfile # TeX → PDF

It will not have been immediately obvious - because it • TeX → DVI → PDF
doesn't really cause any serious problems - that the de-
fault page size for all standard document classes is US let- latex myfile # TeX → DVI dvipdf myfile # DVI → PDF
ter. This is shorter by 18 mm (about 3/4 inch), and slightly
wider by 8 mm (about 1/4 inch), compared to A4 (which • TeX → DVI → PS → PDF
is the standard in almost all the rest of the world). While
this is not a serious issue (most printers will print the doc-
latex myfile # TeX → DVI dvips myfile -o myfile.ps #
ument without any problems), it is possible to specify al-
DVI → PS ps2pdf myfile.ps myfile.pdf # PS → PDF
ternative sizes as class option. For A4 format:
Sadly the PDF output page size may not be completely re-
spectful of your settings. Some of these tools do not have
More size options with geometry the same interpretation of the DVI, PS and PDF specifi-
cations, and you may end up with a PDF which has not
One of the most versatile packages for page layout is exactly the right size. Thankfully there is a solution to
the geometry package. The immediate advantage of this that: the \special command lets the user pass PostScript
package is that it lets you customize the page size even or PDF parameters, which can be used here to set the
with classes that do not support the options. For instance, page size appropriately.
to set the page size, add the following to your preamble:
The geometry package has many pre-defined page sizes, • For pdflatex to work fine, using the package geom-
like a4paper, built in. Others include: etry usually works.

• a0paper, a1paper, ..., a6paper, • For the DVI and PS ways, the safest way to always
get the right paper size in the end is to add
• b0paper, b1paper, ..., b6paper,
• letterpaper, to the tex file, and to append the appropriate parameters
to the processors used during output generation:
• legalpaper, dvips -t a4 ... ps2pdf -sPAPERSIZE=a4 ... # On Win-
• executivepaper. dows: ps2pdf -sPAPERSIZE#a4 ... [1]
If you want US Letter instead, replace 210mm,297mm
To explicitly change the paper dimensions using the ge- by 8.5in,11in and a4paper by letter. Also replace a4 by
ometry package, the paperwidth and paperheight options letter in command-line parameters.
can be used. For example:
Page size for tablets
Changing size manually
Those who want to read on tablets or other handheld dig-
Use the \setlength command to adjust the parameters to ital devices need to create documents without the ex-
the appropriate dimensions. See the Lengths chapter. tra whitespace. In order to create PDF documents with
optimal handheld viewing, not only must the text field
• In the preamble, \paperwidth and \paperheight in all and margins be adjusted, so must the page size. If you
cases. are looking for a sensible dimension, consider following
the paper size used by the Supreme Court of the United
• After the preamble, \pdfpagewidth and \pdfpage- States, 441pt by 666pt (or 6.125 inches by 9.25 inches),
height if you are using pdftex. which looks great on tablets. You could also use the
Supreme Court’s text field size of 297 pt by 513 pt, but
Using the PDF dedicated commands has one immediate this is too wide for fonts other than Century Schoolbook,
advantage: it will let you change the page dimension any- the font required by the Supreme Court.
where in the document.

2.12.4 Margins
Page size issues
Readers used to perusing typical physical literature are
If you intend to get a PDF in the end, there are basically probably wondering why there is so much white space
three ways: surrounding the text. For example, on A4 paper a doc-
ument will typically have 44 mm margin widths on the
• TeX → PDF left and right of the page, leaving about 60% of the page
2.12. PAGE LAYOUT 55

width for text. The reason is improved readability. Stud- obsolete and buggy. Use geometry package instead
ies have shown[2][3] that it’s easier to read text when there like this:
are 60–70 characters per line—and it would seem that 66
is the optimal number. Therefore, the page margins are • Edit individual page dimension variables described
set to ensure optimal readability, and excessive margin above, using the \addtolength and \setlength com-
white space is tolerated as a consequence. Sometimes, mands. See the Lengths chapter. For instance,
this white space is left in the inner margin with the as-
sumption that the document will be bound.
If you wish to avoid excessive white space, rather than Odd and even margins
changing the margins, consider instead using a two-
column (or more) layout. This approach is the one usually Using the geometry package, the options left and right are
taken by print magazines because it provides both read- used for the inside and outside margins respectively. They
able line lengths and good use of the page. Another op- also have aliases inner and outer. Thus, the easiest way to
tion for reducing the amount of whitespace on the page handle different margins for odd and even pages is to give
without changing the margins is to increase the font size the twoside option in the document class command and
using the 12pt option to the document class. specify the margins as usually.

If you wish to change the margins of your document, This will result in a value of 4cm on all inner margins (left
there are many ways to do so: margin for odd number pages and right margin for even
pages) and 2cm margin on outer margins.
• One older approach is to use the fullpage package Setting the same value for the inner and outer for geome-
for somewhat standardized smaller margins (around try will remove the difference between the margins. An-
an inch), but it creates lines of more than 100 char- other quick way to eliminate the difference in position
acters per line at with the 10pt default font size (and between even and odd numbered pages would be setting
about 90 if the 12pt documentclass option is used): the values to evensidemargin and oddsidemargin to the
half of odd’s default:
For even narrower margins, the fullpage package has a cm By default, the value of evensidemargin is larger than
option (around 1.5cm), which results in about 120 char- oddsidemargin in the two-sided layout, as one could
acters per line at the 10pt default font size, about double wish to write notes on the side of the page. The side
what is considered readable: for the large margin is chosen opposite to the side where
pages are joined together.
• A more modern and flexible approach is to use the See the Lengths.
geometry package. This package allows you to spec-
ify the 4 margins without needing to remember the
particular page dimensions commands. You can en- Top margin above Chapter
ter the measures in centimeters and inches as well.
Use cm for centimeters and in for inches after each The top margin above a chapter can be changed using the
value (e.g. 1.0in or 2.54cm). Note that by default titlesec package. Example:
(i.e. without any options) this package already re- The command \titleformat must be used when the spacing
duces the margins, so for a 'standard layout' you may of a chapter is changed. In case of a section this command
not need to specify anything. These values are rel- can be omitted.
ative 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, 2.12.5 Page orientation
without creating the dramatically long lines of the
fullpage package (if the the 11pt documentclass op- When you talk about changing page orientation, it usually
tion is used, the line lengths are about 88 charac- means changing to landscape mode, since portrait is the
ters for leter-sized paper and slightly less when using default. We shall introduce two slightly different styles of
a4paper). changing orientation.

It can also recreate the behavior of the fullpage package


using Change orientation of the whole document

You can combine the margin options with the page size The first is for when you want all of your document to be
options seen in this paragraph. in landscape from the very beginning. There are various
packages available to achieve this, but the one we prefer
• You should not use the a4wide package for a page is the geometry package. All you need to do is call the
with A4 document size with smaller margins. It is package, with landscape as an option:
56 CHAPTER 2. COMMON ELEMENTS

Although, if you intend to use geometry to set your paper Standard page styles
size, don't add the \usepackage commands twice, simply
string all the options together, separating with a comma: The possibilities of changing the headers in plain La-
Using standard LaTeX classes, you can use the same class tex are actually quite limited. There are two commands
options: available: \pagestyle{''style''} will apply the specified
style to the current and all subsequent pages, and \this-
pagestyle{''style''} will only affect the current page. The
possible styles are:
Change orientation of specific part
The commands \markright and \markboth can be used
to set the content of the headings by hand. The follow-
The second method is for when you are writing a docu-
ing commands placed at the beginning of an article docu-
ment in portrait, but you have some contents, like a large
ment will set the header of all pages (one-sided) to contain
diagram or table that would be displayed better on a land-
“John Smith” top left, “On page styles” centered and the
scape page. However, you still want the consistency of
page number top right:
your headers and footers appearing the same place as the
other pages. There are special commands containing details on the
running page of the document.
The lscape package is for this very purpose. It supplies
a landscape environment, and anything inside is basically Note that \leftmark and \rightmark convert the names to
rotated. No actual page dimensions are changed. This uppercase, whichever was the formatting of the text. If
approach is more applicable to books or reports than to you want them to print the actual name of the chapter
typical academic publications. Using pdflscape instead of without converting it to uppercase use the following com-
lscape when generating a PDF document will make the mand:
page appear right side up when viewed: the single page Now \leftmark and \rightmark will just print the name of
that is in landscape format will be rotated, while the rest the chapter and section, without number and without af-
will be left in portrait orientation. fecting the formatting. Note that these redefinitions must
Also, to get a table to appear correctly centered on a land- be inserted after the first call of \pagestyle{fancy}. The
scaped page, one must place the tabular environment in- standard book formatting of the \chaptermark is:
side a table environment, which is itself inside the land- Watch out: if you provide long text in two different
scape environment. For instance it should look like this: “parts” only in the footer or only in the header, you might
see overlapping text.
Moreover, with the following commands you can define
Change orientation of floating environment the thickness of the decorative lines on both the header
and the footer:
If you use the above code, you will see that the table is
The first line for the header, the second for the footer.
inserted where it is in the code. It will not be floated! To
Setting it to zero means that there will be no line.
fix this you need the package rotating. See the Rotations
chapter.
Plain pages issue An issue to look out for is that the
major sectioning commands (\part, \chapter or \maketi-
2.12.6 Margins, page size and rotation of a tle) specify a \thispagestyle{plain}. So, if you wish to
specific page suppress all styles by inserting a \pagestyle{empty} at the
beginning of your document, then the style command at
If you need to rotate the page so that the figure fits, the each section will override your initial rule, for those pages
chances are good that you need to scale the margins and only. To achieve the intended result one can follow the
the font size too. Again, the geometry package comes in new section commands with \thispagestyle{empty}. The
handy for specifying new margins for a single page only. \part command, however, cannot be fixed this way, be-
cause it sets the page style, but also advances to the next
Note that order matters! page, so that \thispagestyle{} cannot be applied to that
page. Two solutions:

2.12.7 Page styles • simply write \usepackage{nopageno} in the pream-


ble. This package will make \pagestyle{plain} have
Page styles in Latex terms refers not to page dimensions, the same effect as \pagestyle{empty}, effectively
but to the running headers and footers of a document. suppressing page numbering when it is used.
These headers typically contain document titles, chapter
or section numbers/names, and page numbers. • Use fancyhdr as described below.
2.12. PAGE LAYOUT 57

The tricky problem when customizing headers and foot- Hopefully, the behaviour of the above commands is fairly
ers is to get things like running section and chapter names intuitive: if it has head in it, it affects the head etc, and
in there. Standard LaTeX accomplishes this with a two- obviously, l, c and r means left, centre and right respec-
stage approach. In the header and footer definition, you tively.
use the commands \rightmark and \leftmark to represent
the current section and chapter heading, respectively. The • You can also use the command \fancyhead for
values of these two commands are overwritten whenever header and \fancyfoot for footer. They work in the
a chapter or section command is processed. For ultimate same way, so we'll explain only the first one. The
flexibility, the \chapter command and its friends do not re- syntax is:
define \rightmark and \leftmark themselves. They call yet
another command (\chaptermark, \sectionmark, or \sub-
You can use multiple selectors optionally separated by a
sectionmark) that is responsible for redefining \rightmark
comma. The selectors are the following:
and \leftmark, except if they are starred -- in such a case,
\markboth{Chapter/Section name}{} must be used in- so CE,RO will refer to the center of the even pages and
side the sectioning command if header and footer lines to the right side of the odd pages.
are to be updated.
Again, several packages provide a solution: • \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, respec-
• an alternative one-stage mechanism is provided by
tively. If you omit the H and the F, it will set the
the package titleps);
fields for both.
• fancyhdr will handle the process its own way.
These commands will only work for fancy and fancyplain.
To customize LaTeX default style you need the \fancy-
Customizing with fancyhdr plainstyle command. See below for examples.
To get better control over the headers, one can use the For a clean customization, we recommend you start from
package fancyhdr written by Piet van Oostrum. It pro- scratch. To do so you should erase the current pagestyle.
vides several commands that allow you to customize the Providing empty values will make the field blank. So
header and footer lines of your document. For a more will just delete the current heading/footer configuration,
complete guide, the author of the package produced this so you can make your own.
documentation.
To begin, add the following lines to your preamble:
Plain pages There are two ways to change the style of
You can now observe a new style in your document. plain pages like chapters and titlepage.
The \headheight needs to be 13.6pt or more, otherwise First you can use the fancyplain style. If you do so, you
you will get a warning and possibly formatting issues. can use the command \fancyplain{...}{...} inside fancy-
Both the header and footer comprise three elements each hdr commands like \lhead{...}, etc.
according to its horizontal position (left, centre or right).
When LaTeX wants to create a page with an empty style,
The styles supported by fancyhdr: it will insert the first argument of \fancyplain, in all the
other cases it will use the second argument. For instance:
• the four LaTeX styles; It has the same behavior of the previous code, but you
will get empty header and footer in the title and at the
• fancy defines a new header for all pages but plain-
beginning of chapters.
style pages such as chapters and titlepage;
Alternatively you could redefine the plain style, for ex-
• fancyplain is the same, but for absolutely all pages. ample to have a really plain page when you want. The
command to use is \fancypagestyle{plain}{...} and the ar-
Style customization The styles can be customized gument can contain all the commands explained before.
with fancyhdr specific commands. Those two styles may An example is the following:
be configured directly, whereas for LaTeX styles you In that case you can use any style but fancyplain because
need to make a call to the \fancypagestyle command. it would override your redefinition.
To set header and footer style, fancyhdr provides three
interfaces. They all provide the same features, you just Examples For two-sided, it’s common to mirror the
use them differently. Choose the one you like most. style of opposite pages, you tend to think in terms of inner
and outer. So, the same example as above for two-sided
• You can use the following six commands. is:
58 CHAPTER 2. COMMON ELEMENTS

This is effectively saying author name is top outer, to- • Additionally, the environment can be nested inside
day’s date is top inner, and current page number is bottom other environments, such as figure.
outer. Using \fancyhf can make it shorter:
• multicol outputs balanced columns, whereby the
Here is the complete code of a possible style you could columns on the final page will be of roughly equal
use for a two-sided document: length.
Using \fancypagestyle one can additionally define multi-
ple styles for one’s document that are easy to switch be- • Vertical rules between columns can be customised.
tween. Here’s a somewhat complicated example for a
two-sided book style: • Column environments can be easily customised lo-
cally or globally.

Page n of m
Using multicol package
Some people like to put the current page number in con-
The multicol package overcomes some of the shortcom-
text with the whole document. LaTeX only provides ac-
ings of twocolumn and provides the multicol environ-
cess to the current page number. However, you can use
ment. To create a typical two-column layout:
the lastpage package to find the total number of pages,
like this: Floats are not fully supported by this environment. It can
only cope if you use the starred forms of the float com-
Note the capital letters. Also, add a backslash after \thep-
mands (e.g., \begin{figure*} ) which makes the float span
age to ensure adequate space between the page number
all columns. This is not hugely problematic, since floats
and 'of'. And recall, when using references, that you
of the same width as a column may be too small, and you
have to run LaTeX an extra time to resolve the cross-
would probably want to span them anyway. See this sec-
references.
tion for a more detailed discussion.
The multicol package has two important parameters
Alternative packages which can be set using \setlength:

Other packages for page styles are scrpage2, very simi- • \columnseprule, sets the width of the vertical rule
lar to fancyhdr, and titleps, which takes a one-stage ap- between columns and defaults to 0pt
proach, without having to use \leftmark or \rightmark.
• \columnsep, sets the horizontal space between
columns and the defaults to 10pt, which is quite nar-
2.12.8 Page background row

The eso-pic package will let you print content in the back- To force a break in a column, the command \columnbreak
ground of every page or individual pages. is used.
The starred-version of the \AddToShipoutPicture com-
mand applies to the current page only.
2.12.10 Manual page formatting

2.12.9 Multi-column pages There may be instances, especially in very long docu-
ments, such as books, that LaTeX will not get all page
Using the twocolumn optional class argument breaks looking as good as it could. It may, therefore,
be necessary to manually tweak the page formatting. Of
Using a standard Latex document class, like article, you course, you should only do this at the very final stage of
can simply pass the optional argument twocolumn to the producing your document, once all the content is com-
document class: \documentclass[twocolumn]{article} plete. LaTeX offers the following:
which will give the desired effect.
While this approach is useful, it has limitations. The mul- 2.12.11 Widows and orphans
ticol package provides the following advantages:
In professional books, it’s not desirable to have single lines
• Can support up to ten columns. at the beginning or end of a page. In typesetting such sit-
uations are called 'widows’ and 'orphans’. Normally it is
• Implements a multicols environment, therefore, it is possible that widows and orphans appear in LaTeX docu-
possible to mix the number of columns within a doc- ments. You can try to deal with them using manual page
ument. formatting, but there’s also an automatic solution.
2.13. IMPORTING GRAPHICS 59

LaTeX has a parameter for 'penalty' for widows and or- 2.13.1 Raster graphics vs. vector graphics
phans ('club lines’ in LaTeX terminology). With the
greater penalty LaTeX will try more to avoid widows Raster graphics will highly contrast with the quality of the
and orphans. You can try to increase these penalties by document if they are not in a high resolution, which is the
putting following commands in your document preamble: case with most graphics. The result may be even worse
If this does not help, you can try increasing these values once printed.
even more, to a maximum of 10000. However, it is not Most drawing tools (e.g. for diagrams) can export in vec-
recommended to set this value too high, as setting it to tor format. So you should always prefer PDF or EPS to
10000 forbids LaTeX from doing this altogether, which PNG or JPG.
might result in strange behavior.
It also helps to have rubber band values for the space be-
tween paragraphs:
2.13.2 The graphicx package
Alternatively, you can use the needspace package to re- As stated before, LaTeX can't manage pictures directly,
serve some lines and thus to prevent page breaking for so we will need some extra help: we have to load the
those lines. graphicx package in the preamble of our document:
This package accepts as an argument the external driver to
2.12.12 Troubleshooting be used to manage pictures; however, the latest version of
this package takes care of everything by itself, changing
A very useful troubleshooting and designing technique is the driver according to the compiler you are using, so you
to turn on the showframe option in the geometry package don't have to worry about this. Still, just in case you want
(which has the same effect as the showframe package de- to understand better how it works, here are the possible
scribed above. It draws bounding boxes around the major options you can pass to the package:
page elements, which makes where the various regions
of the page are, which is often unclear because of white • dvips (default if compiling with latex), if you are
whitespace. compiling with latex to get a DVI and you want to
see your document with a DVI or PS viewer.

2.12.13 Notes and References • dvipdfm, if you are compiling with latex to get a
DVI that you want to convert to PDF using dvipdfm,
This page uses material from Andy Roberts’ Getting to grips to see your document with any PDF viewer.
with LaTeX with permission from the author.
• pdftex (default if compiling with pdflatex), if you
are compiling with pdftex to get a PDF that you will
[1] How to use Ghostscript
see with any PDF viewer.
[2] http://webtypography.net/2.1.2

[3] http://baymard.com/blog/line-length-readability But, again, you don't need to pass any option to the pack-
age because the default settings are fine in most of the
cases.

2.13 Importing Graphics In many respects, importing your images into your docu-
ment using LaTeX is fairly simple... once you have your
images in the right format that is! Therefore, I fear for
There are two possibilities to include graphics in your
many people the biggest effort will be the process of con-
document. Either create them with some special code,
verting their graphics files. Now we will see which for-
a topic which will be discussed in the Creating Graph-
mats we can include and then we will see how to do it.
ics part, (see Introducing Procedural Graphics) or import
productions from third party tools, which is what we will
be discussing here. 2.13.3 Document Options
Strictly speaking, LaTeX cannot manage pictures di-
rectly: in order to introduce graphics within documents, The graphics and graphicx packages recognize the draft
LaTeX just creates a box with the same size as the im- and final options given in the \documentclass[...]{...}
age you want to include and embeds the picture, without command at the start of the file. (See Document Classes.)
any other processing. This means you will have to take Using draft as the option will suppress the inclusion of the
care that the images you want to include are in the right image in the output file and will replace the contents with
format to be included. This is not such a hard task be- the name of the image file that would have been seen. Us-
cause LaTeX supports the most common picture formats ing final will result in the image being placed in the output
around. file. The default is final.
60 CHAPTER 2. COMMON ELEMENTS

2.13.4 Supported image formats • EPS can be used with the help of the epstopdf pack-
age. Depending on your installation,
As explained before, the image formats you can use de-
pend on the driver that graphicx is using but, since the • you may just need to have it installed, there is
driver is automatically chosen according to the compiler, no need to load it in your document;
then the allowed image formats will depend on the com- • if it does not work, you need to load it just after
piler you are using. the graphicx package. Additionally, since ep-
Consider the following situation: you have added some stopdf will need to convert the EPS file into a
pictures to your document in JPG and you have success- PDF file and store it, you need to give “writing
fully compiled it in PDF. Now you want to compile it in permissions” to your compiler. This is done by
DVI, you run latex and you get a lot of errors... because adding an option to the compiling command,
you forgot to provide the EPS versions of the pictures you e.g. pdflatex -shell-escape file.tex (if you use a
want to insert. LaTeX editor, they usually allow to modify the
command in the configuration options). Check
At the beginning of this book, we had stated that the same
the epstopdf documentation for other compil-
LaTeX source can be compiled in both DVI and PDF
ers.
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 2.13.5 Including graphics
provide the pictures in two formats (EPS and one of JPG,
PNG or PDF). 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
Compiling with latex loaded the graphicx package in your preamble, you can
include images with \includegraphics, whose syntax is the
The only format you can include while compiling with following:
latex is Encapsulated PostScript (EPS). As usual, arguments in square brackets are optional,
The EPS format was defined by Adobe Systems for mak- whereas arguments in curly braces are compulsory.
ing it easy for applications to import postscript-based The argument in the curly braces is the name of the im-
graphics into documents. Because an EPS file declares age. Write it without the extension. This way the La-
the size of the image, it makes it easy for systems like La- TeX compiler will look for any supported image format
TeX to arrange the text and the graphics in the best way. in that directory and will take the best one (EPS if the
EPS is a vector format—this means that it can have very output is DVI; JPEG, PNG or PDF if the output is PDF).
high quality if it is created properly, with programs that Images can be saved in multiple formats for different pur-
are able to manage vector graphics. It is also possible to poses. For example, a directory can have “diagram.pdf”
store bit-map pictures within EPS, but they will need a for high-resolution printing, while “diagram.png” can be
lot of disk space. used for previewing on the monitor. You can specify
which image file is to be used by pdflatex through the
preamble command:
Compiling with pdflatex
which specifies the files to include in the document (in or-
If you are compiling with pdflatex to produce a PDF, you der of preference), if files with the same basename exist,
have a wider choice. You can insert: but with different extensions.
The variety of possible attributes that can be set is fairly
• JPG, widely used on Internet, digital cameras, etc. large, so only the most common are covered below:
They are the best choice if you want to insert photos. In order to use more than one option at a time, simply sep-
arate each with a comma. The order you give the options
• PNG, a very common format (even if not as much as matters. E.g you should first rotate your graphic (with
JPG); it’s a lossless format and it’s the best choice for angle) and then specify its width.
diagrams (if you were not able to generate a vector
Included graphics will be inserted just there, where you
version) and screenshots.
placed the code, and the compiler will handle them as
• PDF, it is widely used for documents but can be “big boxes”. As we will see in the floats section, this can
used to store images as well. It supports both vec- disrupt the layout; you'll probably want to place graphics
tor and bit-map images, but it’s not recommended inside floating objects.
for the latter, as JPG or PNG will provide the same Also note that the trim option does not work with XeLa-
result using less disk space. Tex.
2.13. IMPORTING GRAPHICS 61

Be careful using any options, if you are working with of the border by adjusting the \setlength\fboxrule{0.5pt}
the chemnum-package. The labels defined by \cmp- command.
dref{<label name>} might not behave as expected. Scal- See Boxes for more details on \framebox and \fbox.
ing the image for instance may be done by \scalebox in-
stead.
The star version of the command will work for .eps files
2.13.6 Graphics storage
only. For a more portable solution, the standard way
should take precedence. The star command will take the
crop dimension as extra parameter: The command \graphicspath tells LaTeX where to look
for images, which can be useful if you store images cen-
trally for use in many different documents. The \graphic-
Examples spath command takes one argument, which specifies the
additional paths you want to be searched when the \in-
OK, it’s time to see graphicx in action. Here are some cludegraphics command is used. Here are some examples
examples. Say you had a file 'chick.jpg' you would include (trailing / is required):
it like: Please see http://www.ctan.org/tex-archive/macros/
This simply imports the image, without any other pro- latex/required/graphics/grfguide.pdf. In the third exam-
cessing. However, it is very large (so we won't give an ple shown there should be a directory named “images”
example of how it would look here!) So, let’s scale it in the same directory as your main tex file, i.e. this is
down: RELATIVE addressing.
This has now scaled it by half. If you wish to be more Using absolute paths, \graphicspath makes your file less
specific and give actual lengths of the image dimensions, portable, while using relative paths (like the third exam-
this is how to go about it: ple), there should not be any problem with portability.
The fourth example uses the “safe” (MS-DOS) form of
One can also specify the scale with respect to the width the Windows MyPictures folder because it’s a bad idea to
of a line in the local environment (\linewidth), the width use directory names containing spaces. Again, ensure file
of the text on a page (\textwidth) or the height of the text names do not contain spaces or alternatively if you are
on a page (\textheight) (pictures not shown): using PDFLaTeX, you can use the package grffile which
To rotate (I also scaled the image down): will allow you to use spaces in file names.
And finally, an example of how to crop an image should Note that you cannot make the graphicx package search
you wish to focus on one particular area of interest: directories recursively. Under Linux/Unix, you can
achieve a recursive search using the environment variable
Note: the presence of clip, as the trim operation will not
TEXINPUTS, e.g., by setting it to
work without it.
export TEXINPUTS=./images//:./Snapshots//
Trick: You can also use negative trim values to add blank
space to your graphics, in cases where you need some
manual alignment. before running latex/pdflatex or your TeX-IDE. (But this,
of course, is not a portable method.)

Spaces in names

If the image file were called “chick picture.png”, then you 2.13.7 Images as figures
need to include the full filename when importing the im-
age: The figure environment is not exclusively used for images.
We will only give a short preview of figures here. More
One option is to not use spaces in file names (if possible), information on the figure environment and how to use it
or to simply replace spaces with underscores (“chick pic- can be found in Floats, Figures and Captions.
ture.png” to “chick_picture.png”)
There are many scenarios where you might want to ac-
company an image with a caption and possibly a cross-
Borders reference. This is done using the figure environment. The
following code sample shows the bare minimum required
It is possible to have LaTeX create a border around your to use an image as a figure.
image by using \fbox: The above code extract is relatively trivial, and doesn't of-
You can control the border padding with the fer much functionality. The following code sample shows
\setlength\fboxsep{0pt} command, in this case I set it to an extended use of the figure environment which is almost
0pt to avoid any padding, so the border will be placed universally useful, offering a caption and label, centering
tightly around the image. You can control the thickness the image and scaling it to 80% of the width of the text.
62 CHAPTER 2. COMMON ELEMENTS

2.13.8 Text wrapping around pictures You should also take a look at Export To Other Formats
for other possibilities.
See Floats, Figures and Captions.
epstopdf

2.13.9 Seamless text integration You can convert EPS to PDF with the epstopdf utility,
included in package of the same name. This tool is actu-
The drawback of importing graphics that were gener- ally called by pdflatex to convert EPS files to PDF in the
ated with a third-party tool is that font and size will not background when the graphicx package is loaded. This
match with the rest of the document. There are still some process is completely invisible to the user.
workarounds though.
You can batch convert files using the command-line. In
The easiest solution is to use the picture environment and Bourne Shell (Unix) this can be done by:
then simply use the “put” command to put a graphics file
$ for i in *.eps; do epstopdf "$i"; done
inside the picture, along with any other desired LaTeX
element. For example:
In Windows, multiple files can be converted by placing
Note that the border around the picture in the above ex-
the following line in a batch file (a text file with a .bat
ample was added by using \fbox, so the contents of the
extension) in the same directory as the images:
border is the picture as generated by the above code.
for %%f in (*.eps) do epstopdf %%f
Tools like Inkscape or Xfig have a dedicated LaTeX ex-
port feature that will let you use correct font and size for
text in vector graphics. See #Third-party graphics tools. which can then be run from the command line.
For a perfect integration of graphics, you might consider If epstopdf produces whole page with your small graphics
procedural graphics capabilities of some LaTeX packages somewhere on it, use
like TikZ or PSTricks. It lets you draw from within a $ epstopdf --gsopt=-dEPSCrop foo.eps
document source. While the learning curve is steeper, it
is worth it most of the time.
or try using ps2pdf utility which should be installed with
Ghostscript (required for any TeX distribution).
2.13.10 Including full PDF pages $ ps2pdf -dEPSCrop foo.eps
There is a great package for including full pages of PDF
files: pdfpages. It is capable of inserting entire pages as to crop final PDF.
is and more pages per one page in any layout (e.g. 2x3).
eps2eps
The package has several options:
Options: When all of the above fails, one can simplify the EPS file
before attempting other conversions, by using the eps2eps
• final: Inserts pages. This is the default. tool (also see next section):
$ eps2eps input.eps input-e2.eps
• draft: Does not insert pages, but prints a box and
the filename instead.
This will convert all the fonts to pre-drawn images, which
• enable-survey: Activates survey functionalities. is sometimes desirable when submitting manuscripts for
(Experimental, subject to change.) publication. However, on the downside, the fonts are
NOT converted to lines, but instead to bitmaps, which
The first command is reduces the quality of the fonts.
Options for key=val (A comma separated list of options
using the key = value syntax) imgtops

You can also inserts pages of several external PDF docu- imgtops is a lightweight graphics utility for conversions
ments. between raster graphics (JPG, PNG, ...) and EPS/PS
Several PDFs can be placed table-like on one page. See files.
more information in its documentation.
Inkscape

2.13.11 Converting graphics Inkscape can also convert files from and to several for-
mats, either from the GUI or from the command-line. For
Note instance, to obtain a PDF from a SVG image you can do:
2.13. IMPORTING GRAPHICS 63

$ inkscape -z -D --file=input.svg --export-pdf=output.pdf Converting a color EPS to grayscale

Sometimes color EPS figures need to be converted to


It is possible to run this from within a LaTeX file,
black-and-white or grayscale to meet publication require-
the Template:LaTeX/package package (when running
ments. This can be achieved with the eps2eps of the
(pdf)latex with the --shell-escape option) can do this us-
Ghostscript package and programs:
ing Inkscape’s pdf+tex export option, or a simple macro
can be used. See How to include SVG diagrams in La- $ eps2eps input.eps input-e2.eps $ pscol −0gray input-
TeX? -- Stackexchange See Export To Other Formats for e2.eps input-gray.eps
more details.

pstoedit
2.13.12 Third-party graphics tools
To properly edit an EPS file, you can convert it to an ed- We will not tackle the topic of procedural graphics cre-
itable format using pstoedit. For instance, to get an Xfig- ated from within LaTeX code here (TikZ, PSTricks,
editable file, do: MetaPost and friends). See Introducing Procedural
$ pstoedit -f fig input.eps output.fig Graphics for that.
You should prefer vector graphics over raster graphics for
And to get an SVG file (editable with any vector graphics their quality. Raster graphics should only be used in case
tool like Inkscape) you can do: of photos. Diagrams of any sort should be vectors.
$ pstoedit -f plot-svg input.eps output.svg As we have seen before, LaTeX handles

• EPS and PDF for vector graphics;


Sometimes pstoedit fails to create the target format (for
example when the EPS file contains clipping informa- • PNG and JPG for raster graphics.
tion).
If some tools cannot save in those formats, you may want
to convert them before importing them.
PDFCreator

Under Windows, PDFCreator is an open source software Vector graphics


that can create PDF as well as EPS files. It installs a
virtual printer that can be accessed from other software Dia
having a “print...” entry in their menu (virtually any pro-
gram). Dia is a cross platform diagramming utility which can
export eps images, or generate tex drawn using the tikz
package.
Raster graphics converters
Inkscape
• Sam2p (convert) or
Another program for creating vector graphics is Inkscape.
• ImageMagick (convert) or It can run natively under Windows, Linux or Mac OS
• GraphicsMagick (gm convert). X (with X11). It works with Scalable Vector Graph-
ics (SVG) files, although it can export to many for-
These three programs operate much the same way, and mats that can be included in LaTeX files, such as
can convert between most graphics formats. Sam2p how- EPS and PDF. From version 0.48, there is a combined
ever is the most recent of the three and seems to offer PDF/EPS/PS+LaTeX output option, similar to that of-
both the best quality and to result in the smallest files. fered by Xfig. There are instructions on how to save your
vector images in a PDF format understood by LaTeX and
have LaTeX manage the text styles and sizes in the im-
PNG alpha channel age automatically.[1] . Today there is the svg package[2]
which provides an \includesvg command to convert and
Acrobat Reader sometimes has problems with displaying include svg-graphics directly in your LaTeX document
colors correctly if you include graphics in PNG format using Inkscape. You may have a look at this extended
with alpha channel. You can solve this problem by drop- example too.
ping the alpha channel. On Linux it can be achieved with An extremely useful plug-in is textext, which can import
convert from the ImageMagick program: LaTeX objects. This can be used for inserting mathemat-
convert -alpha off input.png output.png ical notation or LaTeX fonts into graphics (which may
then be imported into LaTeX documents).
64 CHAPTER 2. COMMON ELEMENTS

Ipe 1. Create the drawing in xfig. Wherever you need La-


TeX text, such as a mathematical formula, enter a
The Ipe extensible drawing editor is a free vector graphics LaTeX string in a textbox.
editor for creating figures in PDF or EPS format. Unlike 2. Use the Edit tool to open the properties of each of
Xfig, Ipe represents LaTeX fonts in their correct size on those textboxes, and change the option on the “Spe-
the screen which makes it easier to place text labels at cial Flag” field to Special. This tells LaTeX to inter-
the right spot. Ipe also has various snapping modes (for pret these textboxes when it opens the figure.
example, snapping to points, lines, or intersections) that
can be used for geometric constructions. 3. Go to File -> Export and export the file as
PDF/LaTeX (both parts) or PS/LaTeX (both parts),
lpic depending on whether you are using pdflatex or ps-
latex to compile your file.
Yet another solution is provided by the lpic packages , 4. In your LaTeX document, where the picture should
which allows TeX annotations to imported graphics. See be, use the following, where “test” is replaced by the
Labels in the figures. name of the image:
Observe that this is just like including a picture, ex-
OpenOffice.org cept that rather than using \includegraphics, we use
\input. If the export was into PS/LaTeX, the file
It is also possible to export vector graphics to EPS for- extension to include would be .pstex_t instead of
mat using OpenOffice.org Draw, which is an open source .pdf_t.
office suite available for Windows, Linux and Mac.
5. Make sure to include packages graphicx and color in
the file, with the \usepackage command right below
TpX the \documentclass command, like this:

Vector editor TpX separates geometric objects from text And you're done!
objects. Geometric objects are saved into .PDF file, the
For more details on using xfig with LaTeX, this chapter
rest is saved in .TpX file to be processed by LaTeX. User
of the xfig User Manual may prove helpful.
just create the graphics in TpX editor and calls the .TpX
file from latex file by command \input{...TpX}.
Other tools
Xfig
Commercial vector graphics software, such as Adobe
Illustrator, CorelDRAW, and FreeHand are commonly
Xfig is a basic program that can produce vector graphics,
used and can read and write EPS figures. However, these
which can be exported to LaTeX. It can be installed on
products are limited to Windows and Mac OS X plat-
Unix platforms.
forms.
On Microsoft Windows systems, Xfig can only be in-
stalled using Cygwin-X; however, this will require a fast
internet connection and about 2 gigabytes of space on Raster graphics
your computer. With Cygwin, to run Xfig, you need to
first start the “Start X - Server”, then launch “xterm” to Adobe Photoshop
bring up a terminal. In this terminal type “xfig” (without
the quotation marks) and press return. It can save to EPS.
Alternatively, WinFIG is an attempt to achieve the func-
tionality of xfig on Windows computers. GIMP

There are many ways to use xfig to create graphics for La-
GIMP, has a graphical user interface, and it is multi-
TeX documents. One method is to export the drawing as
platform. It can save to EPS and PDF.
a LaTeX document. This method, however, suffers from
various drawbacks: lines can be drawn only at angles that
are multiples of 30 and 45 degrees, lines with arrows can Plots and Charts
only be drawn at angles that are multiples of 45 degrees,
several curves are not supported, etc. Generic Mapping Tools (GMT)
Exporting a file as PDF/LaTeX or PS/LaTeX, on the
other hand, offers a good deal more flexibility in draw- Generic Mapping Tools (GMT), maps and a wide range
ing. Here’s how it’s done: of highly customisable plots.
2.14. FLOATS, FIGURES AND CAPTIONS 65

Gnumeric 2.14.1 Floats


Gnumeric, spreadsheets has SVG, EPS, PDF export Floats are containers for things in a document that can-
not be broken over a page. LaTeX by default recognizes
Gnuplot “table” and “figure” floats, but you can define new ones of
your own (see Custom floats below). Floats are there to
Gnuplot, producing scientific graphics since 1986. If you deal with the problem of the object that won't fit on the
want to make mathematical plots, then Gnuplot can save present page, and to help when you really don't want the
in any format. You can get best results when used along object here just now.
PGF/TikZ.
Floats are not part of the normal stream of text, but sepa-
matplotlib rate entities, positioned in a part of the page to themselves
(top, middle, bottom, left, right, or wherever the designer
matplotlib, plotting library written in python, with PDF specifies). They always have a caption describing them
and EPS export. On the other hand there is a PGF export and they are always numbered so they can be referred to
also. There are some tricks to be able to import formats from elsewhere in the text. LaTeX automatically floats
other than EPS into your DVI document, but they're very Tables and Figures, depending on how much space is left
complicated. On the other hand, converting any image to on the page at the point that they are processed. If there is
EPS is very simple, so it’s not worth considering them. not enough room on the current page, the float is moved to
the top of the next page. This can be changed by moving
R the Table or Figure definition to an earlier or later point
in the text, or by adjusting some of the parameters which
R, statistical and scientific figures. control automatic floating.
Authors sometimes have many floats occurring in rapid
Editing EPS graphics succession, which raises the problem of how they are sup-
posed to fit on the page and still leave room for text. In
As described above, graphics content can be imported this case, LaTeX stacks them all up and prints them to-
into LaTeX from outside programs as EPS files. But gether if possible, or leaves them to the end of the chapter
sometimes you want to edit or retouch these graphics files. in protest. The skill is to space them out within your text
An EPS file can be edited with any text editor since it so that they intrude neither on the thread of your argu-
is formatted as ASCII. In a text editor, you can achieve ment or discussion, nor on the visual balance of the type-
simple operations like replacing strings or moving items set pages.
slightly, but anything further becomes cumbersome. Vec-
tor graphics editors, like Inkscape, may also be able to
import EPS files for subsequent editing. This approach Figures
also for easier editing. However, the importing process
may occassionally modify the original EPS image. To create a figure that floats, use the figure environment.
The previous section mentioned how floats are used to
allow LaTeX to handle figures, while maintaining the best
2.13.13 Notes and References
possible presentation. However, there may be times when
[1] Johan B. C. Engelen. “How to include an you disagree, and a typical example is with its positioning
SVG image in LATEX”. mirrorcatalogs.com. of figures. The placement specifier parameter exists as a
http://ctan.mirrorcatalogs.com/info/svg-inkscape/ compromise, and its purpose is to give the author a greater
InkscapePDFLaTeX.pdf. degree of control over where certain floats are placed.
[2] Philip Ilten. “The svg package on CTAN”. ctan.org. http: What you do with these placement permissions is to list
//www.ctan.org/tex-archive/graphics/svg. which of the options you wish to make available to La-
TeX. These are simply possibilities, and LaTeX will de-
cide when typesetting your document which of your sup-
2.14 Floats, Figures and Captions plied specifiers it thinks is best. Frank Mittelbach de-
scribes the algorithm[2] :
The previous chapter introduced importing graphics.
However, just having a picture stuck in between para- • If a float is encountered, LaTeX attempts to place it
graphs does not look professional. To start with, we immediately according to its rules (detailed later)
want a way of adding captions, and to be able to cross-
reference. What we need is a way of defining figures. It • if this succeeds, the float is placed and that de-
would also be good if LaTeX could apply principles sim- cision is never changed;
ilar to when it arranges text to look its best to arranging • if this does not succeed, then LaTeX places the
pictures as well. This is where floats come into play. float into a holding queue to be reconsidered
66 CHAPTER 2. COMMON ELEMENTS

when the next page is started (but not earlier). an option to change the definition of \section to auto-
matically include a \FloatBarrier. This can be set by
• Once a page has finished, LaTeX examines this loading the package with the option [section] (\usepack-
holding queue and tries to empty it as best as possi- age[section]{placeins}). \FloatBarrier may also be useful
ble. For this it will first try to generate as many float to prevent floats intruding on lists created using itemize
pages as possible (in the hope of getting floats off or enumerate. The flafter package can be used to force
the queue). Once this possibility is exhausted, it will floats to appear after they are defined, and the endfloat
next try to place the remaining floats into top and package can be used to place all floats at the end of a
bottom areas. It looks at all the remaining floats and document. The float package provides the H option to
either places them or defers them to a later page (i.e., floating environments, which stops them from floating.
re-adding them to the holding queue once more).

• After that, it starts processing document material for


this page. In the process, it may encounter further 2.14.3 Captions
floats.
It is always good practice to add a caption to any figure or
• If the end of the document has been reached or if a
table. Fortunately, this is very simple in LaTeX. All you
\clearpage is encountered, LaTeX starts a new page,
need to do is use the \caption{''text''} command within
relaxes all restrictive float conditions, and outputs all
the float environment. LaTeX will automatically keep
floats in the holding queue by placing them on float
track of the numbering of figures, so you do not need to
page(s).
include this within the caption text.

In some special cases LaTeX won't follow these position-The location of the caption is traditionally underneath the
ing parameters and additional commands will be neces- float. However, it is up to you to therefore insert the cap-
sary, for example, if one needs to specify an alignment tion command after the actual contents of the float (but
still within the environment). If you place it before, then
other than centered for a float that sits alone in one page[3] .
the caption will appear above the float. Try out the fol-
Use \listoffigures to add a list of the figures in the be- lowing example to demonstrate this effect:
ginning of the document. To change the name used in
the caption from Figure to Example, use \renewcom- Note that the command \reflectbox{...} flips its content
mand{\figurename}{Example} in the figure contents. horizontally.

Figures with borders It’s possible to get a thin border


Side captions
around all figures. You have to write the following once
at the beginning of the document:
It is sometimes desirable to have a caption appear on the
The border will not include the caption. side of a float, rather than above or below. The sidecap
package can be used to place a caption beside a figure
or table. The following example demonstrates this for a
Tables
figure by using a SCfigure environment in place of the
figure environment.
Floating tables are covered in a separate chapter. Let’s
give a quick reminder here. The tabular environment that
was used to construct the tables is not a float by default.
Therefore, for tables you wish to float, wrap the tabular Unnumbered captions
environment within a table environment, like this:
You may feel that it is a bit long winded, but such distinc- In some types of document (such as presentations), it may
tions are necessary, because you may not want all tables not be desirable for figure captions to start Figure:. This is
to be treated as a float. easy to suppress by just placing the caption text in the Fig-
ure environment, without enclosing it in a Caption. This
Use \listoftables to add a list of the tables in the beginning however means that there is no caption available for in-
of the document. clusion in a list of figures.

2.14.2 Keeping floats in their place


Renaming table caption prefix
The placeins package provides the command \FloatBar-
rier, which can be used to prevent floats from being In case you want to rename your table caption from “Ta-
moved over it. This can, e.g., be useful at the be- ble” to something else, you can use the \captionsetup
ginning of each section. The package even provides command. For example,
2.14. FLOATS, FIGURES AND CAPTIONS 67

2.14.4 Lists of figures and tables ample:


You can also allow LaTeX to assign a width to the wrap
Captions can be listed at the beginning of a paper or re-
by setting the width to 0pt. \begin{wrapfigure}{l}{0pt}
port in a “List of Tables” or a “List of Figures” section
by using the \listoftables or \listoffigures commands, re- Note that we have specified a size for both the wrapfigure
spectively. The caption used for each figure will appear in environment and the image we have included. We did it
these lists, along with the figure numbers, and page num- in terms of the text width: it is always better to use rela-
bers that they appear on. tive sizes in LaTeX, let LaTeX do the work for you! The
“wrap” is slightly bigger than the picture, so the compiler
The \caption command also has an optional parameter,
will not return any strange warning and you will have a
\caption[''short'']{''long''} which is used for the List of Ta-
small white frame between the image and the surround-
bles or List of Figures. Typically the short description is
ing text. You can change it to get a better result, but if
for the caption listing, and the long description will be
you don't keep the image smaller than the “wrap”, you
placed beside the figure or table. This is particularly use-
will see the image over the text.
ful if the caption is long, and only a “one-liner” is desired
in the figure/table listing. Here is an example of this us- The wrapfig package can also be used with user-defined
age: floats with float package. See below in the section on cus-
tom floats.

2.14.5 Labels and cross-referencing


Tip for figures with too much white space
Labels and cross-references work fairly similarly to the
general case - see the Labels and Cross-referencing sec- It happens that you'll generate figures with too much (or
tion for more information. too little) white space on the top or bottom. In such a
If the label picks up the section or list number instead case, you can simply make use of the optional argument
of the figure number, put the label inside the caption to [lineheight]. It specifies the height of the figure in num-
ensure correct numbering. If you get an error when the ber of lines of text. Also remember that the environment
label is inside the caption, use \protect in front of the \la- center adds some extra white space at its top and bottom;
bel command. consider using the command \centering instead.
Another possibility is adding space within the float using
the \vspace{...} command. The argument is the size of
2.14.6 Wrapping text around figures the space you want to add, you can use any unit you want,
including pt, mm, in, etc. If you provide a negative ar-
An author may prefer that some floats do not break the gument, it will add a negative space, thus removing some
flow of text, but instead allow text to wrap around it. (Ob- white space. Using \vspace tends to move the caption
viously, this effect only looks decent when the figure in relative to the float while the [lineheight] argument does
question is significantly narrower than the text width.) not. Here is an example using the \vspace command, the
A word of warning: Wrapping figures in LaTex will code is exactly the one of the previous case, we just added
require a lot of manual adjustment of your document. some negative vertical spaces to shrink everything up:
There are several packages available for the task, but none In this case it may look too shrunk, but you can manage
of them works perfectly. Before you make the choice of
spaces the way you like. In general, it is best not to add
including figures with text wrapping in your document, any space at all: let LaTeX do the formatting work!
make sure you have considered all the options. For ex-
ample, you could use a layout with two columns for your (In this case, the problem is the use of \begin{center}
documents and have no text-wrapping at all. to center the image. The center environment adds extra
space that can be avoided if \centering is used instead.)
Anyway, we will look at the package wrapfig. Note that
wrapfig may not come with the default installation of You can use intextsep parameter to control
LaTeX; you might need to install additional packages. additional space above and below the figure:
Noted also, wrapfig is incompatible with the enumerate \setlength\intextsep{0pt}
and itemize environments Alternatively you might use the picins package instead
To use wrapfig, you must first add this to the preamble: of the wrapfig package which produces a correct version
without the excess white space out of the box without any
This then gives you access to: hand tuning.
There are overall eight possible positioning targets: There is also an alternative to wrapfig: the package floatflt
The uppercase-character allows the figure to float, while .
the lowercase version means “exactly here”. [4] To remove the white space from a figure once for all, one
The width is, of course, the width of the figure. An ex- should refer to the program pdfcrop, included in most
68 CHAPTER 2. COMMON ELEMENTS

TeX installations. width of a column (using a LaTeX notation, wider than


0.5\textwidth), otherwise you will see the image overlap-
ping with text. If you really have to use such wide ele-
2.14.7 Subfloats ments, the only solution is to use the “starred” variants
of the floating environments, that are {figure*} and {ta-
A useful extension is the subcaption package which uses ble*}. Those “starred” versions work like the standard
subfloats within a single float. The subfigure and subfig ones, but they will be as wide as the page, so you will get
packages are deprecated however they are useful alterna- no overlapping.
tives when used in-conjunction with latex templates (i.e
templates for journals from Springer and IOP, IEEETran A bad point of those environments is that they can be
and ACM SIG) that are not compatible with subcaption. placed only at the top of the page or on their own page. If
These packages give the author the ability to have subfig- you try to specify their position using modifiers like b or
ures within figures, or subtables within table floats. Sub- h they will be ignored. Add \usepackage{dblfloatfix} to
floats have their own caption, and an optional global cap- the preamble in order to alleviate this problem with regard
tion. An example will best illustrate the usage of the sub- to placing these floats at the bottom of a page, using the
caption package: optional specifier [b]. Default is [tbp]. However, h still
does not work.
To prevent the figures from being placed out-of-order
with respect to their “non-starred” counterparts, the
package fixltx2e [5] should be used (e.g. \usepack-
age{fixltx2e}).

2.14.9 Custom floats

You will notice that the figure environment is set up as If tables and figures are not adequate for your needs, then
usual. You may also use a table environment for subta- you always have the option to create your own! Exam-
bles. For each subfloat, you need to use: ples of such instances could be source code examples, or
maps. For a program float example, one might therefore
If you intend to cross-reference any of the subfloats, see
wish to create a float named program. The package float
where the label is inserted; \caption outside the subfigure-
is your friend for this task. All commands to set up the
environment will provide the global caption.
new float must be placed in the preamble, and not within
subcaption will arrange the figures or tables side-by-side the document.
providing they can fit, otherwise, it will automatically
shift subfloats below. This effect can be added manually,
1. Add \usepackage{float} to the preamble of your
by putting the newline command (\\) before the figure you
document
wish to move to a newline.
Horizontal spaces between figures are controlled by one 2. Declare your new float using:
of several commands, which are placed in between \be- \newfloat{type}{placement}{ext}[outer counter],
gin{subfigure} and \end{subfigure}: where:

• A non-breaking space (specified by ~ as in the exam- • type - the new name you wish to call your float,
ple above) can be used to insert a space in between in this instance, 'program'.
the subfigs. • placement - t, b, p, or h (as previously de-
scribed in Placement), where letters enumer-
• Math spaces: \qquad, \quad, \;, and \,
ate permitted placements.
• Generic space: \hspace{''length''} • ext - the file name extension of an auxiliary
file for the list of figures (or whatever). Latex
• Automatically expanding/contracting space: \hfill
writes the captions to this file.
• outer counter - the presence of this parameter
2.14.8 Wide figures in two column docu- indicates that the counter associated with this
ments new float should depend on outer counter, for
example 'chapter'.
If you are writing a document using two columns (i.e.
you started your document with something like \docu- 3. The default name that appears at the start of the cap-
mentclass[twocolumn]{article}), you might have noticed tion is the type. If you wish to alter this, use \float-
that you can't use floating elements that are wider than the name{type}{floatname}
2.15. HYPERLINKS 69

4. Changing float style can be issued with \float- 2.14.10 Labels in the figures
style{style} (Works on all subsequent \newfloat
commands, therefore, must be inserted before There is a LaTeX package lpic to put LaTeX on top of
\newfloat to be effective). included graphics, thus allowing to add TeX annotations
to imported graphics. It defines a convenient interface to
• plain - the normal style for Latex floats, but the put TeX over included graphics, and allows for drawing
caption is always below the content. a white background under the typeset material to over-
• plaintop - the normal style for Latex floats, but shadow the graphics. It is a better alternative for labels
the caption is always above the content. inside of graphics; you do not have to change text size
when rescaling pictures, and all LaTeX power is available
• boxed - a box is drawn that surrounds the float, for labels.
and the caption is printed below.
A very similar package, with somewhat different syntax,
• ruled - the caption appears above the float, is pinlabel . The link given also points to the packages
with rules immediately above and below. Then psfrag and overpic.
the float contents, followed by a final horizon-
A much more complicated package which can be used
tal rule.
in the same way is TikZ. TikZ is a front-end to a draw-
ing library called pgf (which is used to make beamer for
Float styles can also be customized as the second example instance). It can be used to label figures by adding text
below illustrates. nodes on top of an image node.
An example document using a new program float type:
The verbatim environment is an environment that is al-
2.14.11 Summary
ready part of LaTeX. Although not introduced so far, its
name is fairly intuitive! LaTeX will reproduce everything
That concludes all the fundamentals of floats. You will
you give it, including new lines, spaces, etc. It is good for
hopefully see how much easier it is to let LaTeX do all
source code, but if you want to introduce a lot of code
the hard work and tweak the page layouts in order to get
you might consider using the listings package, that was
your figures in the best place. As always, the fact that
made just for it.
LaTeX takes care of all caption and reference numbering
While this is useful, one should be careful when embed- is a great time saver.
ding the float within another float. In particular, the error
not in outer par mode
may occur. One solution might be to use the [H] option
2.14.12 Notes and references
(not any other) on the inner float, as this option “pins” the
[1] http://www.ctan.org/tex-archive/macros/latex/contrib/
inner float to the outer one.
float/
Newly created floats with \newfloat can also be used in
combination with the wrapfig package from above. E.g. [2] Float environment positioning, by Frank Mittelbach
the following code creates a floating text box, which floats
in the text on the right side of the page and is complete [3] http://tex.stackexchange.com/questions/28556/
with caption, numbering, an index file with the extension how-to-place-a-float-at-the-top-of-a-floats-only-page
.lob and a customization of the float’s visual layout:
[4] http://ftp.univie.ac.at/packages/tex/macros/latex/
contrib/wrapfig/wrapfig-doc.pdf
Caption styles
[5] http://www.tex.ac.uk/cgi-bin/texfaq2html?label=
To change the appearance of captions, use the caption 2colfltorder
package. For example, to make all caption labels small
and bold: This page uses material from Andy Roberts’ Getting to grips
The KOMA script packages have their own caption cus- with LaTeX with permission from the author.
tomizing features with e.g. \captionabove, \captionformat
and \setcapwidth. However these definitions have limited
effect on newly created float environments with the wrap-
fig package.
2.15 Hyperlinks
Alternatively, you can redefine the \thefigure command: LaTeX enables typesetting of hyperlinks, useful when the
See this page for more information on counters. Finally, resulting format is PDF, and the hyperlinks can be fol-
note that the caption2 package has long been deprecated. lowed. It does so using the package hyperref.
70 CHAPTER 2. COMMON ELEMENTS

2.15.1 Hyperref opened pointing at my_url. Here is an example:


Both point at the same page, but in the first case the URL
The package hyperref[1] provides LaTeX the ability to
will be shown, while in the second case the URL will be
create hyperlinks within the document. It works with
hidden. Note that, if you print your document, the link
pdflatex and also with standard “latex” used with dvips
stored using \href will not be shown anywhere in the doc-
and ghostscript or dvipdfm to build a PDF file. If you
ument.
load it, you will have the possibility to include interac-
tive external links and all your internal references will be
turned to hyperlinks. The compiler pdflatex makes it pos- Other possibilities
sible to create PDF files directly from the LaTeX source,
and PDF supports more features than DVI. In particular Apart from linking to websites discussed above, hyperref
PDF supports hyperlinks, and the only way to introduce can be used to provide mailto links, links to local files,
them in LaTeX is using hyperref. Moreover, PDF can and links to anywhere within the PDF output file.
contain other information about a document such as the
title, the author, etc., which can be edited using this same
package. E-mail address A possible way to insert email links is
by
It just shows your email address (so people can know it
2.15.2 Usage even if the document is printed on paper) but, if the reader
clicks on it, (s)he can easily send you an email. Or, to
The basic usage with the standard settings is straightfor- incorporate the url package’s formatting and line breaking
ward. Just load the package in the preamble: abilities into the displayed text, use[2]
This will automatically turn all your internal references When using this form, note that the \nolinkurl command
into hyperlinks. It won't affect the way to write your is fragile and if the hyperlink is inside of a moving argu-
documents: just keep on using the standard \label-\ref ment, it must be preceeded by a \protect command.
system (discussed in the chapter on Labels and Cross-
referencing); with hyperref those “connections” will be-
come links and you will be able to click on them to be Local file Files can also be linked using the url or the
redirected to the right page. Moreover the table of con- href commands. You simply have to add the string run:
tents, list of figures/tables and index will be made of hy- at the beginning of the link string:
perlinks, too. The hyperlinks will not show-up if you are
Following http://tex.stackexchange.com/questions/
working in draft mode.
46488/link-to-local-pdf-file the version with url does
not always work, but href does.
Commands It is possible to use relative paths to link documents near
the location of your current document; in order to do so,
The package provides some useful commands for insert- use the standard Unix-like notation (./ is the current di-
ing links pointing outside the document. rectory, ../ is the previous directory, etc.)

\hyperref Usage: Hyperlink and Hypertarget It is also possible to cre-


This will have the same effect as \ref{label_name} but ate an anchor anywhere in the document (with or without
will make the text link text a full link, instead. The two caption) and to link to it. To create an anchor, use:
can be combined. If the lemma labelled as mainlemma and to link to it, use:
was number 4.1.1 the following example would result in
where the target caption and link caption are the text that
with the hyperlink as expected. Note the "*" after \ref is displayed at the target location and link location respec-
for avoiding nested hyperlinks. tively.

\url Usage:
2.15.3 Customization
It will show the URL using a mono-spaced font and, if
you click on it, your browser will be opened pointing at The standard settings should be fine for most users, but
it. if you want to change something, that is also possible.
There are several variables and two methods to pass those
to the package. Options can be passed as an argument of
\href Usage: the package when it is loaded (the standard way packages
It will show the string description using standard docu- work), or the \hypersetup command can be used as fol-
ment font but, if you click on it, your browser will be lows:
2.15. HYPERLINKS 71

you can pass as many options as you want; separate them Possible solution: Add the following to your preamble:
with a comma. Options have to be in the form:
exactly the same format has to be used if you pass those
options to the package while loading it, like this: Problems with Links and Pages
Here is a list of the possible variables you can change (for
the complete list, see the official documentation). The Messages like the following:
default values are written in an upright font:
! pdfTeX warning (ext4): destination with the same iden-
Checkout 3.8 Big list at hyperref-manual at tug.org tifier (name{page.1}) has been already used, duplicate ig-
Please note, that explicit RGB specification is only al- nored
lowed for the border colors (like linkbordercolor etc.), appear when a counter gets reinitialized, for example by
while the others may only assigned to named colors using the command \mainmatter provided by the book
(which you can define your own, see Colors). In order document class. It resets the page number counter to 1
to speed up your customization process, here is a list with prior to the first chapter of the book. But as the preface
the variables with their default value. Copy it in your doc- of the book also has a page number 1 all links to “page
ument and make the changes you want. Next to the vari- 1” would not be unique anymore, hence the notice that
ables, there is a short explanations of their meaning: “duplicate has been ignored.” The counter measure con-
If you don't need such a high customization, here are sists of putting plainpages=false into the hyperref options.
some smaller but useful examples. When creating PDFs This unfortunately only helps with the page counter. An
destined for printing, colored links are not a good thing as even more radical solution is to use the option hypertex-
they end up in gray in the final output, making it difficult names=false, but this will cause the page links in the index
to read. You can use color frames, which are not printed: to stop working.

or make links black: The best solution is to give each page a unique name by
using the \pagenumbering command:
When you just want to provide information for the Doc-
ument Info section of the PDF file, as well as enabling Another solution is to use \pagenumbering{alph} before
back references inside bibliography: the command \maketitle, which will give the title page
the label page.a. Since the page number is suppressed, it
By default, URLs are printed using mono-spaced fonts. won't make a difference to the output.
If you don't like it and you want them to be printed with
the same style of the rest of the text, you can use this: By changing the page numbering every time before the
counter is reset, each page gets a unique name. In this
case, the pages would be numbered a, b, c, i, ii, iii, iv, v,
2.15.4 Troubleshooting 1, 2, 3, 4, 5, ...
If you don't want the page numbers to be visi-
Problems with Links and Equations 1 ble (for example, during the front matter part), use
\pagestyle{empty} ... \pagestyle{plain}. The important
Messages like the following point is that although the numbers are not visible, each
! pdfTeX warning (ext4): destination with the same iden- page will have a unique name.
tifier (name{ equation.1.7.7.30}) has been already used, Another more flexible approach is to set the counter to
duplicate ignored something negative:
appear, when you have made something like which will give the first pages a unique negative number.
The error disappears, if you use instead this form: The problem can also occur with the algorithms package:
Beware that the shown line number is often completely because each algorithm uses the same line-numbering
different from the erroneous line. scheme, the line identifiers for the second and follow-on
algorithms will be duplicates of the first.
Possible solution: Place the amsmath package before the
hyperref package. The problem occurs with equation identifiers if you
use \nonumber on every line of an eqnarray environ-
ment. In this case, use the *'ed form instead, e.g. \be-
Problems with Links and Equations 2 gin{eqnarray*} ... \end{eqnarray*} (which is an unnum-
bered equation array), and remove the now unnecessary
Messages like the following \nonumber commands.
! Runaway argument? {\@firstoffive }\fi ), Some text If your url’s are too long and running off of the page, try
from your document here (\ref {re\ETC. Latex Error: using the breakurl package to split the url over multiple
Paragraph ended before \Hy@setref@link was complete. lines. This is especially important in a multicolumn envi-
appear when you use \label inside an align environment. ronment where the line width is greatly shortened.
72 CHAPTER 2. COMMON ELEMENTS

Problems with bookmarks Problems with already existing .toc, .lof and similar
files
The text displayed by bookmarks does not always look
like you expect it to look. Because bookmarks are “just The format of some of the auxilliary files generated by la-
text”, much fewer characters are available for bookmarks tex changes when you include the hyperref package. One
than for normal LaTeX text. Hyperref will normally no- can therefore encounter errors like
tice such problems and put up a warning: ! Argument of \Hy@setref@link has an extra }.
Package hyperref Warning: Token not allowed in a PDF- when the document is typeset with hyperref for the first
DocEncoded string: time and these files already exist. The solution to the
You can now work around this problem by providing a problem is to delete all the files that latex uses to get ref-
text string for the bookmarks, which replaces the offend- erences right and typeset again.
ing text:
Math expressions are a prime candidate for this kind of Problems with footnotes and special characters
problem:
which turns \section{$E=mc^2$} to E=mc2 in the book- See the relevant section.
mark area. Color changes also do not travel well into
bookmarks: Problems with Beamer
produces the string “redRed!". The command \textcolor
gets ignored but its argument (red) gets printed. If you Using the command
use: is broken when pointed at a label. Instead of sending the
the result will be much more legible. user to the desired label, upon clicking the user will be
sent to the first frame. A simple work around exists; in-
If you write your document in unicode and use the uni-
stead of using
code option for the hyperref package you can use unicode
characters in bookmarks. This will give you a much larger to label your frames, use
selection of characters to pick from when using \texor- and reference it with
pdfstring.

Problems with draft mode


Problems with tables and figures
WARNING! Please note that if you have activated the
The links created by hyperref point to the label created “draft"-option in your \documentclass declaration the hy-
within the float environment, which, as previously de- perlinks will not show up in the table of contents!!!
scribed, must always be set after the caption. Since the
caption is usually below a figure or table, the figure or ta-
ble itself will not be visible upon clicking the link[4] . A 2.15.5 Notes and References
workaround exists by using the package hypcap with:
[1] Hyperref package webpage in CTAN
Be sure to call this package after loading hyperref.
[2] “Email link with hyperref, url packages”. comp.text.tex
If you use the wrapfig package[5] mentioned in the User Group. http://groups.google.com/group/comp.
"Wrapping text around figures" section of the “Floats, text.tex/browse_thread/thread/ae160fd2fc5680a5/
Figures and Captions” chapter, or other similar packages 71a5a7c7bfceb3cb?lnk=gst&q=email+url+hyperref#
that define their own environments, you will need to man- 71a5a7c7bfceb3cb. Retrieved 2008.
ually include \capstart in those environments, e.g.:
[3] Other possible values are defined in the hyperref manual

[4] http://www.ctan.org/tex-archive/macros/latex/contrib/
Problems with long caption and \listoffigures or long hyperref/README
title
[5] Wrapfig package webpage in CTAN
There is an issue when using \listoffigures with hyper-
ref for long captions or long titles. This happens when
the captions (or the titles) are longer than the page width 2.16 Labels and Cross-referencing
(about 7-9 words depending on your settings). To fix this,
you need to use the option breaklinks when first declar-
2.16.1 Introduction
ing:
This will then cause the links in the \listoffigures to word In LaTeX you can easily reference almost anything that
wrap properly. is numbered (sections, figures, formulas), and LaTeX will
2.16. LABELS AND CROSS-REFERENCING 73

take care of numbering, updating it whenever necessary. \label{...}, but these prefixes become increasingly useful
The commands to be used do not depend on what you are as your document grows in size.
referencing, and they are: Another suggestion: try to avoid using numbers within
labels. You are better off describing what the object is
\label{marker} you give the object you want to reference about. This way, if you change the order of the objects,
a marker, you can see it like a name. you will not have to rename all your labels and their ref-
erences.
\ref{marker} you can reference the object you have
marked before. This prints the number that was as- If you want to be able to see the markers you are using
signed to the object. in the output document as well, you can use the showkeys
package; this can be very useful while developing your
\pageref{marker} It will print the number of the page document. For more information see the Packages sec-
where the object is. tion.

LaTeX will calculate the right numbering for the objects


2.16.2 Examples
in the document; the marker you have used to label the
object will not be shown anywhere in the document. Then
Here are some practical examples, but you will notice that
LaTeX will replace the string "\ref{marker}" with the
they are all the same because they all use the same com-
right number that was assigned to the object. If you ref-
mands.
erence a marker that does not exist, the compilation of
the document will be successful but LaTeX will return a
warning: Sections
LaTeX Warning: There were undefined references.
\section{Greetings} \label{sec:greetings} Hello!
and it will replace "\ref{unknown-marker}" with "??" (so
\section{Referencing} I greeted in section~\ref{sec:
it will be easy to find in the document).
greetings}.
As you may have noticed reading how it works, it is a two-
step process: first the compiler has to store the labels with
the right number to be used for referencing, then it has to
replace the \ref with the right number. That is why, when
you use references, you have to compile your document
twice to see the proper output. If you compile it only
once, LaTeX will use the older information it collected
in previous compilations (that might be outdated), but the
compiler will inform you printing on the screen at the end
of the compilation:
You could place the label anywhere in the section; how-
ever, in order to avoid confusion, it is better to place it
LaTeX Warning: Label(s) may have changed. immediately after the beginning of the section. Note how
Rerun to get cross-references right. the marker starts with sec:, as suggested before. The la-
bel is then referenced in a different section. The tilde (~)
Using the command \pageref{} you can help the reader indicates a non-breaking space.
to find the referenced object by providing also the page
number where it can be found. You could write some-
thing like: Pictures
See figure~\ref{fig:test} on page~\pageref{fig:test}. You can reference a picture by inserting it in the figure
floating environment.
Since you can use exactly the same commands to refer- \begin{figure} \centering \includegraph-
ence almost anything, you might get a bit confused after ics[width=0.5\textwidth]{gull} \caption{Close-up of a
you have introduced a lot of references. It is common gull} \label{fig:gull} \end{figure} Figure \ref{fig:gull}
practice among LaTeX users to add a few letters to the la-shows a photograph of a gull.
bel to describe what you are referencing. Some packages, When a label is declared within a float environment, the
such as fancyref, rely on this meta information. Here is \ref{...} will return the respective fig/table number, but it
an example: must occur after the caption. When declared outside, it
Following this convention, the label of a figure will look will give the section number. To be completely safe, the
like \label{fig:my_figure}, etc. You are not obligated to label for any picture or table can go within the \caption{}
use these prefixes. You can use any string as argument of command, as in
74 CHAPTER 2. COMMON ELEMENTS

As you can see, the label is placed soon after the begin-
ning of the math mode. In order to reference a formula,
you have to use an environment that adds numbers. Most
of the times you will be using the equation environment;
that is the best choice for one-line formulae, whether you
\caption{Close-up of a gull\label{fig:gull}}
are using amsmath or not. Note also the eq: prefix in the
label.
See the Floats, Figures and Captions section for more
about the figure and related environments.
eqref The amsmath package adds a new command for
referencing formulae; it is \eqref{}. It works exactly like
\ref{}, but it adds parentheses so that, instead of printing
Fixing wrong labels The command \label must ap- a plain number as 5, it will print (5). This can be useful
pear after (or inside) \caption. Otherwise, it will pick up to help the reader distinguish between formulae and other
the current section or list number instead of what you in- things, without the need to repeat the word “formula” be-
tended. fore any reference. Its output can be changed as desired;
\begin{figure} \centering \includegraph- for more information see the amsmath documentation.
ics[width=0.5\textwidth]{gull} \caption{Close-up
of a gull} \label{fig:gull} \end{figure}
tag The \tag{eqnno} command is used to manually set
equation numbers where eqnno is the arbitrary text string
you want to appear in the document. It is normally better
to use labels, but sometimes hard-coded equation num-
Issues with links to tables and figures handled by bers might offer a useful work-around. This may for in-
hyperref In case you use the package hyperref to cre- stance be useful if you want to repeat an equation that is
ate a PDF, the links to tables or figures will point to the used before, e.g. \tag{\ref{eqn:before}}.
caption of the table or figure, which is always below the
table or figure itself[1] . Therefore the table or figure will
not be visible, if it is above the pointer and one has to numberwithin The amsmath package adds the
scroll up in order to see it. If you want the link point to \numberwithin{countera}{counterb} command which
the top of the image you can give the option hypcap to replaces the simple countera by a more sophisti-
the caption package: cated counterb.countera. For example \number-
within{equation}{section} in the preamble will prepend
\usepackage[hypcap]{caption} the section number to all equation numbers.

cases The cases package adds the \numcases and


Formulae the \subnumcases commands, which produce multi-case
equations with a separate equation number and a separate
equation number plus a letter, respectively, for each case.
Here is an example showing how to reference formulae:
\begin{equation} \label{eq:solve} x^2 - 5 x + 6 =
0 \end{equation} \begin{equation} x_1 = \frac{5 + 2.16.3 The varioref package
\sqrt{25 - 4 \times 6}}{2} = 3 \end{equation} \be-
gin{equation} x_2 = \frac{5 - \sqrt{25 - 4 \times The varioref package introduces a new command called
6}}{2} = 2 \end{equation} and so we have solved \vref{}. This command is used exactly like the basic \ref,
equation~\ref{eq:solve} but it has a different output according to the context. If
the object to be referenced is in the same page, it works
2.16. LABELS AND CROSS-REFERENCING 75

just like \ref; if the object is far away it will print some- you can disable the creation of hyperlinks in hy-
thing like “5 on page 25”, i.e. it adds the page number au- perref, and just use these commands for automatic
tomatically. If the object is close, it can use more refined text.
sentences like “on the next page” or “on the facing page”
automatically, according to the context and the document • Keep in mind that the \label must be placed inside
class. an environment with a counter, such as a table or
This command has to be used very carefully. It outputs a figure. Otherwise, not only the number will refer
more than one word, so it may happen its output falls on to the current section, as mentioned above, but the
two different pages. In this case, the algorithm can get name will refer to the previous environment with a
confused and cause a loop. Let’s make an example. You counter. For example, if you put a label after closing
label an object on page 23 and the \vref output happens a figure, the label will still say “figure n”, on which
to stay between page 23 and 24. If it were on page 23, n is the current section number.
it would print like the basic ref, if it were on page 24, it
would print “on the previous page”, but it is on both, and
this may cause some strange errors at compiling time that nameref
are very hard to be fixed. You could think that this hap-
pens very rarely; unfortunately, if you write a long docu- The hyperref package also automatically includes the
ment it is not uncommon to have hundreds of references, nameref package, and a similarly named command. It
so situations like these are likely to happen. One way to is similar to \autoref{}, but inserts text corresponding to
avoid problems during development is to use the standard the section name, for example.
ref all the time, and convert it to vref when the document Input:
is close to its final version, and then making adjustments
\section{MyFirstSection} \label{sec:marker} \sec-
to fix possible problems.
tion{MySecondSection} In section~\nameref{sec:
marker} we defined...
2.16.4 The hyperref package
Output:
autoref In section MyFirstSection we defined...

The hyperref package introduces another useful com-


mand; \autoref{}. This command creates a reference Anchor manual positioning
with additional text corresponding to the target’s type,
all of which will be a hyperlink. For example, the com- When you define a \label outside a figure, a table, or other
mand \autoref{sec:intro} would create a hyperlink to the floating objects, the label points to the current section. In
\label{sec:intro} command, wherever it is. Assuming some cases, this behavior is not what you'd like and you'd
that this label is pointing to a section, the hyperlink would prefer the generated link to point to the line where the
contain the text “section 3.4”, or similar (the full list of \label is defined. This can be achieved with the command
default names can be found here). Note that, while there’s \phantomsection as in this example:
an \autoref* command that produces an unlinked prefix
%The link location will be placed on the line below.
(useful if the label is on the same page as the reference),
\phantomsection \label{the_label}
no alternative \Autoref command is defined to produce
capitalized versions (useful, for instance, when starting
sentences); but since the capitalization of autoref names
was chosen by the package author, you can customize the 2.16.5 The cleveref package
prefixed text by redefining \typeautorefname to the prefix
you want, as in: The cleveref package introduces the new command
\def\sectionautorefname{Section} \cref{} which includes the type of referenced object like
\autoref{} does. The alternate \labelcref{} command
works more like standard \ref{}. References to pages are
This renaming trick can, of course, be used for other pur-
handled by the \cpageref{} command.
poses as well.
The \crefrange{}{} and \cpagerefrange{} commands ex-
• If you would like a hyperlink reference, but pect a start and end label in either order and provide a
do not want the predefined text that \autoref{} natural language (babel enabled) range. If labels are enu-
provides, you can do this with a command such merated as a comma-separated list with the usual \cref{}
as \hyperref[sec:intro{]}\protect\char"007B\ command, it will sort them and group into ranges auto-
relaxAppendix~{}\char"005C\relax{}ref*\ matically.
protect\char"007B\relaxsec:intro}}. Note that The format can be specified in the preamble.
76 CHAPTER 2. COMMON ELEMENTS

2.16.6 See also


• LaTeX/Glossary

2.16.7 Notes and References


[1] http://www.ctan.org/tex-archive/macros/latex/contrib/
hyperref/README
Chapter 3

Mechanics

3.1 Errors and Warnings cessfully) by interfering with the letter spacing, LaTeX
takes the view that the author or editor should be able to
LaTeX describes what it is typesetting while it does it. If contribute. While it is certainly possible to set LaTeX’s
it encounters something it doesn't understand or can't do, parameters so that the spacing is sufficiently sloppy that
it will display a message saying what is wrong. It may also you will almost never get a warning about badly-fitting
display warnings for less serious conditions. lines or pages, you will almost certainly just be delaying
matters until you start to get complaints from your readers
Don't panic if you see error messages: it is very common or publishers.
to mistype or misspell commands, forget curly braces,
type a forward slash instead of a backslash, or use a spe-
cial character by mistake. Errors are easily spotted and
easily corrected in your editor, and you can then run La-
3.1.3 Examples
TeX again to check you have fixed everything. Some of
Only a few common error messages are given here: those
the most common errors are described in next sections.
most likely to be encountered by beginners. If you find
another error message not shown here, and it’s not clear
3.1.1 Error messages what you should do, ask for help.
Most error messages are self-explanatory, but be aware
The format of an error message is always the same. Er- that the place where LaTeX spots and reports an error
ror messages begin with an exclamation mark at the start may be later in the file than the place where it actually
of the line, and give a description of the error, followed occurred. For example if you forget to close a curly brace
by another line starting with the number, which refers to which encloses, say, italics, LaTeX won't report this until
the line-number in your document file which LaTeX was something else occurs which can't happen until the curly
processing when the error was spotted. Here’s an exam- brace is encountered (e.g. the end of the document!)
ple, showing that the user mistyped the \tableofcontents Some errors can only be righted by humans who can read
command: and understand what the document is supposed to mean
! Undefined control sequence. l.6 \tableofcotnetns or look like.

When LaTeX finds an error like this, it displays the error Newcomers should remember to check the list of special
message and pauses. You must type one of the following characters: a very large number of errors when you are
letters to continue: learning LaTeX are due to accidentally typing a special
character when you didn't mean to. This disappears after
Some systems (Emacs is one example) run LaTeX with a few days as you get used to them.
a “nonstop” switch turned on, so it will always process
through to the end of the file, regardless of errors, or until
a limit is reached. Too many }'s

! Too many }'s. l.6 \date December 2004}


3.1.2 Warnings
The reason LaTeX thinks there are too many }'s here is
Warnings don't begin with an exclamation mark: they are that the opening curly brace is missing after the \date con-
just comments by LaTeX about things you might want trol sequence and before the word December, so the clos-
to look into, such as overlong or underrun lines (often ing curly brace is seen as one too many (which it is!).
caused by unusual hyphenations, for example), pages run- In fact, there are other things which can follow the \date
ning short or long, and other typographical niceties (most command apart from a date in curly braces, so LaTeX
of which you can ignore until later). Unlike other systems, cannot possibly guess that you've missed out the opening
which try to hide unevennesses in the text (usually unsuc- curly brace until it finds a closing one!

77
78 CHAPTER 3. MECHANICS

Undefined control sequence typesetting when it found this, and the number in square
brackets is the number of the page onto which the of-
! Undefined control sequence. l.6 \dtae {December fending line was printed. The codes separated by slashes
2004} are the typeface and font style and size used in the line.
Ignore them for the moment.
In this example, LaTeX is complaining that it has no such
command (“control sequence”) as \dtae. Obviously it’s This comes up if you force a linebreak, e.g., \\, and have
been mistyped, but only a human can detect that fact: all a return before it. Normally TeX ignores linebreaks, pro-
LaTeX knows is that \dtae is not a command it knows viding full paragraphs to ragged text. In this case it is
about: it’s undefined. Mistypings are the most common necessary to pull the linebreak up one line to the end of
source of errors. Some editors allow common commands the previous sentence.
and environments to be inserted using drop-down menus This warning may also appear when inserting im-
or icons, which may be used to avoid these errors. ages. It can be avoided by using the \textwidth
or possibly \linewidth options, e.g. \includegraph-
Not in Mathematics Mode ics[width=\textwidth]{image_name}

! Missing $ inserted
A character that can only be used in the mathematics was Overfull hbox
inserted in normal text. If you intended to use mathemat-
ics mode, then use $...$ or \begin{math}...\end{math} or [101] Overfull \hbox (9.11617pt too wide) in para-
use the 'quick math mode': \ensuremath{...}. If you did graph at lines 860-−861 []\LY1/brm/m/n/10 Windows,
not intend to use mathematics mode, then perhaps you are \LY1/brm/m/it/10 see \LY1/brm/m/n/10 X Win-
trying to use a special character that needs to be entered
in a different way; for example _ will be interpreted as a An overfull \hbox means that there is a hyphenation or
subscript operator in mathematics mode, and you need \_ justification problem: moving the last word on the line
to get an underscore character. to the next line would make the spaces in the line wider
than the current limit; keeping the word on the line would
This can also happen if you use the wrong character make the spaces smaller than the current limit, so the
encoding, for example using utf8 without "\usepack- word is left on the line, but with the minimum allowed
age[utf8]{inputenc}" or using iso8859-1 without "\usep- space between words, and which makes the line go over
ackage[latin1]{inputenc}", there are several character the edge.
encoding formats, make sure to pick the right one.
The warning is given so that you can find the line in the
code that originates the problem (in this case: 860-861)
Runaway argument and fix it. The line on this example is too long by a shade
over 9pt. The chosen hyphenation point which minimizes
Runaway argument? {December 2004 \maketitle ! Para- the error is shown at the end of the line (Win-). Line num-
graph ended before \date was complete. <to be read bers and page numbers are given as before. In this case,
again> \par l.8 9pt is too much to ignore (over 3mm), and a manual cor-
rection needs making (such as a change to the hyphen-
In this error, the closing curly brace has been omitted
ation), or the flexibility settings need changing.
from the date. It’s the opposite of the error of too many
}'s, and it results in \maketitle trying to format the title If the “overfull” word includes a forward slash, such as
page while LaTeX is still expecting more text for the date! “input/output”, this should be properly typeset as “in-
As \maketitle creates new paragraphs on the title page, put\slash output”. The use of \slash has the same effect
this is detected and LaTeX complains that the previous as using the "/" character, except that it can form the end
paragraph has ended but \date is not yet finished. of a line (with the following words appearing at the start
of the next line). The "/" character is typically used in
units, such as “mm/year” character, which should not be
Underfull hbox broken over multiple lines.
The warning can also be issued when the \end{document}
Underfull \hbox (badness 1394) in paragraph at lines 28-
tag was not included or was deleted.
−30 [][]\LY1/brm/b/n/10 Bull, RJ: \LY1/brm/m/n/10
Ac-count-ing in Busi- [94]
This is a warning that LaTeX cannot stretch the line wide
enough to fit, without making the spacing bigger than its Easily spotting overfull hboxes in the document To
currently permitted maximum. The badness (0-10,000) easily find the location of overfull hbox in your document,
indicates how severe this is (here you can probably ignore you can make latex add a black bar where a line is too
a badness of 1394). It says what lines of your file it was wide:
3.2. LENGTHS 79

Missing package 3.1.4 Software that can check your .tex


Code
! LaTeX Error: File `paralisy.sty' not found. Type X
to quit or <RETURN> to proceed, or enter new name. There are several programs capable of checking LaTeX
(Default extension: sty) Enter file name: source, with the aim of finding errors or highlighting bad
practice, and providing more help to (particularly novice)
When you use the \usepackage command to request La-
users than the built-in error messages.
TeX to use a certain package, it will look for a file with
the specified name and the filetype .sty. In this case the
user has mistyped the name of the paralist package, so it’s • nag (www.ctan.org/tex-archive/macros/latex/
easy to fix. However, if you get the name right, but the contrib/nag) is a LaTeX package designed to
package is not installed on your machine, you will need indicate the use of obsolete commands.
to download and install it before continuing. If you don't
want to affect the global installation of the machine, you • lacheck (www.ctan.org/tex-archive/support/
can simply download from Internet the necessary .sty file lacheck) is a consistency checker intended to spot
and put it in the same folder of the document you are mistakes in code. It is available as source code or
compiling. compiled for Windows and OS/2

• chktex (baruch.ev-en.org/proj/chktex/) is a LaTeX


semantic checker available as source code for Unix-
Package babel Warning: No hyphenation patterns like systems.
were loaded for the language X

Although this is a warning from the Babel package and


not from LaTeX, this error is very common and (can) give
3.2 Lengths
some strange hyphenation (word breaking) problems in
your document. Wrong hyphenation rules can decrease In TeX, a length is
the neatness of your document.
Package babel Warning: No hyphenation patterns were • a floating point number followed by a unit, optionally
loaded for (babel) the language `Latin' (babel) I will use followed by a stretching value;
the patterns loaded for \language=0 instead.
This can happen after the usage of: (see • a floating point factor followed by a macro that ex-
LaTeX/Internationalization) pands to a length.
\usepackage[latin]{babel}
The solution is not difficult, just install the used language
in your LaTeX distribution. 3.2.1 Units

First, we introduce the LaTeX measurement units. All


LaTeX units are two-word abbreviations. You can choose
Package babel Error: You haven't loaded the option from [1]a variety of units. Here are the most common
X yet. ones.
And here are some less common units.[2]
If you previously set the X language, and then decided
to switch to Y, you will get this error. This may seem
awkward, as there is obviously no error in your code if 3.2.2 Box lengths
you did not change anything. The answer lies in the .aux
file, where babel defined your language. If you try the A box in TeX is characterized by three lengths:
compilation a second time, it should work. If not, delete
the .aux file, then everything will work as usual.
• depth

• height
No error message, but won't compile
• width
One common cause of (pdf)LaTeX getting stuck is for-
getting to include \end{document} See Boxes.
80 CHAPTER 3. MECHANICS

3.2.3 Length manipulation \paperwidth The width of the page.

You can change the values of the variables defining the \paperheight The height of the page.
page layout with two commands. With this one you can
set a new value for an existing length variable: \parindent The normal paragraph indentation.
with this other one, you can add a value to the existing \parskip The extra vertical space between paragraphs.
one:
You can create your own length with the command, and \tabcolsep The default separation between columns in a
you must create a new length before you attempt to set it: tabular environment.
You may also set a length from the size of a text with one \textheight The height of text on the page.
of these commands:
When using these commands, you may duplicate the text \textwidth The width of the text on the page.
that you want to use as reference if you plan to also dis-
play it. But LaTeX also provides \savebox to avoid this \topmargin The size of the top margin.
duplication. You may wish to look at the example below
to see how you can use these. See Boxes for more details. \unitlength Units of length in picture environment.

You can also define stretched values. A stretching value


is a length preceded by plus or minus to specify to what 3.2.5 Fixed-length spaces
extent tex is authorized to change the length. Example:
It means that tex will try to use a length of 10pt; if it is un- To insert a fixed-length space, use:
derfull, it will raise the length up to a maximum of 15pt; \hspace stands for horizontal space, \vspace for vertical
if it is overfull, it will lower the length up to a minimum space.
of 7pt.
If such a space should be kept even if it falls at the end or
Note that it is not mandatory to specify both the plus and the start of a line, use \hspace* instead.
the minus values, but if you do, plus must be placed be-
fore minus. If the space should be preserved at the top or at the bot-
tom of a page, use the starred version of the command,
To print a length, you can use the \the command: \vspace*, instead of \vspace. If you want to add space
at the beginning of the document, without anything else
Plain TeX written before, then you may use
It’s important you use the \vspace* command instead of
To create a new length: \vspace, otherwise LaTeX can silently ignore the extra
To set a length: space.

To view, it is the same as with LaTeX, using the command TeX features some macros for fixed-length spacing.
\the.
\smallskip Inserts a small space in vertical mode (be-
tween two paragraphs).
3.2.4 LaTeX default lengths
\medskip Inserts a medium space in vertical mode (be-
Common length macros are: tween two paragraphs).

\baselineskip The normal vertical distance between \bigskip Inserts a big space in vertical mode (between
lines in a paragraph. two paragraphs).
\baselinestretch Multiplies \baselineskip.
The vertical mode is during the process of assembling
\columnsep The distance between columns. boxes “vertically”, like paragraphs to build a page. The
horizontal mode is during the process of assembling
\columnwidth The width of the column.
boxes “horizontally”, like letters to build a word or words
\evensidemargin The margin for 'even' pages (think of to build a paragraph.
a printed booklet). The fact they are vertical mode commands mean they will
\linewidth The width of a line in the local environment. be ignored (or fail) in horizontal mode such as in the mid-
dle of a paragraph. The first token next the a double line-
\oddsidemargin The margin for 'odd' pages (think of a break is still in vertical mode if it does not expand to char-
printed booklet). acters.
3.3. COUNTERS 81

3.2.6 Rubber/Stretching lengths 3.3.1 Counter manipulation


The command: In LaTeX it is fairly easy to create new counters and even
generates a special rubber space where factor is a number, counters that reset automatically when another counter
possibly a float. It stretches until all the remaining space is increased (think subsection in a section for example).
on a line is filled up. If two \hspace{\stretch{factor}} With the command
commands are issued on the same line, they grow accord- you create a new counter that is automatically set to zero.
ing to the stretch factor. If you want the counter to be reset to zero every time
The same way, you can stretch vertically: another counter is increased, use:

You can also use \fill instead of \stretch{1}. To increase the counter, either use

The \stretch command, in connection with \pagebreak, or


can be used to typeset text on the last line of a page, or to or
center text vertically on a page.
here the number can also be negative. For automatic re-
There are 'shortcut commands’ for stretching with factor setting you need to use \stepcounter.
1 (i.e. with \stretch{1} or \fill): \hfill and \vfill.
To set the counter value explicitly, use
Example:

3.3.2 Counter access


Fill the rest of the line
There are several ways to get access to a counter.
Several macros allow filling the rest of the line -- or
stretching parts of the line -- in different manners.
• \theNameOfTheNewCounter will print the format-
• \hfill will produce empty space. ted string related to the counter (note the “the” be-
fore the actual name of the counter).
• \dotfill will produce dots.
• \value{NameOfTheNewCounter} will return the
• \hrulefill will produce a rule. counter value which can be used by other counters
or for calculations. It is not a formatted string, so it
cannot be used in text.
3.2.7 Examples
• \arabic{NameOfTheNewCounter} will print the
Resize an image to take exactly half the text width : formatted counter using arabic numbers.
Make distance between items larger (inside an itemize en-
vironment) : Note that \arabic{NameOfTheNewCounter} may be
Use of \savebox to resize an image to the height of the used as a value too, but not the others.
text: Strangely enough, LaTeX counters are not introduced by
a backslash in any case, even with the \the command.
plainTeX equivalents \count and \newcounter\mycounter
3.2.8 References do abide by the backslash rule.
[1] http://www.giss.nasa.gov/tools/latex/ltx-86.html
[2] http://www.giss.nasa.gov/tools/latex/ltx-86.html 3.3.3 Counter style
Each counter also has a default format that dictates how
3.2.9 See also it is displayed whenever LaTeX needs to print it. Such
formats are specified using internal LaTeX commands:
• University of Cambridge > Engineering Department
> computing help > LaTeX > Squeezing Space in
LaTeX 3.3.4 LaTeX default counters
• part
3.3 Counters
• chapter
Counters are an essential part of LaTeX: they allow you • section
to control the numbering mechanism of everything (sec-
tions, lists, captions, etc.). • subsection
82 CHAPTER 3. MECHANICS

• subsubsection The past chapters have already dealt with some boxes, al-
though they weren't described as such. The tabular en-
• paragraph vironment and the \includegraphics, for example, both
• subparagraph produce a box. This means that one can easily arrange
two tables or images side by side. You just have to make
• page sure that their combined width is not larger than the \tex-
twidth.
• equation
• figure
3.4.1 TeX character boxes
• table
TeX characters are stored in boxes like every printed el-
• footnote ement. Boxes have three dimensional properties:
• mpfootnote
• The height is the length between the baseline and the
top of the box.
For the enumerate environment:
• The depth is the length between the baseline and the
• enumi bottom of the box.

• enumii • The width is the width of the box.

• enumiii
• enumiv

3.3.5 Book with parts, sections, but no


chapters
Here follows an example where we want to use parts and 3.4.2 makebox and mbox
sections, but no chapters in the book class :
While \parbox packs up a whole paragraph doing line
breaking and everything, there is also a class of boxing
3.3.6 Custom enumerate commands that operates only on horizontally aligned ma-
terial. We already know one of them; it’s called \mbox.
See the List Structures chapter. It simply packs up a series of boxes into another one, and
can be used to prevent LaTeX from breaking two words.
(See Hyphenation.) As you can put boxes inside boxes,
3.3.7 Custom sectioning these horizontal box packers give you ultimate flexibility.
Here is an example for recreating something similar to a width defines the width of the resulting box as seen from
section and subsection counter that already exist in La- the outside. This means it can be smaller than the material
TeX: inside the box. You can even set the width to 0pt so that
the text inside the box will be typeset without influencing
the surrounding boxes. Besides the length expressions,
3.4 Boxes you can also use \width, \height, \depth and \totalheight
in the width parameter. They are set from values obtained
by measuring the typeset text.
LaTeX builds up its pages by pushing around boxes. At
first, each letter is a little box, which is then glued to other The pos parameter takes a one letter value: center,
letters to form words. These are again glued to other flushleft, flushright, or spread the text to fill the box.
words, but with special glue, which is elastic so that a
series of words can be squeezed or stretched as to exactly
fill a line on the page. 3.4.3 framebox
Admittedly, this is a very simplistic description of what The command \framebox works exactly the same as
really happens, but the point is that TeX operates with \makebox, but it draws a box around the text.
glue and boxes. Letters are not the only things that can
be boxes. One can put virtually everything into a box, The following example shows you some things you could
including other boxes. Each box will then be handled by do with the \makebox and \framebox commands:
LaTeX as if it were a single letter. You can tweak the following frame lengths.
3.4. BOXES 83

• \fboxsep: the distance between the frame and the Paragraphs in all boxes
content.
You can make use of the long capabilities of minipage
• \fboxrule: the thickness of the rule. and parbox to embed paragraphs in non-long boxes. For
instance:

This prints a thick and more distant frame: This prevents the overfull badness.

This shows the box frame of a letter. You can also use
from the pbox package which will create a box of minimal
size around the text. Note that the \pbox command takes
3.4.4 framed an optional argument that specifies the vertical position
of the text:
An alternative to these approaches is the usage of the The valid values are b (bottom), t (top), and c (center). If
framed environment (you will need to include the framed you specify a length in the first (required) argument, the
package to use it). This provides an easy way to box a text will be wrapped:
paragraph within a document:
You can do it manually with a parbox.
3.4.7 savebox

A \savebox is a reference to a box filled with contents.


3.4.5 raisebox
You can use it as a way to print or manipulate something
repeatedly.
Now that we control the horizontal, the obvious next step
is to go for the vertical. No problem for LaTeX. The The command \newsavebox creates a placeholder for
storing a text; the command \savebox stores the speci-
command lets you define the vertical properties of a box.
fied text in this placeholder, and does not display any-
You can use \width, \height, \depth and \totalheight in the
thing in the document; and \usebox recalls the content of
first three parameters, in order to act upon the size of the
the placeholder into the document.
box inside the text argument. The two optional param-
eters set for the height and depth of the raisebox. For
instance you can observe the difference when embedded
in a framebox. 3.4.8 rotatebox

See Rotations.
3.4.6 minipage and parbox

Most standard LaTeX boxes are not long com- 3.4.9 colorbox and fcolorbox
mands, i.e. they do not support breaks nor para-
graphs. However you can pack a paragraph See Colors. \fcolorbox can also be tweaked with \fboxsep
of your choice into a box with either the \par- and \fboxrule.
box[pos][height][contentpos]{width}{text} command or
the \begin{minipage}[pos][height][contentpos]{width}
text \end{minipage} environment. 3.4.10 resizebox and scalebox
The pos parameter can take one of the letters center, top
or bottom to control the vertical alignment of the box, The graphicx package features additional boxes.
relative to the baseline of the surrounding text. The height
parameter is the height of the parbox or minipage. The
contentpos parameter is the position of the content and 3.4.11 fancybox
can be one of center, top, bottom or spread. width takes
a length argument specifying the width of the box. The
the fancybox package provides additional boxes.
main difference between a minipage and a \parbox is that
you cannot use all commands and environments inside a
parbox, while almost anything is possible in a minipage. • \doublebox
This should print 3 boxes on the same line. Do not put
another linebreak between the \fbox, otherwise you will • \ovalbox
put the following \fbox in another paragraph on another
line. • \shadowbox
84 CHAPTER 3. MECHANICS

3.5 Rules and Struts

3.5.1 Rules
The \rule command in normal use produces a simple
black box:
The depth, width and height parameters are explained in
the Boxes chapter.
Here is an example:
This is useful for drawing vertical and horizontal lines.

3.5.2 Struts
A special case is a rule with no width but a certain height.
In professional typesetting, this is called a strut. It is used
to guarantee that an element on a page has a certain min-
imal height. You could use it in a tabular environment
or in boxes to make sure a row has a certain minimum
height.
In LaTeX a strut is defined as

3.5.3 Stretched rules


LaTeX provides the \hrulefill command, which work like
a stretched horizontal space. See the Lengths chapter.
Chapter 4

Technical Texts

4.1 Mathematics • displayed — displayed formulas are separate from


the main text.
One of the greatest motivating forces for Donald Knuth
when he began developing the original TeX system was As maths require special environments, there are natu-
to create something that allowed simple construction of rally the appropriate environment names you can use in
mathematical formulas, while looking professional when the standard way. Unlike most other environments, how-
printed. The fact that he succeeded was most probably ever, there are some handy shorthands to declaring your
why TeX (and later on, LaTeX) became so popular within formulas. The following table summarizes them:
the scientific community. Typesetting mathematics is one
Suggestion: Using the $$...$$ should be avoided, as it
of LaTeX’s greatest strengths. It is also a large topic due
may cause problems, particularly with the AMS-LaTeX
to the existence of so much mathematical notation.
macros. Furthermore, should a problem occur, the error
If your document requires only a few simple mathemat- messages may not be helpful.
ical formulas, plain LaTeX has most of the tools that
The equation* and displaymath environments are func-
you will need. If you are writing a scientific document
tionally equivalent.
that contains numerous complicated formulas, the ams-
math package[1] introduces several new commands that If you are typing text normally, you are said to be in text
are more powerful and flexible than the ones provided mode, but while you are typing within one of those math-
by LaTeX. The mathtools package fixes some amsmath ematical environments, you are said to be in math mode,
quirks and adds some useful settings, symbols, and envi- that has some differences compared to the text mode:
ronments to amsmath.[2] To use either package, include:
\usepackage{amsmath} 1. Most spaces and line breaks do not have any signifi-
cance, as all spaces are either derived logically from
the mathematical expressions, or have to be speci-
or
fied with special commands such as \quad
\usepackage{mathtools}
2. Empty lines are not allowed. Only one paragraph
per formula.
in the preamble of the document. The mathtools package
loads the amsmath package and hence there is no need 3. Each letter is considered to be the name of a variable
to \usepackage{amsmath} in the preamble if mathtools and will be typeset as such. If you want to typeset
is used. normal text within a formula (normal upright font
and normal spacing) then you have to enter the text
using dedicated commands.
4.1.1 Mathematics environments

LaTeX needs to know beforehand that the subsequent Inserting “Displayed” maths inside blocks of text
text does indeed contain mathematical elements. This is
because LaTeX typesets maths notation differently from In order for some operators, such as \lim or \sum to be
normal text. Therefore, special environments have been displayed correctly inside some math environments (read
declared for this purpose. They can be distinguished into $......$), it might be convenient to write the \displaystyle
two categories depending on how they are presented: class inside the environment. Doing so might cause the
line to be taller, but will cause exponents and indices to be
• text — text formulas are displayed inline, that is, displayed correctly for some math operators. For exam-
within the body of text where it is declared, for ex- ple, the $\sum$ will print a smaller
∑ Σ and $\displaystyle
ample, I can say that a + a = 2a within this sentence. \sum$ will print a bigger one , like in equations (This

85
86 CHAPTER 4. TECHNICAL TEXTS

only works with AMSMATH package). It is also possi- To use operators that are not pre-defined, such as argmax,
ble to force this behaviour for all math environments by see custom operators
declaring \everymath{\displaystyle} at the very beginning
(i.e. before \begin{document}), which is useful in longer
documents. 4.1.5 Powers and indices
Powers and indices are equivalent to superscripts and sub-
4.1.2 Symbols scripts in normal text mode. The caret (^; also known as
the circumflex accent) character is used to raise some-
thing, and the underscore (_) is for lowering. If more
Mathematics has many symbols! One of the most dif-
than one expression is raised or lowered, they should be
ficult aspects of learning LaTeX is remembering how to
grouped using curly braces ({ and }).
produce symbols. There is of course a set of symbols that
can be accessed directly from the keyboard: For powers with more than one digit, surround the power
with {}.
+-=! /()[]<>|':
An underscore (_) can be used with a vertical bar ( | ) to
Beyond those listed above, distinct commands must be
denote evaluation using subscript notation in mathemat-
issued in order to display the desired symbols. There are
ics:
many examples such as Greek letters, set and relations
symbols, arrows, binary operators, etc.
For example: 4.1.6 Fractions and Binomials
Fortunately, there’s a tool that can greatly simplify the
A fraction is created using the
search for the command for a specific symbol. Look for
\frac{numerator}{denominator} command. (for
“Detexify” in the external links section below. Another
those who need their memories refreshed, that’s the
option would be to look in the “The Comprehensive La-
top and bottom respectively!). Likewise, the binomial
TeX Symbol List” in the external links section below.
coefficient (aka the Choose function) may be written
using the \binom command[3] :
4.1.3 Greek letters It is also possible to use the \choose command without
the amsmath package:
Greek letters are commonly used in mathematics, and You can embed fractions within fractions:
they are very easy to type in math mode. You just have to
Note that when appearing inside another fraction, or in
type the name of the letter after a backslash: if the first
inline text ab , a fraction is noticeably smaller than in dis-
letter is lowercase, you will get a lowercase Greek letter,
played mathematics. The \tfrac and \dfrac commands[3]
if the first letter is uppercase (and only the first letter),
force the use of the respective styles, \textstyle and \dis-
then you will get an uppercase letter. Note that some up-
playstyle. Similarly, the \tbinom and \dbinom commands
percase Greek letters look like Latin ones, so they are not
typeset the binomial coefficient.
provided by LaTeX (e.g. uppercase Alpha and Beta are
just “A” and “B” respectively). Lowercase epsilon, theta, Another way to write fractions is to use the \over com-
kappa, phi, pi, rho, and sigma are provided in two differ- mand without the amsmath package:
ent versions. The alternate, or variant, version is created
For relatively simple fractions, especially within the text,
by adding “var” before the name of the letter: it may be more aesthetically pleasing to use powers and
Scroll down to #List of Mathematical Symbols for a com- indices:
plete list of Greek symbols. If this looks a little “loose” (overspaced), a tightened ver-
sion can be defined by inserting some negative space

4.1.4 Operators If you use them throughout the document, usage of xfrac
package is recommended. This package provides \sfrac
command to create slanted fractions. Usage:
An operator is a function that is written as a word: e.g.
trigonometric functions (sin, cos, tan), logarithms and ex- If fractions are used as an exponent curly braces have to
ponentials (log, exp), limits (lim), as well as trace and de- be used around the \sfrac command:
terminant (tr, det). LaTeX has many of these defined as $x^\frac{1}{2}$ % no error $x^\sfrac{1}{2}$ % error
commands: $x^{\sfrac{1}{2}}$ % no error
For certain operators such as limits, the subscript is In some cases, using the package alone will result in er-
placed underneath the operator: rors about certain font shapes not being available. In that
For the modular operator there are two commands: case, the lmodern and fix-cm packages need to be added
\bmod and \pmod: as well.
4.1. MATHEMATICS 87

Alternatively, the nicefrac package provides the \nicefrac There are many other “big” commands which operate in
command, whose usage is similar to \sfrac. a similar manner:
For more integral symbols, including those not included
Continued fractions by default in the Computer Modern font, try the esint
package.
Continued fractions should be written using \cfrac The \substack command[3] allows the use of \\ to write
command[3] : the limits over multiple lines:
If you want the limits of an integral to be specified above
Multiplication of two numbers and below the symbol (like the sum), use the \limits com-
mand:
To make multiplication visually similar to a fraction, a However if you want this to apply to ALL integrals, it is
nested array can be used, for example multiplication of preferable to specify the intlimits option when loading the
numbers written one below the other. amsmath package:
Subscripts and superscripts in other contexts as well as
4.1.7 Roots other parameters to amsmath package related to them are
described in Advanced Mathematics chapter.
The \sqrt command creates a square root surrounding an For bigger integrals, you may use personal declarations,
expression. It accepts an optional argument specified in or the bigints package [4] .
square brackets ([ and ]) to change magnitude:
Some people prefer writing the square root “closing” it
over its content. This method arguably makes it more 4.1.9 Brackets, braces and delimiters
clear what is in the scope of the root sign. This habit is
not normally used while writing with the computer, but How to use braces in multi line equations is described in the
if you still want to change the output of the square root, Advanced Mathematics chapter.
LaTeX gives you this possibility. Just add the following The use of delimiters such as brackets soon becomes im-
code in the preamble of your document: portant when dealing with anything but the most trivial
This TeX code first renames the \sqrt command as \old- equations. Without them, formulas can become ambigu-
sqrt, then redefines \sqrt in terms of the old one, adding ous. Also, special types of mathematical structures, such
something more. The new square root can be seen in the as matrices, typically rely on delimiters to enclose them.
picture on the left, compared to the old one on the right. There are a variety of delimiters available for use in La-
Unfortunately this code won't work √ if you want to use TeX:
multiple roots: if you try to write b a as \sqrt[b]{a} after
you used the code above, you'll just get a wrong output. where \lbrack and \rbrack may be used in place of [ and
In other words, you can redefine the square root this way ].
only if you are not going to use multiple roots in the whole
document.
Automatic sizing
An alternative piece of TeX code that does allow multiple
roots is Very often mathematical features will differ in size, in
However this requires the \usepackage{letltxmacro} which case the delimiters surrounding the expression
package should vary accordingly. This can be done automatically
using the \left, \right, and \middle commands. Any of
the previous delimiters may be used in combination with
4.1.8 Sums and integrals these:
Curly braces are defined differently by using \left\{ and
The \sum and \int commands insert the sum and integral
\right\},
symbols respectively, with limits specified using the caret
(^) and underscore (_). The typical notation for sums is: If a delimiter on only one side of an expression is re-
quired, then an invisible delimiter on the other side may
or
be denoted using a period (.).
The limits for the integrals follow the same notation. It’s
also important to represent the integration variables with
an upright d, which in math mode is obtained through the Manual sizing
\mathrm{} command, and with a small space separating
it from the integrand, which is attained with the \, com- In certain cases, the sizing produced by the \left and \right
mand. commands may not be desirable, or you may simply want
88 CHAPTER 4. TECHNICAL TEXTS

finer control over the delimiter sizes. In this case, the \big, columns be pre-specified:
\Big, \bigg and \Bigg modifier commands may be used: You may see that the AMS matrix class of environments
These commands are primarily useful when dealing with doesn't leave enough space when used together with frac-
nested delimiters. For example, when typesetting tions resulting in output similar to this:
5 1 
we notice that the \left and \right commands produce the 6 6 0
same size delimiters as those nested within it. This can M =  65 0 16 
be difficult to read. To fix this, we write 0 65 16
Manual sizing can also be useful when an equation is too To counteract this problem, add additional leading space
large, trails off the end of the page, and must be sepa- with the optional parameter to the \\ command:
rated into two lines using an align command. Although If you need “border” or “indexes” on your matrix, plain
the commands \left. and \right. can be used to balance TeX provides the macro \bordermatrix
the delimiters on each line, this may lead to wrong de-
limiter sizes. Furthermore, manual sizing can be used to
avoid overly large delimiters if an \underbrace or a similar
Matrices in running text
command appears between the delimiters.
To insert a small matrix, and not increase leading in the
line containing it, use smallmatrix environment:
Typesetting intervals

To denote open and half-open intervals, the notations


]a,b[, (a,b), ]a,b], (a,b], [a,b[ and [a,b) are used. If the 4.1.11 Adding text to equations
square bracket notation is used, then the interval must be
put between curly braces ({ and }) in order to have correct The math environment differs from the text environment
spacing. Similarly, if a (half-)open interval starts with a in the representation of text. Here is an example of trying
negative number, then the number including its minus- to represent text within the math environment:
symbol must also be put between curly brackets, so that There are two noticeable problems: there are no spaces
LaTeX understands that the minus-symbol is the unary between words or numbers, and the letters are italicized
operation. Compare: and more spaced out than normal. Both issues are simply
artifacts of the maths mode, in that it treats it as a math-
ematical expression: spaces are ignored (LaTeX spaces
4.1.10 Matrices and arrays mathematics according to its own rules), and each charac-
ter is a separate element (so are not positioned as closely
A basic matrix may be created using the matrix as normal text).
environment[3] : in common with other table-like struc-
There are a number of ways that text can be added prop-
tures, entries are specified by row, with columns sepa-
erly. The typical way is to wrap the text with the \text{...}
rated using an ampersand (&) and a new rows separated
command [3] (a similar command is \mbox{...}, though
with a double backslash (\\)
this causes problems with subscripts, and has a less de-
To specify alignment of columns in the table, use starred scriptive name). Let’s see what happens when the above
version[5] : equation code is adapted:
The alignment by default is c but it can be any column The text looks better. However, there are no gaps be-
type valid in array environment. tween the numbers and the words. Unfortunately, you
However matrices are usually enclosed in delimiters of are required to explicitly add these. There are many ways
some kind, and while it is possible to use the \left and to add spaces between maths elements, but for the sake
\right commands, there are various other predefined en- of simplicity we may simply insert space characters into
vironments which automatically include delimiters: the \text commands.

When writing down arbitrary sized matrices, it is com-


mon to use horizontal, vertical and diagonal triplets of Formatted text
dots (known as ellipses) to fill in certain columns and
rows. These can be specified using the \cdots, \vdots and Using the \text is fine and gets the basic result. Yet, there
\ddots respectively: is an alternative that offers a little more flexibility. You
In some cases you may want to have finer control of the may recall the introduction of font formatting commands,
alignment within each column, or want to insert lines be- such as \textrm, \textit, \textbf, etc. These commands
tween columns or rows. This can be achieved using the format the argument accordingly, e.g., \textbf{bold text}
array environment, which is essentially a math-mode ver- gives bold text. These commands are equally valid within
sion of the tabular environment, which requires that the a maths environment to include text. The added benefit
4.1. MATHEMATICS 89

here is that you can have better control over the font for- instance, you want the sign to appear close to the appro-
matting, rather than the standard text achieved with \text. priate element to show their association. If you put a + or
a − with nothing before it but you want it to be handled
like a binary operator you can add an invisible character
4.1.12 Formatting mathematics symbols before the operator using {}. This can be useful if you
are writing multiple-line formulas, and a new line could
See also: w:Mathematical Alphanumeric Sym- start with a = or a +, for example, then you can fix some
bols, w:Help:Displaying a formula#Alphabets strange alignments adding the invisible character where
and typefaces and w:Wikipedia:LaTeX sym- necessary.
bols#Fonts
A plus-minus sign is written as:

We can now format text; what about formatting mathe- Similarly, there exists also a minus-plus sign:
matical expressions? There are a set of formatting com-
mands very similar to the font formatting ones just used,
except that they are specifically aimed at text in math
4.1.15 Controlling horizontal spacing
mode (requires amsfonts)
LaTeX is obviously pretty good at typesetting maths—it
These formatting commands can be wrapped around the was one of the chief aims of the core TeX system that
entire equation, and not just on the textual elements: they LaTeX extends. However, it can't always be relied upon
only format letters, numbers, and uppercase Greek, and to accurately interpret formulas in the way you did. It
other math commands are unaffected. has to make certain assumptions when there are ambigu-
To bold lowercase Greek or other symbols use the ous expressions. The result tends to be slightly incorrect
\boldsymbol command[3] ; this will only work if there horizontal spacing. In these events, the output is still sat-
exists a bold version of the symbol in the current font. isfactory, yet any perfectionists will no doubt wish to fine-
As a last resort there is the \pmb command[3] (poor tune their formulas to ensure spacing is correct. These are
mans bold): this prints multiple versions of the charac- generally very subtle adjustments.
ter slightly offset against each other. There are other occasions where LaTeX has done its job
To change the size of the fonts in math mode, see correctly, but you just want to add some space, maybe
Changing font size. to add a comment of some kind. For example, in the
following equation, it is preferable to ensure there is a
decent amount of space between the maths and the text.
Accents This code produces errors with Miktex 2.9 and does not
yield the results seen on the right. Use \mathrm instead
So what to do when you run out of symbols and fonts? of just \text.
Well the next step is to use accents:
(Note that this particular example can be expressed in
more elegant code by the cases construct provided by the
4.1.13 Color amsmath package described in Advanced Mathematics
chapter.)
The package xcolor, described in Colors, allows us to add LaTeX has defined two commands that can be used any-
color to our equations. For example, where in documents (not just maths) to insert some hor-
The only problem is that this disrupts the default LaTeX izontal space. They are \quad and \qquad
formatting around the - operator. To fix this, we enclose A \quad is a space equal to the current font size. So, if you
it in a \mathbin environment, since - is a binary operator. are using an 11pt font, then the space provided by \quad
This process is described here. will also be 11pt (horizontally, of course.) The \qquad
gives twice that amount. As you can see from the code
from the above example, \quads were used to add some
4.1.14 Plus and minus signs separation between the maths and the text.

Latex deals with the + and − signs in two possible ways. OK, so back to the fine tuning as mentioned at the be-
The most common is as a binary operator. When two ginning of the document. A good example would be dis-
maths elements appear on either side of the sign, it is playing the simple equation for the indefinite integral of
assumed to be a binary operator, and as such, allocates y with respect to x:

some space either side of the sign. The alternative way y dx
is a sign designation. This is when you state whether a
mathematical quantity is either positive or negative. This If you were to try this, you may write:
is common for the latter, as in maths, such elements are However, this doesn't give the correct result. LaTeX
assumed to be positive unless a − is prefixed to it. In this doesn't respect the white-space left in the code to signify
90 CHAPTER 4. TECHNICAL TEXTS

that the y and the dx are independent entities. Instead, it same thing, but use \displaystyle instead.
lumps them altogether. A \quad would clearly be overkill
in this situation—what is needed are some small spaces to
be utilized in this type of instance, and that’s what LaTeX 4.1.17 Advanced Mathematics: AMS
provides: Math package
NB you can use more than one command in a sequence
The AMS (American Mathematical Society) mathemat-
to achieve a greater space if necessary.
ics package is a powerful package that creates a higher
So, to rectify the current problem: layer of abstraction over mathematical LaTeX language;
The negative space may seem like an odd thing to use, if you use it it will make your life easier. Some com-
however, it wouldn't be there if it didn't have some use! mands amsmath introduces will make other plain LaTeX
Take the following example: commands obsolete: in order to keep consistency in the
final output you'd better use amsmath commands when-
The matrix-like expression for representing binomial co- ever possible. If you do so, you will get an elegant out-
efficients is too padded. There is too much space between put without worrying about alignment and other details,
the brackets and the actual contents within. This can eas- keeping your source code readable. If you want to use it,
ily be corrected by adding a few negative spaces after the you have to add this in the preamble:
left bracket and before the right bracket.
In any case, adding some spaces manually should be
Introducing dots in formulas
avoided whenever possible: it makes the source code
more complex and it’s against the basic principles of
amsmath defines also the \dots command, that is a gen-
a What You See is What You Mean approach. The
eralization of the existing \ldots. You can use \dots in
best thing to do is to define some commands using all
both text and math mode and LaTeX will replace it with
the spaces you want and then, when you use your com-
three dots "…" but it will decide according to the context
mand, you don't have to add any other space. Later, if
whether to put it on the bottom (like \ldots) or centered
you change your mind about the length of the horizontal
(like \cdots).
space, you can easily change it modifying only the com-
mand you defined before. Let us use an example: you
want the d of a dx in an integral to be in roman font and Dots
a small space away from the rest. If you want to type
an integral like \int x \, \mathrm{d} x, you can define a LaTeX gives you several commands to insert dots (el-
command like this: lipses) in your formulae. This can be particularly useful
in the preamble of your document. We have chosen \dd if you have to type big matrices omitting elements. First
just because it reminds the “d” it replaces and it is fast to of all, here are the main dots-related commands LaTeX
type. Doing so, the code for your integral becomes \int x provides:
\dd x. Now, whenever you write an integral, you just have Instead of using \ldots and \cdots, you should use the se-
to use the \dd instead of the “d”, and all your integrals will mantically oriented commands. It makes it possible to
have the same style. If you change your mind, you just adapt your document to different conventions on the fly,
have to change the definition in the preamble, and all your in case (for example) you have to submit it to a publisher
integrals will be changed accordingly. who insists on following house tradition in this respect.
The default treatment for the various kinds follows Amer-
ican Mathematical Society conventions.
4.1.16 Manually Specifying Formula Style
To manually display a fragment of a formula using text Write an equation with the align environment
style, surround the fragment with curly braces and pre-
fix the fragment with \textstyle. The braces are required How to write an equation with the align environment with
because the \textstyle macro changes the state of the ren- the amsmath package is described in Advanced Mathe-
derer, rendering all subsequent mathematics in text style. matics.
The braces limit this change of state to just the fragment
enclosed within. For example, to use text style for just
the summation symbol in a sum, one would enter 4.1.18 List of Mathematical Symbols
The same thing as a command would look like this: All the pre-defined mathematical symbols from the \TeX\
Note the extra braces. Just one set around the expression package are listed below. More symbols are available
won't be enough. That would cause all math after \tsum from extra packages.
k to be displayed using text style. Note: To use the Greek Letters in LaTeX that have the
To display part of a formula using display style, do the same appearance as their Roman equivalent, just use the
4.2. ADVANCED MATHEMATICS 91

Roman form: e.g., A instead of Alpha, B instead of Beta, 4.2.1 Equation numbering
etc.
The equation environment automatically numbers your
equation:
4.1.19 Summary You can also use the \label and \ref (or \eqref from
the amsmath package) commands to label and reference
As you begin to see, typesetting math can be tricky at equations, respectively. For equation number 1, \ref re-
times. However, because LaTeX provides so much con- sults in 1 and \eqref results in (1) :
trol, you can get professional quality mathematics type-
setting with relatively little effort (once you've had a bit of Further information is provided in the labels and cross-
practice, of course!). It would be possible to keep going referencing chapter.
and going with math topics because it seems potentially To have the enumeration follow from your section or sub-
limitless. However, with this tutorial, you should be able section heading, you must use the amsmath package or
to get along sufficiently. use AMS class documents. Then enter
to the preamble to get enumeration at the section level or
4.1.20 Notes to have the enumeration go to the subsection level.
If the style you follow requires putting dots after ordi-
[1] http://www.ams.org/publications/authors/tex/amslatex
nals (as it is required at least in Polish typography) the
[2] http://www.tex.ac.uk/ctan/macros/latex/contrib/ \numberwithin{equation}{subsection} command in the
mathtools/mathtools.pdf preamble will result in the equation number in the above
example to be rendered in this way: (1.1..1).
[3] requires the amsmath package To remove the duplicate dot, add the following command
immediately after \numberwithin{equation}{section}:
[4] http://hdl.handle.net/2268/6219
For a numbering scheme using \number-
[5] requires the mathtools package within{equation}{subsection}, use:
in the preamble of the document.
4.1.21 Further reading Note: Though it may look like the \renewcommand works
by itself, it won't reset the equation number with each new
• meta:Help:Displaying a formula: Wikimedia uses a section. It must be used together with manual equation
subset of LaTeX commands. number resetting after each new section beginning or with
the much cleaner \numberwithin.

4.1.22 External links


Subordinate equation numbering
• LaTeX maths symbols
To number subordinate equations in a numbered equation
• detexify: applet for looking up LaTeX symbols by environment, place the part of document containing them
drawing them in a subequations environment:
Referencing subordinate equations can be done using
• amsmath documentation either of two methods: adding a label after the \be-
gin{subequations} command, which will reference the
• LaTeX - The Student Room main equation (1.1 above), or adding a label at the end
of each line, before the \\ command, which will refer-
• The Comprehensive LaTeX Symbol List
ence the sub-equation (1.1a or 1.1b above). It is possible
• MathLex - LaTeX math translator and equation to add both labels in case both types of references are
builder needed.

4.2.2 Vertically aligning displayed mathe-


4.2 Advanced Mathematics matics

This page outlines some more advanced uses of math- A problem often encountered with displayed environ-
ematics markup using LaTeX. In particular it makes ments (displaymath and equation) is the lack of any abil-
heavy use of the AMS-LaTeX packages supplied by the ity to span multiple lines. While it is possible to define
American Mathematical Society. lines individually, these will not be aligned.
92 CHAPTER 4. TECHNICAL TEXTS

Above and below Notice that we've added some indenting on the second
line. Also, we need to insert the double braces ({}) before
The \overset and \underset commands[1] typeset symbols the + sign, otherwise latex won't create the correct spac-
above and below expressions. Without AmsTex the same ing after the + sign. The reason for this is that without
result of \overset can be obtained with \stackrel. This can the braces, latex interprets the + sign as a unary operator,
be particularly useful for creating new binary relations: instead of the binary operator that it really is.
or to show usage of L'Hôpital’s rule: More complicated alignments are possible, with addi-
It is convenient to define a new operator that will set the tional &'s on a single line specifying multiple “equation
equal sign with H and the provided fraction: columns”, each of which is aligned. The following exam-
ple illustrates the alignment rule of align*:
which reduces the above example to:
If the purpose is to make comments on particular parts of Braces spanning multiple lines
an equation, the \overbrace and \underbrace commands
may be more useful. However, they have a different syn- If you want a brace to continue across a new line, do the
tax (and can be aligned with the \vphantom command): following:
Sometimes the comments are longer than the formula be- In this construction, the sizes of the left and right braces
ing commented on, which can cause spacing problems. are not automatically equal, in spite of the use of \left\{
These can be removed using the \mathclap command[2] : and \right\}. This is because each line is typeset as a com-
Alternatively, to use brackets instead of braces use \un- pletely separate equation —notice the use of \right. and
derbracket and \overbracket commands[2] : \left. so there are no unpaired \left and \right commands
within a line (these aren't needed if the formula is on one
The optional arguments set the rule thickness and bracket
line). You can control the size of the braces manually
height respectively:
with the \big, \Big, \bigg, and \Bigg commands.
The \xleftarrow and \xrightarrow commands[1] produce
Alternatively, the height of the taller equation can be
arrows which extend to the length of the text. Yet again,
replicated in the other using the \vphantom command:
the syntax is different: the optional argument (using [ and
]) specifies the subscript, and the mandatory argument
(using { and }) specifies the superscript (which can be Using aligned braces for piecewise functions You
left empty by inserting a blank space). can also use \left\{ and \right. to typeset piecewise func-
For more extensible arrows, you must use mathtools tions:
package:
and for harpoons: The cases environment

The cases environment[1] allows the writing of piecewise


align and align* functions:
LaTeX will then take care of defining and or aligning the
The align and align* environments, available through the
columns.
amsmath package, are used for arranging equations of
multiple lines. As with matrices and tables, \\ specifies Within cases, text style math is used with results such as:
a line break, and & is used to indicate the point at which {∫
x dx
the lines should be aligned. a=
b2
The align* environment is used like the displaymath or
equation* environment: Display style may be used instead, by using the dcases
environment[2] from mathtools:
Note that the align environment must not be nested inside
an equation (or similar) environment. Instead, align is a Often the second column consists mostly of normal text,
replacement for such environments; the contents inside to set it in the normal roman font of the document the
an align are automatically placed in math mode. dcases* environment may be used:[2]
align* suppresses numbering. To force numbering on a
specific line, use the \tag{...} command before the line- Other environments
break.
align is similar, but automatically numbers each line like Although align and align* are the most useful, there are
the equation environment. Individual lines may be re- several other environments which may also be of interest:
ferred to by placing a \label{...} before the linebreak. The There are also few environments that don't form a math
\nonumber or \notag command can be used to suppress environment by themselves and can be used as building
the number for a given line: blocks for more elaborate structures:
4.2. ADVANCED MATHEMATICS 93

For example: This defines a new command which may be referred to in


the body:

4.2.3 Indented Equations


4.2.7 Advanced formatting
In order to indent an equation, you can set fleqn in the
document class and then specify a certain value for the
\mathindent variable: Limits

There are defaults for placement of subscripts and super-


4.2.4 Page breaks in math environments scripts e.g. limits for the lim operator are usually placed
below the symbol:
To suggest LaTeX insert a page break inside an amsmath To override this behavior, use the \nolimits operator:
environment you may use the \displaybreak command be- A lim in running text (inside $...$) will have its limits
fore the line break. Just like with \pagebreak, \display- placed on the side, so that additional leading won't be re-
break can take an optional argument between 0 and 4 de- quired. To override this behavior, use the \limits com-
noting the level of desirability of a page break. While 0 mand.
means “it is permissible to break here”, 4 forces a break.
No argument means the same as 4. Similarly one can put subscripts under a symbol that usu-
ally have them on the side:
Alternatively, you may enable automatic page breaks in
math environments with \allowdisplaybreaks. It too can Limits below and under:
have an optional argument denoting the priority of page To change the default placement of summation-type sym-
breaks in equations. Similarly, 1 means “allow page bols to the side for every case, add the nosumlimits option
breaks but avoid them” and 4 means “break whenever you to the amsmath package. To change the placement for in-
want”. You can prohibit a page break after a given line tegral symbols, add intlimits to the options. nonamelimits
using \\*. can be used to change the default for named operators like
LaTeX will insert a page break into a long equation if it det, min, lim, etc.
has additional text added using \intertext{} without any To produce one-sided limits, use \underset as follows:
additional commands.
Specific usage may look like this:
Subscripts and superscripts

4.2.5 Boxed Equations While you can place symbols in subscript or superscript
(in summation style symbols) with \nolimits:
For a single equation or alignment building block, with
the tag outside the box, use \boxed{}: It’s impossible to mix them with typical usage of such
symbols:
If you want the entire line or several equations to be
boxed, use a minipage inside an \fbox{}: To add both prime and a limit to a symbol, one might use
\sideset command:
There is also the mathtools \Aboxed{} which is able to
box across alignment marks: It is very flexible: for example, to put letters in each cor-
ner of the symbol use this command:
If you wish to place them on the corners of an arbitrary
4.2.6 Custom operators symbol, you should use \fourIdx from the fouridx pack-
age.
Although many common operators are available in La- However, a simple grouping can solve the problem:
TeX, sometimes you will need to write your own, e.g. to
typeset the argmax operator. The \operatorname and \op- since a math operator can be used with limits or no limits.
eratorname* commands[1] display custom operators; the If you want to change its state, simply group it. You can
* version sets the underscored option underneath like the make it another math operator if you want, and then you
\lim operator: can have limits and then limits again.

However, if the operator is frequently used, it is prefer-


able to define a new operator that can be used through-
out the entire document. The \DeclareMathOperator and Multiline subscripts
\DeclareMathOperator* commands[1] are specified in the
header of the document: To produce multiline subscript use \substack command:
94 CHAPTER 4. TECHNICAL TEXTS

4.2.8 Text in aligned math display .

To add small interjections in math environments use \in-


tertext command: 4.2.11 Adjusting vertical whitespace
Note that any usage of this command does not change the around displayed math
alignment.
There are four parameters which control the vertical
Also, in the above example, the command \shortinter- whitespace around displayed math:
text{} from the mathtools package could have been used
instead of intertext to reduce the amount of vertical Short skips are used if the preceding line ends, horizon-
whitespace added between the lines. tally, before the formula. These parameters must be set
after
.
4.2.9 Changing font size
There may be a time when you would prefer to have 4.2.12 Notes
some control over the size. For example, using text-mode
maths, by default a simple fraction will look like this: ab [1] Requires amsmath package
, whereas you may prefer to have it displayed larger, like
when in display mode, but still keeping it in-line, like this: [2] requires the mathtools package
a
.
b
A simple approach is to utilize the predefined sizes for
maths elements:
4.3 Theorems
A classic example to see this in use is typesetting con-
With "theorem" we can mean any kind of labelled enun-
tinued fractions (though it’s better to use the \cfrac
ciation that we want to look separated from the rest of the
command[1] described in the Mathematics chapter over
text and with sequential numbers next to it. This approach
the method provided below). The following code pro-
is commonly used for theorems in mathematics, but can
vides an example.
be used for anything. LaTeX provides a command that
As you can see, as the fractions continue, they get smaller will let you easily define any theorem-like enunciation.
(although they will not get any smaller as in this example,
they have reached the \scriptstyle limit). If you wanted to
keep the size consistent, you could declare each fraction 4.3.1 Basic theorems
to use the display style instead, e.g.:
Another approach is to use the \DeclareMathSizes com- First of all, make sure you have the amsthm package en-
mand to select your preferred sizes. You can only define abled:
sizes for \displaystyle, \textstyle, etc. One potential down- \usepackage{amsthm}
side is that this command sets the global maths sizes, as
it can only be used in the document preamble.
The easiest is the following:
However, it’s fairly easy to use: \DeclareMath-
\newtheorem{name}{Printed output}
Sizes{ds}{ts}{ss}{sss}, where ds is the display size, ts is
the text size, etc. The values you input are assumed to be
point (pt) size. put it in the preamble. The first argument is the name you
will use to reference it, the second argument is the output
NB the changes only take place if the value in the first
LaTeX will print whenever you use it. For example:
argument matches the current document text size. It
is therefore common to see a set of declarations in the \newtheorem{mydef}{Definition}
preamble, in the event of the main font being changed.
E.g., will define the mydef environment; if you use it like this:
\begin{mydef} Here is a new definition \end{mydef}
4.2.10 Forcing \displaystyle for all math in
a document It will look like this:

Put
Definition 3 Here is a new definition
before
to force all math to with line breaks separating it from the rest of the text.
4.3. THEOREMS 95

4.3.2 Theorem counters \begin{proof} Here is my proof: \[ a^2 + b^2 = c^2


\qedhere \] \end{proof}
Often the counters are determined by section, for exam-
ple “Theorem 2.3” refers to the 3rd theorem in the 2nd
The method above does not work with the deprecated en-
section of a document. In this case, specify the theorem
vironment eqnarray*. Use align* instead.
as follows:
To use a custom Q.E.D. symbol, redefine the \qedsymbol
\newtheorem{name}{Printed output}[numberby]
command. To hide the Q.E.D. symbol altogether, rede-
fine it to be blank:
where numberby is the name of the section level (sec-
\renewcommand{\qedsymbol}{}
tion/subsection/etc.) at which the numbering is to take
place.
By default, each theorem uses its own counter. However it
is common for similar types of theorems (e.g. Theorems,
Lemmas and Corollaries) to share a counter. In this case, 4.3.4 Theorem styles
define subsequent theorems as:
\newtheorem{name}[counter]{Printed output} It adds the possibility to change the output of the environ-
ments defined by \newtheorem using the \theoremstyle
command[1] in the header:
where counter is the name of the counter to be used. Usu-
ally this will be the name of the master theorem. \theoremstyle{stylename}

The \newtheorem command may have at most one op-


tional argument. the argument is the style you want to use. All subse-
quently defined theorems will use this style. Here is a
You can also create a theorem environment that is not list of the possible pre-defined styles:
numbered by using the newtheorem* command[1] . For
instance,
\newtheorem*{mydef}{Definition}
Custom styles

defines the mydef environment, which will generate def- To define your own style, use the \newtheoremstyle
initions without numbering. This requires amsthm pack- command[1] :
age.
\newtheoremstyle{stylename}% name of the style to be
used {spaceabove}% measure of space to leave above the
4.3.3 Proofs theorem. E.g.: 3pt {spacebelow}% measure of space to
leave below the theorem. E.g.: 3pt {bodyfont}% name
The proof environment[1] can be used for adding the of font to use in the body of the theorem {indent}%
proof of a theorem. The basic usage is: measure of space to indent {headfont}% name of head
\begin{proof} Here is my proof \end{proof} font {headpunctuation}% punctuation between head and
body {headspace}% space after theorem head; " " =
normal interword space {headspec}% Manually specify
It just adds Proof in italics at the beginning of the text head
given as argument and a white square (Q.E.D. symbol,
also known as a tombstone) at the end of it. If you are
writing in another language than English, just use babel (Any arguments that are left blank will assume their de-
with the right argument and the word Proof printed in fault value). Here is an example headspec:
the output will be translated accordingly; anyway, in the \thmname{#1}\thmnumber{ #2}:\thmnote{ #3}
source the name of the environment remains proof.
If you would like to manually name the proof, include the which would look something like:
name in square brackets: Definition 2: Topology
\begin{proof}[Proof of important theorem] Here is my for the following:
important proof \end{proof} \begin{definition}[Topology]...

If the last line of the proof is displayed math then the (The note argument, which in this case is Topology, is
Q.E.D. symbol will appear on a subsequent empty line. always optional, but will not appear by default unless you
To put the Q.E.D. symbol at the end of the last line, use specify it as above in the head spec).
the \qedhere command:
96 CHAPTER 4. TECHNICAL TEXTS

4.3.5 Conflicts an angle relative to the angle of the preceding bond. Fi-
nally, predefined angles are whole numbers from 0 to 7
The theorem environment conflicts with other environ- indicating intervals of 45 degrees. These are produced
ments, for example wrapfigure. A work around is to re- with the syntax [< predefined angle>]. The predefined
define theorem, for example the following way: angles and their corresponding absolute angles are repre-
sented in the diagram below.
% Fix latex \def\smallskip{\vskip\smallskipamount}
\def\medskip{\vskip\medskipamount} <bond type> describes the bond attaching <atom1> and
\def\bigskip{\vskip\bigskipamount} % Hand <atom2>. There are 9 different bond types:
made theorem \newcounter{thm}[section] \re- <coeff> represents the factor by which the bond’s length
newcommand{\thethm}{\thesection.\arabic{thm}} will be multiplied.
\def\claim#1{\par\medskip\noindent\refstepcounter{thm}\hbox{\bf
\arabic{chapter}.\arabic{section}.\arabic{thm}. #1.} <tikz code> includes additional options regarding the
\it\ %\ignorespaces } \def\endclaim{ \par\medskip} color or style of the bond.
\newenvironment{thm}{\claim}{\endclaim} A methane molecule, for instance, can be produced with
the following code:
In this case theorem looks like: Linear molecules (such as methane) are a weak example
\begin{thm}{Claim}\label{lyt-prob} Let it be. Then of this, but molecules are formed in chemfig by nesting.
you know. \end{thm}

4.4.2 Skeletal Diagrams


4.3.6 Notes Skeleton diagrams can be produced as follows:

[1] Requires the amsthm package

4.4.3 Rings
4.3.7 External links
Rings follow the syntax <atom>*<n>(code), where “n”
indicates the number of sides in the ring and “code” repre-
• amsthm documentation
sents the specific content of each ring (bonds and atoms).

4.4 Chemical Graphics 4.4.4 Lewis Structures


chemfig is a package used to draw 2D chemical struc- Lewis structures use the syntax
tures. It is an alternative to ochem. Whereas ochem re- \lewis{<n1><n2>...<ni>,<atom>}, where <ni> is a
quires Perl to draw chemical structures, chemfig uses the number between 0 and 7 representing the position of
tikz package to produce its graphics. chemfig is used by the electrons. By default, the electrons are represented
adding the following to the preamble: by a dash (-). Appending a period (.) or colon (:)
\usepackage{chemfig} after a number will display single and paired electrons
respectively.
Lewis structures can also be included within \chemfig{}.

4.4.1 Basic Usage


4.4.5 Ions
The primary command used in this package is \chem-
fig{}:
For example, consider an acetate ion:
\chemfig{<atom1><bond type>[<angle>,<coeff>,<tikz
code>]<atom2>} Because the chemfig commands enters the math mode,
ion charges can be added as superscripts (one caveat: a
negative ion requires that the minus sign be enclosed in
<angle> is the bond angle between two atoms (or nodes). brackets, as in the example).
There are three types of angles: absolute, relative, and
predefined. Absolute angles give a precise angle (gener- The charge of an ion can be circled by using \oplus and
ally, 0 to 360, though they can also be negative), and are \ominus:
represented with the syntax [:<absolute angle>]. Relative Alternatively, charges can be placed above ions using
angles require the syntax [::<relative angle>] and produce \chemabove{}{}:
4.4. CHEMICAL GRAPHICS 97

4.4.6 Resonance Structures and Formal \chemname{\chemfig{R’OH}}{Alcohol}


Charges \chemsign{+} \chemname{\chemfig{R-C(-
[:−30]OH)=[:30]O}}{Carboxylic acid}
Resonance structures require a few math commands: \chemrel{->} \chemname{\chemfig{R-C(-
[:−30]OR’)=[:30]O}}{Ester} \chemsign{+} \chem-
% see “Advanced Mathematics” for use of name{\chemfig{H_2O}}{Water}
\left and \right % add to preamble: % \usep-
ackage{mathtools} % \Longleftrightarrow
$\left\{\chemfig{O-N(=[:60]O)-[:300]O}\right\} This is fixed by adding \chemnameinit{<deepest
\Longleftrightarrow \left\{\chemfig{O=N(-[:60]O)- molecule>} before the first instance of \chemname{}
[:300]O}\right\} \Longleftrightarrow \left\{\chemfig{O- in a reaction and by adding \chemnameinit{} after the
N(-[:60]O)=[:300]O}\right\}$ reaction:
\chemnameinit{\chemfig{R-C(-[:−30]OH)=[:30]O}}
\chemname{\chemfig{R’OH}}{Alcohol}
\chemsign{+} \chemname{\chemfig{R-C(-
4.4.7 Chemical Reactions [:−30]OH)=[:30]O}}{Carboxylic acid}
\chemrel{->} \chemname{\chemfig{R-C(-
Chemical reactions can be created with the following [:−30]OR’)=[:30]O}}{Ester} \chemsign{+} \chem-
commands: name{\chemfig{H_2O}}{Water} \chemnameinit{}
\chemrel[<arg1>][<arg2>]{<arrow code>}
\chemsign+ % produces a + Lastly, adding \\ in <name> will produce a line-break,
allowing the name to span multiple lines.
In \chemrel{}, <arg1> and <arg2> represent text placed
above and below the arrow, respectively.
There are four types of arrows that can be produced with 4.4.9 Advanced Graphics
\chemrel{}:
A\chemrel{->}B\par A\chemrel{<-}B\par For advanced commands and examples, refer to the
A\chemrel{<->}B\par A\chemrel{<>}B chemfig manual, where a more thorough and complete
introduction to the package can be found.

4.4.8 Naming Chemical Graphics


4.4.10 mhchem Package
Molecules can be named with the command
\chemname[<dim>]{\chemfig{<code of the mhchem is a package used to typeset chemical formu-
molecule>}}{<name>} lae and equations. As well as typeset basic 2D chemical
structures. To use this package, add the following to your
<dim> is inserted between the bottom of the molecule preamble:
and the top of the name defined by <name>. It is 1.5ex \usepackage[version=3]{mhchem}
by default.
<name> will be centered relative to the molecule it de- Chemical species are included using the \ce command.
scribes. For example
\chemname{\chemfig{R-C(- \ce{3H2O} \\ \ce{1/2H2O} \\ \ce{AgCl2-} \\
[:−30]OH)=[:30]O}}{Carboxylic acid} \chem- \ce{H2_{(aq)}} \\
sign{+} \chemname{\chemfig{R’OH}}{Alcohol}
\chemrel{->} \chemname{\chemfig{R-C(- A few things here are automatically typeset; The 2 in
[:−30]OR’)=[:30]O}}{Ester} \chemsign{+} \chem- \ce{H2O} is automatically subscripted without requiring
name{\chemfig{H_2O}}{Water} additional commands. The amount of the species pre-
cedes the formula. 1/2 and other fractional amounts are
In the reaction above, \chemname{} inserts 1.5ex plus the automatically typeset as in \ce{1/2H2O}. The charge in
depth of the carboxylic acid molecule in between each \ce{AgCl2-} is automatically superscripted. If the charge
molecule and their respective names. This is because the is neither 1 or −1, a ^ will superscript it, as in \ce{AgCl2-
graphic for the first molecule in the reaction (carboxylic }. The phase is not automatically subscripted and needs
acid) extends deeper than the rest of the molecules. A to be enclosed in parenthesis preceded with a _ as in
different result is produced by putting the alcohol first: \ce{H2_{(aq)}.
98 CHAPTER 4. TECHNICAL TEXTS

4.4.11 XyMTeX package <text> \ENSURE <text> \RETURN <text> \PRINT


<text> \COMMENT{<text>} \AND, \OR, \XOR,
The following code produces the image for corticosterone \NOT, \TO, \TRUE, \FALSE
below.
\documentclass{letter} \usepack- Complete documentation is listed at . Most commands
age{epic,carom} \pagestyle{empty} \be- are similar to the algorithmicx equivalents, but with dif-
gin{document} \begin{picture}(1000,500) ferent capitalization. The package algorithms bundle at
\put(0,0){\steroid[d]{3D==O;{{10}}==\lmoiety{H$_{3}$C};{{13}}==\lmoiety{H$_{3}$C};{{11}}==HO}}
the ctan repository, dated 2009-08-24, describes both the
\put(684,606){\sixunitv{}{2D==O;1==OH}{cdef}} algorithmic environment (for typesetting algorithms) and
\end{picture} \end{document} the algorithm floating wrapper (see below) which is de-
signed to wrap around the algorithmic environment.
The algorithmic package is suggested for IEEE journals
as it is a part of their default style sheet.[1]

4.5.2 Typesetting using the algorithm2e


package

The algorithm2e package (first released 1995, latest up-


dated January 2013 according to the v5.0 manual) al-
lows typesetting algorithms with a lot of customization.
Like algorithmic, this package is also not compatible with
Revtex-4.1.[2]
Unlike algorithmic, algorithm2e provides a relatively
Corticosterone as rendered by XyMTeX
huge number of customization options to the algorithm
suiting to the needs of various users. The CTAN-manual
provides a comprehensible list of examples and full set of
controls.
4.5 Algorithms Typically, the usage between \begin{algorithm} and
\end{algorithm} would be
LaTeX has several packages for typesetting algorithms in 1. Declaring a set of keywords(to typeset as func-
form of "pseudocode". They provide stylistic enhance- tions/operators), layout controls, caption, title, header
ments over a uniform style (i.e., all in typewriter font) so text (which appears before the algorithm’s main steps e.g.:
that constructs such as loops or conditionals are visually Input,Output)
separated from other text. For typesetting real code, writ- 2. Writing the main steps of the algorithm, with each step
ten in a real programming language, consider the listings ending with a \;
package described in Source Code Listings. This may be taken in analogy with writing a latex-
preamble before we start the actual document.
4.5.1 Typesetting using the algorithmic The package is loaded like
package \usepackage[]{algorithm2e}

The algorithmic package uses a different set of commands


than the algorithmicx package. This is not compatible and a simple example, taken from the v4.01 manual, is
with revtex4-1. Basic commands are: \begin{algorithm}[H] \KwData{this text} \KwRe-
\STATE <text> \IF{<condition>} \STATE{<text>} sult{how to write algorithm with \LaTeX2e } initial-
\ELSE \STATE{<text>} \ENDIF \FOR{<condition>} ization\; \While{not at end of this document}{ read
\STATE{<text>} \ENDFOR \FOR{<condition> current\; \eIf{understand}{ go to next section\; current
\TO <condition> } \STATE{<text>} \ENDFOR section becomes this one\; }{ go back to the beginning of
\FORALL{<condition>} \STATE{<text>} \ENDFOR current section\; } } \caption{How to write algorithms}
\WHILE{<condition>} \STATE{<text>} \ENDWHILE \end{algorithm}
\REPEAT \STATE{<text>} \UNTIL{<condition>}
\LOOP \STATE{<text>} \ENDLOOP \REQUIRE which produces
4.5. ALGORITHMS 99

Basic commands have the following syntax:


Statement (\State causes a new line, can also be used in
front of other commands)
\State $x\gets <value>$

Three forms of if-statements:


\If{<condition>} <text> \EndIf
\If{<condition>} <text> \Else <text> \EndIf
\If{<condition>} <text> \ElsIf{<condition>} <text>
\Else <text> \EndIf
More details are in the manual hosted on the ctan website.
The third form accepts as many \ElsIf{} clauses as re-
quired. Note that it is \ElsIf and not \ElseIf.
4.5.3 Typesetting using the algorithmicx Loops:
package \For{<condition>} <text> \EndFor
\ForAll{<condition>} <text> \EndFor
The algorithmicx package provides a number of \While{<condition>} <text> \EndWhile
popular constructs for algorithm designs. Put \usep- \Repeat <text> \Until{<condition>}
ackage{algpseudocode} in the preamble to use the \Loop <text> \EndLoop
algorithmic environment to write algorithm pseu-
docode (\begin{algorithmic}...\end{algorithmic}).
Pre- and postcondition:
You might want to use the algorithm environ-
ment (\usepackage{algorithm}) to wrap your al- \Require <text>
gorithmic code in an algorithm environment (\be- \Ensure <text>
gin{algorithm}...\end{algorithm}) to produce a floating
environment with numbered algorithms. Functions
The command \begin{algorithmic} can be given the op- \Function{<name>}{<params>} <body> \EndFunction
tional argument of a positive integer, which if given will \Return <text>
cause line numbering to occur at multiples of that inte- \Call{<name>}{<params>}
ger. E.g. \begin{algorithmic}[5] will enter the algorith-
mic environment and number every fifth line.
This command will usually be used in conjunction with a
Below is an example of typesetting a basic algorithm \State command as follows:
using the algorithmicx package (remember to add the
\usepackage{algpseudocode} statement to your docu- \Function{Increment}{$a$} \State $a \gets a+1$ \State
ment preamble): \Return $a$ \EndFunction

\begin{algorithmic} \If {$i\geq maxval$} \State $i\gets


0$ \Else \If {$i+k\leq maxval$} \State $i\gets i+k$ Comments:
\EndIf \EndIf \end{algorithmic} \Comment{<text>}

The LaTeX source can be written to a format familiar Note to users who switched from the old algorithmic
to programmers so that it is easy to read. This will not, package: comments may be placed everywhere in the
however, affect the final layout in the document. source; there are no limitations as in the old algorithmic
package.

Renaming things: algorithm to procedure, re-


quire/ensure to input/output

\floatname{algorithm}{Procedure} \renewcom-
mand{\algorithmicrequire}{\textbf{Input:}} \re-
newcommand{\algorithmicensure}{\textbf{Output:}}
100 CHAPTER 4. TECHNICAL TEXTS

Custom algorithmic blocks of algorithms can be influenced by providing the name of


the document component within which numbering should
The algorithmicx package allows you to define your own be recommenced. The legal values for this option are:
environments. part, chapter, section, subsection, subsubsection or noth-
ing (default). For example:
To define blocks beginning with a starting command and
ending with an ending command, use \usepackage[chapter]{algorithm}
\algblock[<block>]{<start>}{<end>}

This defines two commands \<start> and \<end> which List of algorithms
have no parameters. The text displayed by them is
\textbf{<start>} and \textbf{<end>}. When you use figures or tables, you can add a list of them
close to the table of contents; the algorithm package pro-
With \algblockdefx you can give the text to be output by
vides a similar command. Just put
the starting and ending command and the number of pa-
rameters for these commands. In the text the n-th param- \listofalgorithms
eter is referenced by #n.
\algblockdefx[<block>]{<start>}{<end>} [<startparam- anywhere in the document, and LaTeX will print a list of
count>][<default value>]{<start text>} [<endparam- the “algorithm” environments in the document with the
count>][<default value>]{<end text>} corresponding page and the caption.

Example: An example from the manual


\algblock[Name]{Start}{End} \algblock-
defx[NAME]{START}{END}% [2][Un- This is an example taken from the manual (official man-
known]{Start #1(#2)}% {Ending} \algblock- ual, p.14)
defx[NAME]{}{OTHEREND}% [1]{Until (#1)} \begin{algorithm} % enter the algorithm environment
\begin{algorithmic} \Start \Start \START[One]{x} \caption{Calculate $y = x^n$} % give the algorithm a
\END \START{0} \OTHEREND{\texttt{True}} \End caption \label{alg1} % and a label for \ref{} commands
\Start \End \End \end{algorithmic} later in the document \begin{algorithmic} % enter the
algorithmic environment \REQUIRE $n \geq 0 \vee x
More advanced customization and other constructions are \neq 0$ \ENSURE $y = x^n$ \STATE $y \Leftarrow
described in the algorithmicx manual: http://mirror.ctan. 1$ \IF{$n < 0$} \STATE $X \Leftarrow 1 / x$ \STATE
org/macros/latex/contrib/algorithmicx/algorithmicx.pdf $N \Leftarrow -n$ \ELSE \STATE $X \Leftarrow x$
\STATE $N \Leftarrow n$ \ENDIF \WHILE{$N \neq
0$} \IF{$N$ is even} \STATE $X \Leftarrow X \times
4.5.4 The algorithm environment X$ \STATE $N \Leftarrow N / 2$ \ELSE[$N$ is odd]
\STATE $y \Leftarrow y \times X$ \STATE $N \Left-
It is often useful for the algorithm produced by algorith- arrow N - 1$ \ENDIF \ENDWHILE \end{algorithmic}
mic to be “floated” to the optimal point in the document \end{algorithm}
to avoid it being split across pages. The algorithm en-
vironment provides this and a few other useful features.
Include it by adding the The official manual is located at http://mirrors.ctan.
\usepackage{algorithm} to your document’s preamble. It org/macros/latex/contrib/algorithms/algorithms.
is entered into by pdf
\begin{algorithm} \caption{<your caption for this
algorithm>} \label{<your label for references later in
your document>} \begin{algorithmic} <algorithmic 4.5.5 Typesetting using the program pack-
environment> \end{algorithmic} \end{algorithm} age
The program package provides macros for typesetting al-
gorithms. Each line is set in math mode, so all the inden-
Algorithm numbering tation and spacing is done automatically. The notation
|variable_name| can be used within normal text, maths
The default numbering system for the algorithm package expressions or programs to indicate a variable name. Use
is to number algorithms sequentially. This is often not de- \origbar to get a normal | symbol in a program. The com-
sirable, particularly in large documents where numbering mands \A, \B, \P, \Q, \R, \S, \T and \Z typeset the cor-
according to chapter is more appropriate. The numbering responding bold letter with the next object as a subscript
4.6. SOURCE CODE LISTINGS 101

(eg \S1 typesets {\bf S$_1$} etc). Primes work normally, Here’s the original program:
eg \S‘‘. \begin{program} \VAR \seq{m := 0, p := 0, |last| := ``
Below is an example of typesetting a basic algorithm us- ''}; \ACTIONS |prog|: |prog| \ACTIONEQ % \seq{|line|
ing the program package (remember to add the \usepa- := `` '', m := 0, i := 1}; \CALL |inhere| \ENDACTION l
ckage{program} statement to your document preamble): \ACTIONEQ % i := i+1; \IF (i=(n+1)) \THEN \CALL
\begin{program} \mbox{A fast exponentiation proce- |alldone| \FI ; m := 1; \IF |item|[i] \neq |last| \THEN
|write|(|line|); |line| := `` ''; m := 0; \CALL |inhere| \FI ;
dure:} \BEGIN \\ % \FOR i:=1 \TO 10 \STEP 1 \DO
|expt|(2,i); \\ |newline|() \OD % \rcomment{This text \CALL |more| \ENDACTION |inhere| \ACTIONEQ %
will be set flush to the right margin} \WHERE \PROC p := |number|[i]; |line| := |item|[i]; |line| := |line| \concat ``
|expt|(x,n) \BODY z:=1; \DO \IF n=0 \THEN \EXIT \FI; '' \concat p; \CALL |more| \ENDACTION |more| \AC-
\DO \IF |odd|(n) \THEN \EXIT \FI; \COMMENT{This TIONEQ % \IF (m=1) \THEN p := |number|[i]; |line| :=
is a comment statement}; n:=n/2; x:=x*x \OD; \{ n>0 |line| \concat ``, '' \concat p \FI ; |last| := |item|[i]; \CALL
\}; n:=n-1; z:=z*x \OD; |print|(z) \ENDPROC \END l \ENDACTION |alldone| \ACTIONEQ |write|(|line|);
\end{program} \CALL Z \ENDACTION \ENDACTIONS \END
\end{program}

And here’s the transformed and corrected version:


\begin{program} \seq{|line| := `` '', i := 1}; \WHILE
i \neq n+1 \DO |line| := |item|[i] \concat `` '' \concat
|number|[i]; i := i+1; \WHILE i \neq n+1 \AND |item|[i]
= |item|[i-1] \DO |line| := |line| \concat ``, '' \concat |num-
ber|[i]); i := i+1 \OD ; |write|(|line|) \OD \end{program}

The package also provides a macro for typesetting a set


like this: \set{x \in N | x > 0}.
Lines can be numbered by setting \NumberProgramstrue
and numbering turned off with \NumberProgramsfalse
Package page
Package documentation

The commands \( and \) are redefined to typeset an al-


gorithm in a minipage, so an algorithm can appear as a 4.5.6 References
single box in a formula. For example, to state that a par-
ticular action system is equivalent to a WHILE loop you [1]
can write:
[2] http://tex.stackexchange.com/questions/70181/
\[ \( \ACTIONS A: A \EQ \IF \B{} \THEN \S{}; \CALL revtex4-1-and-algorithm2e-indentation-clash
A \ELSE \CALL Z \FI \QE \ENDACTIONS \) \EQT \(
\WHILE \B{} \DO \S{} \OD \) \] • The official manual for the algorithms pack-
age, Rogério Brito (2009), http://mirrors.ctan.org/
Dijkstra conditionals and loops: macros/latex/contrib/algorithms/algorithms.pdf
\begin{program} \IF x = 1 \AR y:=y+1 \BAR
x = 2 \AR y:=y^2 \utdots \BAR x = n \AR
y:=\displaystyle\sum_{i=1}^n y_i \FI \DO 2 \orig- 4.6 Source Code Listings
bar x \AND x>0 \AR x:= x/2 \BAR \NOT 2 \origbar x
\AR x:= \modbar{x+3} \OD \end{program}
4.6.1 Using the listings package
Loops with multiple exits: Using the package listings you can add non-formatted text
\begin{program} \DO \DO \IF \B1 \THEN \EXIT \FI; as you would do with \begin{verbatim} but its main aim is
\S1; \IF \B2 \THEN \EXIT(2) \FI \OD; \IF \B1 \THEN to include the source code of any programming language
\EXIT \FI \OD \end{program} within your document. If you wish to include pseudocode
or algorithms, you may find Algorithms and Pseudocode
useful also.
A Reverse Engineering Example.
To use the package, you need:
102 CHAPTER 4. TECHNICAL TEXTS

The listings package supports highlighting of all the most Pascal4 , Perl, PHP, PL/I, Plasm, POV, Prolog, Promela,
common languages and it is highly customizable. If you Python, R, Reduce, Rexx, RSL, Ruby, S4 , SAS, Scilab,
just want to write code within your document the package sh, SHELXL, Simula4 , SQL, tcl4 , TeX4 , VBScript, Ver-
provides the lstlisting environment: ilog, VHDL4 , VRML4 , XML, XSLT.
Another possibility, that is very useful if you created a For some of them, several dialects are supported. For
program on several files and you are still editing it, is to more information, refer to the documentation that comes
import the code from the source itself. This way, if you with the package, it should be within your distribution
modify the source, you just have to recompile the LaTeX under the name listings-*.dvi.
code and your document will be updated. The command
is: Notes
in the example there is a Python source, but it doesn't
matter: you can include any file but you have to write 1. It supports Mathematica code only if you are typing
the full file name. It will be considered plain text and it in plain text format. You can't include *.NB files
will be highlighted according to your settings, that means \lstinputlisting{...} as you could with any other pro-
it doesn't recognize the programming language by itself. gramming language, but Mathematica can export in
You can specify the language while including the file with a pretty-formatted LaTeX source.
the following command:
2. Specification of the dialect is manda-
You can also specify a scope for the file. tory for these languages (e.g. lan-
This comes in handy if you are sure that the file will not guage={[x86masm]Assembler}).
change (at least before the specified lines). You may also
3. Modelica is supported via the dtsyntax package
omit the firstline or lastline parameter: it means every-
available here.
thing up to or starting from this point.
This is a basic example for some Pascal code: 4. For these languages, multiple dialects are supported.
C, for example, has ANSI, Handel, Objective and
\documentclass{article} \usepackage{listings} % Sharp. See p. 12 of the listings manual for an
Include the listings-package \begin{document} \lst- overview.
set{language=Pascal} % Set your language (you can
change the language for each code-block optionally) 5. Defined as a dialect of another language
\begin{lstlisting}[frame=single] % Start your code-
block for i:=maxint to 0 do begin { do nothing } end;
Write('Case insensitive '); Write('Pascal keywords.'); Settings
\end{lstlisting} \end{document}
You can modify several parameters that will affect how
the code is shown. You can put the following code any-
where in the document (it doesn't matter whether before
or after \begin{document}), change it according to your
needs. The meaning is explained next to any line.
\usepackage{listings} \usepackage{color} \de-
finecolor{mygreen}{rgb}{0,0.6,0} \define-
color{mygray}{rgb}{0.5,0.5,0.5} \define-
color{mymauve}{rgb}{0.58,0,0.82} \lstset{ % back-
groundcolor=\color{white}, % choose the background
color; you must add \usepackage{color} or \usepack-
age{xcolor} basicstyle=\footnotesize, % the size of the
fonts that are used for the code breakatwhitespace=false,
% sets if automatic breaks should only happen at
Supported languages
whitespace breaklines=true, % sets automatic line
breaking captionpos=b, % sets the caption-position
It supports the following programming languages: to bottom commentstyle=\color{mygreen}, % com-
ABAP2,4 , ACSL, Ada4 , Algol4 , Ant, Assembler2,4 , ment style deletekeywords={...}, % if you want to
Awk4 , bash, Basic2,4 , C#5 , C++4 , C4 , Caml4 , Clean, delete keywords from the given language escapein-
Cobol4 , Comal, csh, Delphi, Eiffel, Elan, erlang, Eu- side={\%*}{*)}, % if you want to add LaTeX within
phoria, Fortran4 , GCL, Gnuplot, Haskell, HTML, IDL4 , your code extendedchars=true, % lets you use non-
inform, Java4 , JVMIS, ksh, Lisp4 , Logo, Lua2 , make4 , ASCII characters; for 8-bits encodings only, does
Mathematica1,4 , Matlab, Mercury, MetaPost, Miranda, not work with UTF-8 frame=single, % adds a frame
Mizar, ML, Modelica3 , Modula-2, MuPAD, NAS- around the code keepspaces=true, % keeps spaces in
TRAN, Oberon-2, Objective C5 , OCL4 , Octave, Oz, text, useful for keeping indentation of code (possibly
4.6. SOURCE CODE LISTINGS 103

needs columns=flexible) keywordstyle=\color{blue}, % In our example, we only set two options globally: the de-
keyword style language=Octave, % the language of the fault style and the escape character. Usage:
code otherkeywords={*,...}, % if you want to add more \begin{lstlisting} #include <stdio.h> #define N 10 /*
keywords to the set numbers=left, % where to put the Block * comment */ int main() { int i; // Line com-
line-numbers; possible values are (none, left, right) num- ment. puts(“Hello world!"); for (i = 0; i < N; i++) {
bersep=5pt, % how far the line-numbers are from the puts(“LaTeX is also great for programmers!"); } return
code numberstyle=\tiny\color{mygray}, % the style that 0; } \end{lstlisting} \lstinputlisting[caption=Scheduler,
is used for the line-numbers rulecolor=\color{black}, % style=customc]{hello.c}
if not set, the frame-color may be changed on line-breaks
within not-black text (e.g. comments (green here))
showspaces=false, % show spaces everywhere adding The C part will print as
particular underscores; it overrides 'showstringspaces’
showstringspaces=false, % underline spaces within
strings only showtabs=false, % show tabs within strings
adding particular underscores stepnumber=2, % the
step between two line-numbers. If it’s 1, each line will
be numbered stringstyle=\color{mymauve}, % string
literal style tabsize=2, % sets default tabsize to 2 spaces
title=\lstname % show the filename of files included with
\lstinputlisting; also try caption instead of title }

escapeinside

The escapeinside line needs an explanation. The option


escapeinside={A}{B} will define delimiters for escaping
into LaTeX code, i.e. all the code between the string “A”
and “B” will be parsed as LaTeX over the current listings
style. In the example above, the comments for Octave
start with %, and they are going to be printed in the doc-
ument unless they start with %*, in which case they are Automating file inclusion
read as LaTeX (with all LaTeX commands fulfilled) un-
til they're closed with another *). If you add the above If you have a bunch of source files you want to include,
paragraph, the following can be used to alter the settings you may find yourself doing the same thing over and over
within the code: again. This is where macros show their real power.
There are many more options, check the official docu- \newcommand{\includecode}[2][c]{\lstinputlisting[caption=#2,
mentation. escapechar=, style=custom#1]{#2}<!---->} % ... \in-
cludecode{sched.c} \includecode[asm]{sched.s} % ...
\lstlistoflistings
Style definition

The package lets you define styles, i.e. profiles specifying In this example, we create one command to ease source
a set of settings. code inclusion. We set the default style to be customc. All
listings will have their name as caption: we do not have
Example to write the file name twice thanks to the macro. Finally
\lstdefinestyle{customc}{ belowcaption- we list all listings with this command from the listings
skip=1\baselineskip, breaklines=true, frame=L, package.
xleftmargin=\parindent, language=C, show- See Macros for more details.
stringspaces=false, basicstyle=\footnotesize\ttfamily,
keywordstyle=\bfseries\color{green!40!black}, com-
mentstyle=\itshape\color{purple!40!black}, identi- Encoding issue
fierstyle=\color{blue}, stringstyle=\color{orange},
} \lstdefinestyle{customasm}{ belowcap- By default, listings does not support multi-byte encoding
tionskip=1\baselineskip, frame=L, xleftmar- for source code. The extendedchar option only works for
gin=\parindent, language=[x86masm]Assembler, 8-bits encodings such as latin1.
basicstyle=\footnotesize\ttfamily, com-
mentstyle=\itshape\color{purple!40!black}, } \lst- To handle UTF-8, you should tell listings how to interpret
set{escapechar=@,style=customc} the special characters by defining them like so
\lstset{literate= {á}{<!---->{\'a}<!---->}1 {é}{<!----
104 CHAPTER 4. TECHNICAL TEXTS

>{\'e}<!---->}1 {í}{<!---->{\'i}<!---->}1 {ó}{<!---- code highlighting, which as of Nov 2014 boasts over 300
>{\'o}<!---->}1 {ú}{<!---->{\'u}<!---->}1 {Á}{<!- supported languages and text formats.
--->{\'A}<!---->}1 {É}{<!---->{\'E}<!---->}1 As the package relies on external Python code, the setup
{Í}{<!---->{\'I}<!---->}1 {Ó}{<!---->{\'O}<!---->}1 require a few more steps than a usual LaTeX package, so
{Ú}{<!---->{\'U}<!---->}1 {à}{<!---->{\`a}<!---->}1 please have a look at their GitHub repo and their manual.
{è}{<!---->{\`e}<!---->}1 {ì}{<!---->{\`i}<!---->}1
{ò}{<!---->{\`o}<!---->}1 {ù}{<!---->{\`u}<!---->}1
{À}{<!---->{\`A}<!---->}1 {È}{<!---->{\'E}<!---->}1 4.6.3 References
{Ì}{<!---->{\`I}<!---->}1 {Ò}{<!---->{\`O}<!---->}1
{Ù}{<!---->{\`U}<!---->}1 {ä}{<!---->{\"a}<!---->}1 A lot more detailed information can be found in a PDF
{ë}{<!---->{\"e}<!---->}1 {ï}{<!---->{\"i}<!---->}1 by Carsten Heinz and Brooks Moses.
{ö}{<!---->{\"o}<!---->}1 {ü}{<!---->{\"u}<!---->}1
{Ä}{<!---->{\"A}<!---->}1 {Ë}{<!---->{\"E}<!---- Details and documentation about the Listings package
>}1 {Ï}{<!---->{\"I}<!---->}1 {Ö}{<!---->{\"O}<!--- can be found at its CTAN website.
->}1 {Ü}{<!---->{\"U}<!---->}1 {â}{<!---->{\^a}<!--
-->}1 {ê}{<!---->{\^e}<!---->}1 {î}{<!---->{\^i}<!--
-->}1 {ô}{<!---->{\^o}<!---->}1 {û}{<!---->{\^u}<!- 4.7 Linguistics
--->}1 {Â}{<!---->{\^A}<!---->}1 {Ê}{<!----
>{\^E}<!---->}1 {Î}{<!---->{\^I}<!---->}1 {Ô}{<!- There are a number of LaTeX packages available for
--->{\^O}<!---->}1 {Û}{<!---->{\^U}<!---->}1 writing linguistics papers. Various packages have been
{œ}{<!---->{\oe}<!---->}1 {Œ}{<!---->{\OE}<!---- created for enumerated examples, syntactic trees, OT
>}1 {æ}{<!---->{\ae}<!---->}1 {Æ}{<!---->{\AE}<!- tableaux, feature matrices, IPA fonts, and many other ap-
--->}1 {ß}{<!---->{\ss}<!---->}1 {ű}{{\H{u}}}1 plications. Some packages such as the tipa package are
{Ű}{{\H{U}}}1 {ő}{{\H{o}}}1 {Ő}{{\H{O}}}1 effectively standard within the field, while others will vary
{ç}{<!---->{\c c}<!---->}1 {Ç}{<!---->{\c C}<!- by author preference.
--->}1 {ø}{<!---->{\o}<!---->}1 {å}{<!---->{\r
Some recommended packages:[1]
a}<!---->}1 {Å}{<!---->{\r A}<!---->}1 {€}{<!---
->{\EUR}<!---->}1 {£}{<!---->{\pounds}<!---->}1
}<!----> • Glosses: gb4e or Covington;
• IPA symbols: tipa;
The above table will cover most characters in latin lan-
• OT Tableaux: OTtablx;
guages. For a more detailed explanation of the usage of
the literate option check section 5.4 in the Listings Doc- • Syntactic trees: qtree + tree-dvips (for drawing ar-
umentation. rows);
Another possibility is to replace \usepackage{listings} (in
the preamble) with \usepackage{listingsutf8}. • Alternatively, xyling is very powerful but
not as user friendly as qtree;
• The xy package itself has a steep learning
Customizing captions curve, but allows a lot of control; for sim-
plest trees use the xymatrix feature and
You can have fancy captions (or titles) for your listings arrows;
using the caption package. Here is an example for listings.
• tikz-qtree has the same syntax as qtree,
\usepackage{caption} \usepackage{listings} \Declare- but uses PGF/TikZ, which allows more
CaptionFont{white}{ \color{white} } \DeclareCaption- options for drawing arrows, etc.
Format{listing}{ \colorbox[cmyk]{0.43, 0.35, 0.35,0.01
}{ \parbox{\textwidth}{\hspace{15pt}#1#2#3} } • Dependency trees and bubble parses:
} \captionsetup[lstlisting]{ format=listing, label-
font=white, textfont=white, singlelinecheck=false,
• The TikZ-dependency package provides
margin=0pt, font={bf,footnotesize} } % ... \lstinputlist-
a high-level, convenient interface to draw
ing[caption=My caption]{sourcefile.lang}
dependency graphs. It is based on
PGF/TikZ but does not require prior
knowledge of TikZ in order to be used
productively.
4.6.2 The minted package
• Attribute-Value Matrices (AVMs): avm
minted is an alternative to listings which has become pop-
ular. It uses the external Python library Pygments for • John Frampton’s expex: expex
4.7. LINGUISTICS 105

4.7.1 Enumerated examples \begin{exe} \ex This sentence is grammatical English.


\ex[*] {This sentence English in ungrammatical is.}
There are several commonly used packages for creating \end{exe}
the kinds of numbered examples that are used in linguis-
tics publications. produces:

gb4e

Referencing examples in text works as it does in nor-


The gb4e package[2] is called with:
mal LaTeX documents. See the labeling and cross-
\usepackage{gb4e} referencing section for more details.
\begin{exe} \ex\label{ex1} Godzilla destroyed the city.
IMPORTANT: If you use gb4e package, let it be the last \ex\label{ex2} Godzilla roared. \end{exe} Sentence
\usepackage call in the document’s preamble. Otherwise (\ref{ex1}) contains two arguments, but (\ref{ex2})
you may get exceeded parameter stack size error. contains only one.
Examples for this package are placed within the exe en-
vironment, and each example is introduced with the \ex Further details can be found in the full documentation
command. available here.
\begin{exe} \ex This is an example. \end{exe}
lingmacros
produces:
The lingmacros package[3] created by Emma Pease is an
alternate method for example numbering. This package
Multiple examples can be included within the environ- uses two main commands, \enumsentence and \eenum-
ment, and each will have its own number. sentence. The former is used for singleton examples,
while the latter command is used for nested examples.
\begin{exe} \ex This is the first example. \ex This is the
second example. \ex This is the third. \end{exe} \enumsentence{This is an example.}

produces:
\enumsentence{This is the first example.} \enumsen-
tence{This is the second example.} \enumsentence{This
is the third.}

To create nested lists of examples, the xlist enviroment is


used.
\begin{exe} \ex \begin{xlist} \ex This is a sub-example.
\ex This is a second sub-example. \ex \begin{xlist}
\ex This is a sub-sub-example. \ex This is a second Multiply nested examples make use of the normal LaTeX
sub-sub-example. \end{xlist} \end{xlist} \end{exe} list environments.
\eenumsentence{\item This is a sub-example. \item
produces: This is a second sub-example. \item \begin{enumerate}
\item This is sub-sub-example. \item This is a second
sub-sub-example. \end{enumerate} }

produces:

For notating acceptability judgments, the \ex command


can take an optional argument. When including a judg-
ment marker, the corresponding sentence must be sur-
rounded by braces.
106 CHAPTER 4. TECHNICAL TEXTS

Full documentation can be found here. \usepackage[nocenter]{qtree} % do not center trees

4.7.2 Syntactic trees or via the command


\qtreecenterfalse % do not center trees from here on
Often, linguists will have to illustrate the syntactic struc-
ture of a sentence. One device for doing this is through
anywhere in the document. The effect of the latter can be
syntactic trees. Unfortunately, trees look very different
undone by using the command
in different grammar formalisms, and different LaTeX
packages are suited for different formalisms. \qtreecentertrue % center trees from here on

Constituent trees IMPORTANT: If you use gb4e package, let it be the last
\usepackage call in the document’s preamble. Otherwise
While there are several packages for drawing syntactic you may get exceeded parameter stack size error.
trees available for LaTeX, this article focuses on the qtree
and xyling packages.
tikz-qtree Using the same syntax as qtree, tikz-qtree
is another easy-to-use alternative for drawing syntactic
qtree Drawing trees with qtree is relatively straightfor- trees.
ward. First, the qtree package has to be included in the For simple trees, tikz-qtree is completely interchangable
document’s preamble: with qtree. However, some of qtree’s advanced features
\usepackage{qtree} are implemented in a different way, or not at all. On the
other hand, tikz-qtree provides other features such as con-
trolling the direction of the tree’s growth (top to bottom,
A new tree is started using the \Tree command, each
left to right etc.) or different styles for edges.
(sub-)tree is indicated by brackets [ ]. The root of a (sub-
)tree is always preceded by a ., leaf nodes are simply ex- To use the tikz-qtree package for drawing trees, put the
pressed by their labels. following into the document’s preamble:
For example, the following code \usepackage{tikz} \usepackage{tikz-qtree}
\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]
The syntax of tikz-qtree and result when drawing a simple
tree is the same as for qtree.
produces this syntactic tree as output:
\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]
Note that, other than for qtree, trees are not centered by

Note that the spaces before the closing brackets are


mandatory.
By default, qtree centers syntactic trees on the page. This default. To center them, put them into a centered envi-
behaviour can be turned off by either specifying the be- ronment:
haviour when loading the package \begin{center} \Tree [.S [.NP LaTeX ] [.VP [.V is ]
4.7. LINGUISTICS 107

[.NP fun ] ] ] \end{center}

For setting the style of trees, tikz-qtree provides the


\tikzset command. For example, to make a tree grow
from left to right instead of from top to bottom, use the
following code:
\tikzset{grow'=right} % make trees grow from left
to right \tikzset{every tree node/.style={anchor=base
west}} % allign nodes of the tree to the left (west) \Tree
[.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]
The above code changes the default orientation for all

A dependency tree created using TikZ

ps2pdf. Latter is the case of another package based on


the package xy, namely xyling.
trees that are defined after \tikzset commands. To only The code for a similar tree using xyling might look like:
change the direction of a single tree, it has to be put into % In the preamble: \usepackage{xyling} % In the
a \tikzpicture environment: document: \Tree{ & \K{is}\B{dl}\B{drr} \\ \K{this}
\begin{tikzpicture} % all changes only affect trees &&& \K{tree}\B{dll}\B{dl}\B{dr} \\ & \K{an} &
within this environment \tikzset{grow'=right} % \K{example} && \K{.} } \medskip \textit{This is an
make trees grow from left to right \tikzset{every tree example tree.}
node/.style={anchor=base west}} % allign nodes of the
tree to the left (west) \Tree [.S [.NP LaTeX ] [.VP [.V is which gives you a drawing like this:
] [.NP fun ] ] ] \end{tikzpicture}

Dependency Trees

Dependency trees can take multiple visual forms. Com-


monly, they quite resemble phrase structure trees. Alter-
natively, they can be captured by brackets drawn above
running text.

Two-dimensional Dependency Trees These can be


either achieved using the fairly universal drawing package
TikZ, like so:
% In the preamble: \usepackage{tikz} % In the docu-
ment: \begin{tikzpicture} \node (is-root) {is} [sibling A dependency tree created using xyling
distance=3cm] child { node {this} } child { node {tree}
[sibling distance=1.5cm] child { node {an} } child {
node {example} } child { node {.} } child[missing] Dependency Trees as Brackets above Text One way
}; \path (is-root) +(0,−2.5\tikzleveldistance) node to typeset dependency brackets above running text is us-
{\textit{This is an example tree.}}; \end{tikzpicture} ing the package xytree. It gives you fairly good control
of how the brackets are typeset but requires compiling
which gives you the following drawing: the LaTeX code to DVI (and perhaps converting to PDF
using the tools dvips and ps2pdf later).
TikZ has the advantage that it allows for generating PDF
directly from the LaTeX source, without need for any de- An example code:
tour of compiling to DVI using latex, and then convert- % In the preamble: \usepackage{xytree} % In the
ing to PDF probably via PS using tools such as dvips and document: \xytext{ \xybarnode{Peter} &~~~& \xy-
108 CHAPTER 4. TECHNICAL TEXTS

barnode{and} \xybarconnect(UL,U){−2}"_{\small With gb4e


conj}" \xybarconnect(UR,U){2}"^{\small conj}"
&~~~& \xybarnode{Mary} &~~~& \xybarn- To create a glossed example, use the normal exe environ-
ode{bought} \xybarconnect[8](UL,U){−4}"_{\small ment. But after the \ex tag, introduce the example and its
subj}" \xybarconnect[13]{6}"^{\small punct}" gloss using \gll and the translation after it with \trans tag.
\xybarconnect[8](UR,U){4}"^{\small obj}"
&~~~& \xybarnode{a} &~~~& \xybarnode{car} \begin{exe} \ex \gll Кот ест сметану\\ cat.NOM
\xybarconnect(UL,U){−2}"_{\small det}" &~~~& eat.3.SG.PRS sour-cream.ACC\\ \trans `The cat eats
\xybarnode{.} } sour cream' \end{exe}

results in: The code will produce the following output:

A dependency tree above running text created using xytree Vertically aligned glosses are separated by spaces, so if
it’s necessary to include a space in part the gloss, simply
enclose the connected parts inside braces.
Dependency Trees using TikZ-dependency The \begin{exe} \ex \gll Pekka pel\"astyi karhusta.\\ Pekka
package provides high level commands to design and style {became afraid} bear.ELA\\ \trans `Pekka became afraid
dependency graphs. To draw a graph, you only need to because of the/a bear.' \end{exe}
create a dependency environment, write the text of the
sentence within the deptext environment and use depedge
commands to draw the edges. Global and local optional
parameters can be used to style and fine tune the looks of
the graph, as shown in the following example: With lingmacros
% In the preamble: \usepackage{tikz-dependency}
% In the document: \begin{dependency}[theme The lingmacros package uses the \shortex command to in-
= simple] \begin{deptext}[column sep=1em] troduce glossed examples inside the \enumsentence and
A \& hearing \& is \& scheduled \& on \& \eenumsentence commands. This command takes four
the \& issue \& today \& . \\ \end{deptext} arguments and builds off the normal tabular environment.
\deproot{3}{ROOT} \depedge{2}{1}{ATT} Its first argument specifies the number of columns in the
\depedge[edge start x offset=−6pt]{2}{5}{ATT} gloss. The second and third arguments give the text and
\depedge{3}{2}{SBJ} \depedge{3}{9}{PU} its gloss respectively, and items within each column are
\depedge{3}{4}{VC} \depedge{4}{8}{TMP} divided by the usual & tabular separator. The fourth ar-
\depedge{5}{7}{PC} \depedge[arc an- gument is the translation.
gle=50]{7}{6}{ATT} \end{dependency} \enumsentence{\shortex{3} {Pekka & pel\"astyi &
karhu-sta.} {Pekka & became afraid & bear.ELA}
This code snippet would produce the following result: {`Pekka became afraid because of the/a bear.'} }

4.7.4 IPA characters

The tipa package is the standard LaTeX package for In-


A dependency tree drawn with TikZ-dependency. ternational Phonetic Alphabet symbols.
There are two methods for getting IPA symbols into a
document. The first way is to use the IPA environment.
4.7.3 Glosses This method is useful for long stretches of text that need
to be in IPA. Alternatively, there is the \textipa command
Below, it is explained how to make glossed examples with that will format the text in its argument into IPA. This
different packages. command is similar to other font typesetting commands.
4.7. LINGUISTICS 109

Basic symbols • The gb4e package page on CTAN.

The IPA format works by translating ASCII characters


into corresponding IPA symbols. Lower case letters are
rendered as usual,
however capital letters are rendered differently.
Punctuation marks that are normally used in LaTeX are
also rendered faithfully in the {{{1}}} environment.
Numerals and @ also have variants in the tipa environ-
ment.
In addition, there are a number of special macros for
representing symbols that don't have other associations,
some of which are listed here. For a complete list see the
official TIPA Manual[4] .
The \; macro preceding a capital letter produces a small
caps version of the letter.
The \: macro produces retroflex symbols.
{{LaTeX/Example|code= \textipa{\:d \:l \:n \:r \:s \:t \:z}|
render= </source>
The \! macro produces implosive symbols and the bilabial
click.

XeLaTeX

Another way of inputting IPA symbols in a document is


to use XeTeX as the compiler and insert the symbols di-
rectly, using a character map or an IPA keyboard.[5]

4.7.5 Phonological rules


Typesetting phonological rules can be done with the help
of the phonrule package.[6]
Following is an example of what you can achieve with the
package:

4.7.6 References
[1] LaTeX for Linguists presentation

[2] The gb4e package on CTAN

[3] The lingmacros package on CTAN

[4] TIPA manual

[5] For more information on IPA keyboards, see SIL .

[6] The package on CTAN.

4.7.7 External links


• LaTeX for Linguists

• The qtree package for drawing syntactic trees.


Chapter 5

Special Pages

5.1 Indexing Compiling indices

When the input file is processed with LaTeX, each \in-


Especially useful in printed books, an index is an alpha- dex command writes an appropriate index entry, together
betical list of words and expressions with the pages of with the current page number, to a special file. The file
the book upon which they are to be found. LaTeX sup- has the same name as the LaTeX input file, but a different
ports the creation of indices with its package makeidx, extension (.idx). This .idx file can then be processed with
and its support program makeindex, called on some sys- the makeindex program. Type in the command line:
tems makeidx.
makeindex filename
Note that filename is without extension: the program will
look for filename.idx and use that. You can optionally
pass filename.idx directly to the program as an argument.
The makeindex program generates a sorted index with the
5.1.1 Using makeidx same base file name, but this time with the extension .ind.
If now the LaTeX input file is processed again, this sorted
index gets included into the document at the point where
To enable the indexing feature of LaTeX, the makeidx LaTeX finds \printindex.
package must be loaded in the preamble with:
The index created by latex with the default options may
and the special indexing commands must be enabled by not look as nice or as suitable as you would like it. To im-
putting the prove the looks of the index makeindex comes with a set
command into the input file preamble. This should be of style files, usually located somewhere in the tex direc-
done within the preamble, since it tells LaTeX to create tory structure, usually below the makeindex subdirectory.
the files needed for indexing. To tell LaTeX what to in- To tell makeindex to use a specific style file, run it with
dex, use the command line option:

where key is the index entry and does not appear in the makeindex -s [style file] filename
final layout. You enter the index commands at the points If you use a GUI for compiling latex and index files, you
in the text that you want to be referenced in the index, may have to set this in the options. Here are some con-
likely near the reason for the key. For example, the text figuration tips for typical tools:
can be re-written as
to create an entry called 'Fourier Series’ with a reference
to the target page. Multiple uses of \index with the same MakeIndex settings in WinEdt Say you want to add
key on different pages will add those target pages to the an index style file named simpleidx.ist
same index entry.
To show the index within the document, merely use the
command • Texify/PDFTexify: Options→Execution
Modes→Accessories→PDFTeXify, add to the
It is common to place it at the end of the document. The
Switches: --mkidx-option="-s simpleidx.ist”
default index format is two columns.
The showidx package that comes with LaTeX prints out
all index entries in the right margin of the text. This is • MakeIndex alone: Options→Execution
quite useful for proofreading a document and verifying Modes→Accessories→MakeIndex, add to com-
the index. mand line: -s simpleidx.ist

110
5.1. INDEXING 111

Sophisticated indexing saries package described in the Glossary chapter. An-


other option is the package acronym .
Below are examples of \index entries:
To enable the Nomenclature feature of LaTeX, the
nomencl package must be loaded in the preamble with:
Subentries If some entry has subsections, these can be Issue the \nomencla-
marked off with !. For example, ture[⟨prefix⟩]{⟨symbol⟩}{⟨description⟩} command
would create an index entry with 'cp850' categorized un- for each symbol you want to have included in the
der 'input' (which itself is categorized into 'encodings’). nomenclature list. The best place for this command is
These are called subsubentries and subentries in makeidx immediately after you introduce the symbol for the first
terminology. time. Put \printnomenclature at the place you want to
have your nomenclature list.

Controlling sorting In order to determine how an in- Run LaTeX 2 times then
dex key is sorted, place a value to sort by before the key makeindex filename.nlo -s nomencl.ist -o filename.nls
with the @ as a separator. This is useful if there is any
followed by running LaTeX once again.
formatting or math mode, so one example may be
To add the abbreviation list to the table of content, intoc
so that the entry in the index will show as ' F⃗ ' but be
option can be used when declare the nomencl package,
sorted as 'F'.
i.e.
To combine with the above feature for subentries, you
instead of using the code in Adding Index to Table Of
should style the appropriate component(s):
Contents section.
The title of the list can be changed using the following
Changing page number style To change the format- command:
ting of a page number, append a | and the name of some
command which does the formatting. This command
should only accept one argument. 5.1.3 Multiple indices
For example, if on page 3 of a book you introduce bull-
dogs and include the command If you need multiple indices you can use the package
multind .
and on page 10 of the same book you wish to show the
main section on bulldogs with a bold page number, use This package provides the same commands as makeidx,
but now you also have to pass a name as the first argument
This will appear in the index as bulldog, 3, 10 to every command.
If you use texindy in place of makeindex, the classified
entries will be sorted too, such that all the bolded entries
will be placed before all others by default. 5.1.4 Adding index to table of contents
By default, Index won't show in Table Of Contents, so
Multiple pages To perform multi-page indexing, add you have to add it manually.
a |( and |) to the end of the \index command, as in To add index as a chapter, use these commands:
The entry in the index for the subentry 'History' will be If you use the book class, you may want to start it on an
the range of pages between the two \index commands. odd page by using \cleardoublepage.

Using special characters In order to place values with


!, @, or |, which are otherwise escape characters, in the
5.1.5 International indices
index, one must quote these characters in the \index com-
If you want to sort entries that have international charac-
mand by putting a double quotation mark (") in front of
ters (such as ő, ą, ó, ç, etc.) you may find that the sort-
them, and one can only place a " in the index by quoting
ing “is not quite right”. In most cases the characters are
it (i.e., a key for " would be \index{""}).
treated as special characters and end up in the same group
This rule does not hold for \", so to put the letter ä in the as @, ¶ or µ. In most languages that use Latin alphabet
index, one may still use \index{a@\"{a}}. it’s not correct.

5.1.2 Abbreviation list Generating index

You can make a list of abbreviations with the package Unfortunately, current version of xindy and hyperref
nomencl . You may also be interested in using the glos- are incompatible. When you use textbf or textit mod-
112 CHAPTER 5. SPECIAL PAGES

ifiers, texindy will print error message:unknown cross- iconv -f latin2 -t utf8 latin2.xdy >utf8.xdy
reference-class `hyperindexformat'! (ignored) and won't in folder
add those pages to index. Work-around for this bug is
described on the talk page. /usr/share/xindy/tex/inputenc
To generate international index file you have to use (You must have root privileges)
texindy instead of makeindex.
xindy is a much more extensible and robust indexing sys- xindy in kile To use texindy instead of makeindex in
tem than the makeindex system. kile, you have to either redefine the MakeIndex tool in
For example, one does not need to write: Settings → Configure Kile... → Tools → Build, or define
new tool and redefine other tools to use it (for example by
to get the Lin entry after LAN and before LZA, instead,
adding it to QuickBuild).
it’s enough to write
The xindy definition should look similar to this:
But what is much more important, it can properly sort
index files in many languages, not only English. General: Command: texindy Options: -L polish -M
lang/polish/utf8 -I latex '%S.idx' Advanced: Type: Run
Unfortunately, generating indices ready to use by LaTeX
Outside of Kile Class: Compile Source extension: idx
using xindy is a bit more complicated than with makein-
Target extension: ind Target file: <empty> Relative dir:
dex.
<empty> State: Editor Menu: Add tool to Build menu:
First, we need to know in what encoding the .tex project Compile Icon: the one you like
file is saved. In most cases it will be UTF-8 or ISO-8859-
1, though if you live, for example in Poland it may be ISO-
8859-2 or CP-1250. Check the parameter to the inputenc
package. 5.2 Glossary
Second, we need to know which language is prominently
Many technical documents use terms or acronyms un-
used in our document. xindy can natively sort indices
known to the general population. It is common practice
in Albanian, Belarusian, Bulgarian, Croatian, Czech,
to add a glossary to make such documents more accessi-
Danish, Dutch, English, Esperanto, Estonian, Finnish,
ble.
French, Georgian, German, Greek, Gypsy, Hausa, He-
brew, Hungarian, Icelandic, Italian, Klingon, Kurdish, The glossaries package can be used to create glossaries.
Latin, Latvian, Lithuanian, Macedonian, Mongolian, It supports multiple glossaries, acronyms, and symbols.
Norwegian, Polish, Portuguese, Romanian, Russian, Ser- This package replaces the glossary package and can be
bian Slovak, Slovenian, Sorbian, Spanish, Swedish, Turk- used instead of the nomencl package.[1] Users requir-
ish, Ukrainian and Vietnamese, ing a simpler solution should consider hand-coding their
entries by using the description environment, or the
I don't know if other languages have similar problems,
longtabu environment provided by the tabu package.
but with Polish, if your .tex is saved using UTF-8, the
.ind produced by texindy will be encoded in ISO-8859-2
if you use only -L polish. While it’s not a problem for
entries containing polish letters, as LaTeX internally en- 5.2.1 Jump start
codes all letters to plain ASCII, it is for accented letters at
beginning of words, they create new index entry groups, Place \usepackage{glossaries} and \makeglossaries in
if you have, for example an "średnia” entry, you'll get a your preamble (after \usepackage{hyperref} if present).
"Ś" encoded in ISO-8859-2 .ind file. LaTeX doesn't like Then define any number of \newglossaryentry and
if part of the file is in UTF-8 and part is in IS-8859-2. The \newacronym glossary and acronym entries in your
obvious solution (adding -C utf8) doesn't work, texindy preamble (recommended) or before first use in your doc-
stops with ument proper. Finally add a \printglossaries call to locate
the glossaries list within your document structure. Then
ERROR: Could not find file “tex/inputenc/utf8.xdy” pepper your writing with \gls{mylabel} macros (and sim-
error. The fix this, you have to load the definiton style for ilar) to simultaneously insert your predefined text and
the headings using -M switch: build the associated glossary. File processing must now
include a call to makeglossaries followed by at least one
-M lang/polish/utf8 further invocation of latex or pdflatex.
In the end we have to run such command:
texindy -L polish -M lang/polish/utf8 filename.idx
5.2.2 Using glossaries
Additional way to fix this problem is use “iconv” to create
utf8.xdy from latin2.xdy To use the glossaries package, you have to load it explic-
itly:
5.2. GLOSSARY 113

if you wish to use xindy (recommended) for the indexing This will avoid the wrong long plural: Frame per Seconds.
phase, as opposed to makeindex (the default), you need So far, the glossary entries have been defined as key-value
to specify the xindy option: lists. Sometimes, a description is more complex than just
For the glossary to show up in your Table of Contents, a paragraph. For example, you may want to have multiple
you need to specify the toc option: paragraphs, itemized lists, figures, tables, etc. For such
See also Custom Name at the bottom of this page. glossary entries use the command longnewglossaryentry
in which the description follows the key-value list. The
Finally, place the following command in your document computer entry then looks like this:
preamble in order to generate the glossary:
Any links in resulting glossary will not be “clickable” un-
Defining symbols
less you load the glossaries package after the hyperref
package.
Defined entries can also be symbols:
In addition, users who wish to make use of makeglos-
You can also define both a name and a symbol:
saries will need to have Perl installed — this is not nor-
mally present by default on Microsoft Windows plat- Note that not all glossary styles show defined symbols.
forms. That said, makeglossaries simply provides a con-
venient interface to makeindex and xindy and is not es-
Defining acronyms
sential.
To define a new acronym you use the \newacronym
5.2.3 Defining glossary entries macro:
where <label> is the unique label identifying the
To use an entry from a glossary you first need to define it. acronym, <abbrv> is the abbreviated form of the
There are few ways to define an entry depending on what acronym and <full> is the expanded text. For example:
you define and how it is going to be used.
Defined acronyms can be put in separate list if you use
Note that a defined entry won't be included in the printed acronym package option:
glossary unless it is used in the document. This enables
you to create a glossary of general terms and just \include
it in all your documents. 5.2.5 Using defined terms
When you have defined a term, you can use it in a docu-
5.2.4 Defining terms ment. There are many different commands used to refer
to glossary terms.
To define a term in glossary you use the \newglossaryentry
macro:
<label> is a unique label used to identify an entry in glos- General references
sary, <settings> are comma separated key=value pairs
A general reference is used with \gls command. If, for
used to define an entry.
example, you have glossary entries defined as those above,
For example, to define a computer entry: you might use it in this way:
The above example defines an entry that has the same la- Description of commands used in above example:
bel and entry name. This is not always the case as the
next entry will show: This command prints the term associated with <label>
passed as its argument. If the hyperref package was
When you define terms, you need to remember that they loaded before glossaries it will also be hyperlinked to the
will be sorted by makeindex or xindy. While xindy is entry in glossary.
a bit more LaTeX aware, it does it by omitting latex
macros (\"{\i}) thus incorrectly sorting the above exam- This command prints the plural of the defined term, other
than that it behaves in the same way as gls.
ple as nave. makeindex won't fare much better, because it
doesn't understand TeX macros, it will interpret the word This command prints the singular form of the term with
exactly as it was defined, putting it inside symbol class, the first character converted to upper case.
before words beginning with naa. Therefore it’s needed This command prints the plural form with first letter of
to extend our example and specify how to sort the word: the term converted to upper case.
You can also specify plural forms, if they are not formed This command creates the link as usual, but typesets the
by adding “s” (we will learn how to use them in next sec- alternate text instead. It can also take several options
tion): which changes its default behavior (see the documenta-
Or, for acronyms: tion).
114 CHAPTER 5. SPECIAL PAGES

This command prints what ever is defined in \newglos- Syntax: \newdualentry[glossary options][acronym op-
saryentry{<label>}{symbol={Output of glssymbol}, ...} tions]{label}{abbrv}{long}{description}
This command prints what ever is defined in \newglos- then, define new (dual) entries for glossary and acronym
saryentry{<label>}{description={Output of glsdesc}, list like this:
...}

Custom Name
Referring acronyms
The name of the glossary section can be replaced with a
Acronyms behave a bit differently than normal glossary custom name or translated to a different language. Add
terms. On first use the \gls command will display "<full> the option title to \printglossary to specify the glossary’s
(<abbrv>)". On subsequent uses only the abbreviation title. Add the option toctitle to specify a the title used in
will be displayed. the table of content (if not used, title is used as default).
[4]
To reset the first use of an acronym use:
or, if you want to reset the use status of all acronyms:
Remove the point
If you just want to print the long version of an acronym
without the abbreviation "<full>", use :
To omit the dot at the end of each description, use this
If you just want to print the long version of an acronym code:
with the abbreviation "<full> (<abbrv>)", use :
If you just want to print the abbreviation "<abbrv>", use
Changing Glossary Entry Presentation Using Glos-
:
sary Styles

A number of pre-built styles are available, and can be


5.3 Displaying the Glossary changed easily using
Commonly used styles include list
To display the sorted list of terms you need to add:
My Term Has some long description 7, 9
at the place you want the glossary and the list of acronyms
altlist (inserts newline after term and indents description)
to appear.
My Term Has some long description 7, 9
If all entries are to be printed the command
altlistgroup or listgroup (group adds grouping based on
can be inserted before \printglossaries. You may also
the first letters of the terms)
want to use \usepackage[nonumberlist]{glossaries} to
suppress the location list within the glossary. M My First Term Has some long description 7, 9 My
Second Term Has some long description 7, 9
altlisthypergroup or listhypergroup (hyper adds an hyper-
Separate Glossary and List of Acronyms
linked 'index' at the top of each glossary to jump to a
group)
\printglossaries will display all the glossaries in the order
in which they were defined.[2] If no custom glossaries are A|B|C|D|F|G|I|M|O|R|S|C|D|G|M|P A A First term Has
defined, the default glossary and the list of acronyms will some long description 7, 9 B Barely missed first Has
be displayed. some long description 7, 9
The glossary and the list of acronyms can be displayed
separately in different places[3] :
5.3.1 Building your document

Dual entries with reference to a glosssary entry from Building your document and its glossary requires three
an acronym It may be useful to have both an acronym steps:
and a glossary entry for the same term. To link these two,
define the acronym with a reference to the glossary entry 1. build your LaTeX document — this will also gener-
like this: ate the files needed by makeglossaries
Refer to acronym with \gls{OWD} and the glossary with 2. invoke makeglossaries — a script which selects the
\gls{gls-OWD} correct character encodings and language settings
To make this easier, we can use this command (modified and which will also run xindy or makeindex if these
from example in the official docs): are specified in your document file
5.4. EXAMPLE FOR USE IN WINDOWS WITH TEXMAKER 115

3. build your LaTeX document again — to produce a 5.4.3 Glossary definitions


document with glossary entries
Write all your glossaries/acronyms in a file: Ex: INP-00-
Thus: glossary.tex
latex doc makeglossaries doc latex doc \newacronym{ddye}{D$_{\text{dye}}$}{donor
where latex is your usual build call (perhaps pdflatex) and dye, ex. Alexa 488}
doc is the name of your LaTeX master file. \newacronym[description={\glslink{r0}{F\"{o}rster
distance}}]{R0}{$R_{0}$}{F\"{o}rster
If your entries are interlinked (entries themselves link to distance} \newglossaryen-
other entries with \gls calls), you will need to run steps 1 try{r0}{name=\glslink{R0}{\ensuremath{R_{0}}},text=F\"{o}rster
and 2 twice, that is, in the following order: 1, 2, 1, 2, 3. distance,description={F\"{o}rster distance,
If you encounter problems, view the doc.log and doc.glg where 50\% ...}, sort=R} \newglossaryen-
files in a text editor for clues. try{kdeac}{name=\glslink{R0}{\ensuremath{k_{DEAC}}},text=$k_{DE
description={is the rate of deactivation from ... and
emission)}, sort=k}
5.4 Example for use in windows
with Texmaker 5.4.4 Include glossary definitions and print
glossary
5.4.1 Compile glossary with xindy - In
Windows with Texmaker Include glossary definitions in the preamble (Before "\be-
gin{document}")
In TeX Live and since June 2015 in MikTeX xindy is \loadglsentries[main]{INP-00-glossary} % or using
already included. \input: %\input{INP-00-glossary} \begin{document}
There is only one issue with path of the install directory Print glossaries, near end
of MikTeX containing spaces. It can be solved via the
following edit: http://tex.stackexchange.com/questions/ \appendix \bibliographystyle{plainnat} \bibli-
251221/miktex-and-xindy-problems/251801#251801 ography{bibtex} \printindex \printglossaries
\end{document}
You need to restart Texmaker after installation of xindy,
to update PATH references to xindy and Perl binaries.
Then, in Texmaker, go to User -> User Commands -> 5.4.5 References
Edit User Commands.
Choose command 1 [1] http://www.ctan.org/pkg/nomencl

[2] http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/
1. Menuitem = makeglossaries contrib/glossaries/glossaries-user.html#dx1-35001
2. Command = makeglossaries %
[3] http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/
contrib/glossaries/glossaries-user.html#dx1-43001
Now push Alt+Shift+F1and then ->F1
Note, for use with the “use build directory” option of Tex- [4] User Manual for glossaries.sty v4.02 as of 2014.01.13
maker: makeglossaries needs to find the aux file. Thank- http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/
fully, while Texmaker does not help there, the option -d contrib/glossaries/glossaries-user.html#sec:printglossary
<dir> of makeglossaries provides for the subdirectory
case. Hence the Command in this case should be:
• The glossaries documentation, http://tug.ctan.org/
Command = makeglossaries -d build % instead.
tex-archive/macros/latex/contrib/glossaries/

5.4.2 Document preamble • Using LaTeX to Write a PhD Thesis, Nicola L.C. Tal-
bot,
In preample should be included (note, hyperref should
be loaded before the glossaries):
• glossaries FAQ, Nicola L. C. Talbot, glossaries FAQ
\usepackage[nomain,acronym,xindy,toc]{glossaries} %
nomain, if you define glossaries in a file, and you
use \include{INP-00-glossary} \makeglossaries \usepa- • Glossaries, Nomenclature, Lists of Symbols and
ckage[xindy]{imakeidx} \makeindex Acronyms, Nicola L. C. Talbot, link
116 CHAPTER 5. SPECIAL PAGES

5.5 Bibliography Management you want more than nine, then input any two-digit num-
ber, such as '56' which allows up to 99 references.
For any academic/research writing, incorporating ref- Next is the actual reference entry itself. This is pre-
erences into a document is an important task. Fortu- fixed with the \bibitem{cite_key} command. The cite_key
nately, LaTeX has a variety of features that make dealing should be a unique identifier for that particular reference,
with references much simpler, including built-in support and is often some sort of mnemonic consisting of any se-
for citing references. However, a much more powerful quence of letters, numbers and punctuation symbols (al-
and flexible solution is achieved thanks to an auxiliary though not a comma). I often use the surname of the first
tool called BibTeX (which comes bundled as standard author, followed by the last two digits of the year (hence
with LaTeX). Recently, BibTeX has been succeeded by lamport94). If that author has produced more than one
BibLaTeX, a tool configurable within LaTeX syntax. reference for a given year, then I add letters after, 'a', 'b',
BibTeX provides for the storage of all references in an etc. But, you should do whatever works for you. Every-
external, flat-file database. (BibLaTeX uses this same thing after the key is the reference itself. You need to
syntax.) This database can be referenced in any La- type it as you want it to be presented. I have put the dif-
TeX document, and citations made to any record that is ferent parts of the reference, such as author, title, etc.,
contained within the file. This is often more convenient on different lines for readability. These linebreaks are ig-
than embedding them at the end of every document writ- nored by LaTeX. I wanted the title to be in italics, so I
ten; a centralized bibliography source can be linked to as used the \emph{} command to achieve this.
many documents as desired (write once, read many!). Of
course, bibliographies can be split over as many files as
one wishes, so there can be a file containing sources con- 5.5.2 Citations
cerning topic A (a.bib) and another concerning topic B
(b.bib). When writing about topic AB, both of these files To actually cite a given document is very easy. Go to
can be linked into the document (perhaps in addition to the point where you want the citation to appear, and use
sources ab.bib specific to topic AB). the following: \cite{cite_key}, where the cite_key is that
of the bibitem you wish to cite. When LaTeX processes
the document, the citation will be cross-referenced with
the bibitems and replaced with the appropriate number
5.5.1 Embedded system citation. The advantage here, once again, is that LaTeX
looks after the numbering for you. If it were totally man-
If you are writing only one or two documents and aren't ual, then adding or removing a reference would be a real
planning on writing more on the same subject for a chore, as you would have to re-number all the citations by
long time, you might not want to waste time creating a hand.
database of references you are never going to use. In this
case you should consider using the basic and simple bib- Instead of WYSIWYG editors, typesetting systems like
liography support that is embedded within LaTeX. \TeX{} or \LaTeX{} \cite{lamport94} can be used.

LaTeX provides an environment called thebibliography


that you have to use where you want the bibliography;
that usually means at the very end of your document, just Referring more specifically
before the \end{document} command. Here is a practical
example: Sometimes you want to refer to a certain page, figure or
\begin{thebibliography}{9} \bibitem{lamport94} Leslie theorem in a text book. For that you can use the argu-
Lamport, \emph{\LaTeX: a document preparation ments to the \cite command:
system}, Addison Wesley, Massachusetts, 2nd edition, \cite[p.~215]{citation01}
1994. \end{thebibliography}
The argument, “p. 215”, will show up inside the same
OK, so what is going on here? The first thing to notice is brackets. Note the tilde in [p.~215], which replaces the
the establishment of the environment. thebibliography is end-of-sentence spacing with a non-breakable inter-word
a keyword that LaTeX recognizes as everything between space. There are two reasons: end-of-sentence spacing is
the begin and end tags as being data for the bibliogra- too wide, and “p.” should not be separated from the page
phy. The mandatory argument, which I supplied after number.
the begin statement, is telling LaTeX how wide the item
label will be when printed. Note however, that the num-
ber itself is not the parameter, but the number of digits is. Multiple citations
Therefore, I am effectively telling LaTeX that I will only
need reference labels of one character in length, which ul- When a sequence of multiple citations are needed, you
timately means no more than nine references in total. If should use a single \cite{} command. The citations are
5.5. BIBLIOGRAPHY MANAGEMENT 117

then separated by commas. Note that you must not use


spaces between the citations. Here’s an example:
\cite{citation01,citation02,citation03}

The result will then be shown as citations inside the same


brackets.
alpha

Bibliography styles
• Overview of Bibtex-Styles: Filterable list of styles
There are several different ways to format lists of bibli- with preview.
ographic references and the citations to them in the text.
These are called citation styles, and consist of two parts: • Preview of several often used styles
the format of the abbreviated citation (i.e. the marker
that is inserted into the text to identify the entry in the list
of references) and the format of the corresponding entry No cite
in the list of references, which includes full bibliographic
details. If you only want a reference to appear in the bibliography,
but not where it is referenced in the main text, then the
Abbreviated citations can be of two main types: num-
\nocite{} command can be used, for example:
bered or textual. Numbered citations (also known as the
Vancouver referencing system) are numbered consecu- Lamport showed in 1995 something...
tively in order of appearance in the text, and consist in \nocite{lamport95}.
Arabic numerals in parentheses (1), square brackets [1],
superscript1 , or a combination thereof[1] . Textual cita- A special version of the command, \nocite{*}, includes
tions (also known as the Harvard referencing system) use all entries from the database, whether they are referenced
the author surname and (usually) the year as the abbrevi- in the document or not.
ated form of the citation, which is normally fully (Smith
2005) or partially enclosed in parenthesis, as in Smith
(2005). The latter form allows the citation to be inte- Natbib
grated in the sentence it supports.
Below you can see three of the styles available with La- Using the standard LaTeX bibliography support, you will
TeX: see that each reference is numbered and each citation cor-
responds to the numbers. The numeric style of citation is
quite common in scientific writing. In other disciplines,
the author-year style, e.g., (Roberts, 2003), such as Har-
vard is preferred. A discussion about which is best will
not occur here, but a possible way to get such an output
is by the natbib package. In fact, it can supersede La-
TeX’s own citation commands, as Natbib allows the user
to easily switch between Harvard or numeric.
plain The first job is to add the following to your preamble in
order to get LaTeX to use the Natbib package:
\usepackage[options]{natbib}

Also, you need to change the bibliography style file to


be used, so edit the appropriate line at the bottom of the
file so that it reads: \bibliographystyle{plainnat}. Once
done, it is basically a matter of altering the existing \cite
commands to display the type of citation you want.
abbrv

Here are some more often used styles: Customization The main commands simply add a t for
'textual' or p for 'parenthesized', to the basic \cite com-
However, keep in mind that you will need to use the nat- mand. You will also notice how Natbib by default will
bib package to use most of these. compress references with three or more authors to the
More examples can be found here: more concise 1st surname et al version. By adding an
118 CHAPTER 5. SPECIAL PAGES

asterisk (*), you can override this default and list all au- of the file is also quite simple. An example of a BibTeX
thors associated with that citation. There are some other entry:
specialized commands that Natbib supports, listed in the @article{greenwade93, author = “George D. Green-
table here. Keep in mind that for instance abbrvnat does wade”, title = “The {C}omprehensive {T}ex {A}rchive
not support \citet* and will automatically choose between {N}etwork ({CTAN})", year = “1993”, journal =
all authors and et al.. “TUGBoat”, volume = “14”, number = “3”, pages =
The final area that I wish to cover about Natbib is cus- “342-−351” }
tomizing its citation style. There is a command called
\bibpunct that can be used to override the defaults and Each entry begins with the declaration of the reference
change certain settings. For example, I have put the fol- type, in the form of @type. BibTeX knows of practically
lowing in the preamble: all types you can think of, common ones are: book, arti-
\bibpunct{(}{)}{;}{a}{,}{,} cle, and for papers presented at conferences, there is in-
proceedings. In this example, I have referred to an article
The command requires six mandatory parameters. within a journal.
After the type, you must have a left curly brace '{' to sig-
1. The symbol for the opening bracket. nify the beginning of the reference attributes. The first
one follows immediately after the brace, which is the ci-
2. The symbol for the closing bracket. tation key, or the BibTeX key. This key must be unique
for all entries in your bibliography. It is this identifier that
3. The symbol that appears between multiple citations. you will use within your document to cross-reference it to
this entry. It is up to you as to how you wish to label each
4. This argument takes a letter:
reference, but there is a loose standard in which you use
• n - numerical style. the author’s surname, followed by the year of publication.
This is the scheme that I use in this tutorial.
• s - numerical superscript style.
Next, it should be clear that what follows are the rele-
• any other letter - author-year style.
vant fields and data for that particular reference. The
5. The punctuation to appear between the author and field names on the left are BibTeX keywords. They are
the year (in parenthetical case only). followed by an equals sign (=) where the value for that
field is then placed. BibTeX expects you to explicitly la-
6. The punctuation used between years, in multiple ci- bel the beginning and end of each value. I personally use
tations when there is a common author. e.g., (Chom- quotation marks ("), however, you also have the option
sky 1956, 1957). If you want an extra space, then of using curly braces ('{', '}'). But as you will soon see,
you need {,~}. curly braces have other roles, within attributes, so I prefer
not to use them for this job as they can get more confus-
Some of the options controlled by \bibpunct are also ac- ing. A notable exception is when you want to use char-
cessible by passing options to the natbib package when it acters with umlauts (ü, ö, etc), since their notation is in
is loaded. These options also allow some other aspect of the format \"{o}, and the quotation mark will close the
the bibliography to be controlled, and can be seen in the one opening the field, causing an error in the parsing of
table (right). the reference. Using \usepackage[utf8]{inputenc} in the
preamble to the .tex source file can get round this, as the
So as you can see, this package is quite flexible, especially accented characters can just be stored in the .bib file with-
as you can easily switch between different citation styles out any need for special markup. This allows a consistent
by changing a single parameter. Do have a look at the format to be kept throughout the .bib file, avoiding the
Natbib manual, it’s a short document and you can learn need to use braces when there are umlauts to consider.
even more about how to use it.
Remember that each attribute must be followed by a
comma to delimit one from another. You do not need to
5.5.3 BibTeX add a comma to the last attribute, since the closing brace
will tell BibTeX that there are no more attributes for this
I have previously introduced the idea of embedding ref- entry, although you won't get an error if you do.
erences at the end of the document, and then using the It can take a while to learn what the reference types are,
\cite command to cite them within the text. In this tuto- and what fields each type has available (and which ones
rial, I want to do a little better than this method, as it’s are required or optional, etc). So, look at this entry type
not as flexible as it could be. I will concentrate on using reference and also this field reference for descriptions of
BibTeX. all the fields. It may be worth bookmarking or printing
A BibTeX database is stored as a .bib file. It is a plain text these pages so that they are easily at hand when you need
file, and so can be viewed and edited easily. The structure them. Much of the information contained therein is re-
5.5. BIBLIOGRAPHY MANAGEMENT 119

peated in the following table for your convenience. @book A published book
+ Required fields, O Optional fields • Required fields: author/editor, title, publisher,
year.
Authors • Optional fields: volume/number, series, ad-
dress, edition, month, note.
BibTeX can be quite clever with names of authors. It
can accept names in forename surname or surname, fore- @book{Xbook, author = "", title = "", publisher = "",
name. I personally use the former, but remember that %volume = "", %number = "", %series = "", %address =
the order you input them (or any data within an entry for "", %edition = "", year = “XXXX”, %month = "", %note
that matter) is customizable and so you can get BibTeX = "", }
to manipulate the input and then output it however you
like. If you use the forename surname method, then you
must be careful with a few special names, where there @booklet A bound work without a named publisher or
are compound surnames, for example “John von Neu- sponsor.
mann”. In this form, BibTeX assumes that the last word
is the surname, and everything before is the forename, • Required fields: title.
plus any middle names. You must therefore manually tell • Optional fields: author, howpublished, ad-
BibTeX to keep the 'von' and 'Neumann' together. This dress, month, year, note.
is achieved easily using curly braces. So the final result
would be “John {von Neumann}". This is easily avoided @booklet{Xbooklet, %author = "", title = "", %howpub-
with the surname, forename, since you have a comma to lished = "", %address = "", %year = “XXXX”, %month
separate the surname from the forename. = "", %note = "", }
Secondly, there is the issue of how to tell BibTeX when a
reference has more than one author. This is very simply
done by putting the keyword and in between every author. @conference Equal to inproceedings
As we can see from another example:
• Required fields: author, title, booktitle, year.
@book{goossens93, author = “Michel Goossens and • Optional fields: editor, volume/number, se-
Frank Mittelbach and Alexander Samarin”, title = ries, pages, address, month, organization, pub-
“The LaTeX Companion”, year = “1993”, publisher = lisher, note.
“Addison-Wesley”, address = “Reading, Massachusetts”
}
@conference{Xconference, author = "", title = "",
booktitle = "", %editor = "", %volume = "", %number
This book has three authors, and each is separated as de- = "", %series = "", %pages = "", %address = "", year
scribed. Of course, when BibTeX processes and outputs = “XXXX”, %month = "", %publisher= "", %note = "", }
this, there will only be an 'and' between the penultimate
and last authors, but within the .bib file, it needs the ands
so that it can keep track of the individual authors. @inbook A section of a book without its own title.
• Required fields: author/editor, title, chapter
Standard templates and/or pages, publisher, year.
• Optional fields: volume/number, series, type,
Be careful if you copy the following templates, the % sign
address, edition, month, note.
is not valid to comment out lines in bibtex files. If you
want to comment out a line, you have to put it outside the
@inbook{Xinbook, author = "", editor = "", title = "",
entry.
chapter = "", pages = "", publisher= "", %volume = "",
%number = "", %series = "", %type = "", %address= "",
@article An article from a magazine or a journal. %edition= "", year = "", %month = "", %note = "", }
• Required fields: author, title, journal, year.
• Optional fields: volume, number, pages, @incollection A section of a book having its own title.
month, note.
• Required fields: author, title, booktitle, pub-
@article{Xarticle, author = "", title = "", journal = "", lisher, year.
%volume = "", %number = "", %pages = "", year = • Optional fields: editor, volume/number, se-
“XXXX”, %month = "", %note = "", } ries, type, chapter, pages, address, edition,
month, note.
120 CHAPTER 5. SPECIAL PAGES

@incollection{Xincollection, author = "", title = "", • Optional fields: address, month, keywords,
booktitle= "", publisher= "", %editor = "", %volume = note.
"", %number = "", %series = "", %type = "", %chapter=
"", %pages = "", %address= "", %edition= "", year = "", @phdthesis{Xphdthesis, author = "", title = "", school =
%month = "", %note = "", } "", %address = "", year = "", %month = "", %keywords
= "", %note = "", }

@inproceedings An article in a conference proceed-


ings.
@proceedings The proceedings of a conference.
• Required fields: author, title, booktitle, year.
• Required fields: title, year.
• Optional fields: editor, volume/number, se-
ries, pages, address, month, organization, pub- • Optional fields: editor, volume/number, se-
lisher, note. ries, address, month, organization, publisher,
note.
@inproceedings{Xinproceedings, author = "", title
= "", booktitle = "", %editor = "", %volume = "", @proceedings{Xproceedings, title = "", %editor = "",
%number = "", %series = "", %pages = "", %address %volume = "", %number = "", %series = "", %address
= "", %organization = "", %publisher = "", year = "", = "", %organization = "", %publisher = "", year = "",
%month = "", %note = "", } %month = "", %note = "", }

@manual Technical manual @techreport Technical report from educational, com-


mercial or standardization institution.
• Required fields: title.
• Optional fields: author, organization, address, • Required fields: author, title, institution, year.
edition, month, year, note.
• Optional fields: type, number, address, month,
@manual{Xmanual, title = "", %author = "", %organi- note.
zation = "", %address = "", %edition = "", year = "",
%month = "", %note = "", } @techreport{Xtreport, author = "", title = "", institution
= "", %type = "", %number = "", %address = "", year =
“XXXX”, %month = "", %note = "", }
@mastersthesis Master’s thesis

• Required fields: author, title, school, year. @unpublished An unpublished article, book, thesis,
• Optional fields: type (eg. “diploma thesis”), etc.
address, month, note.
• Required fields: author, title, note.
@mastersthesis{Xthesis, author = "", title = "", school
• Optional fields: month, year.
= "", %type = “diploma thesis”, %address = "", year =
“XXXX”, %month = "", %note = "", }
@unpublished{Xunpublished, author = "", title = "",
%year = "", %month = "", note = "", }
@misc Template useful for other kinds of publication

• Required fields: none


• Optional fields: author, title, howpublished, Not standard templates
month, year, note.
@patent BiBTeX entries can be exported from Google
@misc{Xmisc, %author = "", %title = "", %howpub- Patents.
lished = "", %year = “XXXX”, %month = "", %note =
"", } (see Cite Patents with Bibtex for an alternative)

@collection
@phdthesis Ph.D. thesis

• Required fields: author, title, year, school. @electronic


5.5. BIBLIOGRAPHY MANAGEMENT 121

Preserving case of letters W. and Kutter, Elizabeth and Carlson, Karin and Miller,
Eric S. and Spicer, Eleanor”, publisher = “ASM Press,
In the event that BibTeX has been set by the chosen style Washington DC”, year = “1994” },
to not preserve all capitalization within titles, problems
can occur, especially if you are referring to proper nouns,
If you have to cite a website you can use @misc, for ex-
or acronyms. To tell BibTeX to keep them, use the good
ample:
old curly braces around the letter in question, (or letters,
if it’s an acronym) and all will be well! It is even possible @misc{website:fermentas-lambda, author = “Fermentas
that lower-case letters may need to be preserved - for ex- Inc.”, title = “Phage Lambda: description \& restriction
ample if a chemical formula is used in a style that sets a map”, month = “November”, year = “2008”, url =
title in all caps or small caps, or if “pH” is to be used in a "http://www.fermentas.com/techinfo/nucleicacids/
style that capitalises all first letters. maplambda.htm" },

title = “The {LaTeX} Companion”, The note field comes in handy if you need to add unstruc-
tured information, for example that the corresponding is-
However, avoid putting the whole title in curly braces, as sue of the journal has yet to appear:
it will look odd if a different capitalization format is used: @article{blackholes, author="Rabbert Klein”, ti-
tle="Black Holes and Their Relation to Hiding Eggs”,
title = "{The LaTeX Companion}", journal="Theoretical Easter Physics”, publisher="Eggs
Ltd.”, year="2010”, note="(to appear)" }
For convenience though, many people simply put double
curly braces, which may help when writing scientific ar-
ticles for different magazines, conferences with different
BibTex styles that do sometimes keep and sometimes not Getting current LaTeX document to use your .bib file
keep the capital letters:
At the end of your LaTeX file (that is, after the content,
title = {{The LaTeX Companion}}, but before \end{document}), you need to place the fol-
lowing commands:
As an alternative, try other BibTex styles or modify the \bibliographystyle{plain} \bibliogra-
existing. The approach of putting only relevant text in phy{sample1,sample2,...,samplen} % Note the lack
curly brackets is the most feasible if using a template un- of whitespace between the commas and the next bib file.
der the control of a publisher, such as for journal submis-
sions. Using curly braces around single letters is also to
Bibliography styles are files recognized by BibTeX that
be avoided if possible, as it may mess up the kerning, es-
tell it how to format the information stored in the .bib file
pecially with biblatex,[1] so the first step should generally
when processed for output. And so the first command
be to enclose single words in braces. listed above is declaring which style file to use. The style
file in this instance is plain.bst (which comes as standard
with BibTeX). You do not need to add the .bst extension
A few additional examples
when using this command, as it is assumed. Despite its
name, the plain style does a pretty good job (look at the
Below you will find a few additional examples of bibliog-
raphy entries. The first one covers the case of multiple output of this tutorial to see what I mean).
authors in the Surname, Firstname format, and the sec- The second command is the one that actually specifies
ond one deals with the incollection case. the .bib file you wish to use. The ones I created for this
@article{AbedonHymanThomas2003, author = tutorial were called sample1.bib, sample2.bib, . . ., sam-
“Abedon, S. T. and Hyman, P. and Thomas, C.”, plen.bib, but once again, you don't include the file ex-
year = “2003”, title = “Experimental examination of tension. At the moment, the .bib file is in the same di-
bacteriophage latent-period evolution as a response rectory as the LaTeX document too. However, if your
to bacterial availability”, journal = “Applied and En- .bib file was elsewhere (which makes sense if you in-
vironmental Microbiology”, volume = “69”, pages = tend to maintain a centralized database of references
“7499-−7506” }, @incollection{Abedon1994, author for all your research), you need to specify the path as
= “Abedon, S. T.”, title = “Lysis and the interaction well, e.g \bibliography{/some/where/sample} or \bibli-
between free phages and infected cells”, pages = “397- ography{../sample1} (if the .bib file is in the parent di-
−405”, booktitle = “Molecular biology of bacteriophage rectory of the .tex document that calls it).
T4”, editor = “Karam, Jim D. Karam and Drake, John Now that LaTeX and BibTeX know where to look for the
W. and Kreuzer, Kenneth N. and Mosig, Gisela and Hall, appropriate files, actually citing the references is fairly
Dwight and Eiserling, Frederick A. and Black, Lindsay trivial. The \cite{ref_key} is the command you need,
122 CHAPTER 5. SPECIAL PAGES

making sure that the ref_key corresponds exactly to one (Extensions are optional, if you put them note that the
of the entries in the .bib file. If you wish to cite more bibtex command takes the AUX file as input.)
than one reference at the same time, do the following: Note that if you are editing your source in vim and at-
\cite{ref_key1, ref_key2, ..., ref_keyN}. tempt to use command mode and the current file shortcut
(%) to process the document like this:
Why won't LaTeX generate any output?
1. :! pdflatex %
The addition of BibTeX adds extra complexity for the
processing of the source to the desired output. This is 2. :! bibtex %
largely hidden from the user, but because of all the com-
plexity of the referencing of citations from your source You will get an error similar to this:
LaTeX file to the database entries in another file, you ac-
tually need multiple passes to accomplish the task. This 1. I couldn't open file name 'current_file.tex.aux'
means you have to run LaTeX a number of times. Each
pass will perform a particular task until it has managed to It appears that the file extension is included by default
resolve all the citation references. Here’s what you need when the current file command (%) is executed. To pro-
to type (into command line): cess your document from within vim, you must explicitly
name the file without the file extension for bibtex to work,
1. latex latex_source_code.tex as is shown below:
2. bibtex latex_source_code.aux
1. :! pdflatex %
3. latex latex_source_code.tex
2. :! bibtex %:r (without file extension, it looks for the
4. latex latex_source_code.tex AUX file as mentioned above)
3. :! pdflatex %
(Extensions are optional, if you put them note that the
bibtex command takes the AUX file as input.) 4. :! pdflatex %
After the first LaTeX run, you will see errors such as:
However, it is much easier to install the Vim-LaTeX plu-
LaTeX Warning: Citation `lamport94' on page 1 unde-
gin from here. This allows you to simply type \ll when
fined on input line 21. ... LaTeX Warning: There were
not in insert mode, and all the appropriate commands are
undefined references.
automatically executed to compile the document. Vim-
The next step is to run bibtex on that same LaTeX source LaTeX even detects how many times it has to run pdfla-
(or more precisely the corresponding AUX file, however tex, and whether or not it has to run bibtex. This is just
not on the actual .bib file) to then define all the references one of the many nice features of Vim-LaTeX, you can
within that document. You should see output like the fol- read the excellent Beginner’s Tutorial for more about the
lowing: many clever shortcuts Vim-LaTeX provides.
This is BibTeX, Version 0.99c (Web2C 7.3.1) The top- Another option exists if you are running Unix/Linux or
level auxiliary file: latex_source_code.aux The style file: any other platform where you have make. Then you can
plain.bst Database file #1: sample.bib simply create a Makefile and use vim’s make command
The third step, which is invoking LaTeX for the second or use make in shell. The Makefile would then look like
time will see more errors like “LaTeX Warning: Label(s) this:
may have changed. Rerun to get cross-references right.”. latex_source_code.pdf: latex_source_code.tex la-
Don't be alarmed, it’s almost complete. As you can guess, tex_source_code.bib pdflatex latex_source_code.tex
all you have to do is follow its instructions, and run LaTeX bibtex latex_source_code.aux pdflatex la-
for the third time, and the document will be output as tex_source_code.tex pdflatex latex_source_code.tex
expected, without further problems.
If you want a pdf output instead of a dvi output you can Including URLs in bibliography
use pdflatex instead of latex as follows:
As you can see, there is no field for URLs. One possibility
1. pdflatex latex_source_code.tex is to include Internet addresses in howpublished field of
@misc or note field of @techreport, @article, @book:
2. bibtex latex_source_code.aux
howpublished = "\url{http://www.example.com}"
3. pdflatex latex_source_code.tex
Note the usage of \url command to ensure proper appear-
4. pdflatex latex_source_code.tex ance of URLs.
5.5. BIBLIOGRAPHY MANAGEMENT 123

Another way is to use special field url and make bibliog- applied to a LaTeX document.
raphy style recognise it. If you are using a custom built .bst file, it is important
url = "http://www.example.com" that LaTeX can find it! So, make sure it’s in the same
You need to use \usepackage{url} in the first case or directory as the LaTeX source file, unless you are using
one of the standard style files (such as plain or plainnat,
\usepackage{hyperref} in the second case.
that come bundled with LaTeX - these will be automati-
Styles provided by Natbib (see below) handle this field, cally found in the directories that they are installed. Also,
other styles can be modified using urlbst program. Modi- make sure the name of the .bst file you want to use is
fications of three standard styles (plain, abbrv and alpha) reflected in the \bibliographystyle{style} command (but
are provided with urlbst. don't include the .bst extension!).
If you need more help about URLs in bibliography, visit
FAQ of UK List of TeX. Localizing bibliography appearance

When writing documents in languages other than English,


Customizing bibliography appearance you may find it desirable to adapt the appearance of your
bibliography to the document language. This concerns
One of the main advantages of BibTeX, especially for words such as editors, and, or in as well as a proper typo-
people who write many research papers, is the ability to graphic layout. The babelbib package can be used here.
customize your bibliography to suit the requirements of For example, to layout the bibliography in German, add
a given publication. You will notice how different pub- the following to the header:
lications tend to have their own style of formatting ref- \usepackage[fixlanguage]{babelbib} \selectbiblan-
erences, to which authors must adhere if they want their guage{german}
manuscripts published. In fact, established journals and
conference organizers often will have created their own
bibliography style (.bst file) for those users of BibTeX, to Alternatively, you can layout each bibliography entry ac-
do all the hard work for you. cording to the language of the cited document:
It can achieve this because of the nature of the .bib \usepackage{babelbib}
database, where all the information about your references
is stored in a structured format, but nothing about style. The language of an entry is specified as an additional field
This is a common theme in LaTeX in general, where it in the BibTeX entry:
tries as much as possible to keep content and presenta-
tion separate. @article{mueller08, % ... language = {german} }

A bibliography style file (.bst) will tell LaTeX how to for-


mat each attribute, what order to put them in, what punc- For babelbib to take effect, a bibliography style supported
tuation to use in between particular attributes etc. Unfor- by it - one of babplain, babplai3, babalpha, babunsrt,
tunately, creating such a style by hand is not a trivial task. bababbrv, and bababbr3 - must be used:
Which is why Makebst (also known as custom-bib) is the \bibliographystyle{babplain} \bibliography{sample}
tool we need.
Makebst can be used to automatically generate a .bst file
based on your needs. It is very simple, and actually asks Showing unused items
you a series of questions about your preferences. Once
complete, it will then output the appropriate style file for Usually LaTeX only displays the entries which are re-
you to use. ferred to with \cite. It’s possible to make uncited entries
It should be installed with the LaTeX distribution (other- visible:
wise, you can download it) and it’s very simple to initiate. \nocite{Name89} % Show Bibliography entry of
At the command line, type: Name89 \nocite{*} % Show all Bib-entries
latex makebst
LaTeX will find the relevant file and the questioning pro-
cess will begin. You will have to answer quite a few (al- Getting bibliographic data
though, note that the default answers are pretty sensible),
which means it would be impractical to go through an Many online databases provide bibliographic data in
example in this tutorial. However, it is fairly straight- BibTeX-Format, making it easy to build your own
forward. And if you require further guidance, then there database. For example, Google Scholar offers the op-
is a comprehensive manual available. I'd recommend ex- tion to return properly formatted output, which can also
perimenting with it and seeing what the results are when be turned on in the settings page.
124 CHAPTER 5. SPECIAL PAGES

One should be alert to the fact that bibliographic • BibSonomy — A free social bookmark and publica-
databases are frequently the product of several genera- tion management system based on BibTeX.
tions of automatic processing, and so the resulting Bib-
Tex code is prone to a variety of minor errors, especially • BibTeXSearch BibTeXSearch is a free searchable
in older entries. BibTeX database spanning millions of academic
records.

Helpful tools • Bibtex Editor - An online BibTeX entry generator


and bibliography management system. Possible to
import and export Bibtex files.

• Bibwiki Bibwiki is a Specialpage for MediaWiki to


manage BibTeX bibliographies. It offers a straight-
forward way to import and export bibliographic
records.

• cb2Bib The cb2Bib is a tool for rapidly extracting


unformatted, or unstandardized bibliographic ref-
erences from email alerts, journal Web pages, and
PDF files.

Literatur-Generator • Citavi Commercial software (with size-limited free


demo version) which even searches libraries for ci-
tations and keeps all your knowledge in a database.
Export of the database to all kinds of formats is
possible. Works together with MS Word and Open
Office Writer. Moreover plug ins for browsers and
Acrobat Reader exist to automatically include refer-
ences to your project.

• CiteULike CiteULike is a free online service to or-


ganise academic papers. It can export citations in
BibTeX format, and can “scrape” BibTeX data from
many popular websites.

• DokuWiki Bibtex is a DokuWiki plugin that allows


for the inclusion of bibtex formatted citations in
DokuWiki pages and displays them in APA format.
JabRef Note: This Plugins is vulnerable to an XSS attack ->
http://www.dokuwiki.org/plugin:bibtex

• Ebib — a BibTeX database manager for Emacs, well


resolved and never more than a few keystrokes away.

• JabRef is a Java program (under the GPL license)


which lets you search many bibliographic databases
such as Medline, Citeseer, IEEEXplore and arXiv
and feed and manage your BibTeX local databases
with your selected articles. Based on BiBTeX,
JabRef can export in many other output formats
such as html, MS Word or EndNote. It can be
used online without being installed (http://jabref.
sourceforge.net/jws/jabref.jnlp)
BibDesk
• KBib Another BibTeX editor for KDE. It has simi-
lar capabilities, and slightly different UI. Features
• BibDesk BibDesk is a bibliographic reference man- include BibTeX reference generation from PDF
ager for Mac OS X. It features a very usable user in- files, plain text, DOI, arXiv & PubMed IDs. Web
terface and provides a number of features like smart queries to Google Scholar, PubMer, arXiv and a
folders based on keywords and live tex display. number of other services are also supported.
5.5. BIBLIOGRAPHY MANAGEMENT 125

• KBibTeX KBibTeX is a BibTeX editor for KDE to information \end{thebibliography}


edit bibliographies used with LaTeX. Features in-
clude comfortable input masks, starting web queries Or, if you are using BibTeX, your references will be saved
(e. g. Google or PubMed) and exporting to PDF, in a .bib file, and your TeX document will include the
PostScript, RTF and XML/HTML. As KBibTeX is bibliography by these commands:
using KDE’s KParts technology, KBibTeX can be
embedded into Kile or Konqueror. \bibliographystyle{plain} \bibliography{mybibtexfile}

• Literatur-Generator is a German-language online


Both of these examples will create a chapter-like (or
tool for creating a bibliography (Bibtex, Endnote,
section-like) output showing all your references. But even
Din 1505, ...).
though the resulting “References” looks like a chapter or
• Mendeley Mendeley is cost-free academic software section, it will not be handled quite the same: it will not
for managing PDFs which can manage a bibliogra- appear in the Table of Contents.
phy in Open Office and read BibTeX.

• Qiqqa Qiqqa is a free research manager that has Using tocbibind


built-in support for automatically associating Bib-
TeX records with your PDFs and a 'BibTeX Snif- The most comfortable way of adding your bibliography
fer' for helping you semi-automatically find BibTeX to the table of contents is to use the dedicated pack-
records. age tocbibind that works with many standard document
classes. Simply include this code in the preamble of your
• Referencer Referencer is a Gnome application to or- document:
ganise documents or references, and ultimately gen-
\usepackage[nottoc]{tocbibind}
erate a BibTeX bibliography file.

• Synapsen — Hypertextual Card Index / Reference This will include the Bibliography in the Table of Con-
Manager with special support for BiBTeX / biblatex, tents without numbering. If you want to have proper
written in Java. numbering, include the following code in the preamble:
• Zotero Zotero is a free and open reference manager \usepackage[nottoc,numbib]{tocbibind}
working as a Firefox plugin or standalone applica-
tion, capable of importing and exporting bib files. The tocbibind package can also handle including the List
of Figures, List of Tables and the Table of Contents itself
Summary in the Table of Contents. It has many options for num-
bering, document structure etc. to fit almost any scenario.
Although it can take a little time to get to grips with Bib- See the tocbibind CTAN page for detailed documenta-
TeX, in the long term, it’s an efficient way to handle your tion.
references. It’s not uncommon to find .bib files on web-
sites that people compile as a list of their own publica-
Other methods
tions, or a survey of relevant works within a given topic,
etc. Or in those huge, online bibliography databases, you As unnumbered item If you want your bibliography
often find BibTeX versions of publications, so it’s a quick to be in the table of contents, just add the following two
cut-and-paste into your own .bib file, and then no more lines just before the thebibliography environment:
hassle!
\clearpage% or cleardoublepage \addcon-
Having all your references in one place can be a big ad- tentsline{toc}{chapter}{Bibliography}
vantage. And having them in a structured form, that al-
lows customizable output is another one. There are a vari-
ety of free utilities that can load your .bib files, and allow (OR \addcontentsline{toc}{section}{Bibliography} if
you to view them in a more efficient manner, as well as you're writing an article)
sort them and check for errors. The first line just terminates the current paragraph and
page. If you are writing a book, use \cleardoublepage to
match the style used. The second line will add a line in
5.5.4 Bibliography in the table of contents the Table of Contents (first option, toc), it will be like the
ones created by chapters (second option, chapter), and
If you are writing a book or report, you'll likely insert your the third argument will be printed on the corresponding
bibliography using something like: line in the Table of Contents; here Bibliography was cho-
\begin{thebibliography}{99} \bibitem{bib:one_book} sen because it’s the same text the thebibliography environ-
some information \bibitem{bib:one_article} other ment will automatically write when you use it, but you are
126 CHAPTER 5. SPECIAL PAGES

free to write whatever you like. If you are using separate database) that can be used in a document. For now, refer
bib file, add these lines between \bibliographystyle and to its comprehensive documentation on CTAN.
\bibliography.
If you use hyperref package, you should also use \phan- Entry and field types in .bib files
tomsection command to enable hyperlinking from the ta-
ble of contents to bibliography. The following table shows most field types. Some field
\clearpage% or cleardoublepage \phantomsection \add- types are lists, either lists of person names, others are
contentsline{toc}{chapter}{Bibliography} literal lists. A date can either be given in parts or full,
some keys are necessary, page references are provided as
ranges and certain special fields contain verbatim code.
This trick is particularly useful when you have to insert There are many kinds of titles.
the bibliography in the Table of Contents, but it can work
for anything. When LaTeX finds the code above, it will Some entry types are hard to distinguish and are treated
record the info as described and the current page number, the same by standard styles:
inserting a new line in the Contents page.
• @article is the same as hypothetic *@inperiodical
and therefore encompasses existing @suppperiodi-
As numbered item If you instead want bibliography cal
to be numbered section or chapter, you'll likely use this
• @inbook = @bookinbook = @suppbook
way:
\cleardoublepage % This is needed if the book class • @collection = @reference
is used, to place the anchor in the correct page, % • @mvcollection = @mvreference
because the bibliography will start on its own page. %
Use \clearpage instead if the document class uses the • @incollection = @suppcollection = @inreference
“oneside” argument \renewcommand*{\refname}{} %
• @online = @electronic = @www
This will define heading of bibliography to be empty, so
you can... \section{Bibliography} % ...place a normal • @report = @techreport
section heading before the bibliography entries. \be-
gin{thebibliography}{99} ... \end{thebibliography} • @thesis = @mastersthesis = @phdthesis

Some field types are defined, but the documentation does


Another even easier solution is to use \section inside of not say which entry types they can be used with. This
the \renewcommand block: is either because they depend on another field being set
\renewcommand{\refname}{\section{Sources}} % to be useful or they can always be used in a user-defined
Using “Sources” as the title of the section \be- manner, but will never be used in standard styles:
gin{thebibliography}{99} ... \end{thebibliography}
• abstract, annotation
You may wish to use • entrysubtype
\renewcommand*{\refname}{\vspace*{−1em}}
followed by \vspace*{−1em} to counteract the extra • file
space the blank \refname inserts. • label
If you are using BibTeX, the \bibliography command,
• library
and the book or report class, you will need to redefine
\bibname instead of \refname like so. • nameaddon
\renewcommand{\bibname}{\section{Sources}} % Re- • origdate, origlocation, origpublisher
define bibname \bibliographystyle{IEEEtran} % Set any
options you want \bibliography{your_bib_file_names} • origtitle, reprinttitle, indextitle
% Build the bibliography • pagination, bookpagination
• shortauthor, shorteditor, shorthand, shorthandintro,
shortjournal, shortseries shorttitle
5.5.5 biblatex
The only field that is always mandatory, is title. All en-
As we said before, biblatex is widely considered the `suc- try types also require either date or year and they specify
cessor' of BibTeX. Intended as a full replacement for Bib- which of author and editor they expect or whether they
TeX, it is more configurable in its output and provides a can use both. Some field types can optionally be used
multitude of new styles (for output) and fields (for the with any entry type:
5.5. BIBLIOGRAPHY MANAGEMENT 127

• addendum, note Printing separate bibliographies We want to sepa-


rate the bibliography into papers, books and others
• language
If the bib entries are located in multiple files we can add
• pubstate them like this:
• urldate We can also filter on other fields, such as entrysubtype. If
we define our online resources like this:
All physical (print) entry types share further optional field
we filter with \printbibliography[title={Online re-
types:
sources}, subtype=inet]
• url, doi
• eprint, eprintclass, eprinttype Example with prefix keys, subheadings and table of
contents As the numbering of the bibliographies are
Multimedia entry types independent, it can be useful to also separate the bibli-
ographies using prefixnumbers such as a, b and c. In ad-
• @artwork dition we add a main heading for the bibliographies and
• @audio add that to the table of contents.
To make Hyperref links point to the correct bibliography
• @image
section, we also add \phantomsection before printing each
• @movie bibliography

• @music To add each of the bibliographies to the table of contents


as sub-sections to the main Bibliography, replace head-
• @performance ing=subbibliography with heading=subbibintoc.
• @video
• @software
5.5.6 Multiple bibliographies
and legal entry types
Using multibib
• @commentary
This package is for multiple Bibliographies for different
• @jurisdiction sections in your work. For example, you can generate a
• @legislation bibliography for each chapter. You can find information
about the package on CTAN[2]
• @legal
• @letter
Using bibtopic
• @review
• @standard The bibtopic-Package[3] is created to differ the citations
on more files, so that you can divide the bibliography into
are defined, but not yet supported (well). more parts.
The entry types @bibnote, @set and @xdata are special. \documentclass[11pt]{article} \usepackage{bibtopic}
\begin{document} \bibliographystyle{alpha}
\section{Testing} Let’s cite all the books:
Printing bibliography \cite{ColBenh:93} and \cite{Munt:93}; and an ar-
ticle: \cite{RouxSmart:95}. File books.bib is used for
Presuming we have defined our references in a file called this listing: \begin{btSect}{books} \section{References
references.bib, we add this to biblatex by adding the fol- from books} \btPrintCited \end{btSect} Here, the arti-
lowing to the preamble: cles.bib is used, and the listing is in plain-format instead
\addbibresource{references.bib} of the standard alpha. \begin{btSect}[plain]{articles}
\section{References from articles} \btPrintCited \sec-
tion{Articles not cited} \btPrintNotCited \end{btSect}
Print the bibiography with this macro (usually at the end Just print all entries here with \btPrintAll \be-
of the document body): gin{btSect}[plain]{internet} \section{References from
\printbibliography the internet} \btPrintAll \end{btSect} \end{document}
128 CHAPTER 5. SPECIAL PAGES

5.5.7 Notes and references • abbrvnat

[1] The biblatex manual • unsrtnat

[2] http://ctan.org/pkg/multibib
which correspond to the three styles available by default
[3] http://ctan.org/pkg/bibtopic in BibTeX where you have a plain numbered style, an
abbreviated numbered style and an unsorted numbered
style.
This page uses material from Andy Roberts’ Getting to grips
with LaTeX with permission from the author. Alongside these new styles is an extended set of citation
commands to provide flexible citation formats. These are
\citet[]{}
5.6 More Bibliographies
and
This is a gentle introduction to using some of the bib-
liography functionality available to LaTeX users beyond \citep[]{}
the BibTeX basics. This introduction won't be discussing
how to create new styles or packages but rather how to each of which has a number of variants.
use some existing ones. It is worth noting that Harvard,
for example, is a citation style. It is associated with an al-
phabetical reference list secondarily ordered on date, but The Preamble
the only strictly defined element of Harvard style is the
citation in author-date format. All Natbib styles require that you load the package in your
document preamble. So, a skeleton LaTeX file with Nat-
bib might look like this:
5.6.1 The example data \documentclass[]{article} \usepackage[round]{natbib}
\begin{document} Document body text with citations.
The database used for my examples contains just the fol- \bibliographystyle{plainnat} \bibliography{myrefs}
lowing \end{document}
@article{Erdos65, title = {Some very hard sums}, jour-
nal={Difficult Maths Today}, author={Paul Erd\H{o}s
and Arend Heyting and Luitzen Egbertus Brouwer},
year={1930}, pages={30} } Options Options available with Natbib can be specified
in the brackets on the \usepackage command. Among
them are:
Clearly some of these options require explanation but that
5.6.2 The limits of BibTeX styles will be achieved via examples below. For now, we just
note that they can be passed through \usepackage[]{} in
Using cite.sty and BibTeX makes it very easy to produce the preamble of your LaTeX file.
some bibliography styles. But author-date styles - for ex-
ample the often mentioned, never defined “Harvard” - are
not so easy. It’s true that you can download some .bst 5.6.4 Citation
files from CTAN that will handle some variants but using
them is not always straightforward. This guide deals with Basic Citation Commands
Natbib a supplementary package that can access .bib files
and has sophisticated functionality for producing custom To cite with Natbib, use the commands \citet or \citep in
or default author-year format citations and bibliographies your document. The “plain” versions of these commands
as well as the numerical styles handled by BibTeX. produced abbreviated lists in the case of multiple authors
but both have * variants which result in full author listings.
We assume the use of the round option in these examples.
5.6.3 Natbib
Natbib is a package created by Patrick Daly as a replace- \citet and \citet* The \citet command is used for tex-
ment for the cite.sty package when author-date citation tual citations, that is to say that author names appear in
styles are required. Natbib provides three associated bib- the text outside of the parenthetical reference to the date
liography styles: of publication. This command can take options for chap-
ter, page numbers etc. Here are examples
• plainnat Here are the \citet* versions
5.6. MORE BIBLIOGRAPHIES 129

\citep and \citep* The \citep command is used where


the author name is to appear inside the parentheses along-
side the date.
Here are the \citep* versions

The Reference List

Having dealt with basic varieties of citation, we turn to


the creation of the bibliography or reference list.
Inserting a correct and correctly formatted bibliography
when using Natbib is no different than when using plain
BibTeX. There are two essential commands -
\bibliography{mybibliographydatabase}

which LaTeX interprets as an instruction to read a bibli-


ographic database file (eg myrefs.bib) and insert the rel-
evant data here, and
\bibliographystyle{plainnat}

which specifies how the data are to be presented.


Above the three basic Natbib styles were mentioned
as analogues of the partially homonymous styles in
BibTeX. Let us imagine documents bearing citations
as in the section about citation above. Here is, approx-
imately, how these citations would appear in plainnat.

What more is there?

This covers the basic functionality provided by the pack-


age Natbib. It may not, of course, provide what you are
looking for. If you don't find what you want here then you
should probably next investigate harvard.sty which pro-
vides a slighly different set of author-date citation func-
tions. Providing a gentle guide to harvard.sty is my next
rainy day project.
Chapter 6

Special Documents

6.1 Letters
Sometimes the mundane things are the most painful.
However, it doesn't have to be that way because of
evolved, user-friendly templates. Thankfully, LaTeX al-
lows for very quick letter writing, with little hassle.

6.1.1 The letter class


To write letters use the standard document class letter.
You can write multiple letters in one LaTeX file - start
each one with \begin{letter}{''recipient''} and end with
\end{letter}. You can leave recipient blank. Each letter
consists of four parts.

1. Opening (like \opening{Dear Sir or Madam,} or


\opening{Dear Kate,}).

2. Main body (written as usual in LaTeX). If you want


the same body in all the letters, you may want to con-
sider putting the entire body in a new command like
\newcommand{\BODY}{actual body} and then us-
ing \BODY in all the letters. A sample letter.

3. Closing (like \closing{Yours sincerely,}).


Road \\ Newport \\ Ipswich IP3 5RT} \opening{Dear
LaTeX will leave some space after clos- Sir or Madam:} I am writing to you on behalf of
ing for your hand-written signature; then the Wikipedia project (http://www.wikipedia.org/),
it will put your name and surname, if you an endeavour to build a fully-fledged multilingual
have declared them. encyclopaedia in an entirely open manner, to ask for
permission to use your copyrighted material. % The
4. Additional elements: post scripta, carbon copy and
\ldots command produces dots in a way that will not
list of enclosures.
upset % the typesetting of the document. \ldots That
said, allow me to reiterate that your material will be
If you want your name, address and telephone number to used to the noble end of providing a free collection of
appear in the letter, you have to declare them first signa- knowledge for everyone; naturally enough, only if you
ture, address and telephone. agree. If that is the case, could you kindly fill in the
The output letter will look like this: attached form and post it back to me? We shall greatly
appreciate it. Thank you for your time and consider-
Here is the example’s code: ation. I look forward to your reply. \closing{Yours
\documentclass{letter} \usepackage{hyperref} \sig- Faithfully,} \ps P.S. You can find the full text of GFDL
nature{Joe Bloggs} \address{21 Bridge Street \\ license at \url{http://www.gnu.org/copyleft/fdl.html}.
Smallville \\ Dunwich DU3 4WE} \begin{document} \encl{Copyright permission form} \end{letter}
\begin{letter}{Director \\ Doe \& Co \\ 35 Anthony \end{document}

130
6.1. LETTERS 131

$ latex envelope.tex && dvips -t unknown -T


To move the closing and signature parts to the left, insert 9.5in,4.125in envelope.dvi $ lpr -o landscape enve-
the following before \begin{document}: lope.ps

\longindentation=0pt It is reported that pdflatex creates the right page size but
not dvips despite what it says in the geometry manual.
The amount of space to the left can be adjusted by in- It will never work though unless your printer settings are
creasing the 0pt. adjusted to the correct page style. These settings depend
on the printer filter you are using and in CUPS might be
available on the lpr command line.
6.1.2 Envelopes
Using the envlab package

The envlab package provides customization to the \make- 6.1.3 Windowed envelopes
labels command, allowing the user to print on any of an
assortment of labels or envelope sizes. For example, be- An alternative to separately printing addresses on en-
ginning your LaTeX file the following way produces a velopes is to use the letter class from the KOMA package.
document which includes the letter and a business-size It supports additional features like folding marks and the
(#10) envelope on the following page. correct address placement for windowed envelopes. Us-
ing the scrlttr2 document class from the KOMA package
Refer to the envlab user guide for more information about
the example letter code is:
this capable package. Note that the envlab package has
issues displaying characters outside the base ASCII char- % koma_env.tex \documentclass[a4paper]{scrlttr2}
acter set, see this bug report for more information. \usepackage{lmodern} \usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} \usepackage[english]{babel}
\usepackage{url} \setkomavar{fromname}{Joe Bloggs}
Using the geometry package \setkomavar{fromaddress}{21 Bridge Street \\ Smallville
\\ Dunwich DU3 4WE} \setkomavar{fromphone}{0123
Here is a relatively simple envelope which uses the ge- 45679} \begin{document} \begin{letter}{Director \\
ometry package which is used because it vastly simplifies Doe \& Co \\ 35 Anthony Road \\ Newport \\ Ipswich IP3
the task of rearranging things on the page (and the page 5RT} \KOMAoptions{fromphone=true,fromfax=false}
itself). \setkomavar{subject}{Wikipedia} \setko-
mavar{customer}{2342} \opening{Dear Sir or Madam,}
I am writing to you on behalf of the Wikipedia project
(\url{http://www.wikipedia.org/}), an endeavour to
build a fully-fledged multilingual encyclopaedia in an
entirely open manner, to ask for permission to use your
copyrighted material. \ldots That said, allow me to
reiterate that your material will be used to the noble
end of providing a free collection of knowledge for
everyone; naturally enough, only if you agree. If that
A sample envelope to be printed in landscape mode. is the case, could you kindly fill in the attached form
and post it back to me? We shall greatly appreciate
it. Thank you for your time and consideration. I
Printing look forward to your reply. \closing{Yours Faith-
fully,} \ps{P.S. You can find the full text of GFDL
The above will certainly take care of the spacing but the license at \url{http://www.gnu.org/copyleft/fdl.html}.}
actual printing is between you and your printer. One user \encl{Copyright permission form} \end{letter}
reports that printing envelopes created with envlab is rel- \end{document}
atively painless. If you use the geometry package, you
may find the following commands useful for printing the The output is generated via
envelope.
$ pdflatex koma_env Folding the print of the resulting
$ pdflatex envelope.tex $ pdf2ps envelope.pdf $ lpr -o file koma_env.pdf according the folding marks it can be
landscape envelope.ps placed into standardized windowed envelopes DIN C6/5,
Alternatively, you can use the latex dvi output driver. DL, C4, C5 or C6.
In the first line, dvips command converts the .dvi file pro- In addition to the default, the KOMA-package includes
duced by latex into a .ps (PostScript) file. In the second predefined format definitions for different standardized
line, the PostScript file is sent to the printer. Swiss and Japanese letter formats.
132 CHAPTER 6. SPECIAL DOCUMENTS

Introductory example

The beamer package is loaded by calling the beamer class:


\documentclass{beamer}

The usual header information may then be specified.


Note that if you are compiling with XeTeX then you
should use
\documentclass[xetex,mathserif,serif]{beamer}

Inside the document environment, multiple frame envi-


ronments specify the content to be put on each slide. The
frametitle command specifies the title for each slide (see
image):
\begin{document} \begin{frame} \frametitle{This is
the first slide} %Content goes here \end{frame} \be-
gin{frame} \frametitle{This is the second slide} \frame-
subtitle{A bit more information about this} %More
content goes here \end{frame} % etc \end{document}

A sample letter with folding marks ready for standardized win-


dowed envelopes.

6.1.4 Reference: letter.cls commands

6.1.5 Sources

• KOMA-Script - The Guide

6.2 Presentations

LaTeX can be used for creating presentations. There are


several packages for the task, including the beamer pack-
age.
The usual environments (itemize, enumerate, equation,
etc.) may be used.
6.2.1 The Beamer package Inside frames, you can use environments like block, the-
orem, proof, ... Also, \maketitle is possible to create the
The beamer package is provided with most LaTeX distri- frontpage, if title and author are set.
butions, but is also available from CTAN. If you use Mik- Trick: Instead of using \begin{frame}...\end{frame},
TeX, all you have to do is to include the beamer package you can also use \frame{...}.
and let LaTeX download all wanted packages automati- For the actual talk, if you can compile it with pdflatex
cally. The documentation explains the features in great then you could use a pdf reader with a fullscreen mode,
detail. You can also have a look at the PracTex article such as Okular, Evince or Adobe Reader. If you want
Beamer by example.[1] to navigate in your presentation, you can use the almost
The beamer package also loads many useful packages in- invisible links in the bottom right corner without leaving
cluding hyperref. the fullscreen mode.
6.2. PRESENTATIONS 133

Document Structure References (Beamer) Beamer does not officially sup-


port BibTeX. Instead bibliography items will need to be
Title page and information You give information partly set “by hand” (see beameruserguide.pdf 3.12). The
about authors, titles and dates in the preamble. following example shows a references slide containing
two entries:
\title[Crisis] % (optional, only for long titles) {The
Economics of Financial Crisis} \subtitle{Evidence from \begin{frame}[allowframebreaks] \frameti-
India} \author[Author, Anders] % (optional, for multiple tle<presentation>{Further Reading} \be-
authors) {F.~Author\inst{1} \and S.~Anders\inst{2}} gin{thebibliography}{10} \beamertemplatebook-
\institute[Universities Here and There] % (optional) { bibitems \bibitem{Autor1990} A.~Autor. \newblock
\inst{1}% Institute of Computer Science\\ University {\em Introduction to Giving Presentations}. \newblock
Here \and \inst{2}% Institute of Theoretical Philoso- Klein-Verlag, 1990. \beamertemplatearticlebibitems
phy\\ University There } \date[KPT 2004] % (optional) \bibitem{Jemand2000} S.~Jemand. \newblock On
{Conference on Presentation Techniques, 2004} \sub- this and that. \newblock {\em Journal of This and
ject{Computer Science} That}, 2(1):50-−100, 2000. \end{thebibliography}
\end{frame}
In the document, you add the title page :
As the reference list grows, the reference slide will divide
\frame{\titlepage}
into two slides and so on, through use of the allowframe-
breaks option. Individual items can be cited after adding
an 'optional' label to the relevant bibitem stanza. The ci-
Table of Contents The table of contents, with the cur- tation call is simply \cite. Beamer also supports limited
rent section highlighted, is displayed by: customization of the way references are presented (see
the manual). Those who wish to use natbib, for example,
\begin{frame} \frametitle{Table of Contents} \tableof- with Beamer may need to troubleshoot both their docu-
contents[currentsection] \end{frame} ment setup and the relevant BibTeX style file.
The different types of referenced work are indicated with
This can be done automatically at the beginning of each a little symbol (e.g. a book, an article, etc.). The Symbol
section using the following code in the preamble: is set with the commands beamertemplatebookbibitems
\AtBeginSection[] { \begin{frame} \frametitle{Table of and beamertemplatearticlebibitems . It is also possible to
Contents} \tableofcontents[currentsection] \end{frame} use setbeamertemplate directly, like so
} \begin{frame}[allowframebreaks] \frameti-
tle<presentation>{Further Reading} \be-
Or for subsections: gin{thebibliography}{10} \setbeamertem-
plate{bibliography item}[book] \bibitem{Autor1990}
\AtBeginSubsection[] { \begin{frame} \fram-
A.~Autor. \newblock {\em Introduction to Giv-
etitle{Table of Contents} \tableofcon-
ing Presentations}. \newblock Klein-Verlag, 1990.
tents[currentsection,currentsubsection] \end{frame}
\setbeamertemplate{bibliography item}[article] \bib-
}
item{Jemand2000} S.~Jemand. \newblock On this and
that. \newblock {\em Journal of This and That}, 2(1):50-
−100, 2000. \end{thebibliography} \end{frame}
Sections and subsections As in all other LaTeX files,
it is possible to structure the document using Other possible types of bibliography items, besides book
\section[Section]{My section} and article , include e.g. online , triangle and text . It is
also possible to have user defined bibliography items by
including a graphic.
,
If one wants to have full references appear as foot notes,
\subsection[Subsection]{My subsection} use the \footfullcite. For example, it is possible to use
\documentclass[10pt,handout,english]{beamer}
and \usepackage[english]{babel}
\subsubsection[Subsubsection]{My subsubsection} \usepackage[backend=biber,style=numeric-
comp,sorting=none]{biblatex} \addbibre-
source{biblio.bib} \begin{frame} \frametitle{Title}
Those commands have to be put before and between A reference~\footfullcite{ref_bib}, with ref_bib an item
frames. They will modify the Table of contents with of the .bib file. \end{frame}
the optional argument. The argument in brackets will be
written on the slide, depending on the used theme.
134 CHAPTER 6. SPECIAL DOCUMENTS

Style • circles
• inmargin
Themes The first solution is to use a built-in theme
such as Warsaw, Berlin, etc. The second solution is to • rounded
specify colors, inner themes and outer themes.
You can define the color of every element:
The Built-in solution To the preamble you can add \setbeamercolor{alerted text}{fg=orange} \setbeam-
the following line: ercolor{background canvas}{bg=white} \setbeamer-
color{block body alerted}{bg=normal text.bg!90!black}
\usetheme{Warsaw} \setbeamercolor{block body}{bg=normal
text.bg!90!black} \setbeamercolor{block body ex-
to use the “Warsaw” theme. Beamer has several themes, ample}{bg=normal text.bg!90!black} \setbeamer-
many of which are named after cities (e.g. Frankfurt, color{block title alerted}{use={normal text,alerted
Madrid, Berlin, etc.). text},fg=alerted text.fg!75!normal text.fg,bg=normal
text.bg!75!black} \setbeamercolor{block ti-
This Theme Matrix contains the various theme and color
tle}{bg=blue} \setbeamercolor{block title exam-
combinations included with beamer. For more customiz-
ple}{use={normal text,example text},fg=example
ing options, have a look to the official documentation in-
text.fg!75!normal text.fg,bg=normal text.bg!75!black}
cluded in your distribution of beamer, particularly the
\setbeamercolor{fine separation line}{} \set-
part Change the way it looks.
beamercolor{frametitle}{fg=brown} \setbeam-
The full list of themes is: ercolor{item projected}{fg=black} \setbeamer-
Color themes, typically with animal names, can be spec- color{normal text}{bg=black,fg=yellow} \set-
ified with beamercolor{palette sidebar primary}{use=normal
text,fg=normal text.fg} \setbeamercolor{palette
\usecolortheme{beaver} sidebar quaternary}{use=structure,fg=structure.fg}
\setbeamercolor{palette sidebar sec-
The full list of color themes is: ondary}{use=structure,fg=structure.fg} \setbeam-
ercolor{palette sidebar tertiary}{use=normal
text,fg=normal text.fg} \setbeamercolor{section in
The do it yourself solution First you can specify the sidebar}{fg=brown} \setbeamercolor{section in side-
outertheme. The outertheme defines the head and the bar shaded}{fg=grey} \setbeamercolor{separation
footline of each slide. line}{} \setbeamercolor{sidebar}{bg=red} \setbeam-
\useoutertheme{infolines} ercolor{sidebar}{parent=palette primary} \setbeam-
ercolor{structure}{bg=black, fg=green} \setbeamer-
color{subsection in sidebar}{fg=brown} \setbeam-
Here is a list of all available outer themes: ercolor{subsection in sidebar shaded}{fg=grey}
\setbeamercolor{title}{fg=brown} \setbeamer-
• infolines color{titlelike}{fg=brown}
• miniframes
Colors can be defined as usual:
• shadow
\definecolor{chocolate}{RGB}{33,33,33}
• sidebar

• smoothbars Block styles can also be defined:


\setbeamertemplate{blocks}[rounded][shadow=true]
• smoothtree \setbeamertemplate{background canvas}[vertical
• split shading][bottom=white,top=structure.fg!25] \set-
beamertemplate{sidebar canvas left}[horizontal shad-
• tree ing][left=white!40!black,right=black]

Then you can add the innertheme: You can also suppress the navigation bar:
\useinnertheme{rectangles} \beamertemplatenavigationsymbolsempty

Here is a list of all available inner themes:


Fonts You may also change the fonts for particular el-
• rectangles ements. If you wanted the title of the presentation as ren-
6.2. PRESENTATIONS 135

dered by \frame{\titlepage} to occur in a serif font instead \end{frame}


of the default sanserif, you would use:
\setbeamerfont{title}{family=\rm}
Hyperlink navigation
You could take this a step further if you are using Open-
Type fonts with Xe(La)TeX and specify a serif font with Internal and external hyperlinks can be used in beamer
increased size and oldstyle proportional alternate number to assist navigation. Clean looking buttons can also be
glyphs: added.
By default the beamer class adds navigation buttons in the
\setbeamerfont{title}{family=\rm\addfontfeatures{Scale=1.18,
Numbers={Lining, Proportional}}} bottom right corner. To remove them one can place
\beamertemplatenavigationsymbolsempty

Math Fonts The default settings for beamer use a dif- in the preamble.
ferent set of math fonts than one would expect from cre-
ating a simple math article. One quick fix for this is to Animations
use at the beginning of the file the option mathserif
\documentclass[mathserif]{beamer} The following is merely an introduction to the possibili-
ties in beamer. Chapter 8 of the beamer manual provides
much more detail, on many more features.
Others have proposed to use the command
Making items appear on a slide is possible by simply using
\usefonttheme[onlymath]{serif}
the \pause statement:
\begin{frame} \frametitle{Some background} We
but it is not clear if this works for absolutely every math
start our discussion with some concepts. \pause The
character.
first concept we introduce originates with Erd\H os.
\end{frame}
Frames Options
Text or figures after \pause will display after one of the
The plain option. Sometimes you need to include a large following events (which may vary between PDF viewers):
figure or a large table and you don't want to have the bot- pressing space, return or page down on the keyboard, or
tom and the top off the slides. In that case, use the plain using the mouse to scroll down or click the next slide but-
option: ton. Pause can be used within \itemize etc.
\frame[plain]{ % ... }
Text animations For text animations, for example in
If you want to include lots of text on a slide, use the shrink the itemize environment, it is possible to specify appear-
option. ance and disappearance of text by using <a-b> where a
and b are the numbers of the events the item is to be dis-
\frame[shrink]{ % ... } played for (inclusive). For example:
\begin{itemize} \item This one is always shown \item<1-
The allowframebreaks option will auto-create new frames > The first time (i.e. as soon as the slide loads) \item<2->
if there is too much content to be displayed on one. The second time \item<1-> Also the first time \only<1-
\frame[allowframebreaks]{ % ... } 1> {This one is shown at the first time, but it will
hide soon (on the next event after the slide loads).}
Before using any verbatim environment (like listings), \end{itemize}
you should pass the option fragile to the frame environ-
ment, as verbatim environments need to be typeset dif- A simpler approach for revealing one item per click is to
ferently. Usually, the form fragile=singleslide is usable use \begin{itemize}[<+->].
(for details see the manual). Note that the fragile option
\begin{frame} \frametitle{`Hidden higher-order con-
may not be used with \frame commands since it expects cepts?'} \begin{itemize}[<+->] \item The truths of
to encounter a \end{frame}, which should be alone on a arithmetic which are independent of PA in some sense
single line. themselves `{contain} essentially {\color{blue}{hidden
\begin{frame}[fragile] \frametitle{Source code} \be- higher-order}}, or infinitary, concepts’??? \item `Truths
gin{lstlisting}[caption=First C example] int main() in the language of arithmetic which \ldots \item That sug-
{ printf(“Hello World!"); return 0; } \end{lstlisting} gests stronger version of Isaacson’s thesis. \end{itemize}
136 CHAPTER 6. SPECIAL DOCUMENTS

\end{frame} and this will hide your slide in both modes. (The order
matters. Don't put handout:0|beamer:0 or it won't work.)
In all these cases, pressing page up, scrolling up, or click- A last word about the handout mode is about the notes.
ing the previous slide button in the navigation bar will Actually, the full syntax for a frame is
backtrack through the sequence.
\begin{frame} ... \end{frame} \note{...} \note{...} ...

and you can write your notes about a frame in the field
Handout mode note (many of them if needed). Using this, you can add
an option to the class calling, either
In beamer class, the default mode is presentation which
\documentclass[12pt,handout,notes=only]{beamer}
makes the slides. However, you can work in a different
mode that is called handout by setting this option when
calling the class: or
\documentclass[12pt,handout]{beamer} \documentclass[12pt,handout,notes=show]{beamer}

This mode is useful to see each slide only one time with all The first one is useful when you make a presentation to
its stuff on it, making any \itemize[<+->] environments have only the notes you need, while the second one could
visible all at once (for instance, printable version). Nev- be given to those who have followed your presentation or
ertheless, this makes an issue when working with the only those who missed it, for them to have both the slides with
command, because its purpose is to have only some text what you said.
or figures at a time and not all of them together. Note that the 'handout' option in the \documentclass line
If you want to solve this, you can add a statement to spec- suppress all the animations.
ify precisely the behavior when dealing with only com- Important: the notes=only mode is literally doing only
mands in handout mode. Suppose you have a code like the notes. This means there will be no output file but the
this DVI. Thus it requires you to have run the compilation
\only<1>{\includegraphics{pic1.eps}} in another mode before. If you use separate files for a
\only<2>{\includegraphics{pic2.eps}} better distinction between the modes, you may need to
copy the .aux file from the handout compilation with the
slides (w/o the notes).
These pictures being completely different, you want them
both in the handout, but they cannot be both on the same
slide since they are large. The solution is to add the hand- Columns and Blocks
out statement to have the following:
\only<1| handout:1>{\includegraphics{pic1.eps}} There are two handy environments for structuring a
\only<2| handout:2>{\includegraphics{pic2.eps}} slide: “blocks”, which divide the slide (horizontally) into
headed sections, and “columns” which divides a slide
(vertically) into columns. Blocks and columns can be
This will ensure the handout will make a slide for each used inside each other.
picture.
Now imagine you still have your two pictures with the
only statements, but the second one show the first one Columns Example
plus some other graphs and you don't need the first one to\begin{frame}{Example of columns 1} \be-
appear in the handout. You can thus precise the handout gin{columns}[c] % the “c” option specifies center
mode not to include some only commands by: vertical alignment \column{.5\textwidth} % column
\only<1| handout:0>{\includegraphics{pic1.eps}} designated by a command Contents of the first column
\only<2>{\includegraphics{pic2.eps}} \column{.5\textwidth} Contents split \\ into two lines
\end{columns} \end{frame} \begin{frame}{Example
of columns 2} \begin{columns}[T] % contents are
The command can also be used to hide frames, e.g. top vertically aligned \begin{column}[T]{5cm}
\begin{frame}<handout:0> % each column can also be its own environment
Contents of first column \\ split into two lines
\end{column} \begin{column}[T]{5cm} % alter-
or even, if you have written a frame that you don't want native top-align that’s better for graphics \include-
anymore but maybe you will need it later, you can write graphics[height=3cm]{graphic.png} \end{column}
\begin{frame}<0| handout:0> \end{columns} \end{frame}
6.2. PRESENTATIONS 137

\hypersetup{pdfstartview={Fit}} % fits the presentation


to the window when first displayed

Numbering slides

It is possible to number slides using this snippet:


\insertframenumber/\inserttotalframenumber

However, this poses two problems for some presentation


authors: the title slide is numbered as the first one, and
the appendix or so-called “backup” (aka appendix, re-
serve) slides are included in the total count despite them
not being indented to be public until a “hard” question is
asked.[3] This is where two features come in:

• Ability to reset the frames counter at any slide. For


instance, this may be inserted at the title slide to
avoid counting it:
Blocks Enclosing text in the block environment creates
a distinct, headed block of text (a blank heading can be
used). This allows to visually distinguish parts of a slide \addtocounter{framenumber}{−1}
easily. There are three basic types of block. Their for-
matting depends on the theme being used. Or alternatively this:
Simple \setcounter{framenumber}{0} or \set-
\begin{frame} \begin{block}{This is a Block} counter{framenumber}{1}
This is important information \end{block} \be-
gin{alertblock}{This is an Alert block} This is an impor-
tant alert \end{alertblock} \begin{exampleblock}{This • The first of the above applies to section slides to
is an Example block} This is an example avoid counting them.
\end{exampleblock} \end{frame}
• This stuff works around the problem of counting the
backup slides:

% (Thanks, David Gleich!) % All your


regular slides % After your last numbered
slide \appendix \newcounter{finalframe} \set-
counter{finalframe}{\value{framenumber}} % Backup
frames \setcounter{framenumber}{\value{finalframe}}
\end{document}

6.2.2 The powerdot package


The powerdot package is an alternative to beamer. It is
available from CTAN. The documentation explains the
features in great detail.
The powerdot package is loaded by calling the powerdot
class:
\documentclass{powerdot}

PDF options The usual header information may then be specified.


Inside the usual document environment, multiple slide en-
You can specify the default options of your PDF.[2] vironments specify the content to be put on each slide.
138 CHAPTER 6. SPECIAL DOCUMENTS

\begin{document} \begin{slide}{This is the first slide} • The solution is given in the solution environment.
%Content goes here \end{slide} \begin{slide}{This is It appears only if \printanswers or answers as an
the second slide} %More content goes here \end{slide} option of the \documentclass are specified in the
% etc \end{document} preamble.

Here is an example :
6.2.3 References \begin{questions} % Begins the questions environment
\question[2] What is the solution? % Introduces a
[1] Andrew Mertz and William Slough Beamer by Example new question which is worth 2 points \begin{solution}
Here is the solution \end{solution} \question[5] What
[2] Other possible values are defined in the hyperref manual is your opinion? \begin{solution} This is my opinion
\end{solution} \end{questions}
[3] Appendix Slides in Beamer: Controlling frame numbers

It is also possible to add stuff only if answers are printed


6.2.4 Links using the \ifprintanswers command.
\ifprintanswers Only if answers are printed \else Only if
• Wikipedia:Beamer (LaTeX)
answers are not printed \fi
• Beamer user guide (pdf) from CTAN

• The powerdot class (pdf) from CTAN


Introduction
• A tutorial for creating presentations using beamer
The macro \numquestions gives the total number of
questions. The macro \numpoints gives the total num-
ber of points.
6.3 Teacher’s Corner
\begin{minipage}{.8\textwidth} This exam includes
\numquestions\ questions. The total number of points is
6.3.1 Intro \numpoints. \end{minipage}
LaTeX has specific features for teachers. We present the
exam class[1] which is useful for designing exams and ex- The backslash after \numquestion prevents the macro
ercises with solutions. Interested people could also have a from gobbling the following whitespace as it normally
look at the probsoln package[2] , the mathexm document would.
class[3] , or the exsheets package[4] .

6.3.3 References
6.3.2 The exam class
[1] examdoc Using the exam document class
We present the exam class. The exam class is well suited [2] Probsoln Creating problem sheets optionally with solu-
to design exams with solutions. You just have to specify tions
in the preamble if you want the solutions to be printed or
not. You can also count the number of points. [3] mathexm documentation

[4] exsheets documentation Create exercise sheets and exams


Preamble

In the preamble you can specify the following lines : 6.4 Curriculum Vitae
You can replace the 3 first lines with the following :
A curriculum vitæ or résumé has a universal requirement:
its formatting must be flawless. This is a great example
Document of cases where the power of LaTeX comes to the front.
Thanks to its strong typographical stance, LaTeX is def-
• The exam is included in the questions environment. initely a document processor of choice to write a CV.

• The command \question introduces a new question. Of course you can design your own CV by hand. Other-
wise, you may want to use a dedicated class for that task.
• The number of points is specified in squared brack- This way, writing a CV in LaTeX is as simple as filling
ets. the forms, and you are done. Seeveeze makes 3 of them
6.4. CURRICULUM VITAE 139

available (ModernCV PlasmatiCV and FriggeriCV) from


a simple web form: no coding or editor required.
A full list of CV packages is available at CTAN.

6.4.1 curve

6.4.2 europecv

6.4.3 moderncv
From CTAN:
Moderncv provides a documentclass for typesetting
modern curriculums vitae, both in a classic and in a casual
style. It is fairly customizable, allowing you to define your
own style by changing the colours, the fonts, etc.
The official package provides some well commented tem-
plates which may be a good start. You can find those tem-
plates in your distribution (if documentation is installed
along packages) or ultimately on CTAN.
We will not repeat the templates here, so we will only
provide a crash course. You should really have a look at
the templates for more details.

First document

Most commands are self-explanatory.

Theme previews

• Themes

• Banking black theme


• Classic green theme

6.4.4 Multilingual support


It is especially convenient for résumés to have only one
document for several output languages, since many parts
are shared among versions (personal data, structure, etc.).
LaTeX with appropriate macros provide a comfortable
way to manage it. See Internationalization.

6.4.5 References
Chapter 7

Creating Graphics

7.1 Introducing Procedural tional graphics files to be dragged along.


Graphics Packages like epic, eepic or pstricks enhance the original
picture environment, and greatly strengthen the graphical
In the Importing Graphics chapter, you learned that you power of LaTeX.
can import or link graphics into LaTeX, such as graph- While the former two packages just enhance the picture
ics that you have created in another program or obtained environment, the pstricks package has its own drawing
elsewhere. In this chapter, you will learn how to create environment, pspicture. The power of pstricks stems
or embed graphics directly in a LaTeX document. The from the fact that this package makes extensive use of
graphics is marked up using commands similar to those PostScript possibilities. Unfortunately it has one big
for typesetting bold text or creating mathematical for- shortcoming: it doesn't work together with pdfLaTeX, as
mulas, as the following example of embedded graphics such. To generate a PDF document from TeX source, you
shows: have to go from TeX to DVI to PDF, losing hyperlinks,
There are several packages supporting the creation of metadata, and microtypographic features of pdflatex in
graphics directly in LaTeX, including picture, xy-Pic and the process.
PGF/TikZ, described in the following sections. In addition, numerous packages have been written for
Compared to WYSIWIG tools like Xfig or Inkscape, this specific purposes. One of them is XY-pic, described at
approach is more time consuming, but leads to much bet- the end of this chapter. A wide variety of these packages
ter results. Furthermore, the output is flawlessly inte- are described in detail in The LaTeX Graphics Compan-
grated to your document (no contrast in size nor fonts). ion (not to be confused with The LaTeX Companion).

See the Importing Graphics for more details on graphics Perhaps the most powerful graphical tool related with
importation and some attempts to circumvent to integra- LaTeX is MetaPost, the twin of Donald E. Knuth’s
tion issue. METAFONT. MetaPost has the very powerful and
mathematically sophisticated programming language of
METAFONT. Contrary to METAFONT, which gener-
7.1.1 Overview ates bitmaps, MetaPost generates encapsulated PostScript
files, which can be imported in LaTeX. For an introduc-
The picture environment allows programming pictures tion, see A User’s Manual for MetaPost. A very thorough
directly in LaTeX. On the one hand, there are rather se- discussion of LaTeX and TEX strategies for graphics (and
vere constraints, as the slopes of line segments as well fonts) can be found in TEX Unbound.
as the radii of circles are restricted to a narrow choice The last but certainly not least are the PGF/TikZ and
of values. On the other hand, the picture environment Asymptote systems. While the previous systems (pic-
of LaTeX2e brings with it the \qbezier command, “q” ture, epic, pstricks or metapost) focus on the how to draw,
meaning quadratic. Many frequently-used curves such TikZ and Asymptote focus more on the what to draw.
as circles, ellipses, and catenaries can be satisfactorily One could say that TikZ and Asymptote are to drawing
approximated by quadratic Bézier curves, although this in LaTeX as LaTeX is to digital typesetting. It’s recom-
may require some mathematical toil. If a programming mended to use one of these if your LaTeX distribution
language like Java is used to generate \qbezier blocks of includes it. TikZ is a pure (La)TeX system, not reliant
LaTeX input files, the picture environment becomes quite on external software, while Asymptote is an external sys-
powerful. tem which integrates seamlessly with (La)TeX. If using
Although programming pictures directly in LaTeX is Asymptote, it is very helpful to use latexmk to manage
severely restricted, and often rather tiresome, there are the compilation steps.
still reasons for doing so. The documents thus produced In many cases, especially for more advanced diagrams, it
are “small” with respect to bytes, and there are no addi-

140
7.3. PICTURE 141

may be easier to draw the graphics using external vector Bézier curves are an exception. They are drawn with the
graphics software, and then import the file into the doc- command
ument (see LaTeX/Importing_Graphics). However most With the package picture absolute dimension (like 15pt)
software does not support LaTeX fonts or mathematical and expression are allowed, in addition to numbers rela-
notation, which can result in not suitable and inconsistent tive to \unitlength.
graphics. There are several solutions to this problem.

7.3.2 Line segments


7.2 MetaPost
Line segments are drawn with the command:
7.3 Picture The \line command has two arguments:

The picture environment allows programming pictures


1. a direction vector,
directly in LaTeX. On the one hand, there are rather se-
vere constraints, as the slopes of line segments as well
as the radii of circles are restricted to a narrow choice 2. a “length” (sort of: this argument is the vertical
of values. On the other hand, the picture environment length in the case of a vertical line segment and in all
of LaTeX2e brings with it the \qbezier command, “q” other cases the horizontal distance of the line, rather
meaning quadratic. Many frequently-used curves such than the length of the segment itself).
as circles, ellipses, and catenaries can be satisfactorily
approximated by quadratic Bézier curves, although this
The components of the direction vector are restricted to
may require some mathematical toil. If a programming
the integers (−6, −5, ... , 5, 6) and they have to be co-
language like Java is used to generate \qbezier blocks of
prime (no common divisor except 1). The figure below
LaTeX input files, the picture environment becomes quite
illustrates all 25 possible slope values in the first quadrant.
powerful.
The length is relative to \unitlength.
Although programming pictures directly in LaTeX is
severely restricted, and often rather tiresome, there are
still reasons for doing so. The documents thus produced
7.3.3 Arrows
are “small” with respect to bytes, and there are no addi-
tional graphics files to be dragged along.
Arrows are drawn with the command
Packages like pict2e, epic, eepic or pstricks enhance the
original picture environment, and greatly strengthen the For arrows, the components of the direction vector are
graphical power of LaTeX. even more narrowly restricted than for line segments,
namely to the integers (−4, −3, ... , 3, 4). Components
also have to be coprime (no common divisor except 1).
Notice the effect of the \thicklines command on the two
7.3.1 Basic commands
arrows pointing to the upper left.
A picture environment is available in any LaTeX distri-
bution, without the need of loading any external package.
This environment is created with one of the two com- 7.3.4 Circles
mands
or The command

The first pair, (x, y) , affects the reservation, within the draws a circle with center (x, y) and diameter (not radius)
document, of rectangular space for the picture. specified by diameter. The picture environment only ad-
mits diameters up to approximately 14mm, and even be-
The optional second pair, (x0 , y0 ) , assigns arbitrary co- low this limit, not all diameters are possible. The \circle*
ordinates to the bottom left corner of the reserved rect- command produces disks (filled circles). As in the case of
angle. line segments, one may have to resort to additional pack-
The numbers x, y, x0, y0 are numbers (lengths) in the ages, such as eepic, pstricks, or tikz.
units of \unitlength, which can be reset any time (but not There is another possibility within the picture environ-
within a picture environment) with a command such as ment. If one is not afraid of doing the necessary calcula-
The default value of \unitlength is 1pt. tions (or leaving them to a program), arbitrary circles and
ellipses can be patched together from quadratic Bézier
Most drawing commands have one of the two forms curves. See Graphics in LaTeX2e for examples and Java
or source files.
142 CHAPTER 7. CREATING GRAPHICS

7.3.5 Text and formulae 7.3.9 Quadratic Bézier curves

As this example shows, text and formulae can be written The command
in the environment with the \put command in the usual
draws a quadratic bezier curve where P1 = (x1 , y1 ) ,
way:
P2 = (x2 , y2 ) denote the end points, and S = (x, y)
denotes the intermediate control point. The respective
tangent slopes, m1 and m2 , can be obtained from the
7.3.6 \multiput and \linethickness equations

The command
{
has 4 arguments: the starting point, the translation vector x = m2 x2 −m 1 x1 −(y2 −y1 )
m2 −m1
from one object to the next, the number of objects, and y = yi + mi (x − xi ); (i = 1, 2 gives same solution)
the object to be drawn. The \linethickness command ap-
plies to horizontal and vertical line segments, but neither
to oblique line segments, nor to circles. It does, however, See Graphics in LaTeX2e for a Java program which gen-
apply to quadratic Bézier curves! erates the necessary \qbezier command line.
As this example illustrates, splitting up a circle into 4
quadratic Bézier curves is not satisfactory. At least 8
are needed. The figure again shows the effect of the
7.3.7 Ovals \linethickness command on horizontal or vertical lines,
and of the \thinlines and the \thicklines commands on
The command oblique line segments. It also shows that both kinds of
or commands affect quadratic Bézier curves, each command
overriding all previous ones.
produces an oval centered at (x, y) and having width w and
height h. The optional position arguments b, t, l, r refer to
“top”, “bottom”, “left”, “right”, and can be combined, as
the example illustrates. Line thickness can be controlled
by two kinds of commands: \linethickness{''length''} on
7.3.10 Catenary
the one hand, \thinlines and \thicklines on the other.
While \linethickness{''length''} applies only to horizontal In this figure, each symmetric half of the catenary y =
and vertical lines (and quadratic Bézier curves), \thinlines cosh x − 1 is approximated by a quadratic Bézier curve.
and \thicklines apply to oblique line segments as well as The right half of the curve ends in the point (2, 2.7622),
to circles and ovals. the slope there having the value m = 3.6269. Using again
equation (*), we can calculate the intermediate control
points. They turn out to be (1.2384, 0) and (−1.2384, 0).
The crosses indicate points of the real catenary. The error
7.3.8 Multiple use of predefined picture is barely noticeable, being less than one percent. This
boxes example points out the use of the optional argument of
the \begin{picture} command. The picture is defined in
A picture box can be declared by the command convenient “mathematical” coordinates, whereas by the
command
then defined by
its lower left corner (marked by the black disk) is assigned
and finally arbitrarily often be drawn by the coordinates (−2.5,−0.25).
The optional position parameter has the effect of defining
the “anchor point” of the savebox. In the example it is set
to “bl” which puts the anchor point into the bottom left
corner of the savebox. The other position specifiers are 7.3.11 Plotting graphs
top and right.
The name argument refers to a LaTeX storage bin and The control points of the two Bézier curves were calcu-
therefore is of a command nature (which accounts for the lated with formulas (*). The positive branch is deter-
backslashes in the current example). Boxed pictures can mined by P1 = (0, 0) , m1 = 1 and P2 = (2, tanh 2)
be nested: In this example, \foldera is used within the , m2 = 1/ cosh2 2 . Again, the picture is defined in
definition of \folderb. The \oval command had to be used mathematically convenient coordinates, and the lower left
as the \line command does not work if the segment length corner is assigned the mathematical coordinates (−3,−2)
is less than about 3 mm. (black disk).
7.4. PGF/TIKZ 143

7.3.12 The picture environment and gnu- html#pgftikzsection


plot In the following some basics of TikZ are presented.

The powerful scientific plotting package gnuplot has the


capability to output directly to a LaTeX picture environ- 7.4.1 Loading Package, Libraries -
ment. It is often far more convenient to plot directly to tikzpicture environment
LaTeX, since this saves having to deal with potentially
troublesome postscript files. Plotting scientific data (or, Using TikZ in a LaTeX document requires loading the
indeed, mathematical figures) this way gives much greater tikz package:
control, and of course typesetting ability, than is available
from other means (such as postscript). Such pictures can \usepackage{tikz}
then be added to a document by an \include{} command.
N.B. gnuplot is a powerful piece of software with a vast somewhere in the preamble. This will automatically load
array of commands. A full discussion of gnuplot lies be- the pgf package. To load further libraries use
yond the scope of this note. See [] for a tutorial. \usetikzlibrary{⟨list of libraries separated by commas⟩}

Examples for libraries are “arrows”, “automata”, “back-


7.4 PGF/TikZ grounds”, “calendar”, “chains”, “matrix”, “mindmap”,
“patterns”, “petri”, “shadows”, “shapes.geometric”,
“shapes.misc”, “spy”, “trees”.
Drawing commands have to be enclosed in an tikzpicture
environment
\begin{tikzpicture}[⟨options⟩] ⟨tikz commands⟩
\end{tikzpicture}

or alternatively
\tikz[⟨options⟩]{⟨tikz commands⟩}

One possible option useful for inlined graphics is


baseline=⟨dimension⟩
Example of graphics done with Tikz. Note the slightly translucent
top layer.
Without that option the lower end of the picture is put on
One way to draw graphics directly with TeX commands the baseline of the surrounding text. Using this option,
is PGF/TikZ. TikZ can produce portable graphics in both you can specify that the picture should be raised or low-
PDF and PostScript formats using either plain (pdf)TEX, ered such that the height ⟨dimension⟩ is on the baseline.
(pdf)Latex or ConTEXt. It comes with very good Another option to scale the entire picture is
documentation and an extensive collection of examples:
http://www.texample.net/tikz/ scale=⟨factor⟩

PGF (“portable graphics format”) is the basic layer, pro-


viding a set of basic commands for producing graphics, or different for height and width, e.g:
and TikZ (“TikZ ist kein Zeichenprogramm”) is the fron- xscale=2.5, yscale=0.5
tend layer with a special syntax, making the use of PGF
easier. TikZ commands are prevalently similar to Meta-
font, the option mechanism is similar to PsTricks syntax.
While the previous systems (picture, epic, pstricks or
7.4.2 Specifying Coordinates
metapost) focus on the how to draw, TikZ focuses more
on the what to draw. One could say that TikZ is to draw- Coordinates are specified in round brackets in an arbi-
ing in LaTeX as LaTeX is to digital typesetting. It’s rec- trary TEX dimension either using Cartesian coordinates
ommended to use it if your LaTeX distribution includes (comma separated), e.g. 1cm in the x direction and 2pt
it. in the y direction

Other packages building on top of TikZ (e.g., (1cm,2pt)


for drawing electrical circuits) can be found here:
http://ftp.dante.de/tex-archive/help/Catalogue/bytopic. or using polar coordinates (colon separated), e.g. 1cm in
144 CHAPTER 7. CREATING GRAPHICS

30 degree direction dotted”, “densely dotted”, “loosely dotted”, “double”.


(30:1cm) Options for filling paths are e.g. “fill=<fill color>", “pat-
tern=<name>", “pattern color=<color>"
Without specifying a unit (1,2), the standard one is cm Straight lines are given by coordinates separated by a dou-
(1cm,2cm). ble minus,
Relative coordinates to the previous given point are given The first coordinate represents a move-to operation. This
by adding one or two plus signs in front of the coordinate. is followed by a series of “path extension operations”, like
With "++" the last point of the path becomes the current "-- (coordinates)".
position, with "+" the previous point stays the current path The same path with some drawing options:
position. Example: 2 standard units to the right of the last
point used: A connected path can be closed using the "--cycle” oper-
ation:
++(2,0)
A further move-to operation in an existing path starts a
new part of the path, which is not connected to the pre-
vious part of the path. Here: Move to (0,0) straight line
7.4.3 Syntax for Paths to (2,0), move to (0,1) straight line to (2,1):
Connecting two points via straight lines that are only hor-
A path is a series of straight and curved line segments(in izontal and vertical, use for first horizontal then vertical
a simplified explanation). The instruction has to end with
\draw (0,0) -| (1,1);
a semicolon.
\path[<options>]⟨specification⟩;
or for first vertical then horizontal
\draw (0,0) |- (1,1);
One instruction can spread over several lines, or several
instructions can be put on one line.
Curved paths using a Bezier curve can be created using
Options for path actions are e.g: “draw”, “fill”, “pattern”,
the "..controls() ..()" command, with one or two control
“shade” (filling, in which its color changes smoothly from
points.
one to another), “clip” (all subsequent drawings up to the
end of the current scope are clipped against the current User-defined paths can be created using the “to” oper-
path and the size of subsequent paths will not be impor- ation. Without an option it corresponds to a straight
tant for the picture size), “use as bounding box”. line, exactly like the double minus command. Using the
“out” and “in” option a curved path can created. E.g.
The "\path” command with these options can be com-
"[out=135,in=45]" causes the path to leave at an angle of
bined to: "\draw”, "\fill”, "\filldraw”, "\pattern”, "\shade”,
135 degree at the first coordinate and arrive at an angle
"\shadedraw”, "\clip”, "\useasboundingbox” .
of 45 degree at the second coordinate.
Geometric path options: “rotate=<angle in de-
For rectangles a special syntax exist. Use a move-to oper-
gree>", “xshift=<length>", “yshift=<length>", “scal-
ation to one corner and after “rectangle” the coordinates
ing=<factor>", “xscale=<factor>", “yscale=<factor>".
of the diagonal corner. The last one becomes the new
Color options for drawing paths: “color=<color name>", current point.
“draw=<line color>", “opacity=<factor>". Following
The fill color “green!20!white” means 20% green and
colors are predefined: red, green, blue, cyan , magenta,
80% white mixed together.
yellow, black, gray, darkgray, lightgray, brown, lime,
olive, orange, pink, purple, teal, violet and white. Circles and ellipses paths are defined beginning with their
center then using the “circle command” either with one
Line width options: “line width=<dimension>", and ab-
length as radius of a circle or with two lengths as semi-
breviations “ultra thin” for 0.1pt, “very thin” for 0.2pt,
axes of an ellipse.
“thin” for 0.4pt (the default width), “semithick” for 0.6pt,
“thick” for 0.8pt, “very thick” for 1.2pt, “ultra thick” for The command “arc” creates a part of a circle or an ellipse:
1.6pt. Or in an alternative syntax:
Line end, line join options: “line cap=<type: round, \draw (0,0) arc[radius = 8mm, start angle= 0, end angle=
rect, or butt>", “arrows=<start arrow kind>-<end arrow 270]; \draw (0,0) arc[x radius = 1.75cm, y radius = 1cm,
kind>", “rounded corners”, “rounded corners=<size>", start angle= 0, end angle= 315];
“line join=<type: round, bevel, or miter>".
Line pattern options: “dash pattern=<dash pattern>" (e.g. There are many more predefined commands for special
“dash pattern=on 2pt off 3pt on 4pt off 4pt”), “dash paths, like “grid”, “parabola”, “sin”, “cos” (sine or cosine
phase=⟨dash phase⟩", “solid”, “dashed”, “dotted”, “dash-
7.4. PGF/TIKZ 145

curve in the interval [0,π/2]). chor=south”), below (“below” or “anchor=north”). Com-


The option “help lines” denotes “fine gray”. binations are also possible, like “anchor=north east” or
“below left”.
To add arrow tips there are simple options for the drawing
command: \fill[fill=yellow] (0,0) node {1st node} -- (1,1)
node[circle,inner sep=0pt,draw] {2nd node} -- (0,2)
A loop can be realized by "\foreach ⟨variable⟩ in {⟨list of node[fill=red!20,draw,double,rounded corners] {3rd
values⟩} ⟨commands⟩". node};
PGF also has a math engine which enables you to plot
functions: To place nodes on a line or a curve use the
\draw [domain=<xmin>:<xmax>] plot (\x, {function}); “pos=<fraction>" option, where fraction is a float-
ing point number between 0 representing the previous
coordinate and 1 representing the current coordinate.
Many functions are possible, here a selection: facto-
rial(\x), sqrt(\x), pow(\x,y), exp(\x), ln(\x), log10(\x), \draw (0,0) -- (3,1) node[pos=0]{0} node[pos=0.5]{1/2}
log2(\x), abs(\x), mod(\x,y), round(\x), floor(\x), ceil(\x), node[pos=0.9]{9/10};
sin(\x), cos(\x), tan(x), min(\x,y,), max(\x,y). The
trigonometric functions assume that x is in degrees; if x There exist some abbreviations: “at start” for “pos=0”,
is expressed in radians use e.g. sin(\x r). Two constants “very near start” for “pos=0.125”, “near start” for
can be useful: e, which is equal to 2.718281828, and pi, “pos=0.25”, “midway” for “pos=0.5”, “near end” for
which is equal to 3.141592654. “pos=0.75”, “very near end” for “pos=0.875”, “at end”
An example with two functions: for “pos=1”.
The “sloped” option causes the node to be rotated to be-
come a tangent to the curve.
7.4.4 Nodes Since nodes are often the only path operation on paths,
there are special commands for creating paths containing
A node is typically a rectangle or circle or another simple only a node, the first with text ouput, the second without:
shape with some text on it. In the simplest case, a node is
just some text that is placed at some coordinate. Nodes \node[<options>](<name>) at (<coordinate>){<text>};
are not part of the path itself, they are added to the picture \coordinate[<options>](<name>) at (<coordinate>);
after the path has been drawn.
Inside a path operation use the following syntax after a One can connect nodes using the nodes’ labels as coordi-
given coordinate: nates. Having "\path(0,0) node(x) {} (3,1) node(y) {};"
defined, the node at (0,0) got the name "(x)" and the one
node[<options>](<name>){<text>} at (3,1) got a label "(y)".
\path (0,0) node(x) {} (3,1) node(y) {}; \draw (x) -- (y);
The "(<name>)" is a name for later reference and it is op-
tional. If you only want to name a certain position without
writing text there are two possibilities: Equivalent to

node[<options>](<name>){} coordi- \coordinate (x) at (0,0); \coordinate (y) at (3,1); \draw


nate[<options>](<name>) (x) -- (y);

Writing text along a given path using the node command Multiline text can be included inside a node. A new
is shown as simple example: line is indicated by double backslash "\\", but additionally
you have to specify the alignment using the node option
\draw[dotted] (0,0) node {1st node} -- (1,1) node {2nd “align=". Here an example:
node} -- (0,2) node {3rd node} -- cycle;
\filldraw (0,0) circle (2pt) node[align=left, below] {test
1\\is aligned left} -- (4,0) circle (2pt) node[align=center,
Possible options for the node command are e.g. “in- below] {test 2\\is centered} -- (8,0) circle (2pt)
ner sep=<dimension>", “outer sep=<dimension>", node[align=right, below] {test 3\\is right aligned};
“minimum size=<dimension>", “shape as-
pect=<aspect ratio>", “text=<color>", “font=",
“align=<left_right_center>". Path construction operations try to be clever, such that the
path starts at the border of the node’s shape and not from
A node is centered at the current coordinate by default. the node’s center.
Often it would be better to have the node to the besides
the actual coordinate: Right (“right” or “anchor=west”), \path (0,0) node(x) {Hello World!} (3,1)
left (“left” or “anchor=east”), above (“above” or “an- node[circle,draw](y) {$\int_1^2 x \mathrm d x$};
146 CHAPTER 7. CREATING GRAPHICS

\draw[->,blue] (x) -- (y); \draw[->,red] (x) -| node[near node[right] {$f(x) = \frac{1}{20} \mathrm e^x$};
start,below] {label} (y); \draw[->,orange] (x) .. controls \end{tikzpicture} \end{document}
+(up:1cm) and +(left:1cm) .. node[above,sloped]
{label} (y);

Once the node x has been defined, you can use anchors 7.5 PSTricks
as defined above relative to (x) as "(x.<anchor>)", like
"(x.north)". PSTricks is a set of extensions. The base package is
pstricks, other packages may be loaded when required.
The xcolor extension gets loaded along PSTricks, so there
7.4.5 Examples is no need to load it manually.

Example 1 PSTricks has one technical specification: it uses


PostScript internally, hence the name. Thus you cannot
\documentclass{article} \usepackage{tikz} \be- use the pdftex or pdflatex compilers, you will need to use
gin{document} \begin{tikzpicture} \draw[thick,rounded dvips to get your proper document. It is still possible to
corners=8pt] (0,0) -- (0,2) -- (1,3.25) -- (2,2) -- (2,0) get PDF from PS files thanks to ps2pdf. There is also the
-- (0,2) -- (2,2) -- (0,0) -- (2,0); \end{tikzpicture} possibility to use the PDFTricks extension, which makes
\end{document} it feasible to use pdflatex together with PSTricks com-
mands.
Example 2 However, if you have installed the package xetex-pstricks,
\documentclass{article} \usepackage{tikz} \be- you can use pstricks with xetex or xelatex without modi-
gin{document} \begin{tikzpicture}[scale=3] fication of source file.
\draw[step=.5cm, gray, very thin] (−1.2,−1.2) grid
(1.2,1.2); \filldraw[fill=green!20,draw=green!50!black]
(0,0) -- (3mm,0mm) arc (0:30:3mm) -- cycle; \draw[->] 7.5.1 The pspicture environment
(−1.25,0) -- (1.25,0) coordinate (x axis); \draw[-
>] (0,−1.25) -- (0,1.25) coordinate (y axis); \draw PSTricks commands are usually placed in a pspicture en-
(0,0) circle (1cm); \draw[very thick,red] (30:1cm) vironment.
-- node[left,fill=white] {$\sin \alpha$} (30:1cm \begin{pspicture}(x1,y1) % ... \end{pspicture}
|- x axis); \draw[very thick,blue] (30:1cm |- x
axis) -- node[below=2pt,fill=white] {$\cos \alpha$}
The first argument between parentheses specifies the co-
(0,0); \draw (0,0) -- (30:1cm); \foreach \x/\xtext
ordinates of the upper-right corner of the picture. The
in {−1, −0.5/-\frac{1}{2}, 1} \draw (\x cm,1pt)
bottom-left corner is at (0,0) and is placed at the refer-
-- (\x cm,−1pt) node[anchor=north,fill=white]
ence point of the next character in the LaTeX document.
{$\xtext$}; \foreach \y/\ytext in {−1, −0.5/-
\frac{1}{2}, 0.5/\frac{1}{2}, 1} \draw (1pt,\y cm) -- It is also possible to specify the coordinates (x0,y0) of the
(−1pt,\y cm) node[anchor=east,fill=white] {$\ytext$}; bottom-left corner:
\end{tikzpicture} \end{document} \begin{pspicture}(x0,y0)(x1,y1) % ... \end{pspicture}

Example 3: A Torus Thus the size of the picture is (x1-x0)x(y1-y0). The de-
\documentclass{article} \usepackage{tikz} \be- fault unit for coordinates is centimeters (cm); this can be
gin{document} \begin{tikzpicture} \draw (−1,0) changed with \psset, as in \psset{unit=1bp}. Any TeX
to[bend left] (1,0); \draw (−1.2,.1) to[bend right] dimension is allowed.
(1.2,.1); \draw[rotate=0] (0,0) ellipse (100pt and 50pt);
\end{tikzpicture} \end{document}
7.5.2 Fundamental objects
Example 4: Some functions Lines and polylines
\documentclass{article} \usepackage{tikz} \be-
gin{document} \begin{tikzpicture}[domain=0:4] A simple line gets printed with
\draw[very thin,color=gray] (−0.1,−1.1) grid (3.9,3.9); \psline(x0,y0)(x1,y1)
\draw[->] (−0.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,−1.2) -- (0,4.2) node[above] {$f(x)$};
\draw[color=red] plot (\x,\x) node[right] {$f(x) =x$}; To get a vector, add an arrow as parameter:
\draw[color=blue] plot (\x,{sin(\x r)}) node[right] {$f(x) \psline{->}(x0,y0)(x1,y1)
= \sin x$}; \draw[color=orange] plot (\x,{0.05*exp(\x)})
7.5. PSTRICKS 147

You can add as many points as you want to get a polyline: will print a symetric parabola with vertical asymptote,
\psline(x0,y0)(x1,y1)(x2,y3)…(xn,yn) vertex (x1,y1) and ending at (x0,y0).
Use \psbezier to print a Bézier curve with an arbitrary
To get rounded corners, add the following option: number of control points. Arcs have at most 4 control
points. Use the showpoints=true option to print the con-
\psline[linearc=0.2]{->}(0,0)(2,1)(1,1) trol points and the tangents.
Use \pscurve to print the interpolation of the given points.
or The \psecurve command omits the first and the last arcs.
\psline[linearc=0.2,arrows=->](0,0)(2,1)(1,1)
7.5.3 Text
Use
Rectangles
\rput(x,y){text}
\psframe(x0,y0)(x1,y1) \psframe*(x0,y0)(x1,y1)
to print text. Provide an angle to rotate the text.
The starred version prints a filled rectangle. Use the fol- \rput{angle}(x,y){text}
lowing parameter to get rounded corners:
\psframe[framearc=0.2](x0,y0)(x1,y1) You can provide the anchor of the text which will be at
the specified coordinate.
\rput[t]{45}(5,5){text}
Polygons
Available anchors:
Polygons are always closed. The syntax is the same as for
\psline: • B, Bl, Br: baseline center, left and right.
\pspolygon(x0,y0)(x1,y1)(x2,y2)...(xn,yn) • t, tl, tr: top center, left and right.
• b, bl, br: bottom center, left and right.
As for rectangles, the starred version prints a filled poly-
gon. And the linearc=0.2 option will print rounded cor-
ners. There is also the \uput command with further options:
\uput{distance}[angle](x,y){text}

Circles, arc and ellipses


The distance parameter is the distance from the coordi-
nate.
Starred version fills the shape.
PSTricks features several frame style for text.
For circles, you need to provide center coordinates and
radius:
• \psframebox{text}: rectangle.
\pscircle(x,y){r}
• \psdblframebox{text}: double rectangle.

To restrict the drawing to an arc, append the starting and • \psshadowbox{text}: shaded rectangle.
ending angles in trigonometric notation:
• \pstcirclebox{text}: circle.
\psarc(x,y){r}{angle1}{angle2}
• \psovalbox{text}: oval.

Finally, ellipses: • \psdiabox{text}: diamond.


\psellipse(x,y)(horizontal_axis,vertical_axis) • \pstribox{text}: triangle.

Example:

Curves \rput(5,5){\psdiabox*[fillcolor=green]{text}}

\psparabola(x0,y0)(x1,y1) Using the pst-text extension, it is possible to draw a text


path.
148 CHAPTER 7. CREATING GRAPHICS

\pstextpath{shape}{text} Axis

To print a text following a path without printing the path, If you want to add axes, use the pstricks-add extension
you need to use \psset{linestyle=none}. with the following commands:

Example: \psaxes(xmin,ymin)(xmax,ymax)
\psaxes(x0,y0)(xmin,ymin)(xmax,ymax)
\usepackage{pst-text} % ... \be-
gin{pspicture}(5,5) \psset{linestyle=none} \ps-
textpath{\psline(0,0)(1,1)(2,0)}{triangle text} (xmin,ymin) and (xmax,ymax) being the extreme, (x0,y0)
\end{pspicture} being the intersection.

Options

7.5.4 Grids
• Dx=value and Dy=value defines the spacing be-
tween graduations.
Without any parameter, the \psgrid command will print
a grid all over the pspicture, with a spacing of 0.2 (i.e. • comma lets you use the comma as decimal separa-
2mm). You can specify parameters: tor.

• \psgrid(xmax,ymax): prints a grid from (0,0) to • As for lines, {->} adds arrows on axes.
(xmax,ymax).
Example
• \psgrid(xmin,ymin)(xmax,ymax): prints a grid from
(xmin,ymin) to (xmax,ymax).
\usepackage{pstricks-add} %
• \psgrid(x0,y0)(xmin,ymin)(xmax,ymax): prints a ... \begin{pspicture}(−1,−1)(5,5)
grid from (xmin,ymin) to (xmax,ymax), one of the \psaxes[comma,Dx=0.5,Dy=0.5]{->}(0,0)(3,3)
node is at (x0,y0). \end{pspicture}
• griddots=value: the full line of the main graduations
is replaced by a dotted line. The value is the number
of dots per graduation.
7.5.5 Generic parameters
• subgriddots=value: same as griddots but for sub-
graduations. All shapes

• gridcolor=color,subgridcolor=color: color of gradu- These are to be added between square brackets.


ations and sub-graduations.
• gridwidth=value,subgridwidth=value: width of the • linewidth=value: if value is without unit, then the
lines. default unit is used.

• subgriddiv=value: number of subgraduations be- • linecolor=color: color is as defined by the xcolor-


tween two main graduations. package.
• gridlabels=value: size of the label numbers. • linestyle=value: value is one of dashed,dotted.
• ticksize=value: self-explanatory. • doubleline=true.
• ticksize=valueneg valuepos: same as above, but val- • showpoints=true: highlights points.
ueneg specifies the size for negative coordinates, val-
uepos for positive coordinates. • dotscale=value specifies the size of the points.
• ticklinestyle=value: self-explanatory. value may be • dotstyle=value where value is among:
one of solid, dashed, dotted. This is useful for huge • *: disc
graduations (i.e. ticksize is high). • o: circle
• +,x: cross
Example
• square, squarre*: starred version is filled.
\psgrid[griddots=5, subgriddiv=0, • diamond, diamond*
gridlabels=0pt](−1,−1)(5,5) • triangle, triangle*
• etc.
7.5. PSTRICKS 149

For example • hatchcolor=color.


\pscircle[linewidth=0.2,linestyle=dashed,linecolor=blue](0,0){1}
• hatchwidth=value.
• hatchsep=value.
To apply parameters globally:
\psset{linewidth=0.2,linestyle=dashed,linecolor=blue} • hatchangle=value.
\pscircle(0,0){1}
Example:
This command also lets you change the default unit for \pscircle[hatchcolor=blue,fillstyle=vlines](0,0){1}
lengths.

• unit=value
7.5.6 Object location
• xunit=value and yunit=value
The \rput and \uput commands can be used to move any
object.
value is a number with or without unit. This changes the
scale of the drawings, but will not change the width of
lines. Example

\begin{pspicture}(5,5) \psline{->}(0,0)(1,1)
Open shapes \rput(1,1){\psline{->}(0,0)(1,1)} \end{pspicture}

You can define the extreme of an open shape (line, poly-


line, arc, etc.) with an optional parameter {symbol1- or
symbol2}. There is a decent list of available symbols. \begin{pspicture}(5,5) \psline{->}(0,0)(1,1) \psline{-
>}(1,1)(2,2) \end{pspicture}
• < or >: arrow.
• << or >>: double arrow. You can repeat the operation with \multirput:
\multirput(x0,y0)(xoffset, yoffset){times}{object}
• |: bar.
• |*: centered bar. You can use the same options as for \rput:
• oo: circle. \multirput[reference]{angle}(x0,y0)(xoffset, yoff-
set){times}{object}
• o: centered circle.
• **: disk. With no text but with graphics only, you can use the \mul-
tips command:
• *: centered disk.
\multips(x0,y0)(xoffset, yoffset){times}{object} \mul-
• |< or >|: arrow plus bar. tips{angle}(x0,y0)(xoffset,yoffset){times}{object}
• cc: rounded extreme.
• c: centered rounded extreme.
7.5.7 The PDFTricks extension
Example: The original PSTricks package does not work with pdfla-
\psline{|->>}(x0,y0)(x1,y1) tex, but thankfully PDFTricks allows us to bypass this
limitation.

Usage
Closed shapes

For closed shape you may define the fillstyle. • Declare the PDFTricks packages in the preamble.
• Place all PSTricks extensions in a psinputs environ-
• fillstyle=value: pattern. Possible values: crosshatch, ment; place all PSTricks commands in a pdfpic en-
crosshatch*, vlines, vlines*, hlines, hlines*, solid. vironment.
• fillcolor=color. • Compile with pdflatex -shell-escape <file>.
150 CHAPTER 7. CREATING GRAPHICS

The -shell-escape parameter enables shell command calls. The modifiers between the slashes define how the curves
It is required for PDFTricks to run. are drawn. Xy-pic offers many ways to influence the
drawing of curves; for more information, check the Xy-
pic documentation.
Example
If you are interested in a more thorough introduction then
consult the Xy-pic Home Page, which contains links to
\documentclass{article} \usepackage{pdftricks} several other tutorials as well as the reference documen-
\begin{psinputs} \usepackage{pstricks} \usepack- tation.
age{multido} \end{psinputs} % ... \begin{document}
% ... \begin{pdfpic} \psset{unit=\linewidth} \be-
gin{pspicture}(0,0)(10,10) [...] \end{pspicture}
\end{pdfpic} % ... \end{document} 7.7 Creating 3D graphics
For creating three-dimensional graphics, there is basic
Another way to use PSTricks with pdflatex is the pst-pdf
functionality in the PGF/TikZ package, although drawing
package.
3D graphics with PGF/TikZ is very non-flexible, mainly
because it lacks functionality for identifying the surfaces
that are covered by other surfaces and should be excluded
7.6 Xy-pic from the rendered image.
A package that can handle this correctly is the pst-
xy is a special package for drawing diagrams. To use it, solides3d package.
simply add the following line to the preamble of your doc- Another way to create 3D graphics is to use Asymptote.
ument:
Yet another way to create 3D graphics is to use Sketch.
\usepackage[all]{xy}

where “all” means you want to load a large standard set


of functions from Xy-pic, suitable for developing the kind
of diagrams discussed here.
The primary way to draw Xy-pic diagrams is over a
matrix-oriented canvas, where each diagram element is
placed in a matrix slot:
The \xymatrix command must be used in math mode.
Here, we specified two lines and two columns. To make
this matrix a diagram we just add directed arrows using
the \ar command.
The arrow command is placed on the origin cell for the
arrow. The arguments are the direction the arrow should
point to (up, down, right and left).
To make diagonals, just use more than one direction. In
fact, you can repeat directions to make bigger arrows.
We can draw even more interesting diagrams by adding
labels to the arrows. To do this, we use the common su-
perscript and subscript operators.
As shown, you use these operators as in math mode. The
only difference is that that superscript means “on top of
the arrow”, and subscript means “under the arrow”. There
is a third operator, the vertical bar: | It causes text to be
placed in the arrow.
To draw an arrow with a hole in it, use \ar[...]|\hole. In
some situations, it is important to distinguish between dif-
ferent types of arrows. This can be done by putting labels
on them, or changing their appearance
Notice the difference between the following two dia-
grams:
Chapter 8

Programming

8.1 Macros digits cannot be used to name macros — invalid charac-


ters will error out at compile-time.
Documents produced with the commands you have LaTeX will not allow you to create a new command that
learned up to this point will look acceptable to a large would overwrite an existing one. But there is a special
audience. While they are not fancy-looking, they obey command in case you explicitly want this: \renewcom-
all the established rules of good typesetting, which will mand. It uses the same syntax as the \newcommand com-
make them easy to read and pleasant to look at. How- mand.
ever, there are situations where LaTeX does not provide
In certain cases you might also want to use the \provide-
a command or environment that matches your needs, or
command command. It works like \newcommand, but if
the output produced by some existing command may not
the command is already defined, LaTeX will silently ig-
meet your requirements.
nore the new command.
In this chapter, we will try to give some hints on how to
With LaTex2e, it is also possible to add a default param-
teach LaTeX new tricks and how to make it produce out-
eter to a command with the following syntax:
put that looks different from what is provided by default.
If the default parameter of \newcommand is present, then
LaTeX is a fairly high-level language compared to Plain
the first of the number of arguments specified by num is
TeX and thus is more limited. The next chapter will focus
optional with a default value of default; if absent, then all
on Plain TeX and will explain advanced techniques for
of the arguments are required.
programming.

8.1.1 New commands Note When the command is used with an explicit first
parameter it is given enclosed with brackets (here
To add your own commands, use the "[lots of users]").
command. Basically, the command requires two argu-
ments: the name of the command you want to create,
and the definition of the command. Note that the com-
mand name can but need not be enclosed in braces, as Here is a common example: if you are writing a book
you like. The num argument in square brackets is optionalabout Mathematics and you have to use vectors, you have
and specifies the number of arguments the new command to decide how they will look. There are several different
standards, used in many books. If a is a vector, some
takes (up to 9 are possible). If missing it defaults to 0, i.e.
no argument allowed. people like to add an arrow over it ( ⃗a ), other people write
it underlined (a); another common version is to write it
The following two examples should help you to get the bold (a). Let us assume you want to write your vectors
idea. The first example defines a new command called with an arrow over them; then add the following line in
\wbal that will print “The Wikibook about LaTeX”. Such your mystyle.sty.
a command could come in handy if you had to write the
title of this book over and over again. and write your vectors inside the new \myvec{...} com-
mand. You can call it as you wish, but you'd better choose
The next example illustrates how to define a new com- a short name because you will probably write it very of-
mand that takes one argument. The #1 tag gets replaced ten. Then, if you change your mind and you want your
by the argument you specify. If you wanted to use more vectors to look differently you just have to change the
than one argument, use #2 and so on, these arguments are definition of your \myvec{...}. Use this approach when-
added in an extra set of brackets. ever you can: this will save you a lot of time and increase
Name your new command \wbalTwo and not \wbal2 as the consistency of your document.

151
152 CHAPTER 8. PROGRAMMING

DeclareRobustCommand Also, if you're still having problems with extra space be-
ing appended at the end of your environment when using
Some commands are fragile, that is they fail in some en- the \input for external source, make sure there is no space
vironments. If a macro works in body text but not in (for between the beginning, sourcing, and end of the environ-
example) a figure caption, it’s worth trying to replace the ment, such as:
\newcommand{\MyCommand}... declaration with \De- or
clareRobustCommand{\MyCommand}... in the pream-
ble. This is especially true for macros which, when ex-
panded, produce text that is written to a .aux file.
8.1.3 Declare commands within newenvi-
ronment
8.1.2 New environments
New commands can be declared within newenvironment.
Just as with the \newcommand command, there is a com- Commands declared within the newenvironment refer to
mand to create your own environments. The \newenvi- their arguments by doubling the # character. In the fol-
ronment command uses the following syntax: lowing example, a new environment is declared along
with a nested command:
Again \newenvironment can have an optional argument.
When the \begin{name} command (which starts the en- If, by mistake, the arguments passed to the \topics macro
vironment) is encountered, the material specified in the are defined with a single # character, the following error
before argument is processed before the text in the en- message will be thrown:
vironment gets processed. The material in the after ar- ! Illegal parameter number in definition of \topics.
gument gets processed when the \end{name} command
(which ends the environment) is encountered.
The num argument is used the same way as in the \new- 8.1.4 Extending the number of arguments
command command. LaTeX makes sure that you do not
define an environment that already exists. If you ever The xkeyval packages will let you define key/value op-
want to change an existing command, you can use the tions for commands.
\renewenvironment command. It uses the same syntax as
the \newenvironment command. The package is quite complete and documentation is ex-
haustive. We recommend that package developers read
The example below illustrates the usage of the \newenvi- it.
ronment command:
Let’s provide a simple example[1] :

Unmatched braces
8.1.5 Arithmetic
Often, part of the motive behind creating an environment
is to surround its body in a grouping of braces. How- LaTeX can manipulate numbers.
ever, this requires unmatched braces to appear in both the
beginning and end portions of the environment declara- The calc package provides the common infix notation.
tion, which will prevent the document from compiling. For high-precision computations, you can use the fp[2]
To solve this issue, use the TeX synonyms \bgroup and package.
\egroup instead of typing { and } in this case.

Extra space 8.1.6 Conditionals

When creating a new environment you may easily get LaTeX can use conditionals thanks to the ifthen package.
bitten by extra spaces creeping in, which can potentially
have fatal effects. For example when you want to create a
title environment which suppresses its own indentation as 8.1.7 Loops
well as the one on the following paragraph. The \ignores-
paces command in the begin block of the environment The PGF/TikZ extension provides the \foreach com-
will make it ignore any space after executing the begin mand.
block. The end block is a bit more tricky as special pro-
cessing occurs at the end of an environment. With the If you are only using \foreach and not drawing graphics,
\ignorespacesafterend LaTeX will issue an \ignorespaces you may instead use the pgffor package directly.
after the special ‘end’ processing has occurred. Alternatively you can check out the multido package.
8.2. PLAIN TEX 153

8.1.8 Strings 8.2 Plain TeX


xstring provides a lot of features. From CTAN: While you play with LaTeX macros, you will notice that it
is quite limited. You may wonder how all these packages
• testing a string’s contents you are using every day have been implemented with so
• extracting substrings little. In fact, LaTeX is a set of Plain TeX macros and
most packages use Plain TeX code. Plain TeX is much
• substitution of substrings more low-level, it has much more capabilities at the cost
• string length of a steep learning curve and complex programming.

• position of a substring Up to a few exceptions, you can use the full Plain TeX
language within a valid LaTeX document whereas the op-
• number of recurrences of a substring posite is false.

Examples:
8.2.1 Vocabulary
8.1.9 LaTeX Hooks To avoid confusion it seems necessary to explain some
terms.
LaTeX provide two hooks:

• \AtBeginDocument will let you specify a set • A group is everything after an opening brace and
of commands that will be executed when \be- before the matching closing brace.
gin{document} is met.
• A token is a character, a control sequence, or a
• \AtEndDocument does the same for group.
\end{document}.
• A control sequence is anything that begins with a \. It
This gives you some more flexiblity for macros. It can is not printed as is, it is expanded by the TeX engine
be useful to override settings that get executed after the according to its type.
preamble. These hooks can be called several times. The
commands will be executed in the order they were set. • A command (or function or macro) is a control se-
For instance, let’s replace the page numbers with old- quence that may expand to text, to (re)definition of
stylenums: control sequences, etc.

There are also hooks for classes and packages. See • A primitive is a command that is hard coded in the
Creating Packages. TeX engine, i.e. it is not written in Plain TeX.

• A register is the TeX way to handle variables. They


8.1.10 Command-line LaTeX are limited in numbers (256 for each type of register
in classic TeX, 32767 in e-TeX).
If you work on a Unix-like OS, you might be using Make-
files or any kind of script to build your LaTeX projects. • A length is a control sequence that contains a length
In that connection it might be interesting to produce dif- (a number followed by a unit). See Lengths.
ferent versions of the same document by calling LaTeX
with command-line parameters. If you add the following • A font is a control sequence that refers to a font file.
structure to your document: See Fonts.
Now you can call LaTeX like this:
• A box is an object that is made for printing. Any-
latex '\providecommand{\blackandwhite}{true}\input{test.tex}' thing that ends on the paper is a box: letters, para-
First the command \blackandwhite gets defined and then graphs, pages... See Boxes.
the actual file is read with input. By setting \blackand-
white to false the color version of the document would be • A glue is a certain amount of space that is put be-
produced. tween boxes when they are being concatenated.

• A counter is a register containing a number. See


8.1.11 Notes and References Counters.

[1] tex.stackexchange.com
There may be more terms, but we hope that it will do it
[2] ctan.mackichan.com for now.
154 CHAPTER 8. PROGRAMMING

8.2.2 Catcodes \makeatletter and \makeatother

In TeX some characters have a special meaning that is not If you have done a bit of LaTeX hacking, you must
to print the associated glyph. For example, \ is used to in- have encountered those two commands, \makeatletter
troduce a control sequence, and will not print a backslash and \makeatother.
by default. In TeX the '@' characters belongs to catcode 11 letters by
To distinguish between different meanings of the charac- default. It means you can use it for macro names. LaTeX
ters, TeX split them into category codes, or catcodes for makes use of the catcode to specify a rule: all non-public,
short. There are 16 category codes in TeX. internal macros that are not supposed to be accessed by
the end-user contains at least one '@' character in their
A powerful feature of TeX is its ability to redefine the
name. In the document, LaTeX changes the catcode of
language itself, since there is a \catcode function that will
'@' to 12, others.
let you change the category code of any characters.
That’s why when you need to access LaTeX internals, you
However, this is not recommended, as it can make code
must enclose all the commands accessing private func-
difficult to read. Should you redefine any catcode in a
tions with \makeatletter and \makeatother. All they do is
class or in a style file, make sure to revert it back at the
just changing the catcode:
end of your file.
If you redefine catcodes in your document, make sure to
do it after the preamble to prevent clashes with package 8.2.3 Plain TeX macros
loading.
\newcommand and \renewcommand are LaTeX-specific
control sequences. They check that no existing command
Active characters gets shadowed by the new definition.
In Plain TeX, the primitives for macro definition make no
Active characters resemble macros: they are single char- check on possible shadowing. It’s up to you to make sure
acters that will expand before any other command. you are not breaking anything.
Note that an active character needs to be directly followed The syntax is
by a definition, otherwise the compilation will fail.
You can use (almost) any sequence of character between
arguments. For instance let’s write a simple macro that
will convert the decimal separator from point to comma.
Examples
First try:
Texinfo This will print (123,4)56. We added the parentheses just
to highlight the issue here. Each parameter is the shortest
possible input sequence that matches the macro defini-
Texinfo uses a syntax similar to TeX with one major dif- tion, separators included. Thus #1 matches all characters
ference: all functions are introduced with a @ instead of up to the first point, and #2 matches the first token only,
a \. This is not by chance: it actually uses TeX to print i.e. the first character, since there is no separator after it.
the PDF version of the files. What it basically does is in-
putting texinfo.tex which redefines the control sequence Solution: add a second separator. A space may seem con-
character. Possible implementation: venient:

With this redefinition, the '@' should now introduce ev- As a general rule, everytime you expect several parame-
ery command, while the '\' will actually print a backslash ters with specific separators, think out the last separator.
character. If you do not want to play with separators, then Plain TeX
macros are used just as LaTeX macros (without default
parameter):
Itemize

Expanded definitions
Some may find the LaTeX syntax of list environments a
bit cumbersome. Here is a quick way to define a wiki-like TeX has another definition command: \edef, which stands
itemize: for expanded def. The syntax remains the same:
The content gets expanded (but not executed, i.e. printed)
Dollar and math at the point where \edef is used, instead of where the de-
fined macro is used. Macro expansion is not always ob-
If you have many 'dollar' symbols to print, you may be vious...
better off to change the math shift character. Example:
8.2. PLAIN TEX 155

Here the redefinition of \intro will have no effect on \ex- \futurelet<csname><token1><token2>... works a bit dif-
ample. ferently. token2 is assigned to csname; after that TeX
processes the <token1><token2>... sequence. So \fu-
turelet allows you to assign a token while using it right
Global definitions after.

Definitions are limited to their scope. However it might


be convenient sometimes to define a macro inside a group Special control sequence name
that remain valid outside the group, and until the end of
the document. This is what we call global definitions. Some macros may have a name that is not directly
writable as is. This is the case of macros whose name
You can also use the \global command with \edef.
is made up of macro names. Example:
Both commands have a shortcut:
The last line will print a sentence depending on the \status.
This command actually does the opposite of \string which
• \gdef for \global\def
prints a control sequence name without expanding it:
• \xdef for \global\edef
Controlling expansion
Long definitions
\expandafter{token1}{token2} will expand token2 be-
The previous definition commands would not allow you fore token1. It is sometimes needed when token2 expan-
to use them over multiple paragraphs, i.e. text containing sion is desired but cannot happen because of token1.
the \par command -- or double line breaks. \noexpand is useful to have fine grained control over what
You can prefix the definition with the \long command to gets expanded in an \edef. Example:
allow multi-paragraph arguments. \the control sequence will let you see the content of vari-
Example: ous TeX types:

• catcodes
Outer definitions
• chardef
This prefix macro prevent definitions from being used in
• font parameters
some context. It is useful to consolidate macros and make
them less error-prone because of bad contexts. Outer • internal parameters
macros are meant to be used outside of any context, hence
the name. • lengths
For instance the following code will fail: • registers
Outer macros are not allowed to appear in: • ...

• macro parameters Example:


• skipped conditional

• ...
8.2.4 Registers
Registers are kind of typed variables. They are limited
let and futurelet in numbers, ranging from 0 to 255. There are 6 different
types:
\let<csname><token> is the same as \ex- TeX uses some registers internally, so you would be better
pandafter\def\expandafter<csname>\expandafter{<content>}. off not using them.
It defines a new control sequence name which is equiva-
lent to the specified token. The token is usually another List of reserved registers:
control sequence.
• \box255 is used for the contents of a page
Note that \let will expand the token one time only, con-
trary to \edef which will expand recursively until no fur- • \count0-\count9 are used for page numbering
ther expansion is possible.
Example[1] : Scratch registers (freely available):
156 CHAPTER 8. PROGRAMMING

• \box0-\box254 depending on which value we want to set in our condi-


tional.
• \count255
3. Now we can use our conditional anywhere after in an
• \dimen0-\dimen9 if control structure.
A full example is:
• \muskip0-\muskip9

• \skip0-\skip9
Case statement
Assign register using the '=' control character. For box
registers, use the \setbox command instead. The syntax is \ifcase <num-
You may use one of the following reservation macro to ber><case0>\or<case1>\or...\else<defaultcase>\fi.
prevent any clash: If number is equal to the case number, its content will be
printed. Note that it starts at 0.
These macros use the following syntax: \new*<csname>.
Example: \else is used to specify the default case (whenever none of
the previous cases have matched).
These commands can not be used inside macros, other-
wise every call to the macro would reserve another regis-
ter.
You can print a register using the \the command. For 8.2.7 Loops
counters use the \number command instead. For boxes
use the \box command. The base syntax is
As always, content and true action are arbitrary TeX con-
tents. \if* refers to any of the conditionals. Note that
8.2.5 Arithmetic there is no false action, you cannot put an \else between
\if* and \repeat. In some case this will be the opposite
The arithmetic capabilities of TeX are very limited, al-
of what you want; you have to change the condition or to
though this base suffice to extend it to some interesting
define a new conditional using \newif. Example:
features. The three main functions:
The above code will print TeX ten times.
register may be of type count, dimen, muskip or skip. It
does not make sense for box nor toks.

8.2.8 Doing nothing


8.2.6 Conditionals
Sometimes it may be useful to tell TeX that you want to
The base syntax is
do nothing. There is two commands for that: \relax and
where \if* is one command among the following. \empty.
Example: Classic example:
The \relax prevents undesired behaviour if a plus or a mi-
Self defined conditionals nus is encounter after the command.
The difference between \empty and \relax lies in the ex-
You can create new conditionals (as a kind of boolean pansion: \empty disappears after macro expansion.
variables) with the \newif command. With this self de-
fined conditionals you can control the output of your code
in an elegant way. The best way to illustrate the use of
conditionals is through an example. 8.2.9 TeX characters
Two versions of a document must be generated. One ver-
sion for group A the other one for the rest of people (i.e. char
not belonging to group A):
We can print all characters using the \char {charcode}
1. We use \newif to define our conditional (i.e. boolean command. The charcode is actually the byte value. For
variable). example
2. In the following way we set a value (true or false) for Most characters correspond to the ASCII value (e.g. A-
our conditional Za-z), some replace the non-printable characters from
that is: ASCII.
8.3. CREATING PACKAGES 157

chardef and mathchardef Another problem arises: how to define a command whose
name is a variable? In most programming languages that’s
You can define control sequence to expand to a not possible at all. What we could be tempted to write is
specific char. The syntax is \chardef<control se-
It will fail for two reasons.
quence>=<charcode>. The following sequences do the
same thing.
1. The two last '#1' are supposed to refer to the argu-
Example: ments of the new macro, but they get expanded to
the \localedef macro first argument because they are
in the body of that macro.
Font encoding map
2. \#1 gets expanded to two tokens: '#' and '1', and the
We can use the above primitive to print the font encoding \def command will fail as it requires a valid control
map. sequence name.
Another version, with different fonts, one entry per line:
The solution to problem 1 is simple: use '##1', which will
expand to '#1' when the macro is executed.
8.2.10 Verbatim lines and spaces For problem 2, it is a little bit tricky. It is possible to
tell tex that a specific token is a control sequence. This is
It is rather confusing to discover (La)TeX treats all what the \csname...\endcsname is used for. However
whitespace as the same type of spacing glue. Plain TeX
provides some commands to preserve the spacing and will fail because it will redefine \csname to '#1', which is
newlines as you wrote it: not what we want, then tex will encounter \endcsname,
which will result in an error.
which means that you will probably need to combine your
own verbatim environment, and your command: We need to delay the expansion of \def, i.e. to
tell tex to expand the \csname stuff first, then to ap-
and then in your tex file: ply \def on it. There is a command for that: \ex-
pandafter{token1}{token2}. It will expand {token2} be-
fore {token1}.
8.2.11 Macros defining macros
Finally if we want to set language from command line, we
This is useful in some case, for example to define lan- must be able to set the \locale variable so that the one in
guage commands as explained in Multilingual versions, the source code is the default value that can be overridden
where the end user can write by the one in the command line. This can be done with
\provdecommand:
and make sure it switches to the appropriate Babel lan-
guage. The final code is
Let’s define a macros that will define language commands And you can compile with
for instance. These commands are simple: if the argu- latex '\providecommand\locale{en}\input{mydocument.tex}'
ment is the value of the \locale variable, then the corre-
sponding macro prints its content directly. Otherwise, it
does nothing. 8.2.12 Notes and References
Basicly, what we want to do is extremely simple: define a
[1] From tex.stackexchange.com: What is the difference be-
bunch of macros like this: tween \let and \edef?
In the previous snippet of code, only the \de command in
going to output its content, \en and \fr will print nothing Further reading
at all. That’s what we want. The problem arises when
you want to automate the task, or if you have a lot of • The TeXbook, Donald Knuth
languages, and you want to change the language selection.
You just have to move the #1, but that’s not convenient • TeX by Topic, Victor Eijkhout
and it makes it impossible to choose the Babel language • TeX for the Impatient, Paul W. Abrahams, Karl
from command line. Think this out... Berry and Kathryn A. Hargreaves
What we are going to do is to define the language com-
mands dynamically following the value of the \locale vari-
able (or any variable of your choice). Hence the use of 8.3 Creating Packages
the \equal command from the ifthen package.
Since it is hardly possible to write it in LaTeX, we will If you define a lot of new environments and commands,
use some Plain TeX. the preamble of your document will get quite long. In
158 CHAPTER 8. PROGRAMMING

this situation, it is a good idea to create a LaTeX package • Write whatever you want in it using all the LaTeX
or class containing all your command and environment commands you know. Normally you should define
definitions. It can be made dynamic enough to fit to all new commands or import other packages.
your future documents.
• \endinput: this must be the last command.
Classes are .cls files, packages are stored in .sty files. They
are very similar, the main difference being that you can
Once your package is ready, we can use it in any doc-
load only one class per document.
ument. Import your new package with the known com-
mand \usepackage{mypack}. The file custom.sty and the
LaTeX source you are compiling must be in the same di-
8.3.1 makeatletter and makeatother rectory.
By default, LaTeX will allow the use of the '@' characters For a more convenient use, it is possible to place the
for control sequences from within package and class files, package within $TEXMFHOME (which is ~/texmf by
but not from within an end-user document. This way it is default) according to the TeX Directory Structure (TDS).
possible to protect commands, i.e. to make them accessi- That would be
ble from packages only. $TEXMFHOME/tex/latex/custom/custom.sty
However it is possible to override this security with the On Windows '~' is often C:\Users\username.
duo \makeatletter and \makeatother. These commands
only make sense in a regular document, they are not You may have to run texhash (or equivalent) to make your
needed in package or class files. TeX distribution index the new file, thus making it avail-
able for use for any document. It will allow you to use
your package as detailed above, but without it needing to
8.3.2 Creating your own package be in the same directory as your document.

Your package can be made available in your document 8.3.3 Creating your own class
just like any other package: using the \usepackage com-
mand. Writing a package basically consists of copying It is also possible to create your own class file. The pro-
the contents of your document preamble into a separate cess is similar to the creation of your own package, you
file with a name ending in .sty. can call your own style file in the preamble of any docu-
Let’s write a first custom.sty file as an example package: ment by the command:
The name of the class file is then myclass.cls. Let’s write
• \NeedsTeXFormat{...} specifies which version of a simple example:
TeX or LaTeX is required at least to run your pack-
age. The optional date may be used to specify the • \ProvidesClass is the counterpart of \ProvidesPack-
version more precisely. age.
• \PassOptionsToClass and \PassOptionsToPackage
• \ProvidesPackage has to have the same name of the
are used to automatically invoke the corresponding
file without the extension. It tells LaTeX the name
options when the class or the package is loaded.
of the package and will allow it to issue a sensible
error message when you try to include a package • \DeclareOption*: the starred version lets you handle
twice. The date is important since it can be used non-implemented options.
by other package to specify the minimum version
requirement they need to use your package. • \ClassWarning will show the corresponding message
in the TeX compiler output.
• Next you may write some TeX or LaTeX code like
• \LoadClass specifies the unique parent class, if any.
loading package, but write only the bare minimum
needed for the package options set below.

• \RequirePackage is equivalent to \usepackage.


8.3.4 Hooks

• \DeclareOptions are end-user parameters. Each op- There are also hooks for classes and packages.
tion is declared by one such command.
• \AtEndOfPackage
• \ExecuteOptions{...} tells which are the default.
• \AtEndOfClass
• \ProcessOptions\relax terminates the option pro-
cessing. They behave as the document hooks. See LaTeX Hooks.
8.4. THEMES 159

8.4 Themes 8.4.5 Sectioning

Newcomers to LaTeX often feel disappointed by the lack This is definitely the most complex part. It is not that hard
of visual customization offered by the system. Actually since the code is almost the same for \section, \subsection
this is done on purpose: the LaTeX philosophy takes a and \subsubsection.
point at doing the formatting while the writer focuses on
We use \needspace to make sure there is no line break
the content. right after a sectioning command. We enclose the com-
In this chapter, we will show what we can achieve with mand in a group where we set a font size since the space
some efforts. we need is \baselineskip which depends on the font size.
Starred commands will not set the counters (LaTeX de-
tault behaviour). You can choose to handle starred com-
8.4.1 Introduction mand differently by resetting the counters for instance.
We preceed the section printing by a \noindent. We make
In the following we will write the theme, a package that
sure to end the section printing by a \par command to
will only change the appearance of the document, so that
make sure following text gets printed properly.
our document will work with or without the theme.
For \subsection we make use of the mirrors option to
Note that if it may look eye-candy, this is absolutely not a
change the appearance accordingly.
model of typography. You should not use such theme for
serious publications. This is more a technogical example To handle the PDF bookmarks properly we need the fol-
to exhibit LaTeX capabilities. lowing lines at the end of the definitions.
Finally, for \section only, we want it to print in the header,
• Custom theme (TOC) so we call the \sectionmark command. Here we changed
the behaviour of the starred command over the original
• Custom theme LaTeX version, since we define and use the \sectionmark-
star command.
• Custom theme (red)

8.4.6 Notes and References


8.4.2 Package configuration

Nothing much to say here. This is a direct application of


the Creating Packages chapter.
We load the required packages.

• needspace is used to prevent page break right after


a sectioning command.

• tikz is used to draw the fancy material.

We define a color option, you may use as much as you


want. Defining colors with specific names makes it very
flexible. We also use an option to toggle the fancy reflec-
tion effect which might be a little too much!

8.4.3 Header and footer

We use TikZ to draw a filled semicircle.


fancyhdr is used to set header and footer. We take care of
using the fancy style and to start from scratch by erasing
the previous header and footer with \fancyhf{}.

8.4.4 Table of contents

We redefine commands used by \tableofcontents.


Chapter 9

Miscellaneous

9.1 Modular Documents book. In such cases it is good practice to split your work
into several files. For example, if you are writing a book,
During this guide we have seen what is possible to do and it makes a lot of sense to write each chapter in a sepa-
how this can be achieved, but the question is: I want to rate .tex file. LaTeX makes this very easy thanks to two
write a proper text with LaTeX, what to do then? Where commands:
should I start from? This is a short step-by-step guide \input{filename}
about how to start a document properly, keeping a good
high-level structure. This is all about organizing your files
and
using the modular capabilities of LaTeX. This way it will
be very easy to make modifications even when the doc- \include{filename}
ument is almost finished. These are all just suggestions,
but you might take inspiration from that to create your
own document.
Comparing the methods: input vs include

9.1.1 Project structure The differences between these two ways to include files
is explained below. What they have in common is that
Create a clear structure of the whole project this way: they process the contents of filename.tex before continu-
ing with the rest of the base file (the file that contains these
statements). When the compiler processes your base file
1. create a directory only for the project. We'll refer to
and reaches one of the commands \input or \include, it
that in the following parts as the root directory
reads filename.tex and processes its content in accordance
2. create two other directories inside the root, one for with the formatting commands specified in the base file.
LaTeX documents, the other one for images. Since This way you can put all the formatting options in your
you'll have to write their name quite often, choose base file and write the contents using \input or \include in
short names. A suggestion would be simply tex and the files which contain the actual content of your work.
img. This means that the important part of your working pro-
cess, i.e. writing, is kept largely separate from format-
3. create your document (we'll call it document.tex, ting choices. This is one of the main reasons why LaTeX
but you can use the name you prefer) and your own is so good for serious writing! You will thus be dealing
package (for example mystyle.sty); this second file solely with text and very basic commands such as \sec-
will help you to keep the code cleaner. tion, \emph etc. Your document will be uncluttered and
much easier to work with.
If you followed all those steps, these files should be in The second method of including a file, \in-
your root directory, using "/" for each directory: clude{filename}, differs from the first in some important
./document.tex ./mystyle.sty ./tex/ ./img/ ways. You cannot nest \include statements within a file
added via \include, whereas \input, on the other hand,
nothing else.
allows you to call files which themselves call other files,
ad infinitum (well, nearly!). You can, however, \include
9.1.2 Getting LaTeX to process multiple a file which contains one or more \input commands.
Please resist the temptation to nest files in this way
files
simply because the system can do it: you will end up
As your work grows, your LaTeX file can become un- with just another kind of complexity!
wieldy and confusing, especially if you are writing a long Another important difference is that using \include will
article with substantial, discrete sections, or a full-length force a page break (which makes it ideal for a book’s

160
9.1. MODULAR DOCUMENTS 161

chapters), whereas the \input command does not (which tree. Writing
in turn makes it ideal for use within, say, a long article \input{./filename.tex}
with discrete sections, which of course are not normally
set on a new page).
will have exactly the same effect as writing
In either case the .tex filename extension is optional.
\input{filename.tex}
Working on discrete parts of your documents has conse-
quences for how the base file is compiled; these will be
dealt with below. but if you found it more convenient to put all your files in
a sub-directory of your current directory, called myfiles,
you would refer to that file by specifying
Using different paths \input{./myfiles/filename.tex}

When the LaTeX compiler finds a reference to an external Indeed, in our example of the absolute path above, you
file in the base file, it will look for it in the same directory. could refer to that file relatively, too:
However, you can in principle refer to any file on your
system, using both absolute and relative paths. \input{../../documents/useful/foo.tex}

An absolute path is a full path- and filename with every


element specified. So, filename.tex might have the full Of course, all commonly used file systems – Linux, Mac
path, OS X and Windows – also feature the UNIX ./, ../ facil-
ity outlined above. Do note, however, that LaTeX uses
\input{/home/user/texfiles/filename.tex} forward slashes / even on Microsoft Windows platforms,
which use backslashes \ in pathnames. LaTeX imple-
If you had created the directory myfiles for your writing mentations for Windows systems perform this conversion
project, in your texfiles directory, its full path would be, for you, which ensures that your document will be valid
across all installations.
\input{/home/user/texfiles/myfiles/filename.tex}
This flexibility, inherent in the way in which LaTeX is
integrated with modern file systems, lets you input files in
Obviously, using absolute paths is inefficient if you are
a way which suits your particular set-up.
referring to a file in the current directory. If, however,
you need to include a file which is always kept at a specific When using relative paths within a LaTeX file imported
place in your system, you may refer to it with an absolute by \input or \include, it is important to note that the paths
path, for example, are relative to the directory in which the main .tex file re-
sides, not to the directory in which the included (or input)
\input{/home/user/documents/useful/foo.tex}
file is found. This is likely to be an issue if using a folder
per chapter, with the figures in each chapter’s folder, and
In practice, an absolute file path is generally used when using \include to read the chapter source into a main La-
one has to refer to a file which is quite some way away TeX file in a parent folder.
in the file system (or perhaps even on a different server!).
One word of warning: do not leave empty spaces in the
filenames, they can cause ambiguous behaviour. Either Compiling the base file
leave no spaces or use underscores _ instead.
When you compile your document, page references and
You may, however, need to make your source portable the like will change according to your use of the \input
(to another computer or to a different location of your and \include commands. Normally LaTeX users only run
harddisk), in which case relative paths should be used if the compiler on parts of the document to check that an
you wish to avoid unnecessary rewriting of path names. individual chapter is syntactically correct and looks as the
Or, a relative path may simply be a more efficient and writer intended. A full run is generally only performed for
elegant way of referring to a file. A relative path is one producing a full draft or the final version. In such cases,
which is defined in relation to the current directory, in our it is invariably necessary to run LaTeX twice or more to
case the one which contains the base file. LaTeX uses the resolve all the page numbers, references, etc. (especially
standard UNIX notation: with a simple dot . you refer to if you are using bibliographic software such as BiBTeX,
the current directory, and by two dots .. you refer to the too).
previous directory, that is the one above the current direc-
tory in the file system tree. The slash / is used to separate The simplest way to check that one or more of the var-
the different components of a pathname: directories and ious components of your work is syntactically robust, is
filenames. So by ./ you refer to the current directory, by to comment out the command with a percentage sign, for
../ you refer to the previous directory, by ../../ you refer to example:
a directory which is two steps upwards in the filesystem \documentclass{article} \begin{document} %\in-
162 CHAPTER 9. MISCELLANEOUS

put{Section_1} %\input{Section_2} %\in- In the main document, the package must be loaded as:
put{Section_3} \input{Section_4} %\input{Section_5} \usepackage{subfiles}
\end{document}

Instead of using \input and \include, child documents


This code will process your base file with the article con-
must be loaded as follows:
ventions but only the material in the file Section_4.tex will
be processed. If that was, say, the last thing you needed \subfile{filename}
to check before sending off to that major journal, you
would then simply remove all the percentage signs and The child documents must start with the following state-
rerun LaTeX, repeating the compiling process as neces- ments:
sary to resolve all references, page numbers and so on.
\documentclass[main.tex]{subfiles} \begin{document}

Using \includeonly and end with:


Using this command provides more complex, and hence \end{document}
more useful possibilities. If you include the follow-
ing command in your preamble, i.e. before \be- In summary, the base document (main.tex) looks like:
gin{document},
\documentclass{book} \usepackage{subfiles} \be-
\includeonly{filename1,filename2,...} gin{document} %% my document content \sub-
file{chapter1} %% more of my document content
only the files specified between the curly braces will be \end{document}
included. Note that you can have one or more files as the
argument to this command: separate them with a comma, and Chapter 1 (chapter1.tex) looks like:
no spaces. If you are using absolute or relative paths to
the files, type in the complete reference. \documentclass[main.tex]{subfiles} \begin{document}
%% my chapter 1 content %% %% more of my chapter
This requires that there are \include commands in the 1 content \end{document}
document which specify these files. The filename should
be written without the .tex file extension:
Some linux distributions don't have subfiles package in
\documentclass{book} \in- their latex distributions, since it was not included until
cludeonly{Chapter_1,Chapter_4} % compile just TeXLive 2012. You can download subfiles.tds.zip from
chapters 1 and 4, space characters not permitted \be- CTAN. This package will contain two files subfiles.cls
gin{document} \include{Chapter_1} % omit the '.tex' and subfiles.sty. Move these files to a directory under
extension \include{Chapter_2} \include{Chapter_3} the name subfiles in the path /usr/share/texmf/tex/latex.
\include{Chapter_4} \end{document} This still won't make the package available; the texhash
program must be executed first. Now you are good to go!
This code would process the base file but only include the
content of the author’s first and fourth chapters (Chap-
ter_1.tex and Chapter_4.tex). Importantly, this alterna- Standalone The standalone package is designed for
tive retains as much of the .aux information as possible moving more of the opposite direction than subfiles. It
from the previous run, so messes up your cross-references provides a means for importing the preamble of child
much less than the makeshift suggestion above. documents into the main document, allowing for a flexi-
ble way to include text or images in multiple documents
Separate compilation of child documents (e.g. an article and a presentation).
In the main document, the package must be loaded as:
A disadvantage of solely using \input and \include is that
\usepackage{standalone}
only the base document can be compiled. However, you
may decide that you work better on individual sections of
text and wish to edit and compile those separate from the Child documents are loaded using \input or \include.
main file. There are a few packages available to address The child documents contain, for example, the following
this problem. statements:
\documentclass{standalone} % Load any packages
Subfiles The subfiles package provides a way to com- needed for this document \begin{document} % Your
pile sections of a document using the same preamble as document or picture \end{document}
the main document.
9.1. MODULAR DOCUMENTS 163

In summary, the base document (main.tex) looks like:


Then add all the packages you want with the standard
\documentclass{book} \usepackage{standalone} command \usepackage{...} as you would do normally,
\begin{document} %% my document content \in- change the value of all the variables you want, etc. It
put{chapter1} %% more of my document content will work like the code you put here would be copied and
\end{document} pasted within your document.
While writing, whenever you have to take a decision about
formatting, define your own command for it and add it to
and Chapter 1 (chapter1.tex) looks like:
your mystyle.sty:let LaTeX work for you. If you do so, it
\documentclass{standalone} % Preamble \be- will be very easy to change it if you change your mind.
gin{document} %% my chapter 1 content %% %%
more of my chapter 1 content \end{document} This is actually the beginning of the process of writing a
package. See LaTeX/Macros for more details.
For a list of several packages you can use, see the List of
Packages section.
Inserting PDF files

If you need to insert an existing, possibly multi-page, 9.1.4 The main document document.tex
PDF file into your LaTeX document, whether or not the
included PDF was compiled with LaTeX or another tool, Then create a file called document.tex; this will be the
consider using the pdfpages package. In the preamble, main file, the one you will compile, even if you shouldn't
include the package: need to edit it very often because you will be working on
\usepackage[final]{pdfpages} other files. It should look like this (it’s the sample code
for a report, but you might easily change it to article or
whatever else):
This package also allows you to specify which pages you
wish to include: for example, to insert pages 3 to 6 from \documentclass[12pt,a4paper]{report} \usepack-
some file insertme.pdf, use: age{graphicx} \usepackage{ifpdf} \ifpdf % put here
packages only for the PDF: \DeclareGraphicsExten-
\includepdf[pages=3-6]{insertme.pdf}
sions{.pdf,.png,.jpg,.mps} \usepackage{hyperref}
\else % put here packages only for the DVI: \fi % put
To insert the whole of insertme.pdf: all the other packages here: \usepackage{mystyle}
\includepdf[pages=-]{insertme.pdf} \begin{document} \input{./tex/title.tex} %\maketi-
tle \tableofcontents \listoffigures \listoftables \in-
put{./tex/intro.tex} \input{./tex/main_part.tex}
For full functionality, compile the output with pdflatex. \input{./tex/conclusions.tex} \appendix \in-
Additional information can be found in the chapter put{./tex/myappendix.tex} % Bibliography: \clearpage
Export To Other Formats. \addcontentsline{toc}{chapter}{Bibliography} \in-
put{./tex/mybibliography.tex} \end{document}

9.1.3 The file mystyle.sty Here a lot of code expressed in previous sections has been
used. At the beginning there is the header discussed in the
Instead of putting all the packages you need at the be- Tips & Tricks section, so you will be able to compile in
ginning of your document as you could, the best way is both DVI and PDF. Then you import the only package
to load all the packages you need inside another dummy you need, that is your mystyle.sty (note that in the code
package called mystyle you will create just for your doc- it has to be imported without the extension), then your
ument. The good point of doing this is that you will just document starts. Then it inserts the title: we don't like
have to add one single \usepackage in your document, the output of \maketitle so we created our own, the code
keeping your code much cleaner. Moreover, all the info for it will be in a file called title.tex in the folder called
about your style will be within one file, so when you will tex we created before. How to write it is explained in the
start another document you'll just have to copy that file Title Creation section. Then tables of contents, figure and
and include it properly, so you'll have exactly the same tables are inserted. If you don't want them, just comment
style you have used. out those lines. Then the main part of the document in
inserted. As you can see, there is no text in document.tex:
Creating your own style is very simple: create a file called everything is in other files in the tex directory so that you
mystyle.sty (you could name it as you wish, but it has to can easily edit them. We are separating our text from the
end with ".sty”). Write at the beginning: structural code, so we are improving the “What You See is
\ProvidesPackage{mystyle} What You Mean” nature of LaTeX. Then we can see the
appendix and finally the Bibliography. It is in a separate
164 CHAPTER 9. MISCELLANEOUS

file and it is manually added to the table of contents using • Another option for collaboration is dropbox. It has 2
a tip suggested in the Tips & Tricks. GB free storage and versioning system. Works like
Once you have created your document.tex you won't need SVN, but more automated and therefore especially
to edit it anymore, unless you want to add other files in the useful for beginning LaTeX users. However, Drop-
tex directory, but this is not going to happen very often. box is not a true versioning control system, and as
Now you can write your document, separating it into as such it does not allow you to roll the article back to
many files as you want and adding many pictures without previous versions.
getting confused: thanks to the rigid structure you gave
to the project, you will be able to keep track of all your • You can use an online collaborative tool built on top
edits clearly. of a versioning control system, such as Authorea or
ShareLatex. Authorea performs most of the actions
A suggestion: do not give your files names like “chap-
described in this document, but in the background
ter_01.tex” or “figure_03.png”, i.e. try to avoid using
(it is built on Git). It allows authors to enter LaTeX
numbers in file-names: if the numbering LaTeX gives
or Markdown via a GUI with mathematical notation,
them automatically, is different from the one you gave
figures, d3.js plots, IPython notebooks, data, and ta-
(and this will likely happen) you will get really confused.
bles. All content is rendered to HTML5. Authorea
When naming a file, stop for a second, think about a short
also features a commenting system and article-based
name that can fully explain what is inside the file without
chat to ease collaboration and review.
being ambiguous, it will let you save a lot of time as soon
as the document gets larger.
• As the LaTeX system uses plain text, you can use
synchronous collaborative editors like Gobby. In
9.1.5 External Links Gobby you can write your documents in collabo-
ration with anyone in real time. It is strongly rec-
• Subfiles package documentation ommended that you use utf8 encoding (especially if
there are users on multiple operating systems collab-
• Standalone package documentation orating) and a stable network (typically wired net-
works).
• pdfpages package documentation
• TitanPad (or other clones of EtherPad). To compile
use the command:
9.2 Collaborative Writing of La- wget -O filename.tex "http://titanpad.com/ep/
pad/export/xxxx/latest?format=txt" && (latex
TeX Documents filename.tex)
where 'xxxx' should be replaced by the pad number
Note: This Wikibook is based on the article Tools for (something like 'z7rSrfrYcH').
Collaborative Writing of Scientific LaTeX Documents by
Arne Henningsen that is published in The PracTeX Jour- • With a dedicated Linux box with LaTeX & Dropbox
nal 2007, number 3 (http://www.tug.org/pracjourn/). it’s possible to use Google docs and some scripting to
get automatically generated PDFs on Dropbox from
updates on Google Docs.
9.2.1 Abstract

Collaborative writing of documents requires a strong syn- • You can use a distributed version control system
chronisation among authors. This Wikibook describes such as Mercurial or Git. This is the definitive solu-
a possible way to organise the collaborative preparation tion for users looking for control and advanced fea-
of LaTeX documents. The presented solution is primar- tures like branch and merge. The learning curve will
ily based on the version control system Subversion (http: be steeper than that for a web-based solution.
//subversion.apache.org/). The Wikibook describes how
Subversion can be used together with several other soft-
9.2.2 Introduction
ware tools and LaTeX packages to organise the collabo-
rative preparation of LaTeX documents. The collaborative preparation of documents requires a
considerable amount of coordination among the authors.
Other Methods This coordination can be organised in many different
ways, where the best way depends on the specific circum-
• You can use one of the online solutions listed in the stances.
Installation chapter. Most of them have collabora- In this Wikibook, I describe how the collaborative writ-
tion features. ing of LaTeX documents is organised at our department
9.2. COLLABORATIVE WRITING OF LATEX DOCUMENTS 165

(Division of Agricultural Policy, Department of Agricul- on other computers (e.g. on the version control server).
tural Economics, University of Kiel, Germany). I present Third, this allows the user to easily switch between dif-
our software tools, and describe how we use them. Thus, ferent computers (e.g. office, laptop, home).
this Wikibook provides some ideas and hints that will be
useful for other LaTeX users who prepare documents to-
gether with their co-authors. 9.2.4 The Version Control System Subver-
sion
9.2.3 Interchanging Documents Subversion (SVN) comes as a successor to the popular
version control system CVS. SVN operates on a client-
There are many ways to interchange documents among server model in which a central server hosts a project
authors. One possibility is to compose documents by in- repository that users copy and modify locally. A repos-
terchanging e-mail messages. This method has the advan- itory functions similarly to a library in that it permits
tage that common users generally do not have to install users to check out the current project, make changes, and
and learn the usage of any extra software, because virtu- then check it back in. The server records all changes a
ally all authors have an e-mail account. Furthermore, the user checks in (usually with a message summarizing what
author who has modified the document can easily attach changes the user made) so that other users can easily ap-
the document and explain the changes by e-mail as well. ply those changes to their own local files.
Unfortunately, there is a problem when two or more au-
Each user has a local working copy of a remote repos-
thors are working at the same time on the same document.
itory. For instance, users can update changes from the
So, how can authors synchronise these files?
repository to their working copy, commit changes from
A second possibility is to provide the document on a com- their own working copy to the repository, or (re)view the
mon file server, which is available in most departments. differences between working copy and repository.
The risk of overwriting each others’ modifications can be
To set up a SVN version control system, the SVN server
eliminated by locking files that are currently edited. How-
software has to be installed on a (single) computer with
ever, generally the file server can be only accessed from
permanent internet access. (If this computer has no static
within a department. Hence, authors who are out of the
IP address, one can use a service like DynDNS to be able
building cannot use this method to update/commit their
to access the server with a static hostname.) It can run
changes. In this case, they will have to use another way to
on many Unix, modern MS Windows, and Mac OS X
overcome this problem. So, how can authors access these
platforms.
files?
Users do not have to install the SVN server software, but
A third possibility is to use a version control system.
a SVN “client” software. This is the unique way to ac-
A comprehensive list of version control systems can be
cess the repositories on the server. Besides the basic SVN
found at Wikipedia. Version control systems keep track
command-line client, there are several Graphical User In-
of all changes in files in a project. If many authors modify
terface Tools (GUIs) and plug-ins for accessing the SVN
a document at the same time, the version control system
server (see http://subversion.tigris.org/links.html). Ad-
tries to merge all modifications automatically. However,
ditionally, there are very good manuals about SVN freely
if multiple authors have modified the same line, the mod-
available on the internet (e.g. http://svnbook.red-bean.
ifications cannot be merged automatically, and the user
com).
has to resolve the conflict by deciding manually which
of the changes should be kept. Authors can also com- At our department, we run the SVN server on a GNU-
ment their modifications so that the co-authors can eas- Linux system, because most Linux distributions include
ily understand the workflow of this file. As version con- it. In this sense, installing, configuring, and maintaining
trol systems generally communicate over the internet (e.g. SVN is a very simple task.
through TCP/IP connections), they can be used from dif- Most MS Windows users access the SVN server by the
ferent computers with internet connections. A restrictive TortoiseSVN client, because it provides the most usual
firewall policy might prevent the version control system interface for common users. Linux users usually use
from connecting to the internet. In this case, the net- SVN utilities from the command-line, or eSvn--a GUI
work administrator has to be asked to open the appro- frontend--with KDiff3 for showing complex differences.
priate port. The internet is only used for synchronising
the files. Hence, a permanent internet connection is not
required. The only drawback of a version control system 9.2.5 Hosting LaTeX files in Subversion
could be that it has to be installed and configured.
Moreover, a version control system is useful even if a sin- On our Subversion server, we have one repository for
gle user is working on a project. First, the user can track a common texmf tree. Its structure complies with the
(and possibly revoke) all previous modifications. Sec- TeX Directory Structure guidelines (TDS, http://www.
ond, this is a convenient way to have a backup of the files tug.org/tds/tds.html, see figure 1). This repository pro-
166 CHAPTER 9. MISCELLANEOUS

of the document at a later date. This feature has been


proven very useful. When creating branches and tags, it
is important always to use the Subversion client (and not
the tools of the local file system) for these actions, be-
cause this saves disk space on the server and it preserves
information about the same history of these documents.
Often the question arises, which files should be put under
version control. Generally, all files that are directly mod-
ified by the user and that are necessary for compiling the
document should be included in the version control sys-
tem. Typically, these are the LaTeX source code (*.tex)
Figure 1: Common texmf tree shown in eSvn's Repository
files (the main document and possibly some subdocu-
Browser
ments) and all pictures that are inserted in the document
(*.eps, *.jpg, *.png, and *.pdf files). All LaTeX classes
(*.cls), LaTeX styles (*.sty), BibTeX data bases (*.bib),
vides LaTeX classes, LaTeX styles, and BibTeX styles
and BibTeX styles (*.bst) generally should be hosted in
that are not available in the LaTeX distributions of the
the repository of the common texmf tree, but they could
users, e.g. because they were bought or developed for the
be included in the respective repository, if some (exter-
internal use at our department. All users have a work-
nal) co-authors do not have access to the common texmf
ing copy of this repository and have configured LaTeX to
tree. On the other hand, all files that are automatically
use this as their personal texmf tree. For instance, teTeX
created or modified during the compilation process (e.g.
(http://www.tug.org/tetex/) users can edit their TeX con-
*.aut, *.aux, *.bbl, *.bix, *.blg, *.dvi, *.glo, *.gls, *.idx,
figuration file (e.g. /etc/texmf/web2c/texmf.cnf) and set
*.ilg, *.ind, *.ist, *.lof, *.log, *.lot, *.nav, *.nlo, *.out,
the variable TEXMFHOME to the path of the working
*.pdf, *.ps, *.snm, and *.toc files) or by the (LaTeX or
copy of the common texmf tree (e.g. by TEXMFHOME
BibTeX) editor (e.g. *.bak, *.bib~, *.kilepr, *.prj, *.sav,
= $HOME/texmf); MiKTeX (http://www.miktex.org/)
*.tcp, *.tmp, *.tps, and *.tex~ files) generally should be
users can add the path of the working copy of the com-
not under version control, because these files are not nec-
mon texmf tree in the 'Roots’ tab of the MiKTeX Options.
essary for compilation and generally do not include addi-
If a new class or style file has been added (but not if these tional information. Furthermore, these files are regularly
files have been modified), the users have to update their modified so that conflicts are very likely.
'file name data base' (FNDB) before they can use these
classes and styles. For instance, teTeX users have to ex-
ecute texhash; MiKTeX users have to click on the button
'Refresh FNDB' in the 'General' tab of the MiKTeX Op-
9.2.6 Subversion really makes the
tions. difference
Furthermore, the repository contains manuals explaining A great feature of a version control system is that all au-
the specific LaTeX software solution at our department
thors can easily trace the workflow of a project by view-
(e.g. this document). ing the differences between arbitrary versions of the files.
The Subversion server hosts a separate repository for each Authors are primarily interested in 'effective' modifica-
project of our department. Although branching, merging, tions of the source code that change the compiled docu-
and tagging is less important for writing text documents ment, but not in 'ineffective' modifications that have no
than for writing source code for software, our repository impact on the compiled document (e.g. the position of
layouts follow the recommendations of the 'Subversion line breaks). Software tools for comparing text docu-
book' (http://svnbook.red-bean.com). In this sense, each ments ('diff tools’) generally cannot differentiate between
repository has the three directories /trunk, /branches, and 'effective' and 'ineffective' modifications; they highlight
/tags. both types of modifications. This considerably increases
The most important directory is /trunk. If a single text the effort to find and review the 'effective' modifications.
document belongs to the project, all files and subdirec- Therefore, 'ineffective' modifications should be avoided.
tories of this text document are in /trunk. If the project In this sense, it is very important not to change the posi-
yields two or more different text documents, /trunk con- tions of line breaks without cause. Hence, automatic line
tains a subdirectory for each text document. A slightly wrapping of the users’ LaTeX editors should be turned
different version (a branch) of a text document (e.g. for off and line breaks should be added manually. Other-
presentation at a conference) can be prepared either in wise, if a single word in the beginning of a paragraph is
an additional subdirectory of /trunk or in a new subdirec- added or removed, all line breaks of this paragraph might
tory of /branches. When a text document is submitted to change so that most diff tools indicate the entire para-
a journal or a conference, we create a tag in the directory graph as modified, because they compare the files line by
/tags so that it is easy to identify the submitted version line. The diff tools wdiff (http://www.gnu.org/software/
9.2. COLLABORATIVE WRITING OF LATEX DOCUMENTS 167

wdiff/) and dwdiff (http://os.ghalkes.nl/dwdiff.html) are


not affected by the positions of line breaks, because they
compare documents word by word. However, their out-
put is less clear so that modifications are more difficult
to track. Moreover, these tools cannot be used directly
with the Subversion command-line switch --diff-cmd, but
a small wrapper script has to be used (http://textsnippets.
com/posts/show/1033).
A reasonable convention is to add a line break after each
sentence and start each new sentence in a new line. Note
that this has an advantage also beyond version control: if
you want to find a sentence in your LaTeX code that you
have seen in a compiled (DVI, PS, or PDF) file or on a Figure 2: Reviewing modifications in KDiff3
printout, you can easily identify the first few words of this
sentence and screen for these words on the left border of
your editor window. between the user’s working copy and the repository can
be easily inspected with a single Subversion command or
Furthermore, we split long sentences into several lines with one or two clicks in a graphical Subversion client.
so that each line has at most 80 characters, because it is Furthermore, authors should verify that their code can be
rather inconvenient to search for (small) differences in compiled flawlessly before they commit their modifica-
long lines. (Note: For instance, the LaTeX editor Kile tions to the repository. Otherwise, the co-authors have
(http://kile.sourceforge.net/) can assist the user in this to pay for these mistakes when they want to compile the
task when it is configured to add a vertical line that marks document. However, this directive is not only reasonable
the 80th column.) We find it very useful to introduce the for version control systems but also for all other ways to
additional line breaks at logical breaks of the sentence, interchange documents among authors.
e.g. before a relative clause or a new part of the sentence
starts. An example LaTeX code that is formatted accord- Subversion has a feature called 'Keyword Substi-
ing to these guidelines is the source code of the article tution' that includes dynamic version information
Tools for Collaborative Writing of Scientific LaTeX Doc- about a file (e.g. the revision number or the last
uments by Arne Henningsen that is published (including author) into the contents of the file itself (see e.g.
the source code) in The PracTeX Journal 2007, Number http://svnbook.red-bean.com, chapter 3). Sometimes,
3 (http://www.tug.org/pracjourn/2007-3/henningsen/). it is useful to include these information not only as
a comment in the LaTeX source code, but also in
If the authors work on different operating sys- the (compiled) DVI, PS, or PDF document. This
tems, their LaTeX editors will probably save the can be achieved with the LaTeX packages svn (http:
files with different newline (end-of-line) characters //www.ctan.org/tex-archive/macros/latex/contrib/svn/),
(http://en.wikipedia.org/wiki/Newline). To avoid this svninfo (http://www.ctan.org/tex-archive/macros/latex/
type of 'ineffective' modifications, all users can agree on contrib/svninfo/), or (preferably) svn-multi (http://www.
a specific newline character and configure their editor ctan.org/tex-archive/macros/latex/contrib/svn-multi/).
to use this newline character. Another alternative is
to add the subversion property 'svn:eol-style' and set The most important directives for collaborative writing of
it to 'native'. In this case, Subversion automatically LaTeX documents with version control systems are sum-
converts all newline characters of this file to the native marised in the following box.
newline character of the author’s operating system Directives for using LaTeX with version control sys-
(http://svnbook.red-bean.com/en/1.4/svn.advanced. tems
props.file-portability.html#svn.advanced.props.special.
eol-style). 1. Avoid 'ineffective' modifications.
There is also another important reason for reducing the
number of 'ineffective' modifications: if several authors 2. Do not change line breaks without good reason.
work on the same file, the probability that the same line
3. Turn off automatic line wrapping of your LaTeX ed-
is modified by two or more authors at the same time in-
itor.
creases with the number of modified lines. Hence, 'inef-
fective' modifications unnecessarily increase the risk of 4. Start each new sentence in a new line.
conflicts (see section Interchanging Documents).
Furthermore, version control systems allow a very effec- 5. Split long sentences into several lines so that each
tive quality assurance measure: all authors should crit- line has at most 80 characters.
ically review their own modifications before they com-
6. Put only those files under version control that are
mit them to the repository (see figure 2). The differences
directly modified by the user.
168 CHAPTER 9. MISCELLANEOUS

7. Verify that your code can be compiled flawlessly be- 9.2.7 Managing collaborative bibliogra-
fore committing your modifications to the reposi- phies
tory.
Writing of scientific articles, reports, and books requires
8. Use Subversion's diff feature to critically review the citation of all relevant sources. BibTeX is an excel-
your modifications before committing them to the lent tool for citing references and creating bibliographies
repository. (Markey 2005, Fenn 2006). Many different BibTeX
styles can be found on CTAN (http://www.ctan.org) and
on the LaTeX Bibliography Styles Database (http://jo.
9. Add a meaningful and descriptive comment when irisson.free.fr/bstdatabase/). If no suitable BibTeX style
committing your modifications to the repository. can be found, most desired styles can be conveniently as-
sembled with custombib/makebst (http://www.ctan.org/
tex-archive/macros/latex/contrib/custom-bib/). Fur-
10. Use the Subversion client for copying, moving, or re- thermore, BibTeX style files can be created or modified
naming files and folders that are under revision con- manually; however this action requires knowledge of the
trol. (unnamed) postfix stack language that is used in BibTeX
style files (Patashnik 1988).

If the users are willing to let go of the built-in diff utility At our department, we have a common bibliographic data
of SVN and use diff tools that are local on their worksta- base in the BibTeX format (.bib file). It resides in our
tions, they can put to use such tools that are more tailored common texmf tree (see section 'Hosting LaTeX files in
to text documents. The diff tool that comes with SVN was Subversion') in the subdirectory /bibtex/bib/ (see figure
designed with source code in mind. As such, it is built to 1). Hence, all users can specify this bibliography by only
be more useful for files of short lines. Other tools, such using the file name (without the full path) --- no matter
as Compare It! allows to conveniently compare text files where the user’s working copy of the common texmf tree
where each line can span hundreds of characters (such as is located.
when each line represents a paragraph). When using a All users edit our bibliographic data base with the graph-
diff tool that allows convenient views of files with long ical BibTeX editor JabRef (http://jabref.sourceforge.
lines, the users can author the TeX files without a strict net/). As JabRef is written in Java, it runs on all major
line-breaking policy. operating systems. As different versions of JabRef gener-
ally save files in a slightly different way (e.g. by introduc-
ing line breaks at different positions), all users should use
the same (e.g. last stable) version of JabRef. Otherwise,
Visualizing diffs in LaTeX: latexdiff and changebar there would be many differences between different ver-
sions of .bib files that solely originate from using different
The tools latexdiff and changebar can visualize differ- version of JabRef. Hence, it would be hard to find the real
ences of two LaTeX files inside a generated document. differences between the compared documents. Further-
This makes it easier to see impact of certain changes more, the probability of conflicts would be much higher
or discuss changes with people not custom to LaTeX. (see section 'Subversion really makes the difference'). As
Changebar comes with a script chbar.sh which inserts a JabRef saves the BibTeX data base with the native new-
bar in the margin indicating parts that have changed. La- line character of the author’s operating system, it is rec-
texdiff allows different styles of visualization. The de- ommended to add the Subversion property 'svn:eol-style'
fault is that discarded text is marked as red and added and set it to 'native' (see section 'Subversion really makes
text is marked as blue. It also supports a mode similar the difference').
to Changebar which adds a bar in the margin. Latexd-
iff comes with a script latexrevise which can be used to
accept or decline changes. It also has a wrapper script
to support version control systems such as the discussed
Subversion.
An example on how to use Latexdiff in the Terminal.
latexdiff old.tex new.tex > diff.tex # Files old.tex and
new.tex are compared and the file visualizing the changes
is written to diff.tex pdflatex diff.tex # Create a PDF
showing the changes
The program DiffPDF can be used to compare two ex-
isting PDFs visually. There is also a command line tool
comparepdf based on DiffPDF. Figure 3: Specify default key pattern in JabRef
9.2. COLLABORATIVE WRITING OF LATEX DOCUMENTS 169

JabRef is highly flexible and can be configured in many the Perl script aux2bib (http://www.ctan.org/tex-archive/
details. We make the following changes to the default biblio/bibtex/utils/bibtools/aux2bib).
configuration of JabRef to simplify our work. First,
we specify the default pattern for BibTeX keys so that
JabRef can automatically generate keys in our desired 9.2.8 Conclusion
format. This can be done by selecting Options → Pref-
erences → Key pattern and modifying the desired pat- This wikibook describes a possible way to efficiently
tern in the field Default pattern. For instance, we use organise the collaborative preparation of LaTeX docu-
[auth:lower{]}{[}shortyear] to get the last name of the ments. The presented solution is based on the Subversion
first author in lower case and the last two digits of the version control system and several other software tools
year of the publication (see figure 3). and LaTeX packages. However, there are still a few is-
sues that can be improved.
First, we plan that all users install the same LaTeX distri-
bution. As the TeX Live distribution (http://www.tug.org/
texlive/) is available both for Unix and MS Windows op-
erating systems, we might recommend our users to switch
to this LaTeX distribution in the future. (Currently, our
users have different LaTeX distributions that provide a
different selection of LaTeX packages and different ver-
Figure 4: Set up general fields in JabRef sions of some packages. We solve this problem by pro-
viding some packages on our common texmf tree.)
Second, we add the BibTeX field location for informa-
tion about the location, where the publication is available Second, we consider to simplify the solution for a com-
as hard copy (e.g. a book or a copy of an article). This mon bibliographic data base. Currently it is based on
field can contain the name of the user who has the hard the version control system Subversion, the graphical Bib-
copy and where he has it or the name of a library and the TeX editor JabRef, and a file server for the PDF files of
publications in the data base. The usage of three dif-
shelf-mark. This field can be added in JabRef by select-
ing Options → Set up general fields and adding the word ferent tools for one task is rather challenging for infre-
quent users and users that are not familiar with these tools.
location (using the semicolon (;) as delimiter) somewhere
in the line that starts with General: (see figure 4). Furthermore, the file server can be only accessed by lo-
cal users. Therefore, we consider to implement an in-
tegrated server solution like WIKINDX (http://wikindx.
sourceforge.net/), Aigaion (http://www.aigaion.nl/), or
refBASE (http://refbase.sourceforge.net/). Using this so-
lution only requires a computer with internet access and
a web browser, which makes the usage of our data base
considerably easier for infrequent users. Moreover, the
stored PDF files are available not only from within the
department, but throughout the world. (Depending on
the copy rights of the stored PDF files, the access to
the server --- or least the access to the PDF files --- has
Figure 5: Specify 'Main PDF directory' in JabRef to be restricted to members of the department.) Even
Non-LaTeX users of our department might benefit from
Third, we put all PDF files of publications in a specific a server-based solution, because it should be easier to use
subdirectory in our file server, where we use the BibTeX this bibliographic data base in (other) word processing
key as file name. We inform JabRef about this subdi- software packages, because these servers provide the data
rectory by selecting Options → Preferences → External not only in BibTeX format, but also in other formats.
programs and adding the path of the this subdirectory in All readers are encouraged to contribute to this wikibook
the field Main PDF directory (see figure 5). If a PDF file by adding further hints or ideas or by providing further so-
of a publication is available, the user can push the Auto lutions to the problem of collaborative writing of LaTeX
button left of JabRef's Pdf field to automatically add the documents.
file name of the PDF file. Now, all users who have access
to the file server can open the PDF file of a publication
by simply clicking on JabRef's PDF icon. 9.2.9 Acknowledgements
If we send the LaTeX source code of a project to a jour-
nal, publisher, or somebody else who has no access to our Arne Henningsen thanks Francisco Reinaldo and Géral-
common texmf tree, we do not include our entire bibli- dine Henningsen for comments and suggestions that
ographic data base, but extract the relevant entries with helped him to improve and clarify this paper, Karsten
170 CHAPTER 9. MISCELLANEOUS

Heymann for many hints and advices regarding LaTeX, 9.3.1 Tools installation
BibTeX, and Subversion, and Christian Henning as well
as his colleagues for supporting his intention to establish This chapter features a lot of third-party tools; most of
LaTeX and Subversion at their department. them are installed independently of your TeX distribu-
tion.
Some tools are Unix-specific (*BSD, GNU/Linux and
9.2.10 References Mac OS X), but it may be possible to make them work on
Windows. If you have the choice, it is often easier with
• Fenn, Jürgen (2006): Managing citations and your Unix systems for command line tools.
bibliography with BibTeX. The PracTEX Journal,
4. http://www.tug.org/pracjourn/2006-4/fenn/. Some tools may already be installed. For instance, you
can check if dvipng is installed and ready to use (Unix
only):
• Markey, Nicolas (2005): Tame the BeaST. The B
to X of BibTeX. http://www.ctan.org/tex-archive/ which dvipng
info/bibtex/tamethebeast/ttb_en.pdf. Version 1.3. You get a directory if it is OK. [[w Most of these tools
are installable using your package manager or portage tree
• Oren Patashnik. Designing BibTeX styles. (Unix only).
http://www.ctan.org/tex-archive/info/biblio/
bibtex/contrib/doc/btxhak.pdf.
9.3.2 Preview mode
• Tools for collaborative paper-writing
This section describes how to generate a screenshot of a
LaTeX page or of a specific part of the page using the
LaTeX package preview. Screenshots are useful, for ex-
9.3 Export To Other Formats ample, if you want to include a LaTeX generated formula
on a presentation using you favorite slideware like Pow-
Strictly speaking, LaTeX source can be used to directly erpoint, Keynote or LibreOffice Impress. First, start by
generate two formats: making sure you have preview. See Installing Extra Pack-
ages.
• DVI using latex, the first one to be supported; Say you want to take a screenshot of

• PDF using pdflatex, more recent.



√ ∑ (−3)−k
Using other software freely available on Internet, you can π = 12 .
2k + 1
k=0
easily convert DVI and PDF to other document formats.
In particular, you can obtain the PostScript version using
Write this formula in the preview environment:
software which is included in your LaTeX distribution.
Some LaTeX IDE will give you the possibility to gener- Note the active option in the package declaration and the
ate the PostScript version directly (even if it uses inter- preview environment around the equation’s code. With-
nally a DVI mid-step, e.g. LaTeX → DVI → PS). It is out any of these two, you won't get any output.
also possible to create PDF from DVI and vice versa. It This package is also very useful to export specific parts
doesn't seem logical to create a file with two steps when to other format, or to produce graphics (e.g. using
you can create it straight away, but some users might need PGF/TikZ) and then including them in other documents.
it because, as you remember from the first chapters, the You can also automate the previewing of specific envi-
format you can generate depends upon the formats of the ronments:
images you want to include (EPS for DVI, PNG and JPG
for PDF). Here you will find sections about different for- This will produce a PDF containing only the listing con-
mats with description about how to get it. tent, the page layout will depend on the shape of the
source code.
Other formats can be produced, such as RTF (which can
be used in Microsoft Word) and HTML. However, these
documents are produced from software that parses and
interprets the LaTeX files, and do not implement all the 9.3.3 Convert to PDF
features available for the primary DVI and PDF outputs.
Nonetheless, they do work, and can be crucial tools for Directly
collaboration with colleagues who do not edit documents
with LaTeX. pdflatex my_file
9.3. EXPORT TO OTHER FORMATS 171

DVI to PDF Customization of PDF output in XeTeX (setting docu-


ment title, author, keywords etc.) is done using the con-
dvipdfm my_file.dvi figuration of hyperref package.
will create my_file.pdf. Another way is to pass through
PS generation: 9.3.4 Convert to PostScript
dvi2ps myfile.dvi ps2pdf myfile.ps
from PDF
you will get also a file called my_file.ps that you can
delete. pdf2ps my_file.pdf

from DVI
Merging PDF
dvi2ps my_file.dvi
If you have created different PDF documents and you
want to merge them into one single PDF file you can use
the following command-line command. You need to have 9.3.5 Convert to RTF
Ghostscript installed:
LaTeX can be converted into an RTF file, which in turn
can be opened by a word processor such as LibreOffice
Using Windows gswin32 -dNOPAUSE -
Writer or Microsoft Word. This conversion is done
sDEVICE=pdfwrite -sOUTPUTFILE=Merged.pdf
through latex2rtf, which may run on any computer plat-
-dBATCH 1.pdf 2.pdf 3.pdf
form, however is only actively supported on Windows,
Linux and BSD, with the last mac update being from
Using Linux gs -dNOPAUSE -sDEVICE=pdfwrite 2001. The program operates by reading the LaTeX
-sOUTPUTFILE=Merged.pdf -dBATCH 1.pdf 2.pdf source, and mimicking the behaviour of the LaTeX pro-
3.pdf gram. latex2rtf supports most of the standard implemen-
tations of LaTeX, such as standard formatting, some math
Alternatively, PDF-Shuffler is a small python-gtk applica- typesetting, inclusion of EPS, PNG or JPG graphics, and
tion, which helps the user to merge or split pdf documents tables. As well, it has some limited support for packages,
and rotate, crop and rearrange their pages using an in- such as varioref, and natbib. However, many other pack-
teractive and intuitive graphical interface. This program ages are not supported.
may be avaliable in your Linux distribution’s repository.
latex2rtf is simple to use. The Windows version has a
Another option to check out is pdftk (or PDF toolkit), GUI (l2rshell.exe), which is straightforward to use. The
which is a command-line tool that can manipulate PDFs command-line version is offered for all platforms, and can
in many ways. To merge one or more files, use: be used on an example mypaper.tex file:
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf latex mypaper bibtex mypaper # if you use bibtex la-
tex2rtf mypaper
Using pdfLaTeX Note: If you are merging external Both latex and (if needed) bibtex commands need to be
PDF documents into a LaTeX document which is com- run before latex2rtf, because the .aux and .bbl files are
piled with pdflatex, a much simpler option is to use the needed to produce the proper output. The result of this
pdfpages package, e.g.: conversion will create myfile.rtf, which you may open in
Three simple shell scripts using the pdfpages package are many word processors such as Microsoft Word or Libre-
provided in the pdfjam bundle by D. Firth. They include Office.
options to merge several pdf files (pdfjoin), put several
pages in one physical sheet (pdfnup) and rotate pages
9.3.6 Convert to HTML
(pdf90).
See also Modular Documents There are many converters to HTML.

HEVEA
XeTeX
hevea mylatexfile
You can also use XeTeX (or, more precisely, XeLaTeX),
which works in the same way as pdflatex: it creates a latex2html
PDF file directly from LaTeX source. One advantage of
XeTeX over standard LaTeX is support for Unicode and latex2html -html_version 4.0,latin1,unicode -split 1 -
modern typography. See its Wikipedia entry for more nonavigation -noinfo -title “MyDocument” MyDocu-
details. ment.tex
172 CHAPTER 9. MISCELLANEOUS

LaTeXML So SVG is great for drawings and a small amount of text.


JPG is a well known raster formats, however it is usually
latexmlc paper.tex --destination=paper.html not as good as PNG for text.
In some cases it may be sufficient to simply copy a region
pdf2htmlEX
of a PDF (or PS) file using the tools available in a PDF
pdf2htmlEX [options] <input.pdf> [<output.html>] viewer (for example using LaTeX to typeset a formula for
pasting into a presentation). This however will not gen-
pdf2htmlEX can convert PDF to HTML without losing erally have sufficient resolution for whole pages or large
text or format. It is designed as a general PDF to HTML areas.
converter, not only restricted to the PDF generated by La-
TeX source. LaTeX users can compile the LaTeX source
code to PDF, and then convert the PDF to HTML via Multiple formats
pdf2htmlEX. Some introductions of pdf2htmlEX can be
found on its own wiki page. More technical details can be pdftocairo
found on the paper published on TUGboat: Online pub-
lishing via pdf2htmlEX HTML / PDF. The Figure 3 of
There is pdftocairo featured in the poppler toolset.
the paper gives different work-flows of publishing HTML
online. pdftocairo -svg latexdoc.pdf output.svg
pdftocairo also supports various raster graphic formats.
TeX4ht

TeX4ht is a very powerful conversion program, but its Vector graphics


configuration is not straightforward. Basically a config-
uration file has to be prepared, and then the program is pdf2svg
called.
Direct conversion from PDF to SVG can be done using
bibtex2html the command line tool pdf2svg.

For BibTeX. pdf2svg file.pdf file.svg

bibtex2html mybibtexfile
ps2svg

9.3.7 Convert to image formats Alternatively DVI or PDF can be converted to PS as de-
scribed before, then the bash script ps2svg.sh can be used
It is sometimes useful to convert LaTeX output to image (as all the software used by this script is multiplatform,
formats for use in systems that do not support DVI nor this is also possible in Windows, a step-by-step guide
PDF files, such as Wikipedia. could be written).
There are two family of graphics:
dvisvgm
• Vector graphics can be scaled to any size, thus do
not suffer from quality loss. SVG is a vector format. One can also use dvisvgm, an open source utility that con-
• Raster graphics define every pixel explicitly. PNG verts from DVI to SVG.
is a raster format. dvisvgm -n file.dvi

So vector graphics are usually preferred. There is still Inkscape


some cases where raster graphics are used:
Inkscape is able to convert to SVG, PDF, EPS, and other
• The target system does not handle vector graphics, vector graphic formats.
only raster graphics are supported.
inkscape --export-area-drawing --export-ps=OUTPUT
• SVG can not embed fonts. So either the font will INPUT inkscape --export-area-page --export-plain-
be rendered using a local .ttf or .otf font (which will svg=OUTPUT INPUT
mostly change the output), or all characters must be
turned to vector graphics. This last method makes
the SVG big and slow. If the input LaTeX file con- Raster graphics
tains a lot of text which formatting must be pre-
served, SVG is not that great. GIMP
9.3. EXPORT TO OTHER FORMATS 173

Open your file with GIMP. It will ask you which page If you want to keep the formating, you can use a DVI-to-
you want to convert, whether you want to use anti-aliasing plain text converter, like catdvi. Example:
(choose strong if you want to get something similar to catdvi yourfile.dvi | fmt -u
what you see on the screen). Try different resolutions to
fit your needs, but 100 dpi should be enough. Once you The use of fmt -u (available on most Unices) will remove
have the image within GIMP, you can post-process it as the justification.
you like and save it to any format supported by GIMP, as
PNG for example.

dvipng

A method for DVI files is dvipng. Usage is the same as


dvipdfm.
Run latex as usual to generate the dvi file. Now, we want
an X font size formula, where X is measure in pixels. You
need to convert this, to dots per inch (dpi). The formula
is: <dpi> = <font_px>*72.27/10. If you want, for in-
stance, X = 32, then the size in dpi corresponds to 231.26.
This value will be passed to dvipng using the flag -D. To
generate the desired png file run the command as follows:
dvipng -T tight -D 231.26 -o foo.png foo.dvi
The flag -T sets the size of the image. The option tight
will only include all ink put on the page. The option -o
sends the output to the file name foo.png.

ImageMagick

The convert command from the ImageMagick suite can


convert both DVI and PDF files to PNG.
convert input.pdf output.png

optipng

You can optimize the resulting image using optipng so


that it will take up less space.

9.3.8 Convert to plain text

If you are thinking of converting to plain text for spell-


checking or to count words, there may be an easier way
-- read Tips and Tricks first.
Most LaTeX distributions come with detex program,
which strips LaTeX commands. It can handle multi-file
projects, so all you need is to give one command:
detex yourfile
(note the omission of .tex extension). This will output
result to standard output. If you want the plain text go to
a file, use
detex yourfile > yourfile.txt
If the output from detex does not satisfy you, you can try
a newer version available on Google Code, or use HTML
conversion first and then copy text from your browser.
Chapter 10

Help and Recommendations

10.1 FAQ • you add the \usepackage[utf8]{inputenc} line in the


preamble.
10.1.1 Margins are too wide
Avoid using latin1. See Special Characters.
LaTeX’s default margins may seem too large. In most
cases, this is a preferred default and improves readability.
If you still disagree, you can easily change them with 10.1.4 Writing the euro symbol directly
See Page Layout.
Add the following lines in your preamble:

10.1.2 Avoid excessive double line breaks


in source code 10.1.5 LaTeX paragraph headings have ti-
tle and content on the same line
Too many paragraphs of one line or two do not look very
good. Some people do not like the way \paragraph{...} writes
the title on the same line as the content. This is actually
Remember the TeX rule:
fairly common in a lot of documents and not as weird as
it may seem at first.
• If two or more consecutive line breaks are found,
TeX starts a new paragraph. There are ways to get around the default behavior, how-
ever; see \paragraph line break for more information.
• If only one linebreak is found, TeX inserts a space
if there is no space directly before or after it.
10.1.6 Fonts are ugly/jagged/bitmaps or
You might be tempted to put blank lines all the time to PDF search fails or Copy/paste from
improve the readability of your source code, but this will
PDF is messy
have an impact on formatting. The solution is simple:
put a comment at the very beginning of the blank lines.
You must be using diacritics (e.g. accents) with OT1 en-
This will prevent TeX from seeing another line break—
coding (the default). Switch to T1 encoding:
all characters up to and including the next line break after
a comment are ignored. If you have ugly jagged fonts after the font encoding
change, then you have no Type1 compatible fonts avail-
Example:
able. Install Computer Modern Super or Latin Modern
(package name may be lm). To use Latin Modern you
10.1.3 Simplified special character input need to include the package:
See Fonts for an explanation.
So long as your computing environment supports UTF-8,
you can enter special characters directly rather than enter-
ing the TeX commands for diacritics and other extended 10.1.7 Manual formatting: use of line
characters. E.g.,
breaks and page breaks
This requires that:
You should really avoid breaking lines and pages manu-
• your text editor supports and is set to save your file ally. The TeX engine is in charge of that. The big prob-
in UTF-8; lem with manual formatting is that it is not dynamic. Even

174
10.1. FAQ 175

if it looks right the first time, the content is likely to ren- not have more weight than normal characters, so they are
der really badly if you change anything before the point usually a better choice for emphasizing small amounts of
you manually formatted. text.
The only place where page breaks are recommended is at The original and more appropriate use of bold and under-
the upper level of sectioning in your documents, e.g. parts line is for special parts, such as headers, the index, glos-
or chapters (although when you start a new part or chap- saries, and so on. (Actually, underlining is rarely used in
ter, LaTeX will ordinarily do this for you). When you do professional environments.)
manually insert a page break, you should use \clearpage LaTeX has a macro \emph{...} for emphasizing text us-
or \cleardoublepage which print currently floating figures ing italics. It should be preferred to \textit{...} because
before starting a new page. \emph{...} will correctly print emphasized text inside
If you absolutely have to insert line or page breaks man- other italic text in the regular font.
ually, you should do it after you are sure you have com-
pleted your document otherwise, so that you don't later
have to come back and update it. 10.1.10 The proper way to use figures

Users used to WYSIWYG document processors like Mi-


10.1.8 Always finish commands with {} crosoft Word or LibreOffice often get frustrated with fig-
ures. The answer is simple: a figure is not a picture!
TeX has an unintuitive rule that if a control sequence (a
command) is not followed by a pair of braces (with a pa- If you use \includegraphics without enclosing it in a figure
rameter in between or not), then the following space char- environment, it will behave just as in a word processor,
acter(s) are ignored. LaTeX will not print any space, and placing the picture right at the spot where it was placed
the command (say, the TeX or LaTeX logos) are run to- in the source.
gether with the following word. Figures are a type of float, which is a virtual object that
To fix this, use a pair of braces after the command, even LaTeX can put in places other than the exact location it
if there are no parameters. Example: was created, which helps to prevent cluttering your text
with pictures and tables.
(Technical explanation: a control sequence name can only
be composed of characters with catcode 11, that is A- See Importing Graphics and Floats, Figures and Captions
Z and a-z by default. TeX knows where the control se- for more details.
quence name start thanks to the backslash, and it knows
where it ends when it encounters the first token which is
not of catcode 11. This character is then skipped. Since 10.1.11 Text stops justifying
consecutive spaces have been concatenated into one sin-
gle space, no space is taken into account.) Most likely you have used \raggedleft, \raggedright or
\centering at some point and forgotten to switch it off.
It is possible to define macros that will insert a space dy- These commands are switches—they remain active until
namically by using the xspace package. the end of the scope, or until the end of the document
if there is no scope. See Paragraph Alignment for more
• If there is no brace and a space following the com- information.
mand, an extra space will be appended.
• If there are braces, no extra space will be printed.
10.1.12 Rules of punctuation and spacing
Example:
LaTeX does some work for you, but not everything. Es-
pecially regarding punctuation, you are pretty free to do
10.1.9 Avoid bold and underline what you want. Punctuation rules are different for each
language. In English there is no space before a punctua-
Typographically speaking, it is usually poor practice to tion mark and one space after it.
use bold or underline formats in the middle of a para- There are a lot of rules, but you can have a quick look at
graph. This has become a common habit for users of tra- Wikipedia.
ditional word processors because these two functions are
very easily accessible (along with italics).
However, bold and underline tend to overweight the text 10.1.13 Compilation fails after a Babel
and distract the reader. When you start reading a para- language change
graph with a bold word in the middle, you often read the
emphasized part first, thus spoiling the content and break- This is a limitation of Babel. Delete the .aux file (or clean
ing the order of the ideas. Italics are less obvious and do the project), then try compiling again.
176 CHAPTER 10. HELP AND RECOMMENDATIONS

10.1.14 Learning LaTeX quickly or cor- 10.1.17 Use vector graphics rather than
rectly raster images

Nowadays it is very common to “learn” on the web by us- Raster (bitmap) graphics scale poorly and often create
ing a search engine and copying and pasting things here jagged or low-quality results which clash with the doc-
and there. As with every programming language, this is ument quality, particularly when printed.
generally a poor method which will lead to lack of control,
Using vector (line-oriented) graphics instead, either
unexpected results, and a lot of frustration. Really learn-
through LaTeX’s native diagramming tools or by export-
ing LaTeX is not that difficult and does not take that long.
ing vector formats from your drawing or diagramming
Most chapters in this book are dedicated to a specific us-
tools, will produce much higher quality results. When
age, so the basics are actually covered very quickly.
possible, you should prefer PDF, EPS, or SVG graphics
If you are getting frustrated with a specific package, make over PNG or JPG.
sure you read its official documentation, which is usually
the best source of information. Content found on the web,
even in this book, is rarely as accurate as the official docu-
mentation. Inaccurate information might result in causing 10.1.18 Stretching tables
mistakes without you understanding why.
The time you spend learning is worth it, and it quickly Trying to stretch tables with the default tabular environ-
makes up for the time you would lose if you don't learn ment will often lead to unexpected results. The nice tabu
things properly and end up stuck all the time. package will do what you want and even much more. Al-
ternatively if you cannot use the tabu package you may
try tabularx or tabulary packages See Tables.
10.1.15 Non-breaking spaces

This useful feature is unknown to most newcomers, al-


10.1.19 Tables are easier than you think
though it is available on most WYSIWYG document pro-
cessors. A non-breaking space between two tokens (e.g.
words, punctuation marks) prevents processors from in- Even though the Tables chapter is quite long, it is worth
serting a line break between them. It is very important reading. In the end, you only need to know a few things
for consistent reading. LaTeX uses the '~' symbol as a about the environment of your choice.
non-breaking space. Some LaTeX editors feature table assistants. Also, many
You usually use non-breaking spaces for punctuation spreadsheet applications have a LaTeX export feature (or
marks in some languages, for units and currencies, for plugin). Again, see Tables for more details.
initials, etc.
For example, in French typography, you put a non-
breaking space before all two-parts punctuation marks. 10.1.20 Relieving cumbersome code (lists
Example: and long command names)
Note that writing French like this might get really painful.
Thankfully, Babel with the frenchb option will take care LaTeX is sometimes cumbersome to write, especially if
of the non-breaking spaces for all punctuation marks. In you are not using an adequate editor. See Editors for
the above example, only the non-breaking space for the some interesting choices.
euro symbol must remain. You can define aliases to shorten some commands:
Here the xspace package comes in handy to avoid swal-
10.1.16 Smart mathematics lowed spaces.
For lists you may want to try the easylist package. Now
All virtual objects designated by letters, variables or oth- writing a list is as simple as
ers should use a dedicated formatting. For math and a lot
of other fields, the LaTeX math formatting is perfect. For
instance, if you want to refer to an object A, write
10.1.21 Reducing the size of your LaTeX
If you want to refer to several objects in a sentence, it is
the same. installation
If you refer to a set of objects, you can still use the math The Installation article explains in detail how to manu-
notation. ally install a fully functional TeX environment, including
Note that this is different from usual text parentheses. LaTeX and other features, in under 100 MB.
10.2. TIPS AND TRICKS 177

10.2 Tips and Tricks within{equation}{section} \number-


within{figure}{section}
10.2.1 Always writing LaTeX in roman
The same can be done with similar counter types and doc-
If you insert the \LaTeX command in an area with a ument units such as “subsection”.
non-default font, it will be formatted accordingly. If you
want to keep LaTeX written in Computer Modern ro-
man shape, you must redefine the function. However, the 10.2.4 Generic header
naive
As explained in the previous sections, a LaTeX source
\renewcommand{\LaTeX}{{\rm \LaTeX}} can be used to generate both a DVI and a PDF file. For
very basic documents the source is the same but, if the
will output: documents gets more complicated, it could be necessary
to make some changes in the source so that it will work
TeX capacity exceeded , sorry [ grouping levels =255].
for a format but it will not for the other. For example,
all that is related to graphics has to be adapted accord-
So you need to create a temporary variable. ing to the final format. As discussed in the section about
Sadly, floating objects, even if you should use different pictures
according to the final format, you can override this limit
\newcommand{\LaTeXtemp}{\LaTeX} \renewcom- putting in the same folder pictures in different formats
mand{\LaTeX}{{\rm \LaTeXtemp}} (e.g., EPS and PNG) with the same name and link them
without writing the extension. There is a simple way to
does not work as well. solve this problem:
We must use the TeX primitive \let instead. \usepackage{ifpdf}
\let\LaTeXtemp\LaTeX \renewcom-
mand{\LaTeX}{{\rm \LaTeXtemp }} or, if you don't have this package, you can add the follow-
ing text just after \documentclass[...]{...} :
\newif\ifpdf \ifx\pdfoutput\undefined \pdffalse \else
\ifnum\pdfoutput=1 \pdftrue \else \pdffalse \fi \fi
10.2.2 id est and exempli gratia (i.e. and
e.g.)
this is plain TeX code. The ifpdf package and this code,
If you simply use the forms “i.e.” or “e.g.”, LaTeX will both define a new if-else you can use to change your code
treat the periods as end of sentence periods (i.e. full stop) according to the compiler you are using. After you have
since they are followed by a space, and add more space be- used this code, you can use whenever you want in your
fore the next “sentence”. To prevent LaTeX from adding document the following syntax:
space after the last period, the correct syntax is either \ifpdf % we are running pdflatex \else % we are running
“i.e.\ " or “e.g.\ ". latex \fi
Depending on style (e.g., The Chicago Manual of Style),
a comma can be used afterwards, which is interpreted byplace after \ifpdf the code you want to insert if you are
LaTeX as part of a sentence, since the period is not fol-
compiling with pdflatex, place after \else the code you
lowed by any space. In this case, “i.e.,” and “e.g.,” do not
want to insert if you are compiling with latex. For exam-
need any special attention. ple, you can use this syntax to load different packages or
If the command \frenchspacing is used in the preamble, different graphic file formats according to the compiler.
the space between sentences is always consistent.
10.2.5 Graphics and Graph editors
10.2.3 Grouping Figure/Equation Num-
Vector image editors with LaTeX support
bering by Section
It is often preferable to use the same font and font size
For long documents the numbering can become cumber- in your images as in the document. Moreover, for sci-
some as the numbers reach into double and triple digits. entific images, you may need mathematical formulae or
To reset the counters at the start of each section and prefix
special characters (such as Greek letters). Both things
the numbers by the section number, include the following can be achieved easily if the image editor allows you to
in the preamble. use LaTeX code in your image. Most vector image edi-
\usepackage{amsmath} \number- tors do not offer this option. There are, however, a few
178 CHAPTER 10. HELP AND RECOMMENDATIONS

exceptions.
In early days, LaTeX users used Xfig for their drawings.
The editor is still used by quite a few people nowadays
because it has special 'export to LaTeX' features. It also
gives you some very basic ways of encapsulating LaTeX
text and math in the image (setting the text’s 'special flag'
to 'special' instead of 'normal'). When exporting, all La-
TeX text will be put in a .tex-file, separately from the rest
of the image (which is put in a .ps file).
A newer and easier-to-use vector image editor specially
tailored to LaTeX use is IPE. It allows any LaTeX com-
mand, including but not limited to mathematical formu-
lae in the image. The program saves its files as editable 3
2.5
.eps or .pdf files, which eliminates the need of exporting 2
-1.5 1.5
your image each time you have edited it. -1 1
-0.5 0.5
A very versatile vector image editor is Inkscape. It does 0 0
0.5
not support LaTeX text by itself, but you can use the plu- 1
1.5
gin Textext for that. This allows you to put any block of
LaTeX code in your image. Additionally since version
gnuplot can plot various numerical data, functions, error distri-
0.48 you can export to vectorgraphics with texts sepa- bution as well as 3D graphs and surfaces
rated in a .tex file. Using this way text is rendered by the
latex compiler itself.
LaTeXDraw is a free and open source graphical PSTricks set format "$%g$" set title “Graph 3: Dependence
generator and editor. It allows you to draw basic geomet- of $V_p$ on $R_0$" set xlabel “Resistance $R_0$
ric objects and save the result in a variety of formats in- [$\Omega$]" set ylabel “Voltage $V_p$ [V]" set border 3
cluding .jpg, .png, .eps, .bmp as well as .tex. In the last set xtics nomirror set ytics nomirror set terminal epslatex
case the saved file contains PSTricks/LaTeX code only. set output “graph1.eps” plot “graph1.csv” using 1:3 #Plot
Owing to that you can include any possible LaTeX code the data
in the picture, since the file is rendered by your LaTeX
Now gnuplot produces two files: the graph drawing in
environment directly.
graph.eps and the text in graph.tex. The second includes
Another way to generate vectorgraphics is using the the EPS image, so that we only need to include the file
Asymptote language. It is a programming language graph.tex in our document:
which produces vector images in encapsulated postscript
\input{graph1.tex}
format and supports LaTeX syntax in any textlabels.
The above steps can be automated by the package gnu-
plottex. By placing gnuplot commands inside \be-
Graphs with gnuplot gin{gnuplot}\end{gnuplot}, and compiling with latex -
shell-escape, the graphs are created and added into your
A simple method to include graphs and charts in LaTeX document.
documents is to create it within a common spreadsheet
software (OpenOffice Calc or MS Office Excel etc.) and Failure to access gnuplot from latex for Windows can be
include it in the document as a cropped screenshot. How- solved by making file title only in one word. Don't type
ever, this produces poor quality rasterized images. Calc my report.tex for your title file, but do myreport.tex .
also allows you to copy-paste the charts into OpenOffice When you are using gnuplottex it is also possible to di-
Draw and save them as PDF files. rectly pass the terminal settings as an argument to the en-
Using Microsoft Excel 2010, charts can be copied di- vironment
rectly to Microsoft Expression Design 4, where they can \begin{gnuplot}[terminal=epslatex, terminalop-
be saved as PDF files. These PDF files can be included tions=color, scale=0.9, linewidth=2 ] ... \end{gnuplot}
in LaTeX. This method produces high quality vectorized
images. Using gnuplottex can cause fraudulent text-highlighting in
some editors when using algebraic functions on imported
An excellent method to render graphs is through gnuplot, data, such as:
a free and versatile plotting software, that has a special
output filter directly for exporting files to LaTeX. We as- (2*($1)):2
sume, that the data is in a CSV file (comma separated Some editors will think of all following text as part of a
text) in the first and third column. A simple gnuplot script formula and highlight it as such (because of the '$' that is
to plot the data can look like this: interpreted as part of the latex code). This can be avoided
10.2. TIPS AND TRICKS 179

by ending with: 10.2.7 New even page


#$ \end{gnuplot}
In the twoside-mode you have the ability to get a new odd-
As it uncomments the dollar sign for the gnuplot inter- side page by:
preter, but is not affecting the interpretation of the .tex
\cleardoublepage
by the editor.
When using pdfLaTeX instead of simple LaTeX, we must
However, LaTeX doesn't give you the ability to get a new
convert the EPS image to PDF and to substitute the name
even-side page. The following method opens up this;
in the graph1.tex file. If we are working with a Unix-like
shell, it is simply done using: The following must be put in your document preamble:
eps2pdf graph1.eps sed -i s/".eps"/".pdf"/g graph1.tex \usepackage{ifthen} \newcommand{\newevenside}{
\ifthenelse{\isodd{\thepage}}{\newpage}{ \newpage
With the included tex file we can work as with an ordinary
\phantom{placeholder} % doesn't appear on page \this-
image.
pagestyle{empty} % if want no header/footer \newpage
Instead of calling eps2pdf directly, we can also include } }
the epstopdf package that automates the process. If we
include a graphics now and leave out the file extension,
To active the new even-side page, type the following
epstopdf will automatically transform the .eps-file to PDF
where you want the new even-side:
and insert it in the text.
\newevenside
\includegraphics{graph1}
This way, if we choose to output to PS or DVI, the EPS
If the given page is an odd-side page, the next new page is
version is used and if we output to PDF directly, the con-
subsequently an even-side page, and LaTeX will do noth-
verted PDF graphics is used. Please note that usage of
ing more than a regular \newpage. However, if the given
epstopdf requires compiling with latex -shell-escape.
page is an even page, LaTeX will make a new (odd) page,
Note: Emacs AucTex users might want to check out put in a placeholder, and make another new (even) page.
Gnuplot-mode. A crude but effective method.

Generate png screenshots 10.2.8 Sidebar with information

See Export To Other Formats. If you want to put a sidebar with information like copy-
right and author, you might want to use the eso-pic pack-
age. Example:
10.2.6 Spell-checking and Word Counting \usepackage{eso-pic} ... \AddToShipoutPic-
ture{% \AtPageLowerLeft{% \rotatebox{90}{%
If you want to spell-check your document, you can use \begin{minipage}{\paperheight} \center-
the command-line aspell, hunspell (preferably), or ispell ing\textcopyright~\today{} Humble me \end{minipage}
programs. % } } % }%
ispell yourfile.tex aspell --mode=tex -c yourfile.tex hun-
spell -l -t -i utf-8 yourfile.tex If you want it on one page only, use the starred version of
All three understand LaTeX and will skip LaTeX com- the AddToShipoutPicture command at the page you want
mands. You can also use a LaTeX editor with built-in it. (\AddToShipoutPicture*{...})
spell checking, such as LyX, Kile, or Emacs. Last another
option is to convert LaTeX source to plain text and open
10.2.9 Hide auxiliary files
resulting file in a word processor like OpenOffice.org or
KOffice. If you're using pdflatex you can create a folder in which
If you want to count words you can, again, use LyX or all the output files will be stored, so your top directory
convert your LaTeX source to plain text and use, for ex- looks cleaner.
ample, UNIX wc command: pdflatex -output-directory tmp
detex yourfile | wc
An alternative to the detex command is the pdftotext Please note that the folder tmp should exist. However if
command which extracts an ASCII text file from PDF: you're using a Unix-based system you can do something
1. pdflatex yourfile.tex 2. pdftotext yourfile.pdf 3. wc like this:
yourfile.txt alias pdflatex='mkdir -p tmp; pdflatex -output-directory
180 CHAPTER 10. HELP AND RECOMMENDATIONS

tmp'

Or for vim modify your .vimrc:


" use pdflatex let g:Tex_DefaultTargetFormat='pdf'
let g:Tex_MultipleCompileFormats='pdf,dvi' let
g:Tex_CompileRule_pdf = 'mkdir -p tmp; pdflatex
-output-directory tmp -interaction=nonstopmode $*; cp
tmp/*.pdf .'
Chapter 11

Appendix

11.1 Authors • Peter Flynn’s Formatting information, a beginner’s


guide to typesetting with LaTeX. We have con-
tacted him by email asking for permission to use
11.1.1 Included books his work. The original book is released under the
GNU Free Documentation License, the same as Wik-
The following books have been included in this wikibook
ibooks. For more information, his personal website
(or we are working on it!), with permission of the author:
is http://silmaril.ie/cgi-bin/blog.

• Andy Roberts’ Getting to grips with Latex.


11.1.2 Wiki users
• Not So Short Introduction to LaTex2e by Tobias
Oetiker, Hubert Partl and Irene Hyna. We have Major contributors to the book on Wikibooks are:
contacted the authors by email asking for permis-
sion: they allowed us to use their material, but they • Alessio Damato
never edited directly this wikibook. That book is
released under the GPL, that is not compatible with • Jtwdog
the GFDL used here in Wikibooks. Anyway, we • Pierre Neidhardt
have the permission of the authors to use their work.
You can freely copy text from that guide to here.
If you find text on both the original book and here
on Wikibooks, then that text is double licensed un-
11.2 Links
der GPL and GFDL. For more information about
Tobias Oetiker and Hubert Partl, their websites Here are some other online resources available:
are http://it.oetiker.ch/ and http://homepage.boku.
ac.at/partl/ respectively. Community
• LaTeX Primer from the Indian TeX Users Group. • The TeX Users Group Includes links to free versions
Their document is released under the GNU Free of (La)TeX for many kinds of computers.
Documentation License, the same as Wikibooks, so
we can include parts of their document as we wish. • UK-TUG The UK TeX Users’ Group
In any case, we have contacted Indian TeX Users
Group and they allowed us to do it. • TUGIndia The Indian TeX Users Group
• comp.text.tex Newsgroup for (La)TeX related ques-
• David Wilkins’ Getting started with LaTeX. The tions
book is not released under any free license, but we
have contacted the author asking him for the per- • CTAN hundreds of add-on packages and programs
mission to use parts of his book on Wikibooks. He
agreed: his work is still protected but you are al-
Tutorials/FAQs
lowed to copy the parts you want on this Wikibook.
If you see text on both the original work and here,
• Tobias Oetiker’s Not So Short Introduction to
then that part (and only that part) is released under
LaTex2e:
the terms of GFDL, like any other text here on Wik-
http://www.ctan.org/tex-archive/info/lshort/
ibooks.
english/lshort.pdf also at
http://web.archive.org/web/20010603070337/http:
In progress //people.ee.ethz.ch/~{}oetiker/lshort/lshort.pdf

181
182 CHAPTER 11. APPENDIX

• Vel’s introduction to LaTeX: What is it, why should • The Comprehensive LaTeX Symbol List (in PDF)
you use it, who should use it and how to get started: http://www.ctan.org/tex-archive/info/symbols/
http://www.vel.co.nz/vel.co.nz/Blog/Entries/2009/ comprehensive/symbols-a4.pdf
11/4_LaTeX_Document_Preparation_System.
html • Getting to Grips with LaTeX (HTML) Collection
of Latex tutorials taking you from the very basics
• Peter Flynn’s beginner’s guide (formatting): towards more advanced topics
http://www.ctan.org/tex-archive/info/beginlatex/ http://www.andy-roberts.net/misc/latex/index.html
beginlatex-3.6.pdf
• Chapter 8 (about typesetting mathematics) of the
• The AMS Short Math Guide for LaTeX, a concise LaTeX companion
summary of math formula typesetting features http://www.macrotex.net/texbooks/
http://www.ams.org/tex/amslatex.html latexcomp-ch8.pdf
• amsmath users guide (PDF) and related files:
http://www.ctan.org/tex-archive/macros/latex/ Reference
required/amslatex/math/
• LaTeX Project Site
• LaTeX Primer from the Indian TeX Users Group:
http://sarovar.org/projects/ltxprimer/ • The Comprehensive TeX Archive Network Latest
(La)TeX-related packages and software
• LaTeX Primer
http://www.maths.tcd.ie/~{}dwilkins/ • TeX Directory Structure, used by many (La)TeX
LaTeXPrimer/ distributions
• PSTricks--fancy graphics exploiting PDF capabili- • Natural Math converts natural language math for-
ties mulas to LaTeX representation
http://sarovar.org/projects/pstricks/
• Obsolete packages and commands
• PDFScreen--create LaTeX PDF files that have nav-
igation buttons used for presentations: • Lamport’s book LaTeX: A Document Preparation
http://sarovar.org/projects/pdfscreen/ System

• David Bausum’s list of TeX primitives (these are the


fundamental commands used in TeX): Templates
http://www.tug.org/utilities/plain/cseq.html
• A resource for free high quality LaTeX templates
• Leslie Lamport’s manual for the commands that for a variety of applications
are unique to LaTeX (commands not used in plain
TeX): • LaTeX template for writing PhD thesis, 2007
http://www.tex.uniyar.ac.ru/doc/latex2e.pdf
• UCL computer department thesis template
• The UK TeX FAQ List of questions and answers that
are frequently posted at comp.text.tex • UT thesis template, 2006
http://www.tex.ac.uk/faq
• A template that supports an easy conversion to *.odt
• TeX on Mac OS X: Guide to using TeX and LaTeX (*.doc), *.pdf and *.html in one run, 2009
on a Mac
http://www.rna.nl/tex.html
11.3 Package Reference
• Text Processing using LaTeX
http://www-h.eng.cam.ac.uk/help/tpl/
textprocessing/ This is an incomplete list of useful packages that can be
used for a wide range of different kind of documents.
• The (La)TeX encyclopaedia Each package has a short description next to it and, when
http://tex.loria.fr/index.html available, there is a link to a section describing such pack-
age in detail. All of them (unless stated) should be in-
• Hypertext Help with LaTeX cluded in your LaTeX distribution as package_name.sty.
http://www.giss.nasa.gov/latex/ For more information, refer to the documentation of the
• EpsLatex: a very comprehensive guide to images, single packages, as described in Installing Extra Pack-
figures and graphics ages.
http://www.ctan.org/tex-archive/info/epslatex.pdf The list is in alphabetical order.
11.5. INDEX 183

11.4 Sample LaTeX documents 11.5.2 B

The easiest way to learn how to use latex is to look at • babel


how other people use it. Here is a list of real world la- • Basics
tex sources that are freely available on the internet. The
information here is sorted by application area, so that it • beamer package
is grouped by the scientific communities that use similar
notation and LaTeX constructs. • Bibliography Management
• BibTeX
11.4.1 General examples • Bold

Tutorial examples, books, and real world uses of LaTeX. • Bullets


• Bullet points
• caption.tex, simple.tex, wrapped.tex

• small2e.tex and sample2e.tex. The “official” sample 11.5.3 C


documents...
• Captions
• A short example of how to use LaTeX for scientific
reports by Stephen J. Eglen. • Collaborative Writing of LaTeX Documents
• The not so Short Introduction to LaTeX by Tobias • Color
Oetiker is distributed with full latex sources.
• color package
• Columns, see Multi-column Pages
11.4.2 Semantics of Programming Lan-
guages • Cross-referencing

Articles on programming language research, from syntax • Customizing LaTeX


to semantics, including source code listings, type rules,
proof trees, and even some category theory. A good
place to start is Mitchell Wand’s Latex Resources, includ-
11.5.4 D
ing a sample file that also demonstrates Didier Remy’s
• Dashes
mathpartir package. The following are latex sources of
some articles, books, or presentations from this field: • description environment
• Diactrical marks
• Pugs: Bootstrapping Perl 6 with Haskell. This paper
by Audrey Tang contains nice examples on config- • Document Classes
uring the listings package to format source code.
• Document Structure
• Drawings
11.5 Index
This is an alphabetical index of the book. 11.5.5 E
• e.g. (exempli gratia)
11.5.1 A • Ellipsis
• Absolute Beginners • em-dash
• Abstract • en-dash
• Accents • enumerate
• Algorithms • Errors and Warnings
• Arrays • Euro currency symbol
• Authors • Export To Other Formats
184 CHAPTER 11. APPENDIX

11.5.6 F 11.5.10 L

• Figures • Labels

• Floats • Letters

• Fonts • Links

• Footer, Page • Lists

• Footnotes
11.5.11 M
• Formatting
• makeidx package

11.5.7 G • \maketitle

• General Guidelines • Margin Notes

• Graphics • Creating Graphics

• Creating • Mathematics
• Embedding • Matrices
• Importing
• Minipage environment example
• graphicx package
• Multi-column Pages

11.5.8 H
11.5.12 P
• Header, Page
• Packages
• HTML output
• Creating 1
• Hyperlinks
• Page Layout
• hyperref package
• PDF output
• hyphen
• picture
• Hyphenation
• Pictures

• PNG output
11.5.9 I
• Presentations
• i.e. (id est)
• Pseudocode
• Images

• Importing Graphics 11.5.13 Q


• Indexing
• LaTeX/Paragraph Formatting#Quoting_text
• Internationalization

• Introduction 11.5.14 R

• Italics • References

• itemize • RTF output


11.6. COMMAND GLOSSARY 185

11.5.15 S 11.6.1 #
• Sentences / see slash marks
• Small Capitals \@ following period ends sentence
• Source Code Listings \\[*][extra-space] new line

• Space Between Words \, thin space, math and text mode

• Spell-checking \; thick space, math mode

• Superscript and subscript: powers and indices \: medium space, math mode

• Superscript and subscript: text mode \! negative thin space, math mode

• SVG output \- hyphenation; tabbing


\= set tab, see tabbing
11.5.16 T \> tab, see tabbing

• Table of contents \< back tab, see tabbing

• Tables \+ see tabbing

• Teletype text \' accent or tabbing

• Text Size \` accent or tabbing


\| double vertical lines, math mode
• Theorems
\( start math environment
• Tips and Tricks
\) end math environment
• Title Creation
\[ begin displaymath environment

11.5.17 U \] end displaymath environment

• URLs
11.6.2 A

11.5.18 V \addcontentsline{file}{sec_unit}{entry} adds an entry


to the specified list or table
• Verbatim Text
\addtocontents{file}{text} adds text (or formatting
commands) directly to the file that generates the
11.5.19 W specified list or table
\addtocounter{counter}{value} increments the
• Word Counting counter
\address{Return address}
11.5.20 X
\addtolength{len-cmd}{len} increments a length com-
• XeTeX mand, see Length

• XY-pic package \addvspace adds a vertical space of a specified height

• xy package \alph causes the current value of a specified counter to


be printed in alphabetic characters
\appendix changes the way sectional units are num-
11.6 Command Glossary bered so that information after the command is con-
sidered part of the appendix
This is a glossary of LaTeX commands—an alphabetical
\arabic causes the current value of a specified counter
listing of LaTeX commands with the summaries of their
to be printed in Arabic numbers
effects. (Brackets "[]" are optional arguments and braces
"{}" are required arguments.) \author declares the author(s). See Document Structure
186 CHAPTER 11. APPENDIX

11.6.3 B 11.6.6 E
\backslash prints a backslash \em Toggles italics on/off for the text inside curly braces
with the command. Such as {\em This is in italics
\baselineskip a length command (see Lengths), which
\em but this isn't \em and this is again}. This com-
specifies the minimum space between the bottom of
mand allows nesting.
two successive lines in a paragraph
\baselinestretch scales the value of \baselineskip \emph Toggles italics on/off for the text in curly braces
following the command e.g. \emph{This is in italics
\bf Boldface typeface \emph{but this isn't} and this is again}.
\bibitem generates a labeled entry for the bibliography \ensuremath (LaTeX2e) Treats everything inside the
\bigskipamount curly braces as if it were in a math environment.
Useful when creating commands in the preamble as
\bigskip equivalent to \vspace{\bigskipamount} they will work inside or out of math environments.
\boldmath bold font in math mode \epigraph Adds an epigraph. Requires epigraph pack-
\boldsymbol bold font for symbols age.
\euro Prints euro € symbol. Requires eurosym pack-
11.6.4 C age.

\cal Calligraphic style in math mode


11.6.7 F
\caption generate caption for figures and tables
\fbox
\cdots Centered dots
\centering Used to center align LaTeX environments \flushbottom

\chapter Starts a new chapter. See Document Structure. \fnsymbol


\circle \footnote Creates a footnote.
\cite Used to make citations from the provided bibliog- \footnotemark
raphy
\footnotesize Sets font size. See Text Formatting.
\cleardoublepage
\footnotetext
\clearpage Ends the current page and causes any floats
to be printed. See Page Layout. \frac inserts a fraction in mathematics mode. The usage
is \frac{numerator}{denominator}.
\cline Adds horizontal line in a table that spans only to
a range of cells. See \hline and Tables chapter. \frame
\closing Inserts a closing phrase (e.g. \closing{yours \framebox Like \makebox but creates a frame around
sincerely}), leaves space for a handwritten signa- the box. See Boxes.
ture and inserts a signature specified by \signature{}.
Used in the Letter class. \frenchspacing Instructs LaTex to abstain from insert-
ing more space after a period (´.´) than is the case for
\color Specifies color of the text. LaTeX/Colors an ordinary character. In order to untoggle this func-
\copyright makes © sign. See Formatting. tionality resort to the command \nonfrenchspacing.

11.6.5 D 11.6.8 G
\dashbox 11.6.9 H
\date
\hfill Abbreviation for \hspace{\fill}.
\ddots Inserts a diagonal ellipsis (3 diagonal dots) in
math mode \hline adds a horizontal line in a tabular environment.
See also \cline, Tables chapter.
\documentclass[options]{style} Used to begin a latex
document \href Add a link, or an anchor. See Hyperlinks
\dotfill \hrulefill
11.6. COMMAND GLOSSARY 187

\hspace Produces horizontal space. \linethickness

\huge Sets font size. See Text Formatting. \linewidth

\Huge Sets font size. See Text Formatting. \listoffigures Inserts a list of the figures in the docu-
ment. Similar to TOC
\hyphenation{word list} Overrides default hyphenation
algorithm for specified words. See Hyphenation \listoftables Inserts a list of the tables in the document.
Similar to TOC

11.6.10 I \location

\include This command is different from \input in that


it’s the output that is added instead of the commands
11.6.13 M
from the other files. For more see LaTex/Basics \makebox Defines a box that has a specified width, in-
\includegraphics Inserts an image. Requires graphicx dependent from its content. See Boxes.
package. \maketitle Causes the title page to be typeset, using in-
\includeonly formation provided by commands such as \title{}
and \author{}.
\indent
\markboth \markright
\input Used to read in LaTex files. For more see
\mathcal
LaTex/Basics.
\mathop
\it Italicizes the text which is inside curly braces with
the command. Such as {\it This is in italics}. \em is \mbox Write a text in roman font inside a math part
generally preferred since this allows nesting.
\medskip
\item Creates an item in a list. Used in list structures.
\multicolumn
\multiput
11.6.11 K
\kill Prevent a line in the tabbing environment from be- 11.6.14 N
ing printed.
\newcommand Defines a new command. See New
Commands.
11.6.12 L
\newcolumntype Defines a new type of column to be
\label Used to create label which can be later referenced used with tables. See Tables.
with \ref. See Labels and Cross-referencing.
\newcounter
\large Sets font size. See Text Formatting.
\newenvironment Defines a new environment. See
\Large Sets font size. See Text Formatting. New Environments.
\LARGE Sets font size. See Text Formatting. \newfont

\LaTeX Prints LaTeX logo. See Formatting. \newlength

\LaTeXe Prints current LaTeX version logo. See \newline Ends current line and starts a new one. See
Formatting. Page Layout.

\ldots Prints sequence of three dots. See Formatting. \newpage Ends current page and starts a new one. See
Page Layout.
\left
\newsavebox
\lefteqn
\newtheorem
\line
\nocite Adds a reference to the bibliography without an
\linebreak Suggests LaTeX to break line in this place. inline citation. \nocite{*} causes all entries in a bib-
See Page Layout. tex database to be added to the bibliography.
188 CHAPTER 11. APPENDIX

\noindent 11.6.17 Q
\nolinebreak \quad Similar to space, but with the size of a capital M
\nonfrenchspacing Setting the command untoggles the
\qquad double \quad
command \frenchspacing and activates LaTeX stan-
dards to insert more space after a period (´.´) than
after an ordinary character. 11.6.18 R
\normalsize Sets default font size. See Text Formatting.
\raggedbottom Command used for top justified within
\nopagebreak Suggests LaTeX not to break page in this other environments.
place. See Page Layout.
\raggedleft Command used for right justified within
\not other environments.

\raggedright Command used for left justified within


11.6.15 O other environments.
\onecolumn \raisebox Creates a box and raises its content. See
LaTeX/Boxes.
\opening Inserts an opening phrase when using the letter
class, for example \opening{Dear Sir} \ref Used to reference to number of previously declared
\oval \label. See Labels and Cross-referencing.

\overbrace Draws a brace over the argument. Can be \renewcommand


used in displaystyle with superscript to label formu-
\right
lae. See Advanced Mathematics.
\overline Draws a line over the argument. \rm

\roman
11.6.16 P \rule Creates a line of specified width and height. See
LaTeX/Rules and Struts.
\pagebreak Suggests LaTeX breaking page in this
place. See Page Layout.
\pagenumbering Defines the type of characters used 11.6.19 S
for the page numbers. Options : arabic, roman, Ro-
man, alph, Alph, gobble (invisible). \savebox Makes a box and saves it in a named storage
bin.
\pageref Used to reference to number of page where
a previously declared \label is located. See Floats, \sbox The short form of \savebox with no optional ar-
Figures and Captions. guments.

\pagestyle See Page Layout. \sc Small caps.


\par Starts a new paragraph \scriptsize Sets font size. See Text Formatting.
\paragraph Starts a new paragraph. See Document \section Starts a new section. See Document Structure.
Structure.
\setcounter
\parbox Defines a box whose contents are created in
paragraph mode. See Boxes. \setlength
\parindent Normal paragraph indentation. See \settowidth
Lengths.
\sf Sans serif.
\parskip
\shortstack
\part Starts a new part of a book. See Document Struc-
ture. \signature In the Letter class, specifies a signature for
\protect later insertion by \closing.

\providecommand (LaTeX2e) See Macros. \sl Slanted.

\put \slash See slash marks


11.6. COMMAND GLOSSARY 189

\small Sets font size. See Text Formatting. \textheight


\smallskip \thanks
\sout Strikes out text. Requires ulem package. See Text \thispagestyle
Formatting.
\tiny Sets font size. See Text Formatting.
\space force ordinary space
\title
\sqrt Creates a root (default square, but magnitude can
be given as an optional parameter). \today Writes current day. See Text Formatting.

\stackrel Takes two arguments and stacks the first on \tt


top of the second.
\twocolumn
\stepcounter Increase the counter.
\typeout
\subparagraph Starts a new subparagraph. See
\typein
Document Structure.
\subsection Starts a new subsection. See Document
Structure. 11.6.21 U

\subsubsection Starts a new sub-subsection. See \uline Underlines text. Requires ulem package. See
Document Structure. Formatting.
\underbrace
11.6.20 T \underline
\tableofcontents Inserts a table of contents (based on \unitlength
section headings) at the point where the command
appears. \usebox

\telephone In the letter class, specifies the sender’s tele- \usecounter


phone number.
\uwave Creates wavy underline. Requires ulem pack-
\TeX Prints TeX logo. See Text Formatting. age. See Formatting.

\textbf{} Sets bold font style. See Text Formatting.


11.6.22 V
\textcolor{}{} Creates colored text. See Entering col-
ored text. \value
\textit{} Sets italic font style. See Text Formatting.\vbox{text} Encloses a paragraph’s text to prevent it
\textmd{} Sets medium weight of a font. See Text For- from running over a page break
matting. \vcenter
\textnormal{} Sets normal font. See Text Formatting. \vdots Creates vertical dots. See Mathematics.
\textrm{} Sets roman font family. See Text Formatting. \vector
\textsc{} Sets font style to small caps. See Text Format-
\verb Creates inline verbatim text. See Formatting.
ting.
\vfill
\textsf{} Sets sans serif font family. See Text Format-
ting. \vline
\textsl{} Sets slanted font style. See Text Formatting. \vphantom
\texttt{} Sets typewriter font family. See Text Format- \vspace
ting.
\textup{} Sets upright shape of a font. See Text For- This page uses material from Dr. Sheldon Green’s
matting. Hypertext Help with LaTeX.

\textwidth
Chapter 12

Text and image sources, contributors, and


licenses

12.1 Text
• LaTeX/Introduction Source: https://en.wikibooks.org/wiki/LaTeX/Introduction?oldid=2986065 Contributors: Ævar Arnfjörð Bjarma-
son, Tualha, Iamunknown, 3mta3, Jraregris, Goodgerster, Derbeth, Graemeg~enwikibooks, Elwikipedista~enwikibooks, Withinfocus, Pde-
long, Orderud, Whiteknight, Kernigh, Latexing, Sgenier~enwikibooks, Igjimh, Alejo2083, Chazz, Gronau~enwikibooks, Xania, Rehoot,
Sjlegg, Conrad.Irwin, Urhixidur, Nbrouard, Vadik wiki, Pi zero, Dan Polansky, Waldir, QuiteUnusual, Piksi, Kri, Mckay, Tom Morris,
Avila.gas, Nobelium, Ambrevar, Martinkunev, PAC2, Anarchyboy, Tomato86, Staticshakedown, E.lewis1, InverseHypercube, Polytropos
Technikos, Torbjorn T., TinyTimZamboni, AllenZh, Ppadmapriya, Benson Muite, Steelangel, Reddraggone9 and Anonymous: 75
• LaTeX/Installation Source: https://en.wikibooks.org/wiki/LaTeX/Installation?oldid=2986066 Contributors: 3mta3, Koavf, Michael-
Billington, Mwtoews, Bryant1410, Pi zero, Marcus Cyron, Gyro Copter, Kazkaskazkasako, QuiteUnusual, Nobelium, Ambrevar, PAC2,
Jason barrington~enwikibooks, Mfwitten, Tomato86, Benregn, Torbjorn T., LlamaAl, Hahc21, RainCity471, Leaderboard, Dplaza000,
Simplelatex, Alansandiego and Anonymous: 41
• LaTeX/Installing Extra Packages Source: https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages?oldid=2771441 Contribu-
tors: Alejo2083, Az1568, Xania, Pi zero, Zylorian, Ollydbg, Mabdul, Ambrevar, Lotus noir, Netheril96, DarkSheep, Dplaza000 and
Anonymous: 21
• LaTeX/Basics Source: https://en.wikibooks.org/wiki/LaTeX/Basics?oldid=2979079 Contributors: Krischik, Chuckhoffmann, 3mta3,
ABCD, Derbeth, Jonathan Webley, Withinfocus, Snaxe920~enwikibooks, Jtwdog~enwikibooks, Tpr~enwikibooks, Jguk, Bilbo1507,
Igjimh, Dilaudid, Alejo2083, Mwtoews, Thenub314, Rehoot, Vadik wiki, Qeny, Atallcostsky, Pi zero, Waldir, MER-C, TomyDuby,
CrazyTerabyte, Kri, Adrignola, Constantine, Ambrevar, PAC2, Chisophugis, Immae, Janskalicky, Tomato86, Robbiemorrison, E.lewis1,
BrettMontgomery, Guyrobbie, Patuck, ATC2~enwikibooks, DragonLord, Guzo, Wickedjargon, Pater Christophorus, Johannes Bo, Red-
draggone9, Negative24, Dplaza000 and Anonymous: 82
• LaTeX/Document Structure Source: https://en.wikibooks.org/wiki/LaTeX/Document_Structure?oldid=2988234 Contributors: Derbeth,
Withinfocus, Orderud, Stephan Schneider, Snaxe920~enwikibooks, Jtwdog~enwikibooks, Jomegat, Nkour, Igjimh, Dilaudid, Alejo2083,
JECompton~enwikibooks, Mwtoews, BiT, Thenub314, ConditionalZenith~enwikibooks, Xania, FlashSheridan, Spelemann~enwikibooks,
Kovianyo, Recent Runes, Astrophizz~enwikibooks, Spag85~enwikibooks, Pi zero, Tully~enwikibooks, Waldir, Nux, Jan Winnicki, Quite-
Unusual, Neet, Kri, Lovibond, Adrignola, Hosszuka, Wdcf, Ambrevar, DagErlingSmørgrav, Lucasreddinger, Keplerspeed, Dirk Hünniger,
Frap, Tomato86, Derwaldrandfoerster, Echeban, Torbjorn T., LlamaAl, Ntypanski, Wickedjargon, Genethecist, Johannes Bo, Reddrag-
gone9, Kurlovitsch, Kw CUACS.TOPS and Anonymous: 77
• LaTeX/Text Formatting Source: https://en.wikibooks.org/wiki/LaTeX/Text_Formatting?oldid=2972771 Contributors: Derbeth, Within-
focus, Igjimh, Thenub314, Pi zero, ChrisHodgesUK, Adrignola, Ambrevar, Dirk Hünniger, Robbiemorrison, Fishix, Bgeron, RubensMatos,
Leaderboard, Kurlovitsch, Lindhea, Kevin Ryde and Anonymous: 20
• LaTeX/Paragraph Formatting Source: https://en.wikibooks.org/wiki/LaTeX/Paragraph_Formatting?oldid=2953044 Contributors:
Ish ishwar~enwikibooks, ABCD, Derbeth, QuantumEleven, Jonathan Webley, Withinfocus, Orderud, Jtwdog~enwikibooks,
Andyr~enwikibooks, Igjimh, Alejo2083, Mwtoews, Thenub314, ConditionalZenith~enwikibooks, Mcld, Kovianyo, MartinSpacek,
Crasshopper, Recent Runes, Pi zero, Tully~enwikibooks, Ffangs, Hjsb, Yez, Waldir, CarsracBot, Hannes Röst, Rror, Adri-
anwn, ChrisHodgesUK, Pstar, QuiteUnusual, Neet, LR~enwikibooks, Adrignola, Nixphoeni, PatrickDevlin21, Ambrevar, Zzo38,
Cdecoro, Keplerspeed, Zrisher, GPHemsley, Henrybissonnette, TorfusPolymorphus, Smobbl Bobbl, ToematoeAdmn, Dirk Hünniger,
Mouselb, EvanKroske, Tomato86, Fishpi, Robbiemorrison, Tazquebec, Brammers, Listdata, Neoriddle, Xonqnopp, C3l, Harrikoo,
Gmh04~enwikibooks, InverseHypercube, Halilsen, RealSebix, Akim Demaille, Dlituiev, SamuelLB, CD-Stevens, Incognito668, Gmacar,
Dplaza000 and Anonymous: 144
• LaTeX/Colors Source: https://en.wikibooks.org/wiki/LaTeX/Colors?oldid=2964184 Contributors: Alejo2083, Xania, Pi zero, Dan Polan-
sky, Daniel Mietchen, Waldir, Gms, JackPotte, White gecko, ChrisHodgesUK, Kazkaskazkasako, Trace, QuiteUnusual, Kri, Adrig-
nola, Benjaminevans82~enwikibooks, ChristianGruen, Sanderd17, Scorwin, Ambrevar, PAC2, Velociostrich, Dirk Hünniger, Tomato86,
Conighion, Qzxpqbp, SamuelLB, Henry Tallboys, Nicolas Perrault III, Tisep, Tpapastylianou, Honza889, Dplaza000, David Gaudet and
Anonymous: 51
• LaTeX/Fonts Source: https://en.wikibooks.org/wiki/LaTeX/Fonts?oldid=2989509 Contributors: Ish ishwar~enwikibooks, Derbeth, Xa-
nia, Jacho, Mihai Capotă, Joaospam, Pi zero, Waldir, ChrisHodgesUK, Dreaven3, Ambrevar, Wikieditoroftoday, Crissov, InverseHyper-
cube, Flamenco108, SamuelLB, BYIST, TortoiseWrath, Abramsky, Ben9243 and Anonymous: 32

190
12.1. TEXT 191

• LaTeX/List Structures Source: https://en.wikibooks.org/wiki/LaTeX/List_Structures?oldid=2977891 Contributors: Panic2k4, Self-


worm, Xania, ChrisHodgesUK, Ambrevar, Arunib, OlivierMehani, Arthurchy, Henrybissonnette, Dirk Hünniger, Cerniagigante, Scien-
tific29, Kejia, Artemisfowl3rd, SamuelLB, Michael M Hackett, Leaderboard, Lanoxx, Stefantauner, Vog2, Tommypkeane and Anonymous:
28
• LaTeX/Special Characters Source: https://en.wikibooks.org/wiki/LaTeX/Special_Characters?oldid=2989640 Contributors: ‫לערי‬
‫ריינהארט‬, Mwtoews, Ysangkok, Pi zero, Waldir, Zvika, Gms, ChrisHodgesUK, Drevicko, Steindani, Silverpie, Chbarts, Ambrevar,
Olivier.descout, PiRSquared17, Dirk Hünniger, Robbiemorrison, Wikieditoroftoday, Zwiebelleder, Zxx117, SamuelLB, Yeshua Saves,
Leaderboard, Liwangyan and Anonymous: 51
• LaTeX/Internationalization Source: https://en.wikibooks.org/wiki/LaTeX/Internationalization?oldid=2991460 Contributors: Derbeth,
Jomegat, Alejo2083, Mwtoews, BiT, Hroobjartr, Kovianyo, Skarakoleva, Pi zero, Eudoxos~enwikibooks, Louabill, Louisix, ChrisHodge-
sUK, Drevicko, Piksi, Adrignola, Chaojoker, Mijikenda, Ambrevar, Tomato86, Jlrn, Harrikoo, Alzahrawi, Gelbukh, ILubeMyCucum-
bers20, RealSebix, Saippuakauppias, SamuelLB, Lobaluna, Waylesange, Rotlink, Abalenkm, Hdankowski, Johannes Bo, RTPK, Panora-
media and Anonymous: 59
• LaTeX/Rotations Source: https://en.wikibooks.org/wiki/LaTeX/Rotations?oldid=2974180 Contributors: Alejo2083, Ysnikraz, Pi zero,
Ambrevar, Erp and Anonymous: 5
• LaTeX/Tables Source: https://en.wikibooks.org/wiki/LaTeX/Tables?oldid=2991101 Contributors: Marozols, Ish ishwar~enwikibooks,
Jotomicron, Derbeth, Jonathan Webley, Fredmaranhao, Withinfocus, Orderud, Jtwdog~enwikibooks, Selfworm, Henrik-
Midtiby~enwikibooks, Igjimh, Dilaudid, Alejo2083, Mwtoews, Thenub314, Dporter, Fmccown, Drewbie, Mcld, Vesal, Collinpark,
Ysnikraz, Tweenk, Rogal~enwikibooks, Pi zero, Abonnema, Klusinyan, Petter Strandmark, SteveM82, ChrisHodgesUK, Drevicko,
QuiteUnusual, PsyberS, Kri, Adrignola, Benjaminevans82~enwikibooks, Byassine52, Skou~enwikibooks, Rdg nz, Hosszuka, Emreg00,
Taweetham, Zyqqh~enwikibooks, Sargas~enwikibooks, Maratonda, SciYann, Avila.gas, Grenouille~enwikibooks, Erylaos, Ambrevar,
Bumbulski, PAC2, Quaristice, Yanuzz, Chuaprap, Canageek, Helptry, Arided, Topodelapradera, Dirk Hünniger, Robbiemorrison, San-
drobt, Tomxlawson, Crissov, GorillaWarfare, Gallen01, Dubbaluga~enwikibooks, Xonqnopp, David.s.hollman, Jevon, JV~enwikibooks,
Bro4, Gelbukh, Willy james, RealSebix, Ricordisamoa, SamuelLB, Sandbergja, Bianbum, Gibravo, Olaf3142, Squigish, ColeLoki, Tia
sáng mặt trời, AndreKR, Atcovi, Mdpacer and Anonymous: 179
• LaTeX/Title Creation Source: https://en.wikibooks.org/wiki/LaTeX/Title_Creation?oldid=2986901 Contributors: Derbeth,
Cfailde~enwikibooks, Jonathan Webley, Withinfocus, Jomegat, Alejo2083, JECompton~enwikibooks, Mwtoews, Thenub314, Re-
cent Runes, He7d3r, Pi zero, Adrignola, Sargas~enwikibooks, Ambrevar, Infenwe, Spirosdenaxas, Dirk Hünniger, Anarchyboy, Ftravers,
Neoriddle, Yinweichen, Ediahist, Torbjorn T., SamuelLB, Jluttine, Johannes Bo, ZimbiX, Colonel486, Lindhe94 and Anonymous: 34
• LaTeX/Page Layout Source: https://en.wikibooks.org/wiki/LaTeX/Page_Layout?oldid=2990078 Contributors: Panic2k4, Derbeth, With-
infocus, Orderud, Mecanismo, Jtwdog~enwikibooks, Jomegat, Igjimh, Alejo2083, Mwtoews, Xania, Herbythyme, Drewbie, Rajkiran g,
Ojan, Pi zero, Sabalka~enwikibooks, Waldir, JonnyJD, QuiteUnusual, Neet, Adrignola, Vaffelkake, LQST, Ambrevar, Infenwe, Jafeluv,
JenVan, Adouglass, Tomato86, Scientific29, Computermacgyver, Spook~enwikibooks, Halilsen, Harp, RealSebix, SamuelLB, Anthony
Deschamps, Bibi6, Daveturnr, Tisep, Johannes Bo, IMneme, Solid Frog, Lindhe94, Paulgush and Anonymous: 91
• LaTeX/Importing Graphics Source: https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics?oldid=2991354 Contributors: ZeroOne,
Insaneinside, 3mta3, Derbeth, Withinfocus, Orderud, Jtwdog~enwikibooks, NavarroJ, Igjimh, Dilaudid, Alejo2083, Mwtoews, Hankwang,
Tuka~enwikibooks, ConditionalZenith~enwikibooks, TWiStErRob, Matthias M., CommonsDelinker, Hippasus, Spag85~enwikibooks,
Pi zero, Dan Polansky, Ffangs, Bsander~enwikibooks, Waldir, ChrisHodgesUK, Mathieu Perrin, Martin scharrer, QuiteUnusual, Piksi,
Kri, Adrignola, Cengique, KlausFoehl, Wn202, Bcmpinc, Ambrevar, Snoopy67, Danielstrong52, Dirk Hünniger, Wysinwygaa, Jflycn,
Tomato86, Robbiemorrison, MarSraM~enwikibooks, Harrywt, Mikhail Ryazanov, Xonqnopp, Jstein, Crasic~enwikibooks, Nemoniac, Re-
alSebix, QUBot, SamuelLB, Maschen, Bgeron, MQ978, Mateo.longo and Anonymous: 108
• LaTeX/Floats, Figures and Captions Source: https://en.wikibooks.org/wiki/LaTeX/Floats%2C_Figures_and_Captions?oldid=2983493
Contributors: Derbeth, Withinfocus, Orderud, Jtwdog~enwikibooks, Robin~enwikibooks, Hansfn, HenrikMidtiby~enwikibooks, Igjimh,
Dilaudid, Alejo2083, Basenga, Mwtoews, Qwertyus, DavidMcKenzie, Mcld, He7d3r, Spag85~enwikibooks, Pi zero, Tully~enwikibooks,
Borgg, Icc97, Waldir, ChrisHodgesUK, Whym, Robert Borkowski, Tosha, Joe Schmedley, Neet, Svick, Hello71, Adrignola, Hosszuka,
Rhalah, Ypey, Wdcf, Martin von Wittich, Ambrevar, Gryllida, Rafopar, Janltx, Je ne détiens pas la vérité universelle, Caesura, Syockit,
Tomato86, Robbiemorrison, Wikieditoroftoday, Karper, Jer789, Wxm29, Anubhab91, SamuelLB, Sulhan, Defender, Konteki, Johannes
Bo, K.Nevelsteen, Linzhongpeng, Liwangyan and Anonymous: 120
• LaTeX/Hyperlinks Source: https://en.wikibooks.org/wiki/LaTeX/Hyperlinks?oldid=2981645 Contributors: Derbeth, Jomegat,
Alejo2083, Qwertyus, Urhixidur, LaTeX~enwikibooks, MartinSpacek, Recent Runes, Pi zero, Dan Polansky, Blacktrumpeter, Waldir,
Pamputt, ChrisHodgesUK, SiriusB, Neet, Adrignola, Calimo, Wdcf, Juliabackhausen, Ambrevar, Modest Genius, Roarbakk, Belteshazzar,
Bytecrook, Tomato86, Robbiemorrison, Gwpl, Courcelles, Teles, Neoriddle, Xonqnopp, Jwchong, Prawojazdy, Kevinfiesta, PeterAllen,
Thietkeweb~enwikibooks, Joeyboi, Lnkbuildingservices4u, Mimo~enwikibooks, Bajrangkhichi96, Deltasun, Ghoti, Froskoy, SamuelLB,
Shahbaz Youssefi, Niy, BlackMagic1943 and Anonymous: 53
• LaTeX/Labels and Cross-referencing Source: https://en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing?oldid=2950928
Contributors: Derbeth, Jomegat, NavarroJ, Alejo2083, Mwtoews, DavidMcKenzie, Mcld, Kovianyo, MartinSpacek, Hulten, Recent Runes,
Pi zero, Waldir, TomyDuby, Adrignola, Sargas~enwikibooks, Ambrevar, Dirk Hünniger, Robbiemorrison, InverseHypercube, SamuelLB,
Otec Stochastik, Escalator~enwikibooks and Anonymous: 56
• LaTeX/Errors and Warnings Source: https://en.wikibooks.org/wiki/LaTeX/Errors_and_Warnings?oldid=2770271 Contributors: Dark-
lama, Alejo2083, Mwtoews, Chazz, Thenub314, Xania, Pi zero, Waldir, Rogerbrent, ChrisHodgesUK, Wkdurfee~enwikibooks,
LR~enwikibooks, Kri, Adrignola, Ambrevar, Nothing1212, Bro4, SamuelLB, AlanBarrett and Anonymous: 20
• LaTeX/Lengths Source: https://en.wikibooks.org/wiki/LaTeX/Lengths?oldid=2990422 Contributors: Panic2k4, Derbeth, Withinfocus,
Hokiehead~enwikibooks, Igjimh, Alejo2083, Pi zero, Scruss, Waldir, Ollydbg, Kri, Adrignola, Ambrevar, Dendik, Xonqnopp, Ediahist,
Atcovi, Strpeter and Anonymous: 18
• LaTeX/Counters Source: https://en.wikibooks.org/wiki/LaTeX/Counters?oldid=2766071 Contributors: Ambrevar and Anonymous: 3
• LaTeX/Boxes Source: https://en.wikibooks.org/wiki/LaTeX/Boxes?oldid=2990351 Contributors: Selfworm, LivingShadow, Kri, Ambre-
var, Kundor, AthanasiusOfAlex, Atcovi and Anonymous: 10
192 CHAPTER 12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES

• LaTeX/Rules and Struts Source: https://en.wikibooks.org/wiki/LaTeX/Rules_and_Struts?oldid=2496247 Contributors: Ollydbg, Am-


brevar and Anonymous: 1
• LaTeX/Mathematics Source: https://en.wikibooks.org/wiki/LaTeX/Mathematics?oldid=2993329 Contributors: Insaneinside, 3mta3,
Juliusross, Atiq ur Rehman, Derbeth, Jonathan Webley, Withinfocus, Orderud, Mecanismo, Ans, Jtwdog~enwikibooks, Jomegat, Krish-
navedala, Robin~enwikibooks, Cameronc~enwikibooks, Nigels~enwikibooks, Pirround, Hagindaz, Igjimh, Dilaudid, Ms2ger, Alejo2083,
Basenga, Mwtoews, Swift, BiT, DavidMcKenzie, Conrad.Irwin, Dncarley, Elliptic1, Unco, Mcld, Recent Runes, Bonuama, Adam majew-
ski, Pi zero, Waldir, Marra, This, that and the other, Mhue, TomyDuby, Geminatea~enwikibooks, ChrisHodgesUK, Whym, Germanzs,
Cícero, QuiteUnusual, Winfree, Joe Schmedley, Neet, Asmeurer, Kri, Adrignola, Kwetal, Tork73, Prispartlow, Sargas~enwikibooks, Götz,
YuryKirienko, Avila.gas, Karcih, Ambrevar, Lucasreddinger, Keplerspeed, Kwpolska, Xnn, Merciadriluca, Wmheric, Kubieziel, Dirk Hün-
niger, Jodi.a.schneider, Justin W Smith, Tom.marcik, Tomato86, Սահակ, Robbiemorrison, Netheril96, Kejia, Karper, Etoombs, Clebell,
InverseHypercube, Krst, Greenbreen, Karthicknainar~enwikibooks, Fsart, Chafe66, Tgwizard, DmitriyZotikov, McSaks, SamuelLB, Jlut-
tine, Comput2h, Wp4bl0, Volvens, Mandriver, Anthony Deschamps, Ntypanski, Hahc21, Franklin Yu, Unlikelyuser, Leaderboard, Brian-
cricks, Strpeter, Komputerwiz, Hapli, Mgkrupa, Bigwyrm~enwikibooks, Yotann, User000name, Vioricavinersan, Infinite0694, Mpvharme-
len and Anonymous: 208
• LaTeX/Advanced Mathematics Source: https://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics?oldid=2992403 Contributors:
Sbeyer, 3mta3, Jonathan Webley, Ynhockey, Inductiveload, Chazz, BiT, Thenub314, Ojan, Pi zero, Leyo, ChrisHodgesUK, QuiteUnusual,
Control.valve, Adrignola, Nixphoeni, Silca678, LinuxChristian~enwikibooks, Avila.gas, TorfusPolymorphus, Simonjtyler, Tomato86,
Zaslav, Kcho, Geetha nitc, MagnusPI~enwikibooks, Codairem, Krst, Arthurvogel, SamuelLB, Escalator~enwikibooks, Volvens, Garfl,
Paul2520, Atcovi, Leaderboard, JW 00000 and Anonymous: 47
• LaTeX/Theorems Source: https://en.wikibooks.org/wiki/LaTeX/Theorems?oldid=2771879 Contributors: 3mta3, Derbeth, Raylu,
Alejo2083, Mwtoews, Kovianyo, Pi zero, Mhue, Tosha, Juliabackhausen, Ambrevar, Tomato86, SamuelLB, Ajmath62, CtrlAltCarrot
and Anonymous: 25
• LaTeX/Chemical Graphics Source: https://en.wikibooks.org/wiki/LaTeX/Chemical_Graphics?oldid=2973302 Contributors: Commons-
Delinker, QuiteUnusual, Ambrevar, Dirk Hünniger, Andrea09falco, Wickedjargon, &bahn, Daviewales, DrSarah Calumet and Anonymous:
4
• LaTeX/Algorithms Source: https://en.wikibooks.org/wiki/LaTeX/Algorithms?oldid=2988767 Contributors: ZeroOne, Derbeth,
Alejo2083, Mwtoews, Mcld, Webinn, Pi zero, Dan Polansky, Thefrankinator, Lavaka, Nemti, Whym, Tauriel-1, Adrignola, ‫امیر اعوانی‬,
Maartenweyn, Gkc~enwikibooks, Sanderd17, Sargas~enwikibooks, Saehrimnir, Ambrevar, JenVan, Debejyo, Mrt doulaty, Brevity, Writal-
naie, Tomato86, Fishpi, Pandora85, Bhanuvrat, Nsda, SamuelLB, Glad~enwikibooks, Karategeek6, Szellmann, Jimmaykeepsitreal, Harish
victory, Lteu, Uwe Hartwig and Anonymous: 86
• LaTeX/Source Code Listings Source: https://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings?oldid=2995199 Contributors:
Panic2k4, Jomegat, Alejo2083, Pi zero, Vaucouleur, Drevicko, QuiteUnusual, Hosszuka, Bunyk, Gladiool, Ambrevar, Leal26, Arthurchy,
Helptry, Evin~enwikibooks, Tomato86, Robbiemorrison, Diomidis Spinellis, Wenzeslaus, Tau Lambda, Sonic the goliath, Yeshua Saves,
RasmusWriedtLarsen, Felipecarres and Anonymous: 50
• LaTeX/Linguistics Source: https://en.wikibooks.org/wiki/LaTeX/Linguistics?oldid=2974998 Contributors: Neatnate, Xania, Matěj
Grabovský, ChrisHodgesUK, Joe Schmedley, Ambrevar, Dirk Hünniger, SynConlanger, Ngoclong19, DmitriyZotikov, Ghoti, PhilJohnG,
Obelyaev, Olesh, Matej.korvas, Hankjones, SamuelLB, Masterpiga and Anonymous: 13
• LaTeX/Indexing Source: https://en.wikibooks.org/wiki/LaTeX/Indexing?oldid=2965527 Contributors: Itai, Derbeth, Mecanismo,
Stephan Schneider, Alejo2083, Mwtoews, Kovianyo, Uluboz, He7d3r, Pi zero, Neoptolemus, Dan Polansky, Tully~enwikibooks, More-
light~enwikibooks, Petter Strandmark, Neet, Kri, Adrignola, Sargas~enwikibooks, WardMuylaert, Dirk Hünniger, Tomato86, Semperos,
Nsuwan, Halilsen, SamuelLB, Toothbrushbrush, Bombcar and Anonymous: 15
• LaTeX/Glossary Source: https://en.wikibooks.org/wiki/LaTeX/Glossary?oldid=2973326 Contributors: Panic2k4, Recent Runes, Dan
Polansky, Redirect fixer, QuiteUnusual, Speravir, Pmlineditor, Ambrevar, Topodelapradera, Dirk Hünniger, Tomato86, Robbiemorrison,
Bro4, RealSebix, SamuelLB, MoMaT, Hendiadyon, Jessevanassen, Berettag, Tlinnet, Ffavela, Tanzaho, Gmacar, Tonda, Donok11 and
Anonymous: 34
• LaTeX/Bibliography Management Source: https://en.wikibooks.org/wiki/LaTeX/Bibliography_Management?oldid=2994754 Contribu-
tors: ZeroOne, Derbeth, Withinfocus, Orderud, Stephan Schneider, Jtwdog~enwikibooks, Igjimh, Alejo2083, Mwtoews, Braindrain0000,
Qwertyus, Rondenaranja~enwikibooks, Thenub314, Drewbie, Oderbolz, Spelemann~enwikibooks, Amamory, Kovianyo, Nbrouard,
MartinSpacek, Blaisorblade, He7d3r, Spag85~enwikibooks, Pi zero, Kevang, Waldir, Mhue, MichaelSchoenitzer, ChrisHodgesUK,
Kazkaskazkasako, Kroolik, Arbitrarily0, QuiteUnusual, Kri, Vermiculus~enwikibooks, Silca678, Rafaelgr, Rbonvall, Eyliu~enwikibooks,
StevenJohnston, Sandman10000, Sargas~enwikibooks, Nobelium, Ambrevar, Tdomhan, Lucasreddinger, John1923, Pilosa.Folivora, Tor-
fusPolymorphus, MichaelBueker, Topodelapradera, Dirk Hünniger, Lbailey45, Robbiemorrison, Rossdub, Crissov, Xonqnopp, Jevon, Nor-
bert.beckers, Mr. Stradivarius, Bro4, RealSebix, FranklyMyDear..., Gillespie09, Literaturgenerator, QUBot, PatrickGalyon, SamuelLB,
Jluttine, Austinmohr, Johannes Bo, Ch605852, Gmacar, Kurlovitsch, Jpoosterhuis, Syum90, Crabpot8, Kdonavin, Infinite0694, AdhillA97,
Einjohn and Anonymous: 159
• LaTeX/More Bibliographies Source: https://en.wikibooks.org/wiki/LaTeX/More_Bibliographies?oldid=2715264 Contributors: Adrig-
nola, Ambrevar, Jimbotyson, Billy the Goat II, Wootery and Anonymous: 14
• LaTeX/Letters Source: https://en.wikibooks.org/wiki/LaTeX/Letters?oldid=2981227 Contributors: Derbeth, Edudobay, Mwtoews, Xa-
nia, Jld, Garoth~enwikibooks, Pi zero, Neoptolemus, CarsracBot, Gms, ChrisHodgesUK, QuiteUnusual, Ambrevar, GavinMcGimpsey,
Tomato86, E.lewis1, SamuelLB, Empirical bayesian, TheAnarcat and Anonymous: 29
• LaTeX/Presentations Source: https://en.wikibooks.org/wiki/LaTeX/Presentations?oldid=2977259 Contributors: Ish ish-
war~enwikibooks, 3mta3, Derbeth, Xania, Kovianyo, Pi zero, Ramac, Dan Polansky, Flal, Jayk~enwikibooks, ChrisHodgesUK,
FredrikMeyer, Eyliu~enwikibooks, Dreaven3, PAC, Sanderd17, Sargas~enwikibooks, Avila.gas, Ambrevar, Gryllida, Stuples, PAC2,
NqpZ, Helptry, Grj23, Mezzaluna, Flip, Robbiemorrison, Neoriddle, Xonqnopp, Ghoti, SamuelLB, Dr0pi, Espinozahg, Goldkatze, Hapli,
Jerome.dequeker and Anonymous: 53
• LaTeX/Teacher’s Corner Source: https://en.wikibooks.org/wiki/LaTeX/Teacher’{}s_Corner?oldid=2983311 Contributors: PAC, Am-
brevar, PAC2, Tomato86, SamuelLB, Defender, Hapli and Anonymous: 10
12.2. IMAGES 193

• LaTeX/Curriculum Vitae Source: https://en.wikibooks.org/wiki/LaTeX/Curriculum_Vitae?oldid=2833988 Contributors: Jomegat, Qui-


teUnusual, Ambrevar, Reyk, Mariafenrinha, Jianhui67, CallumPoole and Anonymous: 12
• LaTeX/Introducing Procedural Graphics Source: https://en.wikibooks.org/wiki/LaTeX/Introducing_Procedural_Graphics?oldid=
2989008 Contributors: 3mta3, Kenyon, Jonathan Webley, Jomegat, Alejo2083, Mwtoews, Qwertyus, Rajkiran g, Pi zero, Dan Polansky,
Thefrankinator, Jacobrothstein, Niel.Bowerman, Simeon, ChrisHodgesUK, Tosha, Kri, Пика Пика, Adrignola, Ambrevar, Keplerspeed,
Unbitwise, Rnddim, Dirk Hünniger, Jdgilbey, Jflycn, Krisrose~enwikibooks, Tomato86, Kuer.gee, Wikieditoroftoday, Pmillerrhodes, At-
ulya1988, Franzl aus tirol, Wxm29, SamuelLB and Anonymous: 23
• LaTeX/MetaPost Source: https://en.wikibooks.org/wiki/LaTeX/MetaPost?oldid=2473798 Contributors: Ambrevar
• LaTeX/Picture Source: https://en.wikibooks.org/wiki/LaTeX/Picture?oldid=2836084 Contributors: Svick, Ambrevar, Wxm29, Tentotwo
and Anonymous: 9
• LaTeX/PGF/TikZ Source: https://en.wikibooks.org/wiki/LaTeX/PGF/TikZ?oldid=2841652 Contributors: JonnyJD, QuiteUnusual, Kri,
Nobelium, Ambrevar, Franzl aus tirol, Dlituiev and Anonymous: 10
• LaTeX/PSTricks Source: https://en.wikibooks.org/wiki/LaTeX/PSTricks?oldid=2975841 Contributors: ChrisHodgesUK, Ambrevar,
Ngoclong19, Netheril96, Karlberry and Anonymous: 2
• LaTeX/Xy-pic Source: https://en.wikibooks.org/wiki/LaTeX/Xy-pic?oldid=2976037 Contributors: ChrisHodgesUK, Kri, Ambrevar, Dirk
Hünniger and Ngoclong19
• LaTeX/Creating 3D graphics Source: https://en.wikibooks.org/wiki/LaTeX/Creating_3D_graphics?oldid=2982058 Contributors: Kri,
Nobelium, Ambrevar and Anonymous: 1
• LaTeX/Macros Source: https://en.wikibooks.org/wiki/LaTeX/Macros?oldid=2993428 Contributors: Risk, Mecanismo, Alejo2083, Mw-
toews, Pi zero, Tully~enwikibooks, Hsmyers~enwikibooks, Waldir, ChrisHodgesUK, LR~enwikibooks, Kri, Adrignola, Hosszuka, Ambre-
var, Go.pbam., Dirk Hünniger, Robbiemorrison, Aadornellesf, SamuelLB, Funkenstern, AsphyxiateDrake, Yeshua Saves, Mrwil222 and
Anonymous: 38
• LaTeX/Plain TeX Source: https://en.wikibooks.org/wiki/LaTeX/Plain_TeX?oldid=2988620 Contributors: Blaisorblade, Ambrevar,
Yeshua Saves, Bamgooly, Sheep0x and Anonymous: 9
• LaTeX/Creating Packages Source: https://en.wikibooks.org/wiki/LaTeX/Creating_Packages?oldid=2955673 Contributors: Ambrevar,
HansCronau and Anonymous: 5
• LaTeX/Themes Source: https://en.wikibooks.org/wiki/LaTeX/Themes?oldid=2504675 Contributors: Ambrevar and Anonymous: 1
• LaTeX/Modular Documents Source: https://en.wikibooks.org/wiki/LaTeX/Modular_Documents?oldid=2991899 Contributors: Derbeth,
Alejo2083, Mwtoews, Mike.lifeguard, Pi zero, ChrisHodgesUK, Neet, Adrignola, Nixphoeni, Liiiii, Frakturfreund, Zyqqh~enwikibooks,
Ambrevar, Robbiemorrison, Neoriddle, Ediahist, MaBoehm, SamuelLB, CD-Stevens, Vinaisundaram, Stefan.qn~enwikibooks, Wgjbeek,
MfR and Anonymous: 22
• LaTeX/Collaborative Writing of LaTeX Documents Source: https://en.wikibooks.org/wiki/LaTeX/Collaborative_Writing_of_LaTeX_
Documents?oldid=2771532 Contributors: Derbeth, Arnehe, Pi zero, Madskaddie, Schaber, Waldir, ChrisHodgesUK, QuiteUnusual, Tosha,
Kpym, Tim Parenti, Ambrevar, Keplerspeed, Jason barrington~enwikibooks, Dirk Hünniger, Bamgooly~enwikibooks, Robbiemorrison,
Glosser.ca, Wikieditoroftoday, Jmcdon10, Hermine potter, SamuelLB, Jbsnyder and Anonymous: 37
• LaTeX/Export To Other Formats Source: https://en.wikibooks.org/wiki/LaTeX/Export_To_Other_Formats?oldid=2964817 Contribu-
tors: Derbeth, Jomegat, Alejo2083, Mwtoews, Az1568, Pi zero, ChrisHodgesUK, Bpsullivan~enwikibooks, Bakken, Ambrevar, Kepler-
speed, SamuelLB, Wenzeslaus, Migueldvb, Xin-Xin W., Stefan.qn~enwikibooks and Anonymous: 28
• LaTeX/FAQ Source: https://en.wikibooks.org/wiki/LaTeX/FAQ?oldid=2962525 Contributors: Xania, Kayau, Nixphoeni, Ambrevar,
Ghostofkendo, Dredmorbius, Sobjornstad and Anonymous: 11
• LaTeX/Tips and Tricks Source: https://en.wikibooks.org/wiki/LaTeX/Tips_and_Tricks?oldid=2747440 Contributors: Derbeth, With-
infocus, Jguk, Alejo2083, Basenga, Mwtoews, Filip Dominec, Pi zero, Towsonu2003~enwikibooks, Brendanarnold, ChrisHodge-
sUK, Winniehell, Limpato, Vaffelkake, Sargas~enwikibooks, Ambrevar, Bumbulski, Tomato86, Robbiemorrison, Wikieditoroftoday,
Jamoroch~enwikibooks, Russell208, SamuelLB and Anonymous: 44
• LaTeX/Authors Source: https://en.wikibooks.org/wiki/LaTeX/Authors?oldid=2472489 Contributors: Derbeth, Alejo2083, Pi zero, Am-
brevar and Anonymous: 1
• LaTeX/Links Source: https://en.wikibooks.org/wiki/LaTeX/Links?oldid=2695762 Contributors: Derbeth, Jonathan Webley, Withinfocus,
Orderud, Dmb, Alejo2083, Jasu, Pi zero, Ambrevar, RaymondSutanto, Rotlink, Eselmeister and Anonymous: 7
• LaTeX/Package Reference Source: https://en.wikibooks.org/wiki/LaTeX/Package_Reference?oldid=2771320 Contributors: Dan Polan-
sky, Ambrevar, Wickedjargon, Dredmorbius and Anonymous: 1
• LaTeX/Sample LaTeX documents Source: https://en.wikibooks.org/wiki/LaTeX/Sample_LaTeX_documents?oldid=2465029 Contrib-
utors: Thenub314, Vesal, Pi zero, Ambrevar and Anonymous: 2
• LaTeX/Index Source: https://en.wikibooks.org/wiki/LaTeX/Index?oldid=2768358 Contributors: Derbeth, Jonathan Webley, Pi zero, Ra-
mac, Dan Polansky, Ffangs, TomyDuby, Avila.gas, Henridv, Ambrevar, Dirk Hünniger, Kevin Ryde and Anonymous: 1
• LaTeX/Command Glossary Source: https://en.wikibooks.org/wiki/LaTeX/Command_Glossary?oldid=2779997 Contributors: Robert
Horning, Derbeth, Withinfocus, Orderud, Naught101, Dmb, Igjimh, IrfanAli, Spelemann~enwikibooks, Paxinum, Pi zero, Dan Polan-
sky, TomyDuby, ChrisHodgesUK, Pstar, Adrignola, Tuetschek, Kpym, Royote, Stoettner, Dirk Hünniger, Robbiemorrison, Xeracles and
Anonymous: 30

12.2 Images
• File:50_percents.svg Source: https://upload.wikimedia.org/wikipedia/commons/6/62/50_percents.svg License: CC0 Contributors: File:
50%.svg Original artist: Ftiercel
194 CHAPTER 12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES

• File:Acetate-ion.png Source: https://upload.wikimedia.org/wikipedia/commons/2/23/Acetate-ion.png License: CC BY-SA 3.0 Contrib-


utors: Own work Original artist: Pmillerrhodes
• File:Acetate-ion2.png Source: https://upload.wikimedia.org/wikipedia/commons/b/b3/Acetate-ion2.png License: CC BY-SA 3.0 Con-
tributors: Own work Original artist: Pmillerrhodes
• File:Alltt.svg Source: https://upload.wikimedia.org/wikipedia/commons/5/5c/Alltt.svg License: CC BY-SA 3.0 Contributors: Own work
Original artist: Dirk Hünniger
• File:Ammonium_sulphate_mhchem.png Source: https://upload.wikimedia.org/wikibooks/en/1/11/Ammonium_sulphate_mhchem.
png License: Cc-by-3.0 Contributors: ? Original artist: ?
• File:BibDesk-1.3.10-screenshot.png Source: https://upload.wikimedia.org/wikibooks/en/c/ce/BibDesk-1.3.10-screenshot.png License:
Public domain Contributors:
own work
Original artist:
Mij
• File:BibDesk1.3.8.jpg Source: https://upload.wikimedia.org/wikipedia/commons/6/63/BibDesk1.3.8.jpg License: Public domain Con-
tributors: My computer Original artist: Myself
• File:Blocks_beamer_example.png Source: https://upload.wikimedia.org/wikipedia/commons/2/20/Blocks_beamer_example.png Li-
cense: CC BY-SA 3.0 Contributors: Own work Original artist: Israel Buitron
• File:Book_important2.svg Source: https://upload.wikimedia.org/wikipedia/commons/9/91/Book_important2.svg License: CC BY-SA
3.0 Contributors: Own work Original artist: darklama
• File:Bordermatrix.png Source: https://upload.wikimedia.org/wikipedia/commons/c/cc/Bordermatrix.png License: Public domain Con-
tributors: Own work Original artist: Winfree
• File:Butane-skeletal.png Source: https://upload.wikimedia.org/wikipedia/commons/e/eb/Butane-skeletal.png License: Public domain
Contributors: self-made in ChemDraw Original artist: Ben Mills
• File:Carbon_Lewis_Structure_PNG.png Source: https://upload.wikimedia.org/wikipedia/commons/5/5b/Carbon_Lewis_Structure_
PNG.png License: CC BY-SA 4.0 Contributors: Own work Original artist: Daviewales
• File:Cat-eats-cream.png Source: https://upload.wikimedia.org/wikipedia/commons/1/16/Cat-eats-cream.png License: CC BY-SA 3.0
Contributors: Own work Original artist: Olesh
• File:Chemfig_angles.png Source: https://upload.wikimedia.org/wikipedia/commons/0/0f/Chemfig_angles.png License: CC BY-SA 3.0
Contributors: Own work Original artist: Pmillerrhodes
• File:Chemfig_bonds.png Source: https://upload.wikimedia.org/wikipedia/commons/0/0f/Chemfig_bonds.png License: CC BY-SA 3.0
Contributors: Own work Original artist: Pmillerrhodes
• File:Chick1.png Source: https://upload.wikimedia.org/wikipedia/commons/5/54/Chick1.png License: CC-BY-SA-3.0 Contributors:
Transferred from en.wikibooks to Commons by Sanderd17 using CommonsHelper. Original artist: The original uploader was Jtwdog
at English Wikibooks
• File:Clipboard.svg Source: https://upload.wikimedia.org/wikipedia/commons/1/1f/Clipboard.svg License: GPL Contributors: Self-made.
Based on Image:Evolution-tasks-old.png, which was released into the public domain by its creator AzaToth. Original artist: Tkgd2007
• File:Corticosterone_(1).png Source: https://upload.wikimedia.org/wikipedia/commons/7/7c/Corticosterone_%281%29.png License:
Public domain Contributors: Transferred from en.wikipedia; transferred to Commons by User:Sfan00_IMG using CommonsHelper. Orig-
inal artist: Original uploader was Iorsh at en.wikipedia
• File:Dashes.png Source: https://upload.wikimedia.org/wikibooks/en/d/dc/Dashes.png License: GFDL Contributors: ? Original artist: ?
• File:Desc.svg Source: https://upload.wikimedia.org/wikipedia/commons/8/84/Example_of_description_environment_result_using_
LaTeX.svg License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:ESvn-texmf.png Source: https://upload.wikimedia.org/wikipedia/commons/1/15/ESvn-texmf.png License: GPL Contributors:
Transferred from en.wikibooks; transferred to Commons by User:Adrignola using CommonsHelper. Original artist: Original uploader
was Arnehe at en.wikibooks
• File:Emph.png Source: https://upload.wikimedia.org/wikibooks/en/a/a8/Emph.png License: GFDL Contributors: ? Original artist: ?
• File:Enum.svg Source: https://upload.wikimedia.org/wikipedia/commons/2/2b/Enum.svg License: CC BY-SA 3.0 Contributors: Own
work Original artist: Dirk Hünniger
• File:Enumerate.png Source: https://upload.wikimedia.org/wikipedia/commons/3/3a/Enumerate.png License: CC BY-SA 3.0 Contribu-
tors: Own work Original artist: Lanoxx
• File:Envelope.jpg Source: https://upload.wikimedia.org/wikibooks/en/e/ef/Envelope.jpg License: Public domain Contributors: ? Original
artist: ?
• File:Example_of_French_quotation_marks.png Source: https://upload.wikimedia.org/wikipedia/commons/0/01/Example_of_
French_quotation_marks.png License: CC BY-SA 3.0 Contributors: Own work Original artist: Karl Scheel
• File:Example_of_German_quotation_marks.png Source: https://upload.wikimedia.org/wikipedia/commons/5/55/Example_of_
German_quotation_marks.png License: CC BY-SA 3.0 Contributors: Own work Original artist: Karl Scheel
• File:Frametitle_keyword_example.png Source: https://upload.wikimedia.org/wikipedia/commons/8/8c/Frametitle_keyword_example.
png License: CC BY-SA 3.0 Contributors: Own work Original artist: Israel Buitron
• File:Gb4e1.png Source: https://upload.wikimedia.org/wikipedia/commons/6/67/Gb4e1.png License: CC0 Contributors: Own work Orig-
inal artist: jeg
• File:Gb4e2.png Source: https://upload.wikimedia.org/wikipedia/commons/0/0c/Gb4e2.png License: CC BY-SA 3.0 Contributors: Own
work Original artist: Hankjones
12.2. IMAGES 195

• File:Gb4e3.png Source: https://upload.wikimedia.org/wikipedia/commons/6/67/Gb4e3.png License: CC BY-SA 3.0 Contributors: Own


work Original artist: Hankjones
• File:Gb4e4.png Source: https://upload.wikimedia.org/wikipedia/commons/1/1a/Gb4e4.png License: CC BY-SA 3.0 Contributors: Own
work Original artist: Hankjones
• File:Gummi_0.6.1_screenshot.png Source: https://upload.wikimedia.org/wikipedia/commons/1/10/Gummi_0.6.1_screenshot.png Li-
cense: MIT Contributors: Transferred from en.wikipedia; transferred to Commons by User:FSII using CommonsHelper on Labs.
Original artist: Gummi team. Original uploader was Sanderd17 at en.wikipedia
• File:H2O_Lewis_Structure_PNG.png Source: https://upload.wikimedia.org/wikipedia/commons/1/18/H2O_Lewis_Structure_PNG.
png License: CC BY-SA 4.0 Contributors: Own work Original artist: Daviewales
• File:Information_icon4.svg Source: https://upload.wikimedia.org/wikipedia/commons/1/1d/Information_icon4.svg License: Public do-
main Contributors: modified versions from below, which were modifies of http://www.kde-look.org/ Original artist: penubag (color adjust-
ments)
• File:Ion-example.png Source: https://upload.wikimedia.org/wikipedia/commons/1/10/Ion-example.png License: CC BY-SA 3.0 Con-
tributors: No machine readable source provided. Own work assumed (based on copyright claims). Original artist: No machine readable
author provided. Pmillerrhodes assumed (based on copyright claims).
• File:Ipa1.png Source: https://upload.wikimedia.org/wikipedia/commons/2/29/Ipa1.png License: CC BY-SA 3.0 Contributors: Own work
Original artist: Hankjones
• File:Ipa2.png Source: https://upload.wikimedia.org/wikipedia/commons/2/22/Ipa2.png License: CC BY-SA 3.0 Contributors: Own work
Original artist: Hankjones
• File:Ipa3.png Source: https://upload.wikimedia.org/wikipedia/commons/9/90/Ipa3.png License: CC BY-SA 3.0 Contributors: Own work
Original artist: Hankjones
• File:Ipa4.png Source: https://upload.wikimedia.org/wikipedia/commons/a/a8/Ipa4.png License: CC BY-SA 3.0 Contributors: Own work
Original artist: Hankjones
• File:Ipa5.png Source: https://upload.wikimedia.org/wikipedia/commons/9/9f/Ipa5.png License: CC BY-SA 3.0 Contributors: Own work
Original artist: Hankjones
• File:Ipa6.png Source: https://upload.wikimedia.org/wikipedia/commons/c/ca/Ipa6.png License: CC BY-SA 3.0 Contributors: Own work
Original artist: Hankjones
• File:Ipa7.png Source: https://upload.wikimedia.org/wikipedia/commons/4/40/Ipa7.png License: CC0 Contributors: Own work Original
artist: ChrisHodgesUK
• File:Itemize.svg Source: https://upload.wikimedia.org/wikipedia/commons/a/a9/Itemize.svg License: CC BY-SA 3.0 Contributors: Own
work Original artist: Dirk Hünniger
• File:JabRef-ExternalPrograms.png Source: https://upload.wikimedia.org/wikipedia/commons/e/e9/JabRef-ExternalPrograms.png Li-
cense: GPL Contributors: Transferred from en.wikibooks; transferred to Commons by User:Adrignola using CommonsHelper. Original
artist: Original uploader was Arnehe at en.wikibooks
• File:JabRef-GeneralFields.png Source: https://upload.wikimedia.org/wikipedia/commons/8/8c/JabRef-GeneralFields.png License:
GPL Contributors: Transferred from en.wikibooks; transferred to Commons by User:Adrignola using CommonsHelper. Original artist:
Original uploader was Arnehe at en.wikibooks
• File:JabRef-KeyPattern.png Source: https://upload.wikimedia.org/wikipedia/commons/8/87/JabRef-KeyPattern.png License: GPL
Contributors: Transferred from en.wikibooks; transferred to Commons by User:Adrignola using CommonsHelper. Original artist: Original
uploader was Arnehe at en.wikibooks
• File:Jabref-2.2-screenshot.png Source: https://upload.wikimedia.org/wikipedia/commons/8/84/Jabref-2.2-screenshot.png License:
CC-BY-SA-3.0 Contributors: ? Original artist: ?
• File:Kdiff3-modification.png Source: https://upload.wikimedia.org/wikipedia/commons/c/c1/Kdiff3-modification.png License: GPL
Contributors: Transferred from en.wikibooks; transferred to Commons by User:Adrignola using CommonsHelper. Original artist: Original
uploader was Arnehe at en.wikibooks
• File:Kile_1.9.3.png Source: https://upload.wikimedia.org/wikipedia/commons/e/e2/Kile_1.9.3.png License: GPL Contributors: ? Origi-
nal artist: ?
• File:Koma_env.png Source: https://upload.wikimedia.org/wikibooks/en/0/05/Koma_env.png License: Cc-by-sa-3.0 Contributors:
own work, basing on “Formal - Another proposition” from Wikipedia:Example requests for permission under GFDL license
Original artist:
gms
• File:LaTeX-boxed-equation.png Source: https://upload.wikimedia.org/wikipedia/commons/0/02/LaTeX-boxed-equation.png License:
CC BY-SA 3.0 Contributors: Own work Original artist: Tomato86
• File:LaTeX-boxed-formula-minipage.png Source: https://upload.wikimedia.org/wikipedia/commons/a/ab/
LaTeX-boxed-formula-minipage.png License: CC BY-SA 3.0 Contributors: Own work Original artist: Tomato86
• File:LaTeX-dingbats.png Source: https://upload.wikimedia.org/wikibooks/en/5/56/LaTeX-dingbats.png License: GFDL Contributors:
http://andy-roberts.net/misc/latex/tutorial7/dingbats.png Original artist:
Andrew Roberts
• File:LaTeX-displaybreak-in-math.png Source: https://upload.wikimedia.org/wikipedia/commons/0/0d/LaTeX-displaybreak-in-math.
png License: CC BY-SA 3.0 Contributors: Own work Original artist: Tomato86
• File:LaTeX-letter.png Source: https://upload.wikimedia.org/wikibooks/en/f/f0/LaTeX-letter.png License: GFDL Contributors:
own work, basing on “Formal - Another proposition” from Wikipedia:Example requests for permission under GFDL license Original artist:
Derbeth
196 CHAPTER 12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES

• File:LaTeX-mathclap-example.png Source: https://upload.wikimedia.org/wikipedia/commons/c/cd/LaTeX-mathclap-example.png Li-


cense: CC BY-SA 3.0 Contributors: Own work Original artist: Tomato86
• File:LaTeX-mathtools-arrows.png Source: https://upload.wikimedia.org/wikipedia/commons/2/2e/LaTeX-mathtools-arrows.png Li-
cense: CC BY-SA 3.0 Contributors: Own work Original artist: Tomato86
• File:LaTeX-mathtools-brackets.png Source: https://upload.wikimedia.org/wikipedia/commons/b/b7/LaTeX-mathtools-brackets.png
License: CC BY-SA 3.0 Contributors: Own work Original artist: Tomato86
• File:LaTeX-mathtools-harpoons.png Source: https://upload.wikimedia.org/wikipedia/commons/3/33/LaTeX-mathtools-harpoons.png
License: CC BY-SA 3.0 Contributors: Own work Original artist: Tomato86
• File:LaTeX-smallmatrix.png Source: https://upload.wikimedia.org/wikipedia/commons/6/63/LaTeX-smallmatrix.png License: CC
BY-SA 3.0 Contributors: Own work Original artist: Tomato86
• File:LaTeX-xfrac-example.png Source: https://upload.wikimedia.org/wikipedia/commons/9/9c/LaTeX-xfrac-example.png License:
CC BY-SA 3.0 Contributors: Own work Original artist: Tomato86
• File:LaTeXAlternateRowTable.svg Source: https://upload.wikimedia.org/wikipedia/commons/e/e7/LaTeXAlternateRowTable.svg Li-
cense: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_-_Indented_Equations.png Source: https://upload.wikimedia.org/wikipedia/commons/f/fc/LaTeX_-_Indented_
Equations.png License: Public domain Contributors: Own work Original artist: Inductiveload
• File:LaTeX_Dotsb.png Source: https://upload.wikimedia.org/wikipedia/commons/6/60/LaTeX_Dotsb.png License: Public domain Con-
tributors: Own work Original artist: Neet
• File:LaTeX_Dotsc.png Source: https://upload.wikimedia.org/wikipedia/commons/0/0f/LaTeX_Dotsc.png License: Public domain Con-
tributors: Own work Original artist: Neet
• File:LaTeX_Dotsi.png Source: https://upload.wikimedia.org/wikipedia/commons/5/55/LaTeX_Dotsi.png License: Public domain Con-
tributors: Own work Original artist: Neet
• File:LaTeX_Dotsm.png Source: https://upload.wikimedia.org/wikipedia/commons/5/59/LaTeX_Dotsm.png License: Public domain
Contributors: Own work Original artist: Neet
• File:LaTeX_Dotso.png Source: https://upload.wikimedia.org/wikipedia/commons/b/b5/LaTeX_Dotso.png License: Public domain Con-
tributors: Own work Original artist: Neet
• File:LaTeX_TabWidth1.svg Source: https://upload.wikimedia.org/wikipedia/commons/0/0c/LaTeX_TabWidth1.svg License: CC BY-
SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_TabWidth2.svg Source: https://upload.wikimedia.org/wikipedia/commons/b/b4/LaTeX_TabWidth2.svg License: CC BY-
SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_TabXWidth1.svg Source: https://upload.wikimedia.org/wikipedia/commons/0/07/LaTeX_TabXWidth1.svg License: CC
BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_TabXWidth2.svg Source: https://upload.wikimedia.org/wikipedia/commons/e/ee/LaTeX_TabXWidth2.svg License: CC
BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_animal_table.svg Source: https://upload.wikimedia.org/wikipedia/commons/7/79/LaTeX_animal_table.svg License: CC
BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_animal_table_with_booktabs.svg Source: https://upload.wikimedia.org/wikipedia/commons/8/8d/LaTeX_animal_table_
with_booktabs.svg License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_bibliography_abbrv.svg Source: https://upload.wikimedia.org/wikipedia/commons/0/00/LaTeX_bibliography_abbrv.svg
License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_bibliography_alpha.svg Source: https://upload.wikimedia.org/wikipedia/commons/b/bb/LaTeX_bibliography_alpha.svg
License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_bibliography_plain.svg Source: https://upload.wikimedia.org/wikipedia/commons/0/08/LaTeX_bibliography_plain.svg
License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_colour_demo_1.png Source: https://upload.wikimedia.org/wikipedia/commons/f/f7/LaTeX_colour_demo_1.png License:
CC0 Contributors: Own work Original artist: ChrisHodgesUK
• File:LaTeX_desc-newline.svg Source: https://upload.wikimedia.org/wikipedia/commons/2/27/LaTeX_desc-newline.svg License: CC
BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:LaTeX_diagram.svg Source: https://upload.wikimedia.org/wikipedia/commons/7/78/LaTeX_diagram.svg License: CC-BY-SA-3.0
Contributors: This vector image was created with Inkscape. Original artist: Alessio Damato
• File:LaTeX_example_dcolumn.png Source: https://upload.wikimedia.org/wikipedia/commons/4/42/LaTeX_example_dcolumn.png Li-
cense: CC0 Contributors: Own work Original artist: ChrisHodgesUK
• File:LaTeX_example_dcolumn_bold.png Source: https://upload.wikimedia.org/wikipedia/commons/e/e6/LaTeX_example_dcolumn_
bold.png License: CC0 Contributors: Own work Original artist: ChrisHodgesUK
• File:LaTeX_example_split_gather.png Source: https://upload.wikimedia.org/wikipedia/commons/0/0b/LaTeX_example_split_gather.
png License: CC0 Contributors: Own work Original artist: ChrisHodgesUK
• File:LaTeX_example_sqrt.png Source: https://upload.wikimedia.org/wikipedia/commons/c/ca/LaTeX_example_sqrt.png License: CC0
Contributors: Own work Original artist: ChrisHodgesUK
• File:LaTeX_figure_caption_with_lof_entry.png Source: https://upload.wikimedia.org/wikipedia/commons/f/f7/LaTeX_figure_
caption_with_lof_entry.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Mwtoews
• File:LaTeX_font_example.png Source: https://upload.wikimedia.org/wikipedia/commons/8/87/LaTeX_font_example.png License:
CC0 Contributors: Own work Original artist: ChrisHodgesUK
12.2. IMAGES 197

• File:LaTeX_logo.svg Source: https://upload.wikimedia.org/wikipedia/commons/9/92/LaTeX_logo.svg License: Public domain Contrib-


utors: ? Original artist: ?
• File:LaTeX_program_package_example01.png Source: https://upload.wikimedia.org/wikipedia/commons/4/45/LaTeX_program_
package_example01.png License: CC BY-SA 3.0 Contributors: Own work Original artist: MyName (Gkc (<a href='//commons.wikimedia.
org/wiki/User_talk:Gkc' title='User talk:Gkc'>talk</a>))
• File:LaTeX_sloppypar.png Source: https://upload.wikimedia.org/wikibooks/en/a/ac/LaTeX_sloppypar.png License: Public domain
Contributors:
own work
Original artist:
Derbeth
• File:LaTeX_tabularx_multi.svg Source: https://upload.wikimedia.org/wikipedia/commons/8/8c/LaTeX_tabularx_multi.svg License:
CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:Latex-Aboxed-example.png Source: https://upload.wikimedia.org/wikipedia/commons/8/8f/Latex-Aboxed-example.png License:
CC0 Contributors: Own work Original artist: ChrisHodgesUK
• File:Latex-algorithm2e-if-else.png Source: https://upload.wikimedia.org/wikipedia/commons/6/6d/Latex-algorithm2e-if-else.png Li-
cense: CC BY-SA 3.0 Contributors: Own work Original artist: Lavaka
• File:Latex-algorithmic-if-else.png Source: https://upload.wikimedia.org/wikipedia/commons/3/3b/Latex-algorithmic-if-else.png Li-
cense: Public domain Contributors: Own work Original artist: Nemti
• File:Latex-dependency-parse-example-with-tikz-dependency.png Source: https://upload.wikimedia.org/wikipedia/commons/6/61/
Latex-dependency-parse-example-with-tikz-dependency.png License: GFDL Contributors: Own work Original artist: Daniele Pighin
• File:Latex-intertext.png Source: https://upload.wikimedia.org/wikipedia/commons/9/9b/Latex-intertext.png License: CC BY-SA 3.0
Contributors: Own work Original artist: Tomato86
• File:Latex-tables-double-dichotomy-example.svg Source: https://upload.wikimedia.org/wikipedia/commons/0/0a/
Latex-tables-double-dichotomy-example.svg License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:Latex-tikz-simple-deptree.png Source: https://upload.wikimedia.org/wikipedia/commons/2/2c/Latex-tikz-simple-deptree.png Li-
cense: Public domain Contributors: Own work Original artist: Matěj Korvas
• File:Latex-xyling-simple-deptree.png Source: https://upload.wikimedia.org/wikipedia/commons/2/2b/Latex-xyling-simple-deptree.
png License: CC0 Contributors: Own work Original artist: Matej.korvas
• File:Latex-xyling-simple-text-with-deptree.png Source: https://upload.wikimedia.org/wikipedia/commons/9/96/
Latex-xyling-simple-text-with-deptree.png License: CC0 Contributors: Own work Original artist: Matej.korvas
• File:Latex-xymatrix.png Source: https://upload.wikimedia.org/wikipedia/commons/4/41/Latex-xymatrix.png License: CC0 Contribu-
tors: Own work Original artist: ChrisHodgesUK
• File:Latex_Beamer_-_Columns_Example_2.png Source: https://upload.wikimedia.org/wikipedia/commons/0/02/Latex_Beamer_-_
Columns_Example_2.png License: CC BY-SA 3.0 Contributors: Own work Original artist: Flip
• File:Latex_Pascal_Listing.png Source: https://upload.wikimedia.org/wikipedia/commons/3/3e/Latex_Pascal_Listing.png License: CC
BY 3.0 Contributors: LaTeX / GIMP Original artist: LaTeX / GIMP
• File:Latex_caption_example.png Source: https://upload.wikimedia.org/wikipedia/commons/d/de/Latex_caption_example.png License:
CC-BY-SA-3.0 Contributors: own work, but the image of the gull that’s from commons Image:Gull portrait ca usa.jpg Original artist:
Alessio Damato
• File:Latex_dashes_example.png Source: https://upload.wikimedia.org/wikipedia/commons/9/97/Latex_dashes_example.png License:
CC-BY-SA-3.0 Contributors: it’s from The not so short introduction to LaTeX, a GPLed book by Tobias Oetiker, used with permission of
the author Original artist: Tobias Oetiker
• File:Latex_example_arrows.png Source: https://upload.wikimedia.org/wikipedia/commons/0/0c/Latex_example_arrows.png License:
CC-BY-SA-3.0 Contributors: part of "the not so short introduction to LaTeX", used with permission of the author Original artist: Alessio
Damato
• File:Latex_example_bezier.png Source: https://upload.wikimedia.org/wikipedia/commons/a/a5/Latex_example_bezier.png License:
CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author Original artist: Alessio
Damato
• File:Latex_example_box_test.png Source: https://upload.wikimedia.org/wikipedia/commons/3/35/Latex_example_box_test.png Li-
cense: CC-BY-SA-3.0 Contributors: taken as a screenshot of <a data-x-rel='nofollow' class='external text' href='http://www.ctan.org/
tex-archive/info/lshort/english/lshort.pdf'>The not so short introduction to LaTeX</a>, used with permission of the authors Original artist:
Alessio Damato
• File:Latex_example_box_test_2.png Source: https://upload.wikimedia.org/wikipedia/commons/9/9d/Latex_example_box_test_2.png
License: CC-BY-SA-3.0 Contributors: taken as a screenshot of <a data-x-rel='nofollow' class='external text' href='http://www.ctan.org/
tex-archive/info/lshort/english/lshort.pdf'>The not so short introduction to LaTeX</a>, used with permission of the authors Original artist:
Alessio Damato
• File:Latex_example_catenary.png Source: https://upload.wikimedia.org/wikipedia/commons/c/ca/Latex_example_catenary.png Li-
cense: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author Original artist:
Alessio Damato
• File:Latex_example_circles.png Source: https://upload.wikimedia.org/wikipedia/commons/a/a3/Latex_example_circles.png License:
CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author Original artist: Alessio
Damato
• File:Latex_example_defining_multiple_columns.svg Source: https://upload.wikimedia.org/wikipedia/commons/9/96/Latex_
example_defining_multiple_columns.svg License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
198 CHAPTER 12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES

• File:Latex_example_enumitem_inline_list.svg Source: https://upload.wikimedia.org/wikipedia/commons/d/d8/Latex_example_


enumitem_inline_list.svg License: CC BY-SA 3.0 Contributors: Own work Original artist: Arthurchy
• File:Latex_example_figure_referencing.png Source: https://upload.wikimedia.org/wikipedia/commons/e/ef/Latex_example_figure_
referencing.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato 13:31, 12 January 2007 (UTC)
• File:Latex_example_ligatures.png Source: https://upload.wikimedia.org/wikipedia/commons/9/99/Latex_example_ligatures.png Li-
cense: CC-BY-SA-3.0 Contributors: it’s from The not so short introduction to LaTeX, a GPLed book by Tobias Oetiker, used with permis-
sion of the author Original artist: Tobias Oetiker
• File:Latex_example_line_segments.png Source: https://upload.wikimedia.org/wikipedia/commons/6/6a/Latex_example_line_
segments.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author
Original artist: Alessio Damato
• File:Latex_example_math_referencing.png Source: https://upload.wikimedia.org/wikipedia/commons/4/48/Latex_example_math_
referencing.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
• File:Latex_example_middle.png Source: https://upload.wikimedia.org/wikipedia/commons/1/15/Latex_example_middle.png License:
CC0 Contributors: Own work Original artist: ChrisHodgesUK
• File:Latex_example_multiple_pics.png Source: https://upload.wikimedia.org/wikipedia/commons/0/0e/Latex_example_multiple_
pics.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author
Original artist: Alessio Damato
• File:Latex_example_multiput.png Source: https://upload.wikimedia.org/wikipedia/commons/b/b7/Latex_example_multiput.png Li-
cense: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author Original artist:
Alessio Damato
• File:Latex_example_newenvironment.png Source: https://upload.wikimedia.org/wikipedia/commons/6/6e/Latex_example_
newenvironment.png License: CC-BY-SA-3.0 Contributors: taken as a screenshot of <a data-x-rel='nofollow' class='external text'
href='http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf'>The not so short introduction to LaTeX</a>, used with permission
of the authors Original artist: Alessio Damato
• File:Latex_example_ovals.png Source: https://upload.wikimedia.org/wikipedia/commons/3/3d/Latex_example_ovals.png License: CC-
BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author Original artist: Alessio Damato
• File:Latex_example_paralist.svg Source: https://upload.wikimedia.org/wikipedia/commons/7/75/Latex_example_paralist.svg License:
CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:Latex_example_rapidity.png Source: https://upload.wikimedia.org/wikipedia/commons/d/dd/Latex_example_rapidity.png Li-
cense: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author Original artist:
Alessio Damato
• File:Latex_example_referencing_section.png Source: https://upload.wikimedia.org/wikipedia/commons/e/e5/Latex_example_
referencing_section.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
• File:Latex_example_rule.png Source: https://upload.wikimedia.org/wikipedia/commons/6/67/Latex_example_rule.png License: CC-
BY-SA-3.0 Contributors: taken as a screenshot of <a data-x-rel='nofollow' class='external text' href='http://www.ctan.org/tex-archive/info/
lshort/english/lshort.pdf'>The not so short introduction to LaTeX</a>, used with permission of the authors Original artist: Alessio Damato
• File:Latex_example_sidecap.png Source: https://upload.wikimedia.org/wikipedia/commons/5/59/Latex_example_sidecap.png License:
CC-BY-SA-3.0 Contributors: Own work Original artist: User:Mwtoews
• File:Latex_example_subfig.png Source: https://upload.wikimedia.org/wikipedia/commons/e/e5/Latex_example_subfig.png License:
CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
• File:Latex_example_tabular_cline.svg Source: https://upload.wikimedia.org/wikipedia/commons/e/e1/Latex_example_tabular_cline.
svg License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:Latex_example_text_dots.png Source: https://upload.wikimedia.org/wikipedia/commons/7/74/Latex_example_text_dots.png Li-
cense: CC-BY-SA-3.0 Contributors: it’s from The not so short introduction to LaTeX, a GPLed book by Tobias Oetiker, used with permis-
sion of the author Original artist: Tobias Oetiker
• File:Latex_example_text_formulas.png Source: https://upload.wikimedia.org/wikipedia/commons/f/f7/Latex_example_text_
formulas.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author
Original artist: Alessio Damato
• File:Latex_example_wrapfig.png Source: https://upload.wikimedia.org/wikipedia/commons/7/74/Latex_example_wrapfig.png Li-
cense: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
• File:Latex_example_wrapfig_vspace.png Source: https://upload.wikimedia.org/wikipedia/commons/d/dc/Latex_example_wrapfig_
vspace.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
• File:Latex_example_wrapped_table.svg Source: https://upload.wikimedia.org/wikipedia/commons/a/a5/Latex_example_wrapped_
table.svg License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:Latex_example_xypics_arrow_list.png Source: https://upload.wikimedia.org/wikipedia/commons/a/a8/Latex_example_xypics_
arrow_list.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author
Original artist: Alessio Damato
• File:Latex_example_xypics_arrows_1.png Source: https://upload.wikimedia.org/wikipedia/commons/d/d4/Latex_example_xypics_
arrows_1.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the au-
thor Original artist: Alessio Damato
• File:Latex_example_xypics_arrows_2.png Source: https://upload.wikimedia.org/wikipedia/commons/5/52/Latex_example_xypics_
arrows_2.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the au-
thor Original artist: Alessio Damato
12.2. IMAGES 199

• File:Latex_example_xypics_arrows_3.png Source: https://upload.wikimedia.org/wikipedia/commons/5/5a/Latex_example_xypics_


arrows_3.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the au-
thor Original artist: Alessio Damato
• File:Latex_example_xypics_arrows_labels.png Source: https://upload.wikimedia.org/wikipedia/commons/5/54/Latex_example_
xypics_arrows_labels.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission
of the author Original artist: Alessio Damato
• File:Latex_example_xypics_basic.png Source: https://upload.wikimedia.org/wikipedia/commons/d/d6/Latex_example_xypics_basic.
png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission of the author Origi-
nal artist: Alessio Damato
• File:Latex_example_xypics_curved_arrow.png Source: https://upload.wikimedia.org/wikipedia/commons/f/f0/Latex_example_
xypics_curved_arrow.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission
of the author Original artist: Alessio Damato
• File:Latex_example_xypics_inarrow_labels.png Source: https://upload.wikimedia.org/wikipedia/commons/9/97/Latex_example_
xypics_inarrow_labels.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permission
of the author Original artist: Alessio Damato
• File:Latex_example_xypics_standard_arrow.png Source: https://upload.wikimedia.org/wikipedia/commons/c/cf/Latex_example_
xypics_standard_arrow.png License: CC-BY-SA-3.0 Contributors: part of “the not so short introduction to LaTeX”, used with permis-
sion of the author Original artist: Alessio Damato
• File:Latex_layout.svg Source: https://upload.wikimedia.org/wikipedia/commons/a/ad/Latex_layout.svg License: CC-BY-SA-3.0 Con-
tributors: the layout.sty LaTeX package, heavily post-processed by myself Original artist: Alessio Damato
• File:Latex_new_squareroot.png Source: https://upload.wikimedia.org/wikipedia/commons/b/bd/Latex_new_squareroot.png License:
CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
• File:Latex_picture_example.png Source: https://upload.wikimedia.org/wikipedia/commons/c/cc/Latex_picture_example.png License:
CC0 Contributors: Own work Original artist: ChrisHodgesUK
• File:Latex_qtree_simple_tree.png Source: https://upload.wikimedia.org/wikipedia/commons/1/1d/Latex_qtree_simple_tree.png Li-
cense: CC0 Contributors: Own work Original artist: Philip John Gorinski
• File:Latex_quote_3.png Source: https://upload.wikimedia.org/wikipedia/commons/a/a3/Latex_quote_3.png License: CC BY-SA 3.0
Contributors: Own work Original artist: Thenub314
• File:Latex_quote_4.png Source: https://upload.wikimedia.org/wikipedia/commons/a/ac/Latex_quote_4.png License: CC BY-SA 3.0
Contributors: Own work Original artist: Tomato86
• File:Latex_ready-made_strings.png Source: https://upload.wikimedia.org/wikipedia/commons/3/3a/Latex_ready-made_strings.png
License: CC-BY-SA-3.0 Contributors: it’s from The not so short introduction to LaTeX, a GPLed book by Tobias Oetiker, used with
permission of the author Original artist: Tobias Oetiker
• File:Latex_showkeys_example.png Source: https://upload.wikimedia.org/wikipedia/commons/2/24/Latex_showkeys_example.png Li-
cense: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
• File:Listings_Example.svg Source: https://upload.wikimedia.org/wikipedia/commons/4/4b/Listings_Example.svg License: CC BY-SA
3.0 Contributors: Own work Original artist: Ambrevar
• File:Literatur-Generator.jpg Source: https://upload.wikimedia.org/wikipedia/commons/d/d2/Literatur-Generator.jpg License: CC BY
3.0 Contributors: Own work Original artist: Literaturgenerator
• File:LyX1.6.3.png Source: https://upload.wikimedia.org/wikipedia/commons/4/42/LyX1.6.3.png License: Public domain Contributors:
Screenshot taken by myself. Original artist: LyX developer team (see www.lyx.org)
• File:Mathscr_(A-F).png Source: https://upload.wikimedia.org/wikipedia/commons/2/28/Mathscr_%28A-F%29.png License: CC-BY-
SA-3.0 Contributors: File:Mathscr.png Original artist: Waldir
• File:Merge-arrow.svg Source: https://upload.wikimedia.org/wikipedia/commons/a/aa/Merge-arrow.svg License: Public domain Contrib-
utors: ? Original artist: ?
• File:Methane_chemfig.png Source: https://upload.wikimedia.org/wikipedia/commons/3/33/Methane_chemfig.png License: CC BY-SA
3.0 Contributors: Own work Original artist: Pmillerrhodes
• File:Multicolumn.svg Source: https://upload.wikimedia.org/wikipedia/commons/8/8a/Multicolumn.svg License: CC BY-SA 3.0 Con-
tributors: Own work Original artist: Dirk Hünniger
• File:Multirow.svg Source: https://upload.wikimedia.org/wikipedia/commons/1/1c/Multirow.svg License: CC BY-SA 3.0 Contributors:
Own work Original artist: Dirk Hünniger
• File:Multirowandcolumnexample.svg Source: https://upload.wikimedia.org/wikipedia/commons/f/fe/Multirowandcolumnexample.svg
License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:Neighbourhood_definition2.svg Source: https://upload.wikimedia.org/wikipedia/commons/2/21/Neighbourhood_definition2.svg
License: CC BY-SA 3.0 Contributors:
• Neighbourhood_definition2.png Original artist: Neighbourhood_definition2.png: Wegmann
• File:Nested.svg Source: https://upload.wikimedia.org/wikipedia/commons/d/d3/Nested.svg License: CC BY-SA 3.0 Contributors: Own
work Original artist: Dirk Hünniger
• File:Nuvola_apps_important_yellow.svg Source: https://upload.wikimedia.org/wikipedia/commons/d/dc/Nuvola_apps_
important_yellow.svg License: LGPL Contributors: An icon from gnome-themes-extras-0.9.0.tar.bz2 (specifically
Nuvola/icons/scalable/emblems/emblem-important.svg) by David Vignoni. Original artist: Modified to look more like the PNG
file by Bastique. Recolored by flamurai.
200 CHAPTER 12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES

• File:Partial-vertical-line-add.svg Source: https://upload.wikimedia.org/wikipedia/commons/a/ab/Partial-vertical-line-add.svg License:


CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:Partial-vertical-line-remove.svg Source: https://upload.wikimedia.org/wikipedia/commons/3/31/Partial-vertical-line-remove.svg
License: CC BY-SA 3.0 Contributors: Own work Original artist: Dirk Hünniger
• File:Phonrule_output_example.png Source: https://upload.wikimedia.org/wikipedia/commons/8/84/Phonrule_output_example.png Li-
cense: CC BY-SA 4.0 Contributors: Own work Original artist: SynConlanger
• File:Plainnatrefs2.png Source: https://upload.wikimedia.org/wikipedia/commons/6/63/Plainnatrefs2.png License: CC BY-SA 3.0 Con-
tributors: Own work Original artist: Jimbotyson
• File:Quote1.png Source: https://upload.wikimedia.org/wikibooks/en/5/56/Quote1.png License: GFDL Contributors: ? Original artist: ?
• File:Quote2.png Source: https://upload.wikimedia.org/wikibooks/en/8/88/Quote2.png License: GFDL Contributors: ? Original artist: ?
• File:Quote4.png Source: https://upload.wikimedia.org/wikipedia/commons/c/cc/Quote4.png License: CC BY-SA 3.0 Contributors: Own
work Original artist: Tomato86
• File:Ring2_chemfig.png Source: https://upload.wikimedia.org/wikipedia/commons/0/0c/Ring2_chemfig.png License: CC BY-SA 3.0
Contributors: Own work Original artist: Pmillerrhodes
• File:Ring3_chemfig.png Source: https://upload.wikimedia.org/wikipedia/commons/9/95/Ring3_chemfig.png License: CC BY-SA 3.0
Contributors: Own work Original artist: Pmillerrhodes
• File:Ring4_chemfig.png Source: https://upload.wikimedia.org/wikipedia/commons/a/a3/Ring4_chemfig.png License: CC BY-SA 3.0
Contributors: Own work Original artist: Pmillerrhodes
• File:Ring_chemfig.png Source: https://upload.wikimedia.org/wikipedia/commons/2/21/Ring_chemfig.png License: CC BY-SA 3.0
Contributors: Own work Original artist: Pmillerrhodes
• File:Simple_sideways_tree.png Source: https://upload.wikimedia.org/wikipedia/commons/9/97/Simple_sideways_tree.png License:
CC0 Contributors: Own work Original artist: Philip John Gorinski
• File:Skeletondiagram2.png Source: https://upload.wikimedia.org/wikipedia/commons/0/05/Skeletondiagram2.png License: CC BY-SA
3.0 Contributors: Own work Original artist: Pmillerrhodes
• File:Soliton_2nd_order.svg Source: https://upload.wikimedia.org/wikipedia/commons/6/61/Soliton_2nd_order.svg License: CC-BY-
SA-3.0 Contributors: This image was created with gnuplot. Original artist: Alessio Damato
• File:Specifier1.svg Source: https://upload.wikimedia.org/wikipedia/commons/9/92/Specifier1.svg License: CC BY-SA 3.0 Contributors:
Own work Original artist: Dirk Hünniger
• File:Specifier2.svg Source: https://upload.wikimedia.org/wikipedia/commons/5/5d/Specifier2.svg License: CC BY-SA 3.0 Contributors:
Own work Original artist: Dirk Hünniger
• File:Specifier3.svg Source: https://upload.wikimedia.org/wikipedia/commons/8/8f/Specifier3.svg License: CC BY-SA 3.0 Contributors:
Own work Original artist: Dirk Hünniger
• File:Specifier4.svg Source: https://upload.wikimedia.org/wikipedia/commons/d/d1/Specifier4.svg License: CC BY-SA 3.0 Contributors:
Own work Original artist: Dirk Hünniger
• File:TeXworks.png Source: https://upload.wikimedia.org/wikipedia/commons/a/a1/TeXworks.png License: GPL Contributors: Screen-
shot Original artist: PAC2
• File:Texcharbox.svg Source: https://upload.wikimedia.org/wikipedia/commons/c/c4/Texcharbox.svg License: CC0 Contributors: Own
work Original artist: Ambrevar
• File:TikZ_Tutorial_-_Bezier_curve.svg Source: https://upload.wikimedia.org/wikipedia/commons/8/88/TikZ_Tutorial_-_Bezier_
curve.svg License: CC0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_arrows.svg Source: https://upload.wikimedia.org/wikipedia/commons/b/bb/TikZ_Tutorial_-_arrows.svg Li-
cense: CC BY-SA 4.0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_bending.svg Source: https://upload.wikimedia.org/wikipedia/commons/2/22/TikZ_Tutorial_-_bending.svg Li-
cense: CC BY-SA 4.0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_circles.svg Source: https://upload.wikimedia.org/wikipedia/commons/9/91/TikZ_Tutorial_-_circles.svg License:
CC BY-SA 4.0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_closed_straight_lines.svg Source: https://upload.wikimedia.org/wikipedia/commons/d/d2/TikZ_Tutorial_-_
closed_straight_lines.svg License: CC0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_filled_rectangle.svg Source: https://upload.wikimedia.org/wikipedia/commons/e/e8/TikZ_Tutorial_-_filled_
rectangle.svg License: CC BY-SA 4.0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_foreach.svg Source: https://upload.wikimedia.org/wikipedia/commons/5/5a/TikZ_Tutorial_-_foreach.svg Li-
cense: CC BY-SA 4.0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_pie.svg Source: https://upload.wikimedia.org/wikipedia/commons/1/14/TikZ_Tutorial_-_pie.svg License: CC
BY-SA 4.0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_plots.svg Source: https://upload.wikimedia.org/wikipedia/commons/4/4d/TikZ_Tutorial_-_plots.svg License:
CC BY-SA 4.0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_special_paths.svg Source: https://upload.wikimedia.org/wikipedia/commons/6/6b/TikZ_Tutorial_-_special_
paths.svg License: CC BY-SA 4.0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_straight_lines.svg Source: https://upload.wikimedia.org/wikipedia/commons/e/ef/TikZ_Tutorial_-_straight_
lines.svg License: CC0 Contributors: Own work Original artist: Nobelium
12.3. CONTENT LICENSE 201

• File:TikZ_Tutorial_-_straight_lines_style_options.svg Source: https://upload.wikimedia.org/wikipedia/commons/0/0c/TikZ_


Tutorial_-_straight_lines_style_options.svg License: CC0 Contributors: Own work Original artist: Nobelium
• File:TikZ_Tutorial_-_two_straight_lines.svg Source: https://upload.wikimedia.org/wikipedia/commons/9/9f/TikZ_Tutorial_-_two_
straight_lines.svg License: CC0 Contributors: Own work Original artist: Nobelium
• File:Verbatim.svg Source: https://upload.wikimedia.org/wikipedia/commons/e/ed/Verbatim.svg License: CC BY-SA 3.0 Contributors:
Own work Original artist: Dirk Hünniger
• File:Wikipedia-logo.png Source: https://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png License: GFDL Contrib-
utors: based on the first version of the Wikipedia logo, by Nohat. Original artist: version 1 by Nohat (concept by Paullusmagnus);

12.3 Content license


• Creative Commons Attribution-Share Alike 3.0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy