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.


1 Answer 1


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 option ActualText={}. As such, a simple redefinition of the linenumber counter (the basic/standard counter providing the line numbers for lineno) printing mechanism \thelinenumber does the trick:

\usepackage{lineno}% http://ctan.org/pkg/lineno
\usepackage{accsupp}% http://ctan.org/pkg/accsupp
\usepackage{lipsum}% http://ctan.org/pkg/lipsum

\renewcommand{\thelinenumber}{% Line number printing mechanism

\linenumbers% Turn line numbering on

\lipsum[1-5]% Dummy text

enter image description here

  • Great, I didn't know about the ActualText feature in PDF until now. Thanks
    – topskip
    Oct 7, 2011 at 7:46
  • Thank you for this answer (complete with full working example, no less!). I didn't know accsupp existed. I tried it, and indeed it works, but apparently only in Acrobat; on Mac OS X 10.6, using Preview or a 3rd-party application like Skim, the full text (including line numbers) is still copied. Do you (or anyone else) have any thoughts about how to make it work for other PDF readers too? (In any case, thank you again for solving it for Acrobat; that's miles better than not having any solution.)
    – mhucka
    Oct 10, 2011 at 3:58
  • @mhucka: I work with Acrobat Reader 99.9% of the time. Therefore, I don't know about other alternatives. The accsupp documentation also suggests ActualText while referencing (only) Adobe Reader.
    – Werner
    Oct 10, 2011 at 4:54
  • OK, no problem; I'm happy with having at least this much of a solution. Thanks again!
    – mhucka
    Oct 13, 2011 at 0:05
  • @Werner What PDF viewer do you use? Your approach only seems viable for some viewers; it doesn't work in Mac OS X preview, for intance.
    – jub0bs
    Mar 31, 2014 at 13:02

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.