# [texhax] listings.sty question: how to implement single-spacing

Tue Jun 16 17:41:49 CEST 2009

Hey folks,

I am using the wonderful listings.sty to typeset my code listings
for my thesis. Since I am using (have to use) double-spacing for the
flow text, I'd like to ensure single-spacing for listings to
conserve space, and because it actually increases the readability.

My attempts thus far have been foiled. The following does not work,
even though I can happily define the new environment with with
\lstnewenvironment if I don't try to use the singlespace environment
in its "constructor" and "destructor":

\documentclass{article}
\usepackage{listings,setspace}
\lstnewenvironment{mylisting}
{\begin{singlespace}\lstset{language=pascal}}
{\end{singlespace}}
\begin{document}
\begin{mylisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{mylisting}
\end{document}

This gives me:

% latex l.tex
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
[...]
Package: setspace' 6.7 <2000/12/01>
) (./l.aux) (/usr/share/texmf-texlive/tex/latex/listings/lstlang1.sty)
(/usr/share/texmf-texlive/tex/latex/base/omscmr.fd))
*
^--- cursor just stays here and I am in TeX command mode

Do you have any idea how to make it do what I want? How can
I typeset visually-appealing listings (with frames across multiple
pages, labels and captions, I don't care so much about syntax
highlighting) in singly-spaced?

Thanks,

--

"wickedness is a myth
invented by good people
to account for the curious attraction of others."
-- oscar wilde

`