[texhax] listings.sty question: how to implement single-spacing
Ulrike Fischer
news3 at nililand.de
Wed Jun 17 12:03:15 CEST 2009
Am Tue, 16 Jun 2009 17:41:49 +0200 schrieb martin f krafft:
> 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?
There is no need to use an environment. Use the command:
\documentclass{article}
\usepackage{listings,setspace}
\doublespacing %for test
\lstnewenvironment{mylisting}
{\singlespacing\lstset{language=pascal}}
{}
\begin{document}
\begin{mylisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{mylisting}
a\\b
\end{document}
--
Ulrike Fischer
More information about the texhax
mailing list