How to achieve black&white-friendly syntax highlighting in PDFs produced with knitr

StackOverflow https://stackoverflow.com/questions/22666475

  •  21-06-2023
  •  | 
  •  

Question

I am writing a document with knitr (Rnw to be processed to PDF) that will be printed in black&white. I still would like the code chunks to have syntax highlighting.

Is it possible, and how, to modify default syntax highlighting colors to use some shades of gray etc.?

PS. I do not want to switch to LaTeX 'listings' package.

Était-ce utile?

La solution

As suggested by @Roland, knitr themes (?knit_theme) do the job. In particular, the print theme seems to suite black-and-white printing best. A gallery of all built-in knitr themes can be found here http://animation.r-forge.r-project.org/knitr/

In particular, to set print theme in my Rnw document put this in the initial R code chunk:

opts_knit$set( out.format="latex" )
knit_theme$set("print")
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top