# Mangling listings source code

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

``````\lstset{%
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
frame=b,
showspaces=false,           % Leerzeichen anzeigen ?
showtabs=false,             % Tabs anzeigen ?
xleftmargin=17pt,
showstringspaces=false      % Leerzeichen in Strings anzeigen ?
keywordstyle=\color{Red},
stringstyle=\color{OliveGreen},
identifierstyle=\color{Blue},
rulesepcolor=\color{Gray},
escapeinside={\%*}{*)},         % if you want to add a comment within your code
mathescape=false,
columns=flexible
}
``````
-
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 at 20:05
show 1 more comment

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.

-
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 at 20:09
With `showspaces=true` and `showstringspaces=true` it could be a little bit harder for the students to copy the code.
@Flavius It's `\textvisiblespace` –  egreg Jul 16 '12 at 16:40