Generallstlisting and two-sided documents

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jbf987
Posts: 1
Joined: Tue Feb 16, 2010 10:37 pm

lstlisting and two-sided documents

Post by jbf987 »

I'm working on a book manuscript that uses two-sided printing templates. While lstlistings works fine as I've configured it, I've run into an interesting side effect of margin notes via \marginpar{} interacting with the line numbers from lstlistings - namely, when the line number is beyond two digits, the two collide.

While I can re-size the margins to lstlisting via x*margin options, many of the source code examples a quite long and the line breaks can become challenging to follow. I can similarly tweak the space allocated for the margin note, but that causes other problems.

I've found a better "appearing" method is to move the border edge and line numbers to the "inside" gutter margin. Thus, I'd like to use "frame=r,numbers=right" on even pages, and "frame=l,numbers=left" on odd pages.

Since this is beyond what lstlisting actually supports, I'm wondering if anyone else has encountered this and devised a way to make it work from a global setting? Or if I need to hack the style file directly? Manually editing each listing (there are hundreds) is simply beyond the scope of reason for this manuscript, particularly when the listings move around as parts of the text are modified.

Thanks for any input.

Cheers,
-josh

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply