简体   繁体   English

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

[英]Pandoc's environment cslreferences undefined when knitting RMarkdown to PDF in RStudio

Knitting (in RStudio version 1.2.1335) an RMarkdown file to PDF fails when trying to create citations (for pandoc version 2.8.0.1, and R version 3.6.1).尝试创建引文时(在 RStudio 版本 1.2.1335 中)将 RMarkdown 文件编织为 PDF 失败(对于 pandoc 版本 2.8.0.1 和 R 版本 3.6.1)。 (This does not happen when knitting to HTML, for example.) (例如,在编织到 HTML 时不会发生这种情况。)

Here is a small rep.这是一个小代表。 ex.前任。 in RMarkdown:在 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

Knitting this yields as final output (on my machine):编织它作为最终输出(在我的机器上):

"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 "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 " 输出文件:RepEx.knit.md

! LaTeX Error: Environment cslreferences undefined. LaTeX 错误:未定义环境 cslreferences。

This seems to have started after a recent update to pandoc 2.8.0.1, and I just found on https://pandoc.org/releases.html that in 2.8 a few changes seem to have been made in the cslreferences environment (but up to now there seems to have nothing appeared on pandoc-discuss or on the respective github bug tracker).这似乎是在最近更新 pandoc 2.8.0.1 之后开始的,我刚刚在https://pandoc.org/releases.html上发现,在 2.8 中似乎在 cslreferences 环境中进行了一些更改(但最多现在似乎没有任何内容出现在 pandoc-discuss 或相应的 github 错误跟踪器上)。

Any ideas?有任何想法吗?

According to the release notes you linked, cslreferences was introduced in version 2.8, including a suitable definition of this environment in the pandoc template.根据您链接的发行说明, cslreferences是在 2.8 版中引入的,包括在 pandoc 模板中对此环境的合适定义。 However, Rmarkdown is using its own template ( C:\\Users\\gcb7\\Documents\\R\\win-library\\3.6\\rmarkdown\\rmd\\latex\\default-1.17.0.2.tex in your case), which does not have this definition.但是,Rmarkdown 使用它自己的模板( C:\\Users\\gcb7\\Documents\\R\\win-library\\3.6\\rmarkdown\\rmd\\latex\\default-1.17.0.2.tex在你的情况下),它没有这个定义. This has been fixed on GitHub, cf https://github.com/rstudio/rmarkdown/issues/1649 .这已在 GitHub 上修复,参见https://github.com/rstudio/rmarkdown/issues/1649

One workaround would be to copy the relevant lines to a local copy of Rmarkdown's template and specify that via the template field.一种解决方法是将相关行复制到 Rmarkdown 模板的本地副本,并通过template字段指定。 Alternatively you could add或者你可以添加

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

or或者

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

to the resulting tex file via header-includes or similar.通过header-includes或类似方法生成的tex文件。 Or you could use the pandoc that comes with RStudio, if you have that installed.或者你可以使用 RStudio 附带的pandoc ,如果你安装了它。 This can be accomplished by prepending <rstudio-dir>/bin/pandoc/ to the PATH , possibly within .Renviron to make it R specific.这可以通过将<rstudio-dir>/bin/pandoc/预先添加到PATH ,可能在.Renviron以使其特定于.Renviron

Everything untested, since I do not have pandoc 2.8 ...一切都未经测试,因为我没有 pandoc 2.8 ...

Had the same issue when using thesisdown .使用thesisdownthesisdown了同样的问题。 Which was confusing, since the solution from Ralf (adding \\newenvironment{cslreferences} ) is already included in the template.tex file form thesisdown.这令人困惑,因为来自 Ralf 的解决方案(添加 \\newenvironment{cslreferences} )已经包含在模板.tex 文件中形成 thesisdown。

After some while I figured out:过了一会儿,我想通了:

Changing \\newenvironment{cslreferences}% to \\newenvironment{CSLReferences}% solves the problem.\\newenvironment{cslreferences}%更改为\\newenvironment{CSLReferences}%可以解决问题。

Specifically if you are also having this problem with thesisdown , you must alter the this in the template.tex file.特别是如果你也有thesisdown 的这个问题,你必须改变 template.tex 文件中的 this 。 The section in template.tex should look like this then: template.tex 中的部分应该如下所示:

$if(csl-refs)$
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newenvironment{CSLReferences}%
  {$if(csl-hanging-indent)$\setlength{\parindent}{0pt}%
  \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces$endif$}%
  {\par}
$endif$ 

As also describes here .正如这里也描述的。

Seems like the default Pandoc template also uses \\newenvironment{CSLReferences} since Version 2.11 ( see Commit )似乎默认 Pandoc 模板也使用 \\newenvironment{CSLReferences} 自 2.11 版( 请参阅 Commit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM