Equations and Formulas#

Objective: Experiment with mathematical notation in LaTeX.

Getting Started: Basic Equations#

Inline vs Display Style#

To add math to your documents, you first have to enter math mode. Math can be displayed inline or in math blocks (called display style). To render equations in inline style, enclose them in a pair of dollar signs $...$.

Inline: Using $x + y = z$ will display the equation \(x + y = z\) in the line.

To render equations in display style, LaTeX offers several options. We suggest using \[...\] to start.

Display: Using \[ x + y = z \] will display the equation centered on its own line as below.

\[ x + y = z \]

Simple Operators, Subscripts, Superscripts & More#

To render simple equations, you also need to know syntax and commands for operators, relations, subscripts, superscripts, and fractions.

Operators & Relations:
+, -, =, >, < work as expected. Here are some other commands:

Command

Display

Command

Display

\times

\(\times\)

\cdot

\(\cdot\)

\div

\(\div\)

\pm

\(\pm\)

\geq

\(\geq\)

\leq

\(\leq\)

\neq

\(\neq\)

\approx

\(\approx\)

Subscript: use the underscore (_) / Superscript: use the carret (^)

Note

If the subscript or superscript includes more than one character, enclose it in curly brackets–otherwise the command applies only to the first character.

Example: $x^n+1$ gives \(x^n+1\) but $x^{n+1}$ gives \(x^{n+1}\)

Fractions:
To display a fraction, use the command \frac followed by the numerator and denominator in curly brackets.

Example: \frac{1}{x} gives \(\frac{1}{x}\)

Exercise 1#

Open a blank document in Overleaf and recreate this text in your document using LaTeX commands:


A quadratic equation is an equation of the form \(ax^2 + bx + c = 0\) and such equations can be solved using the quadratic formula:

\[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \]

Commands needed: \frac{}{}, \pm, \sqrt{}

Challenge Exercise

Recreate these equations in your document:


\[ a^2_1 + a^2_2 = a^2_3 \]
\[ v(x,t) = x - \sqrt{x^2 + e^{a-2t}} \]

Tip

Getting compile errors or having problems getting the equations to render correctly? Compare your LaTeX code with the solutions.

Next Steps: Greek Letters, Integrals & More#

Greek Letters#

Many equations and formulas use Greek letters. The command is simple - just the backslash and the name of the letter. Capitalize the command to get the capital letter. Here are some examples:

Command

Display

Command

Display

\alpha

\(\alpha\)

\mu

\(\mu\)

\beta

\(\beta\)

\pi

\(\pi\)

\Gamma

\(\Gamma\)

\rho

\(\rho\)

\delta

\(\delta\)

\sigma

\(\sigma\)

\Delta

\(\Delta\)

\Phi

\(\Phi\)

\lambda

\(\lambda\)

\omega

\(\omega\)

\Lambda

\(\Lambda\)

\Omega

\(\Omega\)

Note

Greek letters that are the same in English are an exception, for example, use A for Alpha, B for Beta, Z for Zeta. For more commands, see the Overleaf list of Greek letters.

Limits, Integrals, Products & Sums#

There are also commands for common operations that take upper and lower bounds:

Limits:

\[ 
lim_{x \to \infty} f(x) 
\]

results in

\[ lim_{x \to \infty} f(x) \]

Integrals

\[ 
\int_{a}^{b} x^2 dx 
\]

results in

\[ \int_{a}^{b} x^2 dx \]

Products

\[ 
\prod_{i=a}^{b} f(i) 
\]

results in

\[ \prod_{i=a}^{b} f(i) \]

Sums

What about summation (\(\sum\))?

Exercise 2#

Recreate these equations in your Overleaf document:


\[ e^{i\pi} = -1 \]
\[ f(x) = \sum_{i=0}^{\infty} \frac{f^{(i)}(0)}{i!} x^i \]

Commands needed: \pi, \infty, \frac{}{}, \sum_{}^{}

Challenge Exercise

Recreate this text in your document:


Suppose that the measurable sets \(A_1,A_2,...\) are “almost disjoint” in the sense that \(\mu(A_i \cap A_j) = 0\) if \(i \neq j\). Prove that

\[ \mu(\cup_{k=1}^{\infty} A_k) = \sum_{k \geq 1} \mu(A_k) \]

Commands needed: \mu, \cap, \neq, \cup, \infty, \sum_{}, \geq

Tip

Need help getting the text and equations to render properly? Compare your LaTeX code with the solutions.

More Advanced: Math Packages#

amsmath & amssymb Packages#

LaTeX has many packages that you can use to extend its capabilities. The amsmath and amssymb packages provide you with additional symbols and commands for structuring equations.

To include them, add these commands to the preamble of your LaTeX document:
\usepackage{amsmath}
\usepackage{amssymb}

amsmath: Equations Environment#

Use the \begin{equation}...\end{equation} command to include a numbered equation in display mode.

\begin{equation}
(I - A \otimes A) vec(X) = vec(Q)
\end{equation}

results in

\[ \begin{equation} (I - A \otimes A) vec(X) = vec(Q) \tag{1} \end{equation} \]

Note

Use \begin{equation*} for unnumbered equations.

amsmath: Align Environment#

The command \begin{align}...\end{align} will allow you to align a series of equations around a common element, which you can identify with the ampersand (&).

\begin{align}
\frac{d}{dx} \sin x &= \cos x \\
\frac{d}{dx} \cos x &= -\sin x \\
\frac{d}{dx} \tan x &= \sec^2 x
\end{align}

results in

\[\begin{split} \begin{align} \frac{d}{dx} \sin x &= \cos x \tag{2} \\ \frac{d}{dx} \cos x &= -\sin x \tag{3} \\ \frac{d}{dx} \tan x &= \sec^2 x \tag{4} \end{align} \end{split}\]

amsmath: Cases Environment#

The amsmath package also offers the \begin{cases}...\end{cases} command, which enables you to display an equation with multiple cases.

\begin{equation*}
f(n) = \begin{cases}
0 & n=0 \\
1 & n=1 \\
f(n-1) + f(n-2) & \text{otherwise}
\end{cases}
\end{equation*}

results in

\[\begin{split} \begin{equation*} f(n) = \begin{cases} 0 & n=0 \\ 1 & n=1 \\ f(n-1) + f(n-2) & \text{otherwise} \end{cases} \end{equation*} \end{split}\]

Note

Use the \text{} command to include text in math mode.

amssymb#

The amssymb package provides access to more options for mathematical symbols including additional fonts such as Blackboard-Bold.

More fonts:
\mathbb{R} gives \(\mathbb{R}\) for the set of real numbers.

More symbols:
\approxeq \(\Rightarrow\) \(\approxeq\)
\nleq \(\Rightarrow\) \(\nleq\)

Alternate versions of symbols:
in plain LaTeX: \emptyset \(\Rightarrow\) \(\emptyset\)
with amssymb: \varnothing \(\Rightarrow\) \(\varnothing\)

Matrices#

To create a matrix in your document, you can use the the {array} environment in plain LaTeX or the simpler {matrix} environment in the amsmath package.

\[
\begin{matrix}
a & b & c \\
d & e & f \\
\end{matrix}
\]

results in a matrix with no brackets:

\[\begin{split} \begin{matrix} a & b & c \\ d & e & f \\ \end{matrix} \end{split}\]

Note

Compare that to {pmatrix} for matrices with parentheses, {bmatrix} for matrices with square brackets, and {vmatrix} for determinants.

{pmatrix}

\[\begin{split} \begin{pmatrix} a & b & c \\ d & e & f \\ \end{pmatrix} \end{split}\]

{bmatrix}

\[\begin{split} \begin{bmatrix} a & b & c \\ d & e & f \\ \end{bmatrix} \end{split}\]

{vmatrix}

\[\begin{split} \begin{vmatrix} a & b & c \\ d & e & f \\ \end{vmatrix} \end{split}\]

Exercise 3#

Part A

Recreate these matrices in your Overleaf document:


\[\begin{split} A = \begin{bmatrix} a & b & c \\ p & q & r \\ u & v & w \end{bmatrix}, B = \begin{pmatrix} \alpha & \beta & \gamma \\ \lambda & \mu & \nu \\ \rho & \sigma & \tau \end{pmatrix} \end{split}\]

Commands needed: \begin{bmatrix}...\end{bmatrix}, \begin{pmatrix}...\end{pmatrix}, \alpha, \beta, \gamma, \lambda, \mu, \nu, \rho, \sigma, \tau

Part B

Recreate this equation in your document:


\[ \begin{equation} \int_{\Sigma} \left( \sum_{i=1}^{3} f_i \frac{\partial \rho}{\partial x_i} \right) dS_x = 0 \text{ for any } \rho \in C^{\infty} (\mathbb{R}^3) \end{equation} \]

Commands needed: \begin{equation*}...\end{equation*}, \int_{}, \Sigma, \sum_{}^{}, \frac{}{}, \partial, \rho, \text{}, \in, \infty, \mathbb{}

Note

To scale the parentheses to the height of the equation, use the commands \left( and \right).

Tip

Need help getting the text and equations to render properly? Compare your LaTeX code with the solutions.