I include some code or file contents in a pdf through the use of the
listings package. For convenience, sometimes I like to add line numbers the
the listings. The problem is, when I add the line numbers, the code cannot
be easily copy-pasted from the pdf, because the line numbers are copied too
(I mean with acrobat, with xpdf it is possible to select a rectangular
region of text).
Does anyone have a solution or suggestion for this? Maybe attaching the file
(better if it were accessible with a right-click on the code, or something
like that)?
Thanks in advance.
--
Ignacio __ Fernández Galván
/ /\
Linux user / / \ PGP Pub Key
#289967 / / /\ \ 0x01A95F99
/ / /\ \ \
http://djelibeibi.unex.es
/________\ \ \
jellby \___________\/ yahoo.com
AFAIR there is the attachfile package for attaching files to PDFs.
Though it might only be Adobe Reader that actually supports attached files.
/daleif
> Hi all,
>
> I include some code or file contents in a pdf through the use of the
> listings package. For convenience, sometimes I like to add line numbers the
> the listings. The problem is, when I add the line numbers, the code cannot
> be easily copy-pasted from the pdf, because the line numbers are copied too
> (I mean with acrobat, with xpdf it is possible to select a rectangular
> region of text).
If the language in question has a construct for "comment until EOL",
say, //, format the line numbers as //\thelstlineno and put them on
the right. (Winged comments /* */ don't work as well because of
nesting behaviour.)
It's prabably not the most beautiful solution, but it works.
HTH
Ulrich
--
http://talcum.sarovar.org/ (Current release: 0.5.138 20050911)
You could add empty replacement text, so that line numbers will be
displayed but not copied:
\documentclass{article}
\usepackage{listings}
\lstset{numbers=left,numberstyle=\tiny}
\makeatletter
\def\lst@PlaceNumber{%
\llap{\normalfont
\pdfliteral direct{/Span<</ActualText()>>BDC}%
\lst@numberstyle{\thelstnumber}%
\pdfliteral direct{EMC}%
\kern\lst@numbersep}}
\makeatother
\begin{document}
\begin{lstlisting}
foo
bar
baz
\end{lstlisting}
\end{document}
Regards,
--
Robert
> The problem is, when I add the line numbers, the code cannot
> be easily copy-pasted from the pdf, because the line numbers are copied too
> (I mean with acrobat, with xpdf it is possible to select a rectangular
> region of text).
Both with Acrobat 5.05 (full) and with Acrobat Reader 5.05
- I don't know if this works with more recent Acrobat
releases also - you can select a rectangular region of text:
Mouse-click on the small triangle near the "Text-Select"-symbol.
[The symbol looks like a large T with a small rectangular box
on the right (formed by dashed lines)].
Then you get a menu with two or three items from which you
can choose the "Column-Select-Tool". [The associated symbol
looks like the "Text-Select"-symbol but this time within a
rectangular "dashed box" instead of the box on the right.]
If you are interested, I can post a small screen-shot to your
e-mail address.
Ulrich
> Both with Acrobat 5.05 (full) and with Acrobat Reader 5.05
> - I don't know if this works with more recent Acrobat
> releases also - you can select a rectangular region of text:
It is also possible with Adobe Reader 7.0.9 and Adobe Acrobat Standard 7.0
Regards,
Dominik.-
> Both with Acrobat 5.05 (full) and with Acrobat Reader 5.05
> - I don't know if this works with more recent Acrobat
> releases also - you can select a rectangular region of text:
>
> Mouse-click on the small triangle near the "Text-Select"-symbol.
I think I know what you mean. Unfortunately, it doesn't seem to be possible
with Adobe Reader 7.0.8 under linux. There's just no "small triangle" on
the select tool, and I don't see any menu item that could help.
>> I include some code or file contents in a pdf through the use of the
>> listings package. For convenience, sometimes I like to add line numbers
>> the the listings. The problem is, when I add the line numbers, the code
>> cannot be easily copy-pasted from the pdf, because the line numbers are
>> copied too (I mean with acrobat, with xpdf it is possible to select a
>> rectangular region of text).
>
> You could add empty replacement text, so that line numbers will be
> displayed but not copied:
Great! That's exactly the kind of thing I was looking for.
For the record, I included this code (overriding the definition in
lstmisc.sty) in my file, so I could selectively set the behaviour (it adds
the options "phantomleft" and "phantomright" to the "numbers" keyword).
\lst@Key{numbers}{none}{%
\let\lst@PlaceNumber\@empty
\lstKV@SwitchCases{#1}%
{none&\\%
left&\def\lst@PlaceNumber{\llap{\normalfont
\lst@numberstyle{\thelstnumber}\kern\lst@numbersep}}\\%
right&\def\lst@PlaceNumber{\rlap{\normalfont
\kern\linewidth \kern\lst@numbersep
\lst@numberstyle{\thelstnumber}}}\\%
phantomleft&\def\lst@PlaceNumber{\llap{\normalfont
\pdfliteral direct{/Span<</ActualText()>>BDC}%
\lst@numberstyle{\thelstnumber}%
\pdfliteral direct{EMC}%
\kern\lst@numbersep}}\\%
phantomright&\def\lst@PlaceNumber{\rlap{\normalfont
\pdfliteral direct{/Span<</ActualText()>>BDC}%
\kern\linewidth \kern\lst@numbersep
\lst@numberstyle{\thelstnumber}%
\pdfliteral direct{EMC}}}%
}{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}
I don't know what others will think, but I believe this would be a very
useful feature for the listings package.
Thanks for the code!
>I don't know what others will think, but I believe this would be a very
>useful feature for the listings package.
Indeed! But it would be nice if it were device driver independent,
where available.
Michele
--
>It's because the universe was programmed in C++.
No, no, it was programmed in Forth. See Genesis 1:12:
"And the earth brought Forth ..."
- Robert Israel in sci.math, thread "Why numbers?"