34,79 €
LaTeX is high-quality open source typesetting software that produces professional prints and PDF files. It's a powerful and complex tool with a multitude of features, so getting started can be intimidating. However, once you become comfortable with LaTeX, its capabilities far outweigh any initial challenges, and this book will help you with just that!
The LaTeX Beginner's Guide will make getting started with LaTeX easy. If you are writing mathematical, scientific, or business papers, or have a thesis to write, this is the perfect book for you. With the help of fully explained examples, this book offers a practical introduction to LaTeX with plenty of step-by-step examples that will help you achieve professional-level results in no time. You'll learn to typeset documents containing tables, figures, formulas, and common book elements such as bibliographies, glossaries, and indexes, and go on to manage complex documents and use modern PDF features. You'll also get to grips with using macros and styles to maintain a consistent document structure while saving typing work.
By the end of this LaTeX book, you'll have learned how to fine-tune text and page layout, create professional-looking tables, include figures, present complex mathematical formulas, manage complex documents, and benefit from modern PDF features.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 359
Veröffentlichungsjahr: 2021
Create visually appealing texts, articles, and books for business and science using LaTeX
Stefan Kottwitz
BIRMINGHAM—MUMBAI
Copyright © 2021 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Rohit Rajkumar
Publishing Product Manager: Ashitosh Gupta
Senior Editor: Hayden Edwards
Content Development Editor: Rashi Dubey
Technical Editor: Simran Haresh Udasi
Copy Editor: Safis Editing
Project Coordinator: Manthan Patel
Proofreader: Safis Editing
Indexer: Manju Arasan
Production Designer: Roshan Kawale
First published: March 2011
Second edition: August 2021
Production reference: 1030921
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80107-865-8
www.packt.com
To the members of TUG and DANTE for supporting TeX and LaTeX development, infrastructure, and education. To all the helpers on internet forums for their tireless support for LaTeX beginners.
– Stefan Kottwitz
Stefan Kottwitz studied mathematics in Jena and Hamburg. He works as a network and IT security engineer both for Lufthansa Industry Solutions and for Eurowings Aviation.
For many years, he has been providing LaTeX support on online forums. He maintains the web forums LaTeX.org and goLaTeX.de and the Q&A sites TeXwelt.de and TeXnique.fr. He runs the TeX graphics gallery sites TeXample.net, TikZ.net, and PGFplots.net, the TeXlive.net online compiler, the TeXdoc.org service, and the CTAN.net software mirror. He is a moderator of the TeX Stack Exchange site and matheplanet.com. He publishes ideas and news from the TeX world on his blogs LaTeX.net and TeX.co.
Before this book, he authored the first edition of LaTeX Beginner's Guide in 2011, and LaTeX Cookbook in 2015, both published by Packt.
LianTze Lim has reveled in the joys and beauty of LaTeX typesetting for nearly two decades. She is currently Community TeXpert at Overleaf and has been helping Overleaf users with LaTeX-related questions since 2014.
Joseph Wright is the author of the popular siunitx package for units, leads maintenance of the beamer class, and is a member of the LaTeX project. He is also one of the moderators on the popular TeX – LaTeX Stack Exchange Q&A site.
You are familiar with word processing software: you type something, and the software prints it as it is on screen. In contrast, LaTeX, as typesetting software, receives instructions and text from you, and then creates the output. It produces high-quality output based on sophisticated algorithms for justification, text alignment, whitespace balancing, figure placement, and more, such as predefined formatting styles for headings and general page layout, which you can customize.
Are you ready to leave those "what you see is what you get" word processors behind and to enter the world of accurate, reliable, and high-quality typesetting? Yes? Then let's go together!
It's great that you decided to learn LaTeX. This book will guide you along the way to help you get the most out of it. Let's speak briefly about LaTeX's benefits and the challenges, and then we shall prepare our tools.
In this chapter, we will get to know LaTeX, as well as how to install and use it. Specifically, our topics will be as follows:
What is LaTeX?Installing and using LaTeXWorking with LaTeX online using OverleafAccessing documentationAt the end of this chapter, you will have working LaTeX software, and you will know how to edit and typeset a document and how to obtain further documentation.
So, let's get started.
We will focus on the Windows operating system here, but you can also install LaTeX on Mac OS X, Linux, and other systems.
A complete installation takes about 8 GB of disk space.
If you have an internet connection, you don't have to install LaTeX. You can use online LaTeX software, such as Overleaf. We will look at Overleaf at the end of this chapter.
All code examples of this book are available on GitHub at https://github.com/PacktPublishing/LaTeX-Beginner-s-Guide.
On the book's website, https://latexguide.org, you can read, edit, and compile every code example in this book online without installing anything. An internet browser with JavaScript enabled is all you need for this, and a PC, laptop, tablet, or smartphone.
LaTeX is free, open source software for typesetting documents. In other words, it's a document preparation system. LaTeX is not a word processor, but it's a document markup language.
It was initially written by Leslie Lamport and is based on the TeX typesetting engine by Donald Knuth. People often refer to it as just TeX, meaning LaTeX. It has a long history; you can read about it at https://tug.org/whatis.html.
For now, let's continue by looking at how we can make the most of LaTeX.
LaTeX is especially well suited for scientific and technical documents. LaTeX's superior typesetting of mathematical formulas is legendary. Suppose you are a student or a scientist. In that case, LaTeX is by far the best choice, and even if you don't need its scientific capabilities, there are other uses—it produces very high-quality output and is incredibly stable. It handles complex documents easily, no matter how large they are.
Some more remarkable strengths of LaTeX are its cross-referencing capabilities, the ability for automatic numbering, and the generation of lists of contents, figures and tables, indexes, glossaries, and bibliographies. It is multilingual with language-specific features, and it can use PostScript and PDF features.
Apart from being perfect for scientists, LaTeX is incredibly flexible—there are templates for letters, presentations, bills, philosophy books, law texts, music scores, and even chess game notation. Hundreds of LaTeX users have written thousands of templates, styles, and valuable tools for every possible purpose. It is collected and categorized online on archiving servers.
You could benefit from its impressive high quality by starting with its default styles and relying on its intelligent formatting, but you are free to customize and modify everything. People of the TeX community have already written a lot of extensions addressing nearly every formatting need.
The code of LaTeX is entirely open source, free, and readable for everyone. This enables you to study and change everything, from the core of LaTeX to the latest extension packages. But what does this mean for you as a beginner? There's a huge LaTeX community with a lot of friendly, helpful people. Even if you cannot benefit from the open source code directly, they can read the source and assist you. Just join a LaTeX web forum and ask your questions there. Helpers will, if necessary, dig into LaTeX sources and, in all probability, find a solution for you, sometimes by recommending a suitable package, often providing a redefinition of a default command.
Today, we're already profiting from about 30 years of development by the LaTeX community. The open source philosophy made it possible, as every user is invited to study and improve the software and develop it further. Chapter 14, Using Online Resources, will point the way to the community.
A fundamental principle of LaTeX is that the author should not be distracted too much by formatting issues. Usually, the author focuses on the content and formats logically. For example, instead of writing a chapter title in big, bold letters, you just tell LaTeX that it's a chapter heading. You can let LaTeX design the heading or decide in the document's settings what the headings will look like—just once for the whole document. LaTeX extensively uses style files called classes and packages, making it easy to design and modify the entire document's appearance and all of its details.
LaTeX is available for nearly every operating system, such as Windows, Linux, Mac OS X, and many more. Its file format is plain text, readable and editable on all operating systems, which means LaTeX will produce the same output on each system. There are several LaTeX software packages, which we call TeX distributions. We will focus on the TeX Live distribution since this one is available for Windows, Linux, and Mac OS X. On the Mac, the native TeX Live version is called MacTeX.
LaTeX doesn't have a graphical user interface; that's one of the reasons why it's so portable. You can choose any text editor. There are many editors, even specialized in LaTeX, for every operating system. Some editors are available for several systems; for instance, TeXworks runs on Windows, Linux, and Mac OS X, which is one of the reasons why we will use it in our book. Another significant reason is that it's probably best suited for beginners.
LaTeX generates PDF output, which is printable and readable on most computers and looks identical regardless of the operating system. Besides PDF, it supports DVI, PostScript, and HTML output, preparing the ground for distribution both in print and online, such as on personal computers, electronic book readers, and smartphones. To sum up, LaTeX is portable in three ways: your source, implementation, and output.
LaTeX documents are stored in human-readable text format, not in some obscure proprietary word processing format, that may be altered in a different version of the same software.
Try to open a 20-year-old document written with a commercial word processor. What might your modern software show? Even if you can read the file, its visual appearance would undoubtedly be different than before. LaTeX promises that the document will always be readable and will result in the same output. Even though it's further developed, it will remain backward compatible.
Word processor documents could be infected with viruses, and malicious macros could destroy the data. Did you ever hear of a virus "hiding" in a text file? LaTeX documents are not threatened by viruses.
The learning curve could be steep, but this book will help you master it.
Though writing LaTeX looks like programming, don't be afraid. Soon you will know the frequently used commands, while text editors with auto-completion and keyword highlighting will support you. They might even provide menus and dialogs with commands for you.
Do you still think it will take a long time until you can learn to achieve creditable results? Don't worry; this book will give you a quick start. You will learn by practicing with a lot of examples. Many more examples can be read and downloaded from the internet. In Chapter 14, Using Online Resources, we will explore online resources. There are LaTeX help forums where you get answers to your questions. Specifically, https://latex.org has a forum dedicated to the readers of this book. Visit us there!
There are two ways to approach working with LaTeX:
The traditional way is to install LaTeX on your own computer. It's pretty straightforward, and we will walk through installing on Windows in the Installing and using LaTeX section.Another way is to use LaTeX online in the cloud. No installation is needed; all you need is an internet-connected computer, tablet, or phone. We will explore this option in the Working with LaTeX online using Overleaf section at the end of this chapter.Now, we will continue with the setup of LaTeX on our computer. If you like, you could skip it for the moment and jump to the Working with LaTeX online using Overleaf section, and then decide which approach you would like to take.
Let's start with the installation of the LaTeX distribution, TeX Live. This distribution is available for Windows, Linux, Mac OS X (MacTeX), and other Unix-like operating systems. TeX Live is well maintained, and it is actively developed.
Alternative LaTeX distribution
Another excellent and user-friendly LaTeX distribution for Windows is MiKTeX. It's easy to install, like any other Windows application. You can download it from https://miktex.org. Visit https://latexguide.org/distributions for a detailed, up-to-date comparison.
You can install TeX Live for a single user (that's you) or as a shared installation for all users on a computer. The latter is called admin mode. It requires running the installation as an administrator: either log in with an administrator account or right-click on the install program and choose Run as administrator.
It is recommended to install in single-user mode.
First, we will visit the TeX Live homepage and take a survey of the installation possibilities. To do this, open the TeX Live homepage using https://tug.org/texlive/:
Figure 1.1 – TeX Live home page
Feel free to explore the home page in depth to study the information offered there, though, in this book, we will cover two types of installation:
Installing TeX Living using the net installer wizard; this will be online and requires an internet connection.Installing TeX offline; this starts with a considerable download, but then we can do it offline.Before we start the installation, let's have a look at LaTeX packaging conventions with different granularity:
A package, also called a style file, is a single LaTeX file with some macros to add specific features or provide a particular look and document style. It has the filename extension .sty.A bundle is a set of packages with a similar purpose. It may also contain class files that have the filename extension .cls.A collection is a larger set of packages for a field of interest. That can be, for example, an extensive set of math and natural science packages, music packages, or graphics-related packages.A scheme is a LaTeX installation of a specific size. That can be minimal (the smallest to be able to work), basic (commonly needed stuff), or full (everything available).We can now install and update LaTeX with this understanding. The easiest option is to install everything fully, that is, the full scheme. That way, you will not miss any packages.
Let's check out two installation methods on a Windows PC. The first one will be installing over the internet, which requires a good internet connection. If you don't have a good internet connection, go to the next section, Installing TeX Live offline.
We will download the TeX Live net installer and install the complete TeX Live distribution on our computer. To do this, follow these steps:
Click on download as seen in Figure 1.1, or go to https://tug.org/texlive/acquire-netinstall.html:Figure 1.2 – Installation instructions
Download the executable installer program, install-tl-windows.exe, and run the program.Confirm the installation mode (as a Single-user or as the Administrator), click Next, and then Install.The net installer will automatically detect your operating system language. You can change the language of the Graphical User Interface (GUI) by clicking on GUI language in the menu of the window that opens, as we can see in Figure 1.3:Figure 1.3 – TeX Live Installer
You can change the installation root, that is, the location of all TeX Live installed files on your hard drive. That complete default installation is fine, though you can click on Advanced to determine what shall happen more specifically, as you can see here:Figure 1.4 – TeX Live Installer advanced options
You can change the Scheme (options include Full, Medium, and Small) and customize the number of software collections, such as installed formats, fonts, styles, graphics packages, editor, language support, and many more. As the recommended options are already the most significant parts of the installation, unchecking some collections won't save much space. The full scheme is recommended.Click on Install to proceed. Now, there's no interaction needed for a long time, and you can lean back while all the thousands of TeX packages are downloaded and installed:Figure 1.5 – Installation progress
Finally, you will get a welcome message. Finish by clicking on Close.You have completed the installation of TeX Live. Now your Start menu contains a TeX Live 2021 folder containing six programs:
Figure 1.6 – TeX Live in the Windows Start menu
Let's briefly look at each of the programs:
DVIOUT DVI viewer—a viewer program for the classic LaTeX output format DVI (today, most people choose PDF output, so you probably won't need this).TeX Live command-line—use this if you would like to run other TeX live programs at the command line.TeX Live documentation—opens the TeX Live manual in your web browser.TeX Live Manager—this is your tool for package management (for example, for installing and updating LaTeX packages).TeXworks editor—this is an editor that was developed to create LaTeX documents comfortably. We will make extensive use of TeXworks in this book.Uninstall TeX Live—use this before you install a new TeX Live version from scratch, or if you would like to install MiKTeX instead.Now we will go through the offline installation of TeX Live.
Every year, the TeX user group creates a TeX software collection DVD and sends it to their members. You can get a DVD from a TUG member or purchase it from the TUG web store, where it's listed for $16 in 2021. But we can download the DVD's content for free.
We will now download an ISO image of TeX Live with a size of about 4 GB. After extraction, we can burn it on a DVD and run the installation from there. To do this, follow these steps:
Visit the download area at https://tug.org/texlive/acquire-iso.html.Download the texlive.iso file. If possible, use a download manager, especially if your internet connection is not stable.Either burn the ISO file on a DVD using burning software that supports the ISO format, or extract it to your hard disk drive. For example, the free program 7-zip can extract ISO files.Among the extracted files or on your DVD, you will find the installer batch files install-tl and install-tl-advanced. Choose one, start it, and go through the installation similar to the online installation. More information is available on https://tug.org/texlive/quickinstall.html.Installing TeX offline was just like the first installation. Still, this time you've got all the data, and you won't need an internet connection during the installation or for another installation. This download approach is especially recommended if it's foreseeable that you will install TeX Live on another computer later, or if you would like to give it to friends or colleagues.
As TeX runs on other operating systems as well, let's take a brief look at other systems.
TeX also runs on a lot of systems other than Windows. Here's a quick glance:
Mac OS X: You can download a customized version of TeX Live at https://tug.org/mactex/. Download the huge .pkg file and double-click on it to install. It will print very straightforward instructions.Ubuntu Linux: Use the Software Center to install TeX Live packages, or run sudo apt-get install texlive-full to get everything.Debian Linux: Use Synaptic to install TeX Live packages, or run apt-get install texlive-full (via sudo or as root user) to get everything.Red Hat, CentOS, and Fedora Linux: Use the Red Hat package manager, or yum via Command Prompt, such as yum install texlive-scheme-full, or DNF: sudo dnf install texlive-scheme-full.Others: Visit https://tug.org/texlive/quickinstall.html and follow the instructions.If you want to stay on the edge, you could download and install the most current version of TeX Live from its home page instead of the version from the operating system's repositories, as mentioned in the last point.
If we need to update or add packages, the following section shows you how.
The LaTeX developers update it continuously, both for new features and for bug fixes. From time to time, you can update your system.
To do this, go to the Start menu, then the TeX Live folder, and start the TeX Live Manager (also referred to as tlmgr for short, and also called TeX Live Shell). This application is both for updating and installing additional packages. Take a look at this screenshot so we can talk about how to use the TeX Live Manager:
Figure 1.7 – The TeX Live Manager
The first section in the TeX Live Manager shows the Repository. A repository is a server with a TeX Live software archive. If the default repository is unavailable or is too slow in your area, you can click on Options to choose another repository from a list.
Click on File | Load repository to synchronize LaTeX with the latest software status.
In the PACKAGE LIST section, you can search packages by name or filter the view to see all available packages or only those installed, not installed, or updatable. In the middle of Figure 1.7, you can see an option to change the granularity to see all the packages or only collections or schemes.
The lowest section shows the packages when a filter is selected, with a short description and the version. You can choose packages here. Then you can click on Install marked if you would like to install the selected packages or click on Remove marked to uninstall them.
An easy way is just to click on Update all. If the Update tlmgr button is enabled and clickable, then there's a TeX Live Manager update available, and you can click the Update tlmgr button to update.
Yearly updates
The update procedure is only for the same TeX Live version. Every year, there's a new TeX Live version with the year as the version number. It would be best to uninstall the current TeX Live for a yearly upgrade and then install the new version from scratch. On https://tug.org/texlive/, you can see the upgrade plan with estimated dates.
Now that we've prepared the ground, let's start to write LaTeX!
We've installed TeX and an editor; now, let's jump in at the deep end by writing our first LaTeX document using the TeXworks editor.
For Mac users
Please use the Cmd key when you see the Ctrl key here.
Our first goal is to create a document that prints out just one sentence. We want to use it to understand the basic structure of a LaTeX document. To do this, follow these steps:
Launch the TeXworks editor by clicking on the desktop icon or by opening it in the Start menu. In Figure 1.8, you can see the editor with the menu, buttons, and toolbar.Click on the New button (or type Ctrl + N) or choose File | New in the menu.Enter the following lines:\documentclass{article}
\begin{document}
This is our first document.
\end{document}
Click on the Save button (or type Ctrl + S) to save the document. Choose a location where you want to store your LaTeX documents, ideally in its own folder.Make sure that in the drop-down field in the TeXworks toolbar, pdfLaTeX is selected (this should be the default anyway):Figure 1.8 – The TeXworks editor
Click the Typeset button or press Ctrl + T.The output window will automatically open. Have a look at it:Figure 1.9 – The PDF output in the TeXworks editor
Those were the first few minutes of the life of a LaTeX document. You may edit it, typeset and check the output, and edit again. Don't forget to save your document frequently.
As mentioned earlier, in contrast to the classic word processor software, you cannot see the effect of changes immediately—but the result is just one click away.
Do you have experience in working with complex programs? Do you like using a feature-rich and powerful editor? Then have a look at these LaTeX editors. Visit their websites to find screenshots and to read about their features:
Texmaker—a cross-platform editor running on Windows, Linux, Mac OS X, and Unix systems: https://xm1math.net/texmaker/TeXstudio—another cross-platform editor for Windows, Linux, Mac OS X, and Unix systems: https://texstudio.org/Kile— a user-friendly editor for operating systems with KDE, such as Linux: https://kile.sourceforge.io/TeXShop—an easy-to-use and very popular editor for Mac OS X: https://pages.uoregon.edu/koch/texshop/These editors are free, open source software. You can find more at https://latexguide.org/editors.
Online editors run on any internet-capable operating system. Let's take a close look at an online editor and compiler in the following section.
Installing LaTeX on your computer is recommended, but it can take up about 8 GB on your hard drive and two hours to install it.
How about simply using LaTeX in your internet browser? Here comes Overleaf. It's a pure online LaTeX service that mathematicians enthusiastic about TeX started in 2011. You can access it through this link: https://www.overleaf.com.
In this section about Overleaf, we will do the following:
Check the Overleaf requirementsLook at the benefits of OverleafEvaluate possible caveatsUse the Overleaf editorTry out WritefullLet's go online now.
To use Overleaf, you need the following:
Any internet browser, such as Firefox, Chrome, Opera, or Edge.You don't need any other local software such as a LaTeX compiler, editor, or PDF viewer.It is free for basic usage, and that covers a lot. It provides a complete TeX Live with unlimited projects and a feature-rich editor, real-time-sync collaboration with another user, and hundreds of templates to start with. You can easily write your thesis or book with Overleaf with free usage.
An advanced personal or professional subscription costs money and provides additional features, such as the following:
Unlimited collaborators per projectDocument history (going back and forth between document versions)Advanced bibliography management (with Mendeley)Dropbox sync integrationGitHub integrationPriority personal supportThe advanced features go beyond regular LaTeX. You can check if you are eligible; many universities and institutions partner with Overleaf to provide their members the full service.
Let's look at what you can gain when using Overleaf, compared to using classic editors locally on your computer. With Overleaf, you can do the following:
Use it on any device, such as a PC, laptop, tablet, or smartphone.Use it on a locked-in work computer where you cannot install anything yourself.Access your own files on any device (be it a private or work or library computer) once you log in with your password.If you invite somebody to work with you, both of you can instantly edit and see each other's changes, making collaboration easy.Have an automatic real-time view of the PDF result while you type.Access a version history for LaTeX projects to track changes.Annotate LaTeX source code with comments and answers to them.Work with a new LaTeX software without doing an upgrade.However, there are some challenges to Overleaf. Let's think about that now.
To be clear, there can be some caveats:
You always need the internet available.As your documents are stored online, you have to rely on data security and privacy by Overleaf. See https://www.overleaf.com/legal.