I would like to use knitr to produce pdf documents from which example code can be cleanly cut and pasted, but don't seem to be able to.
An example of the problems I run into:
The knitr manual pdf includes this code block (p.3):
## option tidy=TRUE
for (k in 1:10) {
j <- cos(sin(k) * kˆ2) + 3
print(j - 5)
}
When copied from the pdf and then pasted into R (or SO, or etc.), it yields:
## option tidy=TRUE
for (k in 1:10) f j <- cos(sin(k) * kˆ2) + 3
print(j - 5)
g
See how the first two code lines get combined onto one, and, worse, {
and }
get converted to f
and g
?
My questions:
First, I guess, is this something other folks experience? Does it happen just on Windows, or elsewhere as well?
If it's not just me, is there some easy workaround? Would using a different font when compiling the *.tex
file produce a *.pdf
document that is easier to copy-and-paste from?
(FWIW, if I instead use minted to highlight my R code, I don't have any of the same problems, so I know it's possible to get this right.)