amsmath + amssymb + mathtools — 数式の組版
CTAN: https://ctan.org/pkg/amsmath | https://ctan.org/pkg/mathtools
マニュアル: texdoc amsmath、texdoc mathtools
セットアップ
\usepackage{amsmath} % core math environments
\usepackage{amssymb} % extra symbols (loads amsfonts)
\usepackage{mathtools} % fixes + extensions for amsmath (loads amsmath)
\usepackage{amsthm} % theorem environments
% mathtools loads amsmath, so you can just use:
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsthm}
数式環境
単一の数式
% Numbered
\begin{equation}
E = mc^2
\label{eq:einstein}
\end{equation}
% Unnumbered
\begin{equation*}
E = mc^2
\end{equation*}
% or: \[ E = mc^2 \]
align — 複数の数式を揃える
\begin{align}
f(x) &= x^2 + 2x + 1 \label{eq:f} \\
&= (x+1)^2 \label{eq:f2}
\end{align}
% Unnumbered: align*
% Suppress single number: \nonumber or \notag before \\
gather — 揃えずに中央揃え
\begin{gather}
x + y = 1 \\
x - y = 3
\end{gather}
multline — 長い単一の数式
\begin{multline}
f(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3 \\
+ a_4 x^4 + a_5 x^5 + a_6 x^6
\end{multline}
最初の行は左揃え、最後の行は右揃え、中間の行は中央揃えになります。
split — equation 内での部分的な揃え
\begin{equation}
\begin{split}
f(x) &= a + b + c \\
&\quad + d + e
\end{split}
\end{equation}
グループ全体に対して数式番号が1つ付きます。
cases
\begin{equation}
|x| = \begin{cases}
x & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}
\end{equation}
% mathtools: dcases (displaystyle), rcases (right brace)
\begin{dcases}
\frac{x}{2} & x > 0 \\
0 & x = 0
\end{dcases}
aligned / gathered — インラインのサブ環境
% Use inside equation or \[ \] for sub-alignment
\begin{equation}
\left\{
\begin{aligned}
2x + 3y &= 7 \\
x - y &= 1
\end{aligned}
\right.
\end{equation}
subequations
\begin{subequations} \label{eq:system}
\begin{align}
x + y &= 1 \label{eq:system_a} \\
x - y &= 3 \label{eq:system_b}
\end{align}
\end{subequations}
% Produces (1a), (1b)
環境の概要
| 環境 | 揃え方 | 番号付け | 用途 |
|---|
equation | 中央揃え | 1つの番号 | 単一の数式 |
align | & 列 | 行ごと | 揃えた数式 |
gather | 中央揃え | 行ごと | 互いに関連しない数式 |
multline | 最初は左、最後は右 | 1つの番号 | 長い数式 |
split | & 列 | 1つの番号(親) | equation 内で部分的に揃える |
cases | & 列 | なし(equation 内) | 区分的な関数 |
aligned | & 列 | なし(equation 内) | インラインで部分的に揃える |
flalign | & 列 | 行ごと | 全幅で揃える |
番号なしのバリエーションを使うには * を追加します(split、aligned、gathered を除く)。
数式内のテキスト
\text{if } % normal text (respects surrounding font)
\mathrm{const} % upright roman
\textit{word} % italic text
\mathit{diff} % math italic (different spacing than default)
\mathbf{v} % bold (not for Greek — use \boldsymbol)
\boldsymbol{\alpha} % bold Greek
\mathbb{R} % blackboard bold: ℝ (amssymb)
\mathcal{L} % calligraphic: ℒ
\mathfrak{g} % Fraktur (amssymb)
\mathsf{X} % sans-serif
\mathtt{code} % monospace
\operatorname{span} % upright operator (one-off)
数式内のスペース
| コマンド | 幅 | 例 |
|---|
\, | 3/18 em(細) | \int f(x)\, dx |
\: または \> | 4/18 em(中) | |
\; | 5/18 em(太) | |
\! | −3/18 em(負の細スペース) | 詰めるには \!\! |
\quad | 1 em | x \quad y |
\qquad | 2 em | |
\phantom{x} | 「x」の幅のスペース | 揃えに使う |
\hphantom{x} | 水平方向のみ | |
\vphantom{x} | 垂直方向のみ | |
演算子
% Built-in: \sin, \cos, \tan, \log, \ln, \exp, \min, \max,
% \sup, \inf, \lim, \det, \dim, \ker, \gcd, \Pr, \hom, ...
% Custom operator (preamble)
\DeclareMathOperator{\tr}{tr} % like \sin
\DeclareMathOperator*{\argmax}{arg\,max} % limits below in display
% Usage
\tr(A) = \sum_i a_{ii} \qquad x^* = \argmax_x f(x)
行列
\begin{pmatrix} a & b \\ c & d \end{pmatrix} % ( )
\begin{bmatrix} a & b \\ c & d \end{bmatrix} % [ ]
\begin{Bmatrix} a & b \\ c & d \end{Bmatrix} % { }
\begin{vmatrix} a & b \\ c & d \end{vmatrix} % | | (determinant)
\begin{Vmatrix} a & b \\ c & d \end{Vmatrix} % ‖ ‖
\begin{matrix} a & b \\ c & d \end{matrix} % no delimiters
% Small inline matrix
$\bigl(\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\bigr)$
列の既定の最大数 = 10。 さらに増やすには、\setcounter{MaxMatrixCols}{20} を指定します。
区切り記号
% Auto-sizing (use sparingly — can oversize)
\left( \frac{a}{b} \right)
\left[ \sum_i x_i \right]
\left\{ x \in \mathbb{R} \mid x > 0 \right\}
\left. \frac{df}{dx} \right|_{x=0} % \left. = invisible delimiter
% Manual sizing (preferred for control)
\bigl( \bigr) % slightly bigger
\Bigl( \Bigr) % bigger
\biggl( \biggr) % even bigger
\Biggl( \Biggr) % biggest
% mathtools paired delimiters (best approach)
\DeclarePairedDelimiter\abs{\lvert}{\rvert}
\DeclarePairedDelimiter\norm{\lVert}{\rVert}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
\DeclarePairedDelimiter\set{\{}{\}}
% Usage:
\abs{x} % |x| (no sizing)
\abs*{x} % \left|x\right| (auto-sizing)
\abs[\big]{x} % \bigl|x\bigr| (manual)
mathtools の追加機能
% Colon equals
\coloneqq % :=
\eqqcolon % =:
% dcases (displaystyle fractions in cases)
\begin{dcases} ... \end{dcases}
% rcases (right brace)
\begin{rcases} ... \end{rcases}
% Short intertext (less vertical space than \intertext)
\begin{align}
f(x) &= x^2 \\
\shortintertext{where}
x &> 0
\end{align}
% Prescript (left sub/superscript)
\prescript{14}{6}{\mathrm{C}} % ¹⁴₆C
% Cramped styles
\cramped{x^{x^x}} % reduces height
% Smashed operator limits
\smashoperator{\sum_{i=1}^{n}}
記号一覧
ギリシャ文字
| 小文字 | 大文字 | 小文字 | 大文字 |
|---|
\alpha α | — | \nu ν | — |
\beta β | — | \xi ξ | \Xi Ξ |
\gamma γ | \Gamma Γ | \pi π | \Pi Π |
\delta δ | \Delta Δ | \rho ρ | — |
\epsilon ε | — | \sigma σ | \Sigma Σ |
\varepsilon ε | — | \tau τ | — |
\zeta ζ | — | \upsilon υ | \Upsilon Υ |
\eta η | — | \phi ϕ | \Phi Φ |
\theta θ | \Theta Θ | \varphi φ | — |
\iota ι | — | \chi χ | — |
\kappa κ | — | \psi ψ | \Psi Ψ |
\lambda λ | \Lambda Λ | \omega ω | \Omega Ω |
\mu μ | — | | |
異形: \varepsilon、\vartheta、\varphi、\varrho、\varsigma
関係記号
| 記号 | コマンド | 記号 | コマンド |
|---|
| ≤ | \leq | ≥ | \geq |
| ≪ | \ll | ≫ | \gg |
| ≠ | \neq | ≈ | \approx |
| ∼ | \sim | ≃ | \simeq |
| ≡ | \equiv | ≅ | \cong |
| ∝ | \propto | ∈ | \in |
| ∉ | \notin | ⊂ | \subset |
| ⊆ | \subseteq | ⊃ | \supset |
| ⊇ | \supseteq | ⊄ | \not\subset |
| ≺ | \prec | ≻ | \succ |
| ⊥ | \perp | ∥ | \parallel |
| ⊢ | \vdash | ⊣ | \dashv |
| ⊨ | \models | | |
二項演算子
| 記号 | コマンド | 記号 | コマンド |
|---|
| ± | \pm | ∓ | \mp |
| × | \times | ÷ | \div |
| · | \cdot | ∗ | \ast |
| ⊕ | \oplus | ⊗ | \otimes |
| ∪ | \cup | ∩ | \cap |
| ∨ | \vee | ∧ | \wedge |
| ∘ | \circ | • | \bullet |
| † | \dagger | ‡ | \ddagger |
矢印
| 記号 | コマンド | 記号 | コマンド |
|---|
| → | \to / \rightarrow | ← | \leftarrow |
| ⇒ | \Rightarrow | ⇐ | \Leftarrow |
| ↔ | \leftrightarrow | ⇔ | \Leftrightarrow |
| ↦ | \mapsto | ⟶ | \longrightarrow |
| ↑ | \uparrow | ↓ | \downarrow |
| ⇑ | \Uparrow | ⇓ | \Downarrow |
| ↗ | \nearrow | ↘ | \searrow |
| ⟹ | \implies | ⟸ | \impliedby |
| ⟺ | \iff | | |
| ↪ | \hookrightarrow | ↠ | \twoheadrightarrow |
大型演算子
| 記号 | コマンド | 記号 | コマンド |
|---|
| ∑ | \sum | ∏ | \prod |
| ∫ | \int | ∮ | \oint |
| ∬ | \iint | ∭ | \iiint |
| ⋃ | \bigcup | ⋂ | \bigcap |
| ⨁ | \bigoplus | ⨂ | \bigotimes |
| ⋁ | \bigvee | ⋀ | \bigwedge |
| ∐ | \coprod | | |
点
| コマンド | 出力 | 用途 |
|---|
\cdots | ⋯ | 演算子の間:$a + \cdots + z$ |
\ldots | … | リスト内:$a_1, \ldots, a_n$ |
\vdots | ⋮ | 垂直方向 |
\ddots | ⋱ | 対角方向(行列) |
その他の記号(amssymb)
| 記号 | コマンド | 記号 | コマンド |
|---|
| ℝ | \mathbb{R} | ℂ | \mathbb{C} |
| ℤ | \mathbb{Z} | ℕ | \mathbb{N} |
| ℚ | \mathbb{Q} | ∅ | \emptyset / \varnothing |
| ∞ | \infty | ∂ | \partial |
| ∇ | \nabla | ℓ | \ell |
| ℏ | \hbar | ∀ | \forall |
| ∃ | \exists | ¬ | \neg |
| √ | \sqrt{x} | ⁿ√ | \sqrt[n]{x} |
| ∠ | \angle | △ | \triangle |
| ⊤ | \top | ⊥ | \bot |
| ♠ | \spadesuit | ♣ | \clubsuit |
アクセント
| コマンド | 結果 | 用途 |
|---|
\hat{a} | â | 単位ベクトル |
\bar{a} | ā | 平均、共役 |
\vec{a} | a⃗ | ベクトル |
\dot{a} | ȧ | 時間微分 |
\ddot{a} | ä | 2階微分 |
\tilde{a} | ã | 近似 |
\widehat{abc} | 幅広のハット | 範囲を覆う |
\widetilde{abc} | 幅広のチルダ | 範囲を覆う |
\overline{abc} | 上線 | 集合、共役 |
\underline{abc} | 下線 | |
\overbrace{a+b}^{n} | 上括弧 | グループ化 |
\underbrace{a+b}_{n} | 下括弧 | グループ化 |
定理環境(amsthm)
\usepackage{amsthm}
% Define theorem types (preamble)
\newtheorem{theorem}{Theorem}[section] % numbered by section
\newtheorem{lemma}[theorem]{Lemma} % shares theorem counter
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}[theorem]{Proposition}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}
% Usage
\begin{theorem}[Pythagoras]
For a right triangle: $a^2 + b^2 = c^2$.
\end{theorem}
\begin{proof}
Obvious. % ends with □ automatically
% Use \qedhere to place □ at end of equation:
% \[ a^2 + b^2 = c^2 \qedhere \]
\end{proof}
定理スタイル
| スタイル | 本文のフォント | 見出し | 用途 |
|---|
plain(デフォルト) | イタリック | 太字 | 定理、補題 |
definition | 立体 | 太字 | 定義、例 |
remark | 立体 | イタリック | 備考、注記 |
よくある問題
| 問題 | 原因 | 対処法 |
|---|
$$...$$ | TeX プリミティブで、間隔が不適切 | \[...\] または equation* を使用する |
eqnarray | = の周囲の間隔が不適切 | 代わりに align を使用する(常に) |
| 数式番号が誤った行に表示される | 最終行の後に \\ がある | 末尾の \\ を削除する |
複数行にまたがる \left...\right | \\ をまたげない | 手動で \bigl...\bigr を使用する |
| ギリシャ文字を太字にできない | \mathbf が機能しない | \boldsymbol{\alpha} を使用する |
\displaystyle がない | インラインの分数が小さい | \dfrac(または \displaystyle\frac)を使用する |
:= の間隔が不適切 | コロンが関係演算子として扱われる | \coloneqq(mathtools)を使用する |
\mid と | と ` | ` の違い | 間隔がそれぞれ異なる |
| 数式で hbox がはみ出す | 数式の幅が広すぎる | multline、split、または手動の改行を使用する |
| 証明ボックスが表示されない | 環境内で \qed を使用している | 末尾に \qedhere を使用する |