5

I have been looking for a solution to include the full text of a reference item (bibentry) in the body of the (R)markdown text document, that is, before the reference list. This can be done with LaTeX (https://tex.stackexchange.com/questions/49048/how-to-cite-one-bibentry-in-full-length-in-the-body-text). Can it be done with (R)markdown?

Samuel-Rosa
  • 339
  • 3
  • 10
  • `rmarkdown` uses pandoc to render output formats. If your output is LaTeX then you can include those commands directly. However those commands will cause other output formats to fail compiling. – Kevin Arseneau Sep 17 '17 at 05:43
  • This is related to https://stackoverflow.com/questions/42602055/full-citation-in-rmarkdown – markdly Sep 17 '17 at 06:47
  • @kevin.arseneau, then there is no solution for HLML and DOCX outputs? – Samuel-Rosa Sep 17 '17 at 13:33
  • @Samuel-Rose, not that I am aware. Although, I would say that the `bookdown` package has enhanced cross-referencing and may provide an html solution. Check out the `html_document2` output format. – Kevin Arseneau Sep 17 '17 at 19:09

2 Answers2

3

A reasonable solution is to read and parse the bibliography database using, for example, the R-package bibtex and then capture.output of print as a character string, which can then be used to include the full text of a reference item (bibentry) in the body of the (R)markdown text document.

For example:

```{r, echo=FALSE}
biblio <- bibtex::read.bib("my-biblio-database.bib")
```

Then, in line, use:

`r capture.output(print(biblio["my-bibkey"]))`

which will print the reference text.

Samuel-Rosa
  • 339
  • 3
  • 10
  • this would be useful if it was possible to specify a csl file for formatting; unfortunately it doesn't seem possible – julou Dec 29 '19 at 12:20
0

The bibtex interprets the bibliography file and places it into the bibentry class, which is part of the utils package.

Thus, the correct way of showing a citation is to switch away from the accepted answer of:

`r capture.output(biblio["my-bibkey"])`

to

`r format(biblio["my-bibkey"], style = "text")`

Note, we're using the utils:::format.bibentry(entry, style = "text") to correctly set the output display.

coatless
  • 20,011
  • 13
  • 69
  • 84