4
votes

[FYI: This question is related to rmarkdown: how to use multiple bibliographies for a document

In LaTeX documemnts or even in Rmarkdown .Rnw, I can simply use something like

\bibliography{graphics, statistics, timeref}

to have BibTeX search for the files graphics.bib, statistics.bib, and timeref.bib under my local texmf directories.

In a .Rmd file, using a yaml header, I'm forced to list each bibliography file using either absolute paths (not portable), or relative paths (clunky, error-prone). Here is one recent example:

---
title: "My Cool Paper"
author: "Me"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
  html_document

bibliography:
  - "../../../localtexmf/bibtex/bib/graphics.bib"
  - "../../../localtexmf/bibtex/bib/statistics.bib"
  - "../../../localtexmf/bibtex/bib/timeref.bib"
---

Question: Just as I can use r format(Sys.time(), '%d %B, %Y') to use R to fill in the date, can I use some R expression to find/fill-in the paths to my .bib files under bibliography:?

OK, from the earlier question, I tried using

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

This finds the correct paths, but just generates them as output in the R markdown log, rather than into the yaml header. I see:

processing file: Vis-MLM.Rmd
  |........                                                              |  11%
   inline R code fragments

C:/Users/friendly/Dropbox/localtexmf/bibtex/bib/graphics.bib
C:/Users/friendly/Dropbox/localtexmf/bibtex/bib/statistics.bib
C:/Users/friendly/Dropbox/localtexmf/bibtex/bib/timeref.bib
1
Interesting question! Have you seen this post? - J_F
Yes, I've seen that post, but it (doesn't really) answer a different question. This and similar questions expose flaws/limitations in the yaml -> {r-markdown, pandoc-citeproc} chain. I posted this because I thought there was perhaps a clever work around for the particular problem I described. - user101089

1 Answers

4
votes

I nearly had it right, but forgot intern=TRUE

This works:

bibliography:
  - "`r system('kpsewhich graphics.bib', intern=TRUE)`"
  - "`r system('kpsewhich statistics.bib', intern=TRUE)`"
  - "`r system('kpsewhich timeref.bib', intern=TRUE)`"