Rmarkdown removes citation hyperlink

微笑、不失礼 提交于 2019-12-01 17:29:15

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/33233827/rmarkdown-removes-citation-hyperlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!