1

I have this latex code

\documentclass{article}
\usepackage[lmargin=2.5cm,rmargin=2.5cm,tmargin=1.5cm,bmargin=3.5cm]{geometry}
\usepackage{listings}  % Environment meant for source code (useful for word-wrapping verbatim text)

\begin{document} \lstset{basicstyle = \verbatim@font,columns=fullflexible,numbers=left}

\begin{lstlisting} //Define Variables Test1_up = [XZ:This (Index)][1]; Test2_down = [XZ:This Index][1];

//Specify Parameter Values beta1 = .2238202445016966; beta2 = .6676275732948469; \end{lstlisting}

\end{document}

It shows:

enter image description here

And when the reader try to select the code to copy/paste it, the line numbers are also selected:

enter image description here

Does exists some latex feature that let the reader copy the code excluding the line numbers?

Thanks!

  • This is probably a duplicate of: https://tex.stackexchange.com/questions/57141/is-there-a-latex-trick-to-prevent-a-pdf-viewer-from-copying-the-line-number (see also https://tex.stackexchange.com/questions/57151/how-do-i-prevent-conflicts-between-accsupp-and-hyperref). Notice however that if it works or not depends a lot on the viewer. pdf.js (the embedded viewer in most browser) is normally quite bad at it. – Rmano Feb 19 '24 at 10:42
  • You can check it with https://circuitikz.github.io/circuitikz/circuitikzmanualgit.pdf --- in the browser, the line numbers are copied. But if you download it, for example in evince, you just copy the code. I do not think there is a solution to this... – Rmano Feb 19 '24 at 10:45
  • A solution could be that the numbers not typeset as letters but as PS paths. But I don't even know whether there exists a package for that ... – Jasper Habicht Feb 19 '24 at 10:53
  • See also https://tex.stackexchange.com/questions/4911/phantom-spaces-in-listings. In general, copy&paste from PDF is always a nightmare (especially if the language is sensitive to spaces --- Python is especially bad for that). – Rmano Feb 19 '24 at 10:53

0 Answers0