When an Rnw file is converted to PDF with RStudio and knitr, the code blocks have a pleasant grey background colour (like they do here at SO). When I convert a md file to PDF, the background colour is white and I can't seem to change it. The knitr code decoration option background is only for LaTeX and has no effect in md.
How can I set a background colour for code blocks in the PDF I get from my md file? I see in some related questions that editing the markdown.css file might be relevant, but I'm not sure if that applies here since there's no html file in between the md and PDF files.
This effect can be reproduced using the knitr examples: Rnw source: knitr-minimal.Rnw and markdown source: 001-minimal.Rmd.
To convert Rnw to PDF I just click the 'compile PDF' button in RStudio. Here's what I do to convert md to PDF:
# Load packages
require(knitr)
require(markdown)
setwd("C:/Users/.../Desktop/")
# Process .md and .pdf files
filen <- "myfile"
knit(paste0(filen,".md"))
system(paste0("pandoc -s ", paste0(filen,"-out.md"), " -t latex -o ", paste0(filen,".pdf")))
Is there another way to convert md to PDF so I can get a coloured code background?
And this is zenburn:
And this is espresso

system()command, that is what thepandoc()function is for: yihui.name/knitr/demo/pandoc - Yihui Xiesystem()andpandoc()require approximately the same typing effort, so feel free to go withsystem():) - Yihui Xieknitrpackage. For me (and I'm sure many others), it's packages likeknitr,ggplot2,plyranddata.tablethat make a huge improvement to the versatility, accessibility and appeal ofR. - Ben