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?

marked as duplicate by Paul Gaborit, mafp, egreg, lockstep, Claudio Fiandrino Jul 3 '13 at 13:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Jul 3 '13 at 11:18

This question came from our site for professional and enthusiast programmers.


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 Jul 3 '13 at 13:27