4

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},
    frame=shadowbox,
    rulesepcolor=\color{Gray},
    escapeinside={\%*}{*)},         % if you want to add a comment within your code
    mathescape=false,
    columns=flexible
}
6
  • 1
    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 ... Jul 16, 2012 at 15:52
  • 1
    @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, 2012 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 Jul 16, 2012 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, 2012 at 23:08
  • 1
    Diametrically opposed to but related to tex.stackexchange.com/questions/148144/…
    – jub0bs
    Jan 15, 2014 at 20:05

2 Answers 2

4

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.

1
  • Doesn't work for me. If I follow your approach, I can still copy the code (in Preview) and paste it into an editor.
    – jub0bs
    Jan 15, 2014 at 20:09
2

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.

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

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.