Include the text of a `bibentry` in the (R)markdown text body output
Asked Answered
M

2

6

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?

Marathi answered 17/9, 2017 at 3:43 Comment(4)
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.Ferrin
This is related to https://mcmap.net/q/1378820/-full-citation-in-rmarkdownFrothy
@kevin.arseneau, then there is no solution for HLML and DOCX outputs?Marathi
@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.Ferrin
M
4

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.

Marathi answered 23/9, 2017 at 22:25 Comment(1)
this would be useful if it was possible to specify a csl file for formatting; unfortunately it doesn't seem possiblePompeii
L
2

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.

Larimor answered 27/3, 2023 at 21:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.