在 Markdown 中嵌入 KaTex 数学公式

2022-10-04 19:52:02
在 Word 中,我们经常用到公式编辑器,来编辑数学公式,比如像这样: $x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$ 一个简单的方法是把公式做成图片,但是图片既不好排版,又很难缩放。最好的方法是用文字来描述数学公式,这样就可以方便地编辑公式。 ## 插入公式 在 Markdown 中嵌入公式,使用一个或两个 `$` 符号,一个 `$` 将公式插入到本行内, `$$` 代表将公式插入到一个新的行中并居中显示 ## 上标与下标 上标符号,符号:`^`,如:`$X^{32}$` 的效果是 $X^{32}$ 下标符号,符号:`_`,如:`$X_2$`的效果是 $X_2$ | 效果 | 符号 | 举例 | 效果 | | ---- | ---- | ---- | ---- | | 上划线 | \overline{算式} | `$\overline {x+y}$` | $\overline {x+y}$ | | 下划线 | \underline{算式} | `$\underline {x+y}$` | $\underline {x+y}$ | | 上大括号 | \overbrace{算式} | `$\overbrace{a+b+c+d}^{4}$` | $\overbrace{a+b+c+d}^{4}$ | | 下大括号 | \underbrace{算式} | `$a+ \underbrace {b+c}_{4} +d$` | $a+ \underbrace {b+c}_{4} +d$ | | 上位符号 | \stackrel {上位符号} {基位符号} | `${x} \stackrel {i=1}{=}{y}$` | ${x} \stackrel {i=1}{=}{y}$ | ## 占位符 | 占位符 | 符号 | 举例 | 效果 | | ---- | ---- | ---- | --- | | 两个quad空格 | \qquad | `$x \qquad y$` | $x \qquad y$ | | quad空格 | \quad | `$x \quad y$` | $x \quad y$ | | 一个空格 | \ | `$x \ y$ ` | $x \ y$ | | 换行 | \\ | `$n\\ b$` | $n\\ b$ | | 换行 | \newline | `$n\newline b$` | $n\newline b$ | ## 定界符 | 定界符 | 符号 | 举例 | 效果 | | ---- | ---- | ---- | ---- | | 括号 | ()\big(\big) \Big(\Big) \bigg(\bigg) \Bigg(\Bigg) | `() $() \big(\big) \Big(\Big) \bigg(\bigg) \Bigg(\Bigg)$` | () $() \big(\big) \Big(\Big) \bigg(\bigg) \Bigg(\Bigg)$ | | 中括号 | [] | `$[x+y]$` | $[x+y]$ | | 自适应括号 | \left \right | `$\left( x{y \choose z_f} \right)$` | $\left( x{y \choose z_f} \right)$ | | 带括号上下标 | {上位公式 \choose 下位公式} | `${n \choose k}$` | ${n \choose k}$ | | 不带括号上下标 | {上位公式 \atop 下位公式} | `${n \atop k}$` | ${n \atop k}$ | ## 四则运算 | 四则运算 | 符号 | 示例 | 效果 | | ----------- | ------------------- | ----------------------- | ------------------- | | 加法 | + | `$x+y=z$` | $x+y=z$ | | 减法 | - | `$x-y=z$` | $x-y=z$ | | 加减 | \pm | `$x \pm y=z$` | $x \pm y=z$ | | 乘法 | \times | `$x \times y=z$` | $x \times y=z$ | | 点乘 | \cdot | `$x \cdot y=z$` | $x \cdot y=z$ | | 星乘 | \ast | `$x \ast y=z$` | $x \ast y=z$ | | 除法 | \div | `$x \div y=z$` | $x \div y=z$ | | 斜法 | / | `$x / y=z$` | $x / y=z$ | | 小分式表示1 | \frac{分子}{分母} | `$\frac {x+y}{y+z}$` | $\frac {x+y}{y+z}$ | | 小分式表示2 | {分子} \voer {分母} | `${x+y} \over {y+z}$` | ${x+y} \over {y+z}$ | | 大分式 | \dfrac{分子}{分母} | `$\dfrac {x+y}{y+z}$` | $\dfrac {x+y}{y+z}$ | | 绝对值 | \vert | `$f(x)=\vert a-b\vert$\|` | $f(x)=\vert a-b\vert$ | ## 高级运算 | 高级运算 | 符号 | 举例 | 效果 | | ---------- | ----------------------------- | -------------------------------------------------------- | ------------------------------------------------------ | | 平均数 | \overline{算式} | `$\overline{xyz}$` | $\overline{xyz}$ | | 开二次方 | \sqrt | `$\sqrt {x}$` | $\sqrt {x}$ | | 开方 | \sqrt[开方数]{被开方数} | `$\sqrt[3]{x+y}$` | $\sqrt[3]{x+y}$ | | 对数运算1 | \log(数) | `$\log(x)$` | $\log(x)$ | | 对数运算2 | \lg(数) | `$\lg(x)$` | $\lg(x)$ | | 极限运算1 | \lim | `$\lim^{x \to 1}_{y \to 0}{\frac{x}{y}}$` | $\lim^{x \to 1}_{y \to 0}{\frac{x}{y}}$ | | 极限运算2 | \displaystyle \lim | `$\displaystyle \lim^{x \to 1}_{y \to 0}{\frac{x}{y}}$` | $\displaystyle \lim^{x \to 1}_{y \to 0}{\frac{x}{y}}$ | | 求和运算1 | \sum | `$\sum^{x \to 0}_{y \to 0}{\frac{x}{y}}$` | $\sum^{x \to 0}_{y \to 0}{\frac{x}{y}}$ | | 求和运算2 | \displaystyle \sum | `$\displaystyle \sum^{x \to 0}_{y \to 0}{\frac{x}{y}}$` | $\displaystyle \sum^{x \to 0}_{y \to 0}{\frac{x}{y}}$ | | 连乘运算1 | \prod | `$\prod^{x \to 0}_{y \to 0}{\frac{x}{y}}$` | $\prod^{x \to 0}_{y \to 0}{\frac{x}{y}}$ | | 连乘运算2 | \displaystyle \prod | `$\displaystyle \prod^{x \to 0}_{y \to 0}{\frac{x}{y}}$` | $\displaystyle \prod^{x \to 0}_{y \to 0}{\frac{x}{y}}$ | | 积分运算1 | \int | `$\int^{1}_{0}{xdx}$` | $\int^{1}_{0}{xdx}$ | | 积分运算2 | \displaystyle \int | `$\displaystyle \int^{1}_{0}{xdx}$` | $\displaystyle \int^{1}_{0}{xdx}$ | | 微分运算 | \partial | `$\frac{\partial x}{\partial y}$` | $\frac{\partial x}{\partial y}$ | | 微分运算2 | | `$\dfrac{\partial x}{\partial y}$` | $\dfrac{\partial x}{\partial y}$ | | 无框矩阵 | \begin{matrix} \end{matrix} | `$\begin{matrix} 1 & 2 \\ 4 & 5\end{matrix}$` | $\begin{matrix} 1 & 2 \\ 4 & 5\end{matrix}$ | | 方括号矩阵 | \begin{bmatrix} \end{bmatrix} | `$\begin{bmatrix} 1 & 2 \\ 4 & 5\end{bmatrix}$` | $\begin{bmatrix} 1 & 2 \\ 4 & 5\end{bmatrix}$ | | 花括号矩阵 | \begin{Bmatrix} \end{Bmatrix} | `$\begin{Bmatrix} 1 & 2 \\ 4 & 5\end{Bmatrix}$` | $\begin{Bmatrix} 1 & 2 \\ 4 & 5\end{Bmatrix}$ | ## 逻辑运算 | 逻辑运算 | 符号 | 示例 | 效果 | | --------------- | ------------ | ---------------------- | -------------------- | | 等于 | = | `$x+y=z$` | $x+y=z$ | | 大于 | > | `$x+y>z$` | $x+y>z$ | | 小于 | < | `$x+y<z$` | $x+y<z$ | | 不等于 | \neq | `$x+y \neq z$` | $x+y \neq z$ | | 不大于 | \not > | `$x+y \not > z$` | $x+y \not > z$ | | 不小于 | \not < | `$x+y \not < z$` | $x+y \not < z$ | | 大于等于 | \geq | `$x+y \geq z$` | $x+y \geq z$ | | 小于等于 | \leq | `$x+y \leq z$` | $x+y \leq z$ | | 不大于等于1 | \ngeq | `$x+y \ngeq z$` | $x+y \ngeq z$ | | 不大于等于2 | \not \geq | `$x+y \not \geq z$` | $x+y \not \geq z$ | | 不小于等于 | \not \leq | `$x+y \not \leq z$` | $x+y \not \leq z$ | | 约等于 | \approx | `$x+y \approx z$` | $x+y \approx z$ | | 恒定等于 | \equiv | `$x+y \equiv z$` | $x+y \equiv z$ | | 不约等于 | \not \approx | `$x+y \not \approx z$` | $x+y \not \approx z$ | | 不恒定等于 | \not \equiv | `$x+y \not \equiv z$` | $x+y \not \equiv z$ | ## 集合运算 | | | | | | ---------- | ------------------ | -------------------- | ------------------ | | 属于 | \in | `$x \in y$` | $x \in y$ | | 不属于 | \notin | `$x \notin y$` | $x \notin y$ | | 不属于2 | \not \in | `$x \not \in y$` | $x \not \in y$ | | 左子集 | \subset | `$x \subset y$` | $x \subset y$ | | 左非子集 | \not \subset | `$x \not \subset y$` | $x \not \subset y$ | | 左真子集 | \subseteq | `$x \subseteq y$` | $x \subseteq y$ | | 左非真子集 | \subsetneq | `$x \subsetneq y$` | $x \subsetneq y$ | | 右子集 | \supset | `$x \supset y$` | $x \supset y$ | | 右非子集 | \not \supset | `$x \not \supset y$` | $x \not \supset y$ | | 右真子集 | \supseteq | `$x \supseteq y$` | $x \supseteq y$ | | 右非真子集 | \supsetneq | `$x \supsetneq y$` | $x \supsetneq y$ | | 并集 | \cup | `$x \cup y$` | $x \cup y$ | | 交集 | \cap | `$x \cap y$` | $x \cap y$ | | 差集 | \setminus | `$x \setminus y$` | $x \setminus y$ | | 同或 | \odot \bigodot | `$x \bigodot y$` | $x \bigodot y$ | | 同或 | | `$x \odot y$` | $x \odot y$ | | 异或 | \otimes \bigotimes | `$x \bigotimes y$` | $x \bigotimes y$ | | 异或 | | `$x \otimes y$` | $x \otimes y$ | | 联结运算 | \bowtie | `$\bowtie$` | $\bowtie$ | | 实数集合 | \mathbb{R} | `$\mathbb{R}$` | $\mathbb{R}$ | | 自然数集合 | \mathbb{Z} | `$\mathbb{Z}$` | $\mathbb{Z}$ | | 空集 | \emptyset | `$\emptyset$` | $\emptyset$ | ## 数学符号 | 数学符号 | 符号 | 示例 | 效果 | | ---------------- | -------- | ------------------------------------------------------------ | ----------------------------------------------------------- | | 无穷 | \infty | `$\infty$` | $\infty$ | | 任意 | \forall | `$\forall$` | $\forall$ | | 存在 | \exists | `$\exists$` | $\exists$ | | 虚数 | \imath | `$\imath$` | $\imath$ | | 虚数 | \jmath | `$\jmath$` | $\jmath$ | | 概率估算 | \hat{a} | `$\hat{a}$` | $\hat{a}$ | | 数学符号 | \bar{a} | `$\bar{a}$` | $\bar{a}$ | | 矢量符号 | \vec{a} | `$\vec{a}$` | $\vec{a}$ | | 一阶导数 | \dot{a} | `$\dot{a}$` | $\dot{a}$ | | 二阶导数 | \ddot{a} | `$\ddot{a}$` | $\ddot{a}$ | | 底端对齐的省略号 | \ldots | `,2,\ldots,n$` | ,2,\ldots,n$ | ## 取整 向上取整 `$\lceil {x} \rceil$` $\lceil {x} \rceil$ 向下取整:`$\lfloor {x} \rfloor$` $\lfloor {x} \rfloor$ ## 函数 `$x = \begin{cases} a \\ b \end{cases}$` $x = \begin{cases} a \\ b \end{cases}$ `$x = \begin{cases} a &\text{if } b \\\ c &\text{if } d \end{cases}$` $x = \begin{cases} a &\text{if } b \\ c &\text{if } d \end{cases}$ ## 带框 `$\text{\boxed{hello}}$` $\text{\boxed{hello}}$ ## 粗体 `$\bold{hello}$` $\bold{hello}$ ## 波浪线 `\sim` $\sim$ <hr> [更多示例](https://katex.org/docs/support_table.html) [在线编辑公式](https://www.codecogs.com/latex/eqneditor.php?lang=zh-cn) [一些数学符号公式和字母](https://blog.csdn.net/cui_yonghua/article/details/119382580)