2

I would like to add a bibtex reference to the notes for a gt table in Quarto, but using @citationkey does not seem to work. Does anyone know how to do it?

Here's a reproducible example:

---
title: "Untitled"
format: pdf
bibliography: refs.bib
---

```{r}
#| include: false
library(dplyr)
library(gt)

    ```

Here I can cite @dirac

But below I get only the literal "@dirac". If I do not include the quotation marks, the code does not compile.

```{r}
#| include: true
#| echo: false

head(mtcars) %>%
  gt() %>%
  tab_source_note("@dirac")
    ```

# References {-}

And the reference in refs.bib:

@book{dirac,
  title={The Principles of Quantum Mechanics},
  author={Paul Adrien Maurice Dirac},
  isbn={9780198520115},
  series={International series of monographs on physics},
  year={1981},
  publisher={Clarendon Press},
  keywords = {physics}
}
nicholas
  • 903
  • 2
  • 12

1 Answers1

2

Following this post you could read your bib file via bibtex::read.bib. Afterwards you could add your citation to the gt table via cite like so:

---
title: "Untitled"
format: pdf
bibliography: refs.bib
---

```{r}
#| include: false
library(dplyr)
library(gt)
library(bibtex)
```
```{r}
biblio <- bibtex::read.bib("refs.bib")
```

Here I can cite @dirac

But below I get only the literal "@dirac". If I do not include the quotation marks, the code does not compile.

```{r}
#| include: true
#| echo: false
head(mtcars) %>%
  gt() %>%
  tab_source_note(cite("dirac", biblio, textual = TRUE))
```

enter image description here

stefan
  • 90,330
  • 6
  • 25
  • 51