Search code examples
rrstudior-markdownpdflatex

Rstudio pdf knit fails with "Environment Shaded undefined" error


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.

Reproducible example:

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: [email protected]
    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))
```

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.


Notes:

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

Solution

  • 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$