SciTech-Mathmatics-Markdown:List 嵌入 code block + LaTex: 论文写作、排版与使用 + 数学公式的输入方式

民主与共和

更好的共和度保障更高级的民主, 是因为 民主共和 是统一的。
平衡态的“跃迁”是需要“吸收足够能量”, "改变"总是需要"成本"的。
在正确的方向上,每一天的学习是“质变飞跃”的必要。


Markdown: 嵌入 视频链接

在GitHub上嵌入视频可以通过两种方式实现:使用YouTube视频链接 或 使用GitHub Pages来托管视频文件。

一、使用YouTube视频链接

首先,在YouTube上上传或者获取想要嵌入到GitHub的视频的链接。
其次,在GitHub上打开要嵌入视频的Markdown文件。使用以下格式将视频嵌入后提交git commit & push:

[![视频名称](视频缩略图链接)](视频链接)

例如:

[![GitHub视频1](https://img.youtube.com/vi/视频ID/0.jpg)](https://www.youtube.com/watch?v=视频ID)

注意:

  • 视频名称 可以根据实际情况进行修改,
  • 视频缩略图链接可以使用视频的封面图链接,
  • 视频链接为在YouTube上的视频链接。

二、使用GitHub Pages托管视频文件

首先,将视频文件上传到GitHub仓库,可以将视频文件直接拖拽到Github项目文件夹。
其次,在GitHub上打开要嵌入视频的Markdown文件。并使用以下格式将视频嵌入后提交git commit & push:

  • "视频文件路径" 为相对于Markdown文件的视频文件路径。

需要注意的是,GitHub对于视频的播放和格式支持有一定限制。

  • 视频文件不能超过100MB,
  • 并且仅支持一些常见的视频格式,如MP4、AVI和MOV。
  • 嵌入完成,记得"git commit & push"

确保你的视频文件符合这些要求,以便正确地在GitHub上进行嵌入和播放。



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, 也避免配置带来的问题。
要提高效率, 可以选用:

选择pdf阅读器和编辑器

LaTeX编译的结果是pdf文件,建议选用专业的pdf阅读器或pdf编辑器。
特别是在阅读beamer类型文件时,不同的阅读器效果差别极大。在这里推荐Acrobat:

利用LaTeX编写文档

文档类型

TeX有多种文档类型可选,笔者较常用的有如下几种类型:

  • 对于英文,可以用bookarticlebeamer
  • 对于中文,可以用 ctexbookctexartctexbeamer
    这些类型自带了对中文的支持。

不同的文件类型,编写的过程中也会有一定的差异,如果直接修改文件类型的话,甚至会报错。
以下统一选用ctexart。在编辑框第一行,输入如下内容来设置文件类型:
\documentclass{ctexart}

另外,一般也可以在\documentclass处设置基本参数,
笔者通常设置默认字体大小为12pt,纸张大小为A4,单面打印。
需要将第一行的内容替换为:
\documentclass[12pt, a4paper, oneside]{ctexart}

文件的正文部分需要放入document Environment,在documentEnvironment外的部分不会出现在文件。

\documentclass[12pt, a4paper, oneside]{ctexart}
\begin{document}

这里是正文. 

\end{document}

Macro Package

为了完成一些功能(如定理Environment),还需要在导言区,也即documentEnvironment之前加载宏包。

  • 加载宏包的代码是`usepackage{}`。
    本教程,
    • 数学公式定理Environment有关的宏包为 amsmathamsthmamssymb
    • 图片插入的宏包为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}



正文

正文直接在documentEnvironment书写,没有必要加入空格来缩进, 因为文档默认会进行首行缩进

  • 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] 的作用是让theoremEnvironment在每个section单独编号

  • 正文加入一条定理(注意: [定理名称]不是必须的):

      \begin{theorem}[定理名称]
       这里是定理的内容. 
        \end{theorem}
    
  • 建立新Theory Environment:
    新Theory EnvironmenttheoremEnvironment 一起计数, 可如下:

      \newtheorem{theorem}{定理}[section]
      \newtheorem{definition}[theorem]{定义}
      \newtheorem{lemma}[theorem]{引理}
      \newtheorem{corollary}[theorem]{推论}
      \newtheorem{example}[theorem]{例}
      \newtheorem{proposition}[theorem]{命题}
    
  • 定理的证明可以直接用proofEnvironment。

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}


Logic & Inference(逻辑推理)

Cause-Effect:

  • \because: \(\because\)
  • \therefore: \(\therefore\)

Arrows(Relational Operator and their Latex Code) :

TERM LATEX CODE SYMBOL
Left Arrow \leftarrow $ \leftarrow $
Right Arrow \rightarrow $ \rightarrow $
Up Arrow \uparrow $\uparrow $
Down Arrow \downarrow $ \downarrow $
Left Right Arrow \leftrightarrow $ \leftrightarrow $
Up Down Arrow \updownarrow $\updownarrow $
North West Arrow \nwarrow $ \nwarrow $
North East Arrow \nearrow $ \nearrow $
South West Arrow \swarrow $\swarrow $
South East Arrow \searrow $\searrow $
Long Right Arrow \longrightarrow $\longrightarrow $
Double Right Arrow \Rightarrow $\Rightarrow $
Right Harpoon Up \rightharpoonup $ \rightharpoonup $
  • \leftarrow \ \rightarrow \ \uparrow \ \downarrow : $ \leftarrow \ \rightarrow \ \uparrow \ \downarrow $
  • \Leftarrow \ \Rightarrow \ \Uparrow \ \Downarrow : $ \Leftarrow \ \Rightarrow \ \Uparrow \ \Downarrow $
  • \leftharpoonup \rightharpoonup \leftharpoondown \rightharpoondown : $ \leftharpoonup \rightharpoonup \leftharpoondown \rightharpoondown $



数学公式的输入方式

行内公式

只要是公式,就需要放入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{i=n}{\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}$

效果:\(\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^n $;
下标可以用_来输入,例如a_1,效果为 $ a_n $。
上下标只会读取第一个字符,如果上下标的内容超过一个字符,要改成^{}_{}

分式

  • 分式(正常)\dfrac{}{}: 例如\dfrac{a}{b}, 效果为: $ \dfrac{a}{b}$
  • 小分式\frac{}{}: 例如a^\frac{1}{n},效果为$ a^\frac{1}{n}$

括号

Type LaTeX markup LaTeX markup
for Multiple-line
Renders as
Parentheses; round brackets (x+y) $ $
Brackets; square brackets [x+y] $ $
Curly Brackets \{ \} $ $
Pipes; vertical bars ` x+y `
Double pipes |x+y| $ $
Angle brackets \langle \alpha_1, \alpha_2, \cdots, \alpha_n \rangle $ \langle \alpha_1, \alpha_2, \cdots, \alpha_n \rangle $
LaTeX markup Renders as
\bigl( \Bigl( \biggl( \Biggl( $ {\big (}{\Big (}{\bigg (}{\Bigg (} $
\bigr] \Bigr] \biggr] \Biggr] $ {\big ]}{\Big ]}{\bigg ]}{\Bigg ]} $
\bigl\{ \Bigl\{ \biggl\{ \Biggl\{ $ {\big {}{\Big {}{\bigg {}{\Bigg {} $
\bigl \langle \Bigl \langle \biggl \langle \Biggl \langle $ {\big \langle }{\Big \langle }{\bigg \langle }{\Bigg \langle } $
\bigr \rangle \Bigr \rangle \biggr \rangle \Biggr \rangle $ {\big \rangle}{\Big \rangle}{\bigg \rangle}{\Bigg \rangle} $
`\big \Big
\big| \Big| \bigg| \Bigg| $ \big| \Big| \bigg| \Bigg| $
\bigl \lceil \Bigl \lceil \biggl \lceil \Biggl \lceil $ \bigl \lceil \Bigl \lceil \biggl \lceil \Biggl \lceil $
\bigr \rceil \Bigr \rceil \biggr \rceil \Biggr \rceil $ \bigr \rceil \Bigr \rceil \biggr \rceil \Biggr \rceil $
\bigl \lfloor \Bigl \lfloor \biggl \lfloor \Biggl \lfloor $ \bigl \lfloor \Bigl \lfloor \biggl \lfloor \Biggl \lfloor $
\bigr \rfloor \Bigr \rfloor \biggr \rfloor \Biggr \rfloor $ \bigr \rfloor \Bigr \rfloor \biggr \rfloor \Biggr \rfloor $
  • 括号: 可以直接用(..)输入;
  • 高括号: 有时候括号的内容高度较高, 改用\left(..\right)
    例如: \left(1+\dfrac{1}{n}\right)^n,效果是$ \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} $
$\large K_1 \approx {s_1}, K_2 \equiv {s_2, s_3, s_4} $

  • \neq: \(\large \neq\)
  • \approx : \(\approx\) is used mostly for the approximate (read: calculated) value of a mathematical expression like \(\pi \approx 3.14\)
  • \cong : \(\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., \(5 \text{ mod } 3 \cong 11 \text{ mod } 3\) (although this is also written as \(\equiv\)). In LaTeX it is coded as \cong.
  • \sim : \(\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 \(n\)). This is a weaker statement than the other two.
  • \simeq : \(\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{}来加粗,这可以保留公式的斜体。

大括号

  1. How do I get curly braces to show in math mode?
    • Q: When I write this: $ K_1 = {s_1}, K_2 = {s_2, s_3, s_4} $
      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 the DeclarePairedDelimiter command from the mathtools 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 .
    • 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*}
      

\[ \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*}\]

  1. Some comments:
  • Use the cases environment, provided by the amsmath package,
    to place a left curly brace ahead of two or more expressions.

  • Don't use ... to create a typographical ellipsis; 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 to span all three rows,
    you could do so with the following code:( Observe, though,
    this code doesn't make full use of the capabilities of the cases;
    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*}
    
  1. 也可以使用cases Environment,可用于分段函数或者方程组,例如

     $$
     f(x)=\begin{cases}
      x, & x>0, \\
     -x, & x\leq 0.
     \end{cases}
     $$
    
     效果是:
    

\[ f(x)=\begin{cases} x, & x>0, \\ -x, & x\leq 0. \end{cases} \]


多行公式

多行公式通常使用aligned Environment,例如

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

效果是:

\[\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 $ A \supset B $
Element \in $ A \in B $
Not an Element \notin $ A \notin B $
Union \cup $ A \cup B $
Intersection \cap $ A \cap B $
Complement \complement $ A^\complement $
Set Difference \setminus $ A \setminus B $
Power Set \wp $ A \wp B $
Cartesian Product \times $ A \times B $
Cardinality |A|, \aleph_{\omicron},c $ |A|, \aleph_{\omicron},c $
Set Builder Notation \ $ \{ x | P(x) \} $
Set Membership Predicate P(x) \in A $ P(x) \in A $
Set Minus A - B $ A - B $
Set Inclusion Predicate A \subseteq B $ A \subseteq B $
Set Equality A = B $ A = B $
Disjoint Sets A \cap B = \emptyset $ A \cap B $
Subset Not Equal to A \subsetneq B $ A \subsetneq B $
Superset Not Equal to A \supsetneq B $ A \supsetneq B $
Symmetric Difference A \triangle B $ A \triangle B $
Subset of or Equal to A \subseteq B $ A \subseteq B $
Proper Subset of to A \subset B $ A \subset B $
Cartesian Power A^ $ A^{n} $
Union of Sets \bigcup A_i $ \bigcup A_i $
Intersection of Sets \bigcap A_i $ \bigcap A_i $
Cartesian Product of Sets \times A_i $ \times A_i $
Set of All Functions from A to B B^ $ B^{A} $
Set of All Relations from A to B A \times B $ | A \times B | $



Ending

这个教程耐心学习完后,能满足日常使用的需求。

LaTeX的使用还需要一定的熟练度,仍有时间的读者还可以考虑:

  • 试着用LaTeX抄几页书籍, 或者写几页文章,增加熟练度;
  • 配置Visual Studio Code上的LaTeX,探索效率更高的编辑器;
  • 研究如何美化排版,或是使用网络上的精美模板,让排版的效果更好。
posted @ 2024-10-04 03:27  abaelhe  阅读(123)  评论(0)    收藏  举报