LaTex语法与实例
<font size=4>前言:最近没课在看一些书,博客搭好了所以想写一些笔记/分享,但是发现公式的编辑很是一个问题,怎样才能用比较简单快速的方法编辑出美观规范的数学公式呢?语法+工具</font>
1.配置hexo-math插件
我使用的是NexT主题,对于大多数主题来说,推荐可以使用hexo-math插件来完成对LaTex公式的渲染。只需一步即可完成:
$ npm install hexo-math --save
是不是很省心~
2.常用LaTex语法
在这里我按照现有的文档总结了几个实用的LaTex语法:
段落处理
操作 | 方式 |
---|---|
空格 | 不起作用 |
换行 | \ |
分段 | \par |
换页 | \newpage |
西文字符转换表
实用为主,不赘述,可以用工具完成,工具下面会介绍
字号转换命令表
中文字号 | 控制命令 |
---|---|
一号 | \Huge |
二号 | \huge |
三号 | \LARGE |
四号 | \Large |
小四号 | \large |
五号 | \normalsize |
小五号 | \small |
六号 | \footnotesize |
小六号 | \scriptsize |
页面控制命令
系统默认:字号10pt= 五号字;西文字体为罗马字体;textwidth=12.2cm,textheight=18.6cm。相当于美国标准信纸大小。
可以通过以下操作改变页面尺寸:
\textwidth=
\textheight=
3.LaTex 公式渲染与 Markdown 渲染冲突问题
如LaTex 中的下划线_
就会出现解析错误。解决方法有很多,这里介绍两种:
- 将LaTex 语法公式中的所有
_
加反斜线\
转义,即\_
可以解析成功。
但是,这样的方式将导致所有的下标都修改一遍。 - 将公式前后的一对
$
分别换成{% math %}和{% endmath %}。
这种的方法实例将在5中给出。
4.在线LaTex编辑器
即使掌握了LaTex语法,但是编辑公式仍然是费时费力的,这里推荐在线LaTex编辑器,可以实现实时预览功能的同时还提供了图形辅助操作,节省了记忆和查询语法的时间。相信你在第一眼看到它的时候就会用啦~
但是,最基本的语法还是要掌握的,工具不是万能的,有些生僻的格式还需要语法知识,相辅相成嘛。
OK,用下面展示一些常用的代码实例。
5.常用公式代码实例
上下标
{% math %}
\begin{aligned}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
\dot{x} & = \sigma(y-x) \
\dot{y} & = \rho x - y - xz \
\dot{z} & = -\beta z + xy
\end{aligned}
{% endmath %}
积分与求和
{% math %}
\begin{aligned}
\sum_{i=1}^{n}x_{i}=\int_{0}^{1}f(x)\mathrm{d}x
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
\sum_{i=1}{n}x_{i}=\int_{0}{1}f(x)\mathrm{d}x
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
\sum_{
1\leqslant i\leq n \atop
1\leqslant j\leq n
}a_{ij}
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
\sum_{
1\leqslant i\leq n \atop
1\leqslant j\leq n
}a_{ij}
\end{aligned}
{% endmath %}
极限
{% math %}
\begin{aligned}
\lim_{n \to \infty }\sin x_{n}=0
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
\lim_{n \to \infty }\sin x_{n}=0
\end{aligned}
{% endmath %}
根式
{% math %}
\begin{aligned}
x=\sqrt[m]{1+x^{p}}
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
x=\sqrt[m]{1+x^{p}}
\end{aligned}
{% endmath %}
绝对值
{% math %}
\begin{aligned}
\left | a+b \right |=\coprod_{m}^{n} \frac{e}{f}
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
\left | a+b \right |=\coprod_{m}^{n} \frac{e}{f}
\end{aligned}
{% endmath %}
矩阵
{% math %}
\begin{aligned}
\begin{pmatrix}
1 & 3 & 5 \\
2 & 4 & 6
\end{pmatrix}
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
\begin{pmatrix}
1 & 3 & 5 \
2 & 4 & 6
\end{pmatrix}
\end{aligned}
{% endmath %}
花括号
{% math %}
\begin{aligned}
\overbrace{a+b+\cdots +y+z}^{26}_{=\alpha +\beta}
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
\overbrace{a+b+\cdots +y+z}^{26}_{=\alpha +\beta}
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
a+\underbrace{b+\cdots +y}_{24}+z
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
a+\underbrace{b+\cdots +y}_{24}+z
\end{aligned}
{% endmath %}
堆砌
{% math %}
\begin{aligned}
y\stackrel{\rm def}{=} f(x) \stackrel{x\rightarrow 0}{\rightarrow} A
\end{aligned}
{% endmath %}
{% math %}
\begin{aligned}
y\stackrel{\rm def}{=} f(x) \stackrel{x\rightarrow 0}{\rightarrow} A
\end{aligned}
{% endmath %}