Lesson 4 of 4

Math Basics

The superpower of LaTeX. Learn how to write inline equations, display equations, and basic math symbols.

This is it. This is the main reason millions of scientists, engineers, and mathematicians use LaTeX: the ability to typeset complex mathematical equations effortlessly and beautifully.

In LaTeX, mathematics must be written inside a special "math mode." There are two primary types of math mode: Inline Math and Display Math.

1. Inline Math

Inline math is used when you want to write an equation naturally inside a sentence. To trigger inline math mode, you wrap your equation in single dollar signs $ ... $.

According to the Pythagorean theorem, if a right triangle has legs of length $a$ and $b$, and a hypotenuse of length $c$, then $a^2 + b^2 = c^2$.

LaTeX will automatically format variables (like aa, bb, and cc) in a special italicized math font, and properly space the operators like + and =.

Don't use math mode for normal italics!

Never use $word$ just to make a word italicized in your text. Math mode completely ignores standard spaces and uses different kerning rules designed specifically for variables, so your text will look squished and ugly. Always use \textit{word} for normal text.

2. Display Math

If an equation is too large or too important to sit inside a sentence, you should use Display Math. This centers the equation on its own line and makes it larger and more readable.

To trigger display math mode, wrap your equation in \[ ... \].

The roots of a quadratic equation are given by the formula:
 
\[
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\]

(Note: Older LaTeX tutorials might tell you to use double dollar signs $$ ... $$ for display math. This is a deprecated Plain TeX command and should be avoided in modern LaTeX, as it can mess up vertical spacing).

Common Math Operations

Here are some of the most essential math commands you'll need. Remember, these will only work if they are inside math mode ($...$ or \[...\]).

Superscripts and Subscripts

Use the caret ^ for superscripts (exponents) and the underscore _ for subscripts. If your superscript or subscript contains more than one character, you must wrap it in curly braces {}.

$x^2$        % Correct
$x_1$        % Correct
$x^{10}$     % Correct (braces group the 10 together)
$x^10$       % Incorrect! This prints as x¹0.

Fractions

Fractions use the \frac{numerator}{denominator} command.

\[
\frac{1}{2} + \frac{x}{y+1} = z
\]

Roots

Square roots use the \sqrt{} command. You can pass an optional argument in square brackets [] for other roots, like cube roots.

$\sqrt{25} = 5$
 
$\sqrt[3]{8} = 2$

Greek Letters

To type Greek letters, just write a backslash followed by the phonetic name of the letter. To get the uppercase version, capitalize the first letter.

$\alpha, \beta, \gamma, \pi, \theta$
 
$\Gamma, \Pi, \Theta, \Omega$

Knowledge Check

Knowledge Check

Which of the following is the correct, modern way to write a Display Math equation (centered on its own line)?