Ger*_*rit 3 latex r pandoc knitr r-markdown
尝试创建引文时(在 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
Run Code Online (Sandbox Code Playgroud)
编织它作为最终输出(在我的机器上):
"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 错误:未定义环境 cslreferences。
这似乎是在最近更新 pandoc 2.8.0.1 之后开始的,我刚刚在https://pandoc.org/releases.html上发现,在 2.8 中似乎在 cslreferences 环境中进行了一些更改(但最多现在似乎没有任何内容出现在 pandoc-discuss 或相应的 github 错误跟踪器上)。
有任何想法吗?
使用时也遇到同样的问题thesisdown。这很令人困惑,因为 Ralf 的解决方案(添加 \newenvironment{cslreferences} )已经包含在 template.tex 文件中。
一段时间后我发现:
改变
\newenvironment{cslreferences}% 才能
\newenvironment{CSLReferences}%解决问题。
具体来说,如果您也遇到thesisdown问题,则必须更改 template.tex 文件。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$
Run Code Online (Sandbox Code Playgroud)
也如此处所述。
似乎默认的 Pandoc 模板也从版本 2.11 开始使用 \newenvironment{CSLReferences} (请参阅 Commit)
根据您链接的发行说明,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。
一种解决方法是将相关行复制到 Rmarkdown 模板的本地副本,并通过template字段指定。或者你可以添加
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newenvironment{cslreferences}%
{\setlength{\parindent}{0pt}%
\everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces}%
{\par}
Run Code Online (Sandbox Code Playgroud)
或者
\newenvironment{cslreferences}%
{}%
{\par}
Run Code Online (Sandbox Code Playgroud)
到结果tex文件通过header-includes或类似。或者你可以使用pandocRStudio 附带的,如果你安装了它。这可以通过<rstudio-dir>/bin/pandoc/在PATH,前加上来实现,可能在其中.Renviron使其特定于R。
一切都未经测试,因为我没有 pandoc 2.8 ...
| 归档时间: |
|
| 查看次数: |
2157 次 |
| 最近记录: |