If I generate listings code with line numbers and copy the result from the PDF I can not use it again as tex code. First the line numbers are included which they should not, second spaces are included which should not appear.
For example with this code:
\documentclass{scrbook}
\usepackage{listings}
\lstdefinestyle{demostyle}{
basicstyle=\small\ttfamily,
numbers=left,
stepnumber=1,
frame=single,
}
\begin{document}
\begin{lstlisting}[style=demostyle]
\textbf{\textit{foobar}}
\textit{\sffamily foobar}}
\end{lstlisting}
\end{document}
you get this result:
1 \ textbf {\ textit { foobar }}
2 \ textit {\ sffamily foobar }}
Here I found a solution in How to make listings code indentation remain unchanged when copied from PDF?.
\lstset{columns=flexible}
\lstset{keepspaces=true}
\makeatletter
\def\lst@outputspace{{\ifx\lst@bkgcolor\empty\color{white}\else\lst@bkgcolor\fi\lst@visiblespace}}
\makeatother
However it is not clear to me how reader-safe the solution is. It works for me in PDF-XChange. However, the line numbers are still copyable. Can this be solved as well?
Besides this problem - is it possible to add a link to the PDF which copies the code to the clipboard? The code should not be in a file, it shall be part of the PDF but nevertheless linked with a hyperlink as a file to download.
EDIT (embedfile does not what I expect)
\documentclass{scrbook}
\usepackage{embedfile}
\usepackage{filecontents}
\begin{filecontents*}{democode}
\so{letterspacing}, \\
\ul{underlining}, \\
\st{overstriking} \\
and \hl{highlighting}.
\end{filecontents*}
\begin{document}
Any Text.
\embedfile[]{democode.tex}
\embedfilesetup{view}
\end{document}
Basically the code compiles but nothing further is visible. From the doc I do not understand how this package shall be used anyway. Especially I do not know how to link or view the embedded files.
EDIT2 (attachfile)
I also tested the package attachfile. It links to a file, but the link is not text, but an annotation which is almost invisible. Tested with:
\textattachfile{democode.tex}{source code}
embedfilepackage (orattachfile/attachfile2) allows for this. – Werner Oct 02 '11 at 23:05// 127and put them to the end of the line. (If you can't figure out how to win, simply change the game. ;) ) – Ulrich Schwarz Oct 03 '11 at 07:21