13

when using Rmarkdown to build a pdf with citations included, it removes the hyperlinks of the citations by default.

Looking at the latex file produced, I can see \usepackage{hyperref} in the pre-amble, but the citations look as follows:

rmd input:    @sharpe
latex output:  sharpe (1999)

Thus it produces a non-dynamic citation in pdf.

The latex output that I would expect is: \citet{sharpe}, which produces hyperlinked citation in pdf.

Any ideas why it writes out my bibtex inputs like this and how I can make it hyperlinked?

Nick
  • 3,262
  • 30
  • 44

2 Answers2

14

By default pandoc will do the rendering of the citations. I see two alternatives.

  1. Use \citet{sharpe} in the Rmd instead of @sharpe. Downside: you can only render the Rmd into pdf.
  2. Use the --natbib argument. Downside: You need an extra bibtex step when rendering into pdf.

Update: You can also provide the option link-citations: true in your YAML (since pandoc v1.16) and keep the pandoc syntax for citations.

cpauvert
  • 3
  • 3
Thierry
  • 18,049
  • 5
  • 48
  • 66
  • Hi @Thierry, thanks for the suggestion. However using \citet{sharpe} produces a '?' in the pdf, despite being \citet{sharpe} in the tex file? – Nick Oct 20 '15 at 10:24
  • Also, I made the default latex file to use natbib, but it doesn't fix my problem. What do you mean by the extra bibtex step? – Nick Oct 20 '15 at 10:25
  • 1
    Try to compile the tex file manually: `pdflatex yourfile.tex`, `bibtex yourfile`, `pdflatex yourfile.tex`, `pdflatex yourfile.tex` – Thierry Oct 20 '15 at 10:29
  • That is not ideal though, but solves my problem thanks. Please let me know if you know of a way to make it happen dynamically. – Nick Oct 20 '15 at 10:44
  • btw what did you mean by the extra bibtex step when using natbib? – Nick Oct 20 '15 at 11:04
  • See http://pandoc.org/demo/example19/Citation-rendering.html `bibtex` is the step in which the citations are generated in base LaTeX. – Thierry Oct 20 '15 at 11:54
  • 4
    `link-citations: true` did not appear to work. Cold you be more specific about how it's supposed to enter the YAML header? – MichaelChirico Feb 22 '17 at 22:26
  • 2
    @MichaelChirico try something like ```--- output: pdf_document bibliography: Main_Document.bib link-citations: true ---``` – Carl H Mar 17 '19 at 01:22
  • `\citet` gives me `! Undefined control sequence.` But no need, with `link-citations: true`. – James Hirschorn Jun 12 '21 at 07:02
10

Example of YAML for link citations in Rmd using PDF

---
title: "Introduction to data mining – Assignment"
author: "Your Name"
date: "Date"
output: 
  pdf_document: default
bibliography: <references>.bib
csl: <your_csl_file>.csl
link-citations: yes
linkcolor: blue
---

In text quote.

Here is my quote @AuthorYear
tcratius
  • 525
  • 6
  • 15