Let's list the printable ASCII characters:
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[]^_`{|}~Alphanumeric characters are always copyable. Many punctutation characters work out of the box if powerful fonts are correctly set up (e.g. with cm-super): . / : ; < = > ? @ [ ].
Many other characters just need to be escaped in order to be copy-pastable:
\#, \$, \%, \&, \{, \}
The problems start with " (double quotes), \ (backslash), ' (single quote, apostrophe), - (hyphen or minus), ^ (caret), | (pipe), ` (backtick, backquotes, accent grave), ~ (equivalency sign - tilde), _ (underscore).
It turns out that obtaining those characters is not straigthforward: it depends on your default fonts and on whether
\usepackage[T1]{fontenc} is present.Here are commands that might work:
- " (double quotes):
\verb|"|,\char34 - \ (backslash):
\textbackslash(with\usepackage{textcomp}),\verb|\|,\char124 - ' (single quote, apostrophe):
\textquotesingle(with\usepackage{textcomp}),\char"0D,\char39 - - (hyphen or minus):
\verb|-|,\texttt{-},\char45 - ^ (caret):
\verb|^|,\char94 - | (pipe): out of the box (sometimes),
\texttt{|},\char124 - ` (backquote):
\`{},\char"0D,\char96 - ~ (equivalency sign - tilde):
\verb|~|,\char126 - _ (underscore): \verb|~|,
\char95
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\begin{document}
\tiny{
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\char34\#\$\%\&\verb|\|\textquotesingle()*+,\verb|-|./:;<=>?@[]\verb|^|\verb|_|\`{}\{\texttt{|}\}\verb|~|
}
\end{document}
Without
\documentclass{article}
\begin{document}
\tiny{
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\verb|"|\#\$\%\&\verb|\|\char"0D()*+,\verb|-|./:;<=>?@[]\verb|^|\verb|_|\`{}\{\texttt{|}\}\verb|~|
}
\end{document}
See also Copy-pastable listings in PDF from LaTeX