Making Source Code Copyable with listings [duplicate]

I'm using listings to display some matlab code in my latex document but i'd like to have syntax highlighting. I've tried two ways of getting syntax highlighting and neither make the code copyable. The first is:

`````` \usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\lstset{
backgroundcolor=\color{lbcolor},
tabsize=4,
rulecolor=,
language=matlab,
basicstyle=\scriptsize,
upquote=true,
aboveskip={1.5\baselineskip},
columns=fixed,
showstringspaces=false,
extendedchars=true,
breaklines=true,
prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
frame=single,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\color[rgb]{0,0,1},
stringstyle=\color[rgb]{0.627,0.126,0.941},
}
``````

The other way is:

``````\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{ideablue}{RGB}{1,24,146}

\lstset{ %
language=matlab,                % the language of the code
basicstyle=\footnotesize,           % the size of the fonts that are used for the code
numbers=left,                   % where to put the line-numbers
numberstyle=\tiny\color{gray},  % the style that is used for the line-numbers
stepnumber=1,                   % the step between two line-numbers. If it's 1, each line
% will be numbered
numbersep=5pt,                  % how far the line-numbers are from the code
backgroundcolor=\color{white},      % choose the background color. You must add         \usepackage{color}
showspaces=false,               % show spaces adding particular underscores
showstringspaces=false,         % underline spaces within strings
showtabs=false,                 % show tabs within strings adding particular underscores
frame=single,                   % adds a frame around the code
rulecolor=\color{black},        % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
tabsize=2,                      % sets default tabsize to 2 spaces
captionpos=b,                   % sets the caption-position to bottom
breaklines=true,                % sets automatic line breaking
breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace
title=\lstname,                   % show the filename of files included with     \lstinputlisting;
% also try caption instead of title
keywordstyle=\color{ideablue},          % keyword style
stringstyle=\color{mauve},         % string literal style
morekeywords={*,...},              % if you want to add more keywords to the set
deletekeywords={...}              % if you want to delete keywords from the given language
}
``````

But neither of these make the code copyable. So what can I do so that the source code is copyable?

-
Maybe this link could help: monperrus.net/martin/copy-pastable-listings-in-pdf-from-latex –  Sašo Živanović Feb 7 '13 at 10:10
For large code snippets, copy pasting is always a pain. Another option is to also attach the file in the PDF (I use a setup that does this automatically with `vim` module in ConTeXt; something similar should be possible in LaTeX with the hyperref package). –  Aditya Apr 22 '13 at 20:18
Is my answer at this link tex.stackexchange.com/questions/108118/… at all related to what you are trying to do? –  Steven B. Segletes May 3 '13 at 14:29

marked as duplicate by Jubobs, Andrew Swann, Claudio Fiandrino, Peter Jansson, Svend TveskægJan 16 at 15:30

try `\usepackage[T1]{fontenc}` in your preamble

-
Instead of suggestions it's best to provide a tested MWE –  percusse Apr 22 '13 at 19:45