【问题标题】:knitr/Rmarkdown/pandoc : How to set bibliography paths globally in .Rmd filesknitr/Rmarkdown/pandoc : 如何在 .Rmd 文件中全局设置参考书目路径
【发布时间】:2020-08-10 07:53:00
【问题描述】:

[仅供参考:这个问题与rmarkdown: how to use multiple bibliographies for a document有关

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

\bibliography{graphics, statistics, timeref}

让 BibTeX 搜索文件 graphics.bibstatistics.bibtimeref.bib 在我本地的texmf 目录下。

.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 文件的路径987654333@?

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

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

【问题讨论】:

  • 有趣的问题!你看过this的帖子吗?
  • 是的,我看过那篇文章,但它(不是真的)回答了一个不同的问题。这个问题和类似问题暴露了yaml -> {r-markdown, pandoc-citeproc} 链中的缺陷/限制。我发布这个是因为我认为对于我描述的特定问题可能有一个聪明的解决方法。

标签: yaml r-markdown knitr pandoc pandoc-citeproc


【解决方案1】:

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

这行得通:

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

【讨论】:

  • 通过相对路径包含参考书目实际上很有帮助。就我而言,参考文件在父目录中,所以bibliography: - "`r system('kpsewhich ../references.bib', intern = TRUE)`" 做到了:)
猜你喜欢
  • 2016-01-07
  • 1970-01-01
  • 1970-01-01
  • 2021-09-23
  • 1970-01-01
  • 2014-01-25
  • 2014-12-13
  • 2021-02-07
  • 1970-01-01
相关资源
最近更新 更多