5

When I include code snippets in my documents, my lazier readers, i.e. students :), are often tempted to just copy and paste those snippets instead of typing them themselves. However, there are risks associated with that practice.

                         enter image description here

Copying and pasting of listings is the subject of numerous questions on the site; at the time of writing this question, the search copy paste [listings] is:question returns at least ten questions relevant to that problem. The answers to those questions show that the problem remains, by and large, unsolved.

Therefore, instead of letting my readers run the risk of saving an imperfect copy of one of my listings to their "clipboard", I'd like to preclude them from copying anything from my listings. Niet. Nada. Nichts. Rien du tout! Because I still want to make the source code available to them, though, I plan to embed it in the PDF instead.

How can I preclude my readers from copying my listings?

Notes:

  1. My question is related to Mangling listings source code. However, I cannot afford to export the listings as raster images only to import them back as graphics is not an option, because I want to keep the listings in vectorised format.

  2. Also, I do not want to encrypt the whole PDF as in Is it possible to produce a PDF with un-copyable text?. I simply want to forbid copying of my listings.

  3. I don't care that OCR can be used to recover my listings. I suspect most of my users wouldn't know how to use OCR or wouldn't do it just to avoid having to type a listing themselves.

jub0bs
  • 58,916
  • You could export it and convert the text to curves? Then you still have vectors, but no text to copy anymore. – Juri Robl Feb 26 '14 at 23:27
  • 1
  • @Jubobs: I just added for both questions the tag [tag:copy-paste]. – Speravir Feb 26 '14 at 23:36
  • Maybe I'm not reading you correctly, but if you're making the source code available anyway, why do you care if they're able to copy/paste the listing? – Paul Gessler Feb 26 '14 at 23:37
  • @PaulGessler Because 1) I think copying & pasting is more natural to most people than extracting source code from a PDF, and 2) even if I tell my readrs how to extract the source code from the PDF, I'm ready to bet that a non-negligible fraction of them will attempt to copy & paste, thereby causing me a lot of pain. – jub0bs Feb 26 '14 at 23:40
  • 1
    Just give the listing and a link in the PDF to download the code. Yes, there will always be dimwits doing it the hard way. As the saying here goes, "If they could fly, nobody would see the sun." – vonbrand Feb 26 '14 at 23:51
  • @vonbrand I like the quote, and I'll consider your approach, but the question stills stands. – jub0bs Feb 26 '14 at 23:59
  • The original quote is quite rude (in Spanish, impossible to translate). – vonbrand Feb 27 '14 at 00:25
  • It may not be ideal, but what about enclosing your listings in precompiled graphics ? It's a workaround. – 1010011010 Aug 07 '14 at 16:52
  • @1010011010 I address that possibility in the question. It doesn't suit me because I want to retain the crisp quality of vector graphics. – jub0bs Aug 07 '14 at 17:03
  • Isn't that a limitation of the conversion software? The standalone package allows for arbitrary resolutions, doesn't it? – 1010011010 Aug 07 '14 at 17:04
  • @1010011010 Are you suggesting saving the listing as PDF, then importing it in the main document? Unfortunately, text from the imported PDF can still be copied from the main document, and that would be too much hassle anyway. – jub0bs Aug 08 '14 at 12:41
  • I'm suggesting conversion to .png at high dpi (3000 would be a start?) through the global key convert=.png from the standalone package. I believe this makes use of "Image Magick" (http://www.imagemagick.org/). (See texdoc standalone, page 15 at the bottom.) – 1010011010 Aug 08 '14 at 14:48
  • @1010011010 Sorry for being obsessive, but I don't like raster format; also, using such a high dpi for graphics would dramatically increase the size of the main document. – jub0bs Aug 08 '14 at 14:58
  • It's understandable. When you do something in TeX, you of course want to have everything perfect. Just good won't cut it. I think the answer you're looking for is applying the solution in http://tex.stackexchange.com/questions/11307/is-it-possible-to-produce-a-pdf-with-un-copyable-text locally. I'll look into it over the next couple of days (not that much time on my hands, sorry). – 1010011010 Aug 08 '14 at 15:45

1 Answers1

2

Add a watermark!

You prevent an easy copy by adding a background picture with a watermark (»Don't copy!«) to every listing. A solution has been suggested here: https://tex.stackexchange.com/a/63590/4736 . I did not test that, but I presume you cannot copy only the listing, without the letters of the watermark.

Keks Dose
  • 30,892
  • Sorry for getting back to you so late. Thanks for your suggestion, but I don't the approach would work for listings spanning multiple pages. – jub0bs Mar 31 '14 at 12:59