A quick guide to using LaTeX

What is LaTeX?

LaTeX is a document preparation system. It is a code-based approach to preparing documents whereas programs such as Microsoft Word are largely visual-based and WYSIWYG.

Why should I use LaTeX?

In theory LaTeX allows you to separate content from formatting. The structure of the document is handled programmatically and is independent of the document’s content.

a meme illustrating how moving a picture in Microsoft Word messes up text
Microsoft Word’s image capabilities can be lacking

It also makes your content look great. It has especially robust formatting and typesetting options for mathematical equations, which makes LaTeX the default choice for papers written in STEM fields.

Why shouldn’t I use LaTeX?

  • Since it’s not a WYSIWYG tool, the document has to render every time you make a change. This only takes a few seconds but the feedback is not as immediate as, say, Microsoft Word.
  • The markup commands, while not unintuitive in most cases, can be hard to remember. Even after several years of using LaTeX I often have to consult cheat sheets, and syntax errors (ex. missing or extra curly braces) are fairly common.
  • Since the documents are programmatically generated, in most cases the documents won’t even render until errors are fixed. The corresponding error messages can range from self-explanatory to cryptic.
  • In theory LaTeX allows you to separate content from formatting. In practice this means that formatting something nonstandard often requires hacky solutions.
  • Due to TeX’s extreme attention to detail in typesetting, adding fonts is not a trivial task. Most LaTeX documents use the default Computer Modern as a result.

How do I install LaTeX?

Since this is a Quick Start guide and not a History of LaTeX article, I am skipping a lot of the technical details behind LaTeX. But a brief explanation: LaTeX, a document preparation system, is based on TeX, a typesetting system.

TeX implements formatting and typesetting, such as kerning, line spacing, line breaks, etc. while LaTeX implements structure, such as cover pages, sections, tables, and so on. LaTeX is essentially a set of macros for TeX that allow you to focus on higher-level structure rather than low-level formatting.

What does this mean in terms of using LaTeX? In a process familiar to anyone who uses open-source software, you have to download some distribution of TeX/LaTeX, such as MiKTeX, and install it and update it. Instructions on how to do so can be found on the LaTeX project website.

You could also use online LaTeX editors such as Overleaf, which are far more convenient. You may not be able to render documents offline but it’s simple and easy to set up.

How do I use LaTeX?

LaTeX is markup language that controls how a document is formatted, with content interspersed, similar to Markdown. Thus creating a document in LaTeX means creating a .tex file. Most commands are of the format \command[parameters]{content}. Some examples:

  • \noindent disables automatic paragraph indentation when inserted directly before a paragraph
  • \textbf{test} displays “test” in boldface
  • \includegraphics[width=2in]{graph.png} inserts the graph.png file into the document with a width of 2 inches

Preamble

A LaTeX file contains a preamble similar to a <head> element in HTML, which defines the document’s format and the pacakges it uses. It must contain at the very least \documentclass[xxx]{xxx} in it, and the actual document itself sandwiched inside \begin{document} ... \end{document}.

The most common documentclass is \documentclass[letter]{article}, which sets the document to use 8.5″ x 11″ letter-size paper, but there are several others. Additionally we can import packages in the preamble that add extra functionality or commands to our document. For example we can add \usepackage[margin=1in]{geometry} to set the margins to 1 inch and also \usepackage{amsmath} and \usepackage{amssymb} to aid in mathematical formatting and typesetting. (Note that by default margins are 1.5 inches to help in readability and aesthetics.) You can find lists of packages here and here.

Document structure

The body of the document is inside \begin{document} ... \end{document}. Most documents use \section{Section header here} similar to Markdown’s #... ##... ###... to structure the document.

For example:

\section{This is a section}
Here is some text.
\subsection{This is a subsection}
Here is some more text.
\subsubsection{This is a subsubsection}
Here is some more text.
\subsubsection{This is another subsubsection}
Here is some more text at the same depth.
\section*{This is a section without a number}
\subsection*{This is a subsection without a number}
Here is some more text.
\section{It does not affect numbering}

produces the output:

rendering output of the code to produce sections

Paragraph structuring works as follows:

\section{Section header}
The first paragraph of a section, subsection, etc. is not indented.
Content after a newline continues the paragraph.
So how do we make a new paragraph?

Two newlines can start a new paragraph. Note that this indents the new paragraph.\\
Additionally we can use two backslash characters to start a new line without indentation.

\noindent Alternatively we can use the noindent command to do the same thing.

This produces the output:

rendering output of the code to produce paragraphs

Formatting and lists

We can format text in a variety of ways. We can use:

\textbf{bolded text}\\
\textit{italicized text}\\
\underline{underlined text}

to get:

rendering output of the code to produce formatting

We can generate lists as follows:

This is a numbered list:
\begin{enumerate}
\item First item
\item Second item
\item And so forth
\end{enumerate}
This is a bulleted list:
\begin{itemize}
\item First item
\item Second item
\item And so forth
\end{itemize}

to get:

rendering output of the code to produce lists

Tables

Tables can be quite complicated. At best the code is somewhat understandable; at worst the code is a monstrosity requiring several packages. Luckily we can use LaTeX table generators to help.

Math mode

LaTeX’s math mode is one of its main features. We can format mathematical things in two ways:

\section{Section header}
First is inline mode, wrapped by single dollar signs, 
where the formulas appear in the text body. For example: 
$x^2, \sum_{i=1}^n \frac{1}{n}, 2\sin^2(x)+\cosh(x^2), 
\frac{n!}{k!(n-k)!} = \binom{n}{k},
\frac{\frac{1}{x}+\frac{1}{y}}{y-z}$ appear in the text body.

Alternatively we can wrap with double dollar signs 
to give the formulas their own, centered line. For example: 
$$x^2, \sum_{i=1}^n \frac{1}{n}, 2\sin^2(x)+\cosh(x^2),
\frac{n!}{k!(n-k)!} = \binom{n}{k},
\frac{\frac{1}{x}+\frac{1}{y}}{y-z}$$ 
appear centered on a separate line.

This renders as:

rendering output of the code to produce math

LaTeX can handle practically every conceivable form of mathematical notation. Again, online equation editors are of great help. Remember that for many symbols we need to include \usepackage{amsmath} and \usepackage{amssymb} in the preamble.

Images

Inserting images is as simple as:

\includegraphics[scale=0.5]{example.png}

which renders the example.png image. Note that we must have \usepackage{graphicx} in the preamble to work with graphics. The image file must be in the same directory as the .tex file if you are running LaTeX on your computer; for online implementations of LaTeX there is usually a file manager. The [scale=0.5] controls the size of the image. It can be replaced with [width=0.5in], for example, to specify a given width or height, or [width=\textwidth] to scale it to the width of the text area.

Resources for continuing to learn

The previous sections cover the basics of working with LaTeX. The following resources go into much more depth:

  • LaTeX on Wikibooks, an excellent and thorough guide to 95% of everything you need to know about LaTeX, with detailed examples.
  • TeX Stack Exchange, where every single question you’ll have has already been asked and answered.
  • The Comprehensive TeX Archive Network, with an incredible array of packages that cover anything else you might want to do. There are packages specifically for drawing Celtic knots, importing OpenStreetMap images, generating Gantt charts, and much more.

Trial and error and repeated experimentation go a long way in terms of understanding LaTeX.