0

I use pdflatex to convert my tex file, and I use lots of lstlisting due to the technical nature of the document. The main issue I have is in making the text copy/paste friendly. Please see the screenshot attached, for the #include and #define in C code, it looks like the text gets selected and copied as a column rather than as a line.

enter image description here

It leads to broken code when pasting it, with the first lines being #include only, and the lines after that being the name of the packages being including, making the code unusable.

Is there a way to force the copy of text to be on a line basis?

If it can be of any help, here is the style used for my lstlisting:

\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{lightgray}{rgb}{0.95,0.95,0.95}

\lstset{frame=tb,
  language=Bash,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=fullflexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
  breakatwhitespace=true,
  tabsize=3,
  upquote=true,
  backgroundcolor = \color{lightgray},
  xleftmargin=10pt,
  xrightmargin=10pt,
  framexleftmargin=10pt,
  framexrightmargin=10pt,
  keepspaces=true
}
  • 1
    Wellcome to TeX.SE! Which pdf viewer do you use? – Mensch Sep 15 '17 at 21:17
  • Evince in GNU/Linux, and this is for an exam with a focus on GNU/Linux, so most likely the reviewers will be using evince as well. – Loic Duros Sep 15 '17 at 21:22
  • Probably quite dependent on the PDF viewer. I would try omitting the syntax highlighting colors, maybe use fancyvrb instead of listings. Also, would it not be more straightforward to just distribute the listed sources as plain text files? That would be easier to use than copying and pasting ... – Michael Palmer Sep 16 '17 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.