KaTeX(css:preload + js:defer) サンプルページ
KaTeX の もう一つの推奨パターン である Web フォントを rel="preload"
で先読みするパターンです。加えて、jsdelivr の結合機能 により2つのスクリプトを結合しているため、大抵のブラウザの TCP 同時接続数 以下で、並列に読み込む事が可能になります。
ディスプレイ数式(数式だけの行)
段落を分けるために前後を空行で囲むのが基本ルールです(例外あり)。
・$$...$$
$$
\frac{ \sum\limits_{n > 0} z^n }
{ \prod\limits_{1\leq k\leq n} (1-q^k) }
$$
\textstyle
を追加すると、テキストスタイルになります。
$$ \textstyle
\frac{ \sum\limits_{n > 0} z^n }
{ \prod\limits_{1\leq k\leq n} (1-q^k) }
$$
・\[...\]
前後に空行は必要ありませんが、二重の \\
で \
をエスケープする必要があります。1
テキスト
\\[
\sum_{i=1}^{n}(2\times i-1) = n^2
\\]
テキスト
テキスト \[ \sum_{i=1}^{n}(2\times i-1) = n^2 \] テキスト
\textstyle
を追加すると、テキストスタイルになります。
テキスト
\\[ \textstyle
\sum_{i=1}^{n}(2\times i-1) = n^2
\\]
テキスト
テキスト \[ \textstyle \sum_{i=1}^{n}(2\times i-1) = n^2 \] テキスト
・\begin{}...\end{}
MathJax と異なり、空行と $$...$$
で囲む必要があります。
$$
\begin{align}
Re[e^{ix}]&=\cos x \\
&=1-\frac{x^{2}}{2!}+\frac{x^{4}}{4!}- \cdots
\end{align}
$$
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}
$$
1行に収まる方程式であれば \textstyle
が効きます。空行も $$...$$
も不要で、ディスプレイ数式(数式だけの行)として表示されます。
テキスト
\begin{equation} \textstyle
\sum_{i=1}^{n}(2\times i-1) = n^2
\end{equation}
テキスト
テキスト \begin{equation} \textstyle \sum_{i=1}^{n}(2\times i-1) = n^2 \end{equation} テキスト
インライン数式(文章中の数式)
前後を空行で囲まず、1つの段落中に数式を記述します。
・$...$
デフォルトでは $...$
は使えないので、$$...$$
で囲みます。
テキスト
$$
\frac{d^2f}{dx^2} = f’’(x) = f^{(2)}(x)
$$
テキスト
テキスト \(\frac{d^2f}{dx^2} = f’’(x) = f^{(2)}(x)\) テキスト
・\(...\)
二重の \\
で \
をエスケープする必要があります。1
テキスト
\\(
\frac{d^2f}{dx^2} = f’’(x) = f^{(2)}(x)
\\)
テキスト
テキスト \( \frac{d^2f}{dx^2} = f’’(x) = f^{(2)}(x) \) テキスト
・\begin{}...\end{}
MathJax と異なり、LaTeX の仕様通り align
や equation
、split
はディスプレイ数式(数式だけの行)でしか使えません。インライン数式なら aligned
や 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}
$$
テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト テキスト
テキスト \(\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{align}
y&=(x+1)^2 -4x\\
&=x^2+2x+1-4x\\
&=x^2-2x+1\\
&=(x-1)^2
\end{align}
$$
円、楕円の公式
$$
x^2 + y^2 = 1
\frac{x^2}{a^2}+\frac{y^2}{b^2}=1
$$
テキスト
\\[
\int{x}\, dx = x^2 + C\,
\text{($C$ は積分定数)},\,
\int_{0}^{1}\frac{1}{\sqrt{1-x^2}} = \frac{\pi}{4}
\\]
\[ \int{x}\, dx = x^2 + C\, \text{($C$ は積分定数)},\, \int_{0}^{1}\frac{1}{\sqrt{1-x^2}} = \frac{\pi}{4} \]
ボックスで囲まれた式
$$
\boxed{\sin{(\frac{\pi}{4})}=\frac{\sqrt{2}}{2}}
$$