Scripts, Fractions, Brackets, and Matrices
Use ^ to write superscripts, _ to write subscripts, and \frac to write fractions. amsmath provides matrices, piecewise functions, and more reliable mathematical structures.
EasyLaTeX compiler setting: pdfLaTeX + article; amsmath needs to be loaded.
Superscripts and Subscripts
Use ^ for superscripts and _ for subscripts:
\[
x^2 + y_1 = z.
\]
When a superscript or subscript contains multiple characters, curly braces must be used to delimit its scope:
\[
x^{n+1}, \qquad a_{i,j}, \qquad e^{-x^2}.
\]
x^n+1 only makes n become a superscript, while +1 remains on the baseline; this is one of the most common formula errors made by beginners.
Fractions and Radicals
Use \frac{numerator}{denominator}:
\[
\frac{a+b}{c+d}.
\]
Use \sqrt{...} for square roots; use an optional bracket parameter for nth roots:
\[
\sqrt{x}, \qquad \sqrt[3]{x+y}.
\]
Nested fractions can appear too tall when used inline. If the formula itself requires explanation or contains multiple layers of structure, use a standalone equation or split the derivation.
Automatically Sized Brackets
For short content, you can directly use (, ), [, and ]. When parentheses surround a fraction or matrix, use \left and \right to automatically match the height:
\[
\left( \frac{a}{b} \right)^2.
\]
When only one side needs visible brackets, use the invisible delimiter \left. or \right. on the other side:
\[
\left. \frac{d}{dx} x^n \right|_{x=1} = n.
\]
\left must be paired with \right in the same mathematical group. There is no need to overuse automatically scalable parentheses in short formulas; excessively large parentheses can impair readability.
Matrices
After loading amsmath, environments such as pmatrix, bmatrix, etc. can be used. Columns are separated by &, and line endings use \\ for line breaks:
\[
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
\]
Common environments are as follows:
| Environment | Outer delimiters |
|---|---|
matrix | None |
pmatrix | Parentheses |
bmatrix | Square brackets |
Bmatrix | Braces |
vmatrix | Single vertical bar |
Vmatrix | Double vertical bar |
Piecewise Functions
cases The environment generates a large brace on the left, suitable for piecewise definitions:
\[
f(x) =
\begin{cases}
x^2, & x \geq 0, \\
-x, & x < 0.
\end{cases}
\]
& Align the expressions and conditions in separate columns; English explanations in the conditions may use \text{...}.
Common Misuses
Put all content inside a pair of curly braces
x^{n+1} requires curly braces, but x^2 does not. Curly braces are used only to delimit command arguments or the scope of superscripts and subscripts; they themselves do not appear in the PDF.
Forgetting the Double Backslash at the End of a Matrix Row
In a matrix, a line break is \\, not a single backslash as in ordinary text. The last row usually does not need \\.
Enclose a tall matrix in ordinary parentheses
( \begin{matrix} ... \end{matrix} ) brackets do not automatically grow taller. Use pmatrix, or use the paired \left( and \right).
Complete Example
\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\begin{document}
\[
x^{n+1} = \frac{x^n \cdot x}{1}.
\]
\[
A = \begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}.
\]
\[
f(x) =
\begin{cases}
x^2, & x \geq 0, \\
-x, & x < 0.
\end{cases}
\]
\end{document}