[Tex/LaTex] Changing the syntax highlighting color in a Rmarkdown/beamer presentation

beamerrmarkdown

Which tex package does Rmarkdown use by default to implement syntax highlighting and how to change the highlighting colors?

I have written a style file which i use as a template for my beamer presentations written in Rmarkdown.

When I include a code chunk, e.g:


g = ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, size=cyl)) +
      geom_point() +
      theme(legend.position="none") 

This is visible in the knitted pdf as a code chunk as it apparently draws on some RMD defaults not specified in my style file.

By adding the following to the style file, I was able to change the background color of the code chunk and the font size:


\let\oldShaded\Shaded
\let\endoldShaded\endShaded
\renewenvironment{Shaded}{\footnotesize\oldShaded}{\endoldShaded}

\definecolor{shadecolor}{RGB}{      221,    219,    217}

Now I would also like to change the syntax highlighting color to better match the overall style of my template.

Best Answer

mwe

---
output:
  beamer_presentation:
    highlight: espresso
---

# foo

```{r,eval=FALSE}
g = ggplot(mtcars, aes(x=wt, y=mpg, 
      color=cyl, size=cyl)) +
      geom_point() +
      theme(legend.position="none")
```

For more styles: `pandoc --list-highlight-styles`
Related Question