Book Image

LaTeX Cookbook - Second Edition

By : Stefan Kottwitz
Book Image

LaTeX Cookbook - Second Edition

By: Stefan Kottwitz

Overview of this book

The second edition of LaTeX Cookbook offers improved and additional examples especially for users in science and academia, with a focus on new packages for creating graphics with LaTeX. This edition also features an additional chapter on ChatGPT use to improve content, streamline code, and automate tasks, thereby saving time. This book is a practical guide to utilizing the capabilities of modern document classes and exploring the functionalities of the newest LaTeX packages. Starting with familiar document types like articles, books, letters, posters, leaflets, and presentations, it contains detailed tutorials for refining text design, adjusting fonts, managing images, creating tables, and optimizing PDFs. It also covers elements such as the bibliography, glossary, and index. You’ll learn to create graphics directly within LaTeX, including diagrams and plots, and explore LaTeX’s application across various fields like mathematics, physics, chemistry, and computer science. The book’s website offers online compilable code, an example gallery, and supplementary information related to the book, including the author’s LaTeX forum, where you can get personal support. By the end of this book, you’ll have the skills to optimize productivity through practical demonstrations of effective LaTeX usage in diverse scenarios.
Table of Contents (16 chapters)

Preparing your LaTeX tools

LaTeX has been around for many years. Over time, developers and authors contributed numerous extensions to its code base.

Such an extension could be one of the following:

  • Document class: A base file that is the frame of your document. It provides various formatting styles and usually comes with meaningful default settings, which can be changed via options when loading it. It often provides commands for authors to modify settings.
  • Package: A style file with a specific purpose that you can load in addition to the document class. Packages can be combined. Most of the time, we load many of them by executing the \usepackage command.
  • Bundle: A set of closely related packages or classes. In our next recipe, Writing a short text, we will get to know some bundles.
  • Template: A document with dummy text that you can take as a starting point and fill in your headings, texts, formulas, and images. We will look at templates in another recipe, Developing a thesis.

Those add-ons are incredibly valuable. They are one reason for the enduring success of LaTeX. We all agree that learning LaTeX can be challenging with its steep learning curve. However, if you don’t reinvent the wheel and start with a good template or class and a quality set of packages, you can quickly achieve great results.

The purpose of this book is to assist you in this regard.

Getting ready

To be able to work with LaTeX, you need to have the following installed on your computer:

  • TeX and LaTeX software, called a TeX distribution
  • A LaTeX editor, though you could use any text editor
  • A PDF viewer for seeing the final output

If you already have those installed, great! In that case, you can skip the following paragraphs and immediately proceed to the first recipe.

A PDF reader is probably already installed on your computer, such as Adobe Reader or the Preview app on the Mac. Furthermore, most editors come with an integrated PDF previewer. So, let’s have a look at TeX software and editors.

TeX and LaTeX distributions

There are TeX and LaTeX software collections ready to use and easy to install. Their websites provide install and update information. You may choose the download site for your system:

  • TeX Live: On https://tug.org/texlive, you can find download information and installation instructions for the cross-platform TeX distribution, which runs on Windows, Linux, Mac OS X, and other Unixes. It is supported by the TeX Users Group (TUG).
  • MacTeX: This is based on TeX Live and has been significantly customized for Mac OS X. Essential information is available at https://tug.org/mactex.
  • MiKTeX: A download and documentation for the Windows-specific distribution can be found at https://miktex.org.

If you own a Mac, I suggest selecting MacTeX. Otherwise, I recommend using TeX Live because the TUG provides excellent development and support.

Describing the setup is outside the scope of this book. For TeX Live, you can find a step-by-step explanation with screenshots in the LaTeX Beginner’s Guide by Packt Publishing. Generally, you can find detailed setup instructions when you visit the aforementioned internet addresses.

Finally, on Linux systems, such as Ubuntu, Debian, Red Hat, Fedora, and SUSE versions, a TeX Live-based software package is usually available via the operating system repositories. While it’s usually not as up to date as an installation via the TeX Live website or a TeX Live DVD, it’s straightforward to install using the Linux package manager you deploy to install any software there.

I strongly recommend choosing a complete LaTeX installation containing all available software, packages, and fonts. At the time of writing, it typically requires around 8 GB of disk space, but it guarantees you won’t encounter any missing packages or dependencies later.

LaTeX editors

There are many LaTeX editors, from small and quick to feature-rich editors. The TeX distributions already provide the fine editor TeXworks, which I use myself. You set it up with TeX or a package manager on Linux, and it can be downloaded from https://tug.org/texworks.

You can find a collection of LaTeX editors and additional software at https://latex.net/software. You may look for alternative editors running on your operating system there.

Using LaTeX online

A complete online cloud solution for LaTeX saves you from installing LaTeX software yourself. The most advanced one is called Overleaf and comes with an online LaTeX editor that runs in a web browser, so you can use it even on tablets and smartphones for storing, editing, and compiling even large LaTeX projects. You can find it at https://www.overleaf.com. While registration is necessary, basic access to the platform is free. Some advanced features require purchasing a subscription, but it’s worth noting that many universities and institutions partner with Overleaf and provide enhanced licenses for their students and employees.

The LaTeX Beginner’s Guide explores Overleaf in more detail; you can find this section online at https://latexguide.org/overleaf.

If you need help setting up and using LaTeX or an editor, you can visit a LaTeX web forum such as https://latex.org. In Chapter 12, Getting Support on the Internet, you can find their addresses and how to use them. You can also meet me there and ask me and our fellow forum users any LaTeX-related questions.

Once you have done the installation or online setup, you can start with a LaTeX recipe from the following sections.

See also

Many LaTeX tutorials available on the internet can help you with the first steps. I recommend looking at the following:

  • https://learnlatex.org covers the most essential LaTeX basics in short lessons in 10 languages. It is very modern and comes with an online compiler for its examples.
  • https://texdoc.org/pkg/lshort is the web link for The not so short introduction to LaTeX2e, a famous introductory text. It has been translated into more than 20 languages, available at https://ctan.org/pkg/lshort.
  • https://www.overleaf.com/learn takes you to the Overleaf knowledge base with various guides and many articles about LaTeX.
  • https://en.wikibooks.org/wiki/LaTeX takes you to the LaTeX Wikibook, a collaboratively created extensive guide.
  • https://www.dickimaw-books.com/latex/novices contains the free introductory book LaTeX for Complete Novices by Nicola L. C. Talbot. It is somewhat dated but OK for the first steps.
  • https://latex2e.org hosts the Unofficial reference manual for LaTeX, an excellent resource whenever you need to know how to use specific LaTeX commands, environments, arguments, and syntax in general.
  • https://latexguide.org is the website for the LaTeX Beginner’s Guide, with a sample chapter, all code examples by chapter, reviews, and additional information in case you’re considering buying a modern book on paper or in electronic format.

If you still need to learn LaTeX, read one of the guides, and you will then be well prepared to get the best out of this book.