I'm writing a LaTeX document and want to include several listings for source code examples.

Is there a way to disable the selection of line-numbers when selecting the source code?

My prof just wants to copy/paste the source code from the final pdf-file without manually removing all the line numbers afterwards. Does anyone know how to fix this problem?


1 Answer 1


Unfortunately I really need the line numbers. I want to reference several lines within my text.

After I kept searching, I found a solution for this problem using the following snippet:

\lstset {


That way the line numbers won't be selected anymore. In addition using colums=flexible I get rid of the whitespaces when copy/pasting the source code out of the pdf-file.

  • 2
    Welcome to TeX.SX! This is pretty much the solution in the first question suggested as a duplicate ;-)
    – mafp
    Commented Jul 3, 2013 at 13:27