I'm using lineno for a document. I have it configured to put line numbers in the margins of the document. I generate PDF using pdflatex. Here's the problem: when people copy a region of text in a PDF previewer (Acrobat, or Mac OS X's Preview), the line numbers are included in the text that's copied. This leads to confusing text when they paste it into another document or application.
Is there a way to make it so that the line numbers are ignored when someone copies text from within a PDF previewer? I would like just the main text to be copied, not the line numbers.
Best Answer
Using a method similar to that proposed in How to make listings code correct copyable from PDF and with hyperlink, the following works (at least in Adobe Reader).
The
accsupp
package provides accessibility support for PDFs. By using the\BeginAccSupp
and\EndAccSupp
group, the line numbers can be typeset in the PDF, but actually replaced by an empty space{}
. This is done by supplying the optionActualText={}
. As such, a simple redefinition of thelinenumber
counter (the basic/standard counter providing the line numbers forlineno
) printing mechanism\thelinenumber
does the trick: