Created attachment 116825 [details] Created PDF file SUMMARY When copying listings produced with latex there are extra spaces between the characters, so it is not possible to use the copied text. STEPS TO REPRODUCE 1. Copy listing from the attached pdf or create a new pdf with the following code: \documentclass[10pt,a4paper]{article} \usepackage[latin1]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{graphicx} \usepackage{listings} % Syntax Highlining, Programmier sprachen \begin{document} \begin{lstlisting}[language=bash,caption={Skript um für Eclipse die Projektdateien zu erstellen}] #!/bin/bash sudo apt-get install libevdev-dev libglib2.0-dev sudo apt-get install libpcre3 libpcre3-dev lzma lzma-dev \end{lstlisting} \end{document} 2. Copy one line from the listing and paste it somewhere OBSERVED RESULT sudo apt−g e t i n s t a l l l i b e v d e v −dev l i b g l i b 2 .0− dev EXPECTED RESULT sudo apt-get install libevdev-dev libglib2.0-dev SOFTWARE/OS VERSIONS Linux/KDE Plasma: Gnome 3.30.2, Arch Linux KDE Frameworks 5.52.0 Qt 5.11.2 (kompiliert gegen 5.11.2) Das xcb Fenstersystem ADDITIONAL INFORMATION
I'm sure this is not an okular bug, because it also happens with pdftotext. pdftotext related to poppler, so it might be a poppler bug. $ pdftotext /tmp/OkularBug.pdf $ cat /tmp/OkularBug.txt Listing 1: Skript um für Eclipse die Projektdateien zu erstellen #! / b i n / b a s h sudo apt−g e t i n s t a l l l i b e v d e v −dev l i b g l i b 2 .0− dev sudo apt−g e t i n s t a l l l i b p c r e 3 l i b p c r e 3 −dev lzma lzma−dev 1 Looks like lstlisting with language=bash recognizes the dashes as short command line option, and tries to do some formatting.
Did you write a bugreport for poppler or should I do that?
No, I didn’t. But the same behavior appears in pdf.js, which is AFAIK not based on poppler. So it must be a bug in listings. Did you try with other arguments for the language option?
I tried with languate=C++ and it is the same. I think you are right. When I mark the text, I am able to select spaces between characters
By default, the spacing between characters is made uniform so as to preserve alignments (source: https://tex.stackexchange.com/questions/99416/latex-source-code-listing-with-less-space-between-characters) So this is not a problem of okular or any other library. This is to make the listing clearer to read and the spaces are in the listing it self. Setting "columns=fullflexible" solves the problem \documentclass[10pt,a4paper]{article} \usepackage[latin1]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{graphicx} \usepackage{listings} % Syntax Highlining, Programmier sprachen \begin{document} \begin{lstlisting}[columns=fullflexible, language=bash,caption={Skript um für Eclipse die Projektdateien zu erstellen}] #!/bin/bash sudo apt-get install libevdev-dev libglib2.0-dev sudo apt-get install libpcre3 libpcre3-dev lzma lzma-dev \end{lstlisting} \end{document}