13

[My environment: Win 7 Pro / R 3.2.1 / knitr_1.12.3 / R Studio Version 0.99.892]

I am trying to write an article in .Rmd format using R Studio, Knit -> PDF, and I've been following http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html for details of how to get pandoc and pandoc-citeproc to produce a References section and citations in the text.

My BibTeX references are in several different .bib files, which, when using LaTeX in .Rnw files, are all found in my local texmf tree via

\bibliography{statistics, graphics}

I can't seem to make this work with pandoc-citeproc. My YAML header has the following, that works for one .bib file, as long as it is in the same directory as the source .Rmd file:

    ---
    title: "Notes on Testing Equality of Covariance Matrices"
    author: "Michael Friendly"
    date: '`r format(Sys.time(), "%B %d, %Y")`'
    output:
      pdf_document:
        fig_caption: yes
        keep_tex: yes
        number_sections: yes
    csl: apa.csl
    bibliography: statistics.bib
    ---

Following advice in the link given above, I tried:

bibliography: [statistics.bib,graphics.bib]

this gives:

pandoc-citeproc.exe: "stdin" (line 50, column 12):
unexpected ":"
expecting letter, digit, white space or "="
pandoc.exe: Error running filter pandoc-citeproc
Filter returned error status 1

[Edit: For completeness, I show the generated pandoc command, where it looks like both .bib files are passed correctly]:

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS EqCov.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output EqCov.pdf --template "C:\R\R-3.2.1\library\rmarkdown\rmd\latex\default-1.15.2.tex" --number-sections --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" --bibliography statistics.bib --bibliography graphics.bib --filter pandoc-citeproc 
output file: EqCov.knit.md

So do all the following forms:

    bibliography: ["statistics.bib","graphics.bib"]

    bibliography: 
      - "statistics.bib"
      - "graphics.bib"

    bibliography: 
      - statistics.bib
      - graphics.bib

Ideally, I'd like to be able to use one of the following forms, and not have to copy the .bib files to the document directory.

bibliography: ["C:/Dropbox/localtexmf/bibtex/bib/statistics.bib","C:/Dropbox/localtexmf/bibtex/bib/graphics.bib"]

bibliography: 
 - "C:/Dropbox/localtexmf/bibtex/bib/statistics.bib"
 - "C:/Dropbox/localtexmf/bibtex/bib/graphics.bib"
user101089
  • 3,756
  • 1
  • 26
  • 53
  • Just a note - this seems to work without problems in HTML output. Has there been any update regardidng the pdf problem? – radek Nov 13 '18 at 05:16
  • @user101089, although the "for a document" part of the question's title is somewhat helpful, the question can still be mistaken for asking about obtaining different bibliography/references sections, whereas it asks for using multiple bibliography source files. Perhaps, you would consider editing to improve clarity. – streamline Aug 28 '23 at 12:07

1 Answers1

5

For the record: I raised this as an issue for pandoc-citeproc at https://github.com/jgm/pandoc-citeproc/issues/220

It turns out that there were problems in how pandoc-citeproc handles some characters in @{string={}} and non-ASCII characters in .bib files, so what I was trying now works, with hard-coded pathnames, in all the forms I tried.

To make it work more like processing of .Rnw files via Latex/bibtex it would be nice to be able to use something like

bibliography: 
  - `r system(kpsewhich statistics.bib)`
  - `r system(kpsewhich graphics.bib)`

Those commands do find the right files in an R session, but not from a YAML header.

user101089
  • 3,756
  • 1
  • 26
  • 53
  • I've found that R commands can (sometimes) be run from YAML headers by encapsulating them in single-quotes, so the following might work: `- '\`r system(kpsewhich statistics.bib)\`'` For instance, this works for the YAML "date" header: `date: '\`r format(Sys.Date(), "%B %Y")\`'` – Tom Aug 20 '18 at 15:14