TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make it harder for students to just copy/paste code listings from the PDF.

How to achieve this? I want them to actually understand the code, close the book, and write from their minds.

Currently, lstlisting is setup like this

    basicstyle=\footnotesize\ttfamily, % Standardschrift
    numbers=left,               % Ort der Zeilennummern
    numberstyle=\tiny,          % Stil der Zeilennummern
    numbersep=5pt,              % Abstand der Nummern zum Text
    tabsize=4,                  % Groesse von Tabs
    extendedchars=true,         %
    breaklines=true,            % Zeilen werden Umgebrochen
    showspaces=false,           % Leerzeichen anzeigen ?
    showtabs=false,             % Tabs anzeigen ?
    showstringspaces=false      % Leerzeichen in Strings anzeigen ?        
    escapeinside={\%*}{*)},         % if you want to add a comment within your code
share|improve this question
Perhaps just list the crucial/interesting parts of the code, separately and not necessarily in the order in which they should appear in the full program. Students could still cut and paste from the listings, but would have to understand how the pieces fit together, who calls whom ... – Ethan Bolker Jul 16 '12 at 15:52
@EthanBolker that's not a good solution, they are beginners, I want to force them actually type in code. Some of them do not really understand that typing is crucial for programming, so they'll have to learn it "the hard way". – Flavius Jul 16 '12 at 15:55
You could use ewellic.org/mathtext.html to mangle your text before including it but depending on your TeX engine and font choices, it may confuse TeX as much as the students – David Carlisle Jul 16 '12 at 15:59
I'm afraid that if you want that the notes are readable, then any of the free OCR readers around the net will make any PDF mangling useless. Inserting the code as an image might discourage the students who wouldn't need to copy anyway, not the lazier ones. – egreg Jul 16 '12 at 23:08
Diametrically opposed to but related to tex.stackexchange.com/questions/148144/… – Jubobs Jan 15 '14 at 20:05

Use the standalone class and make a pdf for just the code. Now put that back into your directions as a graphic image. While there are way to extract text from an image, it is unlikely that beginning programmers will know how. Additionally if you want to make it much more difficult to use any form of copy-OCR analysis then write you code out by hand and then just scan in as an image to be included. Personally as a computer science instructor I warn the students that if they do not learn the fundamentals personally, that this early taking of 'shortcuts' will become very evident and penalized later in the course when it will be very difficult for any remediation.

share|improve this answer
Doesn't work for me. If I follow your approach, I can still copy the code (in Preview) and paste it into an editor. – Jubobs Jan 15 '14 at 20:09

Don't give them a pdf! Give them a paper; then they are forced to type in the code. That's the way I'm working with my LaTeX-Students. When all of them received different error and warning messages they get ready code to include in there own LaTeX code.

With showspaces=true and showstringspaces=true it could be a little bit harder for the students to copy the code.

share|improve this answer
How can that symbol be typeset in pure latex, outside of lstlisting? – Flavius Jul 16 '12 at 16:08
@Flavius It's \textvisiblespace – egreg Jul 16 '12 at 16:40
@Flavius: See Explicit space character? – Werner Jul 16 '12 at 17:11
The Ents are not gonna be happy about such waste of paper... – Jubobs Mar 10 '14 at 12:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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