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.


listen-address=127.0.0.1, 10.35.9.1

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.


basicstyle=\ttfamily,
columns=fullflexible

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s