I am trying to get good copy-n-paste'able text from a LaTeX generated PDF using the listings package.
I have three listings that all behave not as I'd like:
Long lines are broken using
breaklinesand when copy-n-pasted the linebreak is also copied (tested in Preview and Adobe). I'd like it to NOT copy the line break (see example in MWE).Correctly indented and spaced listings are displayed differently when cut-n-pasted.
For example, this listing:
\begin{lstlisting}[caption={Initial base.tf configuration}, language=java]
provider "aws" {
access_key = "abc123"
secret_key = "abc123"
region = "us-east-1"
}
\end{lstlisting}
Becomes:
provider "aws" { access_key = "abc123" secret_key = "abc123" region = "us-east-1"
}
I've cut down my doc to an MWE.
\documentclass[letterpaper,oneside,12pt]{book}
\usepackage[T1]{fontenc}
\usepackage[no-math]{fontspec}
% fonts
\setmainfont{Charis SIL}
% Listings
\usepackage{MnSymbol}
\usepackage{listings}
\usepackage{fancyvrb}
\newfontfamily{\lstsansserif}[Scale=.85]{DejaVuSansMono}
\lstset{
caption=\lstname,
fancyvrb=true,
basicstyle=\ttfamily\linespread{0.9}\lstsansserif,
tabsize=2,
numbers=none,
upquote=true,
showstringspaces=false,
breaklines=true,
literate={-}{-}1,
breakatwhitespace=false,
escapechar=\&,
columns=fullflexible,
keepspaces=true
}
\begin{document}
\begin{lstlisting}[language=bash, caption={Download the Terraform zip file}, language=bash]
$ cd /tmp
$ wget https://releases.hashicorp.com/terraform/0.7.7/terraform_0.7.7_linux_amd64.zip
\end{lstlisting}
\begin{lstlisting}[language=bash, caption={The base README.md file}, language=bash]
# Our first AWS configuration for Terraform
An initial configuration for Terraform.
## Usage
$ terraform apply
## License
MIT
\end{lstlisting}
\begin{lstlisting}[caption={Initial base.tf configuration}, language=java]
provider "aws" {
access_key = "abc123"
secret_key = "abc123"
region = "us-east-1"
}
\end{lstlisting}
\end{document}