Reputation: 1213
I'm getting to grips with writing publications in rmarkdown. No issues at all generating .html files, or .docx files, but when I generate .pdf files the citations don't seem to inherit the style defined in the .csl file.
For example, with a numbered .csl style I expect:
[@Author_Title_2003]
-> (1)
Which is successful in .html and .docx files, but in .pdfs I get:
[@Author_Title_2003]
-> [Author, 2003]
With square brackets printed as well.
An example:
test.rmd:
---
title: 'My Title'
author: "Me me me me!"
output: pdf_document
bibliography: references.bib
csl: elsevier-vancouver.csl
---
Application written in the R programming language [@RCoreTeam] using the Shiny framework [@Chang2015].
# REFERENCES
references.bib:
@Misc{Chang2015,
Title = {shiny: Web Application Framework for R. R package version 0.12.1},
Author = {Chang, W. and Cheng, J. and Allaire, JJ. and Xie, Y. and McPherson, J. },
Year = {2015},
Type = {Computer Program},
Url = {http://CRAN.R-project.org/package=shiny}
}
@Article{RCoreTeam,
Title = {R: A Language and Environment for Statistical Computing},
Author = {{R Core Team}},
Year = {2015},
Type = {Journal Article},
Url = {http://www.R-project.org}
}
elsevier-vancouver.csl: link
running rmarkdown::render("test.Rmd", "pdf_document")
gives:
/home/jordan/.cabal/bin/pandoc +RTS -K512m -RTS paper.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output paper.tex --template /home/jordan/R/x86_64-pc-linux-gnu-library/3.2/rmarkdown/rmd/latex/default-1.14.tex --highlight-style tango --latex-engine pdflatex --natbib --variable graphics=yes --variable 'geometry:margin=1in' --bibliography references.bib
And the output file is:
See the incorrectly formatted citations. Also note this format is generated regardless of the csl argument in the header. Any help would be much appreciated.
pandoc version 1.15.2.1, pandoc-citeproc version 0.8.1.3.
Upvotes: 0
Views: 1758
Reputation: 1213
So I figured out what was going on after a) reading the rmarkdown package code and b) getting to know latex a bit better. I thought I'd post my answer here in case anyone has a similar problem.
In short, rmarkdown generates a .tex file from the .rmd file, and then processes the .tex file using latexmk
(or a similar R system call). Latex engines of course don't actually use .csl style files, instead bibtex uses .bst files.
In short, for formatted references in a .pdf document (generated from .rmd) either:
Create a .bst file with the required format, and convert the .tex file produced by R(Studio) manually.
Convert the .tex file to pdf using pandoc again, which can use .csl files in the process. This does seem to remove hyperlinking, however.
Upvotes: 1