title: LaTeX listings package: copy-pastable listings
body: <p>Writing some docs with code snippets which I want to be copyable to run as written.  These snippets may include lines with preceding spaces.  The listings package formats the text fine, but the spaces are not copyable.</p>
  
  <p>Let's say I have the following example:</p>
  
  <pre><code>\documentclass{article}
  \usepackage{listings}
  \begin{document}
  \lstset{
      basicstyle=\ttfamily,
      frame=single,
      columns=fullflexible
  }
  \begin{lstlisting}[language=python]
  def foo():
      return "bar"
  \end{lstlisting}
  \end{document}
  </code></pre>
  
  <p>If I copy and paste the listing somewhere, it becomes:</p>
  
  <pre><code>def foo():
  return "bar"
  </code></pre>
  
  <p>which must be corrected by hand.</p>
  
  <p>Is there a way to make the listings package include the original spaces?  Or is there a package better suited for cases like this?</p>