Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code styling for black and white documents

Tags:

r

latex

knitr

One of the nice things about knitr is that you can easily change the colouring of R code. However, most documents are printed in black and white. So would be a good styling setting for R code when printing documents using a black and white printer?

like image 891
csgillespie Avatar asked Jul 10 '12 20:07

csgillespie


2 Answers

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.)

like image 197
Richie Cotton Avatar answered Nov 10 '22 07:11

Richie Cotton


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")
like image 23
csgillespie Avatar answered Nov 10 '22 09:11

csgillespie