Matthias K. Gobbert

Introduction to LaTeX and Overleaf

LaTeX2e - July 2021


This page can be reached via my homepage at http://www.umbc.edu/~gobbert.

Note on Approach

This page starts with a classical introduction to LaTeX, which would use a local installation and involve processing of a tex source code file into a PDF file by explicit call of a command. I believe, this is useful to read, since it clarifies the concept of LaTeX. But many people use LaTeX in the cloud nowadays at Overleaf (overleaf.com), which is like Google Docs for LaTeX and capable of multiple authors editing a LaTeX document simultaneously. I address Overleaf near the bottom of this page.

Purpose of this Document

This webpage is used as a repository for useful information on LaTeX. The information in this page should be applicable, no matter under which operating system you use LaTeX. When processing under the Linux operating system for example, the compile command would be pdflatex typically nowadays. See your local information how to process LaTeX under other operating systems.

You are welcome to tell others about this page and to create a link to it. Instead of providing a live link to this page, I suggest to link to my homepage like I have done above. I have tried my best to be brief as well as accurate, but you will know how hard this is, if you tried to put together a document like this yourself. If you find any mistakes or have comments, please contact me at gobbert@umbc.edu.


What is LaTeX?

LaTeX is a macro package written by Leslie Lamport on top of the type-setting system TeX by Donald Knuth. The name derives from the Greek word "tex," meaning "to write." TeX's version has been permanently frozen at 3.14159 (go figure, this shows that mathematicians were involved). LaTeX and TeX are not word-processors, because the phrase "what-you-see-is-what-you-get" (WYSIWYG) does not apply, rather they are professional-grade typesetting systems, formally only available to publishing companies.

In more modern web-parlance, they are mark-up languages, in which the writer merely indicates the structure of the document (e.g., "start a new section here" but the actual appearance is controlled by class and style files (e.g., how a section header is actually formatted). Here is an example of the most basic LaTeX source code file in the plain text file hello.tex:

\documentclass[12pt]{article}
\begin{document}
  Hello, world!
\end{document}
LaTeX commands start with a backslash \, and required arguments are enclosed in curly braces. The first line chooses the documentclass article, with the optional arguments in brackets specifying a 12 pt fontsize. All text that you want to appear in the final output hello.pdf appears between the begin and end of the document environment, in this example the classical "Hello, world!" text. To obtain the PDF output from the tex input, you call LaTeX like a compiler for source code programming languages.

A lot of other things could be said here, for instance, about the choice of the name and its Capitalization (to avoid patent infringement on the material latex as in "latex gloves" I refer to the section on "The Game of the Name" in Lamport's book; see below for full reference.

Side-note on the effect of all this: LaTeX has turned math professors into typesetters and publishers like Elsevier and Springer into glorified copy shops: They receive a type-set and fully paginated book from the author, all the publisher does is to have the master copy "photo-copied," send it to the binder, and put a cover around it. But LaTeX has also taken over journals and conference proceedings. Thus, you often have to submit fully functioning LaTeX files at the outset of the submission process. And even if not at the outset, you later have to submit it in that form and thus it is a good idea to use the journal's class and style files from the beginning. And because of this need, it is necessary to learn LaTeX yourself and early on, which is why I created this webpage.

Additionally, let me point out that there are also various other versions of TeX and LaTeX, like AMS-TeX and AMS-LaTeX, propagated by the American Mathematical Society. Those are genuinely different packages than TeX or LaTeX with quite different appearance and partially different commands; I try to avoid using extensions as much as possible.

On the other hand, as LaTeX is freely distributed, there are distributions of it, like teTeX included with Linux distributions. Such distributions include, if they are LaTeX2e compatible, a large number of so-called standard packages like amsmath, cite, graphicx, and many others, all of which are not part of LaTeX, but genuine extensions that provide additional features and functionality.


Where to Find General Documentation

There are many sources of information available, most notably books for sale or in the library, handouts and similar material distributed inofficially, and pages on the web (like this one). In all cases, you should only accept recent information that pertains to the current version of LaTeX! LaTeX's present version as of writing this document is known as LaTeX2e. The previous version has become known as LaTeX 2.09. Be critical with all information given to you, in particular, if it comes from sources, whose credibility and competence you cannot assess well (like on the web or inofficial hand-outs)! Unfortunately, library books are often out-of-date, as well, as are even well-meaning sites like this one.

The books listed below are all appropriate for LaTeX2e. The starting point should always be the book by Leslie Lamport, which is both concise and readable and which explains LaTeX's philosophy well. The price paid for both is lack of completeness, when it comes to advanced features. In this context, "advanced features" include redefining section headers, importing files, and overcoming the struggle with float placement. I have found both the book by Frank Mittelbach et al. as well as the one by George Grätzer useful - in different ways: Mittelbach et al. is organized `horizontally' and discusses material organized by package; I suggest to use it, if you want to dig into the innards of LaTeX2e like redefining section headers or advanced float placement. Compared to that, Grätzer is organized `vertically,' because it discusses tools for one topic from all available sources together. If you need to typeset very complicted formulas or have other problems with the mathematics, I recommend Grätzer because of its well-chosen examples and its organization.

Considering we are in the 21st century, I must mention the huge repository for information and macros put out by the TeX Users Group (abbreviated as TUG). You can find them at http://www.tug.org/. There is a wealth of information available including style files and similar. Or for that matter, I have been rather successful with google searches, if I had specific problems.

Recommended books:

  1. Frank Mittelbach, Michel Goossens, Johannes Braams, David Carlisle, Chris Rowley, The LaTeX Companion, Addison-Wesley, 2nd edition, 2004. Link to its webpage
  2. George Grätzer, Math into LaTeX, Birkhäuser, 3rd edition, 2000.
    Link to its webpage
  3. Leslie Lamport, LaTeX: A Document Preparation System, second edition, Addison-Wesley, 1994. Link to its webpage

Short Sample Document for LaTeX2e

Here is a short sample document that demonstrates the use of many commands that might typically be needed to typeset mathematics in LaTeX. The file is old and was designed to avoid any advanced features. So, on the one hand, its outline as a document is basic, and it demonstrates rather plain use of, for instance, the thebibliography environment. It also contains a wealth of examples of the typsetting of the most common mathematical constructs like fractions and matrices. Therefore, on the other hand, you can simply study this sample file as a quick introduction to LaTeX by reading this tex source code. For more advanced features, see the Template for Project Reports below.

Click on this link to sample.tex to download it to your computer. To process the file, use the following command sequence at the Unix/Linux prompt:
pdflatex sample.tex
pdflatex sample.tex
Notice that running LaTeX twice is needed to get the automatic cross-referencing right. The resulting PDF file sample.pdf should be identical to the one I processed and that is posted here as sample.pdf.


Template for Project Reports

This template was originally created to improve the uniformity in appearance of project reports in my classes. Since then, it has been improved to provide a repository for demonstrating the use of more advanced features than the basic sample document above does. The features include sophisticated cross-referencing, the importing of plots and computer code, and the use of BibTeX, in particular. They also include comments on float placement and answers to frequently asked questions like how to count formula numbers by section. Fundamentally, the document is self-contained in the sense that its text explains the use of the features, both syntactically and stylistically. Therefore, it is vital to read both the actual text and the LaTeX source code carefully. However, if you do not know how to get started, you may want to download the final result in PDF format, which contains information (on Pages 2 and 8) on what to download and how to process the LaTeX source code to reproduce the result.

Files needed to use the template: The LaTeX source template.tex needs several other files, namely the bibliography database file template.bib, the files for the figures, and the Matlab code (that is used as example how to include code). The zip file below contains all these needed files.


Other Information

If you are looking for information about using Unix/Linux at UMBC, which may be helpful, if you use LaTeX on such a machine, go to my homepage.

A particular book to point to is Nicholas J. Higham, Handbook of Writing for the Mathematical Sciences, third edition, SIAM, 2020. If you are a Ph.D. student, I strongly recommend that you read this book, because it addresses many question about how publishing works in the sciences.

For a more complete literature list covering also other aspects of mathematics, see my homepage.


Overleaf --- Google Docs for LaTeX

The webpage app Overleaf is a LaTeX editor in the cloud and accessed via a web browser, thus you do not have to install LaTeX locally on your computer. Moreover, you can share the document with co-authors to facilitate joint editing of the document.

After creating an account at overleaf.com, you can create a new project on the upper left. The easiest way is to use Upload Project by dropping a zip file onto the page. You can use the template.zip of the project report template above. Overleaf will automatically start processing LaTeX (and BibTeX) on the files in the zip archive. Notice how the resulting PDF file looks exactly like the PDF file template.pdf posted above that I processed manually under a Linux operating system! The narrow left-hand panel of the screen will list the files in the project. The rest of the screen should show two main portions, the center one the tex source code and the right one the processed PDF file.

Overleaf has lots of neat features, like being able to jump to the corresponding source code line in the tex file by double-clicking in the PDF file or navigating between the files with the arrows on the vertical divider between tex and PDF file. This feature is particulary useful for my template file, since that is designed to have you read tex and PDF next to each other simultaneously to see by example, how the output was created from the LaTeX commands. Note that you can make either of these full-screen by clicking on each's upper right corner; reverse this process by clicking on the upper right to split the screen again. It is important that you read the logs for errors and warnings; these can be found by clicking on the document logo to the right of the Recompile button on top of the PDF document.


Copyright © 1997-2021 by Matthias K. Gobbert. All Rights Reserved.
This page version 5.6, July 2021.