LaTeX lstlisting: Easily Copy&Paste Snippets from PDF

I regularly use LaTeX for documentation. While lstlisting is really great for printing snippets of code out of the box you may encounter some situations where you need to tweak it a little to fit your needs.

Imagine you have, e.g., some snippets of shell script in some documentation. If you want to reuse this code the most straight forward approach is to copy&paste it from the documentation PDF to your shell. Unfortunately, sometimes you may encounter some problems while doing this.

One issue you may encounter is that additional space characters are inserted into your precious pasted snippets; e.g.


may become something like

l i s t e n −a d d r e s s = 1 2 7 . 0 . 0 . 1 , 1 0 . 3 5 . 9 . 1

To get around this issue just add the following options either via \lstset or for each lstlisting element separately.


This entry was posted in Snippets and tagged . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.