I’m just beginning to learn BibTeX, which is, according to Wikipedia (2019), “reference management software for formatting lists of references”.
It is useful for publishing formats such as R Markdown documents and books created with bookdown, like the Data Science in Education Using R book.
I’m basically using this post to document what I’m learning.
Adding references
I started with references, which are saved in plain text documents ending in .bib
. Next, so that R Markdown knows the file(s) to use, you have to add the filename to the front matter of the document. In R Markdown, for example, I can use the plain text file references.bib
, im which I store references, by adding this line to the YAML front matter:
bibliography: [references.bib]
References have a format which is a bit intuitive. Here is an example for our book:
@book{dsieur-under-contract,
author = {Emily A. Bovee and Ryan A. Estrellado and Jesse Mostipak and Joshua M. Rosenberg and Isabella C. Velásquez},
title = {Data science in education using R},
year = {under contract},
publisher = {Routledge},
url = {https://datascienceineducation.com},
}
The key parts are the @book
(which can be replaced with @article
, @proceedings
, .etc), the “key” (which, for us, is dsieur-under-contract
), and the various fields (e.g., for the title and authors).
In addition to those used above (for author, title, year, publisher, and url), others are also available, including volume, issue, chapter, and editor).
Adding citations
With a reference saved in the .bib
file (and the .bib
file referenced in the document or book front matter), it can be cited in text by referring to the citation key. For example, the following sentence:
An aim of *Data science in education using R* is to help to equip those working
in education, including teachers, data analysts and scientists, researchers, and
administrators to solve problems and ask questions in the context of educational
data and systems [@dsieur-under-contract.]
(Oye, I’ll leave it to my co-authors to summarize the aims of our book better.)
Would render as the following:
An aim of Data science in education using R is to help to equip those working in education, including teachers, data analysts and scientists, researchers, and administrators to solve problems and ask questions in the context of educational data and systems (Bovee et al., n.d.).
References can be cited in different way.
- For parenthetical citations:
[@dsieur-under-contract]
renders as (Bovee et al., n.d.) - - For in-text citations:
@dsieur-under-contract
renders as Bovee et al. (n.d.) - For only the year:
-@dsieur-under-contract
renders as (n.d.)
Other notes
BibTeX only works with R Markdown documents saved as
.Rmd
files - it does not work with.rmarkdown
(or with.md
) documents.You can add citations to R packages used in a file with the following, wich creates a
.bib
file (calledpackges.bib
, in this case):
knitr::write_bib(.packages(), "packages.bib")
- This could then be added to the bibliography file, e.g.:
bibliography: [using-bibtex.bib, packages.bib]
References generate automatically. You can add a section heading, e.g., a level three heading for references (
### References
) (as the following heading before the references is).The raw
.bib
. file is here
References
Bovee, Emily A., Ryan A. Estrellado, Jesse Mostipak, Joshua M. Rosenberg, and Isabella C. Velásquez. n.d. Data Science in Education Using R. Routledge. https://datascienceineducation.com.
Wikipedia. 2019. “BibTeX.” https://en.wikipedia.org/wiki/BibTeX.