Skip to content

Commit d4b45a3

Browse files
committed
exercise 13
1 parent cb31666 commit d4b45a3

2 files changed

Lines changed: 134 additions & 0 deletions

File tree

book/_toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ parts:
2525
- file: syntax_exercises/010.md
2626
- file: syntax_exercises/011.md
2727
- file: syntax_exercises/012.md
28+
- file: syntax_exercises/013.md
2829
- file: references.md
2930
- file: changelog.md
3031
- file: credits.md

book/syntax_exercises/013.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Exercise 13: Adding a Bibliography
2+
3+
In this exercise, you will learn how to add a bibliography to your book and how to include references to sources using different citation styles (e.g., numeric, author–year, or label-based).
4+
5+
\::::::{topic} Exercise objective
6+
Can you include references in your book using a bibliography file and cite them using different formats?
7+
\::::::
8+
9+
```{tip}
10+
Citing references properly gives credit to original authors and improves your writing. See the [JupyterBook guide on citations](https://jupyterbook.org/en/stable/content/citations.html) for full details.
11+
```
12+
13+
## Adding a bibliography
14+
15+
1. Open or create a Markdown file where you want to use references.
16+
17+
2. Make sure a bibliography file exists in your project. The default format is `.bib`, which uses BibTeX syntax. You can create a file called `references.bib` in the root or relevant folder of your project.
18+
19+
3. In the `references.bib` file, and add entries to reference like the examples below.
20+
21+
```
22+
@book{knuth1984,
23+
author = {Donald E. Knuth},
24+
title = {The TeXbook},
25+
year = {1984},
26+
publisher = {Addison-Wesley}
27+
}
28+
29+
@article{einstein1905,
30+
author = {Einstein, Albert},
31+
title = {On the Electrodynamics of Moving Bodies},
32+
journal = {Annalen der Physik},
33+
year = {1905}
34+
}
35+
```
36+
4. Return to the Markdown file you are working on, and link the bibliography file using a **front matter header**. This should be placed at the very top of your file to automatically enable citations and bibliography rendering:
37+
38+
```md
39+
---
40+
bibliography: references.bib
41+
---
42+
```
43+
44+
````{admonition} What is a front matter header?
45+
:class: note
46+
47+
A front matter header is a block of configuration settings written in YAML and placed at the very top of a Markdown file, enclosed between triple dashes `---`. It allows you to specify page-level options such as the title, tags, or the bibliography file to use.
48+
49+
For example, the following tells Jupyter Book to use `references.bib` for any citations on that page:
50+
51+
```yaml
52+
---
53+
bibliography: references.bib
54+
---
55+
```
56+
````
57+
58+
59+
60+
```{tip}
61+
You can add this `bibliography:` key in `_config.yml` to make the reference file available to the whole book instead of just per page.
62+
```
63+
64+
## Citing sources in different formats
65+
66+
5. To cite a source in **numeric style** (default when using `unsrt`), use `[@key]`. Try the following example:
67+
68+
```md
69+
Einstein's paper on relativity changed physics [@einstein1905].
70+
```
71+
72+
73+
6. To cite a source in **author–year style**, change the style to `author-year` as shown below. Try this out and see how the citation from the previous step changes to the new formatting style.
74+
75+
````md
76+
```{bibliography}
77+
:style: author-year
78+
:filter: False
79+
```
80+
````
81+
82+
83+
7. You can also write inline references using `@key`, which will automatically expand to author/year or number depending on the style. Try this out:
84+
85+
```md
86+
@einstein1905 describes special relativity...
87+
```
88+
89+
8. You can also site **multiple references** by separating them with semicolons:
90+
91+
```md
92+
Several foundational works include [@einstein1905; @knuth1984].
93+
```
94+
95+
96+
## Rendering the bibliography
97+
98+
9. At the bottom of the page (or wherever appropriate), include a `{bibliography}` directive to render the list of references:
99+
100+
````md
101+
```{bibliography}
102+
:style: unsrt
103+
```
104+
````
105+
106+
```{tip}
107+
You can use `:style:` to choose different reference formats. Common options include:
108+
- `unsrt` (numerical, unsorted)
109+
- `plain` (numerical, sorted)
110+
- `author-year` (author/date)
111+
- `apa`, `ieee`, `nature` (other standard citation styles)
112+
```
113+
114+
10. Ensure your `.bib` file is correctly formatted and that each key used in `@key` or `[@key]` matches an entry in that file. If a reference doesn’t show up, double-check the syntax or run the build process again.
115+
116+
12. When you are ready, commit your changes to the repository by clicking on the green `Commit changes` button.
117+
118+
13. Add a commit message.
119+
120+
14. To see your changes, go to {octicon}`play` `Actions` - The most recent workflow run `overview.md / the commit message of the commit you just made` - Wait for it to finish - In the summary, click on the link of your book shown in the table `Branches deployed` and under `Primary book at root` (getting bored of waiting? There'll be exercising on doing this locally which prevents you from waiting).
121+
122+
15. Do you see your change? If you don't see it click `CTRL`+`F5`/`Control`+`F5`to refresh the page.
123+
124+
125+
```{admonition} Check your understanding
126+
:class: note
127+
128+
Before moving on, make sure you understand:
129+
- How to include and link a bibliography file.
130+
- How to cite a reference using `@key` and `[@key]`.
131+
- How to switch between citation styles like numeric or author–year.
132+
- How to render the bibliography list at the bottom of a page.
133+
```

0 commit comments

Comments
 (0)