Hello,
I would really like to make a pdf that has code that can be copied and pasted into an editor and run, however, when I use:
\documentclass{article}
\usepackage{listings}
\begin{document}
\lstset{language=C}
\begin{lstlisting}
// Basic command
fprintf("I'm sad this doesn't work");
\end{lstlisting}
\end{document}
And copy and paste from the resultant pdf into a text editor, it looks like this:
// B a s i c command
f p r i n t f ( ” I ’m sad t h i s doesn ’ t work ” ) ;
I'd like to not have those spaces between each letter. I have tried tweaking things with \lstset, however, nothing I have tried yet seems to work.
Text Formatting ⇒ Using listings to create code that can be copied and pasted
NEW: TikZ book now 40% off at Amazon.com for a short time.

Using listings to create code that can be copied and pasted
Add this option to your \lstset command:
You may also want to use a monospaced font for your code listings; it just looks better. I use the beramono package for that. Here's how I would do your code:
Code: Select all
columns=fullflexible
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage[T1]{fontenc}\usepackage[scaled=0.80]{beramono}\usepackage{listings}\usepackage{xcolor}\definecolor{code}{HTML}{ECF8F4}\definecolor{comments}{HTML}{5269A5}\lstloadlanguages{C}\lstset{%language=C,showstringspaces=false,lineskip=1pt,xleftmargin=0.06\textwidth,linewidth=0.99\textwidth,columns=fullflexible,backgroundcolor=\color{code},keepspaces=true,breaklines=true,basicstyle={\small\fontfamily{fvm}\fontseries{m}\selectfont},keywordstyle={\small\fontfamily{fvm}\fontseries{b}\selectfont},commentstyle={\color{comments}\small\fontfamily{fvm}\itshape\selectfont},belowcaptionskip=10pt,float=h,label=lst:squiggle,caption={\quad Program listing for squiggle.c: no more spaces!}}\begin{document}\begin{lstlisting}[frame=single,framerule=0pt]// Basic commandfprintf("I'm sad this doesn't work");\end{lstlisting}\end{document}