Code styling for black and white documents

As other commenters have mentioned, you only really have a choice of altering a few shades of grey, plus bold and italics. Here's a stylesheet in loose order of most prominent to least prominent items. Your preference may vary.

.background {
  color: #ffffff;
}
.source, .output, .warning, .error, .message {
  padding: 0em 1em;
  border: solid 1px #f7f7f7;
}
.error, .warning, .message {
  font-weight: bolder;
  font-style: italic;
  color: #000000;
}
.keyword {
  font-weight: bolder;
  color: #000000;
}
.functioncall, .package {
  font-weight: bolder;
  color: #202020;
}
.source, .output, .number, .argument, .formalargs, .eqformalargs, .assignement, .symbol, .prompt {
  color: #404040;
}
.string {
  font-weight: bold;
  color: #606060;
}
.comment, .roxygencomment, .slot {
  font-style: italic;
  color: #808080;
}

The easiest way to make this available is to save as e.g., "knitr/themes/bw.css" in whichever library the knitr package is in. Then you can use it by calling

knit_theme$set("bw")

(Alternately, for a small amount of extra typing, you can provide knit_theme a path to the CSS file.)


There are now grey scale themes within knitr: greyscale0, greyscale1 and greyscale2. You can view all knitr themes via:

library("knitr")
knit_theme$get()

To set the theme in a knitr document, add (for example) the line

knit_theme$set("greyscale2")

Tags:

R

Latex

Knitr