2137 字
11 分钟
KaTex语法
重要的事情

目前仍在搬运,预计在暑假结束完成基本语法的内容。

Katex简介#

根据 官网 的介绍,KaTeX\KaTeX是一个快速、易用的 JavaScript 库,用于在网络上渲染TeX\TeX数学图像。其语法与LaTeX\LaTeX类似,对于熟悉LaTeX\LaTeX的用户来说,使用起来非常简单。

声调记号#

第一列第二列第三列
aa' a'a~\tilde{a} \tilde{a}g˚\mathring{g} \mathring{g}
aa'' a''ac~\widetilde{ac}\widetilde{ac}AB\overgroup{AB}\overgroup{AB}
aa^{\prime} a^{\prime}AB~\utilde{AB} \utilde{AB}AB~\utilde{AB} \utilde{AB}
aˊ\acute{a} \acute{a}F\vec{F}\vec{F}AB\Overrightarrow{AB}\Overrightarrow{AB}
yˉ\bar{y} \bar{y}AB\overleftarrow{AB}\overleftarrow{AB}AB\overrightarrow{AB}\overrightarrow{AB}
a˘\breve{a} \breve{a}AB\underleftarrow{AB} \underleftarrow{AB}AB\underrightarrow{AB} \underrightarrow{AB}
aˇ\check{a} \check{a}ac\overleftharpoon{ac}\overleftharpoon{ac}ac\overrightharpoon{ac}\overrightharpoon{ac}
a˙\dot{a} \dot{a}AB\overleftrightarrow{AB}\overleftrightarrow{AB}AB\overbrace{AB}\overbrace{AB}
a¨\ddot{a} \ddot{a}AB\underleftrightarrow{AB} \underleftrightarrow{AB}AB\underbrace{AB} \underbrace{AB}
aˋ\grave{a} \grave{a}AB\overline{AB} \overline{AB}ABundefined\overlinesegment{AB}\overlinesegment{AB}
θ^\hat{\theta} \hat{\theta}AB\underline{AB} \underline{AB}ABundefined\underlinesegment{AB} \underlinesegment{AB}
ac^\widehat{ac}\widehat{ac}acˇ\widecheck{ac}\widecheck{ac}X\underbar{X} \underbar{X}

还有一些功能可以放在\text{}内使用

第一列第二列第三列第四列
aˊ\text{\'{a}} \'{a}a˜\text{\~{a}} \~{a}a˙\text{\.{a}} \.{a}a˝\text{\H{a}} \H{a}
aˋ\text{\`{a}} \`{a}aˉ\text{\={a}} \={a}a¨\text{\"{a}} \"{a}aˇ\text{\v{a}} \v{a}
aˆ\text{\^{a}} \^{a}a˘\text{\u{a}} \u{a}a˚\text{\r{a}} \r{a}

界定符(括号、箭头)#

第一列第二列第三列第四列第五列
()( ) ( )()\lparen \rparen \lparen \rparen⌈ ⌉ ⌈ ⌉\lceil \rceil \lceil rceil\uparrow \uparrow
[][ ] [ ][]\lbrack \rbrack \lbrack \rbrack⌊ ⌋ ⌊ ⌋\lfloor \rfloor \lfloor \rfloor\downarrow \downarrow
{}\{ \} \{ \}{}\lbrace \rbrace \lbrace \rbrace⎰ ⎱ ⎰ ⎱\lmoustache \rmoustache \lmoustache \rmoustache\updownarrow \updownarrow
⟨ ⟩ ⟨ ⟩\langle \rangle \langle \rangle⟮ ⟯ ⟮ ⟯\lgroup \rgroup \lgroup \rgroup\Uparrow \Uparrow
| |\vert \vert┌ ┐ ┌ ┐\ulcorner \urcorner \ulcorner \urcorner\Downarrow \Downarrow
\| \ |\Vert \Vert└ ┘ └ ┘\llcorner \lrcorner \llcorner \lrcorner\Updownarrow \Updownarrow
\lvert \rvert \lvert \rvert\lVert \rVert \lVert \rVert\left.\right.\\backslash \backslash
\lang \rang \lang \rang<>\lt \gt \lt \gt⟦ ⟧ ⟦ ⟧\llbracket \rrbracket \llbracket \rrbracket\lBrace \rBrace \lBrace \rBrace

界定符大小#

第一列第二列第三列第四列第五列
left\big\bigl\bigm\bigr
\middle\Big\Bigl\Bigm\Bigr
\right\bigg\biggl\biggm\biggr
\Big\Bigl\Bigm\Bigr

\left, \right, 和 \middle 是用来创建可伸缩的括号或其它包围符的命令,\left\right 必须成对出现,它们会根据它们之间的内容自动调整大小;\middle 通常与 \left\right 结合使用,它用于在括号之间插入额外的符号,如下所示。
(AB)\left(\LARGE{AB}\right) \left(\LARGE{AB}\right)
(((((( \big( \Big( \bigg( \Bigg( ( \big( \Big( \bigg( \Bigg(

环境#

第一列第二列第三列第四列
abcd\begin{matrix}a & b \\c & d\end{matrix}\begin{matrix}a&b\\c&d\endmatrix\begin{aligned}&\tt \backslash begin\{matrix\} \\&\tt\quad a \& b \backslash \backslash \\ &\tt\quad c \& d \\&\tt \backslash end{matrix} \\\end{aligned}abcd\begin{array}{cc}a & b \\c & d\end{array}\begin{array}{cc}a&b\\c&d\end{array}\begin{aligned}&\tt \backslash begin\{array\}\{cc\}\\&\tt\quad a \& b \backslash \backslash\\&\tt\quad c \& d\\&\tt \backslash end\{array\}\\\end{aligned}
(abcd)\begin{pmatrix}a & b \\c & d\end{pmatrix}\begin{pmatrix}a&b\\c&d\end{pmatrix}\begin{aligned}&\tt\backslash begin\{pmatrix\}\\&\tt\quad a \& b \backslash \backslash \\&\tt\quad c \& d\\&\tt\backslash end\{pmatrix\}\\\end{aligned}[abcd]\begin{bmatrix}a & b \\c & d\end{bmatrix}\begin{bmatrix}a&b\\c&d\end{bmatrix}\begin{aligned}&\tt\backslash begin\{bmatrix\} \\&\tt\quad a \& b \backslash \backslash \\&\tt\quad c \& d \\&\tt\backslash end\{bmatrix\} \\\end{aligned}
abcd\begin{vmatrix}a & b \\c & d\end{vmatrix}\begin{vmatrix}a&b\\c d\end{vmatrix}\begin{aligned}&\tt\backslash begin\{vmatrix\}\\&\tt\quad a \& b \backslash \backslash \\&\tt\quad c \ d\\&\tt\backslash end\{vmatrix\}\\\end{aligned}abcd\begin{Vmatrix}a & b \\c & d\end{Vmatrix}\begin{Vmatrix}a&b\\c d\end{Vmatrix}\begin{aligned}&\tt\backslash begin\{Vmatrix\}\\&\tt\quad a \& b \backslash \backslash \\&\tt\quad c \ d\\&\tt\backslash end\{Vmatrix\}\\\end{aligned}
{abcd}\begin{Bmatrix}a & b \\c & d\end{Bmatrix}\begin{Bmatrix}a&b\\c d\end{Bmatrix}\begin{aligned}&\tt\backslash begin\{Bmatrix\}\\&\tt\quad a \& b \backslash \backslash \\&\tt\quad c \ d\\&\tt\backslash end\{Bmatrix\}\\\end{aligned}abcdefghi\def\arraystretch{1.5} \begin{array}{c:c:c} a & b & c \\ \hline d & e & f \\\hdashline g & h & i\end{array}\def\arraystretch{1.5}\begin{array}{c:c:c}a&b&c\\\hlined&e&f\\\hdashlineg&h&i\end{array}\begin{aligned}&\tt\backslash def\backslash arraystretch\{1.5\}\\&\tt\quad \backslash begin\{array\}\{c:c:c\}\\&\tt\quad a \& b \& c \backslash\backslash \backslash hline\\&\tt\quad d \& e \& f \backslash \backslash\\&\tt\quad \backslash hdashline\\&\tt\quad g \& h \& i\\&\tt\backslash end\{array\}\end{aligned}
a=b+cd+e=f\begin{aligned}a&=b+c \\d+e&=f\end{aligned}\{aligned}a&=b+c\\d+e&=f\end{aligned}\begin{aligned}&\tt\backslash \{aligned\}\\&\tt\quad a\&=b+c \backslash \backslash \\&\tt\quad d+e\&=f\\&\tt\backslash end\{aligned\}\\\end{aligned}10x+3y=23x+13y=4\begin{alignedat}{2}10&x+ &3&y = 2 \\3&x+&13&y = 4\end{alignedat}\begin{alignedat}{2}10&x+&3&y=2\\3&x+&13&y=4\end{alignedat}\begin{aligned}&\tt\backslash begin\{alignedat\}\{2\}\\&\tt\quad 10\&x+ \&3\&y = 2 \backslash \backslash \\&\tt\quad 3\&x+\&13\&y = 4\\&\tt\backslash end\{alignedat\}\\\end{aligned}
a=be=b+c\begin{gathered}a=b \\e=b+c\end{gathered}\begin{gathered}a=b\\e=b+c\end{gathered}\begin{aligned}&\tt\backslash begin\{gathered\}\\&\tt\quad a=b \backslash\backslash\\&\tt\quad e=b+c\\&\tt\backslash end\{gathered\}\\\end{aligned}x={aif bcif dx = \begin{cases}a &\text{if } b \\c &\text{if } d\end{cases}x=\begin{cases}a&{if}b\\c&{if}d\endcases\begin{aligned}&\tt x = \backslash begin\{cases\} \\&\tt\quad a \&\text\{if \} b \backslash\backslash \\&\tt\quad c \&\text\{if \} d\\&\tt\backslash end{cases}\\\end{aligned}

字母和符号#

希腊字母#

直接输出:
ABΓΔEZHΘIKΛMNΞOΠPΣTΥXΦΨΩ\Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta \Theta \Iota \Kappa \Lambda \Mu \Nu \Xi \Omicron \Pi \Rho \Sigma \Tau \Upsilon \Chi \Phi \Psi \Omega
αβγδϵζηθικλμνξοπρστυϕχψωεϰϑϖϱςφϝ\alpha \beta \gamma \delta \epsilon \zeta \eta \theta \iota \kappa \lambda \mu \nu \xi \omicron \pi \rho \sigma \tau \upsilon \phi \chi \psi \omega \varepsilon \varkappa \vartheta \varpi \varrho \varsigma \varphi \digamma

第一列第二列第三列第四列第五列
A\Alpha \AlphaB\Beta \BetaΓ\Gamma \GammaΔ\Delta \DeltaE\Epsilon \Epsilon
Z\Zeta \ZetaH\Eta \EtaΘ\Theta \ThetaI\Iota \IotaK\Kappa \Kappa
Λ\Lambda \LambdaM\Mu \MuN\Nu \NuΞ\Xi \XiO\Omicron \Omicron
Π\Pi \PiP\Rho \RhoΣ\Sigma \SigmaT\Tau \TauΥ\Upsilon \Upsilon
X\Chi \ChiΨ\Psi \PsiΩ\Omega \OmegaΔ\varDelta \varDeltaΩ\varOmega \varOmega
α\alpha \alphaβ\beta \betaγ\gamma \gammaδ\delta \deltaϵ\epsilon \epsilon
ζ\zeta \zetaη\eta \etaθ\theta \thetaι\iota \iotaκ\kappa \kappa
λ\lambda \lambdaμ\mu \muν\nu \nuξ\xi \xiο\omicron \omicron
π\pi \piρ\rho \rhoσ\sigma \sigmaτ\tau \tauυ\upsilon \upsilon
ϕ\phi \phiχ\chi \chiψ\psi \psiω\omega \omegaε\varepsilon \varepsilon
ϰ\varkappa \varkappaϑ\vartheta \varthetaϑ\thetasym \thetasymϖ\varpi \varpiϱ\varrho \varrho
ς\varsigma \varsigmaφ\varphi \varphiϝ\digamma \digamma

其他字母#

第一列第二列第三列第四列第五列
ı\imath \imath\nabla \nabla\Im \ImR\Reals \RealsŒ\text{\OE} \text{\OE}
ȷ\jmath \jmath\partial \partial\image \image\wp \wpø\text{\o} \text{\o}
\aleph \aleph\Game \Gamek\Bbbk \Bbbk\weierp \weierpØ\text{\O} \text{\O}
\alef \alef\Finv \FinvN\N \NZ\Z \Zß\text{\ss} \text{\ss}
\alefsym \alefsymC\cnums \cnumsN\natnums \natnumsa˚\text{\aa} \text{\aa}ı\text{\i} \text{\i}
\beth \bethC\Complex \ComplexR\R \RA˚\AA \AAȷ\text{\j} \text{\j}
\gimel \gimel\ell \ell\Re \Reæ\text{\ae} \text{\ae}
\daleth \daleth\hbar \hbar\real \realÆ\text{\AE} \text{\AE}
ð\eth \eth\hslash \hslashR\reals \realsœ\text{\oe} \text{\oe}

字体#

字段支持的字符字段支持的字符
粗体A-Z,a-z,0-9\textbf{A-Z,a-z,0-9}双线体AZ,k\Bbb{A-Z,k}
意大利斜体A-Z,a-z\textit{A-Z,a-z}无衬线字体A-Z,a-z,0-9\textsf{A-Z,a-z,0-9}
粗意大利斜体A-Z,a-z\textbf{\textit{A-Z,a-z}}粗体无衬线A-Z,a-z,0-9\textsf{\textbf{A-Z,a-z,0-9}}
手写体AZ\mathscr{A-Z}斜体无衬线A-Z,a-z \textsf{\textit{A-Z,a-z }}
花体AZ,az\frak{A-Z,a-z}打字机字体A-Z,a-z,0-9\texttt{A-Z,a-z,0-9}

布局#

注解#

第一列第二列
5\cancel{5} \cancel{5}a+b+cnote\overbrace{a+b+c}^{\text{note}} \overbrace{a+b+c}^{\text{note}}
5\bcancel{5} \bcancel{5}a+b+cnote\underbrace{a+b+c}_{\text{note}} \underbrace{a+b+c}_{\text{note}}
ABC\xcancel{ABC}\xcancel{ABC}\not = \not =
abc\sout{abc} \sout{abc}π=cd\boxed{\pi=\frac c d} \boxed{\pi=\frac c d}
ana_{\angl n} $a_{\angl n}78\phase{-78^\circ} \phase{-78^\circ}

\tag{hi} x+y^{2x}

x+y2x(hi)\tag{hi} x+y^{2x}

\tag*{hi} x+y^{2x}

x+y2xhi\tag*{hi} x+y^{2x}

换行#

KaTeX\KaTeX 0.10.0之后会在关系式或二元运算符(如”=“或 ”+“)之后的内联数学中自动插入换行符。可以通过 \nobreak 或将数学放在一对大括号内,如 {F=ma} 来抑制这种情况。\allowbreak 允许在关系或运算符以外的位置自动换行。硬换行符是\\\newline。在显示数学中,KaTeX\KaTeX 不会插入自动换行符。当渲染选项为 strict: true 时,它会忽略显示数学的硬换行符。

垂直布局#

第一列第二列第三列
xnx_n x_n=!\stackrel{!}{=} \stackrel{!}{=}aba \atop b a \atop b
exe^x e^x=!\overset{!}{=} \overset{!}{=}abca\raisebox{0.25em}{$b$}c a\raisebox{0.25em}{$b$}c
uo_u^o _u^o=!\underset{!}{=} \underset{!}{=}a+(abc)a+\left(\vcenter{\hbox{$\frac{\frac a b}c$}}\right) a+\left(\vcenter{\hbox{$\frac{\frac a b}c$}}\right)

\sum_{\substack{0<i<m\\0<j<n}}

0<i<m0<j<n\sum_{\substack{0<i<m\\0<j<n}}

重叠和间距#

第一列第二列
=/{=}\mathllap{/\,} {=}\mathllap{/\,}(x2)\left(x^{\smash{2}}\right) \left(x^{\smash{2}}\right)
/=\mathrlap{\,/}{=} \mathrlap{\,/}{=}y\sqrt{\smash[b]{y}} \sqrt{\smash[b]{y}}

\sum_{\mathclap{1\le i\le j\le n}} x_{ij}

1ijnxij\sum_{\mathclap{1\le i\le j\le n}} x_{ij}

KaTeX\KaTeX 还支持 \llap\rlap\clap,但它们只在文本中使用。

\llap, \rlap, 和 \clap 命令被用来创建水平重叠的文字或符号,一般用在需要控制字符或符号的水平对齐方式时。

  • \llap{<text>}: 使左侧重叠,即文本不会占据任何水平空间,而是从当前位置向左“悬挂”出去。
  • \rlap{<text>}: 使右侧重叠,文本从当前位置向右“悬挂”,也不会占据任何额外的空间。
  • \clap{<text>}: 使在当前位置居中,但不会为文本分配任何宽度,从而实现一种“居中悬挂”的效果。

比如以下的区别
\sum\limits_{1\le i\le j \le k \le n}i\times j \times k

1ijkni×j×k\sum\limits_{1\le i\le j \le k \le n}i\times j \times k

\sum\limits_{\mathclap{1\le i\le j \le k \le n}}i\times j \times k

1ijkni×j×k\sum\limits_{\mathclap{1\le i\le j \le k \le n}}i\times j \times k

间隔#

指令备注指令备注
\,318\frac{3}{18} em\rm em 的间距\kern{distance}宽度为distance的间距
\thinspace318\frac{3}{18} em\rm em 的间距\mkern{distance}宽度为distance的间距
\>418\frac{4}{18} em\rm em 的间距\mskip{distance}宽度为distance的间距
\:418\frac{4}{18} em\rm em 的间距\hskip{distance}宽度为distance的间距
\medspace418\frac{4}{18} em\rm em 的间距\hspace{distance}宽度为distance的间距
\;518\frac{5}{18} em\rm em 间距\hspace*{distance}宽度为distance的间距
\thickspace518\frac{5}{18} em\rm em 间距\phantom{content}长与高等于参数的间距
\enspace12\frac{1}{2} em\rm em 间距\hphantom{content}高度等于参数的间距
\quad11 em\rm em 间距\vphantom{content}高度等于参数的间距
\qquad22 em\rm em 间距\!318\frac{3}{18} em\rm em 间距
~不换行间距\negthinspace318\frac{3}{18} em\rm em 间距
\<space>间距\negmedspace418\frac{4}{18} em\rm em 间距
\nobreakspace不换行间距\negthickspace518\frac{5}{18} em\rm em 间距
\space普通的空格\mathstrut\vphantom{(}

逻辑与集合符号#

第一列第二列第三列第四列
\forall \forall\complement \complement\therefore \therefore\emptyset \emptyset
\exists \exists\subset \subset\because \because\empty \empty
\exist \exist\supset \supset\mapsto \mapsto\varnothing \varnothing
\nexists \nexists\mid \mid\to \to    \implies \implies
\in \in\land \land\gets \gets    \impliedby \impliedby
\isin \isin\lor \lor\leftrightarrow \leftrightarrow    \iff \iff
\notin \notin\ni \ni\notni \notni¬\neg \neg 或者 \lnot

也可以直接输入:¬CHNPQR∀∴∁∵∃∣∈∋⊂⊃∧∨↦→←↔¬ℂℍℕℙℚℝ

宏定义#

待补充

运算符#

巨型运算符#

第一列第二列第三列第四列
\sum \sum\prod \prod\bigotimes \bigotimes\bigvee \bigvee
\int \int\coprod \coprod\bigoplus \bigoplus\bigwedge \bigwedge
\iint \iint\intop \intop\bigodot \bigodot\bigcap \bigcap
\iiint \iiint\smallint \smallint\biguplus \biguplus\bigcup \bigcup
\oint \oint\oiint \oiint\oiiint \oiiint\bigsqcup \bigsqcup

也可以直接输入:∫∬∭∮∏∐∑⋀⋁⋂⋃⨀⨁⨂⨄⨆∯∰

二元运算符#

第一列第二列第三列第四列
++ +\cdot \cdot\gtrdot \gtrdotx(moda)x \pmod a x \pmod a
- -\cdotp \cdotp\intercal \intercalx(a)x \pod a x \pod a
// /\centerdot \centerdot\land \land\rhd \rhd
* *\circ \circ\leftthreetimes \leftthreetimes\rightthreetimes \rightthreetimes
⨿\amalg \amalg\circledast \circledast.\ldotp \ldotp\rtimes \rtimes
&\And \And\circledcirc \circledcirc\lor \lor\setminus \setminus
\ast \ast\circleddash \circleddash\lessdot \lessdot\smallsetminus \smallsetminus
\barwedge \barwedge\Cup \Cup\lhd \lhd\sqcap \sqcap
\bigcirc \bigcirc\cup \cup\ltimes \ltimes\sqcup \sqcup
mod\bmod \bmod\curlyvee \curlyveexmodax \mod a x\mod a×\times \times
\boxdot \boxdot\curlywedge \curlywedge\mp \mp\unlhd \unlhd
\boxminus \boxminus÷\div \div\odot \odot\unrhd \unrhd
\boxplus \boxplus\divideontimes \divideontimes\ominus \ominus\uplus \uplus
\boxtimes \boxtimes\dotplus \dotplus\oplus \oplus\vee \vee
\bullet \bullet\doublebarwedge \doublebarwedge\otimes \otimes\veebar \veebar
\Cap \Cap\doublecap \doublecap\oslash \oslash\wedge \wedge
\cap \cap\doublecup \doublecup±\pm \pm 或者\plusmn\wr \wr

也可以直接输入:+/±×÷+−/∗⋅∘∙±×÷∓∔∧∨∩∪≀⊎⊓⊔⊕⊖⊗⊘⊙⊚⊛⊝◯∖

分数和二项式#

第一列第二列第三列
ab\frac{a}{b} \frac{a}{b}ab\tfrac{a}{b} \tfrac{a}{b}[15]^{[15]}(aa+1]\genfrac(]{2pt}{1}a{a+1} \genfrac (]{2pt}{1}a{a+1}
ab{a \over b} {a \over b}ab\dfrac{a}{b} \dfrac{a}{b}ab+1{a\above{2pt}b+1} {a \above{2pt} b+1}
a/ba/b a/ba1+1b\cfrac{a}{1+\cfrac{1}{b}} \cfrac{a}{1 +\cfrac{1}{b}}
(nk)\binom{n}{k} \binom{n}{k}(nk)\dbinom{n}{k} \dbinom{n}{k}{nk}{n\brace k} {n\brace k}
(nk){n \choose k} {n \choose k}(nk)\tbinom{n}{k} \tbinom{n}{k}[nk]{n\brack k} {n\brack k}

数学运算符#

第一列第二列第三列第四列
arcsin\arcsin \arcsincosec\cosec \cosecdeg\deg \degsec\sec \sec
arccos\arccos \arccoscosh\cosh \coshdim\dim \dimsin\sin \sin
arctan\arctan \arctancot\cot \cotexp\exp \expsinh\sinh \sinh
arctg\arctg \arctgcotg\cotg \cotghom\hom \homsh\sh \sh
arcctg\arcctg \arcctgcoth\coth \cothker\ker \kertan\tan \tan
arg\arg \argcsc\csc \csclg\lg \lgtanh\tanh \tanh
ch\ch \chctg\ctg \ctgln\ln \lntg\tg \tg
cos\cos \coscth\cth \cthlog\log \logth\th \th
arg max\argmax \argmaxinj lim\injlim \injlimmin\min \minlim\varinjlim \varinjlim
arg min\argmin \argminlim\lim \limplim\plim \plimlim\varliminf \varliminf
det\det \detlim inf\liminf \liminfPr\Pr \Prlim\varlimsup \varlimsup
gcd\gcd \gcdlim sup\limsup \limsupproj lim\projlim \projlimlim\varprojlim \varprojlim
inf\inf \infmax\max \maxsup\sup \supf\operatorname{f} \operatorname{f}

根号#

x\sqrt{x} \sqrt{x}
x3\sqrt[3]{x} \sqrt[3]{x}

关系符#

=!\stackrel{!}{=} \stackrel{!}{=}