I am using knitr to compile an rnw document containing both R and latex code, though it seems to also be a problem with the verbatim environment in general. The pdf looks fine, but when I try to copy and paste the code chunks, inverted commas are missing. I would like to be able to copy the code directly! It seems to only be a problem for some pdf readers - potentially only adobe reader - but would be good to be able to fix nevertheless. The following code compiles and displays as expected:



test <- 'trytocopythisfromthepdf'

\textquotesingle trytocopythisfromthepdf\textquotesingle


but when copying the text from adobe reader and pasting it, the single quotes from both the knitr block and verbatim environment are missing, though the upquotes from the textcomp package are fine:

library(knitr) test <- trytocopythisfromthepdf 'trytocopythisfromthepdf' trytocopythisfromthepdf

  • I cannot reproduce this problem: Pasted from my PDF output using this MWE : test <- 'trytocopythisfromthepdf' – Fran Sep 2 '17 at 4:15
  • Thanks. I double checked on another pc and it still happens, but using sumatra instead of adobe reader does let me copy the text properly. Would be good to get it working for adobe, given how common it is... – Charlie Sep 2 '17 at 9:55

I resolved this by including the following two lines in the preamble:

| improve this answer | |

With the default OT1 encoded Computer Modern fonts you can use


to resolve most of such copy&paste problems. The package adds a character map to the generated PDF.

Another suggestion would be to switch to a UTF8 engine like PDFTeX or LuaTeX. With current LaTeX this would also switch the font.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.