4.5 KiB
Exercise 13: Adding a Bibliography
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).
::::::{topic} Exercise objective Can you include references in your book using a bibliography file and cite them using different formats? ::::::
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.
Adding a bibliography
-
Open or create a Markdown file where you want to use references.
-
Make sure a bibliography file exists in your project. The default format is
.bib, which uses BibTeX syntax. You can create a file calledreferences.bibin the root or relevant folder of your project. -
In the
references.bibfile, and add entries to reference like the examples below.
@book{knuth1984,
author = {Donald E. Knuth},
title = {The TeXbook},
year = {1984},
publisher = {Addison-Wesley}
}
@article{einstein1905,
author = {Einstein, Albert},
title = {On the Electrodynamics of Moving Bodies},
journal = {Annalen der Physik},
year = {1905}
}
- 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:
---
bibliography: references.bib
---
:class: note
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.
You can add this `bibliography:` key in `_config.yml` to make the reference file available to the whole book instead of just per page.
Citing sources in different formats
- To cite a source in numeric style (default when using
unsrt), use[@key]. Try the following example:
Einstein's paper on relativity changed physics [@einstein1905].
- To cite a source in author–year style, change the style to
author-yearas shown below. Try this out and see how the citation from the previous step changes to the new formatting style.
```{bibliography}
:style: author-year
:filter: False
```
- You can also write inline references using
@key, which will automatically expand to author/year or number depending on the style. Try this out:
@einstein1905 describes special relativity...
- You can also site multiple references by separating them with semicolons:
Several foundational works include [@einstein1905; @knuth1984].
Rendering the bibliography
- At the bottom of the page (or wherever appropriate), include a
{bibliography}directive to render the list of references:
```{bibliography}
:style: unsrt
```
You can use `:style:` to choose different reference formats. Common options include:
- `unsrt` (numerical, unsorted)
- `plain` (numerical, sorted)
- `author-year` (author/date)
- `apa`, `ieee`, `nature` (other standard citation styles)
-
Ensure your
.bibfile is correctly formatted and that each key used in@keyor[@key]matches an entry in that file. If a reference doesn’t show up, double-check the syntax or run the build process again. -
When you are ready, commit your changes to the repository by clicking on the green
Commit changesbutton. -
Add a commit message.
-
To see your changes, go to {octicon}
playActions- The most recent workflow runoverview.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 tableBranches deployedand underPrimary book at root(getting bored of waiting? There'll be exercising on doing this locally which prevents you from waiting). -
Do you see your change? If you don't see it click
CTRL+F5/Control+F5to refresh the page.
:class: note
Before moving on, make sure you understand:
- How to include and link a bibliography file.
- How to cite a reference using `@key` and `[@key]`.
- How to switch between citation styles like numeric or author–year.
- How to render the bibliography list at the bottom of a page.