Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

latex

knitr

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.

like image 751
Michał Avatar asked Mar 26 '14 15:03

Michał


People also ask

How do I achieve black colour?

Creating shades of black color with primary colors Red, blue and yellow are the three primary colors for what colors make black paint when mixed together. Simply mix equal amounts of red, blue, and yellow together and you will get a nice black.

What makes black a black color?

In science, black is the absence of light. And colour is a phenomenon of light. But a black object or black images printed on white paper are made from pigment, not light. So artists must use their darkest colour of paint to approximate black.

What color goes with black?

Darker shades of blue such as navy, indigo, and cobalt are surprisingly chic paired with black, adding subtle depth and nuance.

What color do you add to Brown to make black?

Mix Brown with Blue = Black Ensure that close to half of the mixture is blue. Add a dab of burnt umber near your blue dab, and then swirl the two colors gently to yield black. You can adjust the amount of either color to create your desired shade of black.


1 Answers

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")
like image 108
Michał Avatar answered Sep 27 '22 18:09

Michał