r - 在 RStudio 中将 RMarkdown 编织为 PDF 时 Pandoc 的环境 cslreferences 未定义

标签 r latex r-markdown knitr pandoc

尝试创建引用时(在 RStudio 版本 1.2.1335 中)将 RMarkdown 文件编织为 PDF 失败(对于 pandoc 版本 2.8.0.1 和 R 版本 3.6.1)。 (例如,当编织到 HTML 时,不会发生这种情况。)

这是一个小代表。前任。在 RMarkdown 中:

---
title: "Rep. Ex. for 'LaTeX Error: Environment cslreferences undefined'"
output:
  pdf_document: default
bibliography: report.bib
---

```{r generate-bibtex-file, include=FALSE}
knitr::write_bib(file = "report.bib", prefix = "")
```

# Used R version

R 3.6.1 [@base]

# References

编织这个结果作为最终输出(在我的机器上):

"C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS RepEx.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output RepEx.tex --template "C:\Users\gcb7\Documents\R\win-library\3.6\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --lua-filter "C:/Users/gcb7/Documents/R/win-library/3.6/rmarkdown/rmd/lua/pagebreak.lua" --lua-filter "C:/Users/gcb7/Documents/R/win-library/3.6/rmarkdown/rmd/lua/latex-div.lua" --variable "geometry:margin=1in" --variable "compact-title:yes" --filter "C:/PROGRA~1/Pandoc/pandoc-citeproc.exe" output file: RepEx.knit.md

! LaTeX Error: Environment cslreferences undefined.

这似乎是在最近更新 pandoc 2.8.0.1 之后开始的,我刚刚在 https://pandoc.org/releases.html 上找到了在 2.8 中,cslreferences 环境似乎进行了一些更改(但到目前为止,pandoc-discuss 或相应的 github bug 跟踪器上似乎没有出现任何内容)。

有什么想法吗?

最佳答案

根据您链接的发行说明,cslreferences在 2.8 版本中引入,包括在 pandoc 模板中对此环境的适当定义。但是,Rmarkdown 使用自己的模板(在您的情况下为 C:\Users\gcb7\Documents\R\win-library\3.6\rmarkdown\rmd\latex\default-1.17.0.2.tex ),该模板没有此定义。此问题已在 GitHub 上修复,参见https://github.com/rstudio/rmarkdown/issues/1649 .

一种解决方法是复制 relevant lines到 Rmarkdown 模板的本地副本并通过 template 指定该副本 field 。或者你可以添加

\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newenvironment{cslreferences}%
  {\setlength{\parindent}{0pt}%
  \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces}%
  {\par}

\newenvironment{cslreferences}%
  {}%
  {\par}

结果tex文件通过 header-includes或类似的。或者您可以使用pandoc如果您安装了 RStudio,则它会附带。这可以通过前置 <rstudio-dir>/bin/pandoc/ 来完成到PATH ,可能在.Renviron内使其特定于 R。

一切都未经测试,因为我没有 pandoc 2.8 ...

关于r - 在 RStudio 中将 RMarkdown 编织为 PDF 时 Pandoc 的环境 cslreferences 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59193797/

相关文章:

应用于数据框中列表的 R 函数

python - 如何在 Python matplotlib 中的 LaTeXed 下标中包含字符串链

switch-statement - Latex 中的 Switch Case 条件输出

markdown - 如何为 R markdown 文档中的 toc 链接设置颜色?

r - 当我渲染 R markdown 时隐藏包加载消息

r - R 中的 log2 : How to calculate the exponent and mantissa

r - 一维矩阵更改为R中的向量

r - ggplot2 中辅助 y 轴的更好转换

latex - Overleaf : is it possible to select, 删除或同时移动多个文件?

r - 带有 revealjs r markdown 演示文稿的 ggplotly 工具提示