5

[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
user101089
  • 3,756
  • 1
  • 26
  • 53
  • Interesting question! Have you seen [this](https://stackoverflow.com/questions/49707298/how-to-get-a-second-bibliography) post? – J_F Apr 26 '20 at 20:27
  • 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 Apr 26 '20 at 21:30

1 Answers1

5

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)`"
user101089
  • 3,756
  • 1
  • 26
  • 53
  • That's actually helpful to include the bibliography by a relative path. In my case, the reference file was in the parent directory, so ```bibliography: - "`r system('kpsewhich ../references.bib', intern = TRUE)`" ``` did it :) – bathyscapher May 28 '21 at 10:40