rmarkdown: how to use multiple bibliographies for a document

跟風遠走 提交于 2020-01-01 09:43:19

问题


[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"

回答1:


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.



来源:https://stackoverflow.com/questions/36202023/rmarkdown-how-to-use-multiple-bibliographies-for-a-document

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