Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

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:

         prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},

The other way is:



\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
  commentstyle=\color{dkgreen},       % comment style
  stringstyle=\color{mauve},         % string literal style
  escapeinside={\%*}{*)},            % if you want to add LaTeX within your code
  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?

share|improve this question
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
add comment

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

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

share|improve this answer
Instead of suggestions it's best to provide a tested MWE –  percusse Apr 22 '13 at 19:45
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.