SciTech-Mathmatics-Markdown:List 嵌入 code block + LaTex: 论文写作、排版与使用 + 数学公式的输入方式
民主与共和
更好的共和度保障更高级的民主, 是因为 民主 与 共和 是统一的。
平衡态的“跃迁”是需要“吸收足够能量”, "改变"总是需要"成本"的。
在正确的方向上,每一天的学习是“质变飞跃”的必要。
Markdown: List 嵌入 code block
Code is possible in markdown (see here) - you just have to leave a blank line and then indent by 8 spaces as a minimum.
The text below:
* example
this.isSomeCode = true;
*
addMoreCode();
will generate this:
-
example
this.isSomeCode = true;
-
addMoreCode();
LaTeX:从入门到日常使用
发表于2022-02-05 | 更新于2022-03-20 | 教程 |字数总计:3.6k | 阅读时长:12分钟 |阅读量:
前言:排版 与 书写 的讨论
LaTeX是一种“非所见即所得”的排版系统,用户需要输入特定的代码,保存在后缀为.tex的文件,通过编译得到所需的pdf文件,例如以下代码:
\documentclass{article}
\begin{document}
Hello, world!
\end{document}
输出的结果是一个pdf文件,内容是“Hello, world!”。
类比, 假设使用 Word 排版是驾驶汽车, 那么使用LaTeX进行排版, 就像驾驶飞机。
使用LaTeX是更高层级的自由,因为其强规范性的保障。
这使LaTeX非常适合论文排版。在学习的过程, 将会深刻感受到这一点。
无论是 LaTeX 还是 Word,其本质都是用来 排版,
另外, 笔者最建议的书写格式是Markdown,其书写格式独立于排版,
也支持使用 LaTeX语法 输入公式,与LaTeX之间的转换非常方便。
准备工作:安装LaTeX与配置
安装Tex Live
官方地址 http://mirror.ctan.org/systems/texlive/Images/texlive2021.iso
以下是一些镜像地址:
清华大学 北京交通大学 上海交通大学 中科大 重庆大学 腾讯云
其中的iso文件可以使用压缩软件解压, 或加载到光盘, 接下来直接安装就行。
其他操作系统的用户(如MacOS),可参考TeX Live 下载及安装说明 | (liam.page)的方法.
选择TeX编辑器
对于初学, 最推荐的编辑器是TeXworks, 也避免配置带来的问题。
要提高效率, 可以选用:
- TeXstudio,安装地址为: TeXstudio - A LaTeX editor (sourceforge.net);
- Visual Studio Code,这是笔者最建议的TeX编辑器,不过需要配置LaTeX,较麻烦;
- 另外有在线的编辑器,如Overleaf, 在线LaTeX编辑器。
选择pdf阅读器和编辑器
LaTeX编译的结果是pdf文件,建议选用专业的pdf阅读器或pdf编辑器。
特别是在阅读beamer类型文件时,不同的阅读器效果差别极大。在这里推荐Acrobat:
- Adobe Acrobat Reader, 免费, 可查看、签署、协作处理和批注 PDF 文件,
安装地址为: Adobe Acrobat Reader; - Adobe Acrobat Pro,付费,可用于创建、保护、转换和编辑 PDF文件,
安装地址为: Adobe Acrobat | Adobe Document Cloud。
利用LaTeX编写文档
文档类型
TeX有多种文档类型可选,笔者较常用的有如下几种类型:
- 对于英文,可以用
book
、article
和beamer
; - 对于中文,可以用
ctexbook
、ctexart
和ctexbeamer
,
这些类型自带了对中文的支持。
不同的文件类型,编写的过程中也会有一定的差异,如果直接修改文件类型的话,甚至会报错。
以下统一选用ctexart
。在编辑框第一行,输入如下内容来设置文件类型:
\documentclass{ctexart}
另外,一般也可以在\documentclass
处设置基本参数,
笔者通常设置默认字体大小为12pt,纸张大小为A4,单面打印。
需要将第一行的内容替换为:
\documentclass[12pt, a4paper, oneside]{ctexart}
文件的正文部分需要放入document
Environment,在document
Environment外的部分不会出现在文件。
\documentclass[12pt, a4paper, oneside]{ctexart}
\begin{document}
这里是正文.
\end{document}
Macro Package
为了完成一些功能(如定理Environment),还需要在导言区,也即document
Environment之前加载宏包。
- 加载宏包的代码是`usepackage{}`。
本教程,数学公式
与定理Environment
有关的宏包为amsmath
、amsthm
、amssymb
,- 图片插入的宏包为
graphicx
,
- 代码如下:
\usepackage{amsmath, amsthm, amssymb, graphicx}
加载宏包时
还可以设置基本参数
,如使用超链接宏包hyperref
,可以设置引用的颜色为黑色等,代码如下:
\usepackage[bookmarks=true, colorlinks, citecolor=blue, linkcolor=black]{hyperref}
Title
\title{}
设置 标题,
\author
设置 作者,
\date{}
设置 日期,
要使用\maketitle
才能在文档显示标题信息
,
这些都需要放在导言区
。例如:
\documentclass[12pt, a4paper, oneside]{ctexart}
\usepackage{amsmath, amsthm, amssymb, graphicx}
\usepackage[bookmarks=true, colorlinks, citecolor=blue, linkcolor=black]{hyperref}
% 导言区
\title{我的第一个\LaTeX 文档}
\author{统计91董晟渤}
\date{\today}
\begin{document}
\maketitle
这里是正文.
\end{document}
正文
正文直接在document
Environment书写,没有必要加入空格来缩进, 因为文档默认会进行首行缩进。
- Page: 另起一页的方式是:
\newpage
- Paragraph 段落:
- 两邻行在编译时仍然会视为同一段落.
- 另起一段的方式是使用一行分隔;如下代码,编译出来就是两个段落:
我是第一段.
我是第二段.
- 正文部分多余的空格、回车等等都会被自动忽略;
这保证, 全文排版不会突然多出一行, 或者多出一个空格。 - 标点符号: 笔者为保证美观,通常将中文标点符号替换为英文标点符号,
需要注意的是英文标点符号后面还有一个空格,这特别适合数学类型的文档。 - 正文设置局部的特殊字体:
字体 命令
直立 \textup{}
意大利 \textit{}
倾斜 \textsl{}
小型大写 \textsc{}
加宽加粗 \textbf{}
Chapt 章节
对ctexart
文件类型,章节可用\section{}
和\subsection{}
来标记, 例如:
\documentclass[12pt, a4paper, oneside]{ctexart}
\usepackage{amsmath, amsthm, amssymb, graphicx}
\usepackage[bookmarks=true, colorlinks, citecolor=blue, linkcolor=black]{hyperref}
% 导言区
\title{我的第一个\LaTeX 文档}
\author{统计91董晟渤}
\date{\today}
\begin{document}
\maketitle
\section{一级标题}
\subsection{二级标题}
这里是正文.
\subsection{二级标题}
这里是正文.
\end{document}
TOC(Table of Contents)目录
在有了章节的结构之后,使用\tableofcontents
命令就可以在指定位置生成目录。
通常带有目录的文件需要编译两次,因为需要先在目录生成.toc
文件,再据此生成目录。
\documentclass[12pt, a4paper, oneside]{ctexart}
\usepackage{amsmath, amsthm, amssymb, graphicx}
\usepackage[bookmarks=true, colorlinks, citecolor=blue, linkcolor=black]{hyperref}
% 导言区
\title{我的第一个\LaTeX 文档}
\author{统计91董晟渤}
\date{\today}
\begin{document}
\maketitle
\tableofcontents
\section{一级标题}
\subsection{二级标题}
这里是正文.
\subsection{二级标题}
这里是正文.
\end{document}
图片
插入图片需要使用graphicx
宏包,建议使用如下方式:
\begin{figure}[htbp]
\centering
\includegraphics[width=8cm]{图片.jpg}
\caption{图片标题}
\end{figure}
注释:
[htbp]
: 是自动选择插入图片的最优位置,
\centering
: 图片居中,
[width=8cm]
: 图片的宽度为8cm
,
\caption{}
: 图片的标题。
表格
LaTeX 表格插入较麻烦, 直接使用 Create LaTeX tables online 来生成。
建议使用如下方式:
\begin{table}[htbp]
\centering
\caption{表格标题}
\begin{tabular}{ccc}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{tabular}
\end{table}
列表
LaTeX的列表Environment包含 无序列表itemize
、有序列表enumerate
和描述description
,
以enumerate
为例,用法如下:
\begin{enumerate}
\item 这是第一点;
\item 这是第二点;
\item 这是第三点.
\end{enumerate}
另外,也可以自定义\item
的样式:
\begin{enumerate}
\item[(1)] 这是第一点;
\item[(2)] 这是第二点;
\item[(3)] 这是第三点.
\end{enumerate}
Theory Environment
-
Theory Environment需要使用
amsthm
宏包,
首先在导言区
加入:\newtheorem{theorem}{定理}[section]
注释:
{theorem}
是Environment的名称
,
{定理}
设置了该Environment显示的名称
是“定理
”,
[section]
的作用是让theorem
Environment在每个section
有单独编号
。 -
在
正文加入一条定理
(注意:[定理名称]
不是必须的):\begin{theorem}[定理名称] 这里是定理的内容. \end{theorem}
-
建立新Theory Environment:
要 新Theory Environment 和theorem
Environment 一起计数, 可如下:\newtheorem{theorem}{定理}[section] \newtheorem{definition}[theorem]{定义} \newtheorem{lemma}[theorem]{引理} \newtheorem{corollary}[theorem]{推论} \newtheorem{example}[theorem]{例} \newtheorem{proposition}[theorem]{命题}
-
定理的证明可以直接用
proof
Environment。
Page 页面
-
Page Size(页面大小): 选择文件类型时, 设置的
页面大小
是a4paper
,
也可以修改页面大小为b5paper
等等。 -
Page Margin(页边距): LaTeX 默认的页边距很大,
为让每一页显示内容更多, 用geometry
宏包,并在导言区
加入以下代码:\usepackage{geometry} \geometry{left=2.54cm, right=2.54cm, top=3.18cm, bottom=3.18cm}
-
Line Space(行间距): 使用如下代码:
\linespread{1.5}
-
Page Number(页号)
-
默认的页号编码方式是阿拉伯数字,用户也可以自己设置为
小写罗马数字
:
\pagenumbering{roman}
另外:
aiph
表示小写字母,Aiph
表示大写字母,
Roman
表示大写罗马数字,arabic
表示默认的阿拉伯数字
。 -
设置页号从0开始:
\setcounter{page}{0}
-
数学公式的输入方式
行内公式
只要是公式,就需要放入Equation Environment
。
Equation Environment
通常使用特殊的字体
,并且默认为斜体
。
行内公式
通常使用$..$
来输入,这通常被称为Equation
,例如:
若 $a>0$, $b>0$, 则$a+b>0$.
如果要在行内公式
展现出行间公式
的效果,可以在前面加入\displaystyle
,例如
设$\displaystyle\lim_{n\to\infty}x_n=x$
行间公式
行间公式
也是正文的一部分
,需要与正文连贯,并且加入标点符号。
行间公式
需要用$$..$$
来输入,笔者习惯的输入方式如下:
if $a>0$, $b>0$, then
$$
a+b>0.
$$
这种输入方式的一个好处是,这同时也是Markdown
的语法。
输入方式,可以参考: 在线LaTeX公式编辑器-编辑器 (latexlive.com),
上下结构
上方: \overset{OverContent}{MainContent}
下方: \underset{UnderContent}{MainContent}
$\large \begin{array}{*} \\
\underset{i=1}{ \overset{i=n}{ \lim { \text{text} } } } \\
\end{array}$
效果:
$\large \begin{array}{*} \\
\underset{i=1}{ \overset{\infty}{\lim}} {\text{text}},\ \underset{i=1}{ \overset{\infty}{\bigcup}} {A_{i}}, \\
\end{array}$
效果:
更多参考: Over(\overset) and Under(\underset):
上下标
上标
可以用^
输入,例如a^n
,效果为
下标
可以用_
来输入,例如a_1
,效果为
上下标只会读取第一个字符
,如果上下标的内容超过一个字符,要改成^{}
或_{}
。
分式
- 分式(正常)
\dfrac{}{}
: 例如\dfrac{a}{b}
, 效果为: - 小分式
\frac{}{}
: 例如a^\frac{1}{n}
,效果为
括号
- 括号: 可以直接用
(..)
输入; - 高括号: 有时候括号的
内容高度较高
, 改用\left(..\right)
。
例如:\left(1+\dfrac{1}{n}\right)^n
,效果是 。 - 中间要隔开时用
\left( .. \middle| .. \right)
- 大括号
{}
: 要用\{..\}
,注意:\
起到转义作用
。
等号
$\large K_1 \approx {s_1}, K_2 \equiv {s_2, s_3, s_4} $
\approx
: is used mostly for the approximate (read: calculated) value of a mathematical expression like\cong
: is used to show a congruency between two mathematical expressions, which could be geometrical, topological, and when using modulo arithmetic you can get different numbers that are congruent, e.g., (although this is also written as ). In LaTeX it is coded as \cong.\sim
: is a similarity in geometry and can be used to show that two things are asymptotically equal (they become more equal as you increase a variable like ). This is a weaker statement than the other two.\simeq
: is more of a grab-bag of meaning. which means "similar equal" so it can be either, which might be appropriate in a certain situations.
加粗
对于加粗的公式,建议使用bm宏包
,并且用命令\bm{}
来加粗,这可以保留公式的斜体。
大括号
- How do I get curly braces to show in math mode?
-
Q: When I write this:
the braces disappear in the output. -
A: You need to escape the braces like
\{ ... \}
.- But, as the contents inside the braces may vary in size,
it would be better to use theDeclarePairedDelimiter
command from themathtools
package:
\DeclarePairedDelimiter\set\{\}
This defines a\set{…}
command, which accepts an optional argument:\big
,\Big
,\bigg
, or\Bigg
,
which implicitly adds a pair of\bigl
…\bigr
, &c. in front of the braces. Example:\set[\big]{...}
- A
\set*{…}
variant becomes available, which adds implicitly a pair of\left…\right
.
- But, as the contents inside the braces may vary in size,
-
Example:
\begin{gather*} c \colon \{1, \dots, n\} \rightarrow \{1, \dots, n\} \text{ such that} \\ \begin{cases} c(a_i) = a_{i+1} & \text{for }1\le i<l \\ c(a_l) = a_1 \end{cases} \end{gather*}
-
- Some comments:
-
Use the
cases
environment, provided by theamsmath
package,
to place aleft curly brace
ahead of two or more expressions. -
Don't use
...
to create a typographicalellipsis
; instead, use\dots
. -
Use the
\text{ }
command to write text material inside mathematical expressions. -
As pointed out in the comments by @SvendTveskæg and @daleif,
it's better (typographically speaking) to use the command\colon
instead of:
. -
if you need the
left-hand curly brace
tospan all three rows
,
you could do so with the following code:( Observe, though,
this code doesn't make full use of the capabilities of thecases
;
for sure, one could replace\begin{cases} ... \end{cases}
with a more basic,
\left\{\begin{array}{@{}l} ... \end{array}\right.
construct.):\begin{equation*} \begin{cases} c \colon \{1, \dots, n\} \rightarrow \{1, \dots, n\} \text{ such that}\\ c(a_i) = a_{i+1} \text{ for $1\le i<l$}\\ c(a_l) = a_1 \end{cases} \end{equation*}
-
也可以使用
cases
Environment,可用于分段函数
或者方程组
,例如$$ f(x)=\begin{cases} x, & x>0, \\ -x, & x\leq 0. \end{cases} $$ 效果是:
多行公式
多行公式通常使用aligned
Environment,例如
$$
\begin{aligned}
a & =b+c \\
& =d+e
\end{aligned}
$$
效果是:
Set Operations(集合运算)
notation and their Latex Code
This table serves as a quick reference for common set notations and their LaTeX representations, aiding in the effective communication of mathematical concepts.
Proper Superset | \supset | ||
Element | \in | ||
Not an Element | \notin | ||
Union | \cup | ||
Intersection | \cap | ||
Complement | \complement | ||
Set Difference | \setminus | ||
Power Set | \wp | ||
Cartesian Product | \times | ||
Cardinality | |A|, \aleph_{\omicron},c | ||
Set Builder Notation | \ | ||
Set Membership Predicate | P(x) \in A | ||
Set Minus | A - B | ||
Set Inclusion Predicate | A \subseteq B | ||
Set Equality | A = B | ||
Disjoint Sets | A \cap B = \emptyset | ||
Subset Not Equal to | A \subsetneq B | ||
Superset Not Equal to | A \supsetneq B | ||
Symmetric Difference | A \triangle B | ||
Subset of or Equal to | A \subseteq B | ||
Proper Subset of to | A \subset B | ||
Cartesian Power | A^ | ||
Union of Sets | \bigcup A_i | ||
Intersection of Sets | \bigcap A_i | ||
Cartesian Product of Sets | \times A_i | ||
Set of All Functions from A to B | B^ | ||
Set of All Relations from A to B | A \times B |
Ending
这个教程耐心学习完后,能满足日常使用的需求。
LaTeX的使用还需要一定的熟练度,仍有时间的读者还可以考虑:
- 试着用
LaTeX
抄几页书籍, 或者写几页文章,增加熟练度; - 配置
Visual Studio Code
上的LaTeX
,探索效率更高的编辑器; - 研究如何美化排版,或是使用网络上的精美模板,让排版的效果更好。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY