KaTeX推奨パターン では、defer 属性を付けた2つの <script><head> に配置します。2つ目の <script>onload から renderMathInElement() を呼び出してレンダリングを開始します。

\[\int \tan\theta \, d\theta = \int \frac{\sin\theta}{\cos\theta} \, d\theta = -\log|\cos\theta| + C\]

ディスプレイ数式(数式だけの行)

段落を分けるために前後を空行で囲むのが基本ルールです(例外あり)。

$$...$$

 
$$
s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2}
$$
 
\[s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2}\]

\textstyle を追加すると、テキストスタイルになります。

 
$$ \textstyle
s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2}
$$
 
\[\textstyle s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2}\]

\[...\]

前後に空行は必要ありませんが、二重の \\\ をエスケープする必要があります。1

テキスト
\\[
s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2}
\\]
テキスト

テキスト \[ s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2} \] テキスト

\textstyle を追加すると、テキストスタイルになります。

テキスト
\\[ \textstyle
s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2}
\\]
テキスト

テキスト \[ \textstyle s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2} \] テキスト

\begin{}...\end{}

MathJax と異なり、空行と $$...$$ で囲む必要があります。

 
$$
\begin{equation}
  \begin{split} 
    a &= \int_0^\infty f(x) \sin x \cos x \, dx \\
      &\quad + \int_0^\infty f(-x) \sin x \log x \, dx 
  \end{split}
\end{equation}
$$
 
\[\begin{equation} \begin{split} a &= \int_0^\infty f(x) \sin x \cos x \, dx \\ &\quad + \int_0^\infty f(-x) \sin x \log x \, dx \end{split} \end{equation}\]

split は方程式が1行に収まらないので、\textstyle は効きません。

 
$$
\begin{equation} \textstyle
  \begin{split}
    a &= \int_0^\infty f(x) \sin x \cos x \, dx \\
      &\quad + \int_0^\infty f(-x) \sin x \log x \, dx 
  \end{split}
\end{equation}
$$
 
\[\begin{equation} \textstyle \begin{split} a &= \int_0^\infty f(x) \sin x \cos x \, dx \\ &\quad + \int_0^\infty f(-x) \sin x \log x \, dx \end{split} \end{equation}\]

1行に収まる方程式であれば \textstyle が効きます。空行も $$...$$ も不要で、ディスプレイ数式(数式だけの行)として表示されます。

テキスト
\begin{equation} \textstyle
s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2}
\end{equation}
テキスト

テキスト \begin{equation} \textstyle s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2} \end{equation} テキスト

インライン数式(文章中の数式)

前後を空行で囲まず、1つの段落中に数式を記述します。

$...$

デフォルトでは $...$ は使えないので、$$...$$ で囲みます。

テキスト
$$
s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2}
$$
テキスト

テキスト \(s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2}\) テキスト

\(...\)

二重の \\\ をエスケープする必要があります。1

テキスト
\\(
s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2}
\\)
テキスト

テキスト \( s^2 = \frac{1}{n} \sum_{i=1}^n {(x_i - \overline{x})^2} \) テキスト

\begin{}...\end{}

MathJax と異なり、LaTeX の仕様通り alignequationsplit はディスプレイ数式(数式だけの行)でしか使えません。インライン数式なら alignedgathered を使います。

テキスト
$$
\begin{gathered}
  a &= \int_0^\infty f(x) \sin x \cos x \, dx \\
    &\quad + \int_0^\infty f(-x) \sin x \log x \, dx 
\end{gathered}
$$
テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト

テキスト \(\begin{gathered} a &= \int_0^\infty f(x) \sin x \cos x \, dx \\ &\quad + \int_0^\infty f(-x) \sin x \log x \, dx \end{gathered}\) テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト

様々な数式

二次方程式の解

When $$ a \ne 0 $$, there are two solutions to $$ ax^2 + bx + c = 0 $$ and they are
$$ x = {-b \pm \sqrt{b^2-4ac} \over 2a} $$

When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are \(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)

ローレンツ方程式

$$
\begin{align}
  \dot{x} & = \sigma(y-x) \\
  \dot{y} & = \rho x - y - xz \\
  \dot{z} & = -\beta z + xy
\end{align}
$$
\[\begin{align} \dot{x} & = \sigma(y-x) \\ \dot{y} & = \rho x - y - xz \\ \dot{z} & = -\beta z + xy \end{align}\]

テキスト

このテンポと4分音符一拍分の長さ(時間)は
$$ \textstyle
\frac{60000\;[msec]}{\text{1分間に数える回数}}
\;\times\;
\frac{n}{N4}
$$
となります。

このテンポと4分音符一拍分の長さ(時間)は \(\textstyle \frac{60000\;[msec]}{\text{1分間に数える回数}} \;\times\; \frac{n}{N4}\) となります。

ボックスで囲まれた式

$$
\boxed{\eta \leq C(\delta(\eta) +\Lambda_M(0,\delta))}
$$
\[\boxed{\eta \leq C(\delta(\eta) +\Lambda_M(0,\delta))}\]