前言
由于在洛谷,有很多人对于$\KaTeX$和$\LaTeX$之间的关系并不清楚,导致很多人去搜$\LaTeX$的资料,然后发现有许多指令无法在洛谷运行。
但是事实上,$\KaTeX$才是洛谷上的$\LaTeX$的渲染机制。因此只有$\KaTeX$支持的指令才能正常使用。在$\KaTeX$官网,其实有两张支持表,这里搬运过来以便于大家能够正确使用指令。
这张表应该涵盖了纯$\KaTeX$所有的功能。当然,$\LaTeX$公式大全亦可作为部分参考。下面是搬运部分。
受支持的功能
这是一张由$\KaTeX$支持的$\TeX$公式清单。他按照逻辑顺序分类。
这有一个相似的按照字典序排列的支持表。那张表格同样写出了不受支持的公式。
声调记号
第一列 | 第二列 | 第三列 |
---|---|---|
a′ a' |
ã \tilde{a} |
g̊ \mathring{g} |
a″ a'' |
$\widetilde{ac}$
\widetilde{ac} |
$\overgroup{AB}$\overgroup{AB} |
a′
a^{\prime} |
$\utilde{AB}$ \utilde{AB} |
$\undergroup{AB}$
\undergroup{AB} |
á \acute{a} |
F⃗ \vec{F} |
$\Overrightarrow{AB}$
\Overrightarrow{AB} |
ȳ \bar{y} |
$\overleftarrow{AB}$
\overleftarrow{AB} |
$\overrightarrow{AB}$
\overrightarrow{AB} |
ă \breve{a} |
$\underleftarrow{AB}$
\underleftarrow{AB} |
$\underrightarrow{AB}$
\underrightarrow{AB} |
ǎ \check{a} |
$\overleftharpoon{ac}$
\overleftharpoon{ac} |
$\overrightharpoon{ac}$
\overrightharpoon{ac} |
ȧ \dot{a} |
$\overleftrightarrow{AB}$
\overleftrightarrow{AB} |
$\overbrace{AB}$
\overbrace{AB} |
$\ddot{a}$ \ddot{a} |
$\underleftrightarrow{AB}$
\underleftrightarrow{AB} |
$\underbrace{AB}$
\underbrace{AB} |
à \grave{a} |
$\overline{AB}$
\overline{AB} |
$\overlinesegment{AB}$
\overlinesegment{AB} |
θ̂ \hat{\theta} |
$\underline{AB}$
\underline{AB} |
$\underlinesegment{AB}$
\underlinesegment{AB} |
$\widehat{ac}$ \widehat{ac} |
$\widecheck{ac}$
\widecheck{ac} |
另外,还有一些上下音标适合用在\text{}
环境下。[1] | 第一列 | 第二列 | 第三列 |
第四列 | | :———– | :———– | :———– | :———– | | á \'{a}
| ã \~{a}
| a \.{a}
| $\text{\H{a}}$ \H{a}
| | à [2]| ā \={a}
| ä \"{a}
| $ $ \v{a}
| | â \^{a}
| ă \u{a}
| $\text{\r{a}}$ \r{a}
| |
[1]:
这类特殊的音标需要用在文字环境下,即\text{}
里面。比如$\text{\'{a}}$
[2]: 由于会和$\rm
Markdown$的代码块冲突,这里说明一下,这个音标的代码其实是\+波浪线对应按键+{}
。
另请参阅 字母 章节。
定界符(括号之类)
第一列 | 第二列 | 第三列 | 第四列 | 第五列 |
---|---|---|---|---|
()
() |
()
\lparen\rparen |
⌈⌉
⌈ ⌉ |
⌈⌉
\lceil rceil |
↑
\uparrow |
[]
[ ] |
[]\lbrack\rbrack |
⌊⌋
⌊ ⌋ |
⌊⌋
\lfloor\rfloor |
↓
\downarrow |
{}
\{ \} |
{}
\lbrace\rbrace |
⎰⎱
⎰⎱ |
⎰⎱
\lmoustache\rmoustache |
↕
\updownarrow |
⟨⟩
⟨ ⟩ |
⟨⟩\langle\rangle |
⟮⟯
⟮ ⟯ |
⟮⟯
\lgroup\rgroup |
⇑
\Uparrow |
[3] | |
|
\vert |
┌┐
┌ ┐ |
⌜⌝
\ulcorner\urcorner |
⇓
\Downarrow |
∥
\| |
‖
\Vert |
└┘
└ ┘ |
⌞⌟
\llcorner\lrcorner |
⇕
\Updownarrow |
||\lvert\rvert |
‖‖
\lVert\rVert |
\left. [4] |
\right. |
∖
\backslash |
⟪⟫
\lang\rang |
< >\lt \gt |
⟦⟧⟦ ⟧ |
⟦⟧
\llbracket\rrbracket |
⦃⦄
\lBrace \rBrace |
[3]: 由于$\rm
Markdown$的制表与|
有冲突,因此无法在表格中显示 |。
[4]:
\left
和\right
后面直接加括号,能显示括号。(人类迷惑行为)
定界符大小[5]
$\left(\LARGE{AB}\right)$
\left(\LARGE{AB}\right)
(((((
( \big( \Big( \bigg( \Bigg(
[5]: 这里定界符主要指括号。$\KaTeX$提供了一些指令来调整括号的大小。另外,这里\left,\right
指令是自动调整括号大小。
第一列 | 第二列 | 第三列 | 第四列 | 第五列 |
---|---|---|---|---|
\left |
\big |
\bigl |
\bigm |
\bigr |
\middle |
\Big |
\Bigl |
\Bigm |
\Bigr |
\right |
\bigg |
\biggl |
\biggm |
\biggr |
\Bigg |
\Biggl |
\Biggm |
\Biggr |
环境[6]
第一列 | 第二列 | 第三列 | 第四列 |
---|---|---|---|
$\begin{matrix}a & b \\c & d\end{matrix}$ | $\begin{aligned}&\tt \backslash begin\{matrix\} \\&\tt\quad a \& b \backslash \backslash \\ &\tt\quad c \& d \\&\tt \backslash end{matrix} \\\end{aligned}$ | $\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}$ |
$\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}$ | $\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}$ |
$\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}$ | $\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}$ |
$\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}$ | $\def\arraystretch{1.5} \begin{array}{c:c:c} a & b & c \\ \hline d & e & f \\\hdashline g & 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}$ |
$\begin{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}$ | $\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}$ |
$\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 = \begin{cases}a &\text{if } b \\c &\text{if } d\end{cases}$ | $\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}$ |
$\begin{smallmatrix}a & b \\c & d\end{smallmatrix}$ | $\begin{aligned}&\tt\backslash begin\{smallmatrix\}\\&\tt\quad a \& b \backslash \backslash \\&\tt\quad c \ d\\&\tt\backslash end\{smallmatrix\}\\\end{aligned}$ |
[6]: 因为相关原因,在表格里换行不是很方便,因此这里直接嵌入的是$\KaTeX$。
Unicode[7]数学字母、符号
字段 | 支持的字符 | 字段 | 支持的字符 |
---|---|---|---|
粗体 | A-Z,a-z,0-9 | 双线体 | $\Bbb{A-Z,k}$ |
意大利斜体 | A-Z,a-z | 无衬线字体 | A-Z,a-z,0-9 |
粗意大利斜体 | $\textbf{\textit{A-Z,a-z}}$ | 粗体无衬线 | $\textsf{\textbf{A-Z,a-z,0-9}}$ |
手写体 | 𝒜 − 𝒵 | 斜体无衬线 | $\textsf{\textit{A-Z,a-z }}$ |
花体 | $\frak{A-Z,a-z}$ | 打字机字体 | A-Z,a-z,0-9 |
[7]: 这里$\rm Unicode$就是万国码。这里是指$\rm Unicode$里支持的字体样式。关于它们的指令,请参考下面的“字体”一段。
Unicode
上面列出的字母可以在任何$\KaTeX$模式下正确渲染。
此外,文本模式始终接受Brahmic,Georgian,中文,日文和韩文的字形。但是,这些字形将从系统字体(而不是$\KaTeX$提供的字体)中呈现,因此它们的版式可能会发生冲突。您可以为CSS类[8].latin-fallback
,.cyrillic-fallback
,.brahmic-fallback
,.georgian-fallback
,.cjk-fallback
和.hangul-fallback
中提供规则,以为这些语言提供后备字体。这些字形的使用可能会引起小的垂直对齐问题:$\KaTeX$列出了符号、大多数拉丁字母、希腊和西里尔字母的详细大小度量值,但其他接受的字形则被视为与当前$\KaTeX$字体中的字母M一样高。(因此很多时候$\KaTeX$用字母M作为参考大小——编者注)
如果$\KaTeX$呈现模式的设置中,strict设置为了false或warn(默认),则$\KaTeX$将在文本和数学模式下接受所有Unicode字母。所有无法识别的字符将被视为它们以文本模式显示。这样可能会遇到使用系统字体以及使用不正确的垂直对齐方式的问题。
对于波斯语中的复合字符,我们正在开发为用户提供的插件。(虽然你可能不会使用它——编者注)
[8]: 因为没怎么写过$\rm CSS$,所以可能说明上有一些问题。
布局
注解/标记
第一列 | 第二列 |
---|---|
$\cancel{5}$ \cancel{5} |
$\overbrace{a+b+c}^{\text{note}}$
\overbrace{a+b+c}^{\text{note}} |
$\bcancel{5}$ \bcancel{5} |
$\underbrace{a+b+c}_{\text{note}}$
\underbrace{a+b+c}_{\text{note}} |
$\xcancel{ABC}$
\xcancel{ABC} |
≠
\not = |
$\sout{abc}$ \sout{abc} |
$\boxed{\pi=\frac c d}$
\boxed{\pi=\frac c d} |
\tag{hi} x+y^{2x}
x + y2x
\tag*{hi} x+y^{2x}
x + y2x
换行指令
$\KaTeX$ 0.10.0版本之后将在关系或二元运算符(例如“
=”或“ +”)之后的内联数学中自动插入换行符。你可以通过\nobreak
或将公式放在一对大括号中来阻止自动换行,例如{F = ma}
。\allowbreak
将允许在关系或运算符以外的其他位置自动换行。
硬换行符是\\
和\newline
。[9]
在数学模式中,$\KaTeX$不会自动插入换行符。但是当渲染选项strict设置为true时,它将忽略显示数学模式并且插入硬换行。
[9]: 软换行换行不换段,硬换行换行也换段。简单来说,$\KaTeX$有时会自动换行,但换行之后仍在同一段,也就是软换行。而硬换行之后,两部分内容就分离了。
垂直布局
第一列 | 第二列 | 第三列 |
---|---|---|
xn
x_n |
$\stackrel{!}{=}$
\stackrel{!}{=} |
$a \atop
b$ a \atop b |
ex
e^x |
$\overset{!}{=}$
\overset{!}{=} |
$a\raisebox{0.25em}{b}c$
a\raisebox{0.25em}{b}c |
uo
_u^o |
$\underset{!}{=}$
\underset{!}{=} |
$\sum\limits_{\substack{0<i<m\\0<j<n}}$
\sum_{\substack{0<i<m\\0<j<n}} |
如果\raisebox
的第二个参数嵌套在$...$
分隔符内,则可以包含数学运算符,当然前提是整个公式包括在$$ $$
当中。例如$$a\raisebox{0.25em}{$\frac a b$}c$$
的显示效果为
$$a\raisebox{0.25em}{$\frac a b$}c$$
重叠和间距
第一列 | 第二列 |
---|---|
${=}\mathllap{/\,}$
{=}\mathllap{/\,} |
$\left(x^{\smash{2}}\right)$
\left(x^{\smash{2}}\right) |
$\mathrlap{\,/}{=}$
\mathrlap{\,/}{=} |
$\sqrt{\smash[b]{y}}$
\sqrt{\smash[b]{y}} |
$\sum\limits_{\mathclap{1\le i\le j\le n}}
x_{ij}$
\sum_{\mathclap{1\le i\le j\le n}} x_{ij}
$\KaTeX$同样支持\llap
[10],\rlap
和\clap
,但是它们仅能在文本模式中使用,而不是数学模式。
[10]:
这里解释一下这个命令的用处:当我们使用巨运算符时,它的上标/下标可能过长,比如$\sum\limits_{1\le i\le j \le k \le n}i\times j
\times
k$,这样i*j*k
离运算符较远。但是当我们用了这些指令,就可以自动缩小这个距离。
$$\sum\limits_{\mathclap{1\le i\le j \le k \le n}}i\times j \times k$$
间隔
指令 | 备注 | 指令 | 备注 |
---|---|---|---|
\, |
$\frac{3}{18}$ $\rm em$[11] 的间距 | \kern{distance} |
宽度为distance 的间距 |
\thinspace |
$\frac{3}{18}$ $\rm em$ 的间距 | \mkern{distance} |
宽度为distance 的间距 |
\> |
$\frac{4}{18}$ $\rm em$ 的间距 | \mskip{distance} |
宽度为distance 的间距 |
\: |
$\frac{4}{18}$ $\rm em$ 的间距 | \hskip{distance} |
宽度为distance 的间距 |
\medspace |
$\frac{4}{18}$ $\rm em$ 的间距 | \hspace{distance} |
宽度为distance 的间距 |
\; |
$\frac{5}{18}$ $\rm em$ 间距 | \hspace*{distance} |
宽度为distance 的间距 |
\thickspace |
$\frac{5}{18}$ $\rm em$ 间距 | \phantom{content} |
长与高等于参数的间距 |
\enspace |
$\frac{1}{2}$ $\rm em$ 间距 | \hphantom{content} |
高度等于参数的间距 |
\quad |
1 $\rm em$ 间距 | \vphantom{content} |
高度等于参数的间距 |
\qquad |
2 $\rm em$ 间距 | \! |
– $\frac{3}{18}$ $\rm em$ 间距 |
~ |
不换行间距 | \negthinspace |
– $\frac{3}{18}$ $\rm em$ 间距 |
\<space> |
间距 | \negmedspace |
– $\frac{4}{18}$ $\rm em$ 间距 |
\nobreakspace |
不换行间距 | \negthickspace |
– $\frac{5}{18}$ $\rm em$ 间距 |
\space |
普通的空格 |
[11]: 有关单位,请参考下方的“单位”一段。
提示
distance
参数可以接受任何$\KaTeX$的单位。
\kern
,\mkern
,\mskip
和\hspace
都可以直接加上距离参数,例如,\kern1em
可以生成一个宽度为$\rm 1em$的空格。
\mkern
和\mskip
在文本模式下不起作用,并且两者都将为mu
以外的任何单位显示警告。
逻辑与集合符号
第一列 | 第二列 | 第三列 | 第四列 |
---|---|---|---|
∀
\forall |
∁
\complement |
∴
\therefore |
∅
\emptyset |
∃
\exists |
⊂
\subset |
∵
\because |
$\empty$
\empty |
$\exist$
\exist |
⊃
\supset |
↦
\mapsto |
⌀
\varnothing |
∄
\nexists |
∣
\mid |
→
\to |
⟹
\implies |
∈
\in |
∧
\land |
←
\gets |
⟸
\impliedby |
$\isin$
\isin |
∨
\lor |
↔︎
\leftrightarrow |
⇔
\iff |
∉
\notin |
∋
\ni |
∌
\notni |
¬
\neg 或者 \lnot |
你也可以直接输入这些:∀∴∁∵∃ ∣ ∈ ∋ ⊂ ⊃ ∧∨ ↦ → ← ↔︎ ¬ℂℍℕℙℚℝ
宏定义
显示效果 | 代码 |
---|---|
x2 + x2 | \def\foo{x^2} \foo + \foo |
y2 + y2 | \gdef\bar#1{#1^2} \bar{y} + \bar{y} |
\global\def\名称#1#2…{定义} |
|
\newcommand\名称[参数数量]{定义} |
|
\renewcommand\名称[参数数量]{定义} |
|
\providecommand\名称[参数数量]{定义} |
你同样可以在$\KaTeX$的渲染选项中定义宏。[12]
宏最多接受九个参数:#1
,#2
等。
gdef和 global def宏将在数学表达式之间保留。
这些都是合法的指令名称:
\char
\mathchoice
\TextOrMath
\@ifstar
\@ifnextchar
\@firstoftwo
\@secondoftwo
\relax
@是命令的有效字符,就像你使用了\makeatletter
指令。[13]
[12]: 宏定义类似于$\rm
C++$中的\define
,可以简化代码,也可以嵌套。
可能有人不怎么清楚宏定义的具体用法,这里举个栗子:
假设我们有一段代码:
$$ \color{red}{\text{Hello world!!}}\\ \color{red}{\text{Hello world!!}}\\ \color{red}{\text{Hello world!!}}\\ $$
1 |
|
但是这样非常麻烦,所以我们可以用宏定义简化一下。
$$
\def{\HelloWorld}{\color{red}{\text{Hello world!!}}\\}
\HelloWorld\HelloWorld\HelloWorld
$$ 1
2
3
4$$
\def{\HelloWorld}{\color{red}{\text{Hello world!!}}\\}
\HelloWorld\HelloWorld\HelloWorld
$$
顺带解释一下一些细节。
\def,\newcommand
之类都可以直接加自定义指令的名称,而不需要加括号。比如\def\kkksc03{AK IOI!}
。\gdef,\global\def
用处比较诡异,一般用不到。和\def
的区别是,\def
如果在一定嵌套中定义,只能用在有限的定义域内。而\gdef
一类相当于直接在全局定义。可能有点模糊,这里举个栗子:{\def\t{2333} \t}
这句话定义后的\t
只能在括号中使用,比如{\def\t{2333} \t}
。而括号外会失效。{\def\t{2333}} \t
会渲染失败。而如果使用\gdef
一类,就会作用于“全局”。{\gdef\t{2333}} \t
成功渲染。关于下面三个
command
的关系:\newcommand
是定义一个新的指令,如果已经有同名指令,就会渲染失败。\renewcommand
是重新定义指令。但是如果原来没有这个指令,也会渲染失败(迷惑行为)。\providecommand
综合了上面两个指令的缺点,满足如果原来没有这个指令,就会定义一个;否则重新定义。(更迷惑了好不好)。关于覆写的问题:正如上面提到的,
\def
与\command
系列一样,只能作用于一定范围内,因此覆写的效果仅支持于这个范围。但是,如果将这些指令放在代码开头,就相当于全局定义了。\gdef
范围更广。\newcommand
不支持覆写;\renewcommand
只支持覆写;\providecommand
和\def
都支持覆写。关于多参数:首先,$\KaTeX$不支持不定参。然后,
\def
系列的参数可以这样定义:\def{\qwq}#1#2#3{#1+#2+#3=?}
要强调的是,参数只能从#1
开始排列,并且递增。比如,你要⑨个参数,只能这样写:\def{\名称}#1#2#3#4#5#6#7#8#9{定义}
(非常迷惑)。而command
系列相对方便,\newcommand{\名称}[参数数量]{定义}
就可以了。(总结:遇事不决用
\def
,全局定义用\def
,多参数还能用\def
,)\def
天下第一
[13]:
解释一下\makeatletter
指令:因为部分原因,我们在$\TeX$中无法使用@
作为指令名称,除非使用这个指令。而$\KaTeX$中的@
则不需要,所以说“就像你使用了\makeatletter
指令”。
运算符
巨型运算符[14]
第一列 | 第二列 | 第三列 | 第四列 |
---|---|---|---|
∑
\sum |
∏
\prod |
⨂
\bigotimes |
⋁
\bigvee |
∫
\int |
∐
\coprod |
⨁
\bigoplus |
⋀
\bigwedge |
∬
\iint |
$\intop$
\intop |
⨀
\bigodot |
⋂
\bigcap |
∭
\iiint |
$\smallint$ \smallint |
⨄
\biguplus |
⋃
\bigcup |
∮
\oint |
∯
\oiint |
∰
\oiiint |
⨆
\bigsqcup |
当然,你也可以直接输入这些: ∫∬∭∮∏∐∑⋀⋁⋂⋃⨀⨁⨂⨄⨆
[14]: 这里的巨型运算符在居中情况下自动变大,都支持上下标摆放在上下两侧。
二元运算符
第一列 | 第二列 | 第三列 | 第四列 |
---|---|---|---|
+
+ |
⋅
\cdot |
⋗
\gtrdot |
x (mod a)
x \pmod a |
−
- |
·
\cdotp |
⊺
\intercal |
x (a)
x \pod a |
/
/ |
⬝
\centerdot |
∧
\land |
⊳
\rhd |
*
* |
∘
\circ |
⋋
\leftthreetimes |
⋌
\rightthreetimes |
∐
\amalg |
⊛
\circledast |
$\ldotp$
\ldotp |
⋊
\rtimes |
$\And$
\And |
⊚
\circledcirc |
∨
\lor |
\
\setminus |
*
\ast |
⊝
\circleddash |
⋖
\lessdot |
∖
\smallsetminus |
⌅
\barwedge |
⋓
\Cup |
⊲
\lhd |
⊓
\sqcap |
○
\bigcirc |
∪
\cup |
⋉
\ltimes |
⊔
\sqcup |
$\bmod$
\bmod |
⋎
\curlyvee |
x mod a
x\mod a |
×
\times |
⊡
\boxdot |
⋏
\curlywedge |
∓
\mp |
⊴
\unlhd |
⊟
\boxminus |
÷
\div |
⊙
\odot |
⊵
\unrhd |
⊞
\boxplus |
⋇
\divideontimes |
⊖
\ominus |
⊎
\uplus |
⊠
\boxtimes |
∔
\dotplus |
⊕
\oplus |
∨
\vee |
•
\bullet |
⌆
\doublebarwedge |
⊗
\otimes |
⊻
\veebar |
⋒
\Cap |
$\doublecap$ \doublecap |
⊘
\oslash |
∧
\wedge |
∩
\cap |
$\doublecup$ \doublecup |
±
\pm 或者\plusmn |
≀
\wr |
当然,你也可以直接输入这些:+ − / ∗ ⋅ ± × ÷ ∓ ∔ ∧ ∨ ∩ ∪ ≀ ⊎ ⊓ ⊔ ⊕ ⊖ ⊗ ⊘ ⊙ ⊚ ⊛⊝
分数和二项式
第一列 | 第二列 | 第三列 |
---|---|---|
$\frac{a}{b}$ \frac{a}{b} |
$\tfrac{a}{b}$ \tfrac{a}{b} [15] |
$\genfrac(]{2pt}{1}a{a+1}$
\genfrac (]{2pt}{1}a{a+1} |
${a \over
b}$ {a \over b} |
$\dfrac{a}{b}$ \dfrac{a}{b} |
${a\above{2pt}b+1}$
{a \above{2pt} b+1} |
$\cfrac{a}{1+\cfrac{1}{b}}$
\cfrac{a}{1 +\cfrac{1}{b}} |
||
$\binom{n}{k}$ \binom{n}{k} |
$\dbinom{n}{k}$
\dbinom{n}{k} |
${n\brace
k}$ {n\brace k} |
${n \choose
k}$ {n \choose k} |
$\tbinom{n}{k}$
\tbinom{n}{k} |
${n\brack
k}$ {n\brack k} |
[15]: 在洛谷讨论区的$\KaTeX$版本中,有个$\rm
Bug$:嵌套使用\tfrac{}{}
会导致字体膨胀。
数学运算符
第一列 | 第二列 | 第三列 | 第四列 |
---|---|---|---|
arcsin
\arcsin |
$\cotg$
\cotg |
ln
\ln |
det
\det |
arccos
\arccos |
coth
\coth |
log
\log |
gcd
\gcd |
arctan
\arctan |
csc
\csc |
sec
\sec |
inf
\inf |
$\arctg$
\arctg |
$\ctg$
\ctg |
sin
\sin |
lim
\lim |
$\arcctg$
\arcctg |
$\cth$
\cth |
sinh
\sinh |
liminf
\liminf |
arg
\arg |
deg
\deg |
$\sh$
\sh |
limsup
\limsup |
$\ch$
\ch |
dim
\dim |
tan
\tan |
max
\max |
cos
\cos |
exp
\exp |
tanh
\tanh |
min
\min |
$\cosec$
\cosec |
hom
\hom |
$\tg$
\tg |
Pr
\Pr |
cosh
\cosh |
ker
\ker |
$\th$
\th |
sup
\sup |
cot
\cot |
lg
\lg |
$\argmax$
\argmax |
$\argmin$
\argmin |
$\plim$
\plim |
f
\operatorname{f} |
f
\operatorname*{f} |
参数显示在右侧的公式,如$\sum_{i=1}^{n}$可以使用\limits
强行显示在上下侧,$\sum\limits_{i=1}^{n}$,\sum\limits_{i=1}^{n}
开根
$\sqrt{x}$ \sqrt{x}
$\sqrt[3]{x}$
\sqrt[3]{x}
关系指令
$\stackrel{!}{=}$
\stackrel{!}{=}
第一列 | 第二列 | 第三列 | 第四列 |
---|---|---|---|
=
= |
≖
\eqcirc |
⋚
\lesseqgtr |
⊐
\sqsupset |
<
< |
≕
\eqcolon |
⪋
\lesseqqgtr |
⊒
\sqsupseteq |
>
> |
$\Eqcolon$ \Eqcolon |
≶
\lessgtr |
⋐
\Subset |
:
: |
≕
\eqqcolon |
≲
\lesssim |
⊂
\subset 或者 \sub |
≈
\approx |
$\Eqqcolon$ \Eqqcolon |
≪
\ll |
⊆
\subseteq 或者 \sube |
≊
\approxeq |
≂
\eqsim |
⋘
\lll |
⫅
\subseteqq |
≍
\asymp |
⪖
\eqslantgtr |
$\llless$
\llless |
≻
\succ |
϶
\backepsilon |
⪕
\eqslantless |
<
\lt |
⪸
\succapprox |
∽
\backsim |
≡
\equiv |
∣
\mid |
≽
\succcurlyeq |
⋍
\backsimeq |
≒
\fallingdotseq |
⊨
\models |
≽
\succeq |
≬
\between |
⌢
\frown |
⊸
\multimap |
≿
\succsim |
⋈
\bowtie |
≥
\ge |
∋
\owns |
⋑
\Supset |
≏
\bumpeq |
≥
\geq |
∥
\parallel |
⊃
\supset |
≎
\Bumpeq |
≧
\geqq |
⟂
\perp |
⊇
\supseteq 或者 \supe |
≗
\circeq |
≥
\geqslant |
⋔ ⋔
\pitchfork |
⫆
\supseteqq |
$\colonapprox$ \colonapprox |
≫
\gg |
≺
\prec |
$\thickapprox$ \thickapprox |
$\Colonapprox$ \Colonapprox |
⋙
\ggg |
⪷
\precapprox |
$\thicksim$ \thicksim |
≔
\coloneq |
$\gggtr$
\gggtr |
≼
\preccurlyeq |
⊴
\trianglelefteq |
⩴
\Coloneq |
>
\gt |
≼
\preceq |
≜
\triangleq |
≔
\coloneqq |
⪆
\gtrapprox |
≾
\precsim |
⊵
\trianglerighteq |
⩴
\Coloneqq |
⋛
\gtreqless |
∝
\propto |
∝
\varpropto |
$\colonsim$ \colonsim |
⪌
\gtreqqless |
≓
\risingdotseq |
▵
\vartriangle |
$\Colonsim$ \Colonsim |
≷
\gtrless |
$\shortmid$ \shortmid |
⊲
\vartriangleleft |
≅
\cong |
≳
\gtrsim |
$\shortparallel$
\shortparallel |
⊳
\vartriangleright |
⋞
\curlyeqprec |
∈
\in 或者 \isin |
∼
\sim |
$\vcentcolon$ \vcentcolon |
⋟
\curlyeqsucc |
⋈
\Join |
≃
\simeq |
⊢
\vdash |
⊣
\dashv |
≤
\le |
⌢
\smallfrown |
⊨
\vDash |
$\dblcolon$ \dblcolon |
≤
\leq |
⌣
\smallsmile |
⊩
\Vdash |
≐
\doteq |
≦
\leqq |
⌣
\smile |
⊪
\Vvdash |
≑
\Doteq |
≤
\leqslant |
⊏
\sqsubset |
|
≑
\doteqdot |
⪅
\lessapprox |
⊑
\sqsubseteq |
当然,你也可以直接输入这些:
$ ∉ ∌ ∤ ∦ ≁ ≆ ≠ ≨ ≩ ≮ ≯ ≰ ≱ ⊀ ⊁ ⊈ ⊉ ⊊ ⊋ ⊬ ⊭ ⊮ ⊯ ⋠ ⋡ ⋦ ⋧ ⋨ ⋩ ⋬ ⋭ ⪇ ⪈ ⪉ ⪊ ⪵ ⪶ ⪹ ⪺ ⫋ ⫌∈$
箭头
第一列 | 第二列 | 第三列 |
---|---|---|
↺
\circlearrowleft |
↼
\leftharpoonup |
$\rArr$
\rArr |
↻
\circlearrowright |
⇇
\leftleftarrows |
$\rarr$
\rarr |
↶
\curvearrowleft |
↔︎
\leftrightarrow |
↾
\restriction |
↷
\curvearrowright |
⇔
\Leftrightarrow |
→
\rightarrow |
$\Darr$
\Darr |
⇆
\leftrightarrows |
⇒
\Rightarrow |
$\dArr$
\dArr |
⇋
\leftrightharpoons |
↣
\rightarrowtail |
$\darr$
\darr |
↭
\leftrightsquigarrow |
⇁
\rightharpoondown |
⇠
\dashleftarrow |
⇚
\Lleftarrow |
⇀
\rightharpoonup |
⇢
\dashrightarrow |
←
\longleftarrow |
⇄
\rightleftarrows |
↓
\downarrow |
⇐
\Longleftarrow |
⇌
\rightleftharpoons |
⇓
\Downarrow |
↔︎
\longleftrightarrow |
⇉
\rightrightarrows |
⇊
\downdownarrows |
⇔
\Longleftrightarrow |
⇝
\rightsquigarrow |
⇃
\downharpoonleft |
↦
\longmapsto |
⇛
\Rrightarrow |
⇂
\downharpoonright |
→
\longrightarrow |
↱
\Rsh |
←
\gets |
⇒
\Longrightarrow |
↘
\searrow |
$\Harr$
\Harr |
↫
\looparrowleft |
↙
\swarrow |
$\hArr$
\hArr |
↬
\looparrowright |
→
\to |
$\harr$
\harr |
$\Lrarr$
\Lrarr |
↞
\twoheadleftarrow |
↩︎
\hookleftarrow |
$\lrArr$
\lrArr |
↠
\twoheadrightarrow |
↪
\hookrightarrow |
$\lrarr$
\lrarr |
$\Uarr$
\Uarr |
⇔
\iff |
↰
\Lsh |
$\uArr$
\uArr |
⟸
\impliedby |
↦
\mapsto |
$\uarr$
\uarr |
⟹
\implies |
↗
\nearrow |
↑
\uparrow |
$\Larr$
\Larr |
↚
\nleftarrow |
⇑
\Uparrow |
$\lArr$
\lArr |
⇍
\nLeftarrow |
↕
\updownarrow |
$\larr$
\larr |
↮
\nleftrightarrow |
⇕
\Updownarrow |
⤳
\leadsto |
⇎
\nLeftrightarrow |
↿
\upharpoonleft |
←
\leftarrow |
↛
\nrightarrow |
↾
\upharpoonright |
⇐
\Leftarrow |
⇏
\nRightarrow |
⇈
\upuparrows |
↢
\leftarrowtail |
↖
\nwarrow |
|
↽
\leftharpoondown |
$\Rarr$
\Rarr |
你也可以直接输入这些:$ ← ↑ → ↓ ↔︎ ↕ ↖ ↗ ↘ ↙ ↚ ↛ ↞ ↠ ↢ ↣ ↦ ↩︎ ↪ ↫ ↬ ↭ ↮ ↰ ↱↶ ↷ ↺ ↻ ↼ ↽ ↾ ↾ ↿ ⇀ ⇁ ⇂ ⇃ ⇄ ⇆ ⇇ ⇈ ⇉ ⇊ ⇋ ⇌⇍ ⇎ ⇏ ⇐ ⇑ ⇒ ⇓ ⇔ ⇕ ⇚ ⇛ ⇝ ⇠ ⇢ $
箭头扩展[16]
第一列 | 第二列 |
---|---|
$\xleftarrow{abc}$
\xleftarrow{abc} |
$\xrightarrow[under]{over}$
\xrightarrow[under]{over} |
$\xLeftarrow{abc}$
\xLeftarrow{abc} |
$\xRightarrow{abc}$
\xRightarrow{abc} |
$\xleftrightarrow{abc}$
\xleftrightarrow{abc} |
$\xLeftrightarrow{abc}$
\xLeftrightarrow{abc} |
$\xhookleftarrow{abc}$
\xhookleftarrow{abc} |
$\xhookrightarrow{abc}$
\xhookrightarrow{abc} |
$\xtwoheadleftarrow{abc}$
\xtwoheadleftarrow{abc} |
$\xtwoheadrightarrow{abc}$
\xtwoheadrightarrow{abc} |
$\xleftharpoonup{abc}$
\xleftharpoonup{abc} |
$\xrightharpoonup{abc}$
\xrightharpoonup{abc} |
$\xleftharpoondown{abc}$
\xleftharpoondown{abc} |
$\xrightharpoondown{abc}$
\xrightharpoondown{abc} |
$\xleftrightharpoons{abc}$
\xleftrightharpoons{abc} |
$\xrightleftharpoons{abc}$
\xrightleftharpoons{abc} |
$\xtofrom{abc}$
\xtofrom{abc} |
$\xmapsto{abc}$
\xmapsto{abc} |
$\xlongequal{abc}$
\xlongequal{abc}
可扩展的箭头都可以用相同的方式接受可选参数,比如说,\xrightarrow[under]{over}
显示出来就是$\xrightarrow[under]{over}$。
[16]: 这里扩展箭头指箭头上下方可以放置文字,且箭头长度随文字长度的增加而增加。
样式,颜色,大小和字体
类的分配[17]
\mathbin
\mathclose
\mathinner
\mathop
\mathopen
\mathord
\mathpunct
\mathrel
颜色
F = ma
\color{blue} F=ma
请注意,$\KaTeX$
中的\color
的作用类似于开关,使用后一定范围内所有的字体都会改变颜色。这与$\LaTeX$一致,但是与$\rm MathJax$不同。而$\KaTeX$得其他颜色指令中,它的颜色和内容都是参数;
$\textcolor{blue}{F=ma}$\textcolor{#228B22}{F=ma}
$\colorbox{aqua}{A}$\colorbox{aqua}{A}
[18]
$\fcolorbox{red}{aqua}{A}$
\fcolorbox{red}{aqua}{A}
对于颜色的名称,$\KaTeX$颜色函数将接受标准的$\rm
HTML$预定义颜色名称。他们还将接受$\rm CSS$十六进制样式的$\rm
RGB$参数,比如#ff0000
表示红色,而其中的#
是可选的。(不过洛谷讨论区版本较旧,因此在那里必须加#
)。
[18]:
\colorbox
和\fcolorbox
里面不能嵌套环境,但是\box
能。
字体
第一列 | 第二列 | 第三列 |
---|---|---|
Ab0
\mathrm{Ab0} |
Ab0
\mathbf{Ab0} |
Ab0
\mathit{Ab0} |
$\mathnormal{Ab0}$
\mathnormal{Ab0} |
Ab0
\textbf{Ab0} |
Ab0 \textit{Ab0} |
Ab0
\textrm{Ab0} |
$\bf{Ab0}$ \bf{Ab0} |
$\it{Ab0}$ \it Ab0 |
$\rm{Ab0}$ \rm{Ab0} |
$\bold{Ab0}$ \bold{Ab0} |
$\textup{Ab0}$ \textup{Ab0} |
$\textnormal{Ab0}$
\textnormal{Ab0} |
Ab0
\boldsymbol{Ab} |
$\Bbb{AB}$ \Bbb{AB} |
Ab0
\text{Ab0} |
Ab0
\bm{Ab0} |
𝔸𝔹
\mathbb{AB} |
Ab0
\mathsf{Ab0} |
$\textmd{Ab0}$ \textmd{Ab0} |
$\frak{Ab0}$ \frak{Ab0} |
Ab0
\textsf{Ab0} |
A b 0
\mathtt{Ab0} |
𝔄𝔟0
\mathfrak{Ab0} |
$\sf{Ab0}$ \sf Ab0 |
Ab0
\texttt{Ab0} |
𝒜ℬ0
\mathcal{AB0} |
$\tt{Ab0}$ \tt Ab0 |
𝒜ℬ
\mathscr{AB} |
通过使用\textXX
类型的字体指令,可以堆叠字体样式、粗细和形状。
因此\textsf{\textbf{H}}
将渲染出$\textsf{\textbf{H}}$。其他字体指令不会堆叠,例如\mathsf{\mathbf{H}}
将渲染出H。
如果KaTeX字体没有粗体字形,你可以使用\pmb
指令可以模拟一个。例如,\pmb{\ mu}
呈现为:μ。(所以莫反一类文章的大量希腊字母粗体都可以用这种方法生成——编者注)。
大小
第一列 | 第二列 |
---|---|
$\Huge
AB$ \Huge AB |
$\normalsize
AB$ \normalsize AB |
$\huge
AB$ \huge AB |
$\small
AB$ \small AB |
$\LARGE
AB$ \LARGE AB |
$\footnotesize
AB$ \footnotesize AB |
$\Large
AB$ \Large AB |
$\scriptsize
AB$ \scriptsize AB |
$\large
AB$ \large AB |
$\tiny
AB$ \tiny AB |
样式
显示效果 | 代码 |
---|---|
$\displaystyle\sum_{i=1}^n$ | \displaystyle\sum_{i=1}^n |
$\textstyle\sum_{i=1}^n$ | \textstyle\sum_{i=1}^n |
x | \scriptstyle x (The size of a first sub/superscript) |
x | \scriptscriptstyle x (The size of subsequent sub/superscripts) |
$\lim\limits_x$ | \lim\limits_x |
limx | \lim\nolimits_x |
$\verb!x^2!$ | \verb!x^2! [19] |
在居中的环境下(即在$$ $$
当中),在\text{}
里面可以放置$...$
用来显示数学模式。
[19]:
\verb
以两个感叹号作为括号,里面可以填充任意文字。使用等宽字体(打字机字体)。
符号和标点
第一列 | 第二列 | 第三列 |
---|---|---|
% 注释 |
…
\dots |
$\KaTeX$
\KaTeX |
%
\% |
⋯
\cdots |
$\LaTeX$
\LaTeX |
#
\# |
⋱
\ddots |
$\TeX$
\TeX |
&
\& |
…
\ldots |
∇
\nabla |
$\__$
\_ |
⋮
\vdots |
∞
\infty |
$\text{\textunderscore}$
\text{\textunderscore} |
⋯
\dotsb |
$\infin$
\infin |
–
\text{--} |
…
\dotsc |
✓
\checkmark |
$\text{\textendash}$
\text{\textendash} |
⋯
\dotsi |
†
\dag |
—
\text{---} |
⋯
\dotsm |
†
\dagger |
$\text{\textemdash}$
\text{\textemdash} |
…
\dotso |
$\text{\textdagger}$
\text{\textdagger} |
~
\text{\textasciitilde} |
$\sdot⋅$
\sdot |
‡
\ddag |
^
\text{\textasciicircum} |
$\mathellipsis$
\mathellipsis |
‡
\ddagger |
[20] | $\text{\textellipsis}$
\text{\textellipsis} |
$\text{\textdaggerdbl}$
\text{\textdaggerdbl} |
$\text{\textquoteleft}$
text{\textquoteleft} |
□
\Box |
$\Dagger$
\Dagger |
$\lq$
\lq |
▫
\square |
∠
\angle |
$\text{\textquoteright}$
\text{\textquoteright} |
◼
\blacksquare |
∡
\measuredangle |
$\rq$
\rq |
△
\triangle |
∢
\sphericalangle |
$\text{\textquotedblleft}$
\text{\textquotedblleft} |
▿
\triangledown |
⊤
\top |
$"$
" |
⊲
\triangleleft |
⊥
\bot |
$\text{\textquotedblright}$
\text{\textquotedblright} |
⊳
\triangleright |
$
\$ |
:
\colon |
▽
\bigtriangledown |
$\text{\textdollar}$
\text{\textdollar} |
‵
\backprime |
△
\bigtriangleup |
£
\pounds |
′
\prime |
▴
\blacktriangle |
£
\mathsterling |
$\text{\textless}$
\text{\textless} |
▾
\blacktriangledown |
$\text{\textsterling}$
\text{\textsterling} |
$\text{\textgreater}$
\text{\textgreater} |
◂
\blacktriangleleft |
¥
\yen |
$\text{\textbar}$
\text{\textbar} |
▸
\blacktriangleright |
$\surd$
\surd |
$\text{\textbardbl}$
\text{\textbardbl} |
⋄
\diamond |
$\degree$
\degree |
$\text{\textbraceleft}$
\text{\textbraceleft} |
◇
\Diamond |
$\text{\textdegree}$
\text{\textdegree} |
$\text{\textbraceright}$
\text{\textbraceright} |
◊
\lozenge |
℧
\mho |
\
\text{\textbackslash} |
⬧
\blacklozenge |
$\diagdown$ \diagdown |
$\text{\P}$ \text{\P} |
⋆
\star |
$\diagup$
\diagup |
$\text{\S}$ \text{\S} |
★
\bigstar |
♭
\flat |
$\text{\sect}$ \text{\sect} |
♣
\clubsuit |
♮
\natural |
$\copyright$ \copyright |
$\clubs$
\clubs |
♯
\sharp |
®
\circledR |
♢
\diamondsuit |
♡
\heartsuit |
$\text{\textregistered}$
\text{\textregistered} |
$\diamonds$ \diamonds |
$\hearts$
\hearts |
$\circledS$ \circledS |
♠
\spadesuit |
$\spades$
\spades |
$\text{\textcircled a}$
\text{\textcircled a} |
✠
\maltese |
你也可以直接输入这些:$£ ¥ ∇ ∞ · ∠ ∡ ∢ ♠ ♡ ♢ ♣ ♭ ♮ ♯ ✓ … ⋮ ⋯ ⋱ ! $
[20]: 同样由于$\rm
Markdown$制表问题,无法显示字符`。这里的显示效果就是$\lq$,同\lq
。
单位
在$\KaTeX$中,单位与在$\TeX$中一样按比例进行处理。
但是很多地方,$\KaTeX$单位不同于$\rm CSS$单位。
$\text{\KaTeX 单位}$ | 备注 | $\text{\KaTeX 单位}$ | 备注 |
---|---|---|---|
em | CSS em | bp | 1/72 inch × F × G |
ex | CSS ex | pc | $\text{12 \KaTeX pt}$ |
mu | 1/18 CSS em | dd | $\text{1238/1157 \KaTeX pt}$ |
pt | 1/72.27 inch × F × G | cc | $\text{14856/1157 \KaTeX pt}$ |
mm | 1 mm × F × G | nd | $\text{685/642 \KaTeX pt}$ |
cm | 1 cm × F × G | nc | $\text{1370/107 \KaTeX pt}$ |
in | 1 inch × F × G | sp | $\text{1/65536 \KaTeX pt}$ |
其中,
F=(围绕着$\rm HTML$文字的字体大小)/($\rm 10 pt$)
G默认情况下为1.21,因为$\KaTeX$字体大小通常为1.21×周围字体大小。$\rm HTML$网页的$\rm CSS$可以覆盖此值。
样式和大小的影响范围:
单位 | 文本模式 | $\rm script$大小[21] | $\rm huge$大小 |
---|---|---|---|
em 与 ex | $\rule{1em}{1em}$ | $\scriptscriptstyle\rule{1em}{1em}$ | $\huge\rule{1em}{1em}$ |
mu | $\rule{18mu}{18mu}$ | $\scriptscriptstyle\rule{18mu}{18mu}$ | $\huge\rule{18mu}{18mu}$ |
其他 | $\rule{10pt}{10pt}$ | $\scriptscriptstyle\rule{10pt}{10pt}$ | $\huge\rule{10pt}{10pt}$ |
[21]:
这里不确定如何翻译scriptscript
和huge
。
本文全部译自$\KaTeX$官网。
历时1.5天终于肝完了$\rm orz$。希望能为洛谷的$\LaTeX$发展做出一些贡献。可能有一些不足,希望能在博客的评论区提出来。