5

[仅供参考:这个问题与rmarkdown有关:如何为一个文档使用多个参考书目

在 LaTeX 文档甚至 Rmarkdown 中.Rnw,我可以简单地使用类似的东西

\bibliography{graphics, statistics, timeref}

让 BibTeX在我的本地目录下搜索文件graphics.bib、、statistics.bib和。timeref.bibtexmf

.Rmd文件中,使用yaml标题,我被迫使用绝对路径(不可移植)或相对路径(笨重,容易出错)列出每个参考书目文件。这是最近的一个例子:

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

问题:就像我可以r format(Sys.time(), '%d %B, %Y')使用 R 来填写日期一样,我可以使用一些 R 表达式来查找/填写我的 .bib 文件的路径bibliography:吗?

好的,从前面的问题,我尝试使用

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

这会找到正确的路径,但只是将它们生成为 R 降价日志中的输出,而不是生成到yaml标题中。我懂了:

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
4

1 回答 1

5

我几乎是正确的,但忘记了intern=TRUE

这有效:

bibliography:
  - "`r system('kpsewhich graphics.bib', intern=TRUE)`"
  - "`r system('kpsewhich statistics.bib', intern=TRUE)`"
  - "`r system('kpsewhich timeref.bib', intern=TRUE)`"
于 2020-04-27T13:48:51.710 回答