# 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/… – jub0bs Jan 15 '14 at 20:05

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