本文介绍了在RStudio中将RMarkdown编织为PDF时,Panddoc的环境cslreferences未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试创建引文(对于Pandoc 2.8.0.1版和R版本3.6.1版)时,将RMarkdown文件编织(在RStudio版本1.2.1335中)失败为PDF. (例如,在编织为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

将其编织为最终输出(在我的机器上):

这似乎是在最近对Pandoc 2.8.0.1更新之后开始的,而我只是在 https:/上找到/pandoc.org/releases.html ,它在2.8版中似乎对cslreferences环境进行了一些更改(但到目前为止,在pandoc讨论中或相应的github bug跟踪器上似乎都什么都没有出现)

有什么想法吗?

解决方案

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

一种解决方法是复制相关行到Rmarkdown模板的本地副本,然后通过template字段进行指定.或者,您可以添加

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

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

通过header-includes或类似文件

到生成的tex文件.或者,如果安装了RStudio,则可以使用RStudio随附的pandoc.这可以通过将<rstudio-dir>/bin/pandoc/放在PATH之前(可能在.Renviron内)以使其特定于R来实现.

所有内容都未经测试,因为我没有pandoc 2.8 ...

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). (This does not happen when knitting to HTML, for example.)

Here is a small rep. ex. in 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):

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).

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. 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. This has been fixed on GitHub, c.f. 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. 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. Or you could use the pandoc that comes with RStudio, if you have that installed. This can be accomplished by prepending <rstudio-dir>/bin/pandoc/ to the PATH, possibly within .Renviron to make it R specific.

Everything untested, since I do not have pandoc 2.8 ...

这篇关于在RStudio中将RMarkdown编织为PDF时,Panddoc的环境cslreferences未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 09:49