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?
Include the text of a `bibentry` in the (R)markdown text body output
Asked Answered
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.
this would be useful if it was possible to specify a csl file for formatting; unfortunately it doesn't seem possible –
Pompeii
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.
© 2022 - 2024 — McMap. All rights reserved.
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. – Ferrinbookdown
package has enhanced cross-referencing and may provide an html solution. Check out thehtml_document2
output format. – Ferrin