LaTeX 列表包:可复制粘贴的列表
使用代码片段编写一些文档,我希望这些代码片段可以复制以按编写的方式运行。这些片段可能包含前面有空格的行。列表包的文本格式很好,但空格不可复制。
假设我有以下示例:
\documentclass{article}
\usepackage{listings}
\begin{document}
\lstset{
basicstyle=\ttfamily,
frame=single,
columns=fullflexible
}
\begin{lstlisting}[language=python]
def foo():
return "bar"
\end{lstlisting}
\end{document}
如果我将列表复制并粘贴到某处,它就会变成:
def foo():
return "bar"
必须手动更正。
有没有办法让listing包包含原来的空间?或者有没有更适合这种情况的包?
Writing some docs with code snippets which I want to be copyable to run as written. These snippets may include lines with preceding spaces. The listings package formats the text fine, but the spaces are not copyable.
Let's say I have the following example:
\documentclass{article}
\usepackage{listings}
\begin{document}
\lstset{
basicstyle=\ttfamily,
frame=single,
columns=fullflexible
}
\begin{lstlisting}[language=python]
def foo():
return "bar"
\end{lstlisting}
\end{document}
If I copy and paste the listing somewhere, it becomes:
def foo():
return "bar"
which must be corrected by hand.
Is there a way to make the listings package include the original spaces? Or is there a package better suited for cases like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这(很可能)不是列表(或乳胶)的问题,而是 PDF 渲染软件的问题。例如,在 OSX 上使用基于 PDFKit 的(预览、浏览等),我得到了您所描述的行为。但是,通过使用 Xpdf,可以正确复制文本。
This is (most likely) not a problem with listings (or latex at all), but with your PDF rendering software. For instance, with PDFKit-based (Preview, Skim, ...) on OSX, I get the behavior that you describe. By using Xpdf, however, the text is copied correctly.