Rmarkdown removes citation hyperlink
Asked Answered
D

2

14

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?

Delafuente answered 20/10, 2015 at 10:10 Comment(0)
S
15

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.

Shophar answered 20/10, 2015 at 10:20 Comment(9)
Hi @Thierry, thanks for the suggestion. However using \citet{sharpe} produces a '?' in the pdf, despite being \citet{sharpe} in the tex file?Delafuente
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?Delafuente
Try to compile the tex file manually: pdflatex yourfile.tex, bibtex yourfile, pdflatex yourfile.tex, pdflatex yourfile.texShophar
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.Delafuente
btw what did you mean by the extra bibtex step when using natbib?Delafuente
See pandoc.org/demo/example19/Citation-rendering.html bibtex is the step in which the citations are generated in base LaTeX.Shophar
link-citations: true did not appear to work. Cold you be more specific about how it's supposed to enter the YAML header?Piano
@Piano try something like --- output: pdf_document bibliography: Main_Document.bib link-citations: true ---Claypoole
\citet gives me ! Undefined control sequence. But no need, with link-citations: true.Fulmis
O
11

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
Ourselves answered 23/11, 2018 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.