LaTeX-Tutorial

5 minute read

Published:

阅读中文版

After more than half a year, I picked up LaTeX again to write algorithm homework and found that I had forgotten a ridiculous number of symbols. So I wrote this tutorial to record common LaTeX mathematical symbols and environments for future reference.

LaTeX Tutorial

1. Basic Syntax

1.1 Document Structure

\documentclass{article}  % Document type
\usepackage{amsmath}     % Math package
\usepackage{amssymb}     % Math symbol package

\begin{document}
% Document content
\end{document}

1.2 Text Formatting

\textbf{bold text}        % Bold
\textit{italic text}      % Italic
\underline{underline}     % Underline
\texttt{monospace text}   % Typewriter font

2. Math Mode

2.1 Inline and Display Formulas

Inline formula: $E = mc^2$
Display formula: $$E = mc^2$$
Or:
\[ E = mc^2 \]

2.2 equation Environment

\begin{equation}
  E = mc^2
\end{equation}

% Without numbering
\begin{equation*}
  E = mc^2
\end{equation*}

3. Common Mathematical Symbols

3.1 Greek Letters

Lowercase letters:

\alpha    α       \beta     β       \gamma    γ
\delta    δ       \epsilon  ε       \zeta     ζ
\eta      η       \theta    θ       \iota     ι
\kappa    κ       \lambda   λ       \mu       μ
\nu       ν       \xi       ξ       \pi       π
\rho      ρ       \sigma    σ       \tau      τ
\upsilon  υ       \phi      φ       \chi      χ
\psi      ψ       \omega    ω

Uppercase letters:

\Gamma    Γ       \Delta    Δ       \Theta    Θ
\Lambda   Λ       \Xi       Ξ       \Pi       Π
\Sigma    Σ       \Upsilon  Υ       \Phi      Φ
\Psi      Ψ       \Omega    Ω

3.2 Operators

Basic operations:

+         plus    -         minus   \times    ×
\div      ÷       \pm       ±       \mp       ∓
\cdot     ·       \ast      *       \star     ⋆

Relational operators:

=         =       \neq      ≠       <         <
>         >       \leq      ≤       \geq      ≥
\ll       ≪       \gg       ≫       \approx   ≈
\equiv    ≡       \sim      ∼       \simeq    ≃
\propto   ∝       \in       ∈       \notin    ∉
\subset   ⊂       \subseteq ⊆       \supset   ⊃

Logical symbols:

\land     ∧       \lor      ∨       \neg      ¬
\implies  ⟹       \iff      ⟺       \forall   ∀
\exists   ∃       \nexists  ∄       \emptyset ∅

3.3 Superscripts and Subscripts

x^2              % Superscript
x_i              % Subscript
x^{2y}           % Multi-character superscript
x_{ij}           % Multi-character subscript
x_i^2            % Superscript and subscript together

3.4 Fractions and Roots

\frac{a}{b}      % Fraction
\dfrac{a}{b}     % Display-style fraction
\tfrac{a}{b}     % Text-style fraction
\sqrt{x}         % Square root
\sqrt[n]{x}      % n-th root

3.5 Summation, Integrals, and Limits

\sum_{i=1}^{n}          % Summation
\prod_{i=1}^{n}         % Product
\int_{a}^{b}            % Integral
\iint                   % Double integral
\iiint                  % Triple integral
\oint                   % Contour integral
\lim_{x \to \infty}     % Limit

3.6 Brackets

()                       % Parentheses
[]                       % Square brackets
\{\}                     % Braces
\langle \rangle          % Angle brackets
\lfloor \rfloor          % Floor
\lceil \rceil            % Ceiling

Automatic sizing:

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

4. Matrices

4.1 Basic Matrices

% Matrix without brackets
\begin{matrix}
  a & b \\
  c & d
\end{matrix}

% Parenthesized matrix
\begin{pmatrix}
  a & b \\
  c & d
\end{pmatrix}

% Square-bracket matrix
\begin{bmatrix}
  a & b \\
  c & d
\end{bmatrix}

% Brace matrix
\begin{Bmatrix}
  a & b \\
  c & d
\end{Bmatrix}

% Single-vertical-line matrix
\begin{vmatrix}
  a & b \\
  c & d
\end{vmatrix}

% Double-vertical-line matrix
\begin{Vmatrix}
  a & b \\
  c & d
\end{Vmatrix}

4.2 Ellipses

\dots    % Low ellipsis
\cdots   % Centered ellipsis
\vdots   % Vertical ellipsis
\ddots   % Diagonal ellipsis

5. Multi-Line Formulas

5.1 align Environment

\begin{align}
  x &= a + b \\
  y &= c + d \\
  z &= e + f
\end{align}

5.2 cases Environment

f(x) = \begin{cases}
  x^2 & \text{if } x \geq 0 \\
  -x  & \text{if } x < 0
\end{cases}

5.3 split Environment

\begin{equation}
\begin{split}
  f(x) &= (x+1)^2 \\
       &= x^2 + 2x + 1
\end{split}
\end{equation}

6. Special Symbols

6.1 Arrows

\rightarrow  →       \leftarrow   ←
\Rightarrow  ⇒       \Leftarrow   ⇐
\leftrightarrow ↔    \Leftrightarrow ⇔
\uparrow     ↑       \downarrow   ↓
\Uparrow     ⇑       \Downarrow   ⇓
\mapsto      ↦       \longmapsto  ⟼
\longrightarrow ⟶    \Longrightarrow ⟹

6.2 Other Common Symbols

\infty       ∞       \partial     ∂
\nabla       ∇       \hbar        ℏ
\prime       ′       \ldots       …
\cdots       ⋯       \vdots       ⋮
\ddots       ⋱       \angle       ∠
\degree      °       \circ        ∘
\bullet      •       \cap         ∩
\cup         ∪       \triangle    △

6.3 Fonts

\mathbb{R}          % Blackboard bold
\mathcal{A}         % Calligraphic
\mathfrak{A}        % Fraktur
\mathbf{A}          % Bold
\mathrm{A}          % Roman
\mathit{A}          % Italic
\mathsf{A}          % Sans-serif
\mathtt{A}          % Typewriter

7. Spacing Control

a\ b              % Normal space
a\,b              % Small space
a\:b              % Medium space
a\;b              % Large space
a\quad b          % 1em space
a\qquad b         % 2em space
a\!b              % Negative space

8. Text Comments

\text{text content}           % Insert text inside a formula
\mbox{text content}           % Text box

9. Accents

\hat{a}      â       \bar{a}      ā
\tilde{a}    ã       \dot{a}      ȧ
\ddot{a}     ä       \vec{a}      ā⃗
\widehat{ab}         \widetilde{ab}

10. Common Theorem Environments

\usepackage{amsthm}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{proposition}{Proposition}
\newtheorem{corollary}{Corollary}
\newtheorem{definition}{Definition}

\begin{theorem}
  Theorem content
\end{theorem}

\begin{proof}
  Proof content
\end{proof}

11. Common Tips

11.1 Alignment

\begin{aligned}
  &\text{left aligned} \\
  &\text{content}
\end{aligned}

11.2 Numbering Control

\tag{1}              % Manual tag
\notag               % Remove numbering
\nonumber            % Remove numbering

11.3 Colors

\usepackage{xcolor}
\textcolor{red}{red text}
\colorbox{yellow}{yellow background}

12. Best Practices

  1. Matching brackets: use \left and \right to automatically adjust bracket size.
  2. Long formulas: use align or split to break lines.
  3. Matrices: choose an appropriate bracket type.
  4. Spacing: use \,, \quad, and similar commands to adjust spacing.
  5. Text: use \text{} to insert text in formulas.
  6. Symbols: define macros for complex symbols to simplify input.
% Custom command examples
\newcommand{\R}{\mathbb{R}}
\newcommand{\norm}[1]{\left\| #1 \right\|}

References