Reputation: 60462
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?
Upvotes: 14
Views: 1511
Reputation: 33940
Frankly I'm not sold on any of those knitr themes for B&W printing, they're all inferior to good old enscript -E<lang>
Here are the criteria I would consider important for legibility on a B&W printout, with italicizing and bolding as well as coloring:
#Comments should be italicized - very important
fn.name.declarations.should.be.heavily.bolded <- function(...) {
"strings should be bolded"
numbers, NA, Nan should be a different color (prints as something dark gray)
Your choice of how to treat variable names
Your choice of how to treat fncalls, builtins
You didn't say it specifically needed to be LaTex, so why not consider outputting PS or PDF format instead?
Upvotes: 0
Reputation: 60462
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")
Upvotes: 3
Reputation: 121067
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.)
Upvotes: 8