Typora Markdown常用数学编辑公式

基本公式

上下标

A 1 2 B 12 2 x 2 + y A_1^2 \\ B_{12} \\ 2^{x^2+y} A12B122x2+y

$$
A_1^2
\\
B_{12}
\\
2^{x^2+y}
$$

分数

x 1 + x 2 1 2 + x y a b a b \frac{x}{1+x^2} \\ \frac{\frac{1}{2}+x}{y} \\ \tfrac{a}{b} \frac{a}{b} 1+x2xy21+xbaba

$$
\frac{x}{1+x^2}
\\
\frac{\frac{1}{2}+x}{y}
\\
\tfrac{a}{b}
\frac{a}{b}
$$

根号

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

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

组合数

( n k ) ( n k ) \binom{n}{k} \tbinom{n}{k} (kn)(kn)

$$
\binom{n}{k}
\tbinom{n}{k}
$$

导数

a ′ a ′ ′ a ′ a' a'' a^{\prime} aa′′a

$$
a'
a''
a^{\prime}
$$

取模

x ( m o d a ) 2 m o d    x x \pmod a \\ 2\mod{x} x(moda)2modx

$$
x \pmod a
\\
2\mod{x}
$$

积分

∫ 1 2 ∫ 2 1 ∮ ∫ ∬ ∯ ∭ ∰ \int_{1}^{2} \intop_{2}^{1} \oint \smallint \\ \iint \oiint \iiint \oiiint 1221

$$
\int_{1}^{2}
\intop_{2}^{1}
\oint
\smallint
\\
\iint
\oiint
\iiint
\oiiint
$$

微分

∇ ∂ x d x x ˙ y ¨ Δ \nabla \partial x \mathrm{d}x \dot x \ddot y \Delta xdxx˙y¨Δ

$$
\nabla		
\partial x			
\mathrm{d}x	
\dot x		
\ddot y     
\Delta
$$

累加、累乘、极限

∑ i = 1 k ∑ i = 1 n ∑ i = 1 n ∏ i = 1 k ∏ i = 1 n ∏ i = 1 n lim ⁡ k → ∞ lim ⁡ k → ∞ lim ⁡ k → ∞ ] \sum_{i=1}^{k} \displaystyle\sum_{i=1}^n \textstyle\sum_{i=1}^n \\ \prod_{i=1}^{k} \displaystyle\prod_{i=1}^n \textstyle\prod_{i=1}^n \\ \lim_{k \to \infty} \lim\limits_{k \to \infty} \lim\nolimits_{k \to \infty}] i=1ki=1ni=1ni=1ki=1ni=1nlimkklimlimk]

$$
\sum_{i=1}^{k}
\displaystyle\sum_{i=1}^n
\textstyle\sum_{i=1}^n
\\
\prod_{i=1}^{k}
\displaystyle\prod_{i=1}^n
\textstyle\prod_{i=1}^n
\\
\lim_{k \to \infty}
\lim\limits_{k \to \infty}
\lim\nolimits_{k \to \infty}]
$$

修饰符

简单的帽子

θ ^ A B ^ y ˉ A B ‾ a ~ a c ~ a ˉ a ˊ a ˇ a ˋ a ˙ a ¨ \hat{\theta} \widehat{AB} \\ \bar{y} \overline{AB} \\ \tilde{a} \widetilde{ac} \\ \bar{a} \acute{a} \check{a} \grave{a} \\ \dot{a} \ddot{a} θ^AB yˉABa~ac aˉaˊaˇaˋa˙a¨

$$
\hat{\theta}
\widehat{AB}
\\
\bar{y}
\overline{AB}
\\
\tilde{a}
\widetilde{ac}
\\
\bar{a}
\acute{a}
\check{a}
\grave{a}
\\
\dot{a}
\ddot{a}
$$

帽子和袜子

A B ← A B → A B ↔ A B ← A B → A B ↔ A B ⏞ A B ⏟ A B ‾ A B ‾ \overleftarrow{AB} \overrightarrow{AB} \overleftrightarrow{AB} \\ \underleftarrow{AB} \underrightarrow{AB} \underleftrightarrow{AB} \\ \overbrace{AB} \underbrace{AB} \\ \overline{AB} \underline{AB} AB AB AB AB AB ABAB ABABAB

$$
\overleftarrow{AB}
\overrightarrow{AB}
\overleftrightarrow{AB}
\\
\underleftarrow{AB}
\underrightarrow{AB}
\underleftrightarrow{AB}
\\
\overbrace{AB}
\underbrace{AB}
\\
\overline{AB}
\underline{AB}
$$

盒子和帽子

a + b + c ⏞ note a + b + c ⏟ note π = 3.14 \overbrace{a+b+c}^{\text{note}} \\ \underbrace{a+b+c}_{\text{note}} \\ \boxed{\pi=3.14} a+b+c notenote a+b+cπ=3.14

$$
\overbrace{a+b+c}^{\text{note}}
\\
\underbrace{a+b+c}_{\text{note}}
\\
\boxed{\pi=3.14}
$$

各种括号

( ( ( ( ( ( \big( \Big( \bigg( \Bigg( (((((

$$
(
\big(
\Big(
\bigg(
\Bigg(
$$

[ ] < > ∣ − 2 ∣ { } [] <> |-2| \{\} []<>2∣{}

$$
[]
<>
|-2|
\{\}
$$

⟮ x ⟯ ∥ a ∥ ⌈ 2.6 ⌉ ⌊ 1.2 ⌋ \lgroup x \rgroup \lVert a \rVert \lceil 2.6 \rceil \lfloor 1.2 \rfloor xa2.61.2

$$
\lgroup x \rgroup
\lVert a \rVert
\lceil 2.6 \rceil
\lfloor 1.2 \rfloor
$$

⌜ ⌝ ⌞ ⌟ \ulcorner \urcorner \llcorner \lrcorner

$$
\ulcorner
\urcorner
\llcorner
\lrcorner
$$

希腊字母

No.LowercaseUppercaseEnglishIPA
1 1 1 α \alpha α A A A a l p h a alpha alpha/'ælfə/
2 2 2 β \beta β B B B b e t a beta beta/'bi:tə/or/'beɪtə/
3 3 3 γ \gamma γ Γ \Gamma Γ g a m m a gamma gamma/'gæmə/
4 4 4 δ \delta δ Δ \Delta Δ d e l t a delta delta/'deltə/
5 5 5 ϵ \epsilon ϵ E E E e p s i l o n epsilon epsilon/'epsɪlɒn/
6 6 6 ζ \zeta ζ Z Z Z z e t a zeta zeta/'zi:tə/
7 7 7 η \eta η H H H e t a eta eta/'i:tə/
8 8 8 θ \theta θ Θ \Theta Θ t h e t a theta theta/'θi:tə/
9 9 9 ι \iota ι I I I i o t a iota iota/aɪ’əʊtə/
10 10 10 κ \kappa κ K K K k a p p a kappa kappa/'kæpə/
11 11 11 λ \lambda λ λ \lambda λ l a m b d a lambda lambda/'læmdə/
12 12 12 μ \mu μ M M M m u mu mu/mju:/
13 13 13 ν \nu ν N N N n u nu nu/nju:/
14 14 14 ξ \xi ξ Ξ \Xi Ξ x i xi xi/ksi/or/'zaɪ/or/'ksaɪ/
15 15 15 ο \omicron ο O O O o m i c r o n omicron omicron/əu’maikrən/or/'ɑmɪ,krɑn/
16 16 16 π \pi π Π \Pi Π p i pi pi/paɪ/
17 17 17 ρ \rho ρ P P P r h o rho rho/rəʊ/
18 18 18 σ \sigma σ Σ \Sigma Σ s i g m a sigma sigma/'sɪɡmə/
19 19 19 τ \tau τ T T T t a u tau tau/tɔ:/or/taʊ/
20 20 20 υ \upsilon υ Υ \Upsilon Υ u p s i l o n upsilon upsilon/'ipsilon/or/'ʌpsilɒn/
21 21 21 ϕ \phi ϕ Φ \Phi Φ p h i phi phi/faɪ/
22 22 22 χ \chi χ X X X c h i chi chi/kaɪ/
23 23 23 ψ \psi ψ Ψ \Psi Ψ p s i psi psi/psaɪ/
24 24 24 ω \omega ω Ω \Omega Ω o m e g a omega omega/'əʊmɪɡə/or/oʊ’meɡə/
| No.  | Lowercase  | Uppercase  |  English  |              IPA              |
| :--: | :--------: | :--------: | :-------: | :---------------------------: |
| $1$  |  $\alpha$  |    $A$     |  $alpha$  |          **/'ælfə/**          |
| $2$  |  $\beta$   |    $B$     |  $beta$   |    **/'bi:tə/or/'beɪtə/**     |
| $3$  |  $\gamma$  |  $\Gamma$  |  $gamma$  |          **/'gæmə/**          |
| $4$  |  $\delta$  |  $\Delta$  |  $delta$  |         **/'deltə/**          |
| $5$  | $\epsilon$ |    $E$     | $epsilon$ |        **/'epsɪlɒn/**         |
| $6$  |  $\zeta$   |    $Z$     |  $zeta$   |         **/'zi:/**          |
| $7$  |   $\eta$   |    $H$     |   $eta$   |          **/'i:/**          |
| $8$  |  $\theta$  |  $\Theta$  |  $theta$  |         **/'θi:/**          |
| $9$  |  $\iota$   |    $I$     |  $iota$   |         **/aɪ'əʊtə/**         |
| $10$ |  $\kappa$  |    $K$     |  $kappa$  |          **/'kæpə/**          |
| $11$ | $\lambda$  | $\lambda$  | $lambda$  |         **/'læmdə/**          |
| $12$ |   $\mu$    |    $M$     |   $mu$    |          **/mju:/**           |
| $13$ |   $\nu$    |    $N$     |   $nu$    |          **/nju:/**           |
| $14$ |   $\xi$    |   $\Xi$    |   $xi$    |   **/ksi/or/'zaɪ/or/'ksaɪ/**  |
| $15$ | $\omicron$ |    $O$     | $omicron$ | **/əu'maikrən/or/'ɑmɪ,krɑn/** |
| $16$ |   $\pi$    |   $\Pi$    |   $pi$    |           **/paɪ/**           |
| $17$ |   $\rho$   |    $P$     |   $rho$   |           **/rəʊ/**           |
| $18$ |  $\sigma$  |  $\Sigma$  |  $sigma$  |         **/'sɪɡmə/**          |
| $19$ |   $\tau$   |    $T$     |   $tau$   |       **/:/or/taʊ/**        |
| $20$ | $\upsilon$ | $\Upsilon$ | $upsilon$ |  **/'ipsilon/or/'ʌpsilɒn/**   |
| $21$ |   $\phi$   |   $\Phi$   |   $phi$   |           **/faɪ/**           |
| $22$ |   $\chi$   |    $X$     |   $chi$   |           **/kaɪ/**           |
| $23$ |   $\psi$   |   $\Psi$   |   $psi$   |          **/psaɪ/**           |
| $24$ |  $\omega$  |  $\Omega$  |  $omega$  |   **/'əʊmɪɡə/or/oʊ'meɡə/**    |

算数运算符

减号: − + × / ÷ ⋅ # % 减号:- \\ + \times / \div \cdot \# \% 减号:+×/÷#%

$$
减号:-
\\
+
\times
/
\div
\cdot
\#
\%
$$

∘ ∗ ⋆ ⊗ ⊕ ⊙ \circ \ast \star \otimes \oplus \odot

$$
\circ
\ast
\star
\otimes
\oplus
\odot
$$

± ∓ ∔ ⋇ \pm \mp \dotplus \divideontimes ±∔⋇

$$
\pm
\mp
\dotplus
\divideontimes
$$

比较运算符

大于号: > < ≤ ≥ ≫ ≪ 大于号:> \\ < \le \ge \gg \ll 大于号:><≤≥≫≪

$$
大于号:>
\\
<
\le
\ge
\gg
\ll
$$

⋞ ⋟ ≺ ≻ ⪯ ⪰ \curlyeqprec \curlyeqsucc \prec \succ \preceq \succeq ⋞⋟≺≻⪯⪰


$$
\curlyeqprec
\curlyeqsucc
\prec
\succ
\preceq
\succeq
$$

集合运算符

∈ ∋ ⊄ ⊅ ⊆ ⊇ ∩ ∪ ∧ ∨ ¬ ∅ ∅ ∵ ∀ ∃ ∴ \in \owns \not \subset \not \supset \subseteq \supseteq \\ \cap \cup \land \lor \\ \neg \emptyset \varnothing \\ \because \forall \exists \therefore ∈∋⊃⊆⊇¬∅∀∃

$$
\in
\owns \not
\subset \not
\supset
\subseteq
\supseteq
\\
\cap
\cup
\land
\lor
\\
\neg
\emptyset
\varnothing
\\
\because
\forall
\exists
\therefore
$$

∩ ∪ ∧ ∨ ⊔ ⊓ \cap \cup \land \lor \sqcup \sqcap

$$
\cap
\cup
\land
\lor
\sqcup
\sqcap
$$

箭头符

← ← → → ↔ ↑ ↓ ↕ \gets \leftarrow \to \rightarrow \leftrightarrow \\ \uparrow \downarrow \updownarrow ←←→→↔↑↓↕

$$
\gets
\leftarrow
\to
\rightarrow
\leftrightarrow
\\
\uparrow
\downarrow
\updownarrow
$$

⇐ ⇒ ⇔    ⟺    ⇑ ⇓ ⇕ \Leftarrow \Rightarrow \Leftrightarrow \iff \\ \Uparrow \Downarrow \Updownarrow ⇐⇒⇔⇑⇓⇕

$$
\Leftarrow
\Rightarrow
\Leftrightarrow
\iff
\\
\Uparrow
\Downarrow
\Updownarrow
$$

↗ ↘ ↙ ↖ \nearrow \searrow \swarrow \nwarrow ↗↘↙↖

$$
\nearrow
\searrow
\swarrow
\nwarrow
$$

⟵ ⟶ ⟷ ⟸ ⟹ ⟺ ⟼ \longleftarrow \longrightarrow \longleftrightarrow \Longleftarrow \Longrightarrow \Longleftrightarrow \longmapsto ⟵⟶⟷⟸⟹⟺⟼

$$
\longleftarrow
\longrightarrow
\longleftrightarrow
\Longleftarrow
\Longrightarrow
\Longleftrightarrow
\longmapsto
$$

→ o v e r → u n d e r → u n d e r o v e r ← u n d e r o v e r ← u n d e r ← o v e r \xrightarrow{over} \xrightarrow[under]{} \xrightarrow[under]{over} \xleftarrow[under]{over} \xleftarrow[under]{} \xleftarrow[]{over} over underover underover under underover

$$
\xrightarrow{over}
\xrightarrow[under]{}
\xrightarrow[under]{over}
\xleftarrow[under]{over}
\xleftarrow[under]{}
\xleftarrow[]{over}
$$

空格间距

A  ⁣ B A B A   B A   B A   B A B A B A B A\!B \\ AB \\ A\thinspace B \\ A\:B \\ A\ B \\ A \enspace B \\ A\quad B \\ A\qquad B ABABABABA BABABAB

$$
A\!B
\\
AB
\\
A\thinspace B
\\
A\:B
\\
A\ B
\\
A \enspace B
\\
A\quad B
\\
A\qquad B
$$

矩阵

A = a b c d A = \begin{matrix} a & b\\ c & d \end{matrix} A=acbd

$$
A = \begin{matrix}
a & b\\
c & d
\end{matrix}
$$

B = ( a b c d ) B = \begin{pmatrix} a & b\\ c & d \end{pmatrix} B=(acbd)

$$
B = \begin{pmatrix}
a & b\\
c & d
\end{pmatrix}
$$

C = ∣ a b c d ∣ C = \begin{vmatrix} a & b\\ c & d \end{vmatrix} C= acbd

$$
C = \begin{vmatrix}
a & b\\
c & d
\end{vmatrix}
$$

D = [ a b c d ] D = \begin{bmatrix} a & b\\ c & d \end{bmatrix} D=[acbd]

$$
D = \begin{bmatrix}
a & b\\
c & d
\end{bmatrix}
$$

E = ∥ a b c d ∥ E = \begin{Vmatrix} a & b\\ c & d \end{Vmatrix} E= acbd

$$
E = \begin{Vmatrix}
a & b\\
c & d
\end{Vmatrix}
$$

F = { a b c d } F = \begin{Bmatrix} a & b\\ c & d \end{Bmatrix} F={acbd}

$$
F = \begin{Bmatrix}
a & b\\
c & d
\end{Bmatrix}
$$

[ A   b ] = [ a 11 a 12 a 13 b 1 a 21 a 22 a 23 b 2 a 31 a 32 a 33 b 3 ] [A\ b] = \begin{bmatrix} \begin{array}{c c c|c} a_{11} & a_{12} & a_{13} & b_1\\ a_{21} & a_{22} & a_{23} & b_2\\ a_{31} & a_{32} & a_{33} & b_3\\ \end{array} \end{bmatrix} [A b]= a11a21a31a12a22a32a13a23a33b1b2b3

$$
[A\ b] = 
\begin{bmatrix}
\begin{array}{c c c|c}
a_{11} & a_{12} & a_{13} & b_1\\
a_{21} & a_{22} & a_{23} & b_2\\
a_{31} & a_{32} & a_{33} & b_3\\
\end{array}
\end{bmatrix}
$$

a b c d e f g h i \begin{array}{c:c:c} a & b & c \\ \hline d & e & f \\ \hdashline g & h & i \end{array} adgbehcfi

$$
\begin{array}{c:c:c}
a & b & c \\ 
\hline
d & e & f \\
\hdashline
 g & h & i
\end{array}
$$

L n × n = [ a 11 a 12 ⋯ a 1 n a 21 a 22 ⋯ a 2 n ⋮ ⋮ ⋱ ⋮ a n 1 a n 2 ⋯ a n n ] L_{n\times n} = \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots &\ddots & \vdots\\ a_{n1} & a_{n2} & \cdots & a_{nn} \\ \end{bmatrix} Ln×n= a11a21an1a12a22an2a1na2nann

$$
L_{n\times n} = \begin{bmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\ 
a_{21} & a_{22} & \cdots & a_{2n} \\ 
\vdots & \vdots &\ddots & \vdots\\
a_{n1} & a_{n2} & \cdots & a_{nn} \\ 
\end{bmatrix}
$$

列式、方程组

f ( x ) = ( x + 1 ) 2 = x 2 + 2 x + 1 \begin{aligned} f(x) &= (x+1)^2\\ &= x^2 + 2x + 1 \end{aligned} f(x)=(x+1)2=x2+2x+1

$$
\begin{aligned}
f(x) &= (x+1)^2\\
&= x^2 + 2x + 1
\end{aligned}
$$

f ( x ) = { a if b b if a f(x) = \begin{cases} a &\text{if b}\\ b &\text{if a}\\ \end{cases} f(x)={abif bif a

$$
f(x) = \begin{cases}
a &\text{if b}\\
b &\text{if a}\\
\end{cases}
$$

{ x + 2 y = 1 3 x − y = 5 \begin{cases} \begin{aligned} x + 2y &= 1\\ 3x - y &= 5 \end{aligned} \end{cases} {x+2y3xy=1=5

$$
\begin{cases}
\begin{aligned}
x + 2y &= 1\\
3x - y &= 5
\end{aligned}
\end{cases}
$$

g ( x , y ) = { M g − d M f − b [ f ( x , y ) − b ] + d b ≤ f ( x , y ) ≤ M f F L ∗ S L ≤ 0 < S M F R ∗ S M ≤ 0 < S R F R S R ≤ 0 g(x,y)=\left\{ \begin{array}{rcl} \frac{M_g - d}{M_f-b}[f(x,y)-b]+d & & {b \leq f(x,y) \leq M_f}\\ F^*_L & & {S_L \leq 0 < S_M}\\ F^*_R & & {S_M \leq 0 < S_R}\\ F_R & & {S_R \leq 0} \end{array} \right. g(x,y)= MfbMgd[f(x,y)b]+dFLFRFRbf(x,y)MfSL0<SMSM0<SRSR0

$$
g(x,y)=\left\{
\begin{array}{rcl}
\frac{M_g - d}{M_f-b}[f(x,y)-b]+d       &      & {b      \leq  f(x,y)  \leq M_f}\\
F^*_L     &      & {S_L \leq 0 < S_M}\\
F^*_R     &      & {S_M \leq 0 < S_R}\\
F_R       &      & {S_R \leq 0}
\end{array} \right.
$$

作废符

5 5 A B C \cancel{5} \bcancel{5} \xcancel{ABC} 5 5 ABC

$$
\cancel{5}
\bcancel{5}
\xcancel{ABC}
$$

常见图形

□ □ ■ △ ▽ ▲ ⋄ ◊ ⋆ ★ ∘ ∙ ◯ ⨀ \Box \square \blacksquare \triangle \triangledown \blacktriangle \diamond \Diamond \star \bigstar \circ \bullet \bigcirc \bigodot □□■▽▲

$$
\Box
\square
\blacksquare
\triangle
\triangledown
\blacktriangle
\diamond
\Diamond
\star
\bigstar
\circ
\bullet
\bigcirc
\bigodot
$$

♢ ♣ ♡ ♠ \diamondsuit \clubsuit \heartsuit \spadesuit ♢♣♡♠

$$
\diamondsuit
\clubsuit
\heartsuit
\spadesuit
$$

∠ ∡ ⊤ ⊥ ∞ \angle \measuredangle \top \bot \infty ⊤⊥∞

$$
\angle
\measuredangle
\top
\bot
\infty
$$

✓ † ‡ ¥ $ \checkmark \dagger \ddagger \yen \$ ¥$

$$
\checkmark
\dagger
\ddagger
\yen
\$
$$

声明宏(高级用法:定义函数)

对于一些复杂但是只有少许不同的表达式,可以声明一个函数来调用,提高源码的可读性,减少出错.

\def\macroname#1#2{
your command
}

宏允许带任意数量的参数(也可以不带参),必须是#1,#2,……这样的命名格式,同时注意在定义宏的时候注意让#1与\中间隔一个空格,否则会解析成#。在调用的时候格式为\macroname{x}{y}{z},例子
f ( x ) = 1 2 π   σ 1 exp ⁡ [ − ( x − u 1 ) 2 2   σ 1 2 ] f ( y ) = 1 2 π   σ 2 exp ⁡ [ − ( y − u 2 ) 2 2   σ 2 2 ] \def\Normal#1#2#3{ \frac{1}{\sqrt{2\pi}\ #3}\exp{[-\frac{(#1 - #2)^2}{2\ #3^2}]} } f(x)=\Normal{x}{u_1}{\sigma_1}\\ f(y)=\Normal{y}{u_2}{\sigma_2}\\ f(x)=2π  σ11exp[2 σ12(xu1)2]f(y)=2π  σ21exp[2 σ22(yu2)2]

$$
\def\Normal#1#2#3{
\frac{1}{\sqrt{2\pi}\ #3}\exp{[-\frac{(#1 - #2)^2}{2\ #3^2}]}
}
f(x)=\Normal{x}{u_1}{\sigma_1}\\
f(y)=\Normal{y}{u_2}{\sigma_2}\\
$$

颜色和大小

F = m a F = m a F = m a o n e   l i n e n o t h i n g \textcolor{blue}{F=ma} \\ \textcolor{#00ff00}{F=ma} \\ \textcolor{#ff0000}{F=ma} \\ \color{blue} one\ line \\ nothing F=maF=maF=maone linenothing

$$
\textcolor{blue}{F=ma}
\\
\textcolor{#00ff00}{F=ma}
\\
\textcolor{#ff0000}{F=ma}
\\
\color{blue} one\ line
\\
nothing
$$

F=ma A A \colorbox{#00ff00}{F=ma} \\ \colorbox{aqua}{A} \\ \fcolorbox{red}{aqua}{A} F=maAA

$$
\colorbox{#00ff00}{F=ma}
\\
\colorbox{aqua}{A}
\\
\fcolorbox{red}{aqua}{A}
$$

A B A B A B A B A B A B A B A B A B A B AB \Huge AB \huge AB \\ AB \LARGE AB \Large AB \large AB \\ AB \small AB \tiny AB ABABABABABABABABABAB

$$
AB
\Huge AB
\huge AB
\\
AB
\LARGE AB
\Large AB
\large AB
\\
AB
\small AB
\tiny AB
$$

画图

UML时序图

在画时序图的时候
我们的思路应该是这样的:
从左到右(创建好节点),然后,从上到下(编写节点间的交互逻辑),写代码画图。
t1 线程 num = 0 volatile ready = false t2 线程 num=2 ready=true 写屏障 读屏障 读取ready=true 读取num=2 t1 线程 num = 0 volatile ready = false t2 线程
```mermaid
sequenceDiagram
participant t1 as t1 线程
participant num as num = 0
participant ready as volatile ready = false
participant t2 as t2 线程
t1 -->> t1:num=2
t1 ->> ready:ready=true
Note over t1,ready:写屏障
Note over num,t2:读屏障
t2 ->> ready:读取ready=true
t2->> num:读取num=2

流程图

在流程图的时候
LR 指左边到右边,所以是横向流程图
TD 指上边到下边,所以是纵向流程图
我们的思路应该是这样的:
先定义好所有的流程节点,再确定好各个流程节点的指向关系,最后补充流程线上的条件
倒空
检查
已满
还空
保洁阿姨
主人
垃圾袋
新垃圾袋
```mermaid
graph TD
s(保洁阿姨)
m(主人)
g1(垃圾袋)
g2(新垃圾袋)

s-. 倒空 .-> g1
m -- 检查 --> g1
g1 -- 已满 --> g2
g1 -- 还空 --> g1
为空
不为空
成功
失败
已创建
没创建
成功
失败
当前线程
Cells
cas base 累加
当前线程 cell 是否创建
return
longAccumulate
cas cell 累加
```mermaid
graph LR
A(当前线程) --> B(Cells)
B --> |为空| C(cas base 累加)
B --> |不为空| D(当前线程 cell 是否创建)
C --> |成功| E(return)
C --> |失败| F(longAccumulate)
D --> |已创建| G(cas cell 累加)
D --> |没创建| F(longAccumulate)
G --> |成功| E(return)
G --> |失败| F(longAccumulate)
为空
不为空
成功
失败
已创建
没创建
成功
失败
当前线程
Cells
cas base 累加
当前线程 cell 是否创建
return
longAccumulate
cas cell 累加
```mermaid
graph LR
A(当前线程) 
B(Cells)
C(cas base 累加)
D(当前线程 cell 是否创建)
E(return)
F(longAccumulate)
G(cas cell 累加)
A --> B
B -- 为空 --> C
B -- 不为空 --> D
C -- 成功 --> E
C -- 失败 --> F
D -- 已创建 --> G
D -- 没创建 --> F
G -- 成功 --> E
G -- 失败 --> F

状态图

Still
Moving
Crash
```mermaid
stateDiagram-v2
    [*] --> Still
    Still --> [*]

    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]
状态

可以通过多种方式声明一个状态。最简单的方法是将状态 id 定义为描述。

s1
```mermaid
stateDiagram-v2
    s1

另一种方法是使用带有如下描述的 state 关键字:

This is a state description
```mermaid
stateDiagram-v2
    state "This is a state description" as s2

用描述定义状态的另一种方法是定义状态 id,后跟冒号和描述:

This is a state description
```mermaid
stateDiagram-v2
    s2 : This is a state description
过渡

当一种状态进入另一种状态时,转换是路径/边缘。这使用文本箭头“–>”表示。当您定义两个状态之间的转换并且状态尚未定义时,未定义的状态是使用转换中的 id 定义的。您可以稍后将描述添加到以这种方式定义的状态。

s1
s2
```mermaid
stateDiagram-v2
    s1 --> s2

可以向过渡添加文本。来描述它代表什么。

A transition
s1
s2
```mermaid
stateDiagram-v2
    s1 --> s2: A transition
开始和结束

有两种特殊状态指示图表的开始和停止。这些是用 [*] 语法编写的,转换到它的方向将其定义为开始或停止状态。

s1
```mermaid
stateDiagram-v2
    [*] --> s1
    s1 --> [*]
复合状态

在实际使用状态图时,您通常会得到多维图,因为一个状态可以有多个内部状态。在这个术语中,这些被称为复合状态。为了定义复合状态,您需要使用 state 关键字,后跟一个 id 和 {} 之间的复合状态的主体。请参见下面的示例:

First
second
```mermaid
stateDiagram-v2
    [*] --> First
    state First {
        [*] --> second
        second --> [*]
    }

也可以在多个层中执行此操作:

First
Second
second
Third
third
```mermaid
stateDiagram-v2
    [*] --> First

    state First {
        [*] --> Second

        state Second {
            [*] --> second
            second --> Third

            state Third {
                [*] --> third
                third --> [*]
            }
        }
    }

还可以定义复合状态之间的转换:

First
fir
Second
sec
Third
thi
```mermaid
stateDiagram-v2
    [*] --> First
    First --> Second
    First --> Third

    state First {
        [*] --> fir
        fir --> [*]
    }
    state Second {
        [*] --> sec
        sec --> [*]
    }
    state Third {
        [*] --> thi
        thi --> [*]
    }
选择

有时您需要在两条或多条路径之间进行选择建模,您可以使用 <> 来实现.

if n < 0
if n >= 0
IsPositive
False
True
```mermaid
stateDiagram-v2
    state if_state <<choice>>
    [*] --> IsPositive
    IsPositive --> if_state
    if_state --> False: if n < 0
    if_state --> True : if n >= 0
叉子

可以使用 <> <> 在图中指定一个分支。

State2
State3
State4
```mermaid
   stateDiagram-v2
    state fork_state <<fork>>
      [*] --> fork_state
      fork_state --> State2
      fork_state --> State3

      state join_state <<join>>
      State2 --> join_state
      State3 --> join_state
      join_state --> State4
      State4 --> [*]
笔记
The state with a note
Important information! You can write
notes.
State2
This is the note to the left.
```mermaid
stateDiagram-v2
        State1: The state with a note
        note right of State1
            Important information! You can write
            notes.
        end note
        State1 --> State2
        note left of State2 : This is the note to the left.
并发
Active
EvNumLockPressed
EvNumLockPressed
NumLockOff
NumLockOn
EvCapsLockPressed
EvCapsLockPressed
CapsLockOff
CapsLockOn
EvScrollLockPressed
EvScrollLockPressed
ScrollLockOff
ScrollLockOn
```mermaid
stateDiagram-v2
    [*] --> Active

    state Active {
        [*] --> NumLockOff
        NumLockOff --> NumLockOn : EvNumLockPressed
        NumLockOn --> NumLockOff : EvNumLockPressed
        --
        [*] --> CapsLockOff
        CapsLockOff --> CapsLockOn : EvCapsLockPressed
        CapsLockOn --> CapsLockOff : EvCapsLockPressed
        --
        [*] --> ScrollLockOff
        ScrollLockOff --> ScrollLockOn : EvScrollLockPressed
        ScrollLockOn --> ScrollLockOff : EvScrollLockPressed
    }
设置图表的方向
A
B
a
b
C
D
```mermaid
stateDiagram
    direction LR
    [*] --> A
    A --> B
    B --> C
    state B {
      direction LR
      a --> b
    }
    B --> D

类图

定义一个类
Animal
Vehicle
Car
```mermaid
classDiagram
    class Animal
    Vehicle <|-- Car
定义类的成员
BankAccount
+String owner
+BigDecimal balance
+deposit(amount)
+withdrawal(amount)
```mermaid
classDiagram
class BankAccount
BankAccount : +String owner
BankAccount : +BigDecimal balance
BankAccount : +deposit(amount)
BankAccount : +withdrawal(amount)
```mermaid
classDiagram
class BankAccount{
    +String owner
    +BigDecimal balance
    +deposit(amount)
    +withdrawal(amount)
}
定义返回值
BankAccount
+String owner
+BigDecimal balance
+deposit(amount) : bool
+withdrawal(amount) : int
```mermaid
classDiagram
class BankAccount{
    +String owner
    +BigDecimal balance
    +deposit(amount) bool
    +withdrawal(amount) int
}
定义泛型
Square<Shape>
int id
List<int> position
-List<string> messages
setPoints(List<int> points)
getPoints() : List<int>
+setMessages(List<string> messages)
+getMessages() : List<string>
+getDistanceMatrix()
```mermaid
classDiagram
class Square~Shape~{
    int id
    List~int~ position
    setPoints(List~int~ points)
    getPoints() List~int~
}

Square : -List~string~ messages
Square : +setMessages(List~string~ messages)
Square : +getMessages() List~string~
Square : +getDistanceMatrix() List~List~int~~
类成员的可见性
+ Public
- Private
# Protected
~ Package/Internal
// note you can also include additional classifiers to a method definition by 
// adding the following notation to the end of the method, i.e.: after the () or 
// after the return type:
* Abstract 		e.g.: someAbstractMethod()* or someAbstractMethod() int*
$ Static 		e.g.: someStaticMethod()$ or someStaticMethod() String$
//note you can also include additional classifiers to a field definition by 
// adding the following notation to the very end:
$ Static e.g.: String someField$
Demo
string some_filed
+public_methos()
-private_method()
#protected_method()
~packag_method()
abstract_method()
static_method()
```mermaid
classDiagram
class Demo {
	+ public_methos()
	- private_method()
	#protected_method()
	~packag_method()
    abstract_method()*
    static_method()$
    string some_filed$
}
定义类之间的关系
TypeDescription
<|--Inheritance继承
*--Composition组合
o--Aggregation聚合
-->Association关联
--Link (Solid)
..>Dependency依赖
..|>Realization实现
..Link (Dashed)
```mermaid
classDiagram
classA <|-- classB
classC *-- classD
classE o-- classF
classG <-- classH
classI -- classJ
classK <.. classL
classM <|.. classN
classO .. classP
classA
classB
classC
classD
classE
classF
classG
classH
classI
classJ
classK
classL
classM
classN
classO
classP
```mermaid
classDiagram
classA --|> classB : Inheritance
classC --* classD : Composition
classE --o classF : Aggregation
classG --> classH : Association
classI -- classJ : Link(Solid)
classK ..> classL : Dependency
classM ..|> classN : Realization
classO .. classP : Link(Dashed)
Inheritance
Composition
Aggregation
Association
Link(Solid)
Dependency
Realization
Link(Dashed)
classA
classB
classC
classD
classE
classF
classG
classH
classI
classJ
classK
classL
classM
classN
classO
classP
类间关系加标注
implements
composition
aggregation
classA
classB
classC
classD
classE
classF
```mermaid
classDiagram
classA <|-- classB : implements
classC *-- classD : composition
classE o-- classF : aggregation
定义命名空间
classDiagram
namespace BaseShapes {
    class Triangle
    class Rectangle {
      double width
      double height
    }
}
类注释
<<Interface>> To represent an Interface class
<<Abstract>> To represent an abstract class
<<Service>> To represent a service class
<<Enumeration>> To represent an enum
«interface»
Shape
noOfVertices
draw()
«enumeration»
Color
RED
BLUE
GREEN
WHITE
BLACK
```mermaid
classDiagram
class Shape{
    <<interface>>
    noOfVertices
    draw()
}
class Color{
    <<enumeration>>
    RED
    BLUE
    GREEN
    WHITE
    BLACK
}
Comments
```mermaid
classDiagram
%% This whole line is a comment classDiagram class Shape <<interface>>
class Shape{
    <<interface>>
    noOfVertices
    draw()
}
Setting the direction of the diagram
carries
1
1
rides
1
1
Student
-idCard : IdCard
IdCard
-id : int
-name : string
Bike
-id : int
-name : string
```mermaid
classDiagram
  direction RL
  class Student {
    -idCard : IdCard
  }
  class IdCard{
    -id : int
    -name : string
  }
  class Bike{
    -id : int
    -name : string
  }
  Student "1" --o "1" IdCard : carries
  Student "1" --o "1" Bike : rides

Cmd Markdown 简明语法手册
Class diagrams

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

血_影

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值