4

I am using the lineno package to number the lines. However when I select a paragraph of text for copy and paste, the line numbers also get copied. How can I avoid this?

I did some searches but came across no easy fix, is there a different package or environment that I should be using?

enter image description here enter image description here

zmkm
  • 379

1 Answers1

3

Here, I use the accsupp package to redefine the \LineNumber to appear on the page, but not in the copy/paste metadata.

It is perhaps not surprising that the success of this approach will depend on the PDF reader used and whether it honors the results of accsupp (ACCessibility SUPPort). Adobe Reader behaves successfully, whereas Firefox does not.

\documentclass{article}
\usepackage{lineno,accsupp,lipsum}
\renewcommand\LineNumber{%
  \BeginAccSupp{method=escape,ActualText={}}\thelinenumber\EndAccSupp{}}
\begin{document}

\begin{linenumbers}[1] \lipsum[1-2] \end{linenumbers}

\end{document}

enter image description here

Copy and paste of the document gives the following

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra
metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus
eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium
quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean
faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur
auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue
eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim
rutrum.
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et,
tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna,
vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse
ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatibus et
magnis dis parturient montes, nascetur ridiculus mus. Aliquam tincidunt urna.
Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus mauris.
  • I tried in TeXShop and Overleaf (see image above) the numbers are still selected somehow – zmkm Apr 01 '22 at 18:35
  • 1
    @zmkm In my case, after compiling (in MikTeX), I opened up the resulting document in Adobe reader and it did not copy the line numbers. It would be interesting to see what happens if you open up your compiled document in an external reader (not TeXShop) – Steven B. Segletes Apr 01 '22 at 18:52
  • @StevenB.Segletes On a Mac, I get the same problem (the numbers are selected and copypasted) in TeXShop, in the Preview app, and if I open the PDF with Firefox. (Tested with OS 12 and an older OS X) – marquinho Apr 01 '22 at 19:06
  • 1
    @marquinho If I open the PDF in Firefox, it too copies the line numbers. In Adobe Reader, it does not. – Steven B. Segletes Apr 01 '22 at 19:40
  • 2
    Not all PDF readers respect the /ActualText attribute. – muzimuzhi Z Apr 01 '22 at 20:35