Rstudio pdf knit失败,出现"Environment Shaded undefined"错误

HAV*_*AVB 3 r pdflatex rstudio r-markdown

当尝试使用包rticles中的模板编织PDF时,output: rticles::acm_article我收到以下错误:

! LaTeX Error: Environment Shaded undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.76 \begin{Shaded}
Run Code Online (Sandbox Code Playgroud)

这似乎只有在输出文档中包含代码块时才会发生.

可重复的例子:

您需要使用以下命令启动新的Markdown文档New Document -> From Template -> Association for Computing Machinery.这是R Markdown文件:

---
title: Short Paper
author:
  - name: I Am Me
    email: me@email.com
    affiliation: Fictional University
abstract: |
  This is the abstract.
  It consists of two paragraphs.
output: 
  rticles::acm_article:
    keep_tex: true
---


## Simple test

Code chuck follows:

```{r}
plot(rnorm(10))
```
Run Code Online (Sandbox Code Playgroud)

但是,如果我echo=FALSE在标题中设置,则上述示例有效.您不会在输出中获得代码,但对于学术论文,您可能无论如何都不需要它,如果您这样做,您可以以不同的方式显示它.


笔记:

  • R版本3.3.1(2016-06-21)
  • 平台:x86_64-pc-linux-gnu(64位),
  • 运行Ubuntu 16:10
  • 我确保我安装了texlive-latex-base,texlive-latex-recommended和texlive-latex-extra软件包,但仍然没有运气
  • 我也尝试从中间.tex文件生成一个pdf,如此处所示,但我得到了同样的错误.
  • 我考虑过这种方法,但它没有用,我仍然有错误(也许我需要调整才能在我的上下文中工作,但不知道如何)

coa*_*ess 10

因此,这里的问题是rticles模板有时会省略pandoc注入代码突出显示环境的方法,例如Shaded.要解决这个问题,你必须插入template.tex序言:

$if(highlighting-macros)$
$highlighting-macros$
$endif$
Run Code Online (Sandbox Code Playgroud)


Ray*_*Ray 6

我努力修复错误,实际上提出了另一个问题,经过相当多的实验和搜索其他相关问题/答案后,我能够回答这个问题。

简而言之,如果您知道template.tex文件的位置,那么上述由coatless 提供的解决方案非常有效。显然,在遇到有关文章和如何嵌入(缺少)LATEX的相关问题之前,我使用了错误的文件。

更长的答案可以在我的“另一个问题”中找到。以下是关键步骤供参考:

  1. 在 R 包 rticles 库中找到 template.tex 文件。如果您不知道在.libPaths()RStudio 控制台中使用包库的位置。然后按照自己的方式进入文章模板的资源子文件夹。就我而言: R-3.5.0/library/rticles/rmarkdown/templates/ieee_article/resources

  2. template.tex. 序言是该行之前的任何内容\begin{document}

    $if(highlighting-macros)$ $highlighting-macros$ $endif$

  3. 保存template.tex并返回 R/RStudio 并点击 knit 按钮。R 代码块现在可以很好地显示,如果您不使用echo = FALSE.

  • 您可以在 '''template.tex''' 文件的 'preamble' 中的任何位置插入 3 行修复,即行 \begin{document} 之前的任何位置。正如您在我的 [其他问题](/sf/ask/3611649961/和) (2认同)