MathJax Quick Memo

Basis


Formula Mark

使用MathJax时,需要用一些适当的标记告诉MathJax某段文本是公式代码。此外,MathJax中的公式排版有两种方式,inlinedisplayedinline表示公式嵌入到文本段中,displayed表示公式独自成为一个段落(也就是居中显示)。例如 这是一个inline公式,而下面:

这就是一个displayed公式。

MathJax中,默认的displayed公式分隔符有$$...$$\[...\],而默认的inline公式分隔符是$...$

Greek Letter

具体见下表:

名称 大写 Tex 小写 Tex
alpha \alpha
beta \beta
gamma \Gamma \gamma
delta \Delta \delta
epsilon \epsilon
zeta \zeta
eta \eta
theta \theta \theta
iota \iota
kappa \kappa
lambda \Lambda \lambda
mu \mu
nu \nu
xi \Xi \xi
omicron \omicron
pi \Pi \pi
rho \rho
sigma \Sigma \sigma
tau \tau
upsilon \Upsilon \upsilon
phi \Phi \phi
chi \chi
psi \Psi \psi
omega \Omega \omega

Superscript & Subscript

上标和下标分别用^_,如x_i^2:,但是^_分别只对下一个数起作用,比如10^10会得到而不是 ,这事需要用{...}把要组合的数组合起来,也就是10^{10}。总之,加了大括号总归不会错。

Brackets

需要注意的是,原始的符号不会随着公式的变大而缩放,比如\frac{1}{2}:。可以使用\left( ... \right)进行缩放,如下:

\{ \sum_{i=0}^{n}i^2 = \frac {(n^2+n)(2n+1)}{6} \}

\left\{ \sum_{i=0}^{n}i^2 = \frac {(n^2+n)(2n+1)}{6} \right\}

Summation & Integration

Fraction & Radical Expression

Font Family

Special Functions & Symbols

Space

由于MathJax的空间管理比较特殊,所以 a.b或者 a.........b(…表示空格),都会显示为 a b:,如果要增加间隙,可以使用 a\,b:,较宽的间隙 a\;b:,或者是使用 a\quad b:a\qquad b:。还有一种比较方便的方法是不使用转义字符\而是这样 a~b:,可以表示一个空格。

Symbols over letters

对于单字符, \hat x:,对于多个字符使用 \widehat {xy}:,类似的还有 \overline {xy}:,\vec {xy}: ,\overrightarrow {xy}:,\dot {xy}:,\ddot {xy}:,

Form


可以使用 $$\begin{array}{列样式}…\end{array}$$的方式来创建表格,其中列样式可以clr分别表示居中 ,还可以用|表示一条竖线。表格中每一行用\\分隔,每一列使用 &分隔,使用 \hline在本行前面加一条直线,例如:

$$
\begin{array}{c|lcr}
n & \text{Left} & \text{Center} & \text{Right} \\
\hline
1 & 0.24 & 1 & 125 \\
2 & -1 & 189 & -8 \\
3 & -20 & 2000 & 1+10i \\
\end{array}
$$

一个可以复用的例子如下:

$$
\begin{array}{c|ccc}
n & \text{0} & \text{1} & \text{2} & \text{3}\\
\hline
1 & 1 & 2 & 3 & 4 \\
2 & 2 & 3 & 4 & 5 \\
3 & 3 & 4 & 5 & 6 \\
4 & 4 & 5 & 6 & 7 \\
\end{array}
$$

Matrix


Basis Usage

使用$$\begin{matrix}…\end{matrix}$$来表示矩阵,同样使用 \\作为行分隔符,&使用列分隔符。

例如:

$$
        \begin{matrix}
        1 & x & x^2 \\
        1 & y & y^2 \\
        1 & z & z^2 \\
        \end{matrix}
$$

Matrix Brackets

如果要加括号,可以使用\left\right,也可以使用特殊的Matrix,例如:

$$
\left ( \begin{matrix}
1 & x & x^2 \\
1 & y & y^2 \\
1 & z & z^2 \\
\end{matrix}\right )
$$
$$
        \begin{pmatrix}
        1 & x & x^2 \\
        1 & y & y^2 \\
        1 & z & z^2 \\
        \end{pmatrix}
$$
$$
        \begin{bmatrix}
        1 & x & x^2 \\
        1 & y & y^2 \\
        1 & z & z^2 \\
        \end{bmatrix}
$$
$$
        \begin{Bmatrix}
        1 & x & x^2 \\
        1 & y & y^2 \\
        1 & z & z^2 \\
        \end{Bmatrix}
$$
$$
        \begin{vmatrix}
        1 & x & x^2 \\
        1 & y & y^2 \\
        1 & z & z^2 \\
        \end{vmatrix}
$$
$$
        \begin{Vmatrix}
        1 & x & x^2 \\
        1 & y & y^2 \\
        1 & z & z^2 \\
        \end{Vmatrix}
$$

Ellipsis

可以使用\cdots \ddots \vdots 来省略矩阵中的元素,例如:

$$
\begin{pmatrix}
1 & x & x^2 & \cdots & x^n\\
1 & y & y^2 & \cdots & y^n\\
1 & z & z^2 & \cdots & z^n\\
\vdots & \vdots & \vdots & \ddots & \vdots\\
1 & n & n^2 & \cdots & n^n\\
\end{pmatrix}
$$

Augmented Matrix

增广矩阵需要使用前面的array来实现,例如:

$$ \left[
      \begin{array}{cc|c}
        1&2&3\\
        4&5&6
      \end{array}
    \right]
$$

Aligned Formula


如果需要一系列的公式中等号对齐,可以使用\begin{align}…\end{align},其中使用 & 来对其位置,例如:

$$
\begin{align}
\sqrt{37} & = \sqrt{\frac{73^2-1}{12^2}} \\
 & = \sqrt{\frac{73^2}{12^2}\cdot\frac{73^2-1}{73^2}} \\
 & = \sqrt{\frac{73^2}{12^2}}\sqrt{\frac{73^2-1}{73^2}} \\
 & = \frac{73}{12}\sqrt{1 - \frac{1}{73^2}} \\
 & \approx \frac{73}{12}\left(1 - \frac{1}{2\cdot73^2}\right)
\end{align}
$$

Piecewise Expression


分类表达式可以使用 \begin{cases}…\end{cases} 其中用&指示对齐的位置,例如:

$$
f(n) =
\begin{cases}
n/2,  & \text{if $n$ is even} \\
3n+1, & \text{if $n$ is odd}  \\
\end{cases}
$$

上述公式的括号也可以移动到右侧,不过需要使用array来实现,如下:

$$
\left.
\begin{array}{l}
\text{if $n$ is even:}&n/2\\
\text{if $n$ is odd:}&3n+1
\end{array}
\right\}
=f(n)
$$

最后,如果想分类之间的垂直间隔变大,可以使用\[2ex]代替\来分隔不同的情况。(3ex,4ex也可以用,1ex相当于原始距离)。

$$
f(n) =
\begin{cases}
n/2,  & \text{if $n$ is even} \\[4ex]
3n+1, & \text{if $n$ is odd}  \\
\end{cases}
$$

Space Problem


Using of \frac

不要在再指数或者积分中使用 \frac,在指数或者积分表达式中使用 \frac会使表达式看起来不清晰,因此在专业的数学排版中很少被使用。应该使用一个水平的/来代替,效果如下:

$$
\begin{array}{cc}
\mathrm{Bad} & \mathrm{Better} \\
\hline \\
e^{i\frac{\pi}2} \quad e^{\frac{i\pi}2}& e^{i\pi/2} \\
\int_{-\frac\pi2}^\frac\pi2 \sin x\,dx & \int_{-\pi/2}^{\pi/2}\sin x\,dx \\
\end{array}
$$

Separator

使用 \mid 代替 | 作为分隔符,符号 | 作为分隔符时有排版空间大小的问题,应该使用\mid代替。效果如下:

$$
\begin{array}{cc}
\mathrm{Bad} & \mathrm{Better} \\
\hline \\
\{x|x^2\in\Bbb Z\} & \{x\mid x^2\in\Bbb Z\} \\
\end{array}
$$

Multiple Integration

对于多重积分,不要使用\int\int此类的表达,应该使用\iint \iiint等特殊形式。效果如下:

$$
\begin{array}{cc}
\mathrm{Bad} & \mathrm{Better} \\
\hline \\
\int\int_S f(x)\,dy\,dx & \iint_S f(x)\,dy\,dx \\
\int\int\int_V f(x)\,dz\,dy\,dx & \iiint_V f(x)\,dz\,dy\,dx
\end{array}
$$

Continued Fraction


书写连分数表达式时,请使用\cfrac代替\frac或者\over两者效果对比如下:

$$
x = a_0 + \cfrac{1^2}{a_1
          + \cfrac{2^2}{a_2
          + \cfrac{3^2}{a_3 + \cfrac{4^4}{a_4 + \cdots}}}} \tag{\cfrac}
$$
$$
x = a_0 + \frac{1^2}{a_1
          + \frac{2^2}{a_2
          + \frac{3^2}{a_3 + \frac{4^4}{a_4 + \cdots}}}} \tag{\frac}
$$

Equation Set


对于方程组可以使用\begin{array} … \end{array}\left{…\right.配合,表示方程组:

$$
    \left\{
        \begin{array}{c}
            a_1x+b_1y+c_1z=d_1 \\
            a_2x+b_2y+c_2z=d_2 \\
            a_3x+b_3y+c_3z=d_3
        \end{array}
    \right.
$$

同时,还可以使用\begin{cases}…\end{cases}表达同样的方程组,如:

$$
    \begin{cases}
        a_1x+b_1y+c_1z=d_1 \\
        a_2x+b_2y+c_2z=d_2 \\
        a_3x+b_3y+c_3z=d_3
    \end{cases}
$$

对齐方程组中的 = 号,可以使用 \being{aligned} .. \end{aligned},如:

$$
    \left\{
        \begin{aligned}
            a_1x+b_1y+c_1z &=d_1+e_1 \\
            a_2x+b_2y&=d_2 \\
            a_3x+b_3y+c_3z &=d_3
        \end{aligned}
    \right.
$$

如果要对齐 = 号 和项,可以使用\being{array}{列样式} … \end{array},如:

$$
    \left\{
        \begin{array}{ll}
            a_1x+b_1y+c_1z &=d_1+e_1 \\
            a_2x+b_2y &=d_2 \\
            a_3x+b_3y+c_3z &=d_3
        \end{array}
    \right.
$$

Color


命名颜色是浏览器相关的,如果浏览器没有定义相关的颜色名称,则相关文本将被渲染为黑色,具体列表如下:

$$
    \begin{array}{|rc|}
        \hline
            \verb+\color{black}{text}+ & \color{black}{text} \\
            \verb+\color{gray}{text}+ & \color{gray}{text} \\
            \verb+\color{silver}{text}+ & \color{silver}{text} \\
            \verb+\color{white}{text}+ & \color{white}{text} \\
        \hline
            \verb+\color{maroon}{text}+ & \color{maroon}{text} \\
            \verb+\color{red}{text}+ & \color{red}{text} \\
            \verb+\color{yellow}{text}+ & \color{yellow}{text} \\
            \verb+\color{lime}{text}+ & \color{lime}{text} \\
            \verb+\color{olive}{text}+ & \color{olive}{text} \\
            \verb+\color{green}{text}+ & \color{green}{text} \\
            \verb+\color{teal}{text}+ & \color{teal}{text} \\
            \verb+\color{aqua}{text}+ & \color{aqua}{text} \\
            \verb+\color{blue}{text}+ & \color{blue}{text} \\
            \verb+\color{navy}{text}+ & \color{navy}{text} \\
            \verb+\color{purple}{text}+ & \color{purple}{text} \\
            \verb+\color{fuchsia}{text}+ & \color{magenta}{text} \\
        \hline
    \end{array}
$$

此外,HTML5CSS3也定义了一些颜色名称。 同时,颜色也可以使用#rgb的形式来表示,rgb分别表示代表颜色值得16进制数,如:

$$
    \begin{array}{|rrrrrrrr|}\hline
        \verb+#000+ & \color{#000}{text} & & &
        \verb+#00F+ & \color{#00F}{text} & & \\
        & & \verb+#0F0+ & \color{#0F0}{text} &
        & & \verb+#0FF+ & \color{#0FF}{text}\\
        \verb+#F00+ & \color{#F00}{text} & & &
        \verb+#F0F+ & \color{#F0F}{text} & & \\
        & & \verb+#FF0+ & \color{#FF0}{text} &
        & & \verb+#FFF+ & \color{#FFF}{text}\\
        \hline
    \end{array}
$$

Formula Mark & Quote


使用\tag{yourtag}来标记公式,如果想在之后引用该公式,则还需要加上\label{yourlabel}\tag之后,如:

\[
a := x^2-y^3 \tag{1-1}\label{ 1-1}
\]

为了引用公式,可以使用\eqref{rlabel},如:

$$
a+y^3 \stackrel{\eqref{1-1}}= x^2
$$

HTML Color Quick Reference


HTML色彩代码提取

HTML Color Picker

Mathematics Symbols Quick Reference


Detexify,一个数学符号查询手写识别系统,如图:

detexify-demo

Detexify :