作者:Yihui Xie
译者:郑宝童
日期:2021.05.17
In this section, we give a very brief introduction to Pandoc’s Markdown. Readers who are familiar with Markdown can skip this section. The comprehensive syntax of Pandoc’s Markdown can be found on the Pandoc website http://pandoc.org.
2.1 Markdown syntax
2.1.1 Inline formatting
You can make text italic by surrounding it with underscores or asterisks, e.g.,
_text_
or*text*
. For bold text, use two underscores (__text__
) or asterisks (**text**
). Text surrounded by~
will be converted to a subscript (e.g.,H~2~SO~4~
renders H2SO4), and similarly, two carets (^
) produce a superscript (e.g.,Fe^2+^
renders Fe2+). To mark text asinline code
, use a pair of backticks, e.g.,code
.3 Small caps can be produced by the HTML tagspan
, e.g.,<span style="font-variant:small-caps;">Small Caps</span>
renders Small Caps. Links are created using[text](link)
, e.g.,[RStudio](https://www.rstudio.com)
, and the syntax for images is similar: just add an exclamation mark, e.g.,![alt text or image title](path/to/image)
. Footnotes are put inside the square brackets after a caret^[]
, e.g.,^[This is a footnote.]
. We will talk about citations in Section 2.8.
2.1.1 行内格式化
可以用下划线或星号将文本包围,使其变为斜体,例如, _text_
或者 *text*
. 而对于加粗文本,可以使用两个下划线 或者两个星号(__text__
) (**text**
). 被 ~
包围的文本将被转换为下表 (例如, H~2~SO~4~
渲染生成H2SO4), 类似的, 被两个 (^
)包围的文本将被转换为上标 (例如, Fe^2+^
会渲染成 Fe2+).使用一对反钩可以将文本标注为inline code
样式,(例如 code
)3。 Small caps可以用HTML tag span
生成, 例如, <span style="font-variant:small-caps;">Small Caps</span>
.链接可以使用 [text](link)
生成, 例如 [RStudio](https://www.rstudio.com)
,图片的语法也很相似:只需要添加一个感叹号, 例如, ![alt text or image title](path/to/image)
. 脚注放置尖标后面的方括号内 ^[]
,例如., ^[This is a footnote.]
. 我们将子第2.8节讨论引用( citations).
2.1.2 Block-level elements
2.1.2 块级元素
Section headers can be written after a number of pound signs, e.g.,
节标题写在#号之后,例如:
# First-level header
## Second-level header
### Third-level header
If you do not want a certain heading to be numbered, you can add
{-}
after the heading, e.g.,
如果你不希望某个标题被编号,你可以在标题后面添加 {-}
,例如:
# Preface {-}
Unordered list items start with
*
,-
, or+
, and you can nest one list within another list by indenting the sub-list by four spaces, e.g.,
无序列表项以*
, -
, 或+
,开头,通过将子列表缩进4个空格,可以将一个列表嵌套到另一个列表中,例如:
- one item
- one item
- one item
- one item
- one item
The output is:
- one item
- one item
- one item
- one item
- one item
Ordered list items start with numbers (the rule for nested lists is the same as above), e.g.,
有序列表项以数字开头(嵌套列表的规则与上面相同),例如,
1. the first item
2. the second item
3. the third item
The output does not look too much different with the Markdown source:
- the first item
- the second item
- the third item
Blockquotes are written after >
, e.g.,
块引用写在>
后面,例如:
> "I thoroughly disapprove of duels. If a man should challenge me,
I would take him kindly and forgivingly by the hand and lead him
to a quiet place and kill him."
>
> --- Mark Twain
The actual output (we customized the style for blockquotes in this book):、
实际的输出(我们在本书中为blockquotes自定义了样式):
“I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him.”
— Mark Twain
Plain code blocks can be written after three or more backticks, and you can also indent the blocks by four spaces, e.g.,
普通代码块可以写在三个或更多的反勾号之后,你也可以缩进四个空格,例如
```
This text is displayed verbatim / preformatted
Or indent by four spaces: This text is displayed verbatim / preformatted
> <a name="pRlmF"></a>
### 2.1.3 Math expressions
<a name="YVSlP"></a>
### 2.1.3 数学公式
_此处翻译略_<br />Inine LaTeX equations can be written in a pair of dollar signs using the LaTeX syntax, e.g.(, `$f(k) = {n \choose k} p^{k} (1-p)^{n-k}$` (actual output: <br />![](https://cdn.nlark.com/yuque/__latex/ff8811bbb4a276da3a1c55fcb2e5c256.svg#card=math&code=f%28k%29%20%3D%20%7Bn%20%5Cchoose%20k%7D%20p%5E%7Bk%7D%20%281-p%29%5E%7Bn-k%7D&height=45&id=SONPJ)) math expressions of the display style can be written in a pair of double dollar signs, e.g., `$$f(k) = {n \choose k} p^{k} (1-p)^{n-k}$$`, and the output looks like this:<br />![](https://cdn.nlark.com/yuque/__latex/ff8811bbb4a276da3a1c55fcb2e5c256.svg#card=math&code=f%28k%29%20%3D%20%7Bn%20%5Cchoose%20k%7D%20p%5E%7Bk%7D%20%281-p%29%5E%7Bn-k%7D&height=45&id=TstNz)
You can also use math environments inside `$ $` or `$$ $$`, e.g.,
$$\begin{array}{ccc} x{11} & x{12} & x{13}\ x{21} & x{22} & x{23} \end{array}$$
![](https://cdn.nlark.com/yuque/__latex/9e5da60eece603213752b34bbd190640.svg#card=math&code=%5Cbegin%7Barray%7D%7Bccc%7D%0Ax_%7B11%7D%20%26%20x_%7B12%7D%20%26%20x_%7B13%7D%5C%5C%0Ax_%7B21%7D%20%26%20x_%7B22%7D%20%26%20x_%7B23%7D%0A%5Cend%7Barray%7D&height=45&id=bCIT4)
$$X = \begin{bmatrix}1 & x{1}\ 1 & x{2}\ 1 & x_{3} \end{bmatrix}$$
![](https://cdn.nlark.com/yuque/__latex/fcde5ed80f4272c8cdb66320bd69612b.svg#card=math&code=X%20%3D%20%5Cbegin%7Bbmatrix%7D1%20%26%20x_%7B1%7D%5C%5C%0A1%20%26%20x_%7B2%7D%5C%5C%0A1%20%26%20x_%7B3%7D%0A%5Cend%7Bbmatrix%7D&height=66&id=CZa1F)
$$\Theta = \begin{pmatrix}\alpha & \beta\ \gamma & \delta \end{pmatrix}$$
![](https://cdn.nlark.com/yuque/__latex/ac40ec75d48a9b14dff64e0b97919462.svg#card=math&code=%5CTheta%20%3D%20%5Cbegin%7Bpmatrix%7D%5Calpha%20%26%20%5Cbeta%5C%5C%0A%5Cgamma%20%26%20%5Cdelta%0A%5Cend%7Bpmatrix%7D&height=45&id=oIrhJ)
$$\begin{vmatrix}a & b\ c & d \end{vmatrix}=ad-bc$$ ```
- To include literal backticks, use more backticks outside, e.g., you can use two backticks to preserve one backtick inside:
`code`
.↩︎