Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 242
mavericks Avatar asked Aug 25 '20 08:08

mavericks


1 Answers

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.

like image 95
tarleb Avatar answered Oct 20 '22 14:10

tarleb