The Not So Short Introduction to LATEX 2" Or LATEX2" in 139 minutes by Tobias Oetiker Hubert Partl, Irene Hyna and Elisabeth Schlegl Version 6.3, March 26, 2018 ii Copyright ©1995-2016 Tobias Oetiker and Contributors. All rights reserved. Thisdocumentisfree; youcanredistributeitand/ormodifyitundertheterms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This document is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details. YoushouldhavereceivedacopyoftheGNUGeneralPublicLicensealongwith this document; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Thank you! Much of the material used in this introduction comes from an Austrian introduction to LATEX 2.09 written in German by: Hubert Partl <[email protected]> Zentraler Informatikdienst der Universität für Bodenkultur Wien Irene Hyna <[email protected]> Bundesministerium für Wissenschaft und Forschung Wien Elisabeth Schlegl <noemail> in Graz If you are interested in the German document, you can find a version updated for LATEX2" by Jörg Knappen at CTAN://info/lshort/german iv Thank you! The following individuals helped with corrections, suggestions and material toimprovethispaper. Theyputinabigefforttohelpmegetthisdocument into its present shape. I would like to sincerely thank all of them. Naturally, all the mistakes you’ll find in this book are mine. If you ever find a word that is spelled correctly, it must have been one of the people below dropping me a line. If you want to contribute to this booklet, you can find all the source code on https://github.com/oetiker/lshort. Your pull requests will be appreciated. Eric Abrahamsen, Lenimar Nunes de Andrade, Eilinger August, Rosemary Bailey, BarbaraBeeton,MarcBevand,ConnorBlakey,SalvatoreBonaccorso,PietroBraione, Friedemann Brauer, Markus Brühwiler, Jan Busa, David Carlisle, Neil Carter, Carl Cerecke, Mike Chapman, Pierre Chardaire, Xingyou Chen, Christopher Chin, DiegoClavadetscher,WimvanDam,BenjaminDeschwandenJanDittberner,MichaelJohnDownes, MatthiasDreier,DavidDureisseix,HansEhrbar,Elliot,RockrushEngch,WilliamFaulk, Robin Fairbairns, Johan Falk, Jörg Fischer, Frank Fischli, Daniel Flipo, Frank, MicMilicFrederickx,DavidFrey,ErikFrisk,HansFugal,RobertFunnell,GregGam- ble,AndyGoth,CyrilGoutte,KasperB.Graversen,ArloGriffiths,AlexandreGui- mond, Neil Hammond, Christoph Hamburger, Rasmus Borup Hansen, Joseph Hil- ferty, Daniel Hirsbrunner, Martien Hulsen, Björn Hvittfeldt, Morten Høgholm, Werner Icking, Eric Jacoboni, Jakob, Alan Jeffrey, Martin Jenkins, Byron Jones, David Jones, Johannes-Maria Kaltenbach, Nils Kanning, Andrzej Kawalec, Chris- tian Kern, Alain Kessi, Axel Kielhorn, Sander de Kievit, Kjetil Kjernsmo, To- bias Klauser, Jörg Knappen, Michael Koundouros, Matt Kraai, Tobias Krewer, FloriLambrechts,MikeLee,MaikLehradt,RémiLetot,AxelLiljencrantz,JasperLoy, JohanLundberg,MartinMaechler,AlexanderMai,ClausMalten,KevinVanMaren, Pablo Markin, I. J. Vera Marún, Hendrik Maryns, Chris McCormack, Aleksan- dar S. Milosevic, Henrik Mitsch, Stefan M. Moser, Armin Müller, Philipp Nagele, Richard Nagy, Manuel Oetiker, Urs Oswald, Hubert Partl, Marcelo Pasin, Mar- tinPfister,LanThuyPham,BrenoPietracci,DemersonAndrePolli,MaksymPolyakov, NikosPothitos,JohnRefling,MikeRessler,BrianRipley,KurtRosenfeld,BerndRosen- lecher, Chris Rowley, Young U. Ryu, Risto Saarelma, András Salamon, José Car- losSantos,ChristopherSawtell,GillesSchintgen,CraigSchlenter,HanspeterSchmid, BaronSchwartz,JordiSerraiSolanich,MilesSpielberg,SusanStewart,MatthieuStigler, Geoffrey Swindale, Laszlo Szathmary, Boris Tobotras, Josef Tkadlec, Scott Veirs, DidierVerna,Carl-GustavWerner,FabianWernli,MatthewWidmann,DavidWood- house, Chris York, Rick Zaccone, Fritz Zaucker, and Mikhail Zotov. Preface LATEX [1] is a typesetting system that is very suitable for producing scien- tific and mathematical documents of high typographical quality. It is also suitable for producing all sorts of other documents, from simple letters to complete books. LATEX uses TEX [2] as its formatting engine. This short introduction describes LATEX2" and should be sufficient for most applications of LATEX. Refer to [1, 3] for a complete description of the LATEX system. This introduction is split into 6 chapters: Chapter 1 tells you about the basic structure of LATEX2" documents. You will also learn a bit about the history of LATEX. After reading this chapter, you should have a rough understanding how LATEX works. Chapter 2 goes into the details of typesetting your documents. It explains most of the essential LATEX commands and environments. After read- ing this chapter, you will be able to write your first documents, with itemized lists, tables, graphics and floating bodies. Chapter 3 explains how to typeset formulae with LATEX. Many examples demonstrate how to use one of LATEX’s main strengths. At the end of the chapter are tables listing all mathematical symbols available in LATEX. Chapter 4 explainsindexes, bibliographygenerationandsomefinerpoints about creating PDFs. Chapter 5 shows how to use LATEX for creating graphics. Instead of draw- ing a picture with some graphics program, saving it to a file and then including it into LATEX, you describe the picture and have LATEX draw it for you. Chapter 6 contains some potentially dangerous information about how to alterthestandarddocumentlayoutproducedbyLATEX. Itwilltellyou how to change things such that the beautiful output of LATEX turns ugly or stunning, depending on your abilities. vi Preface It is important to read the chapters in order—the book is not that big, after all. Be sure to carefully read the examples, because a lot of the information is in the examples placed throughout the book. LATEX is available for most computers, from the PC and Mac to large UNIX and VMS systems. On many university computer clusters you will find that a LATEX installation is available, ready to use. Information on how to access the local LATEX installation should be provided in the Local Guide [5]. If you have problems getting started, ask the person who gave you this booklet. The scope of this document is not to tell you how to install and set up a LATEX system, but to teach you how to write your documents so that they can be processed by LATEX. If you need to get hold of any LATEX related material, have a look at one of the Comprehensive TEX Archive Network (CTAN) sites. The homepage is at http://www.ctan.org. You will find other references to CTAN throughout the book, especially pointers to software and documents you might want to download. Instead of writing down complete URLs, I just wrote CTAN: followed by whatever location within the CTAN tree you should go to. If you want to run LATEX on your own computer, take a look at what is available from CTAN://systems. If you have ideas for something to be added, removed or altered in this document, please let me know. I am especially interested in feedback from LATEX novices about which bits of this intro are easy to understand and which could be explained better. Tobias Oetiker <[email protected]> OETIKER+PARTNER AG Aarweg 15 4600 Olten Switzerland The current version of this document is available on CTAN://info/lshort Contents Thank you! iii Preface v 1 Things You Need to Know 1 1.1 A Bit of History . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1.1 TEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1.2 LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2.1 Author, Book Designer, and Typesetter . . . . . . . . 2 1.2.2 Layout Design . . . . . . . . . . . . . . . . . . . . . . 2 1.2.3 Advantages and Disadvantages . . . . . . . . . . . . . 3 1.3 LATEX Input Files . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.3.1 Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.3.2 Special Characters . . . . . . . . . . . . . . . . . . . . 5 1.3.3 LATEX Commands . . . . . . . . . . . . . . . . . . . . . 5 1.3.4 Comments . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.4 Input File Structure . . . . . . . . . . . . . . . . . . . . . . . 7 1.5 A Typical Command Line Session . . . . . . . . . . . . . . . 7 1.6 The Layout of the Document . . . . . . . . . . . . . . . . . . 9 1.6.1 Document Classes . . . . . . . . . . . . . . . . . . . . 9 1.6.2 Packages . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.6.3 Page Styles . . . . . . . . . . . . . . . . . . . . . . . . 11 1.7 Files You Might Encounter . . . . . . . . . . . . . . . . . . . 11 1.8 Big Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2 Typesetting Text 15 2.1 The Structure of Text and Language . . . . . . . . . . . . . . 15 2.2 Line Breaking and Page Breaking . . . . . . . . . . . . . . . . 17 2.2.1 Justified Paragraphs . . . . . . . . . . . . . . . . . . . 17 2.2.2 Hyphenation . . . . . . . . . . . . . . . . . . . . . . . 18 2.3 Ready-Made Strings . . . . . . . . . . . . . . . . . . . . . . . 19 2.4 Special Characters and Symbols . . . . . . . . . . . . . . . . . 19 viii CONTENTS 2.4.1 Quotation Marks . . . . . . . . . . . . . . . . . . . . . 19 2.4.2 Dashes and Hyphens . . . . . . . . . . . . . . . . . . . 20 2.4.3 Tilde ((cid:24)) . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.4.4 Slash (/). . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.4.5 Degree Symbol (◦) . . . . . . . . . . . . . . . . . . . . 20 2.4.6 The Euro Currency Symbol (e) . . . . . . . . . . . . . 21 2.4.7 Ellipsis (…) . . . . . . . . . . . . . . . . . . . . . . . . 21 2.4.8 Ligatures . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.4.9 Accents and Special Characters . . . . . . . . . . . . . 22 2.5 International Language Support . . . . . . . . . . . . . . . . . 22 2.5.1 Polyglossia Usage . . . . . . . . . . . . . . . . . . . . . 23 2.6 The Space Between Words . . . . . . . . . . . . . . . . . . . . 27 2.7 Titles, Chapters, and Sections . . . . . . . . . . . . . . . . . . 27 2.8 Cross References . . . . . . . . . . . . . . . . . . . . . . . . . 30 2.9 Footnotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 2.10 Emphasized Words . . . . . . . . . . . . . . . . . . . . . . . . 31 2.11 Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.11.1 Itemize, Enumerate, and Description . . . . . . . . . . 31 2.11.2 Flushleft, Flushright, and Center . . . . . . . . . . . . 32 2.11.3 Quote, Quotation, and Verse . . . . . . . . . . . . . . 33 2.11.4 Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . 33 2.11.5 Printing Verbatim . . . . . . . . . . . . . . . . . . . . 34 2.11.6 Tabular . . . . . . . . . . . . . . . . . . . . . . . . . . 34 2.12 Including Graphics and Images . . . . . . . . . . . . . . . . . 37 2.13 Floating Bodies . . . . . . . . . . . . . . . . . . . . . . . . . . 39 3 Typesetting Mathematical Formulae 43 3.1 The AMS-LATEX bundle . . . . . . . . . . . . . . . . . . . . . 43 3.2 Single Equations . . . . . . . . . . . . . . . . . . . . . . . . . 43 3.2.1 Math Mode . . . . . . . . . . . . . . . . . . . . . . . . 45 3.3 Building Blocks of a Mathematical Formula . . . . . . . . . . 46 3.4 Single Equations that are Too Long: multline . . . . . . . . . 51 3.5 Multiple Equations . . . . . . . . . . . . . . . . . . . . . . . . 52 3.5.1 Problems with Traditional Commands . . . . . . . . . 52 3.5.2 IEEEeqnarray Environment . . . . . . . . . . . . . . . 54 3.5.3 Common Usage . . . . . . . . . . . . . . . . . . . . . . 55 3.6 Arrays and Matrices . . . . . . . . . . . . . . . . . . . . . . . 57 3.7 Spacing in Math Mode . . . . . . . . . . . . . . . . . . . . . . 59 3.7.1 Phantoms . . . . . . . . . . . . . . . . . . . . . . . . . 60 3.8 Fiddling with the Math Fonts . . . . . . . . . . . . . . . . . . 60 3.8.1 Bold Symbols . . . . . . . . . . . . . . . . . . . . . . . 61 3.9 Theorems, Lemmas, … . . . . . . . . . . . . . . . . . . . . . . 61 3.9.1 Proofs and End-of-Proof Symbol . . . . . . . . . . . . 62 3.10 List of Mathematical Symbols . . . . . . . . . . . . . . . . . . 65 CONTENTS ix 4 Specialities 73 4.1 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 4.2 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 4.3 Fancy Headers . . . . . . . . . . . . . . . . . . . . . . . . . . 76 4.4 The Verbatim Package . . . . . . . . . . . . . . . . . . . . . . 77 4.5 Installing Extra Packages . . . . . . . . . . . . . . . . . . . . 77 4.6 LATEX and PDF . . . . . . . . . . . . . . . . . . . . . . . . . . 78 4.6.1 Hypertext Links . . . . . . . . . . . . . . . . . . . . . 79 4.6.2 Problems with Links . . . . . . . . . . . . . . . . . . . 82 4.6.3 Problems with Bookmarks . . . . . . . . . . . . . . . . 82 4.7 Working with XƎLATEX and PDF . . . . . . . . . . . . . . . . 83 4.7.1 The Fonts . . . . . . . . . . . . . . . . . . . . . . . . . 83 4.7.2 Compatibility Between XƎLATEX and pdfLATEX . . . . 84 4.8 Creating Presentations . . . . . . . . . . . . . . . . . . . . . . 85 5 Producing Mathematical Graphics 89 5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 5.2 The picture Environment . . . . . . . . . . . . . . . . . . . . 90 5.2.1 Basic Commands . . . . . . . . . . . . . . . . . . . . . 90 5.2.2 Line Segments . . . . . . . . . . . . . . . . . . . . . . 91 5.2.3 Arrows . . . . . . . . . . . . . . . . . . . . . . . . . . 92 5.2.4 Circles . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 5.2.5 Text and Formulas . . . . . . . . . . . . . . . . . . . . 94 5.2.6 \multiput and \linethickness . . . . . . . . . . . . 94 5.2.7 Ovals . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.2.8 Multiple Use of Predefined Picture Boxes . . . . . . . 96 5.2.9 Quadratic Bézier Curves . . . . . . . . . . . . . . . . . 97 5.2.10 Catenary . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.2.11 Rapidity in the Special Theory of Relativity . . . . . . 99 5.3 The PGF and TikZ Graphics Packages . . . . . . . . . . . . . 99 6 Customising LATEX 103 6.1 New Commands, Environments and Packages . . . . . . . . . 103 6.1.1 New Commands . . . . . . . . . . . . . . . . . . . . . 104 6.1.2 New Environments . . . . . . . . . . . . . . . . . . . . 105 6.1.3 Extra Space . . . . . . . . . . . . . . . . . . . . . . . . 105 6.1.4 Command-line LATEX . . . . . . . . . . . . . . . . . . . 106 6.1.5 Your Own Package . . . . . . . . . . . . . . . . . . . . 107 6.2 Fonts and Sizes . . . . . . . . . . . . . . . . . . . . . . . . . . 107 6.2.1 Font Changing Commands . . . . . . . . . . . . . . . 107 6.2.2 Danger, Will Robinson, Danger . . . . . . . . . . . . . 110 6.2.3 Advice . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 6.3 Spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 6.3.1 Line Spacing . . . . . . . . . . . . . . . . . . . . . . . 111 x CONTENTS 6.3.2 Paragraph Formatting . . . . . . . . . . . . . . . . . . 112 6.3.3 Horizontal Space . . . . . . . . . . . . . . . . . . . . . 113 6.3.4 Vertical Space. . . . . . . . . . . . . . . . . . . . . . . 114 6.4 Page Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 6.5 More Fun With Lengths . . . . . . . . . . . . . . . . . . . . . 117 6.6 Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 6.7 Rules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 A Installing LATEX 121 A.1 What to Install . . . . . . . . . . . . . . . . . . . . . . . . . . 121 A.2 Cross Platform Editor . . . . . . . . . . . . . . . . . . . . . . 121 A.3 TEX on macOS . . . . . . . . . . . . . . . . . . . . . . . . . . 122 A.3.1 TEX Distribution . . . . . . . . . . . . . . . . . . . . . 122 A.3.2 macOS TEX Editor . . . . . . . . . . . . . . . . . . . . 122 A.3.3 Treat yourself to PDFView . . . . . . . . . . . . . . . 122 A.4 TEX on Windows . . . . . . . . . . . . . . . . . . . . . . . . . 122 A.4.1 Getting TEX . . . . . . . . . . . . . . . . . . . . . . . 122 A.4.2 A LATEX editor . . . . . . . . . . . . . . . . . . . . . . 123 A.4.3 Document Preview . . . . . . . . . . . . . . . . . . . . 123 A.4.4 Working with graphics . . . . . . . . . . . . . . . . . . 123 A.5 TEX on Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Bibliography 125 Index 128