SUNY Geneseo Department of Mathematics

A Minimalist Introduction to LaTeX

Doug Baldwin
SUNY Geneseo

Last modified January 30, 2024

LaTeX is the leading software for producing high-quality mathematical and technical documents. It has professional-typographer-level knowledge of spacing and layout for equations (both horizontal and vertical), of other mathematical formatting conventions, of how to lay out paragraphs and pages for best readability, and in fact of how layout varies between different kinds of document, of how to number and cross-reference things, etc. It is sometimes described as “typesetting software” to contrast it with more common word processing software, which is typically easier to use but produces less professional-looking results.

In this tutorial I introduce how LaTeX wants its users to think about documents. I cover very little of the LaTeX notation itself, because there are many other very good tutorials and reference manuals for that. Instead, I concentrate on a few overarching concepts, understanding of which will make it easier for you to use those other sources to learn as much or as little as you want about the rest of LaTeX, when you want to learn it.

Getting LaTeX

The name “LaTeX” refers to both a notation for marking up text to indicate what pieces of it are equations, titles, proofs, tables, etc., and to a computer program that translates that notation into a nice-looking document (usually a PDF file). The following sections introduce the notation, but first this one says a little bit about getting the program so you can experiment with the notation as you learn it.

LaTeX was developed in the 1980s, and has been maintained and extended ever since. By now it is a very large body of software, including a core group of programs and files that define the basic notation, and an every-growing body of extensions, auxiliary programs, etc. The core software has been free since its creation and will likely remain that way; most extensions and related programs are also free, or at least have free versions.

It’s easiest to work with LaTeX through a LaTeX-specific editor. Online ones are probably the simplest to get started with, since you don’t need to install anything on your own computer. Overleaf (https://www.overleaf.com) is a popular example of such a service.

If you prefer to install LaTeX and an editor on your own computer, start at the “Comprehensive TeX Archive Network,” or CTAN (https://ctan.org), which is the Internet home for almost everything LaTex-related. In particular, it includes downloads of complete LaTeX installations for all common computer systems, and links to, if not actual downloads of, editors for those installations.

A Mark-Up Language

The LaTeX notation is a “mark-up language.” This means that when you create a document with LaTeX, you mostly write ordinary text, but every so often drop commands to the LaTeX program into that text. LaTeX commands are words or symbols prefixed by “\” and sometimes followed by arguments enclosed in curly brackets (“{” and “}”). For example, here is a sentence that might appear in a LaTeX document:

Welcome to \LaTeX!

Most of this produces exactly what it looks like, namely the words “Welcome” and “to,” and an exclamation point. However, \LaTeX is a command that tells LaTeX to write the string “latex” into the final document, using character styles and placements that produce a whimsical effect promoted by Leslie Lamport, the creator of LaTeX (and approximated by the plain-text form “LaTeX”). Here is a PDF file containing the document produced from this example.

What you see as you prepare a LaTeX document is plain text with LaTeX commands in it, not what the final document will look like — unlike word processors, LaTeX is not a “what you see is what you get” program. Instead, you prepare your “input” or “source” document in a LaTeX editor, then tell LaTeX to “compile” it into the output document. In most LaTeX editors, compiling is just a matter of clicking a button, and the output is typically a PDF file. Editors generally save LaTeX source documents in other files, usually with a name that ends in “.tex”.

LaTeX pioneered a principle of mark-up languages that has since become widespread, namely that mark-up commands should indicate what a piece of a document is, not how it should look. Thus, for example, you might use a LaTeX command to say that a certain block of text is a theorem statement, but you would not say that it should be prefaced with the word “Theorem” and a number, or be typeset in italic characters. LaTeX would do those things for you, if they were appropriate for the particular kind of document you were writing. That last point is crucial: by marking text up for what it is rather than how it looks, you allow the software that processes the text to change its appearance as its uses change. You will therefore find that most of the LaTeX commands you use help you say what your text is. LaTeX does have some commands that control appearance, but most of the time you won’t need them, and if you have a choice of ways to accomplish some task, try to do it by saying what you’re writing, not what you think it should look like.

Document Structure

LaTeX expects source documents to have a certain structure. These expectations govern where you can put certain commands, and what parts of your document they affect. Understanding the structure of a LaTeX document is thus vital to using LaTeX well.

Preamble and Body

At the highest level of structure, every LaTeX document begins with some preliminary definitions and descriptions of your document, followed by the actual text of the document. The preliminary material is called the document’s “preamble,” and the actual text of the document is called its “body.”

Here is a very simple LaTeX document that illustrates preamble and body:

\documentclass{article}

\begin{document}
Welcome to \LaTeX!
\end{document}

At the very least, a preamble has to say what kind of document you’re writing. This is what the \documentclass command does, so every LaTeX source document begins with \documentclass, followed by the kind, or “class,” of document in braces. In the example above, the document is an article; another common possibility is a book, and most mathematical and technical publishers have LaTeX document classes for the specific kinds of papers, talks, articles, etc. that they publish. For most purposes short of preparing an actual scholarly publication, “article” is a good generic document class for LaTeX.

Every document’s body starts with \begin{document}, and ends with \end{document}. Whatever appears between those two lines is what will appear in the output LaTeX produces. Thus this example produces an output containing the sentence “Welcome to LaTeX!”, as described in the earlier discussion of LaTeX as a mark-up language.

The blank line between the example’s preamble and body makes the source easier to read, but has no effect on the output.

The above example is a complete LaTeX input, which you can type into a LaTeX editor and compile. I encourage you to try doing that now. The output should be a PDF file like this one.

Environments

As mentioned earlier, LaTeX is fundamentally about marking blocks of text to say what role they play in the output — whether a block of text is a table, an equation, part of a list, etc. The way you do this is by enclosing text between \begin and \end commands, whose argument is the name of an “environment” that indicates the type or role of the enclosed text. You have already seen an example of an environment in the simple document above: the entire body is in a document environment, which is basically LaTeX’s way for you to say “this text is the content of the document I want produced.”

You can, and generally do, put environments inside each other, to create a document with whatever nesting of structures you want. For example, here is LaTeX source for a document that includes a bulleted list of key features of LaTeX:

\documentclass{article}

\begin{document}

Welcome to \LaTeX! \LaTeX\ is a document processing system that helps authors write
sophisticated and elegant mathematical and technical documents. Some of its advantages for
this kind of writing include
\begin{itemize}
  \item Professional typesetting of equations
  \item Flexible handling of cross-references
  \item Visually attractive and readable page layout.
\end{itemize}

\end{document}

As in the first example (and all LaTeX documents), the entire body is in a document environment. But inside that environment there is an itemize environment, which is how LaTeX knows that something is supposed to a bulleted list. Each item within that list is indicated by an \item command. (If LaTeX were completely consistent, list items would probably have an “item” environment rather than a command, but then lists would involve so many \begin and \end commands that they would be bulky and hard to write; LaTeX is pragmatic about balancing a consistent notation against ease of use.)

As in the earlier example, blank lines are generally for readability, and don’t effect LaTeX.

However, there is one way that blank lines are significant in LaTeX: they can separate paragraphs. Text which isn’t otherwise controlled by some enclosing environment is treated as one or more paragraphs, with paragraphs ending at blank lines. Paragraphs also end at environment boundaries, and certain commands can indicate the end of a paragraph.

If you compile this example in LaTeX, you should get an output file that looks like this one.

Math and Paragraph Modes

Part of the reason LaTeX can typeset mathematics as well as it does is that it processes mathematical text and regular text in different “modes.” For example, in regular mode (technically called “paragraph mode”), LaTeX understands that text is made up of words, which are separated by spaces. In math mode on the other hand, LaTeX understands that every character is a variable name, that spacing between characters is therefore irrelevant, and that characters should generally be displayed in an italic font.

Normally, LaTeX is in paragraph mode. When you want to write a mathematical expression, you have to switch to math mode. There are two ways to do this. If you just have a small expression that is to be embedded in a prose sentence, you enclose the expression in dollar signs (“$”). For example a fragment of the source for a paragraph about variables a and b might read

…if $a=3$ and $b=4$…

On the other hand, if you have a larger expression that should be displayed separately from the surrounding text, you can put it in an environment that implicitly uses math mode. For example, the equation environment produces a displayed, numbered, equation, and therefore processes its contents in math mode.

Here is an example LaTeX input that demonstrates paragraph mode and both inline and displayed math modes. (Although I don’t intend here to explore the very many commands that are available in math mode, this example illustrates some whose use and purpose you can probably guess.) As with other examples in this tutorial, this is a complete source document that you can try out in your own LaTeX editor. The result should look like this.

\documentclass{article}

\begin{document}

Welcome to \LaTeX! \LaTeX\ excels at typesetting mathematics. For example, the Pythagorean
Theorem states that if $a$ and $b$ are the lengths of the sides of a right triangle, and
$c$ is the length of that triangle's hypotenuse, then
\begin{equation}
a^2 + b^2 = c^2
\end{equation}

From this equation, we can conclude that
\begin{equation}
c = \sqrt{a^2 + b^2}
\end{equation}

So, for example, if $a = 3$ and $b = 4$, we can calculate that $c = 5$.

\end{document}

Extensions

Over time, LaTeX users have defined their own environments and commands for LaTeX; some of these have proven useful enough to share with others. Rather than build all of these extensions into LaTeX, which would require users to keep constantly upgrading their copy of the program, they are available as so-called “packages.” Some packages have proven so popular that they are in fact distributed with LaTeX; others can be downloaded from the Internet by users who want them.

Regardless of how you get a package, if you want to use its features in a document, you have to say in the document’s preamble that you will use that package. The way to do that is with the \usepackage command, which takes the name of the package you want to use as its argument.

For example, a package named “amsmath” is a popular set of extensions to LaTeX’s mathematical typesetting features (so popular in fact that it is part of every modern LaTeX distribution). One of these extensions is an unnumbered equation environment equation*. So if I decided that, in the previous section’s Pythagorean Theorem example, I needed to number the Pythagorean Theorem itself, but not the derived equation involving the square root, I could rewrite the source document thus:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

Welcome to \LaTeX! \LaTeX\ excels at typesetting mathematics. For example, the Pythagorean
Theorem states that if $a$ and $b$ are the lengths of the sides of a right triangle, and
$c$ is the length of that triangle's hypotenuse, then
\begin{equation}
a^2 + b^2 = c^2
\end{equation}

From this equation, we can conclude that
\begin{equation*}
c = \sqrt{a^2 + b^2}
\end{equation*}

So, for example, if $a = 3$ and $b = 4$, we can calculate that $c = 5$.

\end{document}

Notice that I have made two changes to the original example: first, I added the line

\usepackage{amsmath}

to the preamble, so that I could later use the equation* environment. Second, I used that environment, instead of equation, for the second displayed equation.

Compiling this document produces this output.

Learning More

By now you should have a pretty good understanding of the main concepts that LaTeX users need to know: how to think about LaTeX as a markup language, how documents are organized, and particularly the role of environments, math mode and paragraph mode, and how to access features from extension packages. However, as threatened in the introduction, you have only scratched the shallowest surface of the large number of commands and environments available in LaTeX.

Fortunately, there are a great many documents that will teach you about those commands and environments. A simple Internet search for “latex tutorial” will find many of them. If you don’t want to trust Internet search engines, online LaTeX editors (e.g, Overleaf) typically come with tutorials. For a standalone document, I personally am fond of Tobias Oetiker et al’s “Not So Short Introduction to LaTeX2e,” available at http://tug.ctan.org/info/lshort/english/lshort.pdf. Despite its name, it’s a concise and readable introduction to most of what a LaTeX user needs to know.