Manage your references with RefManageR and Quarto

  • article
  • bibliography
  • quarto
  • Q&A
How to use RefManageR to manage your references, and how to adjust the bib-style.
Author
Published

Introduction

As mentioned in a previous post, it is important for an academic researcher or scientist to have an online presence and especially to share their research works and achievements with global audience. On simple solution is to use academic social networks and scholarly literature databases, such as  Orcid,  Clarivate (web-of-science),  Google Scholar,  Scopus,  Academia,  ResearchGate… However, it may be preferable to share one’s contributions on one’s own website.
I create my website using Quarto (see the history page). If you don’t have a Quarto website, you can find many blogs that explain how to create a blog or personal website with Quarto. This guide is for anyone interested in learning how to create a references page like mine.

A previous post shows how to use Quarto listing to create a publication list. This method is “quite” simple, but may be tedious if you have a lot of publications.

Another simple solution, is to use Pandoc to render citations with citeproc1. Put all references in a bibliographic data file (e.g., a .bib file), and to include nocite in the metadata front end, and add div block with id refs in your references documents.
One disadvantage of this approach is that the references are not clearly distinguished or organized.

Problem statement
  • Most editors only support BibTeX (regretfully), but I want the reference manager to support BibLaTeX.
  • I want to organize the references in different categories.
  • Render formatted references in Markdown or in HTML (body only).
  • Manage the bibliography entries style and rendering.

There are many methods for managing bibliography references, particularly if you already use BibLaTeX or BibTeX. In particular, Quarto is a multi-language program that can use Knitr to run R code (such as with R-markdown) and also supports Python, Juia and Observable JS code blocks. I initially used R-markdown when writing my HDR, so I sought a solution with R code and discovered the RefManageR package. With this package, I manage my references page.

Note

Quarto supports Python code blocks, and there are many BibTeX Python parsers out there. I will investigate this solution later. For more information, see the blog of Marcel Bollmann.

Parsing Bib(La)TeX with RefManageR

RefManageR provides tools for importing and working with bibliographic references. It can load BibTeX and BibLaTeX .bib files, and even connect to NCBI, CrossRef, and Zotero to import references.

Once a .bib file is create or imported, it is then straightforward to import them in a R code:

if(!require(RefManageR))
  remotes::install_github("ropensci/RefManageR") 

RefManageR::BibOptions(check.entries = FALSE, 
                       style = "markdown",
                       bib.style = "numeric",
                       sorting = "ydnt",
                       max.names=99)
bib <- RefManageR::ReadBib("references.bib", .Encoding = "UTF-8", 
                           check = 'warn')
1
The printing style here set to markdown.
2
Specifying BibLaTeX style to use for formatting references.
3
Set references sorting.

bib contains all entries of the .bib files, and with a print(bib) all entries are printed (here in markdown style ). It is quite easy to separate the bibliography entries, for example:

# All Article entries type
bibArticle <- bib[bibtype="Article"] 
# All InProceeding entries of the year 2022
bibInProceeding2022 <- bib[c(bibtype="InProceeding", year=2022)]

and the include print(bibArticle), print(bibInProceeding2022) properly in your references document, such as:

## Articles

```{r bibArticle}
#| results: asis
#| echo: false
print(bibArticle)
```
Tip

It is worth noting that it is possible to update certain statistical data on references in a dynamic manner.

Example 1 To illustrate, the following sentence will be updated dynamically (i.e. each time you update your .bib files and render your website)

My scientific activities have led to  `{r} length(bib)` publications
including `{r} length(bibArticle)` articles.

Bibliography style

RefManager offers five natives bibliography styles : numeric, authoryear, authortitle, alphabetic and draft. These options may be suitable for those seeking a basic bibliography style. However, if a specific style is desired, it may be somewhat cumbersome to get it with RefManager.

Custom bibliography style

To create a custom bibliography style, with RefManager, use the bibstyle function from the tools package (native in R). This function uses an environment to hold the functions implementing the style. RefManager has the MakeBibLaTeX and MakeAuthorYear (internal) functions that manage its native bibliography styles:

my_style <- RefManageR:::MakeBibLaTeX()
#
# <<Put here your customization>>
#
tools::bibstyle("my", my_style)

Auxilliary functions

Here some functions which are not part of RefManageR and may be useful.

addColon <- function(s){
  if (!.is_not_nonempty_text(s) && grepl("([^.?!])$", s, useBytes = FALSE))
    paste0(s, ":")
  else
    s
}
# Span a class arround a string
fmtSetClass <- function(s, class, prefix="bib-"){
  if (length(s))
    paste0("[", s, "]\\{.",prefix, class,"\\}")
}
# Format an URI 
fmtURI <- function(label, uri, prefix="", uri_prefix="", class="uri"){
  if (length(uri))
    fmtSetClass(paste0("[", prefix, label, "](",uri, ")\\{rel='noopener noreferrer'\\}."),class)
}
Note

It is my hope that this simple tutorial will prove useful in the creation of your own references page. Should this be the case, I would be grateful if you would share your feedback in the comments section below.

Additionally, the above tutorial is a simplified version of the one used on my website. If you would like to have supplementary tips, ask below.

Footnotes

  1. CiteProc is the generic name for programs that produce formatted bibliographies and citations based on the metadata of the cited objects and the formatting instructions provided by Citation Style Language (CSL) styles (from Wikipedia).↩︎