博客文章头图

Katex 使用指南

1917 字
4 分钟
Markdown
Katex

常用符号的代码

1.上下标,正负无穷

数学表达式 LaTeX代码
$x^2$ x^2
$y_1$ y_1
$\infty$ \infty
$-\infty$ -\infty

2.加减乘,分式,根号,省略号

数学表达式 LaTeX代码
$a+b-c*d$ a+b-c*d
$a \div b$ a\div{b}
$a\pm{b}$ a\pm{b}
$\frac{a}{b}$ \frac{a}{b}
$\sqrt{b}$ \sqrt{b}
$\cdots$ \cdots

3.三角函数

数学表达式 LaTeX代码
$\sin{\theta}$ \sin{\theta}
$\cos{\theta}$ \cos{\theta}
$\tan{\theta}$ \tan{\theta}
$\cot{\theta}$ \cot{\theta}

4.矢量,累加累乘,极限

数学表达式 LaTeX代码
$\vec{F}$ \vec{F}
$\sum_{i=1}^{n}{a_i}$ \sum_{i=1}^{n}{a_i}
$\prod_{i=1}^{n}{a_i}$ \prod_{i=1}^{n}{a_i}
$\lim_{a\rightarrow+\infty}{a+b}$ \lim_{a\rightarrow+\infty}{a+b}

5.希腊字母

数学表达式 LaTeX代码
$\alpha$ \alpha
$\beta$ \bata
$\gamma$ \gamma
$\delta$ \delta
$\epsilon$ \epsilon
$\varepsilon$ \varepsilon
$\eta$ \eta
$\theta$ \theta
$\kappa$ \kappa
$\iota$ \iota
$\zeta$ \zeta
$\lambda$ \lambda
$\mu$ \mu
$\phi$ \phi
$\pi$ \pi
$\rho$ \rho
$\xi$ \xi
$\nu$ \nu
$\upsilon$ \upsilon
$\varphi$ \varphi
$\chi$ \chi
$\psi$ \psi
$\omega$ \omega

6.关系运算符

数学表达式 LaTeX代码
\leq \leq
\geq \geq

矩阵

1.简单矩阵

使用\begin{matrix}…\end{matrix}生成, 每一行以\\结尾表示换行,元素间以&间隔,式子的表示序号\tag{1}(右边的序号)。

$$ \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \tag{1} $$

$$
\begin{matrix}
1 & 2 & 3 \\\\
4 & 5 & 6 \\\\
7 & 8 & 9 
\end{matrix} \tag{1}
$$

2.带左右括号的矩阵(大中小括号)

方法一:在\begin{}之前和\end{}之后添加左右括号的代码。

大括号:

$$ \left\{ \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right\} \tag{2} $$

$$
\left\{
\begin{matrix}
1 & 2 & 3 \\\\
4 & 5 & 6 \\\\
7 & 8 & 9
\end{matrix}
\right\} \tag{2}
$$

中括号:

$$ \left[ \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right] \tag{3} $$

$$
\left[
\begin{matrix}
1 & 2 & 3 \\\\
4 & 5 & 6 \\\\
7 & 8 & 9
\end{matrix}
\right] \tag{3}
$$

小括号:

$$ \left( \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right) \tag{4} $$

$$
\left(
\begin{matrix}
1 & 2 & 3 \\\\
4 & 5 & 6 \\\\
7 & 8 & 9
\end{matrix}
\right) \tag{4}
$$

方法二:改变\begin{matrix}\end{matrix}{matrix}

大括号:

$$ \begin{Bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{Bmatrix} \tag{6} $$

$$
\begin{Bmatrix}
1 & 2 & 3 \\\\
4 & 5 & 6 \\\\
7 & 8 & 9
\end{Bmatrix} \tag{6}
$$

中括号:

$$ \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix} \tag{6} $$

$$
\begin{bmatrix}
1 & 2 & 3 \\\\
4 & 5 & 6 \\\\
7 & 8 & 9
\end{bmatrix} \tag{6}
$$

3.包含希腊字母与省略号**

行省略号\cdots,列省略号\vdots,斜向省略号(左上至右下)\ddots

$$ \left\{ \begin{matrix} 1 & 2 & \cdots & 5 \\ 6 & 7 & \cdots & 10 \\ \vdots & \vdots & \ddots & \vdots \\ \alpha & \alpha+1 & \cdots & \alpha+4 \end{matrix} \right\} $$

$$
\left\{
\begin{matrix}
1      & 2        & \cdots & 5        \\\\
6      & 7        & \cdots & 10       \\\\
\vdots & \vdots   & \ddots & \vdots   \\\\
\alpha & \alpha+1 & \cdots & \alpha+4 
\end{matrix}
\right\}
$$

公式序号

见“矩阵”小节,代码最后的一行即表示右端序号

......
\tag{6}

行列式

行列式相关语法与矩阵类似

$$ \begin{vmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{vmatrix} \tag{7} $$

$$
\begin{vmatrix}
1 & 2 & 3 \\\\
4 & 5 & 6 \\\\
7 & 8 & 9
\end{vmatrix}
\tag{7}
$$

表格

1.简易表格**

$$ \begin{array}{|c|c|c|} \hline 2 & 9 & 4 \\ \hline 7 & 5 & 3 \\ \hline 6 & 1 & 8 \\ \hline \end{array} $$

$$
\begin{array}{|c|c|c|}
\hline 2 & 9 & 4 \\\\
\hline 7 & 5 & 3 \\\\
\hline 6 & 1 & 8 \\\\
\hline
\end{array}
$$

开头结尾\begin{array}\end{array}

定义式:例:{|c|c|c|},其中c l r 分别代表居中、左对齐及右对齐。

分割线

  1. 竖直分割线:在定义式中插入 |, (||表示两条竖直分割线)。
  2. 水平分割线:在下一行输入前插入 \hline,以下图真值表为例。

其他:每行元素间均须要插入 & ,每行元素以 \\ 结尾。

2.真值表

$$ \begin{array}{cc|c} A&B&F\\ \hline 0&0&0\\ 0&1&1\\ 1&0&1\\ 1&1&1\\ \end{array} $$

$$
\begin{array}{cc|c}
A & B & F \\\\
\hline 0 & 0 & 0 \\\\
0 & 1 & 1 \\\\
1 & 0 & 1 \\\\
1 & 1 & 1 \\\\
\end{array}
$$

多行等式对齐

$$ \begin{aligned} a &= b + c \\ &= d + e + f \end{aligned} $$

$$
\begin{aligned}
a &= b + c \\\\
&= d + e + f
\end{aligned}
$$

方程组、条件表达式

方程组:

$$ \begin{cases} 3x + 5y + z \\ 7x - 2y + 4z \\ -6x + 3y + 2z \end{cases} $$

$$
\begin{cases}
3x + 5y +  z \\\\
7x - 2y + 4z \\\\
-6x + 3y + 2z
\end{cases}
$$

同理,条件表达式:

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

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

间隔 (大小空格、紧贴)

紧贴 + 无空格 + 小空格 + 中空格 + 大空格 + 真空格 + 双真空格 $$ a\!b + ab + a\,b + a\;b + a\ b + a\quad b + a\qquad b $$

$$
a\\!b + ab + a\\,b + a\\;b + a\\ b + a\\quad b + a\\qquad b
$$

紧贴\!

无空格 小空格\, 中空格\; 大空格\

真空格\quad 双真空格\qquad

通过Python生成LaTeX表达式

step1:安装latexify-py模块

step2:编写代码

import math         //引入数学模块(有些运算的函数需要)
import latexify     //引入latexify模块

@latexify.with_latex  //特定语法,表示之后定义的函数可以转化为LaTeX代码
def f(x,y,z):         //包含的参数
pass              //此处填写可能需要的数学表达式
return result     //也可以直接体现数学关系

print(f)              //直接print(函数名)

step3:在输出区得到需要的LaTeX数学表达式

特别说明,生成的表达式为定义式,即如果只需要等式,可以把生成表达式中的\triangleq改成=

参考资料

  • 使用Typora添加数学公式(https://blog.csdn.net/mingzhuo_126/article/details/82722455)
  • [CSDN_Markdown] 使用LaTeX写矩阵(https://blog.csdn.net/bendanban/article/details/44221279)
  • Markdown下的LaTeX公式笔记 (https://www.bilibili.com/read/cv1578688/)
  • typora行内公式插入(https://www.zhihu.com/answer/809450524)
本站内容采用 CC BY-NC-SA 4.0 许可,请注明出处;商业转载请联系作者授权。