CSDN-markdown语法之如何使用LaTeX语法编写数学公式

目录

正文

CSDN-markdown编辑器支持基于MathJax编写LaTeX数学公式。

MathJax是一款运行在浏览器中的开源的数学符号渲染引擎,使用MathJax可以方便的在浏览器中显示数学公式,不需要使用图片。这篇文章介绍如何使用LaTeX语法编写数学公式。

标记公式

LaTeX的数学公式有两种:行内公式和块级公式。行内公式放在文中与其它文字混编,块级公式单独成行。都使用美元符号进行标记显示。

行内公式

标记方法:使用一个美元符号包围起来

$数学公式$

例子:

这是行内公式:$\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N$

效果:

这是行内公式: Γ(n)=(n1)!nN <script type="math/tex" id="MathJax-Element-181107">\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N</script>

块级公式

标记方法:使用两个美元符号包围起来

$$数学公式$$

例子:

$$ x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$

效果:

x=b±b24ac2a
<script type="math/tex; mode=display" id="MathJax-Element-223786"> x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a} </script>


上标和下标

^表示上标,_表示下标。如果上下标的内容多于一个字符,要用{}把这些内容括起来当成一个整体。上下标是可以嵌套的,也可以同时使用。

例子:

$x^{y^z}=(1+e^x)^{-2xy^w}$

效果:

xyz=(1+ex)2xyw <script type="math/tex" id="MathJax-Element-223787">x^{y^z}=(1+e^x)^{-2xy^w}</script>

另外,如果要在左右两边都有上下标,可以用\sideset命令。

例子:$\sideset{^1_2}{^3_4}\bigotimes$

效果: 1234 <script type="math/tex" id="MathJax-Element-223788">\sideset{^1_2}{^3_4}\bigotimes</script>


分数表示

方法1:\frac{分子}{分母}
方法2:分子 \over 分母

例子:$\frac{a+b}{c+d}$ 或 $1 \over 3$

效果: a+bc+d <script type="math/tex" id="MathJax-Element-223789">\frac{a+b}{c+d}</script> 或  13 <script type="math/tex" id="MathJax-Element-223790">1 \over 3</script>

注意:对于\frac的方法,如果分子分母都是单个数,那么大括号{}可以省略,如:$\frac12$表示 12 <script type="math/tex" id="MathJax-Element-223791">\frac12</script>。


各种括号

()[]|可以直接表示自己,而{}本来用于分组,因此需要用\{\}来表示自身,也可以使用\lbrace\rbrace来表示,其它括号见下面那个表。

例子:$\{[z-(1+\frac23x)y]\div 4\}$

效果: {[z(1+23x)y]÷4} <script type="math/tex" id="MathJax-Element-223792">\{[z-(1+\frac23x)y]\div 4\}</script>

注意原始符号并不会随着公式大小缩放。有时候我们想要括号和分隔符显示的大点,比如上面例子中希望括号能把整个分数都包住,那么可以用\left\right标记,实现自适应调整。

例子:$\left(1+\frac23x\right)$

效果: (1+23x) <script type="math/tex" id="MathJax-Element-223793">\left(1+\frac23x\right)</script>

\left\right标记能应用的括号很多:

符号名称LaTex代码例子产生的效果
小括号( 和 )\left(x\right) (12) <script type="math/tex" id="MathJax-Element-223794">\left(\frac12\right)</script>
中括号[ 和 ]\left[\frac12\right] [12] <script type="math/tex" id="MathJax-Element-223795">\left[\frac12\right]</script>
大括号{ 和 }\left{\frac12\right} {12} <script type="math/tex" id="MathJax-Element-223796">\left\{\frac12\right\}</script>
取绝对值|\left|\frac12\right| 12 <script type="math/tex" id="MathJax-Element-223797">\left|\frac12\right|</script>
尖括号\langle 和 \rangle\left\langle\frac12\right\rangle 12 <script type="math/tex" id="MathJax-Element-223798">\left\langle\frac12\right\rangle</script>
向上取整\lceil 和 \rceil\left\lceil\frac12\right\rceil 12 <script type="math/tex" id="MathJax-Element-223799">\left\lceil\frac12\right\rceil </script>
向下取整\lfloor 和 \rfloor\left\lfloor\frac12\right\rfloor 12| <script type="math/tex" id="MathJax-Element-223800"> \left\lfloor\frac12\right\rfloor |</script>



注意:

\left\right标记必须是成对出现的,但有时候我们只用到其中一个,比如只用一个|当作分割线,这时候可以通过.来表示空的那一方,即用\left.表达左边空的情况,用\right.表达右边空的情况。

例子:$\left. \frac{du}{dx} \right| _{x=0}$

效果: dudxx=0 <script type="math/tex" id="MathJax-Element-223801">\left. \frac{du}{dx} \right| _{x=0}</script>


根号表示

根号开方使用\sqrt标记,语法格式如下:

\sqrt[开方次数,默认为2]{开方因子}

例子:$\sqrt{x^3}$ 和 $\sqrt[3]{\frac xy}$

效果: x3 <script type="math/tex" id="MathJax-Element-223802">\sqrt{x^3}</script> 和  xy3 <script type="math/tex" id="MathJax-Element-223803">\sqrt[3]{\frac xy}</script>

注意:对于非常复杂的表达式,建议使用{...}^{1/n}代替(n是开方次数)。


省略号

数学公式中常见的省略号有两种,\ldots表示与文本底线对齐的省略号,\cdots表示与文本中线对齐的省略号。

例子:$f(x_1,x_2,\ldots,x_n) = x_1^2 + x_2^2 + \cdots + x_n^2$

效果: f(x1,x2,,xn)=x21+x22++x2n <script type="math/tex" id="MathJax-Element-223804">f(x_1,x_2,\ldots,x_n) = x_1^2 + x_2^2 + \cdots + x_n^2</script>

注意:\ldot\cdot可以表示与文本底线和中线对齐的单个点。


矢量表示

矢量用\vect标记实现,语法格式如下:

 \vec{矢量值}

例子:$\vec{a} \cdot \vec{b}=0$

效果: a⃗ b⃗ =0 <script type="math/tex" id="MathJax-Element-223805">\vec{a} \cdot \vec{b}=0</script>


间隔空间

通常MathJax通过内部策略自己管理公式内部的空间,因此a︹︹ba︹︹︹︹︹b(︹表示空格)都会显示为 ab <script type="math/tex" id="MathJax-Element-223567">ab</script>。可以通过在ab间加入\空格\;增加些许间隙,\quad 与 \qquad 会增加更大的间隙。

例子:$a\;b$ 或 $a\quad b$ 或 $a\qquad b$

效果: ab <script type="math/tex" id="MathJax-Element-223568">a\;b</script> 或 ab <script type="math/tex" id="MathJax-Element-223569">a\quad b</script> 或 ab <script type="math/tex" id="MathJax-Element-223570">a\qquad b</script>


希腊字母

下面的表格用于查询和对比。

序号大写LaTex代码小写LaTex代码中文名称
1 A <script type="math/tex" id="MathJax-Element-223571">A</script>Aα\alpha阿尔法
2 B <script type="math/tex" id="MathJax-Element-223572">B</script>B β <script type="math/tex" id="MathJax-Element-223573">\beta</script>\beta贝塔
3 Γ <script type="math/tex" id="MathJax-Element-223574">Γ</script>Γ γ <script type="math/tex" id="MathJax-Element-223575">\gamma</script>\gamma伽马
4 D <script type="math/tex" id="MathJax-Element-223576">D</script>D δ <script type="math/tex" id="MathJax-Element-223577">\delta</script>\delta德尔塔
5 E <script type="math/tex" id="MathJax-Element-223578">E</script>E ϵ <script type="math/tex" id="MathJax-Element-223579">\epsilon</script>\epsilon伊普西隆
6 Z <script type="math/tex" id="MathJax-Element-223580">Z</script>Z ζ <script type="math/tex" id="MathJax-Element-223581">\zeta</script>\zeta泽塔
7 H <script type="math/tex" id="MathJax-Element-223582">H</script>H η <script type="math/tex" id="MathJax-Element-223583">\eta</script>\eta伊塔
8 Θ <script type="math/tex" id="MathJax-Element-223584">Θ</script>Θ θ <script type="math/tex" id="MathJax-Element-223585">\theta</script>\theta西塔
9 I <script type="math/tex" id="MathJax-Element-223586">I</script>I ι <script type="math/tex" id="MathJax-Element-223587">\iota</script>\iota约塔
10 K <script type="math/tex" id="MathJax-Element-223588">K</script>K κ <script type="math/tex" id="MathJax-Element-223589">\kappa</script>\kappa卡帕
11 Λ <script type="math/tex" id="MathJax-Element-223590">Λ</script>Λ λ <script type="math/tex" id="MathJax-Element-223591">\lambda</script>\lambda兰姆达
12 M <script type="math/tex" id="MathJax-Element-223592">M</script>M μ <script type="math/tex" id="MathJax-Element-223593">\mu</script>\mu
13 N <script type="math/tex" id="MathJax-Element-223594">N</script>N ν <script type="math/tex" id="MathJax-Element-223595">\nu</script>\nu
14 X <script type="math/tex" id="MathJax-Element-223596">X</script>X ξ <script type="math/tex" id="MathJax-Element-223597">\xi</script>\xi克西
15 O <script type="math/tex" id="MathJax-Element-223598">O</script>O ο <script type="math/tex" id="MathJax-Element-223599">\omicron</script>\omicron欧米克隆
16 P <script type="math/tex" id="MathJax-Element-223600">P</script>P π <script type="math/tex" id="MathJax-Element-223601">\pi</script>\pi
17 R <script type="math/tex" id="MathJax-Element-223602">R</script>R ρ <script type="math/tex" id="MathJax-Element-223603">\rho</script>\rho
18 Σ <script type="math/tex" id="MathJax-Element-223604">Σ</script>Σ σ <script type="math/tex" id="MathJax-Element-223605">\sigma</script>\sigma西格玛
19 T <script type="math/tex" id="MathJax-Element-223606">T</script>T τ <script type="math/tex" id="MathJax-Element-223607">\tau</script>\tau
20 Υ <script type="math/tex" id="MathJax-Element-223608">Υ</script>Υ υ <script type="math/tex" id="MathJax-Element-223609">\upsilon</script>\upsilon宇普西隆
21 Φ <script type="math/tex" id="MathJax-Element-223610">Φ</script>Φ ϕ <script type="math/tex" id="MathJax-Element-223611">\phi</script>\phi弗爱
22 X <script type="math/tex" id="MathJax-Element-223612">X</script>X χ <script type="math/tex" id="MathJax-Element-223613"> \chi</script>\chi
23 Ψ <script type="math/tex" id="MathJax-Element-223614">Ψ</script>Ψ ψ <script type="math/tex" id="MathJax-Element-223615">\psi</script>\psi普赛
24 Ω <script type="math/tex" id="MathJax-Element-223616">Ω</script>Ω ω <script type="math/tex" id="MathJax-Element-223617">\omega</script>\omega欧米伽
异体E E <script type="math/tex" id="MathJax-Element-223618">E</script> ε <script type="math/tex" id="MathJax-Element-223619">\varepsilon</script>\varepsilon异体
异体K K <script type="math/tex" id="MathJax-Element-223620">K</script> ϰ <script type="math/tex" id="MathJax-Element-223621">\varkappa</script>\varkappa异体
异体Θ Θ <script type="math/tex" id="MathJax-Element-223622">Θ</script> ϑ <script type="math/tex" id="MathJax-Element-223623">\vartheta</script>\vartheta异体
异体P P <script type="math/tex" id="MathJax-Element-223624">P</script> ϖ <script type="math/tex" id="MathJax-Element-223625">\varpi</script>\varpi异体
异体R R <script type="math/tex" id="MathJax-Element-223626">R</script> ϱ <script type="math/tex" id="MathJax-Element-223627">\varrho</script>\varrho异体
异体Σ Σ <script type="math/tex" id="MathJax-Element-223628">Σ</script> ς <script type="math/tex" id="MathJax-Element-223629">\varsigma</script>\varsigma异体
异体Φ Φ <script type="math/tex" id="MathJax-Element-223630">Φ</script> φ <script type="math/tex" id="MathJax-Element-223631"> \varphi</script>\varphi异体

特殊字符

关系运算符

± <script type="math/tex" id="MathJax-Element-223632">\pm</script>:\pm
× <script type="math/tex" id="MathJax-Element-223633">\times</script>:\times
÷ <script type="math/tex" id="MathJax-Element-223634">\div</script>:\div
<script type="math/tex" id="MathJax-Element-223635">\mid</script>:\mid
<script type="math/tex" id="MathJax-Element-223636">\nmid</script>:\nmid
<script type="math/tex" id="MathJax-Element-223637">\cdot</script>⋅:\cdot
<script type="math/tex" id="MathJax-Element-223638">\circ</script>:\circ
<script type="math/tex" id="MathJax-Element-223639">\ast</script>:\ast
<script type="math/tex" id="MathJax-Element-223640">\bigodot</script>:\bigodot
<script type="math/tex" id="MathJax-Element-223641">\bigotimes</script>:\bigotimes
<script type="math/tex" id="MathJax-Element-223642">\bigoplus</script>:\bigoplus
<script type="math/tex" id="MathJax-Element-223643">\leq</script>:\leq
<script type="math/tex" id="MathJax-Element-223644">\geq</script>:\geq
<script type="math/tex" id="MathJax-Element-223645">\neq</script>:\neq
<script type="math/tex" id="MathJax-Element-223646">\approx</script>:\approx
<script type="math/tex" id="MathJax-Element-223647">\equiv</script>:\equiv
<script type="math/tex" id="MathJax-Element-223648">\sum</script>:\sum
<script type="math/tex" id="MathJax-Element-223649">\prod</script>:\prod
<script type="math/tex" id="MathJax-Element-223650">\coprod</script>:\coprod

集合运算符

<script type="math/tex" id="MathJax-Element-223651">\emptyset</script>:\emptyset
<script type="math/tex" id="MathJax-Element-223652">\in</script>:\in
<script type="math/tex" id="MathJax-Element-223653">\notin</script>:\notin
<script type="math/tex" id="MathJax-Element-223654">\subset</script>:\subset
<script type="math/tex" id="MathJax-Element-223655">\supset</script>:\supset
<script type="math/tex" id="MathJax-Element-223656">\subseteq</script>:\subseteq
<script type="math/tex" id="MathJax-Element-223657">\supseteq</script>:\supseteq
<script type="math/tex" id="MathJax-Element-223658">\supseteq</script>:\bigcap
<script type="math/tex" id="MathJax-Element-223659">\bigcup</script>:\bigcup
<script type="math/tex" id="MathJax-Element-223660">\bigvee</script>:\bigvee
<script type="math/tex" id="MathJax-Element-223661">\bigwedge</script>:\bigwedge
<script type="math/tex" id="MathJax-Element-223662">\biguplus</script>:\biguplus
<script type="math/tex" id="MathJax-Element-223663">\bigsqcup</script>:\bigsqcup

对数运算符

log <script type="math/tex" id="MathJax-Element-223664">\log</script>:\log
lg <script type="math/tex" id="MathJax-Element-223665">\lg</script>:\lg
ln <script type="math/tex" id="MathJax-Element-223666">\ln</script>:\ln

三角运算符

<script type="math/tex" id="MathJax-Element-223667">\bot</script>:\bot
<script type="math/tex" id="MathJax-Element-223668">\angle</script>:\angle
30 <script type="math/tex" id="MathJax-Element-223669">30^\circ</script>:30^\circ
sin <script type="math/tex" id="MathJax-Element-223670">\sin</script>:\sin
cos <script type="math/tex" id="MathJax-Element-223671">\cos</script>:\cos
tan <script type="math/tex" id="MathJax-Element-223672">\tan</script>:\tan
cot <script type="math/tex" id="MathJax-Element-223673">\cot</script>:\cot
sec <script type="math/tex" id="MathJax-Element-223674">\sec</script>:\sec
csc <script type="math/tex" id="MathJax-Element-223675">\csc</script>:\csc

微积分运算符

<script type="math/tex" id="MathJax-Element-223676">\prime</script>:\prime
<script type="math/tex" id="MathJax-Element-223677">\int</script>:\int
<script type="math/tex" id="MathJax-Element-223678">\iint</script>:\iint
<script type="math/tex" id="MathJax-Element-223679">\iiint</script>:\iiint
∬∬ <script type="math/tex" id="MathJax-Element-223680">\iiiint</script>:\iiiint
<script type="math/tex" id="MathJax-Element-223681">\oint</script>:\oint
lim <script type="math/tex" id="MathJax-Element-223682">\lim</script>:\lim
<script type="math/tex" id="MathJax-Element-223683">\infty</script>:\infty
<script type="math/tex" id="MathJax-Element-223684">\nabla</script>:\nabla

逻辑运算符

<script type="math/tex" id="MathJax-Element-223685">\because</script>:\because
<script type="math/tex" id="MathJax-Element-223686">\therefore</script>:\therefore
<script type="math/tex" id="MathJax-Element-223687">\forall</script>:\forall
<script type="math/tex" id="MathJax-Element-223688">\exists</script>:\exists
<script type="math/tex" id="MathJax-Element-223689">\not=</script>:\not=
<script type="math/tex" id="MathJax-Element-223690">\not></script>:\not>
⊄ <script type="math/tex" id="MathJax-Element-223691">\not\subset</script>:\not\subset

戴帽符号

y^ <script type="math/tex" id="MathJax-Element-223692">\hat{y}</script>:\hat{y}
yˇ <script type="math/tex" id="MathJax-Element-223693">\check{y}</script>:\check{y}
y˘ <script type="math/tex" id="MathJax-Element-223694">\breve{y}</script>:\breve{y}

连线符号

a+b+c+d¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ <script type="math/tex" id="MathJax-Element-223695">\overline{a+b+c+d}</script>:\overline{a+b+c+d}
a+b+c+d <script type="math/tex" id="MathJax-Element-223696">\underline{a+b+c+d}</script>:\underline{a+b+c+d}
a+b+c1.0+d2.0 <script type="math/tex" id="MathJax-Element-223697">\overbrace{a+\underbrace{b+c}_{1.0}+d}^{2.0}</script>:\overbrace{a+\underbrace{b+c}_{1.0}+d}^{2.0}

箭头符号

<script type="math/tex" id="MathJax-Element-223698">\uparrow</script>:\uparrow
<script type="math/tex" id="MathJax-Element-223699">\downarrow</script>:\downarrow
<script type="math/tex" id="MathJax-Element-223700">\Uparrow</script>:\Uparrow
<script type="math/tex" id="MathJax-Element-223701">\Downarrow</script>:\Downarrow
<script type="math/tex" id="MathJax-Element-223702">\rightarrow</script>:\rightarrow
<script type="math/tex" id="MathJax-Element-223703">\leftarrow</script>:\leftarrow
<script type="math/tex" id="MathJax-Element-223704">\Rightarrow</script>:\Rightarrow
<script type="math/tex" id="MathJax-Element-223705">\Leftarrow</script>:\Leftarrow
<script type="math/tex" id="MathJax-Element-223706">\longrightarrow</script>:\longrightarrow
<script type="math/tex" id="MathJax-Element-223707">\longleftarrow</script>:\longleftarrow
<script type="math/tex" id="MathJax-Element-223708">\Longrightarrow</script>:\Longrightarrow
<script type="math/tex" id="MathJax-Element-223709">\Longleftarrow</script>:\Longleftarrow

几个例子

例子:

$\sum_{i=0}^n \frac{1}{i^2}$

$\prod_{i=0}^n \frac{1}{i^2}$

$\int_0^1 x^2 {\rm d}x$

$\lim_{n \rightarrow +\infty} \frac{1}{n(n+1)}$

效果:

ni=01i2 <script type="math/tex" id="MathJax-Element-223710">\sum_{i=0}^n \frac{1}{i^2}</script>

ni=01i2 <script type="math/tex" id="MathJax-Element-223711">\prod_{i=0}^n \frac{1}{i^2}</script>

10x2dx <script type="math/tex" id="MathJax-Element-223712">\int_0^1 x^2 {\rm d}x</script>

limn+1n(n+1) <script type="math/tex" id="MathJax-Element-223713">\lim_{n \rightarrow +\infty} \frac{1}{n(n+1)}</script>

其它特殊字符:

空格:\空格
#:\#
$:\$ 
%:\%
&:\&
_:\_
{:\{
}:\}

字体种类

公式里的字符也有字体的选择,若要对公式的某一部分字符进行字体转换,可以用如下语法格式:

{字体标记 需转换的部分字符}

其中“字体标记”可以参照下表选择合适的字体。一般情况下,公式默认为意大利体。

字体标记字体名词例子例子效果
\rm罗马体{\rm ABCDE} ABCDE <script type="math/tex" id="MathJax-Element-223714">{\rm ABCDE}</script>
\bf黑体{\bf ABCDE} ABCDE <script type="math/tex" id="MathJax-Element-223715">{\bf ABCDE}</script>
\Bbb黑板粗体字{\Bbb ABCDE} ABCDE <script type="math/tex" id="MathJax-Element-223716">{\Bbb ABCDE}</script>
\sl倾斜体{\sl ABCDE} \slABCDE <script type="math/tex" id="MathJax-Element-223717">{\sl ABCDE}</script>
\mit数学斜体{\mit ABCDE} ABCDE <script type="math/tex" id="MathJax-Element-223718">{\mit ABCDE}</script>
\scr小体大写字母{\scr ABCDE} ABCDE <script type="math/tex" id="MathJax-Element-223719">{\scr ABCDE}</script>
\it意大利体{\it ABCDE} ABCDE <script type="math/tex" id="MathJax-Element-223720">{\it ABCDE}</script>
\cal花体{\cal ABCDE} ABCDE <script type="math/tex" id="MathJax-Element-223721">{\cal ABCDE}</script>
\sf等线体{\sf ABCDE} ABCDE <script type="math/tex" id="MathJax-Element-223722">{\sf ABCDE}</script>
\tt打字机字体{\tt ABCDE} ABCDE <script type="math/tex" id="MathJax-Element-223723">{\tt ABCDE}</script>
\frakFraktur字母(一种德国字体){\frak ABCDE} ABCDE <script type="math/tex" id="MathJax-Element-223724">{\frak ABCDE}</script>

参考文献

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页