我正在尝试使用列表包从 LaTeX 生成的 PDF 中获取可复制粘贴的文本。
我有三个列表的行为都不如我所愿:
长行使用换行符进行折断
breaklines
,复制粘贴时换行符也会被复制(已在 Preview 和 Adobe 中测试)。我希望它不复制换行符(参见 MWE 中的示例)。剪切粘贴时,正确缩进和间隔的列表会以不同的方式显示。
例如,此列表:
\begin{lstlisting}[caption={Initial base.tf configuration}, language=java]
provider "aws" {
access_key = "abc123"
secret_key = "abc123"
region = "us-east-1"
}
\end{lstlisting}
变成:
provider "aws" { access_key = "abc123" secret_key = "abc123" region = "us-east-1"
}
我已将我的文档缩减为 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}