LaTeX Wikibook
LaTeX Wikibook
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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.5 Viewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.6 Tables and graphics tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.7 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
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 rst document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.3 Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.4 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.4.5 And what now? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2 Common Elements 17
2.1 Document Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1.1 Global structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1.2 Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
i
ii CONTENTS
2.14.3 Captions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.14.4 Lists of gures and tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
2.14.5 Labels and cross-referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
2.14.6 Wrapping text around gures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
2.14.7 Suboats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.14.8 Wide gures in two-column documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.14.9 Custom oats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.14.10 Labels in the gures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.14.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.14.12 Notes and references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2.15 Hyperlinks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2.15.1 Hyperref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2.15.2 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2.15.3 Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.15.4 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.15.5 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.16 Labels and Cross-referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.16.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
2.16.3 The varioref package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
2.16.4 The hyperref package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
2.16.5 The cleveref package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
2.16.6 Interpackage interactions for varioref , hyperref , and cleveref . . . . . . . . . . . . . . . . 73
2.16.7 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
2.16.8 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3 Mechanics 74
3.1 Errors and Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.1.1 Error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.1.2 Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.1.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.1.4 Software that can check your .tex Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.2 Lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.2.1 Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.2.2 Box lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.2.3 Length manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.2.4 LaTeX default lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.2.5 Fixed-length spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.2.6 Rubber/Stretching lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.2.7 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.2.8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.2.9 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
vi CONTENTS
3.3 Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.3.1 Counter manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.3.2 Counter access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.3.3 Counter style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.3.4 LaTeX default counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.3.5 Book with parts, sections, but no chapters . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.3.6 Custom enumerate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.3.7 Custom sectioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.4 Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.4.1 TeX character boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.4.2 makebox and mbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.4.3 framebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.4.4 framed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.4.5 raisebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.4.6 minipage and parbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.4.7 savebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.4.8 rotatebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.4.9 colorbox and fcolorbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.4.10 resizebox and scalebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.4.11 fancybox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.5 Rules and Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.5.1 Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.5.2 Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.5.3 Stretched rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4 Technical Texts 82
4.1 Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.1.1 Mathematics environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.1.2 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.1.3 Greek letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.1.4 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.1.5 Powers and indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.1.6 Fractions and Binomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.1.7 Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.1.8 Sums and integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.1.9 Brackets, braces and delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.1.10 Matrices and arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.11 Adding text to equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.12 Formatting mathematics symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.13 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.14 Plus and minus signs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.15 Controlling horizontal spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
CONTENTS vii
4.5.1 Typesetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.5.2 The algorithm environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.5.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.6 Source Code Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.6.1 Using the listings package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.6.2 The minted package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
4.6.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
4.7 Linguistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
4.7.1 Enumerated examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
4.7.2 Syntactic trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
4.7.3 Glosses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
4.7.4 IPA characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
4.7.5 Phonological rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
4.7.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
4.7.7 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
8 Programming 149
8.1 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
8.1.1 New commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
8.1.2 New environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
8.1.3 Declare commands within new environment . . . . . . . . . . . . . . . . . . . . . . . . . 150
8.1.4 Extending the number of arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
8.1.5 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
8.1.6 Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
8.1.7 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
8.1.8 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
8.1.9 LaTeX Hooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
8.1.10 Command-line LaTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
CONTENTS xi
9 Miscellaneous 159
9.1 Modular Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
9.1.1 Project structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
9.1.2 Getting LaTeX to process multiple les . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
9.1.3 Including complete pdf documents or single pages . . . . . . . . . . . . . . . . . . . . . . 162
9.1.4 The le mystyle.sty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
9.1.5 The main document document.tex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
9.1.6 External Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.2 Collaborative Writing of LaTeX Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.2.1 Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.2.2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.2.3 Interchanging Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.2.4 The Version Control System Subversion . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.2.5 Hosting LaTeX les in Subversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
9.2.6 Subversion really makes the dierence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
xii CONTENTS
11 Appendix 179
11.1 Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.1.1 Included books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.1.2 Wiki users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.2 Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.3 Package Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
11.4 Sample LaTeX documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.4.1 General examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.4.2 Semantics of Programming Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.1 A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.2 B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.3 C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.4 D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.5 E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.6 F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.7 G . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.8 H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.9 I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.10 L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.11 M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.12 P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.13 Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.14 R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.15 S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.16 T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.17 U . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.18 V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.19 W . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.20 X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.6 Command Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.6.1 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.6.2 A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.6.3 B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.4 C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.5 D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.6 E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
xiv CONTENTS
11.6.7 F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.8 G . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.9 H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.10 I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.11 K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.12 L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.13 M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.14 N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.15 O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.16 P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.17 Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.18 R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.19 S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.20 T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.21 U . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.22 V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Getting Started
1
2 CHAPTER 1. GETTING STARTED
You don't need to manually adjust fonts, text sizes, Questions and documentation
line heights, or text ow for readability, as LaTeX
takes care of them automatically. Besides internet resources being plentiful, the best doc-
umentation source remains the ocial manual for every
In LaTeX the document structure is visible to the specic 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 ocial 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, g-
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 le 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 le is processed by the macro package, it can you to typeset without having to manually fetch les and
produce documents in several formats. LaTeX natively congure things.
supports DVI and PDF, but by using other software you
can easily create PostScript, PNG, JPEG, etc. Engines
the TeX Stack Exchange Q&A, MacTeX is a Mac OS-specic 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 les.
If this is the rst 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 oer 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 conguring 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-
benet 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 specically,
Mac OS X
the basic requirement is to have a TeX compiler (which is
used to generate output les from source), fonts, and the
LaTeX macro set. Optional, and recommended 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.pkg on the MacTeX page, unzip it and follow the in-
manage references if you use them a lot. structions. 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 ocial 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 les and congure
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
Conguration Uninstallation
Formerly, TeX distributions used to be congured with By default TeX Live will install in /usr/local/texlive. The
the texcong tool from the teTeX distribution. TeX Live distribution is quite proper as it will not write any le 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,
cong features are implemented by tlmgr. Only use tex-
cong 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 srcles 1 tlmgr option docles 0 tlmgr 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 les 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
les) are all text les, and can be opened and modied
Now we have a running plain TeX environment, lets 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 (Microsoft Word,
# tlmgr install latex latex-bin latexcong latex-fonts LibreOce Writer). Dedicated LaTeX editors are more
useful than generic plain text editors, because they usu-
In this case you can omit latexcong latex-fonts as they ally have autocompletion of commands, spell and error
are auto-resolved dependencies to LaTeX. Note that checking and 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 graphics-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 t
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. conguration, Emacs can provide a complete LaTeX edit-
For instance, use ing environment with auto-completion, spell-checking,
# tlmgr install hyphen-{nnish,sanskrit} a complete set of keyboard shortcuts, table of contents
view, document preview and many other features.
for nnish 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 pdatex 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
Archimedes Archimedes is an easy-to-use LaTeX and Overleaf is a secure, easy to use online LaTeX ed-
Markdown editor designed from the ground up for Mac itor with integrated rapid preview - like EtherPad
OS X. It includes a built-in LaTeX library, code com- for LaTeX. Start writing with one click (no signup
pletion support, live previews, macro support, integra- required) and share the link. It supports real time
tion with sharing services, and PDF and HTML export preview, gures, bibliographies and custom styles.
options. Archimedess Magic Type feature lets users in-
sert mathematical symbols just by drawing them on their publications.li is a real-time collaborative LaTeX
MacBooks trackpad or Magic Trackpad. editor running the open-source editor \BlueLatex.
interfaces all feature a database form, where information Usually you will use a LaTeX compiler like pdatex to
is entered for each reference item, and the resulting text produce a PDF le directly, or a tool like dvi2pdf to con-
le can be used directly by BibTeX. vert the DVI le to PDF format. Then you can view the
result with any PDF viewer.
Foxit (Windows)
prefer to create PDF then run pdfLaTeX instead. If you tion to nd 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) le 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 les While the documentation is printing, MikTeX: initexmf --update-fndb (or use
move or copy the package les 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 les in the main TeX directories; and b)
with the MiKTex logo. In Settings menu
avoid your newly-installed les being overwritten when
choose the rst 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 les in addition to updating the index. Your pack-
Users/username/Library/texmf/. age author should have included a .map le 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=maple.map (if you installed the
tory (see http://docs.miktex.org/manual/
les in a personal tree) or updmap-sys
localadditions.html#id573803)
--enable Map=maple.map (if you in-
stalled the les 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-cong-le
form to the TeX Directory Structure(TDS). For a TDS- updmap, add the line Map maple.map
conformant system, the right place for a LaTeX .sty to the le that opens, then run initexmf
le 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
Often there is just a .sty le to move, but in the case of is that there are still thousands of installations which do
complex packages there may be more, and they may be- not conform to the TDS, such as old shared Unix systems
long in dierent locations. For example, new BibTeX and some Microsoft Windows systems, so there is no way
packages or font packages will typically have several les for an installation program to guess where to put the les:
to install. This is why it is a good idea to create a sub- you have to know this. There are also systems where the
directory for the package rather than dump the les into owner, user, or installer has chosen not to follow the rec-
misc along with other unrelated stu. If there are cong- ommended TDS directory structure, or is unable to do
uration or other les, read the documentation to nd out so for political or security reasons (such as a shared sys-
if there is a special or preferred location to move them to. tem where the user cannot write to a protected directory).
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 modications 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,
comes with every modern version of TeX and has vari- VMS, Windows NT/2000/XP, etc.) where you may not
ous names depending on the LaTeX distribution you use. have write-access to the main TeX installation directory
(Read the documentation that came with your installa- tree. You can also have a personal texmf subdirectory in
1.4. BASICS 11
your own login directory. Your installation must be con- 1.3.5 External resources
gured to look in these directories rst, 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
The following symbols are reserved characters that either Environments in LaTeX have a role that is quite similar
have a special meaning under LaTeX or are unavailable to commands, but they usually have eect on a wider part
in all the fonts. If you enter them directly in your text, of the document. Their syntax is:
they will normally not print but rather make LaTeX do Between the \begin and the \end you can put other com-
things you did not intend. mands and nested environments. The internal mechanism
#$%^&_{}~\ of environments denes a group, which makes its usage
safe (no inuence on the other parts of the document).
As you will see, these characters can be used in your doc-
In general, environments can accept arguments as well,
uments all the same by adding a prex backslash:
but this feature is not commonly used and so it will be
In some circumstances, the bracket characters [ and ] can discussed in more advanced parts of the document.
also be considered as reserved characters, as they are used
Anything in LaTeX can be expressed in terms of com-
to give optional parameters to some commands. If you
mands and environments.
want to print these directly after some command, like in
this situation: \command [text] it will fail, as [text] will
be considered as an option given to \command. You can
achieve the correct output this way: \command {} [text]. LaTeX commands
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 . Thats 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
commands . They consist of a backslash \ and exactly one non-
letter.
If you want to insert text that might contain several par-
ticular symbols (such as URIs), you can consider using
the \verb command, which will be discussed later in the Some commands need an argument, which has to be
section on formatting. For source code, see Source Code given between curly braces { } after the command name.
Listings Some commands support optional parameters, which are
The 'less than' (<) and 'greater than' (>) characters are the added after the command name in square brackets [ ].
only visible ASCII characters (not reserved) that will not The general syntax is:
print correctly. See Special Characters for an explanation Most standard LaTeX commands have a switch equiva-
and a workaround. lent. Switches have no arguments but apply on the rest of
Non-ASCII characters (e.g. accents, diacritics) can be the scope, i.e. the current group or environment. A switch
typed in directly for most cases. However you must con- should (almost) never be called outside of any scope, oth-
gure the document appropriately. The other symbols erwise it will apply on the rest of the document.
and many more can be printed with special commands as Example:
1.4. BASICS 13
1.4.2 Our rst document If you compile a Plain TeX document with a LaTeX com-
piler (such as pdatex) it will work while the opposite is
Now we can create our rst document. We will produce not true: if you try to compile a LaTeX source with a TeX
the absolute bare minimum that is needed in order to get compiler you will get many errors.
some output; the well known Hello World! approach will As a matter of fact, following your operating system latex
be suitable here. and pdatex are simple scripts or symbolic links.
Most of the programs should be already within your
Open your favorite text-editor. vim, emacs,
LaTeX distribution; the others come with Ghostscript,
Notepad++, and other text editors will have syntax
which is a free and multi-platform software as well. Here
highlighting that will help to write your les.
are common programs you expect to nd in any LaTeX
Reproduce the following text in your editor. This is distribution:
the LaTeX source.
dvips converts the .dvi le to .ps (postscript).
Save your le as hello.tex.
dvipdf converts the .dvi le to .pdf (dvipdfm is an
improved version).
When picking a name for your le, make sure it bears a
.tex extension.
and with Ghostscript:
but for now assume you can compile in both DVI and document, which would be useful for the table of con-
PDF without any problem. tents and references. Indeed the compiler cannot guess
Note, in this instance, due to the simplicity of the le, you at which page a specic section is going to be printed, so
only need to run the LaTeX command once. However, if when the table of contents is printed before the upcoming
you begin to create complex documents, including bibli- sections, it cannot set the page numbers.
ographies and cross-references, etc, LaTeX needs to be To circumvent this issue, many LaTeX commands which
executed multiple times to resolve the references. But need to jump use ancillary les which usually have the
this will be discussed in the future when it comes up. same le name as the current document but a dierent
extension. It stores temporary data into these les and
use them for the next compilation. So to have an up-
Autobuild Systems to-date table of contents, you need to compile the docu-
ment twice. There is no need to re-compile if no section
Compiling using only the latex binary can be quite tricky moved.
as soon as you start working on more complex documents
For example, the temporary le for the table of contents
as previously stated. A number of programs exist to auto-
data is lename.toc.
matically read in a TeX document and run the appropriate
compilers the appropriate number of times. For example, None of these les contains unrecoverable information.
latexmk can generate a PDF from most TeX les simply: It means you can delete them safely, compiling will re-
generate them automatically.
$ latexmk -pdf le.tex
When you work with various capabilities of LaTeX (in-
Note that most editors will take care of it for you.
dex, glossaries, bibliographies, etc.) you will soon nd
yourself in a maze of les with various extensions and
Compressed PDF probably no clue. The following list explains the most
common le types you might encounter when working
with TeX:
For a PDF output, you may have noticed that the output
PDF le is not always the same size depending on the
engine you used to compile the le. So latex dvips
ps2pdf will usually be much smaller than pdatex. If you 1.4.5 And what now?
want pdatex features along with a small output le size,
you can use the Ghostscript command: Common Elements
$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -
sOutputFile="Compressed.pdf Original.pdf See Document Structure and the Common Elements
part for all the common features that belong to every type
of document.
1.4.4 Files
Never, ever use directories (folders) or le names that LaTeX has some nice features for most languages in the
contain spaces. Although your operating system probably world. You can tell LaTeX to follow typography rules of
supports them, some don't, and they will only cause grief the target language, ease special characters input, and so
and tears with TeX. Make lenames as short or as long as on. See Special Characters and Internationalization.
you wish, but strictly avoid spaces. Stick to lower-case let-
ters without accents (a-z), the digits 0-9, the hyphen (),
and only one full point or period (.) to separate the le ex- Modular document
tension (somewhat similar to the conventions for a good
Web URL): it will let you refer to TeX les over the Web
See Modular Documents for good recommendations
more easily and make your les more portable. Some
about the way to organize big projects into multiple les.
operating systems do not distinguish between upper-case
and lower-case letters, others do. Therefore its best not
to mix them.
Questions and Issues
Ancillary les We highly urge you to read the FAQ if you have issues
about basic features, or if you want to read essential rec-
The TeX compilers are single-pass processes. It means ommendations. For the more specic questions and is-
that there is no way for a compiler to jump around the sues, refer to the Tips and Tricks page.
16 CHAPTER 1. GETTING STARTED
Working in a team
Common Elements
The main point of writing a text is to convey ideas, infor- When processing an input le, 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, specied 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 reects the logical and semantic structure Here, class species the type of document to be created.
of the content. The LaTeX distribution provides additional classes for
LaTeX is dierent 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 le le, which tells LaTeX how to format your content. But
and in various style les. 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 le 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 le, 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 le 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 aect 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 dier-
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 o the beginning of your text is that LaTeX
allows you to insert extra setup specications 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 o the end of your
text is to provide a place for LaTeX to be programmed to
do extra stu automatically at the end of the document, Packages
like making an index.
While writing your document, you will probably nd that
A useful side-eect 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 le 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
17
18 CHAPTER 2. COMMON ELEMENTS
number of packages pre-installed. The command to use document classes. For example, a book has chapters but
a package is pretty simple: \usepackage: an article doesn't. Here are some of the structure com-
command, where package is the name of the package and mands found in simple.tex.
options is a list of keywords that trigger special features Notice that you do not need to specify section numbers;
in the package. For example, to use the color package, LaTeX will sort that out for you. Also, for sections, you
which lets you typeset in colors, you would type: do not need to use \begin and \end commands to indicate
which content belongs to a given block.
You can pass several options to a package, each separated
by a comma. LaTeX provides 7 levels of depth for dening sections
(see table below). Each section in this table is a subsection
of the one above it.
2.1.3 The document environment
All the titles of the sections are added automatically to
Top matter the table of contents (if you decide to insert one). But
if you make manual styling changes to your heading, for
At the beginning of most documents there will be infor- example a very long title, or some special line-breaks or
mation about the document itself, such as the title and unusual font-play, this would appear in the Table of Con-
date, and also information about the authors, such as tents as well, which you almost certainly don't want. La-
name, address, email etc. All of this type of informa- TeX allows you to give an optional extra version of the
tion within LaTeX is collectively referred to as top matter. heading text which only gets used in the Table of Con-
Although never explicitly specied (there is no \topmat- tents and any running heads, if they are in eect. This
ter command) you are likely to encounter the term within optional alternative heading goes in [square brackets] be-
LaTeX documentation. fore the curly braces:
A simple example:
The \title, \author, and \date commands are self- Section numbering Numbering of the sections is per-
explanatory. You put the title, author name, and date in formed automatically by LaTeX, so don't bother adding
curly braces after the relevant command. The title and them explicitly, just insert the heading you want between
author are usually compulsory (at least if you want La- the curly braces. Parts get roman numerals (Part I, Part
TeX to write the title automatically); if you omit the \date II, etc.); chapters and sections get decimal numbering like
command, LaTeX uses todays date by default. You al- this document, and appendices (which are just a special
ways nish the top matter with the \maketitle command, case of chapters, and share the same structure) are let-
which tells LaTeX that its complete and it can typeset the tered (A, B, C, etc.).
title according to the information you have provided and You can change the depth to which section numbering
the class (style) you are using. If you omit \maketitle, the
occurs, so you can turn it o selectively. By default it
title will never be typeset. is set to 3. If you only want parts, chapters, and sections
Using this approach, you can only create a title with a numbered, not subsections or subsubsections etc., you can
xed layout. If you want to create your title freely, see change the value of the secnumdepth counter using the
the Title Creation section. \setcounter command, giving the depth level you wish.
For example, if you want to change it to 1":
A related counter is tocdepth, which species what depth
Abstract to take the Table of Contents to. It can be reset in exactly
the same way as secnumdepth. For example:
As most research papers have an abstract, there are pre-
dened commands for telling LaTeX which part of the To get an unnumbered section heading which does not
content makes up the abstract. This should appear in its go into the Table of Contents, follow the command name
logical order, therefore, after the top matter, but before with an asterisk before the opening curly brace:
the main sections of the body. This command is available All the divisional commands from \part* to \subpara-
for the document classes article and report, but not book.graph* have this starred version which can be used on
By default, LaTeX will use the word Abstract as a title special occasions for an unnumbered heading when the
for your abstract. If you want to change it into anything setting of secnumdepth would normally mean it would be
else, e.g. Executive Summary, add the following line numbered.
before you begin the abstract environment: If you want the unnumbered section to be in the table
of contents anyway, use package unnumberedtotoc [1] . It
provides the command
Sectioning commands
which will take care of a proper header as well. \addpart
The commands for inserting sections are fairly intuitive. and addchap are also available. KOMA classes provide
Of course, certain commands are appropriate to dierent those commands by default.
2.1. DOCUMENT STRUCTURE 19
If you don't want to use package unnumberedtotoc, you age is used and the link does not point to the correct
have to do everything by hand using \addcontentsline and chapter, the command \phantomsection in combination
\markright{} (or even \markboth{}{}). with \clearpage or \cleardoublepage can be used (see also
Note that if you use PDF bookmarks you will need to add Labels and Cross-referencing):
a phantom section so that hyperlinks will lead to the cor- To change the title of the TOC, you have to paste this
rect place in the document. The \phantomsection com- command \renewcommand{\contentsname}{<New table
mand is dened in the hyperref package, and is Com- of contents title>} in your document preamble. The List
monly used like this: of Figures (LoF) and List of Tables (LoT) names can be
For chapters you will also need to clear the page (this will changed by replacing the \contentsname with \listgure-
also correct page numbering in the ToC): 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
Ordinary paragraphs preamble:
This will make the table of contents include everything
Paragraphs of text come after section headings. Simply down to paragraphs. The levels are dened above on this
type the text and leave a blank line between paragraphs. page. Note that this solution does not permit changing
The blank line means start a new paragraph here": it the depth dynamically.
does not mean you get a blank line in the typeset output.
For formatting paragraph indents and spacing between You can change the depth of specic section type, which
paragraphs, refer to the Paragraph Formatting section. could be useful for PDF bookmarks (if you are using the
hyperref package) :
In order to further tune the display or the numbering of
Table of contents the table of contents, for instance if the appendix should
be less detailed, you can make use of the tocvsec2 pack-
All auto-numbered headings get entered in the Table of age (CTAN, doc).
Contents (ToC) automatically. You don't have to print a
ToC, but if you want to, just add the command \tableof-
contents at the point where you want it printed (usually 2.1.4 Book structure
after the Abstract or Summary).
Entries for the ToC are recorded each time you process The standard LaTeX book class follows the same layout
your document, and reproduced the next time you pro- described above with some additions. By default a book
cess it, so you need to re-run LaTeX one extra time to will be two-sided, i.e. left and right margins will change
ensure that all ToC pagenumber references are correctly according to the page number parity. Furthermore cur-
calculated. We've already seen how to use the optional rent chapter and section will be printed in the header.
argument to the sectioning commands to add text to the If you do not make use of chapters, it is barely useful to
ToC which is slightly dierent from the one printed in use the book class.
the body of the document. It is also possible to add extra
lines to the ToC, to force extra or unnumbered section Additionally the class provides macros to change the for-
headings to be included. matting of some places of the document. We will give
you some advice on how to use them properly.[2]
The commands \listogures and \listoftables work in ex-
actly the same way as \tableofcontents to automatically
list all your tables and gures. If you use them, they nor- The frontmatter chapters will not be numbered.
mally go after the \tableofcontents command. The \table- Page numbers will be printed in roman numerals.
ofcontents command normally shows only numbered sec- Frontmatter is not supposed to have sections, so they
tion headings, and only down to the level dened by the will be numbered 0.n because there is no chapter
tocdepth counter, but you can add extra entries with the numbering. Check the Counters chapter for a x.
\addcontentsline command. For example if you use an
The mainmatter chapters works as usual. The com-
unnumbered section heading command to start a prelim-
mand resets the page numbering. Page numbers will
inary piece of text like a Foreword or Preface, you can
be printed in arabic numerals.
write:
This will format an unnumbered ToC entry for Preface The \appendix macro can be used to indicate that
in the subsection style. You can use the same mecha- following sections or chapters are to be numbered as
nism to add lines to the List of Figures or List of Tables appendices. Appendices can be used for the article
by substituting lof or lot for toc. If the hyperref pack- class too:
20 CHAPTER 2. COMMON ELEMENTS
Only use the \appendix macro once for all appendices. Bibliography
6. Table of contents
2.2 Text Formatting
7. List of gures (can be in the backmatter too)
This section will guide you through the formatting tech-
8. Preface chapter 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
Mainmatter
may also refer to paragraphs and to the page layout, we
will focus on the customization of words and sentences
1. Main topic for now.
A lot of formatting techniques are required to dierenti-
Appendix ate certain elements from the rest of the text. It is often
necessary to add emphasis to key words or phrases. Foot-
1. Some subordinate chapters notes are useful for providing extra information or clari-
cation without interrupting the main ow of text. So, for
these reasons, formatting is very important. However, it
Backmatter is also very easy to abuse, and a document that has been
over-done can look and read worse than one with none at
1. Bibliography all.
LaTeX is so exible that we will actually only skim the
2. Glossary / Index
surface, as you can have much more control over the pre-
sentation of your document if you wish. Having said that,
one of the purposes of LaTeX is to take away the stress
2.1.5 Special pages of having to deal with the physical presentation yourself,
so you need not get too carried away!
Comprehensive papers often feature special pages at the
end, like indices, glossaries and bibliographies. Since this
is quite a complex topic, we will give you details in the 2.2.1 Spacing
dedicated part Special Pages.
2.2. TEXT FORMATTING 21
Line Spacing ing, care must be exercised so that punctuation marks are
not misinterpreted as ends of sentences. TeX assumes
If you want to use larger inter-line spacing in a document, that sentences end with periods, question marks or excla-
you can change its value by putting the mation marks. Although if a period follows an uppercase
letter, this is not taken as a sentence ending, since periods
command into the preamble of your document. Use
after uppercase letters normally occur in abbreviations.
\linespread{1.3} for one and a half line spacing,
Any exception from these assumptions has to be specied
and \linespread{1.6} for double line spacing. Nor-
by the author. A backslash in front of a space generates a
mally the lines are not spread, so the default line
space that will not be enlarged. A tilde ~ character gen-
spread factor is 1. This may not be ideal in all
erates a non-breaking space. The command \@ in front
situations: see http://tex.stackexchange.com/questions/
of a period species that this period terminates a sentence
30073/why-is-the-linespread-factor-as-it-is .
even when it follows an uppercase letter. (If you are us-
The setspace package allows more ne-grained control ing \frenchspacing, then none of these exceptions need be
over line spacing. To set one and a half line spacing specied.)
document-wide, but not where it is usually unnecessary
(e.g. footnotes, captions):
Stretched spaces
To change line spacing within the document, the setspace
package provides the environments singlespace, onehalf-
You can insert a horizontal stretched space with \hll in a
space, doublespace and spacing:
line so that the rest gets pushed toward the right margin.
For instance this may be useful in the header.
Non-breaking spaces Similarly you can insert vertical stretched space with
\vll. It may be useful for special pages.
This essential feature is a bit unknown to newcomers, al-
See Lengths for more details.
though it is available on most WYSIWYG document pro-
cessors. A non-breaking space between two tokens (e.g.
words, punctuation marks) prevents the processors from Manual spacing
inserting a line break between them. Additionally, a non-
breaking space cannot be enlarged. It is very important The spaces between words and sentences, between para-
for a consistent reading. graphs, sections, subsections, etc. is determined automat-
LaTeX uses the '~' symbol as a non-breaking space. You ically by LaTeX. It is against LaTeX philosophy to insert
would usually use non-breaking spaces for punctuation spaces manually and will usually lead to bad formatting.
marks in some languages, for units and currencies, for Manual spacing is a matter of macro writing and package
initials, etc. In French typography, you would put a non- creation.
breaking space before all two-parts punctuation marks. See Lengths for more details.
Examples:
2.2.2 Hyphenation
Space between words and sentences
LaTeX hyphenates words whenever necessary. Hyphen-
To get a straight right margin in the output, LaTeX in- ation rules will vary for dierent languages. LaTeX
serts varying amounts of space between the words. By only supports English by default, so if you want to have
default, it also inserts slightly more space at the end of correct hyphenation rules for your desired language, see
a sentence. However, the extra space added at the end Internationalization.
of sentences is generally considered typographically old- If the hyphenation algorithm does not nd the correct hy-
fashioned in English language printing. (The practice is phenation points, you can remedy the situation by using
found in nineteenth century design and in twentieth cen- the following commands to tell TeX about the exception.
tury typewriter styles.) Most modern typesetters treat the The command
end of sentence space the same as the interword space.
(See for example, Bringhursts Elements of Typographic causes the words listed in the argument to be hyphenated
Style.) The additional space after periods can be disabled only at the points marked by -. The argument of the
with the command command should only contain words built from normal
letters, or rather characters that are considered to be nor-
which tells LaTeX not to insert more space after a pe- mal letters by LaTeX. It is known that the hyphenation
riod than after ordinary character. Frenchspacing can be algorithm does not nd all correct American English hy-
turned o later in your document via the \nonfrenchspac- phenation points for several words. A log of known ex-
ing command. ceptions is published periodically in the TUGboat jour-
If an author wishes to use the wider end-of-sentence spac- nal. (2012 list: https://www.tug.org/TUGboat/tb33-1/
22 CHAPTER 2. COMMON ELEMENTS
Some letter combinations are typeset not just by setting Even if you can easily change the output of your fonts
the dierent letters one after the other, but by actually using those commands, you're better o not using explicit
using special symbols (like ""), called ligatures. Liga- commands like this, because they work in opposition to
tures can be prohibited by inserting {} or, if this does the basic idea of LaTeX, which is to separate the logical
not work, {\kern0pt} between the two letters in question. and visual markup of your document. This means that
This might be necessary with words built from two words. if you use the same font changing command in several
Here is an example: places in order to typeset a special kind of information,
you should use \newcommand to dene a logical wrapper
Ligatures can interfere with some text-search tools (a command for the font changing command.
search for "nally wouldn't nd the string "nally). The
\DisableLigatures from the microtype package can dis- This approach has the advantage that you can decide at
able ligatures in the whole document to increase accessi- some later stage that you want to use some visual rep-
bility. resentation of danger other than \textit, without having
to wade through your document, identifying all the oc-
Note that this will also disable ligatures such as "--" to currences of \textit and then guring out for each one
"", "---" to "", etc. whether it was used for pointing out danger or for some
If you are using XeLaTeX and OpenType fonts, the other reason.
fontspec package allows for standard ligatures to be See Macros for more details.
turned o as well as fancy swash ligatures to be turned
on.
Another solution is to use the cmap package, which will 2.2.10 Text mode superscript and sub-
help the reader to interpret the ligatures: script
2.2.14 Ready-made strings Whitespace in LaTeX can also be made exible (what
Lamport calls rubber lengths). This means that values
There are some very simple LaTeX commands for type- such as extra vertical space inserted before a paragraph
setting special text strings: \parskip can have a default dimension plus an amount
of expansion minus an amount of contraction. This is
useful on pages in complex documents where not every
page may be an exact number of xed-height lines long,
so some give-and-take in vertical space is useful. You
specify this in a \setlength command like this:
If you want to indent a paragraph that is not indented, you
can use
at the beginning of the paragraph. Obviously, this will
2.2.15 Notes and References only have an eect when \parindent is not set to zero. If
you want to indent the beginning of every section, you can
[1] hyphenat package documentation, p3 use the indentrst package: once loaded, the beginning
2.3. PARAGRAPH FORMATTING 25
The \ialse-conditional is always false. HTML. The dvipsnames allows you access to more col-
ors, another 64, and svgnames allows access to about 150
colors. The initialization of table allows colors to be
Quoting text added to tables by placing the color command just before
the table. The package loaded here is the xcolor package.
LaTeX provides several environments for quoting text;
they have small dierences and they are aimed for dif- If you need more colors, then you may also want to look at
ferent types of quotations. All of them are indented on adding the x11names to the initialization section as well,
either margin, and you will need to add your own quota- this oers more than 300 colors, but you need to make
tion marks if you want them. The provided environments sure your xcolor package is the most recent you can down-
are: load.
The 68 standard colors known to dvips The rst species 20 percent blue and 80 percent white;
the second is a mixture of 20 percent blue and 80 percent
Invoke the package with the usenames and dvipsnames black; and the last one is a mixture of (20*0.3) percent
option. If you are using tikz or pstricks package you must blue, ((100-20)*0.3) percent black and (100-30) percent
declare the xcolor package before that, otherwise it will green.
not work.
xcolor also feature a handy command to dene colors
This above syntax may result in an error if you are using from color mixes:
beamer with tikz. To go around it, include usenames and
dvipsnames options when dening the document class.
Using color specications directly
2.4.5 Dening new colors Normally one would predeclare all the colors as above,
but sometimes it is convenient to directly use a color with-
If the predened colors are not adequate, you may wish out naming it rst. To achieve this, \color and \textcolor
to dene your own. have an alternative syntax specifying the model in square
brackets, and the color specication in curly braces. For
example:
Place
Dene the colors in the preamble of your document. Creating / Capturing colors
(Reason: do so in the preamble, so that you can already
refer to them in the preamble, which is useful, for in- You may want to use colors that appear on another doc-
stance, in an argument of another package that supports ument, web pages, pictures, etc. Alternatively, you may
colors as arguments, such as the listings package.) want to play around with rgb values to create your own
custom colors.
Method Image processing suites like the free GIMP suite for
Linux/Windows/Mac oer color picker facilities to cap-
You need to include the xcolor package in your preamble ture any color on your screen or synthesize colors directly
to dene new colors. In the abstract, the colors are dened from their respective rgb / hsv / hexadecimal values.
following this scheme: Smaller, free utilities also exist:
where:
Linux/BSD: The gcolor2 tool (usually also available
name is the name of the color; you can call it as you in repositories)
like
Microsoft Windows: The open-source Color Selec-
model is the way you describe the color, and is one tor tool.
of gray, rgb, RGB, HTML, and cmyk.
Apple Macs: Hex Color Picker for creating custom
color-spec is the description of the color colors and the built-in DigitalColor Meter for cap-
turing colors on screen.
Color Models Online utilities: See here for a Wikipedia article
with several external links
Among the models you can use to describe the color are
the following (several more are described in the xcolor
manual): Spot colors
Cursive Fonts Since LaTeX has no generic family To overcome these shortcomings, several 8-bit CM-like
group for cursive fonts, these fonts are usually assigned font sets were created. Extended Cork (EC) fonts in T1
to the roman family. encoding contains letters and punctuation characters for
most of the European languages based on Latin script.
The LH font set contains letters necessary to typeset doc-
Mathematical Formula Fonts uments in languages using Cyrillic script. Because of
the large number of Cyrillic glyphs, they are arranged
into four font encodingsT2A, T2B, T2C, and X2. The
2.5.4 Emphasizing text CB bundle contains fonts in LGR encoding for the com-
position of Greek text. By using these fonts you can
In order to add some emphasis to a word or a phrase, the improve/enable hyphenation in non-English documents.
simplest way is to use the \emph{text} command, which Another advantage of using new CM-like fonts is that
usually italicizes the text. Italics may be specied explic- they provide fonts of CM families in all weights, shapes,
itly with \textit{text}. and optically scaled font sizes.
Note that the \emph command is dynamic: if you empha- All this is not possible with OT1; thats why you may want
size a word which is already in an emphasized sentence, to change the font encoding of your document.
it will be reverted to the upright font.
Note that changing the font encoding will have some re-
Text may be emphasized more heavily through the use quirements over the fonts being used. The default Com-
of boldface, particularly for keywords the reader may be puter Modern font does not support T1. You will need
trying to nd when reading the text. As bold text is gen- Computer Modern Super (cm-super) or Latin Modern
erally read before any other text in a paragraph or even on (lmodern), which are Computer Modern-like fonts with
a page, it should be used sparingly. It may also be used in T1 support. If you have none of these, it is quite frequent
place of italics when using sans-serif typefaces to provide (depends on your TeX installation) that tex chooses a
a greater contrast with unemphasized text. Bold text can Type3 font such as the Type3 EC, which is a bitmap font.
be generated with the \textbf{text} command. Bitmap fonts look rather ugly when zoomed or printed.
The fontenc package tells LaTeX what font encoding to
2.5.5 Font encoding use. Font encoding is set with:
where encoding is the font encoding. It is possible to load
A character is a sequence of bytes, and should not be con- several encodings simultaneously.
fused with its representation, the glyph, which is what the
reader sees. So the character 'a' has dierent represen- There is nothing to change in your document to use CM
tations following the used font, for example the upright Super fonts (assuming they are installed), they will get
version, the italic version, various weights and heights, loaded automatically if you use T1 encoding. For lmod-
and so on. ern, you will need to load the package after the T1 en-
coding has been set:
Upon compilation, tex will have to choose the right font
glyph for every character. This is what is called font en- The package ae (almost European) is obsolete. It pro-
coding. The default LaTeX font encoding is OT1, the en- vided some workarounds for hyphenation of words with
coding of the original Computer Modern TeX text fonts. special characters. These are not necessary any more with
It contains only 128 characters, many from ASCII, but fonts like lmodern. Using the ae package leads to text en-
leaving out some others and including a number that are coding problems in PDF les generated via pdatex (e.g.
not in ASCII. When accented characters are required, text extraction and searching), besides typographic issues.
TeX creates them by combining a normal character with
an accent. While the resulting output looks perfect, this
approach has some caveats. 2.5.6 Font styles
It stops the automatic hyphenation from working in- Each family has its own font characteristics (such as italic
side words containing accented characters. and bold), also known as font styles, or font properties.
Font styles are usually implemented with dierent font
Searches for words with accents in PDFs will fail. les. So it is possible to build a new font family by spec-
ifying the font styles of dierent font families.
Extracting ('e.g.' copy paste) the umlaut '' via a
PDF viewer actually extracts the two characters '"A'.
The commands in column two are not entirely equiva- The default for \normalsize is 10 point (option 10pt), but
lent to the commands in column one: They do not cor- it may dier for some Document Styles or their options.
rect spacing after the selected font style has ended. The The actual size produced by these commands also de-
commands in column one are therefore in general recom- pends on the Document Style and, in some styles, more
mended. than one of these size commands may produce the same
You may have noticed the absence of underline. This is actual size.
because underlining is not recommended for typographic Note that the font size denitions are set by the docu-
reasons (it weighs the text down). You should use emph ment class. Depending on the document style the actual
instead. However underlining text provides a useful extra font size may dier from that listed above. And not every
form of emphasis during the editing process, for exam- document class has unique sizes for all 10 size commands.
ple to draw attention to changes. Although underlining As a technical note, points in TeX follow the standard
is available via the \underline{...} command, text under- American point size in which 1 pt is approximately
lined in this way will not break properly. This function- 0.35136 mm. The standard point size used in most mod-
ality has to be added with the ulem (underline empha- ern computer programs (known as the desktop publish-
sis) package. Stick \usepackage{ulem} in your pream- ing point or PostScript point) has 1 pt equal to approx-
ble. By default, this overrides the \emph command with imately 0.3527 mm while the standard European point
the underline rather than the italic style. It is unlikely size (known as the Didot point) had 1 pt equal to approx-
that you wish this to be the desired eect, so it is better imately 0.37597151 mm (see: point (typography)).
to stop ulem taking over \emph and simply call the under-
line command as and when it is needed.
2.5.7 Local font selection
To restore the usual \emph formatting, add
\normalem straight after the document envi- You can change font for a specic part of the text. There
ronment begins. Alternatively, use \usepack- are four font properties you can change.
age[normalem]{ulem}.
To underline, use \uline{...} along with \usepack- \fontencoding The font encoding, such as OT1 (TeX
age[normalem]{ulem}.. default) or T1 (extended characters support, better
PDF support, widely used).
To add a wavy underline, use \uwave{...} along with
\usepackage[normalem]{ulem}.. \fontfamily The font family.
For a strike-out (strikethrough), use \sout{...} along \fontseries The series: l=light, m=medium, b=bold,
with \usepackage[normalem]{ulem}.. bx=very bold.
For a slash through each individual char- \fontshape The shape: it=italic, n=normal, sl=slanted,
acter \xout{...} along with \usepack- sc=small capitals.
age[normalem]{ulem}.
The \selectfont command is mandatory, otherwise the
Some font styles are not compatible one with the other. font will not be changed. It is highly recommended to
But some extra packages will ll this hole. For bold small enclose the command in a group to cleanly return to the
capitals, you might want to use: previous font selection when desired.
You can use all these commands in a row:
Sizing text
The default values are stored in \encodingdefault, \fam-
ilydefault, \seriesdefault and \shapedefault. Setting back
To apply dierent font sizes, simply follow the commands
the default font properties can be done with
on this table:
For short, you can use the \use-
These commands change the size within a given scope, so
font{<encoding>}{<family>}{<series>}{<shape>}
for instance {\Large some words} will change the size of
command.
only some words, and does not aect the font in the rest
of the document. It will work for most parts of the text.
These commands cannot be used in math mode. How- 2.5.8 Arbitrary font size
ever, part of a formula may be set in a dierent size by
using an \mbox command containing the size command. The \tiny...\Huge commands are often enough for most
The new size takes eect immediately after the size com- contents. These are xed sizes however. In most docu-
mand; if an entire paragraph or unit is set in a certain ment processors, you can usually choose any size for any
size, the size command should include the blank line or font. This is because the characters actually get magni-
the \end{...} which delimits the unit. ed. If it usually looks correct for medium sizes, it will
32 CHAPTER 2. COMMON ELEMENTS
2.5.10 Using arbitrary system fonts A bash script for installing a LaTeX font family
(MikTeX / TeXLive)
If you use the XeTeX or LuaTeX engine and the fontspec LaTeX And TrueType Font
package, you'll be able to use any font installed in the
system eortlessly. XeTeX also allows using OpenType True Type Fonts with LaTeX under Linux + MiK-
technology of modern fonts like specifying alternate TeX 2.5
glyphs and optical size variants. XeTeX also uses
Unicode by default, which might be helpful for font is- Unicode Truetype font installer for LaTeX under
sues. Windows + MikTeX
To use the fonts, simply load the fontspec package and set Using TrueType fonts with TeX (LaTeX) and pdf-
the font: TeX (pdfLaTeX) (for MikTeX)
Then compile the document with xelatex or lualatex.
Note that you can only generate .pdf les, and that you 2.5.13 References
need a suciently recent TeX distribution (TeX Live
2009 should work for XeTeX and Tex Live 2010 for Lu- [1] found at the Google discussion group latexlovers
aTeX). Also you should not load the inputenc or fontenc
package. Instead make sure that your document is en- [2] Taken from http://www.macfreek.nl/memory/Fonts_in_
LaTeX
coded as UTF-8 and load fontspec, which will take care
of the font encoding. To make your document support
both pdatex and xelatex/lualatex you can use the \ifx-
etex/ \iuatex macro from the ifxetex/ iuatex package. 2.6 List Structures
For example for xelatex
Convenient and predictable list formatting is one of the
many advantages of using LaTeX. Users of WYSIWYG
2.5.11 PDF fonts and properties word processors can sometimes be frustrated by the soft-
wares attempts to determine when they intend lists to be-
PDF documents have the capability to embed font les. It gin and end. As a mark-up language, LaTeX gives more
makes them portable, hence the name Portable Document control over the structure and content of lists.
2.6. LIST STRUCTURES 33
2.6.1 List structures An example for alignment and the width of the label.
The documentation of package enumitem goes into more
Lists often appear in documents, especially academic, as detail with respect to what can be changed and how. You
their purpose is often to present information in a clear can even dene your own lists. Environments like labeling
and concise fashion. List structures in LaTeX are simply and tasks can be changed dierently, details can be found
environments which essentially come in three types: in the package documentation respectively.
A technical matter
Most modern computer systems allow you to input letters Dealing with LaTeX
of alphabets with non-ASCII characters directly from the
keyboard. If you try to input these special characters in TeX uses ASCII by default. But 128 characters is not
your LaTeX source le and compiled it, you may notice enough to support non-english languages. TeX has its
that they do not get printed at all. own way to do that with commands for every diacritical
A LaTeX source document is a plain text le. A computer marking (see Escaped codes). But if we want accents and
stores data in a binary format, that is a sequence of bits other special characters to appear directly in the source
(0 and 1). To display a plain text le, we need a code le, we have to tell TeX that we want to use a dierent
which tells which sequence of bits corresponds to which encoding.
sequence of characters. This association is called input There are several encodings available to LaTeX:
2.7. SPECIAL CHARACTERS 35
ASCII: the default. Only bare english characters are where codepoint is the unicode codepoint of the desired
supported in the source le. character. TeX sequence is what to print when the char-
acter matching the codepoint is met. You may nd code-
ISO-8859-1 (a.k.a. Latin 1): 8-bits encoding. It points on this site. Codepoints are easy to nd on the web.
supports most characters for latin languages, but Example:
thats it.
Now inputting '' will eectively print ''.
UTF-8: a Unicode multi-byte encoding. Supports With XeTeX and LuaTeX the inputenc package is no
the complete Unicode specication. longer needed. Both engines support UTF-8 directly and
allow the use of TTF and OpenType fonts to support Uni-
Others...
code characters. See the Fonts section for more informa-
tion.
In the following we will assume you want to use UTF-8.
There are some important steps to specify encoding. 2.7.2 Escaped codes
Make sure your text editor decodes the le in UTF- In addition to direct UTF-8 input, LaTeX supports the
8. composition of special characters. This is convenient if
your keyboard lacks some desired accents and other dia-
Make sure it saves your le in UTF-8. Most text critics.
editors do not make the distinction, but some do,
such as Notepad++. The following accents may be placed on letters. Although
'o' letter is used in most of the examples, the accents may
If you are working in a terminal, make sure it is set be placed on any letter. Accents may even be placed
to support UTF-8 input and output. Some old Unix above a missing letter; for example, \~{} produces a
terminals may not support UTF-8. PuTTY is not set tilde over a blank space.
to use UTF-8 by default, you have to congure it. The following commands may be used only in paragraph
(default) or LR (left-right) mode.
Tell LaTeX that the source le is UTF-8 encoded.
To place a diacritic on top of an i or a j, its dot has to be
removed. The dotless version of these letters is accom-
inputenc [2] package tells LaTeX what the text encoding
plished by typing \i and \j. For example:
format of your .tex les is.
The inputenc package allows as well the user to change \^{\i} should be used for i circumex '';
the encoding within the document by means of the com-
\"{\i} should be used for i umlaut ''.
mand \inputencoding{'encoding name'}.
If a document is to be written completely in a language
that requires particular diacritics several times, then using
Extending the support
the right conguration allows those characters to be writ-
ten directly in the document. For example, to achieve eas-
The LaTeX support of UTF-8 is fairly specic: it includes
ier coding of umlauts, the babel package can be cong-
only a limited range of unicode input characters. It only
ured as \usepackage[german]{babel}. This provides the
denes those symbols that are known to be available with
short hand o for \"o. This is very useful if one needs to
the current font encoding. You might encounter a situa-
use some text accents in a label, since no backslash will
tion where using UTF-8 might result in error:
be accepted otherwise.
! Package inputenc Error: Unicode char \u8: not set up
More information regarding language conguration can
for use with LaTeX.
be found in the Internationalization section.
This is due to the utf8 denition not necessarily having a
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 >
The two symbols '<' and '>' are actually ASCII charac-
In such case, you may try need to use the utf8x option ters, but you may have noticed that they will print '' and
to dene more character combinations. utf8x is not o- '' respectively. This is a font encoding issue. If you want
cially supported, but can be viable in some cases. How- them to print their real symbol, you will have to use an-
ever it might break up compatibility with some packages other font encoding such as T1, loaded with the fontenc
like csquotes. package. See Fonts for more details on font encoding.
Another possiblity is to stick with utf8 and to dene the Alternatively, they can be printed with dedicated com-
characters yourself. This is easy: mands:
36 CHAPTER 2. COMMON ELEMENTS
\a= for a macron accent 1. LaTeX needs to know how to hyphenate the lan-
guage(s) to be used.
2.7.8 Unicode keyboard input 2. The user needs to use language-specic typographic
rules. In French for example, there is a mandatory
Some operating systems provide a keyboard combination space before each colon character (:).
to input any Unicode code point, the so-called unicode
3. The input of special characters, especially for lan-
compose key.
guages using an input system (Arab, Chinese,
Many X applications (*BSD and GNU/Linux) support Japanese, Korean).
the Ctrl+Shift+u combination. A 'u' symbol should ap-
pear. Type the code point and press enter or space to It is convenient to be able to insert language-specic spe-
actually print the character. Example: cial characters directly from the keyboard instead of us-
<Ctrl+Shift+u> 20AC <space> ing cumbersome coding (for example, by typing instead
of \"{a}). This can be done by conguring input encod-
will print the euro character. ing properly. We will not tackle this issue here: see the
Desktop environments like GNOME and KDE may fea- Special Characters chapter.
ture a customizable compose key for more memorizable Some languages require special fonts with the proper font
sequences. encoding set. See Font encoding.
Xorg features advanced keyboard layouts with variants Some of the methods described in this chapter may be
that let you enter a lot of characters easily with combina- useful when dealing with non-English author names in
tion using the aprioriate modier, like Alt Gr. It highly bibliographies.
depends on the selected layout+variant, so we suggest you
Here is a collection of suggestions about writing a La-
to play a bit with your keyboard, preceeding every key and
dead key with the Alt Gr modier. TeX document in a language other than English. If you
have experience in a language not listed below, please add
In Windows, you can hold Alt and type a <codepoint> to some notes about it.
get a desired character. For example,
<Alt> + 0252
2.8.1 Prerequisites
will print the German letter .
Most non-english language will need to input special
characters very often. For a convenient writing you will
2.7.9 External links need to set the input encoding and the font encoding prop-
erly.
A few other LaTeX accents and symbols
The following conguration is optimal for many lan-
NASA GISS: Accents guages (most latin languages). Make sure your document
is saved using the UTF-8 encoding.
The Comprehensive LATEX Symbol List
For more details check Font encoding and Special Char-
PDF document with a lengthy list of symbols pro- acters.
vided by various packages
languages, which simplify the input of special characters. following code to your preamble:
See the sections about languages below for more infor- You can input text in either romanized characters or na-
mation. tive Arabic script encodings. Use any of the following
If you call babel with multiple languages: commands and environments to enter in text:
then the last language in the option list will be active (i.e. See the ArabTeX Wikipedia article for further details.
languageB), and you can use the command You may also use the Arabi package within Babel to type-
to change the active language. You can also add short set Arabic and Persian
pieces of text in another language using the command You may also copy and paste from PDF les produced
Babel also oers various environments for entering larger with Arabi thanks to the support of the cmap package.
pieces of text in another language: You may use Arabi with LyX, or with tex4ht to produce
The starred version of this environment typesets the main HTML.
text according to the rules of the other language, but See Arabi page on CTAN
keeps the language specic string for ancillary things like
gures, in the main language of the document. The envi-
ronment hyphenrules switches only the hyphenation pat- Armenian
terns used; it can also be used to disallow hyphenation by
The Armenian script uses its own characters, which will
using the language name 'nohyphenation' (but note select-
language* is preferred). require you to install a text editor that supports Unicode
and will allow you to enter UTF-8 text, such as Texmaker
The babel manual provides much more information on or WinEdt. These text editors should then be congured
these and many other options. to compile using XeLaTeX.
Once the text editor is set up to compile with XeLaTeX,
2.8.3 Multilingual versions the fontspec package can be used to write in Armenian:
or
It is possible in LaTeX to typeset the content of one docu-
ment in several languages and to choose upon compilation The Sylfaen font lacks italic and bold, but DejaVu Serif
which language to output. This might be convenient to supports them.
keep a consistent sectioning and formatting across the dif- See Armenian Wikibooks for further details, especially
ferent languages. It is also useful if you make use of mul- on how to congure the Unicode supporting text editors
tiple proper nouns and other untranslated content. Using to compile with XeLaTeX.
the commands above in multilingual documents can be
cumbersome, and therefore babel provides a way to de-
ne shorter names. With Cyrillic script
You can write:
Version 3.7h of babel includes support for the T2* encod-
ings and for typesetting Bulgarian, Russian and Ukrainian
Alternative choice using iang 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 iang inputenc packages. AMS-LaTeX packages should be
(Why?)
package by Heiko Oberdiek (the built-in feature from the loaded before fontenc and babel . If you are going to
babel package is not reliable). Here comes a simple ex- use 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 dening 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 dierent lan-
guage is selected within the document.
2.8.4 Specic languages
On modern operating systems it is benecial to use Uni-
code (utf8 or utf8x) instead of KOI8-RU (koi8-ru) as an
Arabic script
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
2.8. INTERNATIONALIZATION 39
You can load German language support using either one The following lines can be added to write Icelandic text:
of the two following commands. This changes text like Part into Hluti. It makes additional
For traditional (old) German orthography use commands available:
or for reform (new) German orthography use To make special characters such as and become
available just add:
This enables German hyphenation, if you have cong-
ured your LaTeX system accordingly. It also changes The default LATEX font encoding is OT1, but it contains
all automatic text into German, e.g. Chapter becomes only the 128 characters. The T1 encoding contains letters
Kapitel. A set of new commands also becomes avail- and punctuation characters for most of the European lan-
able, which allows you to write German input les more guages using Latin script.
quickly even when you don't use the inputenc package.
Check out the table below for inspiration. With inpu-
Italian
tenc, all this becomes moot, but your text also is locked
in a particular encoding world.
Italian is well supported by LaTeX. Just add
In German books you sometimes nd French quotation
at the beginning of your document and the output of all
marks (guillemets). German typesetters, however, use
the commands will be translated properly.
them dierently. A quote in a German book would look
like this. In the German speaking part of Switzerland,
typesetters use guillemets the same way the French do. Japanese
A major problem arises from the use of commands like
\q: If you use the OT1 font encoding (which is the de- There is a variant of TeX intended for Japanese named
fault) the guillemets will look like the math symbol " pTeX, which supports vertical typesetting.
", which turns a typesetters stomach. T1 encoded fonts,
on the other hand, do contain the required symbols. So Another possible way to write in japanese is to use Lu-
if you are using this type of quote, make sure you use the alatex and the luatex-ja package. Adapted example from
T1 encoding. the Luatexja documentation :
Decimal numbers usually have to be written like 0{,}5 You can also use capabilities provided by the Fontspec
(not just 0,5). Packages like zier enable input like 0,5. package and those provided by Luatexja-fontspec to de-
Alternatively, one can use the \num command from the clare the font you want to use in your paper. Let us take
babel and (globally) set the decimal marker using an example :
Use UTF-8 as your encoding. In case you don't know
how to do this, take a look at Texmaker, a LaTeX editor
which use UTF-8 by default.
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.
les 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
take one argument which is then typeset using the re- The last argument species the font. It must t the desired
quested font encoding. Otherwise you can use the com- language, since fonts are dierent for Chinese, Japanese
mand \selectlanguage{...} described in a previous sec- and Korean. min is an example for Japanese.
tion. Use \euro for the Euro symbol.
Korean
Hungarian The two most widely used encodings for Korean text les
are EUC-KR and its upward compatible extension used
in Korean MS-Windows, CP949/Windows-949/UHC. In
Use the following lines: these encodings each US-ASCII character represents its
More information in hungarian. normal ASCII character similar to other ASCII compat-
2.8. INTERNATIONALIZATION 41
ible encodings such as ISO-8859-x, EUC-JP, Big5, or the formatting of the document is changed to follow Ko-
Shift_JIS. On the other hand, Hangul syllables, Hanjas rean conventions. The package also provides automatic
(Chinese characters as used in Korea), Hangul Jamos, particle selection. In Korean, there are pairs of post-x
Hiraganas, Katakanas, Greek and Cyrillic characters and particles grammatically equivalent but dierent in form.
other symbols and letters drawn from KS X 1001 are Which of any given pair is correct depends on whether
represented by two consecutive octets. The rst has its the preceding syllable ends with a vowel or a consonant.
MSB set. Until the mid-1990s, it took a considerable (It is a bit more complex than this, but this should give
amount of time and eort to set up a Korean-capable en- you a good picture.) Native Korean speakers have no
vironment under a non-localized (non-Korean) operating problem picking the right particle, but it cannot be de-
system. You can skim through the now much-outdated termined which particle to use for references and other
http://jshin.net/faq to get a glimpse of what it was like to automatic text that will change while you edit the docu-
use Korean under non-Korean OS in mid-1990s. ment. It takes a painstaking eort to place appropriate
particles manually every time you add/remove references
TeX and LaTeX were originally written for scripts with
no more than 256 characters in their alphabet. To make or simply shue parts of your document around. HLA-
TEX relieves its users from this boring and error-prone
them work for languages with considerably more charac-
ters such as Korean or Chinese, a subfont mechanism was process.
developed. It divides a single CJK font with thousands or In case you don't need Korean localization features but
tens of thousands of glyphs into a set of subfonts with 256 just want to typeset Korean text, you can put the following
glyphs each. line in the preamble, instead.
For Korean, there are three widely used packages. For more details on typesetting Korean with HLATEX,
refer to the HLATEX Guide. Check out the web site of
HLATEX by UN Koaunghi the Korean TeX User Group (KTUG).
In the FAQ section of KTUG it is recommended to use
hLATEXp by CHA Jaechoon the kotex package
the CJK package by Werner Lemberg
Persian script
HLATEX and hLATEXp are specic to Korean and pro-
vide Korean localization on top of the font support. They For Persian language, there is a dedicated package called
both can process Korean input text les encoded in EUC- XePersian which uses XeLaTeX as the typesetting en-
KR. HLATEX can even process input les encoded in gine. Just add the following code to your preamble:
CP949/Windows-949/UHC and UTF-8 when used along
See XePersian page on CTAN
with , .
Moreover, Arabic script can be used to type Persian as
The CJK package is not specic to Korean. It can process
illustrated in the corresponding section.
input les in UTF-8 as well as in various CJK encodings
including EUC-KR and CP949/Windows-949/UHC, it
can be used to typeset documents with multilingual 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 dierent families and Munhwabu fonts (TrueType) of Connectives Polish has many single letter connectives:
5 dierent 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 Bitstreams cyberbit True-Type font. that LaTeX won't set them as last letter in the line, you
have to use non breakable space:
To use the HLATEX package for typesetting your Korean
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 gures are all translated into Korean and This is achieved by redening few LaTeX macros.
42 CHAPTER 2. COMMON ELEMENTS
[3] babel-french documentation: the French language should 2.9.2 The rotoat package
now be loaded as french, not as frenchb or francais and
preferably as a global option of \documentclass. Some tol-
When it is desirable to place the rotated table at the exact
erance still exists in v3.0, but do not rely on it.
location where it appears in the source (.tex) le, rotoat
package may be used. Then one can use
2.9 Rotations just like for normal tables. The H option can not be used
without this package.
or the export options of your favorite spreadsheet. Thanks you want, their alignment and the vertical lines to separate
to the modular nature of LaTeX, the whole process can them. Once in the environment, you have to introduce
be automated in a fairly comfortable way. the text you want, separating between cells and introduc-
For a long time, LaTeX tables were quite a chaotic topic, ing new lines. The commands you have to use are the
with dozens of packages doing similar things, while not following:
always being compatible with one another. Sometimes Note, any white space inserted between these commands
you had to make trade-os. The situation changed re- is purely down to ones preferences. I personally add
cently (2010) with the release of the tabu package which spaces between to make it easier to read.
combines the power of longtable, tabularx and much
more. The tabu environment is far less fragile and re-
stricted than the older alternatives. Nonetheless, before Basic examples
attempting to use this package for the rst time it will
be benecial to understand how the classic environment This example shows how to create a simple table in La-
works, since tabu works the same way. Note however that TeX. It is a three-by-three table, but without any lines.
the author of tabu will not x bugs to the current version,
Expanding upon that by including some vertical lines:
and that the next version introduces new syntax that will
likely break existing documents.[1] To add horizontal lines to the very top and bottom edges
of the table:
And nally, to add lines between all rows, as well as
2.10.1 The tabular environment centering (notice the use of the center environment - of
course, the result of this is not obvious from the preview
The tabular environment can be used to typeset tables on this web page):
with optional horizontal and vertical lines. LaTeX de-
termines the width of the columns automatically.
The rst line of the environment has the form: Text wrapping in tables
The table spec argument tells LaTeX the alignment to be
LaTeXs algorithms for formatting tables have a few
used in each column and the vertical lines to insert.
shortcomings. One is that it will not automatically wrap
The number of columns does not need to be specied as text in cells, even if it overruns the width of the page.
it is inferred by looking at the number of arguments pro- For columns that will contain text whose length exceeds
vided. It is also possible to add vertical lines between the the columns width, it is recommended that you use the p
columns here. The following symbols are available to de- attribute and specify the desired width of the column (al-
scribe the table columns (some of them require that the though it may take some trial-and-error to get the result
package array has been loaded): you want). For a more convenient method, have a look at
By default, if the text in a column is too wide for the page, The tabularx package, or The tabulary package.
LaTeX wont automatically wrap it. Using p{'width'} Instead of p, use the m attribute to have the lines aligned
you can dene a special type of column which will wrap- toward the middle of the box or the b attribute to align
around the text as in a normal paragraph. You can pass along the bottom of the box.
the width using any unit supported by LaTeX, such as 'pt'
Here is a simple example. The following code creates two
and 'cm', or command lengths, such as \textwidth. You
tables with the same code; the only dierence is that the
can nd a list in chapter Lengths.
last column of the second one has a dened width of 5
The optional parameter pos can be used to specify the centimeters, while in the rst one we didn't specify any
vertical position of the table relative to the baseline of the width. Compiling this code:
surrounding text. In most cases, you will not need this
You get the following output:
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 rst one aligned to the left and in bold
font, the second one aligned in the center and with normal
font, and the third aligned to the right and in italic. The
array package needs to be activated in the preamble for
this to work.
In the rst line you have pointed out how many columns
2.10. TABLES 45
Note that the rst table has been cropped, since the output Column specication using >{\cmd} and <{\cmd}
is wider than the page width.
The column specication can be altered using the array
package. This is done in the argument of the tabular en-
Manually broken paragraphs in table cells vironment using >{\command} for commands executed
right before each column element and <{\command} for
Sometimes it is necessary to not rely on the breaking al- commands to be executed right after each column ele-
gorithm when using the p specier, but rather specify the ment. As an example: to get a column in math mode en-
line breaks by hand. In this case it is easiest to use a \par- ter: \begin{tabular}{>{$}c<{$}}. Another example is
box: changing the font: \begin{tabular}{>{\small}c} to print
the column in a small font.
Here the t argument controls the placement of the text
inside the box. Other allowed values are c for center and The argument of the > and < specications must be cor-
b for bottom. rectly balanced when it comes to { and } characters.
This means that >{\bfseries} is valid, while >{\textbf}
will not work and >{\textbf{} is not valid. If there
is the need to use the text of the table as an argu-
Space between columns ment (for instance, using the \textbf to produce bold
text), one should use the \bgroup and \egroup commands:
To tweak the space between columns (LaTeX will by de- >{\textbf\bgroup}c<{\egroup} produces the intended ef-
fault choose very tight columns), one can alter the col- fect. This works only for some basic LaTeX commands.
umn separation: \setlength{\tabcolsep}{5pt}. The de- For other commands, such as \underline to underline text,
fault value is 6pt. it is necessary to temporarily store the column text in a
box using lrbox. First, you must dene such a box with
\newsavebox{\boxname} and then you can dene:
Space between rows This stores the text in a box and afterwards, takes the text
out of the box with \unhbox (this destroys the box, if the
Re-dene the \arraystretch command to set the space be- box is needed again one should use \unhcopy instead) and
tween rows: passing it to \underline. (For LaTeX2e, you may want to
Default value is 1.0. use \usebox{\boxname} instead of \unhbox\boxname.)
An alternative way to adjust the rule spacing is to This same trick done with \raisebox instead of \underline
add \noalign{\smallskip} before or after the \hline and can force all lines in a table to have equal height, instead of
\cline{i-j} commands: the natural varying height that can occur when e.g. math
terms or superscripts occur in the text.
You may also specify the skip after a line explicitly using
glue after the line terminator Here is an example showing the use of both p{...} and
>{\centering} :
Note the use of \tabularnewline instead of \\ to avoid a
Other environments inside tables Misplaced \noalign error.
spacing between columns. Given a basic table, and vary- Rows spanning multiple columns
ing the column descriptions:
The command for this looks like this: \multicol-
umn{num_cols}{alignment}{contents}. num_cols is the
Aligning columns at decimal points using dcolumn number of subsequent columns to merge; alignment is
either l, c, r, or to have text wrapping specify a width
Instead of using @-expressions to build columns of deci- p{5.0cm} . And contents is simply the actual data you
mals aligned to the decimal point (or equivalent symbol), want to be contained within that cell. A simple example:
it is possible to center a column on the decimal separator
using the dcolumn package, which provides a new column
specier for oating point data. See the dcolumn package Columns spanning multiple rows
documentation for more information, but a simple way to
use dcolumn is as follows. The rst thing you need to do is add \usepack-
age{multirow} to the preamble[3] . This then pro-
A negative argument provided for the number of decimal
vides the command needed for spanning rows: \mul-
places in the new column type allows unlimited decimal
tirow{''num_rows'}{''width''}{''contents'}. The argu-
places, but may result in rather wide columns. Round-
ments are pretty simple to deduce (* for the width means
ing is not applied, so the data to be tabulated should
the contents natural width).
be adjusted to the number of decimal places specied.
Note that a decimal aligned column is typeset in math The main thing to note when using \multirow is that a
mode, hence the use of \mathrm for the column head- blank entry must be inserted for each appropriate cell in
ing in the example above. Also, text in a decimal aligned each subsequent row to be spanned.
column (for example the header) will be right-aligned be- If there is no data for a cell, just don't type anything, but
fore the decimal separator (assuming theres no decimal you still need the "&" separating it from the next columns
separator in the text). While this may be ne for very data. The astute reader will already have deduced that for
short text, or numeric column headings, it looks cum- a table of n columns, there must always be n 1 amper-
bersome in the example above. A solution to this is to sands in each row (unless \multicolumn is also used).
use the \multicolumn command described below, spec-
ifying a single column and its alignment. For exam-
ple to center the header Decimal over its column in the Spanning in both directions simultaneously
above example, the rst line of the table itself would be
Left&Right&Center&\multicolumn{1}{c}{Decimal}\\ Here is a nontrivial example of how to use spanning in
both directions simultaneously and have the borders of
the cells drawn correctly:
Bold text and dcolumn To draw attention to particular
The command \multicolumn{1}{ is just used to draw
entries in a table, it may be nice to use bold text. Ordi-
vertical borders both on the left and on the right of the
narily this is easy, but as dcolumn needs to see the deci-
cell. Even when combined with \multirow{2}{*}{...}, it
mal point it is rather harder to do. In addition, the usual
still draws vertical borders that only span the rst row.
bold characters are wider than their normal counterparts,
To compensate for that, we add \multicolumn{1}{ in the
meaning that although the decimals may align nicely, the
following rows spanned by the multirow. Note that we
gures (for more than 2-3 digits on one side of the deci-
cannot just use \hline to draw horizontal lines, since we
mal point) will be visibly misaligned. It is however possi-
do not want the line to be drawn over the text that spans
ble to use normal width bold characters and dene a new
[2] several rows. Instead we use the command \cline{2-6}
bold column type, as shown below.
and opt out the rst column that contains the text Pow-
ers.
2.10.2 Row specication Here is another example exploiting the same ideas to
make the familiar and popular 2x2 or double di-
It might be convenient to apply the same command over chotomy:
every cell of a row, just as for column. Unfortunately the
tabular environment cannot do that by default. We will
need tabu instead, which provides the \rowfont option. 2.10.4 Controlling table size
Resize tables
2.10.3 Spanning
The graphicx packages features the command \resize-
To complete this tutorial, we take a quick look at how box{width}{height}{object} which can be used with tab-
to generate slightly more complex tables. Unsurprisingly, ular to specify the height and width of a table. The fol-
the commands necessary have to be embedded within the lowing example shows how to resize a table to 8cm width
table data itself. while maintaining the original width/height ratio.
2.10. TABLES 47
2.10.5 Colors
The xcolor package provides the necessary commands This package provides a table environment called tabu-
to produce tables with alternate row colors, when larx, which is similar to the tabular* environment except
loaded with the table option. The command \rowcol- that it has a new column specier X (in uppercase). The
ors{<''starting row''>}{<''odd color''>}{<''even color''>} column(s) specied with this specier will be stretched
has to be specied right before the tabular environment to make the table as wide as specied, greatly simplify-
starts. ing the creation of tables.
The command \hiderowcolors is available to deactivate The content provided for the boxes is treated as for a
highlighting from a specied row until the end of the ta- p column, except that the width is calculated automati-
ble. Highlighting can be reactivated within the table via cally. If you use the package array, you may also apply
the \showrowcolors command. If while using these com- any >{\cmd} or <{\cmd} command to achieve specic
mands you experience misplaced \noalign errors then behavior (like \centering, or \raggedright\arraybackslash)
use the commands at the very beginning or end of a row as described previously.
in your tabular.
Another option is to use \newcolumntype to format se-
or lected columns in a dierent way. It denes a new col-
umn specier, e.g. R (in uppercase). In this example, the
second and fourth column is adjusted in a dierent way
Colors of individual cells (\raggedleft):
Tabularx with rows spanning multiple columns using
As above this uses the xcolor package. \multicolumn. The two central columns are posing as one
by using the X@{} option. Note that the \multicolumn
width (which in this example is 2) should equal the (in
this example 1+1) width of the spanned columns:
2.10.6 Width and stretching
In a way analogous to how new commands with argu-
We keep providing documentation for tabular* and tab- ments can be created with \newcommand, new column
ularx although they are completely eclipsed by the much types with arguments can be created with \newcolumn-
more powerful and exible tabu environment. Actually type as follows:
tabu is greatly inspired by those environments, so it may where since there are 4 columns, the sum of the \hsizes
be worth it to have an idea how they work, particularly (1 + 0.5 + 0.5 + 2) must be equal to 4. The default value
for tabularx. used by tabularx for \hsize is 1.
48 CHAPTER 2. COMMON ELEMENTS
The tabulary package solved. Dening a new columntype will keep the image
vertically centered.
tabulary is a modied tabular* allowing width of columns Or use a parbox to center the image.
set for equal heights. tabulary allows easy and convenient
writing of well balanced tables. A raisebox works as well, also allowing to manually ne-
tune the alignment with its rst parameter.
The problem with tabularx is that it leaves much blank if
your cells are almost empty. Besides, it is not easy to have
dierent column sizes.
2.10.10 Footnotes in tables
tabulary tries to balance the column widths so that each
column has at least its natural width, without exceeding
The tabular environment does not handle footnotes prop-
the maximum length.
erly. The longtabular xes that.
The rst parameter is the maximum width. tabulary will
try not to exceed it, but it will not stretch to it if there is Instead of using longtabular we recommend tabu which
not enough content, contrary to tabularx. handles footnotes properly, both in normal and long ta-
bles.
The second parameter is the column disposition. Possible
values are those from the tabular environment, plus
These are all capitals. 2.10.11 Professional tables
Using array
2.10.8 Partial vertical lines
Using booktabs
Adding a partial vertical line to an individual cell:
Removing part of a vertical line in a particular cell: Usually the need arises for footnotes under a table (and
not at the bottom of the page), with a caption properly
spaced above the table. These are addressed by the ctable
2.10.9 Vertically centered images package. It provides the option of a short caption given
to be inserted in the list of tables, instead of the actual
Inserting images into a table row will align it at the top of caption (which may be quite long and inappropriate for
the cell. By using the array package this problem can be the list of tables). The ctable uses the booktabs package.
2.10. TABLES 49
2.10.13 Table with legend tabular is for the content itself (columns, lines, etc.).
pandas: pandas DataFrames have a method to con- numprint: print numbers, in the current mode (text
vert data they contain to latex, or math) in order to use the correct font, with sepa-
rators, exponent and/or rounded to a given number
latex-tools: a Ruby library, of digits. tabular(*), array, tabularx, and longtable
environments are supported using all features of
xtable: a library for R,
numprint
org-mode: for Emacs users, org-mode tables can be
spreadtab: spread sheets allowing the use of formu-
used inline in LaTeX documents, see for a tutorial.
lae
Emacs align commands: the align commands can
siunitx: alignment of tabular entries
clean up a messy LaTeX table.
pgfplotstable: Loads, rounds, formats and postpro-
Online Table generator for LATeX: An online tool
cesses numerical tables.
for creating simple tables within the browser. La-
TeX format is directly generated as you type.
Have a look at one of the following packages: For documents such as basic articles, the output of
\maketitle is often adequate, but longer documents (such
as books and reports) often require more involved for-
hhline: do whatever you want with horizontal lines matting. We will detail the process here.
array: gives you more freedom on how to dene There are several situations where you might want to cre-
columns ate a title in a custom format, rather than in the format
natively supported by LaTeX classes. While it is possible
colortbl: make your table more colorful to change the output of \maketitle, it can be complicated
even with minor changes to the title. In such cases it is of-
threeparttable makes it possible to put footnotes
ten better to create the title from scratch, and this section
both within the table and its caption
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 ll it with using these
commands placed in the top matter:
slashbox: create 2D tables with the rst 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.
le.
diagbox: compatible to slashbox, come with Tex To form a title, use
Live 2011 or later
This should go after the preceding commands after begin-
dcolumn: decimal point alignment of numeric cells ning the document. For most document classes, this will
form a separate page, while the article document class
rccol: advanced decimal point alignment of numeric will place the title on the top of the rst page. If you want
cells with rounding to have a separate title page for articles as well, use the
2.11. TITLE CREATION 51
documentclass option titlepage command. For example, Remember, if you have a block of text in a dierent size,
one may add even if it is a bit of text on a single line, end it with \par.
The \thanks command can also be used in the \title.
Filling the page
It is dependent on the document class which commands
are used in the title generated by \maketitle. Referring to The command \vll as the last item of your content will
the documentation will lead to trusted information. add empty space until the page is full. If you put it within
the page, you will ensure that all the following text will be
placed at the bottom of the page.
2.11.2 The title for journal submission
Journals follow a specic layout. To ensure this they of- A practical example All these tips might have made
ten provide a template which denes the layout. What you confused. Here is a practical and compilable exam-
is available for the title (for example emails, aliation ple. The picture in use comes with package mwe and
names, keywords) heavily depends on the template and should be available with every complete LaTeX installa-
highly diers between dierent journals. Follow the tion. You can start testing right away.
template if the journal provides one. If they don't you
As you can see, the code looks dirtier than standard La-
should use the most basic concepts of LaTeX titles de-
TeX source because you have to take care of the output
scribed above. as well. If you start changing fonts it gets even more com-
plicated, but you can do it: its only for the title and your
complicated code will be isolated from all the rest within
2.11.3 Create a custom title for a report or its own le.
book The result is shown below
The title page of a book or a report is the rst thing a
reader will see. Keep that in mind when preparing your
title page.
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-
thing is hand crafted. Here are some of the most often
needed things:
Alignment
Images
Text size
Ph.D., etc.) is quite static, it doesn't really change over 2.11.7 Notes and References
time. You can prepare the titlepage in its own little doc-
ument and prepare a one page pdf that you later include [1] Titling package webpage on CTAN
into your real document. This is really useful, if the ti- [2] Frontespizio package webpage on CTAN
tle page is required to have completely dierent margins
compared to the rest of the document. It also saves com- [3] authblk package webpage on CTAN
pile time, though it is not much.
Assuming you have done the title page of your report
in an extra document, lets pretend it is called reportTi- 2.12 Page Layout
tlepage2016.pdf, you can include it quite simply. Here is
a short document setup. LaTeX and the document class will normally take care of
page layout issues for you. For submission to an academic
publication, this entire topic will be out of your hands, as
2.11.4 A title to be re-used multiple times the publishers want to control the presentation. However,
for your own documents, there are some obvious settings
Some universities, departments and companies have strict that you may wish to change: margins, page orientation
rules how a title page of a report should look like. To and columns, to name but three. The purpose of this tu-
ensure the very same output for all reports, a redeniton torial is to show you how to congure your pages.
of the \maketitle command is recommended.
We will often have to deal with TeX lengths in this chap-
This is best done by an experienced LaTeX user. A sim- ter. You should have a look at Lengths for comprehensive
ple example follows, as usual there is no real limit with details on the topic.
respect to complexity.
As a starting point, a LaTeX package called
columbidaeTitle.sty is generated that denes the
2.12.1 Two-sided documents
complete title matter. It will later be hidden from the
Documents can be either one- or two-sided. Articles
end user. Ideally, the person creating the package should
are by default one-sided, books are two-sided. Two-
maintain it for a long time, create an accompanying
sided documents dierentiate the left (even) and right
documentation and ensure user support.
(odd) pages, whereas one-sided do not. The most no-
This package can be loaded within a usual document. The table eect can be seen in page margins. If you want
user can set the variables for title and the like. Which to make the article class two-sided, use \document-
commands are actually available, and which might be class[twoside]{article}.
omissible should be written in a documentation that is
Many commands and variables in LaTeX take this con-
bundled with the package.
cept into account. They are referred to as even and odd.
Look around what happens if you leave one or the other For one-sided document, only the odd commands and
command out. variables will be in eect.
The titling package[1] provides control over the typeset- A page in LaTeX is dened by many internal parame-
ting of the \maketitle and \thanks commands. It is useful ters. Each parameter corresponds to the length of an ele-
for small changes to the standard output. ment of the page, for example, \paperheight is the physi-
cal height of the page. Here you can see a diagram show-
Italian users may also want to use the frontespizio
ing all the variables dening the page. All sizes are given
package[2] . It denes a frontispiece as used in Italia.
in TeX points (pt), there are 72.27pt in an inch or 1pt
Package authblk [3] provides new means to typeset the 0.3515mm.
authors. This is especially helpful for journal submissions
without an available template. 1. one inch + \hoset
Header
It will not have been immediately obvious - because it
doesn't really cause any serious problems - that the de-
6 fault page size for all standard document classes is US let-
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
is the standard in almost all the rest of the world). While
this is not a serious issue (most printers will print the doc-
ument without any problems), it is possible to specify al-
ternative sizes as class option. For A4 format:
Margin notes Body
7
10
One of the most versatile packages for page layout is
3
the geometry package. The immediate advantage of this
package is that it lets you customize the page size even
with classes that do not support the options. For instance,
8 to set the page size, add the following to your preamble:
11
The current details plus the layout shape can be printed latex myle # TeX DVI dvipdf myle # DVI PDF
from a LaTeX document itself. Use the layout pack-
age and the command of the same name: \usepack- TeX DVI PS PDF
age{layout} ... \layout{}
latex myle # TeX DVI dvips myle -o myle.ps #
To render a frame marking the margins of a document DVI PS ps2pdf myle.ps myle.pdf # PS PDF
you are currently working on, add
Sadly the PDF output page size may not be completely re-
\usepackage{showframe} spectful of your settings. Some of these tools do not have
the same interpretation of the DVI, PS and PDF speci-
to the document. cations, and you may end up with a PDF which has not
54 CHAPTER 2. COMMON ELEMENTS
exactly the right size. Thankfully there is a solution to without changing the margins is to increase the font size
that: the \special command lets the user pass PostScript using the 12pt option to the document class.
or PDF parameters, which can be used here to set the If you wish to change the margins of your document,
page size appropriately. there are many ways to do so:
For pdatex to work ne, using the package geom- One older approach is to use the fullpage package
etry usually works. for somewhat standardized smaller margins (around
an inch), but it creates lines of more than 100 char-
For the DVI and PS ways, the safest way to always
acters per line at with the 10pt default font size (and
get the right paper size in the end is to add
about 90 if the 12pt documentclass option is used):
2.12.4 Margins It can also recreate the behavior of the fullpage package
using
Readers used to perusing typical physical literature are You can combine the margin options with the page size
probably wondering why there is so much white space options seen in this paragraph.
surrounding the text. For example, on A4 paper a doc-
ument will typically have 44 mm margin widths on the You should not use the a4wide package for a page
left and right of the page, leaving about 60% of the page with A4 document size with smaller margins. It is
width for text. The reason is improved readability. Stud- obsolete and buggy. Use geometry package instead
ies have shown[2][3] that its easier to read text when there like this:
are 6070 characters per lineand it would seem that 66
is the optimal number. Therefore, the page margins are
set to ensure optimal readability, and excessive margin Edit individual page dimension variables described
white space is tolerated as a consequence. Sometimes, above, using the \addtolength and \setlength com-
this white space is left in the inner margin with the as- mands. See the Lengths chapter. For instance,
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 dierent margins for odd and even pages is to give
2.12. PAGE LAYOUT 55
the twoside option in the document class command and your headers and footers appearing the same place as the
specify the margins as usually. other pages.
This will result in a value of 4cm on all inner margins (left The lscape package is for this very purpose. It supplies
margin for odd number pages and right margin for even a landscape environment, and anything inside is basically
pages) and 2cm margin on outer margins. rotated. No actual page dimensions are changed. This
Setting the same value for the inner and outer for geome- approach is more applicable to books or reports than to
typical academic publications. Using pdscape instead of
try will remove the dierence between the margins. An-
other quick way to eliminate the dierence in position lscape when generating a PDF document will make the
between even and odd numbered pages would be setting page appear right side up when viewed: the single page
the values to evensidemargin and oddsidemargin to the that is in landscape format will be rotated, while the rest
half of odds default: will be left in portrait orientation.
By default, the value of evensidemargin is larger than Also, to get a table to appear correctly centered on a land-
oddsidemargin in the two-sided layout, as one could scaped page, one must place the tabular environment in-
wish to write notes on the side of the page. The side side a table environment, which is itself inside the land-
for the large margin is chosen opposite to the side where scape environment. For instance it should look like this:
pages are joined together. For books (and in general documents using the twoside
See the Lengths. option), the landscape-environment unfortunately does
not pay attention to the dierent layout of even and odd
pages. The macro can be xed using a few lines of extra
Top margin above Chapter code in the preamble[4] .
Change orientation of specic part The possibilities of changing the headers in plain La-
tex are actually quite limited. There are two commands
The second method is for when you are writing a docu- available: \pagestyle{''style''} will apply the specied
ment in portrait, but you have some contents, like a large style to the current and all subsequent pages, and \this-
diagram or table that would be displayed better on a land- pagestyle{''style''} will only aect the current page. The
scape page. However, you still want the consistency of possible styles are:
56 CHAPTER 2. COMMON ELEMENTS
The commands \markright and \markboth can be used exibility, the \chapter command and its friends do not re-
to set the content of the headings by hand. The follow- dene \rightmark and \leftmark themselves. They call yet
ing commands placed at the beginning of an article docu-another command (\chaptermark, \sectionmark, or \sub-
ment will set the header of all pages (one-sided) to contain
sectionmark) that is responsible for redening \rightmark
John Smith top left, On page styles centered and theand \leftmark, except if they are starred -- in such a case,
page number top right: \markboth{Chapter/Section name}{} must be used in-
There are special commands containing details on the side the sectioning command if header and footer lines
running page of the document. are to be updated.
Note that \leftmark and \rightmark convert the names to Again, several packages provide a solution:
uppercase, whichever was the formatting of the text. If
you want them to print the actual name of the chapter an alternative one-stage mechanism is provided by
without converting it to uppercase use the following com- the package titleps);
mand: fancyhdr will handle the process its own way.
Now \leftmark and \rightmark will just print the name of
the chapter and section, without number and without af-
fecting the formatting. Note that these redenitions must Customizing with fancyhdr
be inserted after the rst call of \pagestyle{fancy}. The
standard book formatting of the \chaptermark is: To get better control over the headers, one can use the
package fancyhdr written by Piet van Oostrum. It pro-
Watch out: if you provide long text in two dierent vides several commands that allow you to customize the
parts only in the footer or only in the header, you might header and footer lines of your document. For a more
see overlapping text. complete guide, the author of the package produced this
Moreover, with the following commands you can dene documentation.
the thickness of the decorative lines on both the header To begin, add the following lines to your preamble:
and the footer:
You can now observe a new style in your document.
The rst line for the header, the second for the footer.
Setting it to zero means that there will be no line. The \headheight needs to be 13.6pt or more, otherwise
you will get a warning and possibly formatting issues.
Both the header and footer comprise three elements each
Plain pages issue An issue to look out for is that the according to its horizontal position (left, centre or right).
major sectioning commands (\part, \chapter or \maketi- The styles supported by fancyhdr:
tle) specify a \thispagestyle{plain}. So, if you wish to
suppress all styles by inserting a \pagestyle{empty} at the
the four LaTeX styles;
beginning of your document, then the style command at
each section will override your initial rule, for those pages fancy denes a new header for all pages but plain-
only. To achieve the intended result one can follow the style pages such as chapters and titlepage;
new section commands with \thispagestyle{empty}. The
\part command, however, cannot be xed this way, be- fancyplain is the same, but for absolutely all pages.
cause it sets the page style, but also advances to the next
page, so that \thispagestyle{} cannot be applied to that Style customization The styles can be customized
page. Two solutions: with fancyhdr specic commands. Those two styles may
be congured directly, whereas for LaTeX styles you
simply write \usepackage{nopageno} in the pream- need to make a call to the \fancypagestyle command.
ble. This package will make \pagestyle{plain} have
To set header and footer style, fancyhdr provides three
the same eect as \pagestyle{empty}, eectively
interfaces. They all provide the same features, you just
suppressing page numbering when it is used.
use them dierently. Choose the one you like most.
Use fancyhdr as described below.
You can use the following six commands.
The tricky problem when customizing headers and foot-
ers is to get things like running section and chapter names Hopefully, the behaviour of the above commands is fairly
in there. Standard LaTeX accomplishes this with a two- intuitive: if it has head in it, it aects the head etc, and
stage approach. In the header and footer denition, you obviously, l, c and r means left, centre and right respec-
use the commands \rightmark and \leftmark to represent tively.
the current section and chapter heading, respectively. The
values of these two commands are overwritten whenever You can also use the command \fancyhead for
a chapter or section command is processed. For ultimate header and \fancyfoot for footer. They work in the
2.12. PAGE LAYOUT 57
same way, so we'll explain only the rst one. The Using \fancypagestyle one can additionally dene multi-
syntax is: ple styles for ones document that are easy to switch be-
tween. Heres a somewhat complicated example for a
two-sided book style:
You can use multiple selectors optionally separated by a
comma. The selectors are the following:
so CE,RO will refer to the center of the even pages and Page n of m
to the right side of the odd pages.
Some people like to put the current page number in con-
text with the whole document. LaTeX only provides ac-
\fancyhf is a merge of \fancyhead and \fancyfoot,
cess to the current page number. However, you can use
hence the name. There are two additional selectors
the lastpage package to nd the total number of pages,
H and F to specify the header or the footer, respec-
like this:
tively. If you omit the H and the F, it will set the
elds for both. Note the capital letters. Also, add a backslash after \thep-
age to ensure adequate space between the page number
and 'of'. And recall, when using references, that you
These commands will only work for fancy and fancyplain. have to run LaTeX an extra time to resolve the cross-
To customize LaTeX default style you need the \fancy- references.
plainstyle command. See below for examples.
For a clean customization, we recommend you start from
scratch. To do so you should erase the current pagestyle. Alternative packages
Providing empty values will make the eld blank. So
Other packages for page styles are scrpage2, very simi-
will just delete the current heading/footer conguration, lar to fancyhdr, and titleps, which takes a one-stage ap-
so you can make your own. proach, without having to use \leftmark or \rightmark.
Plain pages There are two ways to change the style of 2.12.8 Page background
plain pages like chapters and titlepage.
First you can use the fancyplain style. If you do so, you The eso-pic package will let you print content in the back-
can use the command \fancyplain{...}{...} inside fancy- ground of every page or individual pages.
hdr commands like \lhead{...}, etc. The starred-version of the \AddToShipoutPicture com-
When LaTeX wants to create a page with an empty style, mand applies to the current page only.
it will insert the rst argument of \fancyplain, in all the
other cases it will use the second argument. For instance:
2.12.9 Multi-column pages
It has the same behavior of the previous code, but you
will get empty header and footer in the title and at the
Using the twocolumn optional class argument
beginning of chapters.
Alternatively you could redene the plain style, for ex- Using a standard Latex document class, like article, you
ample to have a really plain page when you want. The can simply pass the optional argument twocolumn to the
command to use is \fancypagestyle{plain}{...} and the ar- document class: \documentclass[twocolumn]{article}
gument can contain all the commands explained before. which will give the desired eect.
An example is the following:
While this approach is useful, it has limitations. The mul-
In that case you can use any style but fancyplain because ticol package provides the following advantages:
it would override your redenition.
Can support up to ten columns.
Examples For two-sided, its common to mirror the Implements a multicols environment, therefore, it is
style of opposite pages, you tend to think in terms of inner possible to mix the number of columns within a doc-
and outer. So, the same example as above for two-sided ument.
is:
This is eectively saying author name is top outer, to- Additionally, the environment can be nested inside
days date is top inner, and current page number is bottom other environments, such as gure.
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 nal page will be of roughly equal
use for a two-sided document: length.
58 CHAPTER 2. COMMON ELEMENTS
Use multicols* environment for unbalanced and orphans. You can try to increase these penalties by
columns, whereby each column is completely lled putting following commands in your document preamble:
before starting with the next column. If this does not help, you can try increasing these values
Vertical rules between columns can be customised. even more, to a maximum of 10000. However, it is not
recommended to set this value too high, as setting it to
Column environments can be easily customised lo- 10000 forbids LaTeX from doing this altogether, which
cally or globally. might result in strange behavior.
It also helps to have rubber band values for the space be-
Using multicol package tween paragraphs:
Alternatively, you can use the needspace package to re-
The multicol package overcomes some of the shortcom- serve some lines and thus to prevent page breaking for
ings of twocolumn and provides the multicol environ- those lines.
ment. To create a typical two-column layout:
Floats are not fully supported by this environment. It can
only cope if you use the starred forms of the oat com-
2.12.12 Troubleshooting
mands (e.g., \begin{gure*} ) which makes the oat span
A very useful troubleshooting and designing technique is
all columns. This is not hugely problematic, since oats
to turn on the showframe option in the geometry pack-
of the same width as a column may be too small, and you
age (which has the same eect as the showframe pack-
would probably want to span them anyway. See this sec-
age described above). It draws bounding boxes around
tion for a more detailed discussion.
the major page elements, which can be helpful because
The multicol package has two important parameters the boundaries of various regions are usually invisible,
which can be set using \setlength: and complicated by padding whitespace.
[3] http://baymard.com/blog/line-length-readability
2.12.10 Manual page formatting [4] https://stackoverflow.com/questions/4982219/
how-to-make-landscape-mode-rotate-properly-in-a-twoside-book/
There may be instances, especially in very long docu- 5320962#5320962
ments, such as books, that LaTeX will not get all page
breaks looking as good as it could. It may, therefore,
be necessary to manually tweak the page formatting. Of 2.13 Importing Graphics
course, you should only do this at the very nal stage of
producing your document, once all the content is com-
plete. LaTeX oers the following: 2.13.1 Importing external graphics
eps2eps
When all of the above fails, one can simplify the EPS le
before attempting other conversions, by using the eps2eps
tool (also see next section):
$ eps2eps input.eps input-e2.eps
imgtops
(pdf)latex with the --shell-escape option) can do this us- Converting a color EPS to grayscale
ing Inkscapes pdf+tex export option, or a simple macro
can be used. See How to include SVG diagrams in La- Sometimes color EPS gures need to be converted to
TeX? -- Stackexchange See Export To Other Formats for black-and-white or grayscale to meet publication require-
more details. ments. This can be achieved with the eps2eps of the
Ghostscript package and programs:
pstoedit $ eps2eps input.eps input-e2.eps $ pscol 0gray input-
e2.eps input-gray.eps
Raster graphics converters Dia is a cross platform diagramming utility which can
export eps images, or generate tex drawn using the tikz
package.
Sam2p (convert) or
Inkscape
ImageMagick (convert) or
Another program for creating vector graphics is Inkscape.
GraphicsMagick (gm convert). It can run natively under Windows, Linux or Mac OS
X (with X11). It works with Scalable Vector Graph-
ics (SVG) les, although it can export to many for-
These three programs operate much the same way, and mats that can be included in LaTeX les, 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 oer PDF/EPS/PS+LaTeX output option, similar to that of-
both the best quality and to result in the smallest les. fered by Xg. 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 o input.png output.png ical notation or LaTeX fonts into graphics (which may
then be imported into LaTeX documents).
2.13. IMPORTING GRAPHICS 61
Vector editor TpX separates geometric objects from text And you're done!
objects. Geometric objects are saved into .PDF le, the
For more details on using xg with LaTeX, this chapter
rest is saved in .TpX le to be processed by LaTeX. User
of the xg User Manual may prove helpful.
just create the graphics in TpX editor and calls the .TpX
le from latex le by command \input{...TpX}.
Other tools
Xg
Commercial vector graphics software, such as Adobe
Illustrator, CorelDRAW, and FreeHand are commonly
Xg is a basic program that can produce vector graphics,
used and can read and write EPS gures. 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, Xg 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 Xg, you need to
rst start the Start X - Server, then launch xterm to Adobe Photoshop
bring up a terminal. In this terminal type xg (without
the quotation marks) and press return. It can save to EPS.
Alternatively, WinFIG is an attempt to achieve the func-
tionality of xg on Windows computers. GIMP
[2] Philip Ilten. The svg package on CTAN. ctan.org. http: To create a gure that oats, use the gure environment.
//www.ctan.org/tex-archive/graphics/svg. The previous section mentioned how oats are used to
allow LaTeX to handle gures, while maintaining the best
possible presentation. However, there may be times when
2.14 Floats, Figures and Captions you disagree, and a typical example is with its positioning
of gures. The placement specier parameter exists as a
The previous chapter introduced importing graphics. compromise, and its purpose is to give the author a greater
However, just having a picture stuck in between para- degree of control over where certain oats are placed.
graphs does not look professional. To start with, we What you do with these placement permissions is to list
2.14. FLOATS, FIGURES AND CAPTIONS 63
which of the options you wish to make available to La- You may feel that it is a bit long winded, but such distinc-
TeX. These are simply possibilities, and LaTeX will de- tions are necessary, because you may not want all tables
cide when typesetting your document which of your sup- to be treated as a oat.
plied speciers it thinks is best. Frank Mittelbach de- Use \listoftables to add a list of the tables in the beginning
scribes the algorithm[2] : of the document.
In some special cases LaTeX won't follow these position-It is always good practice to add a caption to any gure or
ing parameters and additional commands will be neces- table. Fortunately, this is very simple in LaTeX. All you
sary, for example, if one needs to specify an alignment need to do is use the \caption{''text''} command within
the oat environment. LaTeX will automatically keep
other than centered for a oat that sits alone in one page[3] .
track of the numbering of gures, so you do not need to
Use \listogures to add a list of the gures in the be- include this within the caption text.
ginning of the document. To change the name used in
the caption from Figure to Example, use \renewcom- The location of the caption is traditionally underneath the
mand{\gurename}{Example} in the gure contents. oat. However, it is up to you to therefore insert the cap-
tion command after the actual contents of the oat (but
still within the environment). If you place it before, then
Figures with borders Its possible to get a thin border the caption will appear above the oat. Try out the fol-
around all gures. You have to write the following once lowing example to demonstrate this eect:
at the beginning of the document: Note that the command \reectbox{...} ips its content
The border will not include the caption. horizontally.
Floating tables are covered in a separate chapter. Lets It is sometimes desirable to have a caption appear on the
give a quick reminder here. The tabular environment that side of a oat, rather than above or below. The sidecap
was used to construct the tables is not a oat by default. package can be used to place a caption beside a gure
Therefore, for tables you wish to oat, wrap the tabular or table. The following example demonstrates this for a
environment within a table environment, like this: gure by using a SCgure environment in place of the
64 CHAPTER 2. COMMON ELEMENTS
gure environment. The oatrow package is newer and There are several packages available for the task, but none
has more capabilities. of them works perfectly. Before you make the choice of
including gures with text wrapping in your document,
make sure you have considered all the options. For ex-
Unnumbered captions
ample, you could use a layout with two columns for your
documents and have no text-wrapping at all.
In some types of document (such as presentations), it may
not be desirable for gure captions to start Figure:. This is Anyway, we will look at the package wrapg. Note that
easy to suppress by just placing the caption text in the g- wrapg may not come with the default installation of
ure environment, without enclosing it in a caption. This LaTeX; you might need to install additional packages.
however means that there is no caption available for in- Noted also, wrapg is incompatible with the enumerate
clusion in a list of gures. and itemize environments
To use wrapg, you must rst add this to the preamble:
Renaming table caption prex This then gives you access to:
The lineheight is expressed as the number of lines of text
In case you want to rename your table caption from Ta-
the gure spans. LaTeX will automatically calculate the
ble to something else, you can use the \captionsetup
value if this option is left blank but this can result in g-
command. For example,
ures that look ugly (with too much spacing). The LaTeX
calculation is manually overridden by entering the num-
2.14.4 Lists of gures and tables ber of lines you would like the gure to span. This option
can't be entered in pt, mm etc...
Captions can be listed at the beginning of a paper or re- There are overall eight possible positioning targets:
port in a List of Tables or a List of Figures section
by using the \listoftables or \listogures commands, re- The uppercase-character allows the gure to[4]oat, while
spectively. The caption used for each gure will appear in the lowercase version means exactly here.
these lists, along with the gure numbers, and page num- The overhang of the gure can be manually set using the
bers that they appear on. overhang option in pt, cm etc...
The \caption command also has an optional parameter, The width is, of course, the width of the gure. An ex-
\caption[''short'']{''long''} which is used for the List of Ta- ample:
bles or List of Figures. Typically the short description is
You can also allow LaTeX to assign a width to the wrap
for the caption listing, and the long description will be
by setting the width to 0pt. \begin{wrapgure}{l}{0pt}
placed beside the gure or table. This is particularly use-
ful if the caption is long, and only a one-liner is desired Note that we have specied a size for both the wrapgure
in the gure/table listing. Here is an example of this us- environment and the image we have included. We did it
age: in terms of the text width: it is always better to use rela-
tive sizes in LaTeX, let LaTeX do the work for you! The
wrap is slightly bigger than the picture, so the compiler
2.14.5 Labels and cross-referencing will not return any strange warning and you will have a
small white frame between the image and the surround-
Labels and cross-references work fairly similarly to the ing text. You can change it to get a better result, but if
general case - see the Labels and Cross-referencing sec- you don't keep the image smaller than the wrap, you
tion for more information. will see the image over the text.
If the label picks up the section or list number instead The wrapg package can also be used with user-dened
of the gure number, put the label inside the caption to oats with oat package. See below in the section on cus-
ensure correct numbering. If you get an error when the tom oats.
label is inside the caption, use \protect in front of the \la-
bel command.
Tip for gures with too much white space
2.14.6 Wrapping text around gures You can use intextsep parameter to control
additional space above and below the gure:
An author may prefer that some oats do not break the \setlength\intextsep{0pt}
ow of text, but instead allow text to wrap around it. (Ob- It happens that you'll generate gures with too much (or
viously, this eect only looks decent when the gure in too little) white space on the top or bottom. In such a
question is signicantly narrower than the text width.) case, you can simply make use of the optional argument
A word of warning: Wrapping gures in LaTeX will [lineheight]. It species the height of the gure in num-
require a lot of manual adjustment of your document. ber of lines of text. Also remember that the environment
2.14. FLOATS, FIGURES AND CAPTIONS 65
center adds some extra white space at its top and bottom; where the label is inserted; \caption outside the subgure-
consider using the command \centering instead. environment will provide the global caption.
Another possibility is adding space within the oat using subcaption will arrange the gures or tables side-by-side
the \vspace{...} command. The argument is the size of providing they can t, otherwise, it will automatically
the space you want to add, you can use any unit you want, shift suboats below. This eect can be added manually,
including pt, mm, in, etc. If you provide a negative ar- by putting the newline command (\\) before the gure you
gument, it will add a negative space, thus removing some wish to move to a newline.
white space. Using \vspace tends to move the caption Horizontal spaces between gures are controlled by one
relative to the oat while the [lineheight] argument does of several commands, which are placed in between \be-
not. Here is an example using the \vspace command, the gin{subgure} and \end{subgure}:
code is exactly the one of the previous case, we just added
some negative vertical spaces to shrink everything up:
A non-breaking space (specied by ~ as in the exam-
In this case it may look too shrunk, but you can manage ple above) can be used to insert a space in between
spaces the way you like. In general, it is best not to add the subgs.
any space at all: let LaTeX do the formatting work!
Math spaces: \qquad, \quad, \;, and \,
(In this case, the problem is the use of \begin{center}
to center the image. The center environment adds extra Generic space: \hspace{''length''}
space that can be avoided if \centering is used instead.)
Automatically expanding/contracting space: \hll
Alternatively you might use the picins package instead
of the wrapg package which produces a correct version
without the excess white space out of the box without any 2.14.8 Wide gures in two-column docu-
hand tuning. ments
There is also an alternative to wrapg: the package oatt
. If you are writing a document using two columns (i.e.
you started your document with something like \docu-
To remove the white space from a gure once for all, one
mentclass[twocolumn]{article}), you might have noticed
should refer to the program pdfcrop, included in most
that you can't use oating elements that are wider than the
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 Suboats ments, the only solution is to use the starred variants
of the oating environments, that are {gure*} and {ta-
A useful extension is the subcaption package, which uses ble*}. Those starred versions work like the standard
suboats within a single oat. The subgure and subg ones, but they will be as wide as the page, so you will get
packages are deprecated; however they are useful alter- no overlapping.
natives when used in-conjunction with LaTeX templates
(i.e templates for journals from Springer and IOP, IEEE- A bad point of those environments is that they can be
Tran and ACM SIG) that are not compatible with subcap- placed only at the top of the page or on their own page. If
tion. These packages give the author the ability to have you try to specify their position using modiers like b or
subgures within gures, or subtables within table oats. h, they will be ignored. Add \usepackage{dbloatx} to
Suboats have their own caption, and an optional global the preamble in order to alleviate this problem with regard
caption. An example will best illustrate the usage of the to placing these oats at the bottom of a page, using the
subcaption package: optional specier [b]. Default is [tbp]. However, h still
does not work.
To prevent the gures from being placed out-of-order
with respect to their non-starred counterparts, the
package xltx2e [5] should be used (e.g. \usepack-
age{xltx2e}).
is your friend for this task. All commands to set up the not in outer par mode
new oat must be placed in the preamble, and not within may occur. One solution might be to use the [H] option
the document. (not any other) on the inner oat, as this option pins the
inner oat to the outer one.
1. Add \usepackage{oat} to the preamble of your
Newly created oats with \newoat can also be used in
document
combination with the wrapg package from above. E.g.
2. Declare your new oat using: the following code creates a oating text box, which oats
\newoat{type}{placement}{ext}[outer counter], in the text on the right side of the page and is complete
where: with caption, numbering, an index le with the extension
.lob and a customization of the oats visual layout:
type - the new name you wish to call your oat,
in this instance, 'program'.
Caption styles
placement - t, b, p, or h (as previously de-
scribed in Placement), where letters enumer-
To change the appearance of captions, use the caption
ate permitted placements.
package. For example, to make all caption labels small
ext - the le name extension of an auxiliary le and bold:
for the list of gures (or whatever). LaTeX
The KOMA script packages have their own caption cus-
writes the captions to this le.
tomizing features with e.g. \captionabove, \captionformat
outer counter - the presence of this parameter and \setcapwidth. However these denitions have limited
indicates that the counter associated with this eect on newly created oat environments with the wrap-
new oat should depend on outer counter, for g package.
example 'chapter'.
Alternatively, you can redene the \thegure command:
3. The default name that appears at the start of the cap- See this page for more information on counters. Finally,
tion is the type. If you wish to alter this, use \oat- note that the caption2 package has long been deprecated.
name{type}{oatname}
[1] http://www.ctan.org/tex-archive/macros/latex/contrib/ The package provides some useful commands for insert-
float/ ing links pointing outside the document.
\url Usage:
This page uses material from Andy Roberts Getting to grips
with LaTeX with permission from the author. It will show the URL using a mono-spaced font and, if
you click on it, your browser will be opened pointing at
it.
2.15 Hyperlinks
\href Usage:
LaTeX enables typesetting of hyperlinks, useful when the It will show the string description using standard docu-
resulting format is PDF, and the hyperlinks can be fol- ment font but, if you click on it, your browser will be
lowed. It does so using the package hyperref. opened pointing at my_url. Here is an example:
Both point at the same page, but in the rst case the URL
will be shown, while in the second case the URL will be
2.15.1 Hyperref hidden. Note that, if you print your document, the link
stored using \href will not be shown anywhere in the doc-
The package hyperref[1] provides LaTeX the ability to ument.
create hyperlinks within the document. It works with
pdatex and also with standard latex used with dvips
and ghostscript or dvipdfm to build a PDF le. If you Other possibilities
load it, you will have the possibility to include interac-
tive external links and all your internal references will be Apart from linking to websites discussed above, hyperref
turned to hyperlinks. The compiler pdatex makes it pos- can be used to provide mailto links, links to local les,
sible to create PDF les directly from the LaTeX source, and links to anywhere within the PDF output le.
and PDF supports more features than DVI. In particular
PDF supports hyperlinks. Moreover, PDF can contain
other information about a document such as the title, the E-mail address A possible way to insert email links is
author, etc., which can be edited using this same package. by
It just shows your email address (so people can know it
even if the document is printed on paper) but, if the reader
2.15.2 Usage clicks on it, (s)he can easily send you an email. Or, to
incorporate the url packages formatting and line breaking
[2]
The basic usage with the standard settings is straightfor- abilities into the displayed text, use
ward. Just load the package in the preamble: When using this form, note that the \nolinkurl command
This will automatically turn all your internal references is fragile and if the hyperlink is inside of a moving argu-
into hyperlinks. It won't aect the way to write your ment, it must be preceeded by a \protect command.
documents: just keep on using the standard \label-\ref
system (discussed in the chapter on Labels and Cross-
referencing); with hyperref those connections will be- Local le Files can also be linked using the url or the
come links and you will be able to click on them to be href commands. You simply have to add the string run:
redirected to the right page. Moreover the table of con- at the beginning of the link string:
tents, list of gures/tables and index will be made of hy- Following http://tex.stackexchange.com/questions/
perlinks, too. The hyperlinks will not show-up if you are 46488/link-to-local-pdf-file the version with url does
working in draft mode. not always work, but href does.
68 CHAPTER 2. COMMON ELEMENTS
2.15.3 Customization
Problems with Links and Equations 2
The standard settings should be ne for most users, but Messages like the following
if you want to change something, that is also possible.
There are several variables and two methods to pass those ! Runaway argument? {\@rstove }\ ), Some text
to the package. Options can be passed as an argument of from your document here (\ref {re\ETC. Latex Error:
the package when it is loaded (the standard way packages Paragraph ended before \Hy@setref@link was complete.
work), or the \hypersetup command can be used as fol- appear when you use \label inside an align environment.
lows:
Possible solution: Add the following to your preamble:
you can pass as many options as you want; separate them
with a comma. Options have to be in the form: Note: The same error appears if you use a colon ":" as
part of a label, i.e. \label{lst:program01}. Replacing that
exactly the same format has to be used if you pass those will help.
options to the package while loading it, like this:
Here is a list of the possible variables you can change (for
the complete list, see the ocial documentation). The Problems with Links and Pages
default values are written in an upright font:
Messages like the following:
Checkout 3.8 Big list at hyperref-manual at tug.org
! pdfTeX warning (ext4): destination with the same iden-
Please note, that explicit RGB specication is only al- tier (name{page.1}) has been already used, duplicate ig-
lowed for the border colors (like linkbordercolor etc.), nored
while the others may only assigned to named colors
(which you can dene your own, see Colors). In order appear when a counter gets reinitialized, for example by
to speed up your customization process, here is a list with using the command \mainmatter provided by the book
the variables with their default value. Copy it in your doc- document class. It resets the page number counter to 1
ument and make the changes you want. Next to the vari- prior to the rst chapter of the book. But as the preface
ables, there is a short explanations of their meaning: of the book also has a page number 1 all links to page
1 would not be unique anymore, hence the notice that
If you don't need such a high customization, here are duplicate has been ignored. The counter measure con-
some smaller but useful examples. When creating PDFs
sists of putting plainpages=false into the hyperref options.
destined for printing, colored links are not a good thing as This unfortunately only helps with the page counter. An
they end up in gray in the nal output, making it dicult
even more radical solution is to use the option hypertex-
to read. You can use color frames, which are not printed: names=false, but this will cause the page links in the index
or make links black: to stop working.
When you just want to provide information for the Doc- The best solution is to give each page a unique name by
ument Info section of the PDF le, as well as enabling using the \pagenumbering command:
back references inside bibliography: Another solution is to use \pagenumbering{alph} before
By default, URLs are printed using mono-spaced fonts. the command \maketitle, which will give the title page
If you don't like it and you want them to be printed with the label page.a. Since the page number is suppressed, it
the same style of the rest of the text, you can use this: won't make a dierence to the output.
2.15. HYPERLINKS 69
The text displayed by bookmarks does not always look Problems with already existing .toc, .lof and similar
like you expect it to look. Because bookmarks are just les
text, much fewer characters are available for bookmarks
than for normal LaTeX text. Hyperref will normally no-The format of some of the auxilliary les generated by la-
tice such problems and put up a warning: tex changes when you include the hyperref package. One
Package hyperref Warning: Token not allowed in a PDF- can therefore encounter errors like
DocEncoded string: ! Argument of \Hy@setref@link has an extra }.
You can now work around this problem by providing a when the document is typeset with hyperref for the rst
text string for the bookmarks, which replaces the oend- time and these les already exist. The solution to the
ing text: problem is to delete all the les that latex uses to get ref-
Math expressions are a prime candidate for this kind of erences right and typeset again.
problem:
which turns \section{$E=mc^2$} to E=mc2 in the book- Problems with footnotes and special characters
mark area. Color changes also do not travel well into
bookmarks: See the relevant section.
produces the string redRed!". The command \textcolor
gets ignored but its argument (red) gets printed. If you Problems with Beamer
use:
the result will be much more legible. Using the command
If you write your document in unicode and use the uni- is broken when pointed at a label. Instead of sending the
code option for the hyperref package you can use unicode user to the desired label, upon clicking the user will be
characters in bookmarks. This will give you a much larger sent to the rst frame. A simple work around exists; in-
selection of characters to pick from when using \texor- stead of using
70 CHAPTER 2. COMMON ELEMENTS
to label your frames, use LaTeX will replace the string "\ref{marker}" with the
and reference it with right number that was assigned to the object. If you ref-
erence a marker that does not exist, the compilation of
the document will be successful but LaTeX will return a
Problems with draft mode warning:
LaTeX Warning: There were undened references.
WARNING! Please note that if you have activated the
draft"-option in your \documentclass declaration the hy- and it will replace "\ref{unknown-marker}" with "??" (so
perlinks will not show up in the table of contents, or any- it will be easy to nd in the document).
where else for that matter!!! As you may have noticed reading how it works, it is a two-
The hyperlinks can be re-enabled by using the - step process: rst the compiler has to store the labels with
nal=true option in the following initialization of the hy- the right number to be used for referencing, then it has to
perref package, just after the package was included: replace the \ref with the right number. That is why, when
you use references, you have to compile your document
A good source of further options for the hyperref package twice to see the proper output. If you compile it only
can be found here [6] . 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
2.15.5 Notes and References
of the compilation:
[1] Hyperref package webpage in CTAN
[4] http://www.ctan.org/tex-archive/macros/latex/contrib/
hyperref/README
Using the command \pageref{} you can help the reader
to nd the referenced object by providing also the page
[5] Wrapg package webpage in CTAN number where it can be found. You could write some-
thing like:
[6] Hyperref - Hyperlinks With LaTeX Page
See gure~\ref{fig:test} on page~\pageref{fig:test}.
2.16 Labels and Cross-referencing Since you can use exactly the same commands to refer-
ence almost anything, you might get a bit confused after
2.16.1 Introduction you have introduced a lot of references. It is common
practice among LaTeX users to add a few letters to the la-
In LaTeX you can easily reference almost anything that bel to describe what you are referencing. Some packages,
is numbered (sections, gures, formulas), and LaTeX will such as fancyref, rely on this meta information. Here is
take care of numbering, updating it whenever necessary. an example:
The commands to be used do not depend on what you are Following this convention, the label of a gure will look
referencing, and they are: like \label{g:my_gure}, etc. You are not obligated to
use these prexes. You can use any string as an argument
\label{marker} you give the object you want to reference of \label{...}, but these prexes become increasingly use-
a marker, you can see it like a name. ful as your document grows in size.
Another suggestion: try to avoid using numbers within
\ref{marker} you can reference the object you have
labels. You are better o describing what the object is
marked before. This prints the number that was as-
about. This way, if you change the order of the objects,
signed to the object.
you will not have to rename all your labels and their ref-
\pageref{marker} It will print the number of the page erences.
where the object is. If you want to be able to see the markers you are using
in the output document as well, you can use the showkeys
LaTeX will calculate the right numbering for the objects package; this can be very useful while developing your
in the document; the marker you have used to label the document. For more information see the Packages sec-
object will not be shown anywhere in the document. Then tion.
2.16. LABELS AND CROSS-REFERENCING 71
2.16.2 Examples label for any picture or table can go within the \caption{}
command, as in
Here are some practical examples, but you will notice that \caption{Close-up of a gull\label{fig:gull}}
they are all the same because they all use the same com-
mands.
See the Floats, Figures and Captions section for more
about the gure and related environments.
Sections
Fixing wrong labels The command \label must ap-
\section{Greetings} \label{sec:greetings} Hello! pear after (or inside) \caption. Otherwise, it will pick up
\section{Referencing} I greeted in section~\ref{sec: the current section or list number instead of what you in-
greetings}. tended.
\begin{gure} \centering \includegraph-
ics[width=0.5\textwidth]{gull} \caption{Close-up
of a gull} \label{fig:gull} \end{gure}
\ref{...} will return the respective g/table number, but it As you can see, the label is placed soon after the begin-
must occur after the caption. When declared outside, it ning of the math mode. In order to reference a formula,
will give the section number. To be completely safe, the you have to use an environment that adds numbers. Most
72 CHAPTER 2. COMMON ELEMENTS
of the times you will be using the equation environment; this may cause some strange errors at compiling time that
that is the best choice for one-line formulae, whether you are very hard to be xed. You could think that this hap-
are using amsmath or not. Note also the eq: prex in the pens very rarely; unfortunately, if you write a long docu-
label. ment it is not uncommon to have hundreds of references,
so situations like these are likely to happen. One way to
avoid problems during development is to use the standard
eqref The amsmath package adds a new command for ref all the time, and convert it to vref when the document
referencing formulae; it is \eqref{}. It works exactly like is close to its nal version, and then making adjustments
\ref{}, but it adds parentheses so that, instead of printing to x possible problems.
a plain number as 5, it will print (5). This can be useful
to help the reader distinguish between formulae and other
things, without the need to repeat the word formula be-
fore any reference. Its output can be changed as desired; 2.16.4 The hyperref package
for more information see the amsmath documentation.
autoref
nameref 2. hyperref
In section MyFirstSection we dened... [2] Tests done under report class http://tex.stackexchange.
com/questions/139459/vref-and-input-command
1. varioref
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 LaTeXs
it encounters something it doesn't understand or can't do, parameters so that the spacing is suciently sloppy that
it will display a message saying what is wrong. It may also you will almost never get a warning about badly-tting
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 xed 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 nd
another error message not shown here, and its 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 le 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 le which LaTeX was something else occurs which can't happen until the curly
processing when the error was spotted. Heres 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
! Undened control sequence. l.6 \tableofcotnetns or look like.
When LaTeX nds 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 le, regardless of errors, or until
a limit is reached. Too many }'s
74
3.1. ERRORS AND WARNINGS 75
Undened control sequence typesetting when it found this, and the number in square
brackets is the number of the page onto which the of-
! Undened 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 its 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: its undened. 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 dierent 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 \_ justication 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 nd the line in the
code that originates the problem (in this case: 860-861)
Runaway argument and x 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 exibility settings need changing.
from the date. Its 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 eect
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 nished. 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 t, without making the spacing bigger than its Easily spotting overfull hboxes in the document To
currently permitted maximum. The badness (0-10,000) easily nd 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 le it was wide:
76 CHAPTER 3. MECHANICS
Although this is a warning from the Babel package and 3.2 Lengths
not from LaTeX, this error is very common and (can) give
some strange hyphenation (word breaking) problems in In TeX, a length is
your document. Wrong hyphenation rules can decrease
the neatness of your document.
a oating point number followed by a unit, optionally
Package babel Warning: No hyphenation patterns were followed by a stretching value;
loaded for (babel) the language `Latin' (babel) I will use
the patterns loaded for \language=0 instead.
a oating point factor followed by a macro that ex-
This can happen after the usage of: (see pands to a length.
LaTeX/Internationalization)
\usepackage[latin]{babel}
3.2.1 Units
The solution is not dicult, just install the used language
in your LaTeX distribution. First, we introduce the LaTeX measurement units. All
LaTeX units are two-letter abbreviations. You can
choose from a variety of units. Here are the most com-
mon ones.[1]
Package babel Error: You haven't loaded the option
X yet. The point is the default unit and 1pt is the default length.
All other units are converted to the point by a xed ratio.
[2]
If you previously set the X language, and then decided Here are some less common units.
to switch to Y, you will get this error. This may seem
awkward, as there is obviously no error in your code if
you did not change anything. The answer lies in the .aux 3.2.2 Box lengths
le, where babel dened your language. If you try the
compilation a second time, it should work. If not, delete A box in TeX is characterized by three lengths:
the .aux le, 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.
3.2. LENGTHS 77
3.2.3 Length manipulation \oddsidemargin The margin for 'odd' pages (think of a
printed booklet).
You can change the values of the variables dening the
page layout with two commands. With this one you can \paperwidth The width of the page.
set a new value for an existing length variable: \paperheight The height of the page.
with this other one, you can add a value to the existing
one: \parindent The normal paragraph indentation.
You can create your own length with the command, and \parskip The extra vertical space between paragraphs.
you must create a new length before you attempt to set it:
\tabcolsep The default separation between columns in a
You may also set a length from the size of a text with one tabular environment.
of these commands:
\textheight The height of text on the page.
The calc package provides also the function \settototal-
height{\mylength}{some text} \textwidth The width of the text on the page.
When using these commands, you may duplicate the text
\topmargin The size of the top margin.
that you want to use as reference if you plan to also dis-
play it. But LaTeX also provides \savebox to avoid this \unitlength Units of length in picture environment.
duplication. You may wish to look at the example below
to see how you can use these. See Boxes for more details.
You can also dene stretched values. A stretching value 3.2.5 Fixed-length spaces
is a length preceded by plus or minus to specify to what
extent tex is authorized to change the length. Example: To insert a xed-length space, use:
It means that tex will try to use a length of 10pt; if it is un- \hspace stands for horizontal space, \vspace for vertical
derfull, it will raise the length up to a maximum of 15pt; space.
if it is overfull, it will lower the length up to a minimum If such a space should be kept even if it falls at the end or
of 7pt. the start of a line, use \hspace* instead.
Note that it is not mandatory to specify both the plus and If the space should be preserved at the top or at the bot-
the minus values, but if you do, plus must be placed be- tom of a page, use the starred version of the command,
fore minus. \vspace*, instead of \vspace. If you want to add space
To print a length, you can use the \the command: at the beginning of the document, without anything else
written before, then you may use
Its important you use the \vspace* command instead of
Plain TeX \vspace, otherwise LaTeX can silently ignore the extra
space.
To create a new length:
TeX features some macros for xed-length spacing.
To set a length:
To view, it is the same as with LaTeX, using the command \smallskip Inserts a small space in vertical mode (be-
\the. tween two paragraphs).
Common length macros are: \bigskip Inserts a big space in vertical mode (between
two paragraphs).
\baselineskip The normal vertical distance between
lines in a paragraph. The vertical mode is during the process of assembling
boxes vertically, like paragraphs to build a page. The
\baselinestretch Multiplies \baselineskip. horizontal mode is during the process of assembling
\columnsep The distance between columns. boxes horizontally, like letters to build a word or words
to build a paragraph.
\columnwidth The width of the column. The fact they are vertical mode commands mean they will
\evensidemargin The margin for 'even' pages (think of be ignored (or fail) in horizontal mode such as in the mid-
a printed booklet). dle of a paragraph. The rst token next the a double line-
break is still in vertical mode if it does not expand to char-
\linewidth The width of a line in the local environment. acters.
78 CHAPTER 3. MECHANICS
[2] http://anonscm.debian.org/cgit/debian-tex/texlive-bin.
Strangely enough, LaTeX counters are not introduced by
git/tree/texk/web2c/pdftexdir/pdftex.web?h=debian/ a backslash in any case, even with the \the command.
2015.20150524.37493-5#n10460 plainTeX equivalents \count and \newcounter\mycounter
do abide by the backslash rule.
enumiii The height is the length between the baseline and the
top of the box.
enumiv
The depth is the length between the baseline and the
bottom of the box.
For the eqnarray environment:
The width is the width of the box.
equation
3.3.6 Custom enumerate While \parbox packs up a whole paragraph doing line
breaking and everything, there is also a class of boxing
See the List Structures chapter. commands that operates only on horizontally aligned ma-
terial. We already know one of them; its called \mbox.
It simply packs up a series of boxes into another one, and
3.3.7 Custom sectioning can be used to prevent LaTeX from breaking two words.
(See Hyphenation.) As you can put boxes inside boxes,
Here is an example for recreating something similar to a these horizontal box packers give you ultimate exibility.
section and subsection counter that already exist in La- width denes the width of the resulting box as seen from
TeX: the outside. This means it can be smaller than the material
80 CHAPTER 3. MECHANICS
inside the box. You can even set the width to 0pt so that the \begin{minipage}[pos][height][contentpos]{width}
the text inside the box will be typeset without inuencing text \end{minipage} environment.
the surrounding boxes. Besides the length expressions, The pos parameter can take one of the letters center, top
you can also use \width, \height, \depth and \totalheight
or bottom to control the vertical alignment of the box,
in the width parameter. They are set from values obtained
relative to the baseline of the surrounding text. The height
by measuring the typeset text. parameter is the height of the parbox or minipage. The
The pos parameter takes a one letter value: center, contentpos parameter is the position of the content and
ushleft, ushright, or spread the text to ll the box. can be one of center, top, bottom or spread. width takes
a length argument specifying the width of the box. The
main dierence between a minipage and a \parbox is that
3.4.3 framebox you cannot use all commands and environments inside a
parbox, while almost anything is possible in a minipage.
The command \framebox works exactly the same as
This should print 3 boxes on the same line. Do not put
\makebox, but it draws a box around the text.
another linebreak between the \fbox, otherwise you will
The following example shows you some things you could put the following \fbox in another paragraph on another
do with the \makebox and \framebox commands: line.
You can tweak the following frame lengths.
Paragraphs in all boxes
\fboxsep: the distance between the frame and the
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 species the vertical position
of the text:
An alternative to these approaches is the usage of the
framed environment (you will need to include the framed The valid values are b (bottom), t (top), and c (center). If
package to use it). This provides an easy way to box a you specify a length in the rst (required) argument, the
paragraph within a document: text will be wrapped:
3.4.11 fancybox
The fancybox package provides additional boxes.
\doublebox
\ovalbox
\shadowbox
3.5.1 Rules
The \rule command in normal use produces a simple
black box:
The parameter thickness determines the height, whereas
width determines the width of the produced rule. With
the optional parameter raise, you can optionally raise or
lower the produced rule above or below the baseline.
Here is an example (the thin lines are located at the base-
line):
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 dened as
Technical Texts
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 dierently 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
82
4.1. MATHEMATICS 83
only works with AMSMATH package). It is also possi- To use operators that are not pre-dened, 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
4.1.2 Symbols Powers and indices are equivalent to superscripts and sub-
scripts in normal text mode. The caret (^; also known as
Mathematics has many symbols! One of the most dif- the circumex accent) character is used to raise some-
cult aspects of learning LaTeX is remembering how to thing, and the underscore (_) is for lowering. If more
produce symbols. There is of course a set of symbols that than one expression is raised or lowered, they should be
can be accessed directly from the keyboard: grouped using curly braces ({ and }).
+-=! /()[]<>|': For powers with more than one digit, surround the power
with {}.
Beyond those listed above, distinct commands must be
issued in order to display the desired symbols. There are An underscore (_) can be used with a vertical bar ( | ) to
many examples such as Greek letters, set and relations denote evaluation using subscript notation in mathemat-
symbols, arrows, binary operators, etc. ics:
For example:
Fortunately, theres a tool that can greatly simplify the
search for the command for a specic symbol. Look for 4.1.6 Fractions and Binomials
Detexify in the external links section below. Another
option would be to look in the The Comprehensive La- A fraction is created using the
TeX Symbol List in the external links section below. \frac{numerator}{denominator} command. (for
those who need their memories refreshed, thats the
top and bottom respectively!). Likewise, the binomial
4.1.3 Greek letters coecient (aka the Choose function) may be written
using the \binom command[3] :
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 rst
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 rst letter is uppercase (and only the rst 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 coecient.
provided by LaTeX (e.g. uppercase Alpha and Beta are
just A and B respectively). Lowercase epsilon, theta, For relatively simple fractions, especially within the text,
kappa, phi, pi, rho, and sigma are provided in two dier- it may be more aesthetically pleasing to use powers and
ent versions. The alternate, or variant, version is created indices:
by adding var before the name of the letter: If this looks a little loose (overspaced), a tightened ver-
Scroll down to #List of Mathematical Symbols for a com- sion can be dened by inserting some negative space
plete list of Greek symbols. If you use them throughout the document, usage of xfrac
package is recommended. This package provides \sfrac
command to create slanted fractions. Usage:
4.1.4 Operators
If fractions are used as an exponent curly braces have to
be used around the \sfrac command:
An operator is a function that is written as a word: e.g.
trigonometric functions (sin, cos, tan), logarithms and ex- $x^\frac{1}{2}$ % no error $x^\sfrac{1}{2}$ % error
ponentials (log, exp), limits (lim), as well as trace and de- $x^{\sfrac{1}{2}}$ % no error
terminant (tr, det). LaTeX has many of these dened as In some cases, using the package alone will result in er-
commands: rors about certain font shapes not being available. In that
For certain operators such as limits, the subscript is case, the lmodern and x-cm packages need to be added
placed underneath the operator: as well.
For the modular operator there are two commands: Alternatively, the nicefrac package provides the \nicefrac
\bmod and \pmod: command, whose usage is similar to \sfrac.
84 CHAPTER 4. TECHNICAL TEXTS
Continued fractions For more integral symbols, including those not included
by default in the Computer Modern font, try the esint
Continued fractions should be written using \cfrac package.
command[3] : The \substack command[3] allows the use of \\ to write
the limits over multiple lines:
Multiplication of two numbers If you want the limits of an integral to be specied above
and below the symbol (like the sum), use the \limits com-
To make multiplication visually similar to a fraction, a mand:
nested array can be used, for example multiplication of However if you want this to apply to ALL integrals, it is
numbers written one below the other. preferable to specify the intlimits option when loading the
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
expression. It accepts an optional argument specied in For bigger integrals, you
[4]
may use personal declarations,
square brackets ([ and ]) to change magnitude: or the bigints package .
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 dicult to read. To x 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 o 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
Typesetting intervals line containing it, use smallmatrix environment:
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 x 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:
Similarly, there exists also a minus-plus sign:
We can now format text; what about formatting mathe-
matical expressions? There are a set of formatting com-
mands very similar to the font formatting ones just used,
4.1.15 Controlling horizontal spacing
except that they are specically aimed at text in math
mode (requires amsfonts)
LaTeX is obviously pretty good at typesetting mathsit
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 unaected. 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 ne-
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 oset 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 dened 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 x 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 ne 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 indenite 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 prexed to it. In this doesn't respect the white-space left in the code to signify
instance, you want the sign to appear close to the appro- that the y and the dx are independent entities. Instead, it
priate element to show their association. If you put a + or lumps them altogether. A \quad would clearly be overkill
a with nothing before it but you want it to be handled in this situationwhat is needed are some small spaces to
like a binary operator you can add an invisible character be utilized in this type of instance, and thats what LaTeX
4.1. MATHEMATICS 87
*Not predened in LATEX 2. Use one of the pack- 4.2 Advanced Mathematics
ages latexsym, amsfonts, amssymb, txfonts, pxfonts, or
wasysym This page outlines some more advanced uses of math-
If LaTeX does not include a command for the mathemati- ematics markup using LaTeX. In particular it makes
cal operator you want to use, for example \cis (cosine plus heavy use of the AMS-LaTeX packages supplied by the
i times sine), add to your preamble: American Mathematical Society.
\DeclareMathOperator\cis{cis}
You can then use \cis in the document just like \cos or
4.2.1 Equation numbering
any other mathematical operator.
The equation environment automatically numbers your
equation:
4.1.19 Summary
You can also use the \label and \ref (or \eqref from
As you begin to see, typesetting math can be tricky at the amsmath package) commands to label and reference
times. However, because LaTeX provides so much con- equations, respectively. For equation number 1, \ref re-
trol, you can get professional quality mathematics type- sults in 1 and \eqref results in (1) :
setting with relatively little eort (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 suciently.
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
\numberwithin{equation}{subsection} command in the
[2] http://www.ctan.org/tex-archive/macros/latex/contrib/
preamble will result in the equation number in the above
mathtools/mathtools.pdf
example being rendered as follows: (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-
within{equation}{subsection}, use:
[5] requires the mathtools package
in the preamble of the document.
Note: Although it may look like the \renewcommand
4.1.21 Further reading works by itself, it won't reset the equation number with
each new section. It must be used together with manual
meta:Help:Displaying a formula: Wikimedia uses a equation number resetting after each new section begin-
subset of LaTeX commands. ning, or with the much cleaner \numberwithin.
detexify: applet for looking up LaTeX symbols by To number subordinate equations in a numbered equation
drawing them environment, place the part of document containing them
in a subequations environment:
amsmath documentation Referencing subordinate equations can be done using
either of two methods: adding a label after the \be-
LaTeX - The Student Room gin{subequations} command, which will reference the
main equation (1.1 above), or adding a label at the end
The Comprehensive LaTeX Symbol List of each line, before the \\ command, which will refer-
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. ADVANCED MATHEMATICS 89
4.2.2 Vertically aligning displayed mathe- align* suppresses numbering. To force numbering on a
matics specic line, use the \tag{...} command before the line
break.
A problem often encountered with displayed environ- align is similar, but automatically numbers each line like
ments (displaymath and equation) is the lack of any abil- the equation environment. Individual lines may be re-
ity to span multiple lines. While it is possible to dene ferred to by placing a \label{...} before the line break.
lines individually, these will not be aligned. The \nonumber or \notag command can be used to sup-
press the number for a given line:
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'Hpitals rule: More complicated alignments are possible, with addi-
tional &'s on a single line specifying multiple equation
It is convenient to dene a new operator that will set the
columns, each of which is aligned. The following exam-
equals sign with H and the provided fraction:
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 dierent 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 dierent: the optional argument (using [ and
]) species the subscript, and the mandatory argument
(using { and }) species 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 the mathtools tions:
package:
and for harpoons: The cases environment
The align and align* environments, available through the LaTeX will then take care of dening and or aligning the
amsmath package, are used for arranging equations of columns.
multiple lines. As with matrices and tables, \\ species Within cases, text style math is used with results such as:
a line break, and & is used to indicate the point at which {
the lines should be aligned. x dx
a=
b2
The align* environment is used like the displaymath or
equation* environment: Display style may be used instead, by using the dcases
[2]
Note that the align environment must not be nested inside environment from mathtools:
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]
90 CHAPTER 4. TECHNICAL TEXTS
4.2.4 Page breaks in math environments This denes a new command which may be referred to in
the body:
To suggest that LaTeX insert a page break inside an ams-
math environment, you may use the \displaybreak com- 4.2.7 Advanced formatting
mand before the line break. Just as with \pagebreak,
\displaybreak can take an optional argument between 0 Limits
and 4 denoting the level of desirability of a page break.
Whereas 0 means it is permissible to break here, 4 There are defaults for placement of subscripts and super-
forces a break. No argument means the same as 4. scripts. For example, limits for the lim operator are usu-
Alternatively, you may enable automatic page breaks in ally placed below the symbol:
math environments with \allowdisplaybreaks. It too can To override this behavior, use the \nolimits operator:
have an optional argument denoting the priority of page
breaks in equations. Similarly, 1 means allow page A lim in running text (inside $...$) will have its limits
breaks but avoid them and 4 means break whenever you placed on the side, so that additional leading won't be re-
want. You can prohibit a page break after a given line quired. To override this behavior, use the \limits com-
using \\*. mand.
LaTeX will insert a page break into a long equation if it Similarly one can put subscripts under a symbol that usu-
has additional text added using \intertext{} without any ally has them on the side:
additional commands. Limits below and under:
Specic usage may look like this: To change the default placement of summation-type sym-
Page breaks before display maths (of all various forms) bols to the side for every case, add the nosumlimits option
are controlled by \predisplaypenalty. Its default 10000 to the amsmath package. To change the placement for in-
means never break immediately before a display. Knuth tegral symbols, add intlimits to the options. nonamelimits
(TeXbook chapter 19) explains this as a printers tradition can be used to change the default for named operators like
not to have a displayed equation at the start of a page. It det, min, lim, etc.
can be relaxed with To produce one-sided limits, use \underset as follows:
Sometimes an equation might look best kept together pre-
ceding text by a higher penalty, for example a single-line Subscripts and superscripts
paragraph about a single-line equation, especially at the
end of a section. You can place symbols in subscript or superscript (in
summation style symbols) with \nolimits:
4.2.5 Boxed Equations Its impossible to mix them with typical usage of such
symbols:
For a single equation or alignment building block, with To add both a prime and a limit to a symbol, one might
the tag outside the box, use \boxed{}: use the \sideset command:
If you want the entire line or several equations to be It is very exible: for example, to put letters in each cor-
boxed, use a minipage inside an \fbox{}: ner of the symbol use this command:
4.3. THEOREMS 91
If you wish to place them on the corners of an arbitrary the text size, etc. The values you input are assumed to be
symbol, you should use \fourIdx from the fouridx pack- point (pt) size.
age. Note that the changes only take place if the value in the
But a simple grouping can also solve the problem: rst argument matches the current document text size. It
is therefore common to see a set of declarations in the
since a math operator can be used with limits or no limits.
If you want to change its state, simply group it. You can preamble, in the event of the main font being changed.
E.g.,
make it another math operator if you want, and then you
can have limits and then limits again.
4.2.10 Forcing \displaystyle for all math in
Multiline subscripts a document
put it in the preamble. The rst argument is the name you It just adds Proof in italics at the beginning of the text
will use to reference it, the second argument is the output given as argument and a white square (Q.E.D. symbol,
LaTeX will print whenever you use it. For example: also known as a tombstone) at the end of it. If you are
\newtheorem{mydef}{Denition} writing in another language than English, just use babel
with the right argument and the word Proof printed in
the output will be translated accordingly; anyway, in the
will dene the mydef environment; if you use it like this: source the name of the environment remains proof.
\begin{mydef} Here is a new denition \end{mydef} If you would like to manually name the proof, include the
name in square brackets:
It will look like this: \begin{proof}[Proof of important theorem] Here is my
important proof \end{proof}
Denition 3 Here is a new denition
If the last line of the proof is displayed math then the
with line breaks separating it from the rest of the text. Q.E.D. symbol will appear on a subsequent empty line.
To put the Q.E.D. symbol at the end of the last line, use
the \qedhere command:
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
section of a document. In this case, specify the theorem The method above does not work with the deprecated en-
as follows: vironment eqnarray*. Use align* instead.
(Any arguments that are left blank will assume their de- 4.4.1 Basic Usage
fault value). Here is an example headspec:
\thmname{#1}\thmnumber{ #2}:\thmnote{ #3} The primary command used in this package is \chem-
g{}:
renders:
For more examples, see meta:Help:Displaying a for-
mula#Chemistry 2.
A few things here are automatically typeset; The 2 in
\ce{H2O} is automatically subscripted without requiring
additional commands. The amount of the species pre-
cedes the formula. 1/2 and other fractional amounts are
automatically typeset as in \ce{1/2H2O}. The charge in
\ce{AgCl2-} is automatically superscripted. If the charge
is neither 1 or 1, a ^ will superscript it, as in \ce{AgCl2-
}. The phase is not automatically subscripted and needs Corticosterone as rendered by XyMTeX
to be enclosed in parenthesis preceded with a _ as in
\ce{H2_{(aq)}.
Since February 2016, the mhchem package is also avail-
able in TeX in MediaWiki sites like Wikipedia, using the 4.5 Algorithms
tag <ce>...</ce>.
LaTeX has several packages for typesetting algorithms in
form of "pseudocode". They provide stylistic enhance-
Package chemformula ments over a uniform style (i.e., all in typewriter font) so
that constructs such as loops or conditionals are visually
chemformula is a package from a much bigger chem- separated from other text. The pseudocode is usually put
istry bundel used to typeset chemical formulae and equa- in an algorithm environment. For typesetting real code,
tions. As well as typeset basic 2D chemical structures. written in a real programming language, consider the list-
The package uses a slightly dierent syntax compared to ings package described in Source Code Listings.
mhchem. Package chemmacros will be of great interest
to people doing chemistry related work.
To use this package, add the following to your preamble: 4.5.1 Typesetting
\usepackage{chemformula} There are four notable packages algorithmic, algorithm2e,
algorithmicx, and program,
Chemical species are included using the \ch command.
For example
Typesetting using the algorithmic package
\ch{3 H2O} \\ \ch{1/2 H2O} \\ \ch{AgCl2-} \\
\ch{H2_{(aq)}} \\ The algorithmic package uses a dierent set of commands
than the algorithmicx package. This is not compatible
96 CHAPTER 4. TECHNICAL TEXTS
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}
Algorithm numbering
Loops with multiple exits:
\begin{program} \DO \DO \IF \B1 \THEN \EXIT \FI; The default numbering system for the algorithm package
\S1; \IF \B2 \THEN \EXIT(2) \FI \OD; \IF \B1 \THEN is to number algorithms sequentially. This is often not de-
\EXIT \FI \OD \end{program} sirable, particularly in large documents where numbering
according to chapter is more appropriate. The numbering
of algorithms can be inuenced by providing the name of
A Reverse Engineering Example.
the document component within which numbering should
Heres the original program: be recommenced. The legal values for this option are:
\begin{program} \VAR \seq{m := 0, p := 0, |last| := `` part, chapter, section, subsection, subsubsection or noth-
''}; \ACTIONS |prog|: |prog| \ACTIONEQ % \seq{|line| ing (default). For example:
:= `` '', m := 0, i := 1}; \CALL |inhere| \ENDACTION l \usepackage[chapter]{algorithm}
\ACTIONEQ % i := i+1; \IF (i=(n+1)) \THEN \CALL
|alldone| \FI ; m := 1; \IF |item|[i] \neq |last| \THEN
|write|(|line|); |line| := `` ''; m := 0; \CALL |inhere| \FI ;
\CALL |more| \ENDACTION |inhere| \ACTIONEQ % List of algorithms
p := |number|[i]; |line| := |item|[i]; |line| := |line| \concat ``
'' \concat p; \CALL |more| \ENDACTION |more| \AC- When you use gures or tables, you can add a list of them
TIONEQ % \IF (m=1) \THEN p := |number|[i]; |line| := close to the table of contents; the algorithm package pro-
vides a similar command. Just put
4.6. SOURCE CODE LISTINGS 99
\listofalgorithms just want to write code within your document the package
provides the lstlisting environment:
anywhere in the document, and LaTeX will print a list of Another possibility, that is very useful if you created a
the algorithm environments in the document with the program on several les and you are still editing it, is to
corresponding page and the caption. import the code from the source itself. This way, if you
modify the source, you just have to recompile the LaTeX
code and your document will be updated. The command
An example from the manual is:
This is an example taken from the manual (ocial man- in the example there is a Python source, but it doesn't
ual, p.14) matter: you can include any le but you have to write
the full le name. It will be considered plain text and it
\begin{algorithm} % enter the algorithm environment will be highlighted according to your settings, that means
\caption{Calculate $y = x^n$} % give the algorithm a it doesn't recognize the programming language by itself.
caption \label{alg1} % and a label for \ref{} commands You can specify the language while including the le with
later in the document \begin{algorithmic} % enter the the following command:
algorithmic environment \REQUIRE $n \geq 0 \vee x
\neq 0$ \ENSURE $y = x^n$ \STATE $y \Leftarrow You can also specify a scope for the le.
1$ \IF{$n < 0$} \STATE $X \Leftarrow 1 / x$ \STATE This comes in handy if you are sure that the le will not
$N \Leftarrow -n$ \ELSE \STATE $X \Leftarrow x$ change (at least before the specied lines). You may also
\STATE $N \Leftarrow n$ \ENDIF \WHILE{$N \neq omit the rstline or lastline parameter: it means every-
0$} \IF{$N$ is even} \STATE $X \Leftarrow X \times thing up to or starting from this point.
X$ \STATE $N \Leftarrow N / 2$ \ELSE[$N$ is odd]
\STATE $y \Leftarrow y \times X$ \STATE $N \Left- This is a basic example for some Pascal code:
arrow N - 1$ \ENDIF \ENDWHILE \end{algorithmic} \documentclass{article} \usepackage{listings} %
\end{algorithm} Include the listings-package \begin{document} \lst-
set{language=Pascal} % Set your language (you can
change the language for each code-block optionally)
The ocial manual is located at http://mirrors.ctan. \begin{lstlisting}[frame=single] % Start your code-
org/macros/latex/contrib/algorithms/algorithms. block for i:=maxint to 0 do begin { do nothing } end;
pdf Write('Case insensitive '); Write('Pascal keywords.');
\end{lstlisting} \end{document}
4.5.3 References
[1]
[2] http://tex.stackexchange.com/questions/70181/
revtex4-1-and-algorithm2e-indentation-clash
sh, SHELXL, Simula4 , SQL, tcl4 , TeX4 , VBScript, Ver- keyword style language=Octave, % the language of the
ilog, VHDL4 , VRML4 , XML, XSLT. code morekeywords={*,...}, % if you want to add more
For some of them, several dialects are supported. For keywords to the set numbers=left, % where to put the
more information, refer to the documentation that comes line-numbers; possible values are (none, left, right) num-
with the package, it should be within your distribution bersep=5pt, % how far the line-numbers are from the
under the name listings-*.dvi. code numberstyle=\tiny\color{mygray}, % the style that
is used for the line-numbers rulecolor=\color{black}, %
if not set, the frame-color may be changed on line-breaks
Notes within not-black text (e.g. comments (green here))
showspaces=false, % show spaces everywhere adding
1. It supports Mathematica code only if you are typing particular underscores; it overrides 'showstringspaces
in plain text format. You can't include *.NB les showstringspaces=false, % underline spaces within
\lstinputlisting{...} as you could with any other pro- strings only showtabs=false, % show tabs within strings
gramming language, but Mathematica can export in adding particular underscores stepnumber=2, % the
a pretty-formatted LaTeX source. step between two line-numbers. If its 1, each line will
be numbered stringstyle=\color{mymauve}, % string
2. Specication of the dialect is manda-
literal style tabsize=2, % sets default tabsize to 2 spaces
tory for these languages (e.g. lan-
title=\lstname % show the lename of les included with
guage={[x86masm]Assembler}).
\lstinputlisting; also try caption instead of title }
3. Modelica is supported via the dtsyntax package
available here.
escapeinside
4. For these languages, multiple dialects are supported.
C, for example, has ANSI, Handel, Objective and
The escapeinside line needs an explanation. The option
Sharp. See p. 12 of the listings manual for an
escapeinside={A}{B} will dene delimiters for escaping
overview.
into LaTeX code, i.e. all the code between the string A
5. Dened as a dialect of another language 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-
Settings ument unless they start with %*, in which case they are
read as LaTeX (with all LaTeX commands fullled) un-
You can modify several parameters that will aect how til they're closed with another *). If you add the above
the code is shown. You can put the following code any- paragraph, the following can be used to alter the settings
where in the document (it doesn't matter whether before within the code:
or after \begin{document}), change it according to your
needs. The meaning is explained next to any line. There are many more options, check the ocial docu-
mentation.
\usepackage{listings} \usepackage{color} \de-
necolor{mygreen}{rgb}{0,0.6,0} \dene-
color{mygray}{rgb}{0.5,0.5,0.5} \dene- Style denition
color{mymauve}{rgb}{0.58,0,0.82} \lstset{ %
backgroundcolor=\color{white}, % choose the back- The package lets you dene styles, i.e. proles specifying
ground color; you must add \usepackage{color} or a set of settings.
\usepackage{xcolor}; should come as last argument
basicstyle=\footnotesize, % the size of the fonts Example
that are used for the code breakatwhitespace=false, \lstdenestyle{customc}{ belowcaption-
% sets if automatic breaks should only happen at skip=1\baselineskip, breaklines=true, frame=L,
whitespace breaklines=true, % sets automatic line xleftmargin=\parindent, language=C, show-
breaking captionpos=b, % sets the caption-position stringspaces=false, basicstyle=\footnotesize\ttfamily,
to bottom commentstyle=\color{mygreen}, % com- keywordstyle=\bfseries\color{green!40!black}, com-
ment style deletekeywords={...}, % if you want to mentstyle=\itshape\color{purple!40!black}, identi-
delete keywords from the given language escapein- erstyle=\color{blue}, stringstyle=\color{orange},
side={\%*}{*)}, % if you want to add LaTeX within } \lstdenestyle{customasm}{ belowcap-
your code extendedchars=true, % lets you use non- tionskip=1\baselineskip, frame=L, xleftmar-
ASCII characters; for 8-bits encodings only, does gin=\parindent, language=[x86masm]Assembler,
not work with UTF-8 frame=single, % adds a frame basicstyle=\footnotesize\ttfamily, com-
around the code keepspaces=true, % keeps spaces in mentstyle=\itshape\color{purple!40!black}, } \lst-
text, useful for keeping indentation of code (possibly set{escapechar=@,style=customc}
needs columns=exible) keywordstyle=\color{blue}, %
4.6. SOURCE CODE LISTINGS 101
In our example, we only set two options globally: the de- {}{{\'o}}1 {}{{\'u}}1 {}{{\'A}}1 {}{{\'E}}1
fault style and the escape character. Usage: {}{{\'I}}1 {}{{\'O}}1 {}{{\'U}}1 {}{{\`a}}1
\begin{lstlisting} #include <stdio.h> #dene N 10 /* {}{{\`e}}1 {}{{\`i}}1 {}{{\`o}}1 {}{{\`u}}1
Block * comment */ int main() { int i; // Line com- {}{{\`A}}1 {}{{\'E}}1 {}{{\`I}}1 {}{{\`O}}1
ment. puts(Hello world!"); for (i = 0; i < N; i++) { {}{{\`U}}1 {}{{\"a}}1 {}{{\"e}}1 {}{{\"i}}1
puts(LaTeX is also great for programmers!"); } return {}{{\"o}}1 {}{{\"u}}1 {}{{\"A}}1 {}{{\"E}}1
0; } \end{lstlisting} \lstinputlisting[caption=Scheduler, {}{{\"I}}1 {}{{\"O}}1 {}{{\"U}}1 {}{{\^a}}1
style=customc]{hello.c} {}{{\^e}}1 {}{{\^i}}1 {}{{\^o}}1 {}{{\^u}}1
{}{{\^A}}1 {}{{\^E}}1 {}{{\^I}}1 {}{{\^O}}1
{}{{\^U}}1 {}{{\oe}}1 {}{{\OE}}1
The C part will print as {}{{\ae}}1 {}{{\AE}}1 {}{{\ss}}1
{}{{\H{u}}}1 {}{{\H{U}}}1 {}{{\H{o}}}1
{}{{\H{O}}}1 {}{{\c c}}1 {}{{\c C}}1
{}{{\o}}1 {}{{\r a}}1 {}{{\r A}}1 {}{{\euro}}1
{}{{\pounds}}1 {}{{\guillemotleft}}1 {}{{\guille-
motright}}1 {}{{\~n}}1 {}{{\~N}}1 {}{{?`}}1 }
Customizing captions
You can have fancy captions (or titles) for your listings
Automating le inclusion
using the caption package. Here is an example for listings.
If you have a bunch of source les you want to include, \usepackage{caption} \usepackage{listings} \Declare-
you may nd yourself doing the same thing over and over CaptionFont{white}{ \color{white} } \DeclareCaption-
again. This is where macros show their real power. Format{listing}{ \colorbox[cmyk]{0.43, 0.35, 0.35,0.01
}{ \parbox{\textwidth}{\hspace{15pt}#1#2#3} }
\newcommand{\includecode}[2][c]{\lstinputlisting[caption=#2,
} \captionsetup[lstlisting]{ format=listing, label-
escapechar=, style=custom#1]{#2}<!---->} % ... \in-
font=white, textfont=white, singlelinecheck=false,
cludecode{sched.c} \includecode[asm]{sched.s} % ...
margin=0pt, font={bf,footnotesize} } % ... \lstinputlist-
\lstlistoistings
ing[caption=My caption]{sourcele.lang}
alternate method for example numbering. This package )tree is always preceded by a ., leaf nodes are simply ex-
uses two main commands, \enumsentence and \eenum- pressed by their labels.
sentence. The former is used for singleton examples, For example, the following code
while the latter command is used for nested examples.
\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]
\enumsentence{This is an example.}
produces this syntactic tree as output:
produces:
Note that the spaces before the closing brackets are
mandatory.
By default, qtree centers syntactic trees on the page. This
behaviour can be turned o by either specifying the be-
haviour when loading the package
\usepackage[nocenter]{qtree} % do not center trees
Full documentation can be found here.
104 CHAPTER 4. TECHNICAL TEXTS
or via the command For setting the style of trees, tikz-qtree provides the
\qtreecenterfalse % do not center trees from here on \tikzset command. For example, to make a tree grow
from left to right instead of from top to bottom, use the
following code:
anywhere in the document. The eect of the latter can be
\tikzset{grow'=right} % make trees grow from left
undone by using the command
to right \tikzset{every tree node/.style={anchor=base
\qtreecentertrue % center trees from here on west}} % allign nodes of the tree to the left (west) \Tree
[.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]
IMPORTANT: If you use gb4e package, let it be the last The above code changes the default orientation for all
\usepackage call in the documents preamble. Otherwise
you may get exceeded parameter stack size error.
results in:
A dependency tree created using TikZ A dependency tree above running text created using xytree
The code for a similar tree using xyling might look like:
% In the preamble: \usepackage{xyling} % In the Dependency Trees using TikZ-dependency The
document: \Tree{ & \K{is}\B{dl}\B{drr} \\ \K{this} package provides high level commands to design and style
&&& \K{tree}\B{dll}\B{dl}\B{dr} \\ & \K{an} & dependency graphs. To draw a graph, you only need to
\K{example} && \K{.} } \medskip \textit{This is an create a dependency environment, write the text of the
example tree.} sentence within the deptext environment and use depedge
commands to draw the edges. Global and local optional
which gives you a drawing like this: parameters can be used to style and ne tune the looks of
the graph, as shown in the following example:
% In the preamble: \usepackage{tikz-dependency}
% In the document: \begin{dependency}[theme
= simple] \begin{deptext}[column sep=1em]
A \& hearing \& is \& scheduled \& on \&
the \& issue \& today \& . \\ \end{deptext}
\deproot{3}{ROOT} \depedge{2}{1}{ATT}
\depedge[edge start x oset=6pt]{2}{5}{ATT}
\depedge{3}{2}{SBJ} \depedge{3}{9}{PU}
\depedge{3}{4}{VC} \depedge{4}{8}{TMP}
\depedge{5}{7}{PC} \depedge[arc an-
gle=50]{7}{6}{ATT} \end{dependency}
To create a glossed example, use the normal exe environ- The IPA format works by translating ASCII characters
ment. But after the \ex tag, introduce the example and its into corresponding IPA symbols. Lower case letters are
gloss using \gll and the translation after it with \trans tag. rendered as usual,
\begin{exe} \ex \gll \\ cat.NOM however capital letters are rendered dierently.
eat.3.SG.PRS sour-cream.ACC\\ \trans `The cat eats Punctuation marks that are normally used in LaTeX are
sour cream' \end{exe} also rendered faithfully in the IPA environment.
Numerals and @ also have variants in the IPA environ-
The code will produce the following output: 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
ocial TIPA Manual[4] .
The \; macro preceding a capital letter produces a small
caps version of the letter.
Vertically aligned glosses are separated by spaces, so if The \: macro produces retroex symbols.
its necessary to include a space in part the gloss, simply
enclose the connected parts inside braces. The \! macro produces implosive symbols and the bilabial
click.
\begin{exe} \ex \gll Pekka pel\"astyi karhusta.\\ Pekka
{became afraid} bear.ELA\\ \trans `Pekka became afraid
because of the/a bear.' \end{exe} XeLaTeX
Special Pages
where key is the index entry and does not appear in the makeindex -s [style le] lename
nal layout. You enter the index commands at the points If you use a GUI for compiling latex and index les, 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 guration 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 dierent pages will add those target pages to the an index style le named simpleidx.ist
same index entry.
To show the index within the document, merely use the
command Texify/PDFTexify: OptionsExecution
ModesAccessoriesPDFTeXify, 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: OptionsExecution
quite useful for proofreading a document and verifying ModesAccessoriesMakeIndex, add to com-
the index. mand line: -s simpleidx.ist
107
108 CHAPTER 5. SPECIAL PAGES
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 lename.nlo -s nomencl.ist -o lename.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 . However, this package does not work.
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 rst argument
This will appear in the index as bulldog, 3, 10 to every command.
If you use texindy in place of makeindex, the classied
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.
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-
5.2. GLOSSARY 109
iers, 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 le 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 redene the MakeIndex tool in
For example, one does not need to write: Settings Congure Kile... Tools Build, or dene
new tool and redene other tools to use it (for example by
to get the Lin entry after LAN and before LZA, instead,
adding it to QuickBuild).
its enough to write
The xindy denition should look similar to this:
But what is much more important, it can properly sort
index les 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 le: <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
le 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 its 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 le. LaTeX doesn't like Then dene any number of \newglossaryentry and
if part of the le is in UTF-8 and part is in ISO-8859- \newacronym glossary and acronym entries in your
2. The obvious solution (adding -C utf8) doesn't work, preamble (recommended) or before rst use in your doc-
texindy stops with ument proper. Finally add a \printglossaries call to locate
the glossaries list within your document structure. Then
ERROR: Could not nd le tex/inputenc/utf8.xdy pepper your writing with \gls{mylabel} macros (and sim-
error. The x this, you have to load the deniton style for ilar) to simultaneously insert your predened 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 pdatex.
In the end we have to run such command:
texindy -L polish -M lang/polish/utf8 lename.idx
5.2.2 Using glossaries
Additional way to x this problem is use iconv to create
utf8.xdy from latin2.xdy To use the glossaries package, you have to load it explic-
itly:
110 CHAPTER 5. SPECIAL PAGES
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 dened 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, gures, 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-
Dening symbols
less you load the glossaries package after the hyperref
package.
Dened entries can also be symbols:
In addition, users who wish to make use of makeglos-
You can also dene 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 dened symbols.
forms. That said, makeglossaries simply provides a con-
venient interface to makeindex and xindy and is not es-
Dening acronyms
sential.
To dene a new acronym you use the \newacronym
5.2.3 Dening glossary entries macro:
where <label> is the unique label identifying the
To use an entry from a glossary you rst need to dene it. acronym, <abbrv> is the abbreviated form of the
There are few ways to dene an entry depending on what acronym and <full> is the expanded text. For example:
you dene and how it is going to be used.
Dened acronyms can be put in separate list if you use
Note that a dened 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 dened terms
When you have dened a term, you can use it in a docu-
5.2.4 Dening terms ment. There are many dierent commands used to refer
to glossary terms.
To dene 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 dene an entry.
example, you have glossary entries dened as those above,
For example, to dene a computer entry: you might use it in this way:
The above example denes 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 dene 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 dened 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 dened, putting it inside symbol class, the rst character converted to upper case.
before words beginning with naa. Therefore its needed This command prints the plural form with rst 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).
5.3. DISPLAYING THE GLOSSARY 111
This command prints what ever is dened 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 dened in \newglos- then, dene 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 dierently than normal glossary custom name or translated to a dierent language. Add
terms. On rst use the \gls command will display "<full> the option title to \printglossary to specify the glossarys
(<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 rst use of an acronym, use the command:
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
Dual entries with reference to a glossary 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,
dene the acronym with a reference to the glossary entry 1. build your LaTeX document this will also gener-
like this: ate the les 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 (modied and which will also run xindy or makeindex if these
from example in the ocial docs): are specied in your document le
112 CHAPTER 5. SPECIAL PAGES
[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 nd the aux le. 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 preamble 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 dene glossaries in a le, 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
5.5. BIBLIOGRAPHY MANAGEMENT 113
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- xed with the \bibitem{cite_key} command. The cite_key
nately, LaTeX has a variety of features that make dealing should be a unique identier 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 exible solution is achieved thanks to an auxiliary though not a comma). I often use the surname of the rst
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 congurable 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, at-le 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 le. This is often more convenient on dierent 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 les as 5.5.2 Citations
one wishes, so there can be a le containing sources con-
cerning topic A (a.bib) and another concerning topic B To actually cite a given document is very easy. Go to
(b.bib). When writing about topic AB, both of these les the point where you want the citation to appear, and use
can be linked into the document (perhaps in addition to the following: \cite{cite_key}, where the cite_key is that
sources ab.bib specic to topic AB). 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 Instead of WYSIWYG editors, typesetting systems like
case you should consider using the basic and simple bib- \TeX{} or \LaTeX{} \cite{lamport94} can be used.
liography support that is embedded within LaTeX.
LaTeX provides an environment called thebibliography
that you have to use where you want the bibliography;
Referring more specically
that usually means at the very end of your document, just
before the \end{document} command. Here is a practical
If you want to refer to a certain page, gure or theorem in
example:
a text book, you can use the arguments to the \cite com-
\begin{thebibliography}{9} \bibitem{lamport94} Leslie mand:
Lamport, \emph{\LaTeX: a document preparation
\cite[chapter, p.~215]{citation01}
system}, Addison Wesley, Massachusetts, 2nd edition,
1994. \end{thebibliography}
The argument, p. 215, will show up inside the same
brackets. Note the tilde in [p.~215], which replaces the
OK, so what is going on here? The rst thing to notice is
end-of-sentence spacing with a non-breakable inter-word
the establishment of the environment. thebibliography is
space. This non-breakable inter-word space is inserted
a keyword that LaTeX recognizes as everything between
because the end-of-sentence spacing would be too wide,
the begin and end tags as being data for the bibliogra-
and p. should not be separated from the page number.
phy. The mandatory argument, which I supplied after
the begin statement, is telling LaTeX how wide the item
label will be when printed. Note however, that the num- Multiple citations
ber itself is not the parameter, but the number of digits is.
Therefore, I am eectively telling LaTeX that I will only When a sequence of multiple citations are needed, you
need reference labels of one character in length, which ul- should use a single \cite{} command. The citations are
timately means no more than nine references in total. If then separated by commas. Heres an example:
114 CHAPTER 5. SPECIAL PAGES
\cite{citation01,citation02,citation03}
alpha
Bibliography styles
The nal 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 rst
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 identier 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 authors 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 elds and data for that particular reference. The
5. The punctuation to appear between the author and eld 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
eld 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 eld, causing an error in the parsing of
table (right). the reference. Using \usepackage[utf8]{inputenc} in the
preamble to the .tex source le can get round this, as the
So as you can see, this package is quite exible, especially accented characters can just be stored in the .bib le with-
as you can easily switch between dierent 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 le, avoiding the
Natbib manual, its 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 elds each type has available (and which ones
rial, I want to do a little better than this method, as its are required or optional, etc). So, look at this entry type
not as exible as it could be. I will concentrate on using reference and also this eld reference for descriptions of
BibTeX. all the elds. It may be worth bookmarking or printing
A BibTeX database is stored as a .bib le. It is a plain text these pages so that they are easily at hand when you need
le, and so can be viewed and edited easily. The structure them. Much of the information contained therein is re-
of the le is also quite simple. An example of a BibTeX peated in the following table for your convenience.
entry: + Required elds, O Optional elds
@article{greenwade93, author = George D. Green-
wade, title = The {C}omprehensive {T}ex {A}rchive
{N}etwork ({CTAN})", year = 1993, journal =
TUGBoat, volume = 14, number = 3, pages =
116 CHAPTER 5. SPECIAL PAGES
Required elds: author, title, year, school. (see REVTEX Authors guide)
Optional elds: address, month, keywords,
note. Preserving case of letters
@phdthesis{Xphdthesis, author = "", title = "", school = In the event that BibTeX has been set by the chosen style
"", %address = "", year = "", %month = "", %keywords not to preserve all capitalization within titles, problems
= "", %note = "", } can occur, especially if you are referring to proper nouns,
or acronyms. To tell BibTeX to keep them, use the good
118 CHAPTER 5. SPECIAL PAGES
old curly braces around the letter in question, (or letters, @misc{website:fermentas-lambda, author = Fermentas
if its an acronym) and all will be well! It is even possible Inc., title = Phage Lambda: description \& restriction
that lower-case letters may need to be preserved - for ex- map, month = November, year = 2008, url =
ample if a chemical formula is used in a style that sets a "http://www.fermentas.com/techinfo/nucleicacids/
title in all caps or small caps, or if pH is to be used in a maplambda.htm" },
style that capitalises all rst letters.
The note eld comes in handy if you need to add unstruc-
title = The {LaTeX} Companion, tured information, for example that the corresponding is-
sue of the journal has yet to appear:
However, avoid putting the whole title in curly braces, as
@article{blackholes, author="Rabbert Klein, ti-
it will look odd if a dierent capitalization format is used:
tle="Black Holes and Their Relation to Hiding Eggs,
journal="Theoretical Easter Physics, publisher="Eggs
title = "{The LaTeX Companion}", Ltd., year="2010, note="(to appear)" }
3. :! pdatex %
(Extensions are optional, if you put them note that the
bibtex command takes the AUX le as input.) 4. :! pdatex %
After the rst 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
ned on input line 21. ... LaTeX Warning: There were not in insert mode, and all the appropriate commands are
undened 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 pda-
(or more precisely the corresponding AUX le, however tex, and whether or not it has to run bibtex. This is just
not on the actual .bib le) to then dene 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 Beginners 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 le: latex_source_code.aux The style le: any other platform where you have make. Then you can
plain.bst Database le #1: sample.bib simply create a Makele and use vims make command
or use make in shell. The Makele would then look like
The third step, which is invoking LaTeX for the second
this:
time will see more errors like LaTeX Warning: Label(s)
may have changed. Rerun to get cross-references right.. latex_source_code.pdf: latex_source_code.tex la-
Don't be alarmed, its almost complete. As you can guess, tex_source_code.bib pdatex latex_source_code.tex
all you have to do is follow its instructions, and run LaTeX bibtex latex_source_code.aux pdatex la-
for the third time, and the document will be output as tex_source_code.tex pdatex 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 pdatex instead of latex as follows:
As you can see, there is no eld for URLs. One possibility
1. pdatex latex_source_code.tex is to include Internet addresses in howpublished eld of
@misc or note eld of @techreport, @article, @book:
2. bibtex latex_source_code.aux
howpublished = "\url{http://www.example.com}"
3. pdatex latex_source_code.tex
Note the usage of \url command to ensure proper appear-
4. pdatex latex_source_code.tex ance of URLs.
(Extensions are optional, if you put them note that the Another way is to use special eld url and make bibliog-
bibtex command takes the AUX le as input.) raphy style recognise it.
Note that if you are editing your source in vim and at- url = "http://www.example.com"
tempt to use command mode and the current le shortcut You need to use \usepackage{url} in the rst case or
(%) to process the document like this: \usepackage{hyperref} in the second case.
120 CHAPTER 5. SPECIAL PAGES
Styles provided by Natbib (see below) handle this eld, cally found in the directories that they are installed. Also,
other styles can be modied using urlbst program. Modi- make sure the name of the .bst le you want to use is
cations of three standard styles (plain, abbrv and alpha) reected 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
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:
\usepackage[nottoc,numbib]{tocbibind}
Zotero Zotero is a free and open reference manager
working as a Firefox plugin or standalone applica-
tion, capable of importing and exporting bib les. The tocbibind package can also handle including the List
of Figures, List of Tables and the Table of Contents itself
in the Table of Contents. It has many options for num-
Summary bering, document structure etc. to t almost any scenario.
See the tocbibind CTAN page for detailed documenta-
tion.
Although it can take a little time to get to grips with Bib-
TeX, in the long term, its an ecient way to handle your
references. Its not uncommon to nd .bib les 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 nd BibTeX versions of publications, so its a quick to be in the table of contents, just add the following two
cut-and-paste into your own .bib le, 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- (OR \addcontentsline{toc}{section}{Bibliography} if
ety of free utilities that can load your .bib les, and allow you're writing an article)
you to view them in a more ecient manner, as well as
sort them and check for errors. The rst 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
the Table of Contents (rst option, toc), it will be like the
5.5.4 Bibliography in the table of contents ones created by chapters (second option, chapter), and
the third argument will be printed on the corresponding
If you are writing a book or report, you'll likely insert your line in the Table of Contents; here Bibliography was cho-
bibliography using something like: sen because its the same text the thebibliography environ-
\begin{thebibliography}{99} \bibitem{bib:one_book} ment will automatically write when you use it, but you are
some information \bibitem{bib:one_article} other free to write whatever you like. If you are using separate
information \end{thebibliography} bib le, add these lines between \bibliographystyle and
\bibliography.
Or, if you are using BibTeX, your references will be saved If you use hyperref package, you should also use \phan-
in a .bib le, and your TeX document will include the tomsection command to enable hyperlinking from the ta-
bibliography by these commands: ble of contents to bibliography.
\bibliographystyle{plain} \bibliography{mybibtexle} \clearpage% or cleardoublepage \phantomsection \add-
contentsline{toc}{chapter}{Bibliography}
Both of these examples will create a chapter-like (or
section-like) output showing all your references. But even This trick is particularly useful when you have to insert
though the resulting References looks like a chapter or the bibliography in the Table of Contents, but it can work
section, it will not be handled quite the same: it will not for anything. When LaTeX nds the code above, it will
appear in the Table of Contents. record the info as described and the current page number,
5.5. BIBLIOGRAPHY MANAGEMENT 123
inserting a new line in the Contents page. @article is the same as hypothetic *@inperiodical
and therefore encompasses existing @suppperiodi-
cal
As numbered item If you instead want bibliography
to be numbered section or chapter, you'll likely use this @inbook = @bookinbook = @suppbook
way:
@collection = @reference
\cleardoublepage % This is needed if the book class
is used, to place the anchor in the correct page, % @mvcollection = @mvreference
because the bibliography will start on its own page. %
@incollection = @suppcollection = @inreference
Use \clearpage instead if the document class uses the
oneside argument \renewcommand*{\refname}{} % @online = @electronic = @www
This will dene heading of bibliography to be empty, so
you can... \section{Bibliography} % ...place a normal @report = @techreport
section heading before the bibliography entries. \be-
@thesis = @mastersthesis = @phdthesis
gin{thebibliography}{99} ... \end{thebibliography}
pagination, bookpagination
As we said before, biblatex is widely considered the `suc- The only eld that is always mandatory, is title. All en-
cessor' of BibTeX. Intended as a full replacement for Bib- try types also require either date or year and they specify
TeX, it is more congurable in its output and provides a which of author and editor they expect or whether they
multitude of new styles (for output) and elds (for the can use both. Some eld types can optionally be used
database) that can be used in a document. For now, refer with any entry type:
to its comprehensive documentation on CTAN.
addendum, note
Entry and eld types in .bib les
language
The following table shows most eld types. Some eld pubstate
types are lists, either lists of person names, others are
literal lists. A date can either be given in parts or full, urldate
some keys are necessary, page references are provided as
ranges and certain special elds contain verbatim code. All physical (print) entry types share further optional eld
There are many kinds of titles. types:
Some entry types are hard to distinguish and are treated
the same by standard styles: url, doi
124 CHAPTER 5. SPECIAL PAGES
eprint, eprintclass, eprinttype Example with prex 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 prexnumbers such as a, b and c. In ad-
@artwork dition we add a main heading for the bibliographies and
add that to the table of contents.
@audio
To make Hyperref links point to the correct bibliography
@image section, we also add \phantomsection before printing each
bibliography
@movie
To add each of the bibliographies to the table of contents
@music as sub-sections to the main Bibliography, replace head-
@performance ing=subbibliography with heading=subbibintoc.
@video
@software 5.5.6 Multiple bibliographies
Using multibib
and legal entry types
This package is for multiple Bibliographies for dierent
@commentary
sections in your work. For example, you can generate a
@jurisdiction bibliography for each chapter. You can nd information
about the package on CTAN[2]
@legislation
@legal
Using bibtopic
@letter
@review The bibtopic-Package[3] is created to dier the citations
on more les, so that you can divide the bibliography into
@standard more parts.
\documentclass[11pt]{article} \usepackage{bibtopic}
are dened, but not yet supported (well). \begin{document} \bibliographystyle{alpha}
The entry types @bibnote, @set and @xdata are special. \section{Testing} Lets cite all the books:
\cite{ColBenh:93} and \cite{Munt:93}; and an ar-
ticle: \cite{RouxSmart:95}. File books.bib is used for
Printing bibliography this listing: \begin{btSect}{books} \section{References
from books} \btPrintCited \end{btSect} Here, the arti-
Presuming we have dened our references in a le called cles.bib is used, and the listing is in plain-format instead
references.bib, we add this to biblatex by adding the fol- of the standard alpha. \begin{btSect}[plain]{articles}
lowing to the preamble: \section{References from articles} \btPrintCited \sec-
\addbibresource{references.bib} tion{Articles not cited} \btPrintNotCited \end{btSect}
Just print all entries here with \btPrintAll \be-
gin{btSect}[plain]{internet} \section{References from
Print the bibiography with this macro (usually at the end
the internet} \btPrintAll \end{btSect} \end{document}
of the document body):
\printbibliography
If the bib entries are located in multiple les we can add [2] http://ctan.org/pkg/multibib
them like this:
We can also lter on other elds, such as entrysubtype. If [3] http://ctan.org/pkg/bibtopic
we dene our online resources like this:
we lter with \printbibliography[title={Online re- This page uses material from Andy Roberts Getting to grips
sources}, subtype=inet] with LaTeX with permission from the author.
5.6. MORE BIBLIOGRAPHIES 125
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
abbrvnat
\citep and \citep* The \citep command is used where
unsrtnat the author name is to appear inside the parentheses along-
side the date.
which correspond to the three styles available by default Here are the \citep* versions
in BibTeX where you have a plain numbered style, an
abbreviated numbered style and an unsorted numbered
The Reference List
style.
Alongside these new styles is an extended set of citation Having dealt with basic varieties of citation, we turn to
commands to provide exible citation formats. These are the creation of the bibliography or reference list.
126 CHAPTER 5. SPECIAL PAGES
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.
127
128 CHAPTER 6. SPECIAL DOCUMENTS
\longindentation=0pt It is reported that pdatex 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 lter 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 le 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 simplies 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-edged 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 ll 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 nd 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 nd the following commands useful for printing the The output is generated via
envelope.
$ pdatex koma_env Folding the print of the resulting
$ pdatex envelope.tex $ pdf2ps envelope.pdf $ lpr -o le 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 rst line, dvips command converts the .dvi le pro- In addition to the default, the KOMA-package includes
duced by latex into a .ps (PostScript) le. In the second predened format denitions for dierent standardized
line, the PostScript le is sent to the printer. Swiss and Japanese letter formats.
6.2. PRESENTATIONS 129
Introductory example
6.1.5 Sources
6.2 Presentations
Style circles
inmargin
Themes The rst 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 dene 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 ocial documentation in-
text.fg!75!normal text.fg,bg=normal text.bg!75!black}
cluded in your distribution of beamer, particularly the
\setbeamercolor{ne 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-
ied 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 denes 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 dened as usual:
shadow
\denecolor{chocolate}{RGB}{33,33,33}
sidebar
Then you can add the innertheme: You can also suppress the navigation bar:
\useinnertheme{rectangles} \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 x for this is to Animations
use at the beginning of the le 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.
rst concept we introduce originates with Erd\H os.
\end{frame}
Frames Options
Text or gures 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):
gure 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 o 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 rst 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 rst time \only<1-
\frame[allowframebreaks]{ % ... } 1> {This one is shown at the rst 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 innitary, 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 Isaacsons thesis. \end{itemize}
6.2. PRESENTATIONS 133
\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 eld
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 dierent
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 rst one is useful when you make a presentation to
its stu 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 gures 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 le 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 les for a
\only<2>{\includegraphics{pic2.eps}} better distinction between the modes, you may need to
copy the .aux le from the handout compilation with the
slides (w/o the notes).
These pictures being completely dierent, 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 rst one Columns Example
plus some other graphs and you don't need the rst 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 species 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 rst 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 rst 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 thats 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}
134 CHAPTER 6. SPECIAL DOCUMENTS
Numbering slides
6.4.1 europecv
6.4.2 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 dene your
own style by changing the colours, the fonts, etc.
The ocial package provides some well commented tem-
plates which may be a good start. You can nd 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.
Classic
green theme
6.4.4 References
Chapter 7
Creating Graphics
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. Knuths
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
les, which can be imported in LaTeX. For an introduc-
The picture environment allows programming pictures tion, see A Users 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 Bzier curves, although this in LaTeX as LaTeX is to digital typesetting. Its 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 les, 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-
138
7.3. PICTURE 139
may be easier to draw the graphics using external vector Bzier curves are an exception. They are drawn with the
graphics software, and then import the le 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.
The rst pair, (x, y) , aects the reservation, within the draws a circle with center (x, y) and diameter (not radius)
document, of rectangular space for the picture. specied 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 (lled 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 Bzier
Most drawing commands have one of the two forms curves. See Graphics in LaTeX2e for examples and Java
or source les.
140 CHAPTER 7. CREATING GRAPHICS
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 Bzier curves! erates the necessary \qbezier command line.
As this example illustrates, splitting up a circle into 4
quadratic Bzier curves is not satisfactory. At least 8
are needed. The gure again shows the eect 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 aect quadratic Bzier 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 gure, each symmetric half of the catenary y =
and vertical lines (and quadratic Bzier curves), \thinlines cosh x 1 is approximated by a quadratic Bzier 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 predened 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 dened in
A picture box can be declared by the command convenient mathematical coordinates, whereas by the
command
then dened by
its lower left corner (marked by the black disk) is assigned
and nally arbitrarily often be drawn by the coordinates (2.5,0.25).
The optional position parameter has the eect of dening
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 speciers 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 Bzier 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 dened in
denition 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 141
or alternatively
\tikz[options]{tikz commands}
Options for path actions are e.g: draw, ll, pat- Straight lines are given by coordinates separated by a dou-
tern, shade (a variation on lling that changes col- ble minus,
ors smoothly from one to another), clip (all subsequent The rst coordinate represents a move-to operation. This
drawings up to the end of the current scope are clipped is followed by a series of path extension operations, like
against the current path and the size of subsequent paths "-- (coordinates)".
will not be important for the picture size), use as bound-
ing box. The "\path command with these options can The same path with some drawing options:
be combined to: "\draw, "\ll, "\lldraw, "\pattern, A connected path can be closed using the "--cycle oper-
"\shade, "\shadedraw, "\clip, "\useasboundingbox . ation:
A further move-to operation in an existing path starts a
new part of the path, which is not connected to the pre-
Geometric path actions vious part of the path. Here: Move to (0,0) straight line
to (2,0), move to (0,1) straight line to (2,1):
Geometric path options: rotate=<angle in degree>", Two points can be connected by straight lines that are only
xshift=<length>", yshift=<length>", scale=<factor>", horizontal and vertical. For a connection that is rst hor-
xscale=<factor>", yscale=<factor>". izontal and then vertical, use
or rst vertical then horizontal, use
Color
Color options for drawing paths: color=<color name>", 7.4.5 Drawing curved paths
draw=<line color>", opacity=<factor>". Following
colors are predened: red, green, blue, cyan , magenta, Curved paths using a Bezier curve can be created using
yellow, black, gray, darkgray, lightgray, brown, lime, the "..controls() ..()" command, with one or two control
olive, orange, pink, purple, teal, violet and white. points.
7.4. PGF/TIKZ 143
7.4.8 Arcs Writing text along a given path using the node command
is shown as a simple example:
The command arc creates a part of a circle or an ellipse: Possible options for the node command are e.g. in-
Or in an alternative syntax: ner sep=<dimension>", outer sep=<dimension>",
minimum size=<dimension>", shape as-
\draw (0,0) arc[radius = 8mm, start angle= 0, end angle=
pect=<aspect ratio>", text=<color>", font=",
270]; \draw (0,0) arc[x radius = 1.75cm, y radius = 1cm,
align=<left_right_center>".
start angle= 0, end angle= 315];
A node is centered at the current coordinate by default.
Often it would be better to have the node placed beside
the actual coordinate: Right (right or anchor=west),
7.4.9 Special curves left (left or anchor=east), above (above or an-
chor=south), below (below or anchor=north). Com-
There are many more predened commands for special binations are also possible, like anchor=north east or
paths, like grid, parabola, sin, cos (sine or cosine below left.
curve in the interval [0,/2]). To place nodes on a line or a curve use the
The option help lines denotes ne gray. pos=<fraction>" option, where fraction is a oat-
ing point number between 0 representing the previous
To add arrow tips there are simple options for the drawing coordinate and 1 representing the current coordinate.
command:
There exist some abbreviations: at start for pos=0,
A loop can be realized by "\foreach variable in {list of very near start for pos=0.125, near start for
values} commands". pos=0.25, midway for pos=0.5, near end for
PGF also has a math engine which enables you to plot pos=0.75, very near end for pos=0.875, at end
functions: for pos=1.
\draw [domain=<xmin>:<xmax>] plot (\x, {function}); The sloped option causes the node to be rotated to be-
come a tangent to the curve.
144 CHAPTER 7. CREATING GRAPHICS
Since nodes are often the only path operation on paths, 7.5.1 The pspicture environment
there are special commands for creating paths containing
only a node, the rst with text ouput, the second without: PSTricks commands are usually placed in a pspicture en-
\node[<options>](<name>) at (<coordinate>){<text>}; vironment.
\coordinate[<options>](<name>) at (<coordinate>); \begin{pspicture}(x1,y1) % ... \end{pspicture}
One can connect nodes using the nodes labels as coordi- The rst argument between parentheses species the co-
nates. Having "\path(0,0) node(x) {} (3,1) node(y) {};" ordinates of the upper-right corner of the picture. The
dened, the node at (0,0) got the name "(x)" and the one bottom-left corner is at (0,0) and is placed at the refer-
at (3,1) got the name "(y)". ence point of the next character in the LaTeX document.
Equivalent to It is also possible to specify the coordinates (x0,y0) of the
\coordinate (x) at (0,0); \coordinate (y) at (3,1); \draw bottom-left corner:
(x) -- (y); \begin{pspicture}(x0,y0)(x1,y1) % ... \end{pspicture}
Multiline text can be included inside a node. A new Thus the size of the picture is (x1-x0)x(y1-y0). The de-
line is indicated by double backslash "\\", but additionally fault unit for coordinates is centimeters (cm); this can be
you have to specify the alignment using the node option changed with \psset, as in \psset{unit=1bp}. Any TeX
align=". Here an example: dimension is allowed.
Path construction operations try to be clever, such that the
path starts at the border of the nodes shape and not from
the nodes center.
7.5.2 Fundamental objects
Once the node x has been dened, you can use anchors
as dened above relative to (x) as "(x.<anchor>)", like
"(x.north)". Lines and polylines
Example 1
To get a vector, add an arrow as parameter:
Example 2 \psline{->}(x0,y0)(x1,y1)
Example 3: A Torus You can add as many points as you want to get a polyline:
\psline(x0,y0)(x1,y1)(x2,y3)(xn,yn)
Example 4: Some functions
Polygons are always closed. The syntax is the same as for B, Bl, Br: baseline center, left and right.
\psline:
t, tl, tr: top center, left and right.
\pspolygon(x0,y0)(x1,y1)(x2,y2)...(xn,yn)
b, bl, br: bottom center, left and right.
As for rectangles, the starred version prints a lled poly-
gon. And the linearc=0.2 option will print rounded cor- There is also the \uput command with further options:
ners. \uput{distance}[angle](x,y){text}
Circles, arc and ellipses The distance parameter is the distance from the coordi-
nate.
Starred version lls 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:
\pscirclebox{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*[llcolor=green]{text}}
\psparabola(x0,y0)(x1,y1)
Using the pst-text extension, it is possible to draw a text
path.
will print a symmetric parabola with vertical asymptote,
vertex (x1,y1) and ending at (x0,y0). \pstextpath{shape}{text}
Use \psbezier to print a Bzier curve with an arbitrary
number of control points. Arcs have at most 4 control To print a text following a path without printing the path,
points. Use the showpoints=true option to print the con- you need to use \psset{linestyle=none}.
trol points and the tangents. Example:
Use \pscurve to print the interpolation of the given points. \usepackage{pst-text} % ... \be-
The \psecurve command omits the rst and the last arcs. gin{pspicture}(5,5) \psset{linestyle=none} \ps-
textpath{\psline(0,0)(1,1)(2,0)}{triangle text}
\end{pspicture}
7.5.3 Text
Use
\rput(x,y){text} 7.5.4 Grids
Without any parameter, the \psgrid command will print
to print text. Provide an angle to rotate the text. a grid all over the pspicture, with a spacing of 0.2 (i.e.
\rput{angle}(x,y){text} 2mm). You can specify parameters:
You can provide the anchor of the text which will be at \psgrid(xmax,ymax): prints a grid from (0,0) to
the specied coordinate. (xmax,ymax).
\rput[t]{45}(5,5){text} \psgrid(xmin,ymin)(xmax,ymax): prints a grid from
(xmin,ymin) to (xmax,ymax).
146 CHAPTER 7. CREATING GRAPHICS
ticklinestyle=value: self-explanatory. value may be dotscale=value species the size of the points.
one of solid, dashed, dotted. This is useful for huge
graduations (i.e. ticksize is high). dotstyle=value where value is among:
*: disc
Example o: circle
+,x: cross
\psgrid[griddots=5, subgriddiv=0,
square, squarre*: starred version is lled.
gridlabels=0pt](1,1)(5,5)
diamond, diamond*
triangle, triangle*
Axis etc.
Options This command also lets you change the default unit for
lengths.
Dx=value and Dy=value denes the spacing be-
tween graduations. unit=value
comma lets you use the comma as decimal separa-
xunit=value and yunit=value
tor.
As for lines, {->} adds arrows on axes. value is a number with or without unit. This changes the
scale of the drawings, but will not change the width of
Example lines.
7.5. PSTRICKS 147
<< or >>: double arrow. You can repeat the operation with \multirput:
|: bar. \multirput(x0,y0)(xoset, yoset){times}{object}
**: disk. With no text but with graphics only, you can use the \mul-
*: centered disk. tips command:
\multips(x0,y0)(xoset, yoset){times}{object} \mul-
|< or >|: arrow plus bar. tips{angle}(x0,y0)(xoset,yoset){times}{object}
cc: rounded extreme.
Closed shapes
Usage
For closed shape you may dene the llstyle.
Declare the PDFTricks packages in the preamble.
llstyle=value: pattern. Possible values: crosshatch,
crosshatch*, vlines, vlines*, hlines, hlines*, solid. Place all PSTricks extensions in a psinputs environ-
ment; place all PSTricks commands in a pdfpic en-
llcolor=color. vironment.
hatchcolor=color.
Compile with pdatex -shell-escape <le>.
hatchwidth=value.
Example
Example:
\pscircle[hatchcolor=blue,llstyle=vlines](0,0){1}
\documentclass{article} \usepackage{pdftricks}
\begin{psinputs} \usepackage{pstricks} \usepack-
age{multido} \end{psinputs} % ... \begin{document}
7.5.6 Object location % ... \begin{pdfpic} \psset{unit=\linewidth} \be-
gin{pspicture}(0,0)(10,10) [...] \end{pspicture}
The \rput and \uput commands can be used to move any \end{pdfpic} % ... \end{document}
object.
Another way to use PSTricks with pdatex is the pst-pdf
Example package.
148 CHAPTER 7. CREATING GRAPHICS
7.6 Xy-pic that are covered by other surfaces and should be excluded
from the rendered image.
xy is a special package for drawing diagrams. To use it, A package that can handle this correctly is the pst-
simply add the following line to the preamble of your doc- solides3d package.
ument:
Another way to create 3D graphics is to use Asymptote.
\usepackage[all]{xy}
Yet another way to create 3D graphics is to use Sketch.
Programming
8.1.1 New commands Note When the command is used with an explicit rst
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 denition 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 species the number of arguments the new command to decide how they will look. There are several dierent
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 rst example denes 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 dene 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 dierently you just have to change the
than one argument, use #2 and so on, these arguments are denition 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.
149
150 CHAPTER 8. PROGRAMMING
Extra space
8.1.7 Loops
When creating a new environment you may easily get The PGF/TikZ extension provides the \foreach com-
bitten by extra spaces creeping in, which can potentially mand.
have fatal eects. For example when you want to create a
If you are only using \foreach and not drawing graphics,
title environment which suppresses its own indentation as
you may instead use the pgor package directly.
well as the one on the following paragraph. The \ignores-
paces command in the begin block of the environment Alternatively you can check out the multido package.
will make it ignore any space after executing the begin
block. The end block is a bit more tricky as special pro-
cessing occurs at the end of an environment. With the 8.1.8 Strings
\ignorespacesafterend LaTeX will issue an \ignorespaces
after the special end processing has occurred. xstring provides a lot of features. From CTAN:
position of a substring most packages use Plain TeX code. Plain TeX is much
more low-level, it has much more capabilities at the cost
number of recurrences of a substring of a steep learning curve and complex programming.
Up to a few exceptions, you can use the full Plain TeX
Examples:
language within a valid LaTeX document whereas the op-
posite is false.
8.1.9 LaTeX Hooks
LaTeX provide two hooks: 8.2.1 Vocabulary
[2] ctan.mackichan.com
There may be more terms, but we hope that it will do it
for now.
While you play with LaTeX macros, you will notice that it In TeX some characters have a special meaning that is not
is quite limited. You may wonder how all these packages to print the associated glyph. For example, \ is used to in-
you are using every day have been implemented with so troduce a control sequence, and will not print a backslash
little. In fact, LaTeX is a set of Plain TeX macros and by default.
152 CHAPTER 8. PROGRAMMING
To distinguish between dierent meanings of the charac- makes use of the catcode to specify a rule: all non-public,
ters, TeX split them into category codes, or catcodes for internal macros that are not supposed to be accessed by
short. There are 16 category codes in TeX. the end-user contains at least one '@' character in their
A powerful feature of TeX is its ability to redene 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. Thats why when you need to access LaTeX internals, you
must enclose all the commands accessing private func-
However, this is not recommended, as it can make code
dicult to read. Should you redene any catcode in a tions with \makeatletter and \makeatother. All they do is
class or in a style le, make sure to revert it back at the just changing the catcode:
end of your le.
If you redene catcodes in your document, make sure to
do it after the preamble to prevent clashes with package
loading. 8.2.3 Plain TeX macros
Denitions are limited to their scope. However it might Some macros may have a name that is not directly
be convenient sometimes to dene a macro inside a group writable as is. This is the case of macros whose name
that remain valid outside the group, and until the end of is made up of macro names. Example:
the document. This is what we call global denitions. The last line will print a sentence depending on the \status.
You can also use the \global command with \edef. This command actually does the opposite of \string which
Both commands have a shortcut: prints a control sequence name without expanding it:
The previous denition commands would not allow you \noexpand is useful to have ne grained control over what
to use them over multiple paragraphs, i.e. text containing gets expanded in an \edef. Example:
the \par command -- or double line breaks. \the control sequence will let you see the content of vari-
You can prex the denition with the \long command to ous TeX types:
allow multi-paragraph arguments.
catcodes
Example:
chardef
Outer denitions font parameters
This prex macro prevent denitions from being used in internal parameters
some context. It is useful to consolidate macros and make
lengths
them less error-prone because of bad contexts. Outer
macros are meant to be used outside of any context, hence registers
the name.
...
For instance the following code will fail:
Outer macros are not allowed to appear in: Example:
macro parameters
8.2.4 Registers
skipped conditional
... Registers are kind of typed variables. They are limited
in numbers, ranging from 0 to 255. There are 6 dierent
types:
let and futurelet
TeX uses some registers internally, so you would be better
o not using them.
\let<csname><token> is the same as \ex-
pandafter\def\expandafter<csname>\expandafter{<content>}. List of reserved registers:
It denes a new control sequence name which is equiva-
lent to the specied token. The token is usually another \box255 is used for the contents of a page
control sequence.
\count0-\count9 are used for page numbering
Note that \let will expand the token one time only, con-
trary to \edef which will expand recursively until no fur-
ther expansion is possible. Scratch registers (freely available):
Example[1] :
\box0-\box254
\futurelet<csname><token1><token2>... works a bit dif-
ferently. token2 is assigned to csname; after that TeX \count255
processes the <token1><token2>... sequence. So \fu- \dimen0-\dimen9
turelet allows you to assign a token while using it right
after. \muskip0-\muskip9
154 CHAPTER 8. PROGRAMMING
Assign register using the '=' control character. For box The syntax is \ifcase <num-
registers, use the \setbox command instead. ber><case0>\or<case1>\or...\else<defaultcase>\.
If number is equal to the case number, its content will be
You may use one of the following reservation macro to printed. Note that it starts at 0.
prevent any clash:
\else is used to specify the default case (whenever none of
These macros use the following syntax: \new*<csname>. the previous cases have matched).
Example:
These commands can not be used inside macros, other-
wise every call to the macro would reserve another regis- 8.2.7 Loops
ter.
You can print a register using the \the command. For The base syntax is
counters use the \number command instead. For boxes As always, content and true action are arbitrary TeX con-
use the \box command. tents. \if* refers to any of the conditionals. Note that
there is no false action, you cannot put an \else between
\if* and \repeat. In some case this will be the opposite
8.2.5 Arithmetic of what you want; you have to change the condition or to
dene a new conditional using \newif. Example:
The arithmetic capabilities of TeX are very limited, al-
though this base suce to extend it to some interesting The above code will print TeX ten times.
features. The three main functions:
register may be of type count, dimen, muskip or skip. It
does not make sense for box nor toks. 8.2.8 Doing nothing
depending on which value we want to set in our condi- You can dene control sequence to expand to a
tional. specic char. The syntax is \chardef<control se-
3. Now we can use our conditional anywhere after in an quence>=<charcode>. The following sequences do the
if control structure. same thing.
A full example is: Example:
8.3. CREATING PACKAGES 155
Font encoding map the \localedef macro rst argument because they are
in the body of that macro.
We can use the above primitive to print the font encoding
2. \#1 gets expanded to two tokens: '#' and '1', and the
map.
\def command will fail as it requires a valid control
Another version, with dierent fonts, one entry per line: sequence name.
This is useful in some case, for example to dene lan- Finally if we want to set language from command line, we
guage commands as explained in Multilingual versions, must be able to set the \locale variable so that the one in
where the end user can write the source code is the default value that can be overridden
by the one in the command line. This can be done with
and make sure it switches to the appropriate Babel lan- \providecommand:
guage.
The nal code is
Lets dene a macros that will dene language commands
for instance. These commands are simple: if the argu- And you can compile with
ment is the value of the \locale variable, then the corre- latex '\providecommand\locale{en}\input{mydocument.tex}'
sponding macro prints its content directly. Otherwise, it
does nothing.
8.2.12 Notes and References
Basically, what we want to do is extremely simple: dene
a bunch of macros like this: [1] From tex.stackexchange.com: What is the dierence be-
In the previous snippet of code, only the \de command in tween \let and \edef?
going to output its content, \en and \fr will print nothing
at all. Thats what we want. The problem arises when Further reading
you want to automate the task, or if you have a lot of
languages, and you want to change the language selection. The TeXbook, Donald Knuth
You just have to move the #1, but thats not convenient
and it makes it impossible to choose the Babel language TeX by Topic, Victor Eijkhout
from command line. Think this out... TeX for the Impatient, Paul W. Abrahams, Karl
What we are going to do is to dene the language com- Berry and Kathryn A. Hargreaves
mands dynamically following the value of the \locale vari-
able (or any variable of your choice). Hence the use of
the \equal command from the ifthen package. 8.3 Creating Packages
Since it is hardly possible to write it in LaTeX, we will
use some Plain TeX. If you dene a lot of new environments and commands,
the preamble of your document will get quite long. In
Another problem arises: how to dene a command whose
this situation, it is a good idea to create a LaTeX package
name is a variable? In most programming languages thats
or class containing all your command and environment
not possible at all. What we could be tempted to write is
denitions. It can be made dynamic enough to t to all
It will fail for two reasons. your future documents.
Classes are .cls les, packages are stored in .sty les. They
1. The two last '#1' are supposed to refer to the argu- are very similar, the main dierence being that you can
ments of the new macro, but they get expanded to load only one class per document.
156 CHAPTER 8. PROGRAMMING
After deciding to create an own package or class, you Once your package is ready, we can use it in any doc-
should think about which license the package/class has. ument. Import your new package with the known com-
A license is of great importance, either to protect your mand \usepackage{mypack}. The le custom.sty and the
le, or to make it available for others. LaTeX source you are compiling must be in the same di-
rectory.
For a more convenient use, it is possible to place the
8.3.1 makeatletter and makeatother
package within $TEXMFHOME (which is ~/texmf by
default) according to the TeX Directory Structure (TDS).
By default, LaTeX will allow the use of the '@' characters
That would be
for control sequences from within package and class les,
but not from within an end-user document. This way it is $TEXMFHOME/tex/latex/custom/custom.sty
possible to protect commands, i.e. to make them accessi- On Windows '~' is often C:\Users\username.
ble from packages only.
You may have to run texhash (or equivalent) to make your
However it is possible to override this security with the TeX distribution index the new le, thus making it avail-
duo \makeatletter and \makeatother. These commands able for use for any document. It will allow you to use
only make sense in a regular document, they are not your package as detailed above, but without it needing to
needed in package or class les. be in the same directory as your document.
8.3.2 Creating your own package 8.3.3 Creating your own class
Your package can be made available in your document It is also possible to create your own class le. The pro-
just like any other package: using the \usepackage com- cess is similar to the creation of your own package, you
mand. Writing a package basically consists of copying can call your own style le in the preamble of any docu-
the contents of your document preamble into a separate ment by the command:
le with a name ending in .sty.
The name of the class le is then myclass.cls. Lets write
Lets write a rst custom.sty le as an example package: a simple example:
\ProcessOptions\relax terminates the option pro- They behave as the document hooks. See LaTeX Hooks.
cessing.
8.4.1 Introduction
8.4.5 Sectioning
This is denitely the most complex part. It is not that hard
since the code is almost the same for \section, \subsection
and \subsubsection.
We use \needspace to make sure there is no line break
right after a sectioning command. We enclose the com-
Custom theme mand in a group where we set a font size since the space
we need is \baselineskip which depends on the font size.
158 CHAPTER 8. PROGRAMMING
Miscellaneous
9.1 Modular Documents book. In such cases it is good practice to split your work
into several les. 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 le. 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{lename}
about how to start a document properly, keeping a good
high-level structure. This is all about organizing your les
and
using the modular capabilities of LaTeX. This way it will
be very easy to make modications even when the doc- \include{lename}
ument is almost nished. 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 dierences between these two ways to include les
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 lename.tex before continu-
ing with the rest of the base le (the le that contains these
statements). When the compiler processes your base le
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 lename.tex and processes its content in accordance
2. create two other directories inside the root, one for with the formatting commands specied in the base le.
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 le and write the contents using \input or \include in
short names. A suggestion would be simply tex and the les 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 le 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 les should be in The second method of including a le, \in-
your root directory, using "/" for each directory: clude{lename}, diers from the rst in some important
./document.tex ./mystyle.sty ./tex/ ./img/ ways. You cannot nest \include statements within a le
added via \include, whereas \input, on the other hand,
nothing else.
allows you to call les which themselves call other les,
ad innitum (well, nearly!). You can, however, \include
9.1.2 Getting LaTeX to process multiple a le which contains one or more \input commands.
Please resist the temptation to nest les in this way
les
simply because the system can do it: you will end up
As your work grows, your LaTeX le can become un- with just another kind of complexity!
wieldy and confusing, especially if you are writing a long Another important dierence is that using \include will
article with substantial, discrete sections, or a full-length force a page break (which makes it ideal for a books
159
160 CHAPTER 9. MISCELLANEOUS
chapters), whereas the \input command does not (which tree. Writing
in turn makes it ideal for use within, say, a long article \input{./lename.tex}
with discrete sections, which of course are not normally
set on a new page).
will have exactly the same eect as writing
In either case the .tex lename extension is optional.
\input{lename.tex}
Working on discrete parts of your documents has conse-
quences for how the base le is compiled; these will be
dealt with below. but if you found it more convenient to put all your les in
a sub-directory of your current directory, called myles,
you would refer to that le by specifying
Using dierent paths \input{./myles/lename.tex}
When the LaTeX compiler nds a reference to an external Indeed, in our example of the absolute path above, you
le in the base le, it will look for it in the same directory. could refer to that le relatively, too:
However, you can in principle refer to any le on your
system, using both absolute and relative paths. \input{../../documents/useful/foo.tex}
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{subles}
\end{document}
ble way to include text or images in multiple documents Several PDFs can be placed table-like on one page. See
(e.g. an article and a presentation). more information in its documentation.
In the main document, the package must be loaded as:
\usepackage{standalone} Produce a single .tex from modular documents
In summary, the base document (main.tex) looks like: another C script atten
\documentclass{book} \usepackage{standalone}
\begin{document} %% my document content \in- 9.1.4 The le mystyle.sty
put{chapter1} %% more of my document content
\end{document} Instead of putting all the packages you need at the be-
ginning of your document as you could, the best way is
and Chapter 1 (chapter1.tex) looks like: to load all the packages you need inside another dummy
package called mystyle you will create just for your doc-
\documentclass{standalone} % Preamble \be- ument. The good point of doing this is that you will just
gin{document} %% my chapter 1 content %% %% have to add one single \usepackage in your main.tex doc-
more of my chapter 1 content \end{document} ument, keeping your code much cleaner. Moreover, all
the info about your style will be within one le, so when
you will start another document you'll just have to copy
Import The import package allows for relative direc- that le and include it properly, so you'll have exactly the
tories. While subles fails to have a way of a suble it- same style you have used.
self having references relative to its own directory, the Creating your own style is very simple: create a le called
\subimport command provides this functionality. mystyle.sty (you could name it as you wish, but it has to
end with ".sty). Write at the beginning of the mystyle.sty
le:
9.1.3 Including complete pdf documents
or single pages \ProvidesPackage{mystyle}
There is a great package for including full pages of PDF Then add all the packages you want with the standard
les: pdfpages. It is capable of inserting entire pages as command \usepackage{...} as you would do normally,
is and more pages per one page in any layout (e.g. 2 3 change the value of all the variables you want, etc. It
). will work like the code you put here would be copied and
The package has several options: pasted within your document.
other les. It should look like this (its the sample code 9.2 Collaborative Writing of La-
for a report, but you might easily change it to article or
whatever else):
TeX Documents
\documentclass[12pt,a4paper]{report} \usepack- Note: This Wikibook is based on the article Tools for
age{graphicx} % put all the other packages here: Collaborative Writing of Scientic LaTeX Documents by
\usepackage{mystyle} \usepackage{hyperref} \be- Arne Henningsen that is published in The PracTeX Jour-
gin{document} \input{./tex/title.tex} %\maketi- nal 2007, number 3 (http://www.tug.org/pracjourn/).
tle \tableofcontents \listogures \listoftables \in-
put{./tex/intro.tex} \input{./tex/main_part.tex}
\input{./tex/conclusions.tex} \appendix \in- 9.2.1 Abstract
put{./tex/myappendix.tex} % Bibliography: \clearpage
\input{./tex/mybibliography.tex} \end{document} Collaborative writing of documents requires a strong syn-
chronisation among authors. This Wikibook describes
Here a lot of code expressed in previous sections has been a possible way to organise the collaborative preparation
used. You import the only package you need, that is your of LaTeX documents. The presented solution is primar-
mystyle.sty (note that in the code it has to be imported ily based on the version control system Subversion (http:
without the extension), then your document starts. Then //subversion.apache.org/). The Wikibook describes how
Subversion can be used together with several other soft-
it inserts the title: we don't like the output of \maketitle so
we created our own, the code for it will be in a le called ware tools and LaTeX packages to organise the collabo-
title.tex in the folder called tex we created before. How rative preparation of LaTeX documents.
to write it is explained in the Title Creation section. Then
tables of contents, gure and tables are inserted. If you Other Methods
don't want them, just comment out those lines. Then the
main part of the document is inserted. As you can see, You can use one of the online solutions listed in the
there is no text in document.tex: everything is in other Installation chapter. Most of them have collabora-
les in the tex directory so that you can easily edit them. tion features.
We are separating our text from the structural code, so we
are improving the What You See is What You Mean na- Another option for collaboration is dropbox. It has 2
ture of LaTeX. Then we can see the appendix and nally GB free storage and versioning system. Works like
the Bibliography. It is in a separate le. SVN, but more automated and therefore especially
Once you have created your document.tex you won't need useful for beginning LaTeX users. However, Drop-
to edit it anymore, unless you want to add other les in the box is not a true versioning control system, and as
tex directory, but this is not going to happen very often. such it does not allow you to roll the article back to
Now you can write your document, separating it into as previous versions.
many les as you want and adding many pictures without
getting confused: thanks to the rigid structure you gave You can use an online collaborative tool built on top
to the project, you will be able to keep track of all your of a versioning control system, such as Authorea or
edits clearly. ShareLatex. Authorea performs most of the actions
A suggestion: do not give your les names like chap- described in this document, but in the background
ter_01.tex or gure_03.png, i. e. try to avoid using (it is built on Git). It allows authors to enter LaTeX
numbers in le-names: if the numbering LaTeX gives or Markdown via a GUI with mathematical notation,
them automatically, is dierent from the one you gave gures, 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 le, 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 le 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
Gobby you can write your documents in collabo-
ration with anyone in real time. It is strongly rec-
9.1.6 External Links ommended that you use utf8 encoding (especially if
there are users on multiple operating systems collab-
Subles package documentation orating) and a stable network (typically wired net-
works).
Standalone package documentation
TitanPad (or other clones of EtherPad). To compile
pdfpages package documentation use the command:
164 CHAPTER 9. MISCELLANEOUS
a SVN client software. This is the unique way to ac- 'Refresh FNDB' in the 'General' tab of the MiKTeX Op-
cess the repositories on the server. Besides the basic SVN tions.
command-line client, there are several Graphical User In- Furthermore, the repository contains manuals explaining
terface Tools (GUIs) and plug-ins for accessing the SVN the specic LaTeX software solution at our department
server (see http://subversion.tigris.org/links.html). Ad- (e.g. this document).
ditionally, there are very good manuals about SVN freely
available on the internet (e.g. http://svnbook.red-bean. The Subversion server hosts a separate repository for each
com). project of our department. Although branching, merging,
and tagging is less important for writing text documents
At our department, we run the SVN server on a GNU- than for writing source code for software, our repository
Linux system, because most Linux distributions include layouts follow the recommendations of the 'Subversion
it. In this sense, installing, conguring, and maintaining book' (http://svnbook.red-bean.com). In this sense, each
SVN is a very simple task. repository has the three directories /trunk, /branches, and
Most MS Windows users access the SVN server by the /tags.
TortoiseSVN client, because it provides the most usual The most important directory is /trunk. If a single text
interface for common users. Linux users usually use document belongs to the project, all les and subdirec-
SVN utilities from the command-line, or eSvn--a GUI tories of this text document are in /trunk. If the project
frontend--with KDi3 for showing complex dierences. yields two or more dierent text documents, /trunk con-
tains a subdirectory for each text document. A slightly
dierent version (a branch) of a text document (e.g. for
9.2.5 Hosting LaTeX les in Subversion
presentation at a conference) can be prepared either in
an additional subdirectory of /trunk or in a new subdirec-
tory of /branches. When a text document is submitted to
a journal or a conference, we create a tag in the directory
/tags so that it is easy to identify the submitted version
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 le 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 les should be put under
version control. Generally, all les that are directly mod-
Figure 1: Common texmf tree shown in eSvn's Repository ied by the user and that are necessary for compiling the
Browser
document should be included in the version control sys-
tem. Typically, these are the LaTeX source code (*.tex)
On our Subversion server, we have one repository for
les (the main document and possibly some subdocu-
a common texmf tree. Its structure complies with the
ments) and all pictures that are inserted in the document
TeX Directory Structure guidelines (TDS, http://www.
(*.eps, *.jpg, *.png, and *.pdf les). All LaTeX classes
tug.org/tds/tds.html, see gure 1). This repository pro-
(*.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 congured LaTeX to
tree. On the other hand, all les that are automatically
use this as their personal texmf tree. For instance, teTeX
created or modied 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,
guration le (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 les) 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~ les) generally should be
users can add the path of the working copy of the com-
not under version control, because these les 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 le has been added (but not if these tional information. Furthermore, these les are regularly
les have been modied), the users have to update their modied so that conicts are very likely.
'le 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
166 CHAPTER 9. MISCELLANEOUS
9.2.6 Subversion really makes the If the authors work on dierent operating sys-
dierence tems, their LaTeX editors will probably save the
les with dierent newline (end-of-line) characters
(http://en.wikipedia.org/wiki/Newline). To avoid this
A great feature of a version control system is that all au- type of 'ineective' modications, all users can agree on
thors can easily trace the workow of a project by view- a specic newline character and congure their editor
ing the dierences between arbitrary versions of the les. to use this newline character. Another alternative is
Authors are primarily interested in 'eective' modica- to add the subversion property 'svn:eol-style' and set
tions of the source code that change the compiled docu- it to 'native'. In this case, Subversion automatically
ment, but not in 'ineective' modications that have no converts all newline characters of this le to the native
impact on the compiled document (e.g. the position of newline character of the authors operating system
line breaks). Software tools for comparing text docu- (http://svnbook.red-bean.com/en/1.4/svn.advanced.
ments ('di tools) generally cannot dierentiate between props.file-portability.html#svn.advanced.props.special.
'eective' and 'ineective' modications; they highlight eol-style).
both types of modications. This considerably increases There is also another important reason for reducing the
the eort to nd and review the 'eective' modications. number of 'ineective' modications: if several authors
Therefore, 'ineective' modications should be avoided. work on the same le, the probability that the same line
In this sense, it is very important not to change the posi- is modied by two or more authors at the same time in-
tions of line breaks without cause. Hence, automatic line creases with the number of modied lines. Hence, 'inef-
wrapping of the users LaTeX editors should be turned fective' modications unnecessarily increase the risk of
o and line breaks should be added manually. Other- conicts (see section Interchanging Documents).
wise, if a single word in the beginning of a paragraph is
added or removed, all line breaks of this paragraph might
change so that most di tools indicate the entire para-
graph as modied, because they compare the les line by
line. The di tools wdi (http://www.gnu.org/software/
wdiff/) and dwdi (http://os.ghalkes.nl/dwdiff.html) are
not aected by the positions of line breaks, because they
compare documents word by word. However, their out-
put is less clear so that modications are more dicult
to track. Moreover, these tools cannot be used directly
with the Subversion command-line switch --di-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 Figure 2: Reviewing modications in KDi3
sentence and start each new sentence in a new line. Note
that this has an advantage also beyond version control: if Furthermore, version control systems allow a very eec-
you want to nd a sentence in your LaTeX code that you tive quality assurance measure: all authors should crit-
have seen in a compiled (DVI, PS, or PDF) le or on a ically review their own modications before they com-
printout, you can easily identify the rst few words of this mit them to the repository (see gure 2). The dierences
sentence and screen for these words on the left border of between the users working copy and the repository can
your editor window. 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 about 80 characters, because it is Furthermore, authors should verify that their code can be
rather inconvenient to search for (small) dierences in compiled awlessly before they commit their modica-
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 congured to add a vertical line that marks document. However, this directive is not only reasonable
the 80th column.) We nd 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 Subversion has a feature called 'Keyword Substi-
starts. An example LaTeX code that is formatted accord- tution' that includes dynamic version information
ing to these guidelines is the source code of the article about a le (e.g. the revision number or the last
Tools for Collaborative Writing of Scientic LaTeX Doc- author) into the contents of the le itself (see e.g.
uments by Arne Henningsen that is published (including http://svnbook.red-bean.com, chapter 3). Sometimes,
the source code) in The PracTeX Journal 2007, Number it is useful to include these information not only as
3 (http://www.tug.org/pracjourn/2007-3/henningsen/). a comment in the LaTeX source code, but also in
9.2. COLLABORATIVE WRITING OF LATEX DOCUMENTS 167
the (compiled) DVI, PS, or PDF document. This Visualizing dis in LaTeX: latexdi and changebar
can be achieved with the LaTeX packages svn (http:
//www.ctan.org/tex-archive/macros/latex/contrib/svn/), The tools latexdi and changebar can visualize dier-
svninfo (http://www.ctan.org/tex-archive/macros/latex/ ences of two LaTeX les inside a generated document.
contrib/svninfo/), or (preferably) svn-multi (http://www. This makes it easier to see impact of certain changes
ctan.org/tex-archive/macros/latex/contrib/svn-multi/). or discuss changes with people not custom to LaTeX.
The most important directives for collaborative writing of Changebar comes with a script chbar.sh which inserts a
LaTeX documents with version control systems are sum- bar in the margin indicating parts that have changed. La-
marised in the following box. texdi allows dierent styles of visualization. The de-
fault is that discarded text is marked as red and added
Directives for using LaTeX with version control sys- text is marked as blue. It also supports a mode similar
tems to Changebar which adds a bar in the margin. Latexd-
i comes with a script latexrevise which can be used to
1. Avoid 'ineective' modications. accept or decline changes. It also has a wrapper script
to support version control systems such as the discussed
2. Do not change line breaks without good reason. Subversion.
3. Turn o automatic line wrapping of your LaTeX ed- An example on how to use Latexdi in the Terminal.
itor. latexdi old.tex new.tex > di.tex # Files old.tex and
new.tex are compared and the le visualizing the changes
4. Start each new sentence in a new line. is written to di.tex pdatex di.tex # Create a PDF
5. Split long sentences into several lines so that each showing the changes
line has about 80-100 characters. (A similar rule The program DiPDF can be used to compare two ex-
from older times required lines to be at most 80 char- isting PDFs visually. There is also a command line tool
acters long for the reason that screens at that time comparepdf based on DiPDF.
could not display more than this number of charac-
ters per line; nowadays it seems OK not to be too
strict about the 80-character rule.) 9.2.7 Managing collaborative bibliogra-
6. Put only those les under version control that are
phies
directly modied by the user.
Writing of scientic articles, reports, and books requires
7. Verify that your code can be compiled awlessly be- the citation of all relevant sources. BibTeX is an excel-
fore committing your modications to the reposi- lent tool for citing references and creating bibliographies
tory. (Markey 2005, Fenn 2006). Many dierent BibTeX
styles can be found on CTAN (http://www.ctan.org) and
8. Use Subversion's di feature to critically review on the LaTeX Bibliography Styles Database (http://jo.
your modications before committing them to the irisson.free.fr/bstdatabase/). If no suitable BibTeX style
repository. can be found, most desired styles can be conveniently as-
sembled with custombib/makebst (http://www.ctan.org/
9. Add a meaningful and descriptive comment when tex-archive/macros/latex/contrib/custom-bib/). Fur-
committing your modications to the repository. thermore, BibTeX style les can be created or modied
manually; however this action requires knowledge of the
10. Use the Subversion client for copying, moving, or re-
(unnamed) postx stack language that is used in BibTeX
naming les and folders that are under revision con-
style les (Patashnik 1988).
trol.
At our department, we have a common bibliographic data
If the users are willing to let go of the built-in di utility base in the BibTeX format (.bib le). It resides in our
of SVN and use di tools that are local on their worksta- common texmf tree (see section 'Hosting LaTeX les in
tions, they can put to use such tools that are more tailored Subversion') in the subdirectory /bibtex/bib/ (see gure
to text documents. The di tool that comes with SVN was 1). Hence, all users can specify this bibliography by only
designed with source code in mind. As such, it is built to using the le name (without the full path) --- no matter
be more useful for les of short lines. Other tools, such where the users working copy of the common texmf tree
as Compare It! allows to conveniently compare text les is located.
where each line can span hundreds of characters (such as All users edit our bibliographic data base with the graph-
when each line represents a paragraph). When using a ical BibTeX editor JabRef (http://www.jabref.org). As
di tool that allows convenient views of les with long JabRef is written in Java, it runs on all major operat-
lines, the users can author the TeX les without a strict ing systems. As dierent versions of JabRef generally
line-breaking policy. save les in a slightly dierent way (e.g. by introduc-
168 CHAPTER 9. MISCELLANEOUS
tegrated server solution like WIKINDX (http://wikindx. Using other software freely available on Internet, you can
sourceforge.net/), Aigaion (http://www.aigaion.nl/), or easily convert DVI and PDF to other document formats.
refBASE (http://refbase.sourceforge.net/). Using this so- In particular, you can obtain the PostScript version using
lution only requires a computer with internet access and software which is included in your LaTeX distribution.
a web browser, which makes the usage of our data base Some LaTeX IDE will give you the possibility to gener-
considerably easier for infrequent users. Moreover, the ate the PostScript version directly (even if it uses inter-
stored PDF les are available not only from within the nally a DVI mid-step, e.g. LaTeX DVI PS). It is
department, but throughout the world. (Depending on also possible to create PDF from DVI and vice versa. It
the copy rights of the stored PDF les, the access to doesn't seem logical to create a le with two steps when
the server --- or least the access to the PDF les --- has you can create it straight away, but some users might need
to be restricted to members of the department.) Even it because, as you remember from the rst chapters, the
Non-LaTeX users of our department might benet from format you can generate depends upon the formats of the
a server-based solution, because it should be easier to use images you want to include (EPS for DVI, PNG and JPG
this bibliographic data base in (other) word processing for PDF). Here you will nd sections about dierent for-
software packages, because these servers provide the data mats with description about how to get it.
not only in BibTeX format, but also in other formats. Other formats can be produced, such as RTF (which can
All readers are encouraged to contribute to this wikibook be used in Microsoft Word) and HTML. However, these
by adding further hints or ideas or by providing further so- documents are produced from software that parses and
lutions to the problem of collaborative writing of LaTeX interprets the LaTeX les, and do not implement all the
documents. features available for the primary DVI and PDF outputs.
Nonetheless, they do work, and can be crucial tools for
collaboration with colleagues who do not edit documents
9.2.9 Acknowledgements with LaTeX.
If you have created dierent PDF documents and you dvi2ps my_le.dvi
want to merge them into one single PDF le you can use
the following command-line command. You need to have
Ghostscript installed: 9.3.5 Convert to RTF
LaTeX can be converted into an RTF le, which in turn
Using Windows gswin32 -dNOPAUSE - can be opened by a word processor such as LibreOce
sDEVICE=pdfwrite -sOUTPUTFILE=Merged.pdf Writer or Microsoft Word. This conversion is done
-dBATCH 1.pdf 2.pdf 3.pdf through latex2rtf, which may run on any computer plat-
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-
Alternatively, PDF-Shuer is a small python-gtk applica- tations of LaTeX, such as standard formatting, some math
tion, which helps the user to merge or split pdf documents typesetting, inclusion of EPS, PNG or JPG graphics, and
and rotate, crop and rearrange their pages using an in- tables. As well, it has some limited support for packages,
teractive and intuitive graphical interface. This program such as varioref, and natbib. However, many other pack-
may be available in your Linux distributions repository. ages are not supported.
9.3. EXPORT TO OTHER FORMATS 171
9.3.6 Convert to HTML Vector graphics can be scaled to any size, thus do
not suer from quality loss. SVG is a vector format.
There are many converters to HTML. Some of them use
Raster graphics dene every pixel explicitly. PNG
an intermediate le which then will be converted to the
is a raster format.
destination format.
latex2html -html_version 4.0,latin1,unicode -split 1 - SVG can not embed fonts. So either the font will
nonavigation -noinfo -title MyDocument MyDocu- be rendered using a local .ttf or .otf font (which will
ment.tex mostly change the output), or all characters must be
turned to vector graphics. This last method makes
LaTeXML the SVG big and slow. If the input LaTeX le con-
tains a lot of text which formatting must be pre-
latexmlc paper.tex --destination=paper.html served, SVG is not that great.
Direct conversion from PDF to SVG can be done using This value will be passed to dvipng using the ag -D. To
the command line tool pdf2svg. generate the desired png le run the command as follows:
pdf2svg le.pdf le.svg dvipng -T tight -D 231.26 -o foo.png foo.dvi
The ag -T sets the size of the image. The option tight
ps2svg will only include all ink put on the page. The option -o
sends the output to the le name foo.png.
Alternatively DVI or PDF can be converted to PS as de-
scribed before, then the bash script ps2svg.sh can be used
(as all the software used by this script is multiplatform, ImageMagick
this is also possible in Windows, a step-by-step guide
could be written). The convert command from the ImageMagick suite can
convert both DVI and PDF les to PNG.
dvisvgm convert input.pdf output.png
One can also use dvisvgm, an open source utility that con- optipng
verts from DVI to SVG.
dvisvgm -n le.dvi You can optimize the resulting image using optipng so
that it will take up less space.
Inkscape
9.3.8 Convert to plain text
Inkscape is able to convert to SVG, PDF, EPS, and other
vector graphic formats.
If you are thinking of converting to plain text for spell-
inkscape --export-area-drawing --export-ps=OUTPUT checking or to count words, there may be an easier way
INPUT inkscape --export-area-page --export-plain- read Tips and Tricks rst.
svg=OUTPUT INPUT
Most LaTeX distributions come with detex program,
which strips LaTeX commands. It can handle multi-le
Raster graphics projects, so all you need is to give one command:
detex yourle
JPEG
(note the omission of .tex extension). This will output
Run ghostscript on the PostScript le created by pdf2ps result to standard output. If you want the plain text go to
as follows: a le, use
dvipng
173
174 CHAPTER 10. HELP AND RECOMMENDATIONS
if it looks right the rst 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 oating gures 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 gures
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 LaTeXs native diagramming tools or by export-
ing LaTeX is not that dicult and does not take that long.
ing vector formats from your drawing or diagramming
Most chapters in this book are dedicated to a specic 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 specic package, make over PNG or JPG.
sure you read its ocial documentation, which is usually
the best source of information. Content found on the web,
even in this book, is rarely as accurate as the ocial 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
will output:
Vector image editors with LaTeX support
TeX capacity exceeded , sorry [ grouping levels =255].
Appendix
179
180 CHAPTER 11. APPENDIX
Vels 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 Flynns beginners 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 les:
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 les that have nav-
igation buttons used for presentations: Lamports book LaTeX: A Document Preparation
http://sarovar.org/projects/pdfscreen/ System
11.5.6 F 11.5.10 L
Figures Labels
Floats Letters
Fonts Links
Footnotes
11.5.11 M
Formatting
makeidx package
11.5.7 G \maketitle
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
Introduction 11.5.14 R
Italics References
11.5.15 S 11.6.1 #
Sentences / see slash marks
Small Capitals \@ following period ends sentence
Source Code Listings \\[*][extra-space] new line
Superscript and subscript: powers and indices \: medium space, math mode
Superscript and subscript: text mode \! negative thin space, math mode
URLs
11.6.2 A
11.6.3 B 11.6.6 E
\backslash prints a backslash \em Toggles italics on/o 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-
species 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/o for the text in curly braces
following the command e.g. \emph{This is in italics
\bfseries 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.
11.6.5 D 11.6.8 G
\dashbox 11.6.9 H
\date
\hll Abbreviation for \hspace{\ll}.
\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
\dotll \hrulell
11.6. COMMAND GLOSSARY 185
\Huge Sets font size. See Text Formatting. \listogures Inserts a list of the gures in the docu-
ment. Similar to TOC
\hyphenation{word list} Overrides default hyphenation
algorithm for specied words. See Hyphenation \listoftables Inserts a list of the tables in the document.
Similar to TOC
11.6.10 I \location
\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.
186 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 justied within
\nopagebreak Suggests LaTeX not to break page in this other environments.
place. See Page Layout.
\raggedleft Command used for right justied within
\not other environments.
\raggedright Command used for left justied within
11.6.15 O other environments.
\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
\textwidth
Chapter 12
12.1 Text
LaTeX/Introduction Source: https://en.wikibooks.org/wiki/LaTeX/Introduction?oldid=3199966 Contributors: var Arnfjr 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, Angus, 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, DoVlaNik993
and Anonymous: 77
LaTeX/Installation Source: https://en.wikibooks.org/wiki/LaTeX/Installation?oldid=3204746 Contributors: 3mta3, Koavf, Michael-
Billington, Mwtoews, Chazz, Bryant1410, Pi zero, Marcus Cyron, Gyro Copter, Kazkaskazkasako, QuiteUnusual, Nobelium, Ambrevar,
PAC2, Jason barrington~enwikibooks, Mfwitten, Tomato86, Benregn, Torbjorn T., LlamaAl, Razr Nation, Johannes Bo, RainCity471,
Leaderboard, Inferno986return, Fdar, Ah3kal, Dplaza000, Simplelatex, Alansandiego, DoVlaNik993, Metis spawn, Ptaherkhani and
Anonymous: 52
LaTeX/Installing Extra Packages Source: https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages?oldid=3038524 Contribu-
tors: Alejo2083, Mwtoews, Az1568, Xania, Pi zero, Zylorian, QuiteUnusual, Ollydbg, Mabdul, Ambrevar, Lotus noir, Netheril96, Dark-
Sheep, Dplaza000, DoVlaNik993 and Anonymous: 23
LaTeX/Basics Source: https://en.wikibooks.org/wiki/LaTeX/Basics?oldid=3181777 Contributors: Krischik, Chuckhomann, 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, BwDraco, Guzo, Wickedjargon, Pater Christophorus, Johannes Bo, Reddrag-
gone9, Negative24, Dplaza000, Tropicalkitty, BbcNkl, Nimblemods and Anonymous: 87
LaTeX/Document Structure Source: https://en.wikibooks.org/wiki/LaTeX/Document_Structure?oldid=3195262 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, DagErlingSmrgrav, Lucasreddinger, Keplerspeed, Dirk Hnniger,
Frap, Tomato86, Derwaldrandfoerster, Echeban, Torbjorn T., LlamaAl, Ntypanski, Wickedjargon, Genethecist, Johannes Bo, Reddrag-
gone9, Kurlovitsch, Kw CUACS.TOPS, Vanjanssen, BbcNkl and Anonymous: 82
LaTeX/Text Formatting Source: https://en.wikibooks.org/wiki/LaTeX/Text_Formatting?oldid=3196558 Contributors: Derbeth, Within-
focus, Igjimh, Thenub314, Pi zero, ChrisHodgesUK, Adrignola, Ambrevar, Dirk Hnniger, Robbiemorrison, Fishix, Bgeron, Johannes Bo,
RubensMatos, Leaderboard, Kurlovitsch, Lindhea, Maths314, HLHJ, Kevin Ryde, Paulgush, BbcNkl and Anonymous: 22
LaTeX/Paragraph Formatting Source: https://en.wikibooks.org/wiki/LaTeX/Paragraph_Formatting?oldid=3201909 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, Owl-syme, Hjsb, Yez, Waldir, CarsracBot, Hannes Rst, Rror, Adri-
anwn, ChrisHodgesUK, Pstar, QuiteUnusual, Neet, LR~enwikibooks, Adrignola, Nixphoeni, PatrickDevlin21, Ambrevar, Zzo38,
Cdecoro, Keplerspeed, Zrisher, GPHemsley, Henrybissonnette, TorfusPolymorphus, Smobbl Bobbl, ToematoeAdmn, Dirk Hnniger,
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: 149
LaTeX/Colors Source: https://en.wikibooks.org/wiki/LaTeX/Colors?oldid=3203228 Contributors: Alejo2083, Az1568, Xania, Pi zero,
Dan Polansky, Daniel Mietchen, Waldir, Gms, JackPotte, White gecko, ChrisHodgesUK, Kazkaskazkasako, Trace, QuiteUnusual,
Kri, Adrignola, Benjaminevans82~enwikibooks, ChristianGruen, Sanderd17, Scorwin, Ambrevar, PAC2, Velociostrich, Dirk Hnniger,
Tomato86, Conighion, Qzxpqbp, SamuelLB, Henry Tallboys, Nicolas Perrault III, Tisep, Johannes Bo, Tpapastylianou, Honza889,
Dplaza000, David Gaudet, Ks-M9, DoVlaNik993, AlvaroMolina and Anonymous: 66
188
12.1. TEXT 189
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
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 Hnniger
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_Arrow_Examples.png Source: https://upload.wikimedia.org/wikipedia/commons/b/bb/Chemfig_Arrow_Examples.png
License: CC BY-SA 4.0 Contributors: Own work Original artist: Clapsus
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:Clipboard.svg Source: https://upload.wikimedia.org/wikipedia/commons/1/1f/Clipboard.svg License: GPL Contributors: Own work,
based on File: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 to Commons by Sfan00_IMG using CommonsHelper. Original artist: The
original uploader was Iorsh at English Wikipedia
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: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
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: Own screenshot Original artist: Gummi team
12.2. IMAGES 193