r - Making knitr code blocks more cleanly cut-and-pastable -


i use knitr produce pdf documents example code can cleanly cut , pasted, don't seem able to.

an example of problems run into:

the knitr manual pdf includes code block (p.3):

## option tidy=true (k in 1:10) { j <- cos(sin(k) * kˆ2) + 3 print(j - 5) }  

when copied pdf , pasted r (or so, or etc.), yields:

## option tidy=true (k in 1:10) f j <- cos(sin(k) * kˆ2) + 3 print(j - 5) g  

see how first 2 code lines combined onto one, and, worse, { , } converted f , g?

my questions:

first, guess, other folks experience? happen on windows, or elsewhere well?

if it's not me, there easy workaround? using different font when compiling *.tex file produce *.pdf document easier copy-and-paste from?

(fwiw, if instead use minted highlight r code, don't have of same problems, know it's possible right.)

based on clues in this question , accepted answer, found using latex fontenc package set font encoding t1 fixes problems reported above. (see here explanation of why using t1 more or less officially recommended best practice latex documents of sorts. improved copy-and-pastability 1 of several reasons noted @ link.)

here's start of preamble in fixed document looks like:

\documentclass[a4paper]{article} \usepackage[t1]{fontenc} 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -