Use advanced cite commands (e.g., citetitle, citeauthor, footcite from biblatex/natbib) in R markdown file compiled as both PDF & HTML
Asked Answered
C

1

8

Both natbib and biblatex offer a great variety of commands to insert citations.

However, only a few of them seem to be available in R markdown:

Description R markdown natbib Command biblatex Command
Classical Citation: Author, year, and brackets (with round or square brackets depending on the citation style) [@key] \citep{key} \parencite[Prefix][Suffix]{key}
In-text Citation: Author (year) (without square brackets or with brackets depending on the citation style) @key \citet{key} \cite[Prefix][Suffix]{key}
Year only/suppress Author: (year) [-@key] \citeyear{key} \citeyear[Prefix][Suffix]{key}
Include item in bibliography without citing it in the document Unused References (nocite) \nocite{key} \nocite{key}

Often one would like to use more advanced commands, e.g. to cite the authors only and suppress the year.

Are there ways to add and use the following cite commands in R markdown documents to be compiled in several output formats, in particular PDF & HTML?

\citetitle{key} Returns the title of the source.
\citeauthor{key} Returns the author(s) of the cited source.
\footcite{key} Creates a footnote within the document.
\fullcite{key} Creates a complete quote like in the bibliography
\footfullcite{key} Creates a complete citation, as in the bibliography, in a footnote.

Related SO Qs: author only & add possessive 's to in-text citation; More flexible citation formats

Concordat answered 25/8, 2020 at 8:38 Comment(1)
Citing references as would be very helpful to have: "Bob & Dylan (1965, p. 365) refers to rolling stones.". Is anyone aware of a way to twist or extend @key or [@key] in this way?Concordat
O
3

Depends. If you are only producing PDF documents, then you can use natbib or biblatex directly and use the original LaTeX commands.

---
output:
  pdf_document:
    citation_package: biblatex
---

Show just the author of citation with ID "rick": \citeauthor{rick}

But this works with PDF output only.


Other formats are tricky. R Markdown uses a citeproc processor which handles and styles citations based on definitions written in Citation Style Language (CSL). Some things can be controlled this way, e.g. consistent use of footnotes for references. Other options, like author-only citations, are not supported by the CSL.

You could, in theory, use pandocfilters or Lua filters to hack your own plugin, extending the citation syntax. But that's probably more trouble than it's worth.

Orji answered 22/12, 2020 at 16:40 Comment(2)
Thank you for your suggestion. The idea was to use several output formats, in particular PDF & HTML (and sometimes Word Doc for reviewing with track changes). I should have made this more clear in the initial description, my apologies.Concordat
In case no further answers are proposed in time, the points are nevertheless yours, @tarleb. Thanks againConcordat

© 2022 - 2024 — McMap. All rights reserved.