Markdown
- Markdown
- CommonMark
Markdown是一种轻量级的标记语言,可用于将格式设置元素添加到纯文本文档中。Markdown 由John Gruber于2004年创建。
由于 John Gruber 对 Markdown 语法的规范描述没有明确指定语法,因此在过去 10 年中,实现方式发生了很大差异。因此,用户经常会惊讶地发现,在一个系统上以一种方式呈现的文档(例如,GitHub wiki)在另一个系统上以不同的方式呈现(例如,使用 Pandoc 转换为文档书)。
解决 Markdown 歧义和不一致的唯一方法是 Babelmark,它将 20+ 个 Markdown 实现的输出相互比较,以查看是否达成共识。
基本语法
元素 | Markdown 语法 |
---|---|
标题 | # H1 ## H2 ### H3 |
粗体 | **bold text** |
斜体 | *italicized text* |
块引用 | > blockquote |
有序列表 | 1. First item 2. Second item 3. Third item |
无序列表 | - First item - Second item - Third item |
代码 | `code` |
水平线 | --- |
超链接 | [title](https://www.qq.com) |
图片 |  |
元素 | Markdown 语法 |
---|---|
表格 | | Syntax | Description | | ----------- | ----------- | | Header | Title | | Paragraph | Text | |
围栏代码块 | ``` { "firstName": "John", "age": 25 } ``` |
脚注 | Here's a sentence with a footnote. [^1] [^1]: This is the footnote. |
标题ID | ### My Great Heading {#custom-id} |
删除线 | ~~The world is flat.~~ |
任务列表 | - [x] Write the press release - [ ] Update the website - [ ] Contact the media |
标题
1# 一级标题
2## 二级标题
3### 三级标题
4#### 四级标题
5##### 五级标题
6###### 六级标题
段落
段落的换行
是前后要有一个以上的空行
1段落的换行
2
3是前后要有一个以上的空行
字体
正常文本
斜体文本
粗体文本
粗斜体文本
1正常文本
2
3*斜体文本*
4
5**粗体文本**
6
7***粗斜体文本***
标记文本
Preformatted 文本
小文本
这是 下标
This is 上标
1<mark>标记文本</mark>
2
3<pre>Preformatted 文本</pre>
4
5<small>小文本</small>
6
7这是 <sub>下标</sub>
8
9这是 <sup>上标</sup>
分隔线
1***
不建议
1* * *
2
3*****
4
5- - -
6
7----------
删除线
ABC.COMABC.COM
1ABC@123.COM
2~~ABC@123.COM~~
脚注
[^要注明的文本]
1[^要注明的文本]
列表
无序列表
- 第一项
- 第二项
- 第三项
1* 第一项
2* 第二项
3* 第三项
不建议
1+ 第一项
2+ 第二项
3+ 第三项
4
5
6- 第一项
7- 第二项
8- 第三项
有序列表
- 第一项
- 第二项
- 第三项
11. 第一项
22. 第二项
33. 第三项
列表嵌套
- 第一项:
- 第一项嵌套的第一个元素
- 第一项嵌套的第二个元素
- 第二项:
- 第二项嵌套的第一个元素
- 第二项嵌套的第二个元素
1
21. 第一项:
3 * 第一项嵌套的第一个元素
4 * 第一项嵌套的第二个元素
52. 第二项:
6 * 第二项嵌套的第一个元素
7 * 第二项嵌套的第二个元素
区块
死鱼正口 收杆就走 道袍一换 下河开干
1> 死鱼正口
2> 收杆就走
3> 道袍一换
4> 下河开干
最外层
第一层嵌套
第二层嵌套
- 第一项
- 第二项
- 第一项
- 第二项
大气层
1> 最外层
2> > 第一层嵌套
3> > > 第二层嵌套
4> > >
5> > > 1. 第一项
6> > > 2. 第二项
7> > >
8> > > * 第一项
9> > > * 第二项
10> >
11> 大气层
代码
1```php
2$stu = new Stu();
3```
1$stu = new Stu();
敲击abc
键
1敲击```abc```键
链接
1[链接名称](example.com)
2
3<链接地址>
这个链接用 1 作为网址变量 github
这个链接用 runoob 作为网址变量 Runoob
然后在文档的结尾为变量赋值(网址)
1这个链接用 1 作为网址变量 [github][1]
2
3这个链接用 runoob 作为网址变量 [Runoob][runoob]
4
5然后在文档的结尾为变量赋值(网址)
6
7 [1]: http://www.github.com/
8 [runoob]: http://www.runoob.com/
图片
1
2
3
4
5<img src="http://logo.png" width="50%">
表格
左对齐 | 左对齐 | 居中对齐 | 右对齐 |
---|---|---|---|
格 | 格 | 格 | 格 |
1| 左对齐 | 左对齐 | 居中对齐 | 右对齐 |
2| :-----| ---- | :----: | ----: |
3| 格 | 格 | 格 | 格 |
4
5表头 | 表头
6---- | ----
7格 | 格
转义
加粗
** 不加粗 **
1**加粗**
2\*\* 不加粗 \*\*
代码块套代码块
1````md
2```md
3**加粗**
4\*\* 不加粗 \*\*
5```
6````
Markdown 支持以下这些符号前面加上反斜杠来帮助插入普通的符号:
1\ 反斜线
2` 反引号
3* 星号
4_ 下划线
5{} 花括号
6[] 方括号
7() 小括号
8# 井字号
9+ 加号
10- 减号
11. 英文句点
12! 感叹号
内联html元素
插件作者的意图是为了使 markdown 文件是纯 markdown 的,避免在使用 html 以外的方式渲染时出错。
MD033/no-inline-html: Inline HTML [Element: kbd]markdownlintMD033
1使用 <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Del</kbd> 重启电脑
2
3<u>带下划线文本</u>
4
5上标
6a<sup>2</sup> + b<sup>2</sup> = c<sup>2</sup>
7Windows 10 <sup>TM</sup>
键盘
Ctrl
1<kbd>Ctrl</kbd>
其他
↑<kbd>↑</kbd>
Arrow Up
↓<kbd>↓</kbd>
Arrow Down
←<kbd>←</kbd>
Arrow Left
→<kbd>→</kbd>
Arrow Right
⇪<kbd>⇪</kbd>
Caps Lock
⌘<kbd>⌘</kbd>
Command
⌃<kbd>⌃</kbd>
Control
⌫<kbd>⌫</kbd>
Delete
⌦<kbd>⌦</kbd>
Delete (Forward)
↘<kbd>↘</kbd>
End
⌤<kbd>⌤</kbd>
Enter
⎋<kbd>⎋</kbd>
Escape
↖<kbd>↖</kbd>
Home
⇞<kbd>⇞</kbd>
Page Up
⇟<kbd>⇟</kbd>
Page Down
⌥<kbd>⌥</kbd>
Option, Alt
↵<kbd>↵</kbd>
Return
⇧<kbd>⇧</kbd>
Shift
␣<kbd>␣</kbd>
Space
⇥<kbd>⇥</kbd>
Tab
⇤<kbd>⇤</kbd>
Tab + Shift
复选框
- Java
- Php
1* [ ] Java
2* [x] Php
注释
1<!-- 这是一段被注释掉的文字 -->
数学表达式
KaTeX支持:LaTeX
MathJax支持:LaTeX、MathML、AsciiMath
在线手写公式生成数学表达式代码:https://webdemo.myscript.com/views/math/index.html#
AsciiMath
使用方法:
1$$sum_(i=1)^n i^3=((n(n+1))/2)^2$$
$$sum_(i=1)^n i^3=((n(n+1))/2)^2$$
LaTeX
LaTeX是在TeX基础上,规范化出了一种格式,一种编写风格。可以理解为LaTeX是由TeX写的。
画符号显示符号名称:Detexify
在线手写公式生成数学表达式代码:https://webdemo.myscript.com/views/math/index.html#
详细文档:https://en.wikibooks.org/wiki/LaTeX/Mathematics
LaTeX存在大量第三方插件扩展,包括不限于:Amsmath、MathTools、mathrsfs、amsfonts、xcolor…
文档尽量不考虑扩展确保兼容
使用方法:
类型 | 内联公式 | 显示的方程 | 显示并自动编号的方程 |
---|---|---|---|
Environment | math | displaymath | equation |
LaTeX | \(...\) | \[...\] | |
TeX | $...$ | $$...$$ | |
Comment | equation* (starred version) suppresses numbering, but requires amsmath |
1$$
2E=mc^2
3$$
4
5\[ f(n) =
6 \begin{cases}
7 n/2 & \quad \text{if } n \text{ is even}\\
8 -(n+1)/2 & \quad \text{if } n \text{ is odd}
9 \end{cases}
10\]
[ f(n) = \begin{cases} n/2 & \quad \text{if } n \text{ is even}\ -(n+1)/2 & \quad \text{if } n \text{ is odd} \end{cases} ]
符号
关系符号
象征 | 脚本 | 象征 | 脚本 | |
---|---|---|---|---|
$<$ | < | $>$ | > | |
$\leq$ | \leq | $\geq$ | \geq | |
$\ll$ | \ll | $\gg$ | \gg | |
$\subset$ | \subset | $\supset$ | \supset | |
$\subseteq$ | \subseteq | $\supseteq$ | \supseteq | |
$\nsubseteq$ | \nsubseteq | $\nsupseteq$ | \nsupseteq | |
$\sqsubset$ | \sqsubset | $\sqsupset$ | \sqsupset | |
$\sqsubseteq$ | \sqsubseteq | $\sqsupseteq$ | \sqsupseteq | |
$\preceq$ | \preceq | $\succeq$ | \succeq | |
$\therefore$ | \therefore | $\because$ | \because | |
$\parallel$ | \parallel | $\nparallel$ | \nparallel | |
$\asymp$ | \asymp | $\bowtie$ | \bowtie | |
$\vdash$ | \vdash | $\dashv$ | \dashv | |
$\in$ | \in | $\ni$ | \ni | |
$\smile$ | \smile | $\frown$ | \frown | |
$\models$ | \models | $\notin$ | \notin | |
$\perp$ | \perp | $\mid$ | \mid | |
$\prec$ | \prec | $\succ$ | \succ | |
$\sphericalangle$ | \sphericalangle | $\measuredangle$ | \measuredangle |
象征 | 脚本 | 象征 | 脚本 | |
---|---|---|---|---|
$=$ | = | $\simeq$ | \simeq | |
$\doteq$ | \doteq | $\sim$ | \sim | |
$\equiv$ | \equiv | $\propto$ | \propto | |
$\approx$ | \approx | $\neq$ | \neq | |
$\cong$ | \cong |
二进制操作
象征 | 脚本 | 象征 | 脚本 | |
---|---|---|---|---|
$\pm$ | \pm | $\cap$ | \cap | |
$\mp$ | \mp | $\cup$ | \cup | |
$\times$ | \times | $\uplus$ | \uplus | |
$\div$ | \div | $\sqcap$ | \sqcap | |
$\ast$ | \ast | $\sqcup$ | \sqcup | |
$\star$ | \star | $\vee$ | \vee | |
$\dagger$ | \dagger | $\wedge$ | \wedge | |
$\ddagger$ | \ddagger | $\cdot$ | \cdot | |
$\diamond$ | \diamond | $\oplus$ | \oplus | |
$\bigtriangleup$ | \bigtriangleup | $\ominus$ | \ominus | |
$\bigtriangledown$ | \bigtriangledown | $\otimes$ | \otimes | |
$\triangleleft$ | \triangleleft | $\oslash$ | \oslash | |
$\triangleright$ | \triangleright | $\odot$ | \odot | |
$\bigcirc$ | \bigcirc | $\circ$ | \circ | |
$\bullet$ | \bullet | $\setminus$ | \setminus | |
$\wr$ | \wr | $\amalg$ | \amalg |
设置和/或逻辑符号
象征 | 脚本 | 象征 | 脚本 | |
---|---|---|---|---|
$\exists$ | \exists | $\rightarrow$ | \rightarrow 或 \to | |
$\nexists$ | \nexists | $\leftarrow$ | \leftarrow 或 \gets | |
$\forall$ | \forall | $\mapsto$ | \mapsto | |
$\neg$ | \neg | $\implies$ | \implies | |
$\impliedby$ | \impliedby | $\Rightarrow$ | \Rightarrow 或 \implies | |
$\leftrightarrow$ | \leftrightarrow | $\Leftrightarrow$ | \Leftrightarrow | |
$\iff$ | \iff | $\angle$ | \angle | |
$\land$ | \land | $\lor$ | \lor | |
$\top$ | \top | $\bot$ | \bot | |
$\emptyset$ | \emptyset | $\varnothing$ | \varnothing | |
$\rightleftharpoons$ | \rightleftharpoons |
分隔符
象征 | 脚本 | 象征 | 脚本 | |
---|---|---|---|---|
$\mid$ | \mid | $|$ | | | |
${$ | \{ | $}$ | \} | |
$\uparrow$ | \uparrow | $\Uparrow$ | \Uparrow | |
$\downarrow$ | \downarrow | $\Downarrow$ | \Downarrow | |
$/$ | / | $\backslash$ | \backslash | |
$\langle$ | \langle | $\rangle$ | \rangle | |
$\lceil$ | \lceil | $\rceil$ | \rceil | |
$\lfloor$ | \lfloor | $\rfloor$ | \rfloor |
希腊字母
象征 | 脚本 | 象征 | 脚本 | |
---|---|---|---|---|
$A$ | A | $\alpha$ | \alpha | |
$B$ | B | $\beta$ | \beta | |
$\Gamma$ | \Gamma | $\gamma$ | \gamma | |
$\Delta$ | \Delta | $\delta$ | \delta | |
$E$ | E | $\epsilon$ $\varepsilon$ | \epsilon \varepsilon | |
$Z$ | Z | $\zeta$ | \zeta | |
$H$ | H | $\eta$ | \eta | |
$\Theta$ | \Theta | $ heta$ $\vartheta$ | \theta \vartheta | |
$I$ | I | $\iota$ | \iota | |
$K$ | K | $\kappa$ $\varkappa$ | \kappa \varkappa | |
$\Lambda$ | \Lambda | $\lambda$ | \lambda | |
$M$ | M | $\mu$ | \mu | |
$N$ | N | $\nu$ | \nu | |
$\Xi$ | \Xi | $\xi$ | \xi | |
$O$ | O | $o$ | o | |
$\Pi$ | \Pi | $\pi$ $\varpi$ | \pi \varpi | |
$P$ | P | $\rho$ $\varrho$ | \rho \varrho | |
$\Sigma$ | \Sigma | $\sigma$ $\varsigma$ | \sigma \varsigma | |
$T$ | T | $\tau$ | \tau | |
$Y$ | Y | $\Upsilon$ $\upsilon$ | \Upsilon \upsilon | |
$\Phi$ | \Phi | $\phi$ $\varphi$ | \phi \varphi | |
$X$ | X | $\chi$ | \chi | |
$\Psi$ | \Psi | $\psi$ | \psi | |
$\Omega$ | \Omega | $\omega$ | \omega |
其他符号
象征 | 脚本 | 象征 | 脚本 | |
---|---|---|---|---|
$\partial$ | \partial | $\imath$ | \imath | |
$\eth$ | \eth | $\jmath$ | \jmath | |
$\hbar$ | \hbar | $\ell$ | \ell | |
$\Re$ | \Re | $\nabla$ | \nabla | |
$\Im$ | \Im | $\Box$ | \Box | |
$\wp$ | \wp | $\infty$ | \infty | |
$\aleph$ | \aleph | $\beth$ | \beth | |
$\gimel$ | \gimel |
三角函数
象征 | 脚本 | 象征 | 脚本 | |
---|---|---|---|---|
$\sin$ | \sin | $\arcsin$ | \arcsin | |
$\cos$ | \cos | $\arccos$ | \arccos | |
$\tan$ | \tan | $\arctan$ | \arctan | |
$\cot$ | \cot | $\arccot$ | \arccot | |
$\sinh$ | \sinh | $\sec$ | \sec | |
$\cosh$ | \cosh | $\csc$ | \csc | |
$\tanh$ | \tanh | $\coth$ | \coth |
和与积分
象征 | 脚本 | 象征 | 脚本 | 象征 | 脚本 |
---|---|---|---|---|---|
$\sum$ | \sum | $\prod$ | \prod | $\coprod$ | \coprod |
$\bigoplus$ | \bigoplus | $\bigotimes$ | \bigotimes | $\bigodot$ | \bigodot |
$\bigcup$ | \bigcup | $\bigcap$ | \bigcap | $\biguplus$ | \biguplus |
$\bigsqcup$ | \bigsqcup | $\bigvee$ | \bigvee | $\bigwedge$ | \bigwedge |
$\int$ | \int | $\oint$ | \oint | $\iint$ | \iint |
$\iiint$ | \iiint | $\iiiint$ | \iiiint | $\idotsint$ | \idotsint |
公式排版
行内公式: 使用$
包裹公式 $E=mc^2$
1$E=mc^2$
独立公式: 使用$$
包裹公式
1$$
2E=mc^2
3$$
特殊转义字符
### $ & ~ _ ^ \ { } %
这些字符在MarkDown中有特殊的意义,在需要使用这些字符的时候,需要进行转义
公式
极限: $\lim\limits_{x \to \infty} \exp(-x) = 0$
1$\lim\limits_{x \to \infty} \exp(-x) = 0$
幂和指数: $k_{n+1} = n^2 + k_n^2 - k_{n-1}$
1$k_{n+1} = n^2 + k_n^2 - k_{n-1}$
分数和二项式: $\frac{n!}{k!(n-k)!} = \binom{n}{k} \neq ^3/_7$
1\frac{n!}{k!(n-k)!} = \binom{n}{k} \neq ^3/_7
连续分数
$$ \begin{equation} x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3 + \cfrac{1}{a_4} } } } \end{equation} $$
1\begin{equation}
2 x = a_0 + \cfrac{1}{a_1
3 + \cfrac{1}{a_2
4 + \cfrac{1}{a_3 + \cfrac{1}{a_4} } } }
5\end{equation}
两个数字的乘法
$$ \begin{equation} \frac{ \begin{array}[b]{r} \left( x_1 x_2 \right)\ \times \left( x’_1 x’_2 \right) \end{array} }{ \left( y_1y_2y_3y_4 \right) } \end{equation} $$
1\begin{equation}
2\frac{
3 \begin{array}[b]{r}
4 \left( x_1 x_2 \right)\\
5 \times \left( x'_1 x'_2 \right)
6 \end{array}
7 }{
8 \left( y_1y_2y_3y_4 \right)
9 }
10\end{equation}
根号
$\sqrt{\frac{a}{b}}$
$\sqrt[n]{1+x+x^2+x^3+\dots+x^n}$
1\sqrt{\frac{a}{b}}
2\sqrt[n]{1+x+x^2+x^3+\dots+x^n}
和与积分
$\sum_{i=1}^{10} t_i$
$\displaystyle\sum_{i=1}^{10} t_i$
$\int_0^\infty \mathrm{e}^{-x},\mathrm{d}x$
1\sum_{i=1}^{10} t_i
2\displaystyle\sum_{i=1}^{10} t_i
3\int_0^\infty \mathrm{e}^{-x}\,\mathrm{d}x
$$ \sum_{\substack{ 0<i<m \ 0<j<n }} P(i,j) $$
1\sum_{\substack{
2 0<i<m \\
3 0<j<n
4 }}
5 P(i,j)
$\int\limits_a^b$
1\int\limits_a^b
矩阵和数组
需要 Amsmath 软件包
[ \begin{matrix} a & b & c \ d & e & f \ g & h & i \end{matrix} ]
1\[
2 \begin{matrix}
3 a & b & c \\
4 d & e & f \\
5 g & h & i
6 \end{matrix}
7\]
$$ A_{m,n} = \begin{pmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \ \vdots & \vdots & \ddots & \vdots \ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{pmatrix} $$
1A_{m,n} =
2 \begin{pmatrix}
3 a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
4 a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
5 \vdots & \vdots & \ddots & \vdots \\
6 a_{m,1} & a_{m,2} & \cdots & a_{m,n}
7 \end{pmatrix}
\begin{array}{c|c} 1 & 2 \ \hline 3 & 4 \end{array}
1\begin{array}{c|c}
2 1 & 2 \\
3 \hline
4 3 & 4
5 \end{array}
$$ M = \begin{bmatrix} \frac{5}{6} & \frac{1}{6} & 0 \[0.3em] \frac{5}{6} & 0 & \frac{1}{6} \[0.3em] 0 & \frac{5}{6} & \frac{1}{6} \end{bmatrix} $$
1M = \begin{bmatrix}
2 \frac{5}{6} & \frac{1}{6} & 0 \\[0.3em]
3 \frac{5}{6} & 0 & \frac{1}{6} \\[0.3em]
4 0 & \frac{5}{6} & \frac{1}{6}
5 \end{bmatrix}
分隔符大小
自动调整
$\left(\frac{x^2}{y^3}\right) = (\frac{x^2}{y^3})$
$P\left(A=2\middle|\frac{A^2}{B}>4\right)$
$\left{\frac{x^2}{y^3}\right}$
$\left.\frac{x^3}{3}\right|_0^1$
1\left(\frac{x^2}{y^3}\right) = (\frac{x^2}{y^3})
2
3P\left(A=2\middle|\frac{A^2}{B}>4\right)
4
5\left\{\frac{x^2}{y^3}\right\}
6
7\left.\frac{x^3}{3}\right|_0^1
手动调整
$( \big( \Big( \bigg( \Bigg($
1( \big( \Big( \bigg( \Bigg(
$\frac{\mathrm d}{\mathrm d x} \left( k g(x) \right) = \frac{\mathrm d}{\mathrm d x} \big( k g(x) \big)$
1\frac{\mathrm d}{\mathrm d x} \left( k g(x) \right) = \frac{\mathrm d}{\mathrm d x} \big( k g(x) \big)
常用案例
$f(x)=a^2+b$
1$f(x)=a^2+b$
$$ \begin{Bmatrix} a & b \ c & d \end{Bmatrix} $$
1$$
2\begin{Bmatrix}
3 a & b \\
4 c & d
5\end{Bmatrix}
6$$
加法符号:$x+y=z$
减法符号:$x-y=z$
加减符号:$x pm y=z$
减加符号:$x mp y=z$
叉乘符号:$x times y=z$
点乘符号:$x cdot y=z$
星乘符号:$x ast y=z$
除法符号:$x div y=z$
斜除符号:$x/y=z$
分式1:$frac{x+y}{y+z}$
分式2:${x+y} over {y+z}$
绝对值:$|x+y|$
设置数学符号的格式
默认数学字体: $\mathnormal{ABCDEFabcdef123456}$
1\mathnormal{ABCDEFabcdef123456}
计量单位,一字函数: $\mathrm{ABCDEFabcdef123456}$
1\mathrm{ABCDEFabcdef123456}
多字母函数或变量名称: $\mathit{ABCDEFabcdef123456}$
1\mathit{ABCDEFabcdef123456}
向量: $\mathbf{ABCDEFabcdef123456}$
1\mathbf{ABCDEFabcdef123456}
类别: $\mathsf{ABCDEFabcdef123456}$
1\mathsf{ABCDEFabcdef123456}
无: $\mathtt{ABCDEFabcdef123456}$
1\mathtt{ABCDEFabcdef123456}
向量: $\mathcal{ABCDEF}$
1\mathcal{ABCDEF}
音标
象征 | 脚本 | 象征 | 脚本 | |
---|---|---|---|---|
$a'$ | a' 或 a^{\prime} | $a’'$ | a'' | |
$\hat{a}$ | \hat{a} | $\bar{a}$ | \bar{a} | |
$\grave{a}$ | \grave{a} | $\acute{a}$ | \acute{a} | |
$\dot{a}$ | \dot{a} | $\ddot{a}$ | \ddot{a} | |
$\not{a}$ | \not{a} | $\mathring{a}$ | \mathring{a} | |
$\overrightarrow{AB}$ | \overrightarrow{AB} | $\overleftarrow{AB}$ | \overleftarrow{AB} | |
$a’’'$ | a''' | $a’’’'$ | a'''' | |
$\overline{aaa}$ | \dot{a} | $\check{a}$ | \check{a} | |
$\breve{a}$ | \breve{a} | $\vec{a}$ | \vec{a} | |
$\widehat{AAA}$ | \widehat{AAA} | $\widetilde{AAA}$ | \widetilde{AAA} | |
$\stackrel\frown{AAA}$ | \stackrel\frown{AAA} | $ ilde{a}$ | \tilde{a} | |
$\underline{a}$ | \underline{a} | $\ddot{a}$ | \ddot{a} |
控制水平间距
[ f(n) = \begin{cases} n/2 & \quad \text{if } n \text{ is even}\ -(n+1)/2 & \quad \text{if } n \text{ is odd} \end{cases} ]
1\[ f(n) =
2 \begin{cases}
3 n/2 & \quad \text{if } n \text{ is even}\\
4 -(n+1)/2 & \quad \text{if } n \text{ is odd}
5 \end{cases}
6\]
绘制图形(mermaid.js)
Mermaid语法 文档:https://mermaid-js.github.io/mermaid/#/
Mermaid 允许您使用文本和代码创建图表和可视化效果。
使用方法:
1```mermaid
2<!-- code -->
3```
流程图
标志 | 方向 |
---|---|
TB | top bottom - 从上到下 |
BT | bottom top - 从下到上 |
RL | right left - 从右到左 |
LR | left right - 从左到右 |
TD | 等同于 TB |
graph LR 1号节点 2[2号节点--正方形] 3(3号节点--圆角形) 4((4号节点--圆形)) 5>5号节点--非对称形] 6{6号节点--六角形} 7{{7号节点--六角形}} 8[/8号节点--平行四边形/] 9[9号节点--平行四边形] 10[/10号节点--梯形\] 11[\11号节点--梯形/] 12[(12号节点)] 13[[13号节点]] 14([14号节点]) subgraph 第一组 1号节点---2-- 带文字连接 ---3-->4-- 带文字连接 -->5 end subgraph 第二组 6-.-7-. 带文字连接线 .->8==>9 end subgraph 第三组 10 == 带文字连接线 ==>11---12---13---14 end
1```mermaid
2graph LR
31号节点
42[2号节点--正方形]
53(3号节点--圆角形)
64((4号节点--圆形))
75>5号节点--非对称形]
86{6号节点--六角形}
97{{7号节点--六角形}}
108[/8号节点--平行四边形/]
119[9号节点--平行四边形]
1210[/10号节点--梯形\]
1311[\11号节点--梯形/]
1412[(12号节点)]
1513[[13号节点]]
1614([14号节点])
17
18subgraph 第一组
191号节点---2-- 带文字连接 ---3-->4-- 带文字连接 -->5
20end
21subgraph 第二组
226-.-7-. 带文字连接线 .->8==>9
23end
24subgraph 第三组
2510 == 带文字连接线 ==>11---12---13---14
26end
27```
横向流程图
graph LR A[方形] -->B(圆角) B --> C{条件a} C -->|a=1| D[结果1] C -->|a=2| E[结果2] F[横向流程图]
1```mermaid
2graph LR
3A[方形] -->B(圆角)
4 B --> C{条件a}
5 C -->|a=1| D[结果1]
6 C -->|a=2| E[结果2]
7 F[横向流程图]
8```
竖向流程图
graph TD A[方形] --> B(圆角) B --> C{条件a} C --> |a=1| D[结果1] C --> |a=2| E[结果2] F[竖向流程图]
1```mermaid
2graph TD
3A[方形] --> B(圆角)
4 B --> C{条件a}
5 C --> |a=1| D[结果1]
6 C --> |a=2| E[结果2]
7 F[竖向流程图]
8```
时序图 Sequence diagram
角色(Actor)、对象(Object)、生命线(LifeLine)、控制焦点(Activation)、消息(Message)、自关联消息、组合片段
类型 | 描述 |
---|---|
-> | 直线 |
--> | 虚线 |
->> | 有箭头的实线 |
-->> | 有箭头的虚线 |
sequenceDiagram participant 张三 participant a as 李四 a -> 张三: a loop 生病 王五->王五: 与疾病战斗 end Note over a,张三: Lesson 1 activate 张三 a --> +王五: b Note right of 王五: Lesson 2 loop 传染 a->王五: 传染 end 张三 ->> a: c deactivate 张三 王五 -->> -张三: d
聚焦
sequenceDiagram 李雷->>韩梅梅: Hello, what's your name? activate 韩梅梅 韩梅梅-->>李雷: Hello, my name is Hanmeimei! deactivate 韩梅梅
1```mermaid
2sequenceDiagram
3 李雷->>韩梅梅: Hello, what's your name?
4 activate 韩梅梅
5 韩梅梅-->>李雷: Hello, my name is Hanmeimei!
6 deactivate 韩梅梅
7```
8
9简写
10```mermaid
11sequenceDiagram
12 李雷->>+韩梅梅: Hello, what's your name?
13 韩梅梅-->>-李雷: Hello, my name is Hanmeimei!
14```
备注
sequenceDiagram 李雷->>韩梅梅: Hi Hanmeimei, How do you do? Note right of 韩梅梅: Lesson 1 韩梅梅-->>李雷: How do you do! Note over 李雷,韩梅梅: Lesson 1
1```mermaid
2sequenceDiagram
3 李雷->>韩梅梅: Hi Hanmeimei, How do you do?
4 Note right of 韩梅梅: Lesson 1
5 韩梅梅-->>李雷: How do you do!
6 Note over 李雷,韩梅梅: Lesson 1
7```
逻辑
片段关型 | 名称 | 说明 |
---|---|---|
Opt | 选项 | 包含一个可能发生或可能不发生的序列。可以在临界中指定序列发生的条件。 |
Alt | 抉择 | 包含一个片段列表,这些片段包含备选消息序列。在任何场合下只发生一个序列。可以在每个片段中设置一个临界来指示该片段可以运行的条件。else 的临界指示其他任何临界都不为 True 时应运行的片段。如果所有临界都为 False 并且没有 else,则不执行任何片段。 |
Loop | 循环 | 片段重复一定次数。可以在临界中指示片段重复的条件。Loop 组合片段具有“Min”和“Max”厦性,已们指示片段可以重复的最小和最大次数-默认值是无限制。 |
Break | 中断 | 如果为行此片段,则放弃序列的其余部分,可以使用临界来指示发生中断的条件。 |
Par | 并行 | 并行处理,片段中的事件可以交错. |
Critical | 关键 | 用在 Par 或 Seq 片段中。指示此片段中的消息不得与其他消息交错。 |
Seq | 弱顺序 | 有两个或更多操作数片段.涉及同一生命线的消息心须以片段的顺序发生。如果消息涉及的生命线不同,来自不同片段的消息可能会并行交措。 |
Strict | 强顺序 | 有两个或重多操作数片段,这些片段心须投给定顺序发生: |
循环 Loop
sequenceDiagram loop 不停地说 韩梅梅-->李雷: Great! end
1```mermaid
2sequenceDiagram
3 loop 不停地说
4 韩梅梅-->李雷: Great!
5 end
6```
抉择 Alt
类图 Class diagrams
- 类名称,在类图的最顶端;
- 类属性,在类图的中间层;
- 类方法,在类图的最下层。
classDiagram class 银行账户 银行账户 : +String 户主 银行账户 : +BigDecimal 余额 银行账户 : +存(数量) 银行账户 : +取(数量)
1```mermaid
2classDiagram
3 class 银行账户
4 银行账户 : +String 户主
5 银行账户 : +BigDecimal 余额
6 银行账户 : +存(数量)
7 银行账户 : +取(数量)
8```
classDiagram Animal <|-- Duck Animal <|-- Fish Animal <|-- Zebra Animal : +int age Animal : +String gender Animal: +isMammal() Animal: +mate() class Duck{ +String beakColor +swim() +quack() } class Fish{ -int sizeInFeet -canEat() } class Zebra{ +bool is_wild +run() }
1```mermaid
2classDiagram
3 Animal <|-- Duck
4 Animal <|-- Fish
5 Animal <|-- Zebra
6 Animal : +int age
7 Animal : +String gender
8 Animal: +isMammal()
9 Animal: +mate()
10 class Duck{
11 +String beakColor
12 +swim()
13 +quack()
14 }
15 class Fish{
16 -int sizeInFeet
17 -canEat()
18 }
19 class Zebra{
20 +bool is_wild
21 +run()
22 }
23```
状态图 State diagrams
stateDiagram [*] --> 激活状态 state 激活状态 { [*] --> NumLock关 NumLock关 --> NumLock开 : 按下 NumLock 键 NumLock开 --> NumLock关 : 按下 NumLock 键 -- [*] --> CapsLock关 CapsLock关 --> CapsLock开 : 按下 CapsLock 键 CapsLock开 --> CapsLock关 : 按下 CapsLock 键 -- [*] --> ScrollLock关 ScrollLock关 --> ScrollLock开 : 按下 ScrollLock 键 ScrollLock开 --> ScrollLock关 : 按下 ScrollLock 键 }
1```mermaid
2stateDiagram
3 [*] --> 激活状态
4 state 激活状态 {
5 [*] --> NumLock关
6 NumLock关 --> NumLock开 : 按下 NumLock 键
7 NumLock开 --> NumLock关 : 按下 NumLock 键
8 --
9 [*] --> CapsLock关
10 CapsLock关 --> CapsLock开 : 按下 CapsLock 键
11 CapsLock开 --> CapsLock关 : 按下 CapsLock 键
12 --
13 [*] --> ScrollLock关
14 ScrollLock关 --> ScrollLock开 : 按下 ScrollLock 键
15 ScrollLock开 --> ScrollLock关 : 按下 ScrollLock 键
16 }
17```
stateDiagram-v2 [*] --> Still Still --> [*] Still --> Moving Moving --> Still Moving --> Crash Crash --> [*]
1```mermaid
2stateDiagram-v2
3 [*] --> Still
4 Still --> [*]
5
6 Still --> Moving
7 Moving --> Still
8 Moving --> Crash
9 Crash --> [*]
10```
实体关系图 Entity Relationship Diagrams
erDiagram CUSTOMER ||--o{ ORDER : places ORDER ||--|{ LINE-ITEM : contains CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
1```mermaid
2erDiagram
3 CUSTOMER ||--o{ ORDER : places
4 ORDER ||--|{ LINE-ITEM : contains
5 CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
6```
用户旅行图 User Journey Diagram
journey title My working day section Go to work Make tea: 5: Me Go upstairs: 3: Me Do work: 1: Me, Cat section Go home Go downstairs: 5: Me Sit down: 5: Me
1```mermaid
2journey
3 title My working day
4 section Go to work
5 Make tea: 5: Me
6 Go upstairs: 3: Me
7 Do work: 1: Me, Cat
8 section Go home
9 Go downstairs: 5: Me
10 Sit down: 5: Me
11```
甘特图 Gantt diagrams
gantt dateFormat :YYYY-MM-DD title :甘特图实例 section 基本任务 已完成任务 :done, des1, 2014-01-06,2014-01-08 进行中任务 :active, des2, 2014-01-09, 3d 未开始任务1 : des3, after des2, 5d 未开始任务2 : des4, after des3, 5d section 紧急任务 已完成的紧急任务 :crit, done, 2014-01-06,24h 已完成紧急任务1 :crit, done, after des1, 2d 进行中紧急任务2 :crit, active, 3d 未开始紧急任务3 :crit, 5d 未开始一般任务4 :2d 未开始一般任务5 :1d section 文档编写 进行中文档任务1 :active, a1, after des1, 3d 未开始文档任务2 :after a1 , 20h 未开始文档任务3 :doc1, after a1 , 48h section 其他部分 其他任务1 :after doc1, 3d 其他任务2 :20h 其他任务3 :48h
1```mermaid
2gantt
3 dateFormat :YYYY-MM-DD
4 title :甘特图实例
5
6 section 基本任务
7 已完成任务 :done, des1, 2014-01-06,2014-01-08
8 进行中任务 :active, des2, 2014-01-09, 3d
9 未开始任务1 : des3, after des2, 5d
10 未开始任务2 : des4, after des3, 5d
11
12 section 紧急任务
13 已完成的紧急任务 :crit, done, 2014-01-06,24h
14 已完成紧急任务1 :crit, done, after des1, 2d
15 进行中紧急任务2 :crit, active, 3d
16 未开始紧急任务3 :crit, 5d
17 未开始一般任务4 :2d
18 未开始一般任务5 :1d
19
20 section 文档编写
21 进行中文档任务1 :active, a1, after des1, 3d
22 未开始文档任务2 :after a1 , 20h
23 未开始文档任务3 :doc1, after a1 , 48h
24
25 section 其他部分
26 其他任务1 :after doc1, 3d
27 其他任务2 :20h
28 其他任务3 :48h
29```
饼图 Pie chart
pie title Pets adopted by volunteers "Dogs" : 386 "Cats" : 85 "Rats" : 15
1```mermaid
2pie title Pets adopted by volunteers
3 "Dogs" : 386
4 "Cats" : 85
5 "Rats" : 15
6```
需求图 Requirement Diagram
requirementDiagram requirement test_req { id: 1 text: the test text. risk: high verifymethod: test } element test_entity { type: simulation } test_entity - satisfies -> test_req
1```mermaid
2requirementDiagram
3
4 requirement test_req {
5 id: 1
6 text: the test text.
7 risk: high
8 verifymethod: test
9 }
10
11 element test_entity {
12 type: simulation
13 }
14
15 test_entity - satisfies -> test_req
16```
requirementDiagram requirement test_req { id: 1 text: the test text. risk: high verifymethod: test } functionalRequirement test_req2 { id: 1.1 text: the second test text. risk: low verifymethod: inspection } performanceRequirement test_req3 { id: 1.2 text: the third test text. risk: medium verifymethod: demonstration } interfaceRequirement test_req4 { id: 1.2.1 text: the fourth test text. risk: medium verifymethod: analysis } physicalRequirement test_req5 { id: 1.2.2 text: the fifth test text. risk: medium verifymethod: analysis } designConstraint test_req6 { id: 1.2.3 text: the sixth test text. risk: medium verifymethod: analysis } element test_entity { type: simulation } element test_entity2 { type: word doc docRef: reqs/test_entity } element test_entity3 { type: "test suite" docRef: github.com/all_the_tests } test_entity - satisfies -> test_req2 test_req - traces -> test_req2 test_req - contains -> test_req3 test_req3 - contains -> test_req4 test_req4 - derives -> test_req5 test_req5 - refines -> test_req6 test_entity3 - verifies -> test_req5 test_req <- copies - test_entity2
1```mermaid
2requirementDiagram
3
4 requirement test_req {
5 id: 1
6 text: the test text.
7 risk: high
8 verifymethod: test
9 }
10
11 functionalRequirement test_req2 {
12 id: 1.1
13 text: the second test text.
14 risk: low
15 verifymethod: inspection
16 }
17
18 performanceRequirement test_req3 {
19 id: 1.2
20 text: the third test text.
21 risk: medium
22 verifymethod: demonstration
23 }
24
25 interfaceRequirement test_req4 {
26 id: 1.2.1
27 text: the fourth test text.
28 risk: medium
29 verifymethod: analysis
30 }
31
32 physicalRequirement test_req5 {
33 id: 1.2.2
34 text: the fifth test text.
35 risk: medium
36 verifymethod: analysis
37 }
38
39 designConstraint test_req6 {
40 id: 1.2.3
41 text: the sixth test text.
42 risk: medium
43 verifymethod: analysis
44 }
45
46 element test_entity {
47 type: simulation
48 }
49
50 element test_entity2 {
51 type: word doc
52 docRef: reqs/test_entity
53 }
54
55 element test_entity3 {
56 type: "test suite"
57 docRef: github.com/all_the_tests
58 }
59
60
61 test_entity - satisfies -> test_req2
62 test_req - traces -> test_req2
63 test_req - contains -> test_req3
64 test_req3 - contains -> test_req4
65 test_req4 - derives -> test_req5
66 test_req5 - refines -> test_req6
67 test_entity3 - verifies -> test_req5
68 test_req <- copies - test_entity2
69```
Git图 Gitgraph Diagrams
gitGraph commit commit branch develop checkout develop commit commit checkout main merge develop commit commit
1```mermaid
2 gitGraph
3 commit
4 commit
5 branch develop
6 checkout develop
7 commit
8 commit
9 checkout main
10 merge develop
11 commit
12 commit
13```
思维导图
mindmap root((mindmap)) Origins Long history ::icon(fa fa-book) Popularisation British popular psychology author Tony Buzan Research On effectiveness<br/>and features On Automatic creation Uses Creative techniques Strategic planning Argument mapping Tools Pen and paper Mermaid