2.5. Markdown Cells¶
The d2lbook
provide additional features beyond the normal markdown
supports in Jupyter.
2.5.1. Table of Contents¶
You can use a toc
code block to specify the table of contents. Here
:maxdepth: 2
means display two levels of files, and :numbered:
means adding number to each section (default is not enabled). Also note
that you don’t need to specify the file extension.
```toc
:maxdepth: 2
:numbered:
guide/index
```
2.5.2. Images¶
We can put the image caption in []
. In addition, we can use
:width:
followed by its value in an inline block to specify the
image width, similarly use :height:
for height.

:width:`400px`

Fig. 2.5.1 Estimating the length of a foot¶
2.5.2.1. SVG Images¶
We recommend you to use SVG images as much as you can. It is sharp and
its size is small. But since Latex doesn’t support SVG images, if you
want to build a PDF output, you need to install rsvg-convert
. On
Macos, you can simply brew install librsvg
or
sudo apt-get install librsvg2-bin
for Ubuntu.
Fig. 2.5.2 A LSTM cell in SVG¶
2.5.3. Tables¶
You can insert table caption before the table by starting it with a
:
. Note that you need to leave an empty line between the caption and
the table itself.
: The number is computed by $z_{ij} = \sum_{k}x_{ik}y_{kj}$.
| Year | Number | Comment |
| --- | --- | --- |
| 2018 | 100 | Good year |
| 2019 | 200 | Even better, add something to make this column wider |
Year |
Number |
Comment |
---|---|---|
2018 |
100 |
Good year |
2019 |
200 |
Even better, add something to make this column wider |
Table: The number is computed by \(z_{ij} = \sum_{k}x_{ik}y_{kj}\).
If the Table caption number doesn’t show properly, you may need to
update pandoc
to the latest version.
2.5.4. Cross References¶
We often want to reference sections, figures, tables and equations in a book.
2.5.4.1. Referencing Sections¶
We can put a label immediately after the section title to allow this
section to be referenced by its label. The label format is :label:
followed by its label name in an inline code block.
### Referencing Sections
:label:`my_sec3`
Then we can reference this section through :ref:
followed by label
name in an inline code block
:ref:`my_sec3` demonstrates how to reference a section.
Referencing Sections demonstrates how to reference a section.
Note that it displays the referenced section title with a clickable
link. We can also use a numbered version by changing :num:
to
:numref:
, e.g. Section 2.5.4.1.
If the label is incorrect, say we put my_sec2
here, the build log
will contains a warning such as
WARNING: undefined label: my_sec2
You can turn it into error by setting warning_is_error = True
in
config.ini
.
Besides, we can cross reference label from other files as well, e.g. Section 2.6. This applies to figures, tables and equations as well.
2.5.4.2. Referencing Images¶
Similarly we can label an image and reference it later.

:width:`300px`
:label:`img_catdog`
As can be seen from :numref:`img_catdog`,

Fig. 2.5.3 A nice image with a cat and a dog.¶
As can be seen from Fig. 2.5.3, there is a cat and a dog.
2.5.4.3. Referencing Tables¶
:This a is very long table caption. It will breaks into several lines. And
contains a math equation as well. $z_{ij} = \sum_{k}x_{ik}y_{kj}$.
| Year | Number | Comment |
| --- | --- | --- |
| 2018 | 100 | Good year |
:label:`table`
Refer to :numref:`table`
Year |
Number |
Comment |
---|---|---|
2018 |
100 |
Good year |
Table: This a is very long table caption. It will breaks into several lines. And contains a math equation as well. \(z_{ij} = \sum_{k}x_{ik}y_{kj}\).
Refer to Section 2.5.4.3
2.5.4.4. Referencing Equations¶
The difference here is that we need to use eqlabel
instead of
label
. For example
$$\hat{\mathbf{y}}=\mathbf X \mathbf{w}+b$$
:eqlabel:`linear`
In :eqref:`linear`, we define the linear model.
In (2.5.1), we define the linear model.
2.5.5. Citations¶
First put your bib file at somewhere. All references will be displayed
on the place where it inserted in HTML. But in PDF, all references will
be moved to end of the document. Then we can cite a paper through
:cite:
. Multipel papers can be separated by commans (note there
should be no space)
The breakthrough of deep learning origins from :cite:`krizhevsky2012imagenet` for...
Two keys together :cite:`he2016deep,devlin2018bert`...
:bibliography:`../refs.bib`
The breakthrough of deep learning origins from (Krizhevsky et al., 2012) for computer vision, there is a rich of following up works, such as (He et al., 2016). NLP is catching up as well, the recent work (Devlin et al., 2018) shows significant improvements.
Two keys together (Devlin et al., 2018, He et al., 2016). Single author (Mitchell, 1980), two authors (Newell and Rosenbloom, 1981)
Note that :cite: is the same as \citep
in LaTeX. To use \citet
in LaTeX, just use :citet:. For example:
Two keys together :citet:`he2016deep,devlin2018bert`. Single author
:citet:`mitchell80`, two authors :citet:`Newell81`
Two keys together Devlin et al. (2018), He et al. (2016). Single author Mitchell (1980), two authors Newell and Rosenbloom (1981)
2.5.6. References¶
- Devlin et al., 2018(1,2,3)
Devlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2018). Bert: pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805.
- He et al., 2016(1,2,3)
He, K., Zhang, X., Ren, S., & Sun, J. (2016). Deep residual learning for image recognition. Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 770–778).
- Krizhevsky et al., 2012
Krizhevsky, A., Sutskever, I., & Hinton, G. E. (2012). Imagenet classification with deep convolutional neural networks. Advances in neural information processing systems (pp. 1097–1105).
- Mitchell, 1980(1,2)
Mitchell, T. M. (1980). The Need for Biases in Learning Generalizations. Computer Science Department, Rutgers University.
- Newell & Rosenbloom, 1981(1,2)
Newell, A., & Rosenbloom, P. S. (1981). Anderson, J. R. (Ed.). Mechanisms of skill acquisition and the law of practice. Cognitive Skills and Their Acquisition (pp. 1–51). Hillsdale, NJ: Lawrence Erlbaum Associates, Inc.