3 语法

3.1 Markdown syntax

3.1.1 Inline formatting

-斜体 italic _italic_

-黑体 bold *bold*

-下标左右两边用~隔开,比如H2SO4, H~2~SO~4~

-上标两边用^隔开,比如c10-1, c10^-1^

-脚注用^[]表示,比如 hello1, hello^[this is a footnote.]

3.1.2 Block-level elements

  • one item
  • one item
  • one item
  • one item
  1. first
  2. second

Blockquotes

balabalabala

— Mark Twain

3.1.3 math expresions

$$ \begin{array}{cc}
x_{11} & x_{12} \\
x_{21} & x_{22} 
\end{array}
$$

\[ \begin{array}{cc} x_{11} & x_{12} \\ x_{21} & x_{22} \end{array} \]

3.2 Markdown extensions by bookdown

3.2.1 number and reference equations

带标签和编号的公式

\begin{equation}
a = 3 
(\#eq:a)
\end{equation}
编译后: \[\begin{equation} a = 3 \tag{3.1} \end{equation}\]

引用\@ref(eq:a) As shown in Eq.(3.1)

不带编号和标签的公式

\begin{equation*}
a = 3 
\end{equation*}
\[\begin{equation*} a = 3 \end{equation*}\]

公式对齐align

\begin{align}
a & =3 \notag\\
b & =  \sqrt{2}
(\#eq:align)
\end{align}
\[\begin{align} a & =3 \notag\\ b & = \sqrt{2} \tag{3.2} \end{align}\]

利用split 将一个公式分成几行

\begin{equation}
\begin{split}
a &= 3 + 3 \\
& =6 
\end{split}
(\#eq:var-beta)
\end{equation}
\[\begin{equation} \begin{split} a &= 3 + 3 \\ & =6 \end{split} \tag{3.3} \end{equation}\]

3.2.2 Theorems and proofs

定理

```{theorem,thmtest, name = "my theorem"}
Here is my theorem.
```
编译后为: Theorem 3.1 (my theorem) Here is my theorem.

引用定理

cite Theorem.\@ref(thm:thmtest)

cite Theorem.3.1

lemma、definition、corollary、proposition、example都一样,引用的时候缩写分别为thm、lem、def、cor、prp、ex
Lemma 3.1 Here is my lemma.

Definition 3.1 Here is my definition.

Corollary 3.1 Here is my corollary.

Proposition 3.1 Here is my proposition.

Example 3.1 Here is my example.

3.2.3 Text references

没弄明白

(ref:foo)

3.3 Figures

knitr::include_graphics(rep("images/knit-logo.png", 2))

```{r knitr-logo, out.width='32.8%', fig.show='hold', fig.cap='Three knitr logos included in the document from an external PNG image file.'}
knitr::include_graphics(rep('images/knit-logo.png', 3))
```
knitr::include_graphics(rep('images/knit-logo.png', 3))
Three knitr logos included in the document from an external PNG image file.Three knitr logos included in the document from an external PNG image file.Three knitr logos included in the document from an external PNG image file.

Figure 3.1: Three knitr logos included in the document from an external PNG image file.

3.4 Citations

假设bib文件为ref.bib,引用文献的key为xie2016bookdown,则首先需要在index.RMD里的开头部分加上

---
title: "BookDown Test"
bibliography: [ref.bib] 
biblio-style: apalike  
link-citations: yes
---

然后引用@xie2016bookdown或者[@xie2016bookdown],最后一个RMD文件里放文献列表

`r if (knitr:::is_html_output()) '# References {-}'`

see: Xie (2016) 2.8

3.5 Cross-references

比如要引用某一小节,首先在小节标题后面加上{#id},然后引用的时候\@ref(id) 如果自己没有分配id,pandoc会默认分配id: id和标题一样,只不过空格用-代替,而且标题中的大小全部换成小写了

效果:第1章、第3.4节、第3.2.2

注意:id里不能含有下划线

Xie, Yihui. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. CRC Press.

References

Xie, Yihui. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. CRC Press.


  1. this is a footnote.