LaTeX Workshop
1 TeX Documents
1.1 Document Types
LaTeX documents are structured using document classes that define the overall layout and available commands. Here are the main types:
1.1.1 Standard Document Classes
Article - For short documents, papers, journals this is the standard template you will be using most of the time.
\documentclass[11pt,a4paper]{article}
Report - For longer documents with chapters
\documentclass[12pt]{report}
Book - For books with front/back matter
\documentclass{book}
Letter - For formal letters
\documentclass{letter}
Beamer - For presentations
\documentclass{beamer}
1.1.2 Common Class Options
\documentclass[options]{class}
% Font sizes: 10pt, 11pt, 12pt
% Paper sizes: a4paper, letterpaper, a5paper
% Columns: onecolumn, twocolumn
% Sides: oneside, twoside
% Draft mode: draft, final
% Example:
\documentclass[12pt,a4paper,twocolumn]{article}
1.1.3 Academic and Journal Classes
% IEEE papers
\documentclass{IEEEtran}
% AMS articles
\documentclass{amsart}
% Elsevier journals
\documentclass{elsarticle}
% Many journals provide their own class
\documentclass{specific-journal-class}
1.2 Preamble
The preamble is everything between \documentclass{}
and \begin{document}
. This is where you: - Load packages - Define commands - Set document metadata - Configure formatting
1.2.1 Preamble Structure
\documentclass[11pt]{article}
% Packages for encoding and fonts
\usepackage[utf8]{inputenc} % Input encoding
\usepackage[T1]{fontenc} % Font encoding
\usepackage{lmodern} % Better fonts
% Math packages
\usepackage{amsmath} % Enhanced math
\usepackage{amssymb} % Math symbols
\usepackage{amsthm} % Theorem environments
% Graphics and color
\usepackage{graphicx} % Include images
\usepackage{xcolor} % Color support
% Layout and formatting
\usepackage{geometry} % Page margins
\usepackage{setspace} % Line spacing
\usepackage{fancyhdr} % Headers/footers
% References and links
\usepackage{hyperref} % Clickable links
\usepackage{cleveref} % Smart references
% Custom commands
\newcommand{\R}{\mathbb{R}}
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
% Document metadata
\title{My Document}
\author{Author Name}
\date{\today}
% Page setup
\geometry{margin=1in}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1em}
\begin{document}
% Document content goes here
\end{document}
All of your content needs to be between the \begin{document}
and \end{document}
enviroment. Note that anything after a %
sign is considered a comment and will not be rendered.
1.2.2 Common Packages
For math-heavy documents:
\usepackage{amsmath,amssymb,amsthm,mathtools}
\usepackage{physics} % Bra-ket notation etc
For code listings:
\usepackage{listings}
\usepackage{minted} % for python markdown enviroments
For tables:
\usepackage{booktabs} % Fancy tables
\usepackage{array} % Column types
\usepackage{multirow} % Span rows
2 Text Formatting in LaTeX
2.1 Font Styles and Emphasis
2.1.1 Basic Text Formatting
% Emphasis (basically italic)
\emph{emphasized text}
% Bold
\textbf{bold text}
% Italic
\textit{italic text}
% Underline
\underline{underlined text}
% Small caps
\textsc{Small Capitals}
% Typewriter (monospace)
\texttt{monospace text}
% Sans serif
\textsf{sans serif text}
% Slanted
\textsl{slanted text}
2.1.2 Font Sizes
If you wish to define other text like \({\tiny \textit{tiny text for captions}}\) you can use:
\tiny tiny text}
{\scriptsize script size}
{\footnotesize footnote size}
{\small small text}
{\normalsize normal size}
{\large large}
{\Large larger}
{\LARGE even larger}
{\huge huge}
{\Huge largest} {
2.2 Text Structure
2.2.1 Paragraphs and Line Breaks
% New paragraph: blank line or \par
First paragraph text here.
Second paragraph starts after blank line.
% Force line break without new paragraph
\\
Text on first line
Text on second line
% Line break with extra space
\\[10pt]
Text on first line Text on second line with gap
2.2.2 Lists
Itemized (Bullet) Lists:
\begin{itemize}
\item First item
\item Second item
\begin{itemize}
\item Nested item
\item Another nested
\end{itemize}
\item Third item
\end{itemize}
Enumerated (Numbered) Lists:
\begin{enumerate}
\item First item
\item Second item
\begin{enumerate}
\item Nested item 2.1
\item Nested item 2.2
\end{enumerate}
\item Third item
\end{enumerate}
Description Lists:
\begin{description}
\item[Term 1] Description of first term
\item[Term 2] Description of second term
\item[Term 3] Description of third term
\end{description}
2.2.3 Quotations
% Short quotes (inline with paragraph)
\begin{quote}
Short quotation text here.\end{quote}
% Longer quotes (indented, with paragraph breaks)
\begin{quotation}
Longer quotation with multiple paragraphs.
Second paragraph of the quotation.\end{quotation}
% Verse (for poetry)
\begin{verse}
\\
Roses are red\\
Violets are blue\\
LaTeX is great
And so are you\end{verse}
2.3 Special Characters
2.3.1 Reserved Characters
% These characters have special meaning in LaTeX:
\% percent sign
\$ dollar sign
\& ampersand
\# hash/pound
\_ underscore
\{ left brace
\} right brace
\textbackslash{} backslash
\^{} caret (or \textasciicircum)
\~{} tilde (or \textasciitilde)
2.3.2 Quotes and Dashes
% Correct quotes (not straight quotes)
`single quotes'
``double quotes''
% Dashes
- hyphen (for words)
-- en dash (for ranges: 1--10) --- em dash (for breaks---like this)
2.3.3 Accents and International Characters
\'{e} % é acute
\`{e} % è grave
\^{e} % ê circumflex
\"{o} % ö umlaut
\~{n} % ñ tilde
\c{c} % ç cedilla
\o % ø
\ae % æ
\AA % Å
2.3.4 Spacing
% Non-breaking space
Text~here
% Horizontal spaces (smallest to largest)
\! negative thin space
\, thin space
\: medium space
\; thick space
\ normal space
\quad quad space
\qquad double quad
% Vertical space
\vspace{1cm}
\vspace*{1cm} % Won't be removed at page breaks
% Horizontal fill
\hfill % Pushes content to edges
\hfill Right text Left text
3 Indents and Spacing
3.1 Paragraph Indentation
3.1.1 Controlling Indentation
% Set paragraph indent (in preamble)
\setlength{\parindent}{0pt} % No indent
\setlength{\parindent}{1em} % 1em indent
\setlength{\parindent}{15pt} % 15pt indent
% Set space between paragraphs
\setlength{\parskip}{1em} % Space between paragraphs
% Local indent control
\indent Force indent here
\noindent No indent for this paragraph
% Hanging indent
\hangindent=2cm
\hangafter=1
This paragraph will have a hanging indent starting from the second line.
3.1.2 List Indentation
% Customize list indents
\usepackage{enumitem}
\begin{itemize}[leftmargin=2cm]
\item Indented item
\end{itemize}
\begin{enumerate}[label=\arabic*., leftmargin=*]
\item Auto-adjusted indent
\end{enumerate}
3.2 Environment Indentation
3.2.1 Quote and Theorem Indents
% Standard indented environments
\begin{quote}
Indented quote\end{quote}
% Custom indentation
\leftskip=2cm
\rightskip=2cm
This text is indented from both sides\leftskip=0cm
\rightskip=0cm
% Using minipage for indented blocks
\begin{minipage}{\dimexpr\textwidth-2cm}
This entire block is indented\end{minipage}
3.2.2 Code and Verbatim Indentation
% Verbatim with spaces preserved
\begin{verbatim}
def function():
return "preserves indentation"
\end{verbatim}
% Listings package for code
\usepackage{listings}
\lstset{
\ttfamily,
basicstyle=
breaklines=true,
tabsize=4
}
\begin{lstlisting}[language=Python]
def hello():
print("Hello")
return True \end{lstlisting}
3.3 Section and Outline Structure
3.3.1 Section Numbering Depth
% Control section numbering depth
\setcounter{secnumdepth}{3} % Number up to subsubsection
\setcounter{tocdepth}{2} % Show up to subsection in TOC
\section{Section} % 1
\subsection{Subsection} % 1.1
\subsubsection{SubSubSec} % 1.1.1
\paragraph{Paragraph} % Usually unnumbered
\subparagraph{Subparagraph} % Usually unnumbered
3.3.2 Custom Section Formatting
% Unnumbered sections
\section*{Introduction}
% Add to TOC manually
\addcontentsline{toc}{section}{Introduction}
% Short title for TOC/header
\section[Short Title]{Long Detailed Title for the Document}
4 LaTeX Equations
4.1 Inline vs Display Math
4.1.1 Inline Math
Raw: The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ for quadratic equations.
Rendered: The quadratic formula is \(x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\) for quadratic equations.
4.1.2 Display Math - Using Dollar Signs
Raw:
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi} $$
Rendered: \[ \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi} \]
4.1.3 Display Math - Using Square Brackets
Raw:
\[
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}\]
Rendered: \[ \sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6} \]
4.1.4 Difference Between $ $
and \[ \]
$ $
- TeX Primitive - Comes from the original TeX syntax that predates LaTeX - Can produce inconsistent vertical spacing in LaTeX documents - Less informative error messages - Though more widely used in Markdown, Quarto, Jupyter notebooks, web platforms
\[ \]
- LaTeX Environment - Proper LaTeX syntax (shorthand for \begin{displaymath}...\end{displaymath}
) - Consistent vertical spacing following document class rules - Better error reporting and debugging - Use in: Pure LaTeX documents (.tex
files)
4.1.4.1 Quick Decision Guide
Writing in… | Use | Why |
---|---|---|
LaTeX document (.tex) e.g. Overleaf | \[ \] |
Proper LaTeX syntax, better spacing |
Markdown/Quarto (.md/.qmd) | $ $ |
Markdown standard, more features |
Jupyter/R Markdown | $ $ |
Better compatibility |
LaTeX purists will tell you never to use $ $
as it’s primitive TeX that can break spacing. Markdown users will tell you to use $ $
because it’s the standard that supports extra features.
4.2 Common Mathematical Symbols and Commands
Note that most of these come from the amssymb
or amsmath
packages which contain the most common math symbols.
4.2.1 Greek Letters
Raw: $\alpha, \beta, \gamma, \delta, \epsilon, \theta, \lambda, \mu, \pi, \sigma, \phi, \omega$
Rendered: \(\alpha, \beta, \gamma, \delta, \epsilon, \theta, \lambda, \mu, \pi, \sigma, \phi, \omega\)
If we want the uppercase version of these we simply capitalize.
Raw: $\Gamma, \Delta, \Theta, \Lambda, \Sigma, \Phi, \Omega$
Rendered: \(\Gamma, \Delta, \Theta, \Lambda, \Sigma, \Phi, \Omega\)
4.2.2 Mathematical Operators
Raw:
$\sin(x), \cos(x), \tan(x), \log(x), \ln(x), \exp(x)$
Rendered: \(\sin(x), \cos(x), \tan(x), \log(x), \ln(x), \exp(x)\)
4.2.3 Relations and Operators
Raw:
$a \leq b \geq c$, $x \neq y$, $p \approx q$, $m \equiv n \pmod{p}$
Rendered: \(a \leq b \geq c\), \(x \neq y\), \(p \approx q\), \(m \equiv n \pmod{p}\)
4.2.4 Set Notation
Raw:
$A \cup B$, $A \cap B$, $A \subset B$, $x \in A$, $y \notin B$, $\emptyset$
Rendered: \(A \cup B\), \(A \cap B\), \(A \subset B\), \(x \in A\), \(y \notin B\), \(\emptyset\)
4.3 Fractions and Binomials
4.3.1 Fractions
Raw:
Inline: $\frac{a}{b}$ vs Display: $$\frac{a}{b}$$
Nested: $$\frac{\frac{a}{b}}{\frac{c}{d}} = \frac{ad}{bc}$$
Rendered: Inline: \(\frac{a}{b}\) vs Display: \[\frac{a}{b}\]
Nested: \[\frac{\frac{a}{b}}{\frac{c}{d}} = \frac{ad}{bc}\]
4.3.2 Binomial Coefficients
Raw: $\binom{n}{k} = \frac{n!}{k!(n-k)!}$
Rendered: \(\binom{n}{k} = \frac{n!}{k!(n-k)!}\)
4.4 Subscripts and Superscripts
Raw:
$x_1, x_2, \ldots, x_n$
$x^2 + y^2 = r^2$
$x_i^2$, $x_{i+1}^{n-1}$
$(x^2)^3 = x^6$ vs $x^{2^3} = x^8$
Rendered: \(x_1, x_2, \ldots, x_n\)
\(x^2 + y^2 = r^2\)
\(x_i^2\), \(x_{i+1}^{n-1}\)
\((x^2)^3 = x^6\) vs \(x^{2^3} = x^8\)
4.5 Brackets and Delimiters
4.5.1 Manual Sizing
Raw:
Regular: $(x)$, $[x]$, $\{x\}$, $|x|$
[x\Big]$, $\bigg\{x\bigg\}$, $\Bigg|x\Bigg|$ Big: $\big(x\big)$, $\Big
Rendered: Regular: \((x)\), \([x]\), \(\{x\}\), \(|x|\)
Big: \(\big(x\big)\), \(\Big[x\Big]\), \(\bigg\{x\bigg\}\), \(\Bigg|x\Bigg|\)
4.5.2 Automatic Sizing with \left
and \right
Raw:
$$\left( \frac{x^2}{y^3} \right)$$
[ \sum_{i=1}^n x_i \right]^2$$
$$\left
\{ x \in \mathbb{R} : |x| < 1 \right\}$$ $$\left
Rendered: \[\left( \frac{x^2}{y^3} \right)\]
\[\left[ \sum_{i=1}^n x_i \right]^2\]
\[\left\{ x \in \mathbb{R} : |x| < 1 \right\}\]
4.6 Matrices and Arrays
4.6.1 Basic Matrix
Raw:
$$
\begin{matrix}\\
a & b
c & d
\end{matrix} $$
Rendered: \[ \begin{matrix} a & b \\ c & d \end{matrix} \]
4.6.2 Matrix with Brackets
Raw:
$$
\begin{pmatrix}\\
1 & 2 & 3 \\
4 & 5 & 6
7 & 8 & 9
\end{pmatrix} $$
Rendered: \[ \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix} \]
4.6.3 Other Matrix Types
Raw:
Brackets: $\begin{bmatrix} a & b \\ c & d \end{bmatrix}$
\\ c & d \end{vmatrix}$
Determinant: $\begin{vmatrix} a & b
\\ c & d \end{Bmatrix}$ Curly: $\begin{Bmatrix} a & b
Rendered: Brackets: \(\begin{bmatrix} a & b \\ c & d \end{bmatrix}\)
Determinant: \(\begin{vmatrix} a & b \\ c & d \end{vmatrix}\)
Curly: \(\begin{Bmatrix} a & b \\ c & d \end{Bmatrix}\)
4.7 Aligned Equations
4.7.1 Using aligned
Environment
Raw:
$$
\begin{aligned}\\
2x + 3y &= 7 \\
x - y &= 1 \\
\implies x &= \frac{10}{5} = 2
y &= 1
\end{aligned} $$
Rendered: \[ \begin{aligned} 2x + 3y &= 7 \\ x - y &= 1 \\ \implies x &= \frac{10}{5} = 2 \\ y &= 1 \end{aligned} \]
4.7.2 Multi-line Equations with split
Raw:
$$
\begin{split}\\
(a + b)^2 &= (a + b)(a + b) \\
&= a^2 + ab + ba + b^2
&= a^2 + 2ab + b^2
\end{split} $$
Rendered: \[ \begin{split} (a + b)^2 &= (a + b)(a + b) \\ &= a^2 + ab + ba + b^2 \\ &= a^2 + 2ab + b^2 \end{split} \]
4.8 Cases (Piecewise Functions)
Raw:
$$
f(x) = \begin{cases}\\
x^2 & \text{if } x < 0 \\
2x & \text{if } 0 \leq x \leq 1
3 & \text{if } x > 1
\end{cases} $$
Rendered: \[ f(x) = \begin{cases} x^2 & \text{if } x < 0 \\ 2x & \text{if } 0 \leq x \leq 1 \\ 3 & \text{if } x > 1 \end{cases} \]
4.9 Limits, Derivatives, and Integrals
4.9.1 Limits
Raw:
$$\lim_{x \to \infty} \frac{1}{x} = 0$$
$$\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n = e$$
Rendered: \[\lim_{x \to \infty} \frac{1}{x} = 0\]
\[\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n = e\]
4.9.2 Derivatives
Raw:
$\frac{d}{dx} f(x)$, $\frac{\partial f}{\partial x}$, $f'(x)$, $f''(x)$, $\dot{x}$, $\ddot{x}$
Rendered: \(\frac{d}{dx} f(x)\), \(\frac{\partial f}{\partial x}\), \(f'(x)\), \(f''(x)\), \(\dot{x}\), \(\ddot{x}\)
4.9.3 Integrals
Raw:
$$\int_a^b f(x) \, dx$$
$$\iint_D f(x,y) \, dx \, dy$$
$$\oint_C F \cdot dr$$
Rendered: \[\int_a^b f(x) \, dx\]
\[\iint_D f(x,y) \, dx \, dy\]
\[\oint_C F \cdot dr\]
4.10 Sums and Products
Raw:
$$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$$
$$\prod_{i=1}^{n} x_i = x_1 \cdot x_2 \cdot \ldots \cdot x_n$$
$$\bigcup_{i=1}^{n} A_i, \quad \bigcap_{i=1}^{n} A_i$$
Rendered: \[\sum_{i=1}^{n} i = \frac{n(n+1)}{2}\]
\[\prod_{i=1}^{n} x_i = x_1 \cdot x_2 \cdot \ldots \cdot x_n\]
\[\bigcup_{i=1}^{n} A_i, \quad \bigcap_{i=1}^{n} A_i\]
4.11 Special Symbols and Fonts
4.11.1 Blackboard Bold (Number Sets)
Raw: $\mathbb{N}, \mathbb{Z}, \mathbb{Q}, \mathbb{R}, \mathbb{C}$
Rendered: \(\mathbb{N}, \mathbb{Z}, \mathbb{Q}, \mathbb{R}, \mathbb{C}\)
4.11.2 Calligraphic and Script
Raw: $\mathcal{A}, \mathcal{B}, \mathcal{L}, \mathcal{F}$
Rendered: \(\mathcal{A}, \mathcal{B}, \mathcal{L}, \mathcal{F}\)
Raw: $\mathscr{A}, \mathscr{B}, \mathscr{L}, \mathscr{F}$
(requires \usepackage{mathrsfs}
)
4.11.3 Bold Math
Raw: $\mathbf{x}, \mathbf{A}, \boldsymbol{\alpha}$
Rendered: \(\mathbf{x}, \mathbf{A}, \boldsymbol{\alpha}\)
4.11.4 Text in Math Mode
Raw:
$$x = 2 \text{ where } x \in \mathbb{R}$$
$$\text{Probability} = \frac{\text{favorable outcomes}}{\text{total outcomes}}$$
Rendered: \[x = 2 \text{ where } x \in \mathbb{R}\]
\[\text{Probability} = \frac{\text{favorable outcomes}}{\text{total outcomes}}\]
4.12 Spacing in Math Mode
4.12.1 Manual Spacing
Raw:
No space: $ab$
Thin space: $a\,b$
Medium space: $a\:b$
Thick space: $a\;b$
Quad space: $a\quad b$
Double quad: $a\qquad b$
Negative space: $a\!b$
Rendered: No space: \(ab\) Thin space: \(a\,b\) Medium space: \(a\:b\) Thick space: \(a\;b\) Quad space: \(a\quad b\) Double quad: \(a\qquad b\) Negative space: \(a\!b\)
4.13 Arrows
Raw:
$\rightarrow, \leftarrow, \leftrightarrow, \Rightarrow, \Leftarrow, \Leftrightarrow$
$\uparrow, \downarrow, \updownarrow, \Uparrow, \Downarrow, \Updownarrow$
$\mapsto, \longmapsto, \hookrightarrow, \rightharpoonup$
Rendered: \(\rightarrow, \leftarrow, \leftrightarrow, \Rightarrow, \Leftarrow, \Leftrightarrow\)
\(\uparrow, \downarrow, \updownarrow, \Uparrow, \Downarrow, \Updownarrow\)
\(\mapsto, \longmapsto, \hookrightarrow, \rightharpoonup\)
4.14 Accents and Decorations
Raw:
$\hat{x}, \bar{x}, \vec{x}, \dot{x}, \ddot{x}, \tilde{x}$
$\overline{AB}, \underline{xy}, \overbrace{a+b+c}^{\text{sum}}, \underbrace{x+y}_{\text{terms}}$
Rendered: \(\hat{x}, \bar{x}, \vec{x}, \dot{x}, \ddot{x}, \tilde{x}\)
\(\overline{AB}, \underline{xy}, \overbrace{a+b+c}^{\text{sum}}, \underbrace{x+y}_{\text{terms}}\)
4.15 Using Custom Commands (from Preamble)
The commands defined in the header can be used throughout:
Raw:
The real numbers $\mathbb{R}$ contain the integers $\mathbb{Z}$ and naturals $\mathbb{N}$.
[X] = \mu$ and variance is $\text{Var}(X) = \sigma^2$. The expected value is $\mathbb{E}
Rendered: The real numbers \(\mathbb{R}\) contain the integers \(\mathbb{Z}\) and naturals \(\mathbb{N}\).
The expected value is \(\mathbb{E}[X] = \mu\) and variance is \(\text{Var}(X) = \sigma^2\).
4.16 Theorem Environments
We can define a new command in our preamble:
\newtheorem{theorem}{Theorem} \newtheorem{lemma}{Lemma}
Such that when we call:
\begin{theorem}
$x$, we have $x^2 \geq 0$.
For any real number \end{theorem}
\begin{lemma}
$a > 0$ and $b > 0$, then $ab > 0$.
If \end{lemma}
We will render:
\(\textbf{Theorem 1}\) For any real number \(x\), we have \(x^2 \geq 0\).
\(\textbf{Lemma 1}\) If \(a > 0\) and \(b > 0\), then \(ab > 0\).
4.17 Debugging
- Check to see if math mode has been properly opened and closed
- Curly braces for multi-character sub/superscripts e.g. Use
x_{10}
notx_10
- Did you leave space after commands?
\sin x
not\sinx
- Use
\text{}
for text in math:$x = 2 \text{ meters}$
- Alignment character
&
only in aligned environments - Check if you installed all your needed packages in the preamble.
4.18 Quick Reference Table
Description | LaTeX Code | Rendered |
---|---|---|
Fraction | \frac{a}{b} |
\(\frac{a}{b}\) |
Square root | \sqrt{x} |
\(\sqrt{x}\) |
N-th root | \sqrt[n]{x} |
\(\sqrt[n]{x}\) |
Infinity | \infty |
\(\infty\) |
Not equal | \neq |
\(\neq\) |
Approximately | \approx |
\(\approx\) |
Less/greater equal | \leq \geq |
\(\leq \geq\) |
Element of | \in |
\(\in\) |
Subset | \subset |
\(\subset\) |
Union/Intersection | \cup \cap |
\(\cup \cap\) |
For all/Exists | \forall \exists |
\(\forall \exists\) |
Implies | \implies |
\(\implies\) |
If and only if | \iff |
\(\iff\) |