Bug 401944 - Copy listings created in Latex not copied properly
Summary: Copy listings created in Latex not copied properly
Status: RESOLVED NOT A BUG
Alias: None
Product: okular
Classification: Applications
Component: general (show other bugs)
Version: 1.5.3
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-10 08:59 UTC by Martin
Modified: 2020-04-28 12:40 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Created PDF file (32.67 KB, application/pdf)
2018-12-10 08:59 UTC, Martin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin 2018-12-10 08:59:39 UTC
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
Comment 1 Laura David Hurka 2018-12-10 13:53:56 UTC
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.
Comment 2 Martin 2020-04-28 09:53:10 UTC
Did you write a bugreport for poppler or should I do that?
Comment 3 Laura David Hurka 2020-04-28 11:39:51 UTC
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?
Comment 4 Martin 2020-04-28 12:33:20 UTC
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
Comment 5 Martin 2020-04-28 12:40:40 UTC
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}