Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

LaTeX Math Formulas Basics

LaTeX Math Formulas Basics

Math typesetting is the crown jewel of LaTeX and the primary reason most people choose it.

This part covers the foundation of math formulas: inline and display formulas, superscripts/subscripts, fractions, roots, Greek letters, and a table of common symbols.

Every "syntax -> effect" comparison in this text is rendered live; what you see on the web page is exactly how LaTeX typesets it.


Inline and Display Formulas

Formulas have only two forms: inline formulas embedded in sentences, wrapped in a pair of $; and display formulas on their own centered line, wrapped in [ and ].

Example

Quadratic Equation in One Variable

$ax^2 + bx + c = 0$

has the root formula

[

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

]

where the discriminant

$\Delta = b^2 - 4ac$

determines the number of roots.

Rendered effect:

Quadratic Equation in One Variable

has the root formula

where the discriminant

determines the number of roots.

Form Syntax effect When to Use
Inline formula $...$ Same height as text, embedded in the sentence Simple formulas referenced within a sentence
Display formula [...] On its own line, centered, larger font Important or complex formulas

Two habits to avoid: first, do not use the old $$...$$ for display formulas, which has spacing flaws; always use \[...\]; second, when a sentence is interrupted by a display formula, do not leave a blank line before it - the formula is still inside the sentence and must not start a new paragraph.


Superscripts and Subscripts

^ is a superscript and _ is a subscript; both act only on the single character or brace group immediately following.

x^2

a_{ij}

2^{n+1}

x_i^2

x^{i^2}

e^{-t}

Compare the fourth and fifth lines: x_i^2 is "the square of the i-th x", while x^{i^2} is "x to the power i squared" - braces determine the scope, and a tiny difference leads to a wildly different result.

If a superscript or subscript has more than one character, braces are mandatory. x^10 would be typeset as an x with a superscript 1 followed by a plain 0; the correct form is x^{10}.


Fractions and Roots

\frac{numerator}{denominator} generates a fraction, \sqrt{radicand} generates a root, and an n-th root is written \sqrt[n]{...}.

\frac{a+b}{c}

\frac{1}{1+\frac{1}{x}}

\sqrt{2}

\sqrt[3]{x^2+1}

(\frac{a}{b})

\left(\frac{a}{b}\right)

A final pair worth remembering: ordinary parentheses do not grow with content; \left( and \right) make parentheses automatically fit the content height, and must be used around fractions and matrices.

Fractions in inline formulas are automatically compressed (denominator lowered, font shrunk); if you find it too small, replace \frac with \dfrac (display frac) and the fraction keeps its display size.


Greek Letters

The command for a Greek letter is simply "backslash + English name", and case is controlled by the initial letter of the command.

Command effect Command effect
\alpha \beta
\gamma \delta
\epsilon \varepsilon
\theta \lambda
\mu \pi
\sigma \omega
\phi \varphi
Command effect Command effect
\Gamma \Delta
\Sigma \Omega

Note two points: the uppercase command capitalizes only the first letter (\Sigma not \SIGMA); \epsilon and \varepsilon, \phi and \varphi are two glyphs of the same letter, each with its own mathematical convention - just keep consistent in a paper.


Quick Reference for Common Symbols

High-frequency symbols are grouped into three tables by usage; the effect columns are all rendered live.

Command effect Command effect
\times \div
\pm \mp
\cdot \leq
\geq \neq
\approx \equiv
\ll \gg
Command effect Command effect
\in \notin
\subset \subseteq
\cup \cap
\emptyset \infty
\forall \exists
\Rightarrow \Leftrightarrow
Command effect Command effect
\partial \nabla
\to \mapsto
\mathrm{d}x \hat{x}
\bar{x} \vec{v}

Large Operators: Summation, Integral, Limit

\sum, \int, and \lim are the three most common large operators, used with superscripts and subscripts.

In display formulas, the limits of a summation sit directly above/below the symbol; when placed in an inline formula they are automatically compressed to the side. To keep the "above/below" form inline, wrap it in \displaystyle.


Two Essential Packages: amsmath and amssymb

amsmath and amssymb are the "official extensions" for math typesetting; it is recommended to load them without thinking before writing formulas.

Package What It Provides
amsmath More formula environments (align, etc., Part 7), \dfrac, \tfrac, formula numbering control
amssymb Extended math symbols, such as the \mathbb blackboard-bold font

The commonly used font-effect commands in math also come from these two packages:

\mathbb{R}

\mathcal{F}

\mathbf{v}

\mathrm{e}^{\mathrm{i}\pi}

The last line is a typesetting detail: the base e of natural logarithms and the imaginary unit i, if written directly, are typeset as italic variables; wrapping them with \mathrm to make them upright meets publishing standards.

Do not put Chinese or full-width punctuation inside formulas. Entering a plus sign or a Greek letter directly via the input method (instead of with commands) is a misuse - formula content must be typed with commands, and Chinese notes go outside $.


Comprehensive Example: A Real Document

Put this part's content into a complete document and compile:

Example

\

documentclass

{

ctexart}
\usepackage{amsmath

}

         

% math enhancement package, standard for formula typesetting

\begin

{

document}
The quadratic equation $ax^2 + bx + c = 0$ has the root formula
[
  x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a},
\ ]
where the discriminant $\Delta = b^2 - 4ac$ determines the number of roots.

The most beautiful formula in mathematics is Euler's formula
[
  \mathrm{e}^{\mathrm{i}\pi} + 1 = 0,
\ ]
which connects the five most important constants.
\end{document

}

Compilation result of comprehensive math formula example


Summary

Requirements Syntax
Inline formula $...$
Display formula [...]
Superscripts and Subscripts x^{10}, a_{ij} (multiple characters require braces)
Fraction / Root \frac{a}{b}, \sqrt[n]{x}
Auto-sizing Parentheses \left( \right)
Large inline fraction \dfrac{a}{b}
Upright Characters \mathrm{e}