Rstudio pdf knit 因“Environment Shaded undefined"而失败错误 [英] Rstudio pdf knit fails with "Environment Shaded undefined" error

查看:94
本文介绍了Rstudio pdf knit 因“Environment Shaded undefined"而失败错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When trying to knit a PDF using a template from package rticles output: rticles::acm_article I get the following error:

! LaTeX Error: Environment Shaded undefined.

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

l.76 \begin{Shaded}

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

This appears to only happen when I include code chunks within the output document.

可重现的示例:

您需要使用 New Document -> 开始一个新的 R Markdown 文档.从模板 ->计算机协会.这是 R Markdown 文件:

You will need to start a new R Markdown document using the New Document -> From Template -> Association for Computing Machinery. Here is the R Markdown file:

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

然而,如果我在标题中设置 echo=FALSE,上面的例子就可以工作.您不会在输出中获得代码,但对于学术论文,您可能无论如何都不需要它,如果需要,您可以以不同的方式显示它.

This above example, however, works if I set echo=FALSE in the header. You won't get code in the output, but for an academic paper you probably don't need it anyway, an if you do you can display it in a different manner.

注意事项:

  • 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,正如 here,但我得到了同样的错误.
  • 我考虑过这种方法,但没有用,我仍然遇到错误(也许我需要调整以在我的上下文中工作,但不确定如何)
  • R version 3.3.1 (2016-06-21)
  • Platform: x86_64-pc-linux-gnu (64-bit),
  • running Ubuntu 16:10
  • I made sure I have the texlive-latex-base, texlive-latex-recommended, and texlive-latex-extra package installed, but still no luck
  • I also tried generating a pdf from the intermediate .tex file, as suggested here, but I get the same error.
  • I considered this approach, but it didn't work, I still got an error (maybe I need to tweak to work in my context, but not sure how)

推荐答案

所以,这里的问题是 rticles 模板有时会省略 pandoc 注入代码高亮环境的方法,例如阴影.要解决这个问题,您必须插入 template.tex 序言:

So, the issue here is the rticles templates sometimes omit a means for pandoc to inject code highlighting environments, e.g. Shaded. To get around this, you would have to insert into the template.tex preamble:

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

这篇关于Rstudio pdf knit 因“Environment Shaded undefined"而失败错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆