[texhax] listings options
Lars Madsen
daleif at imf.au.dk
Tue Jan 3 16:07:14 CET 2012
Neal H. Walfield wrote, On 2012-01-03 15:54:
> Hi,
>
> I'm using the listings package to typeset some code. I have some
> short snippets that I'm including inline and some longer examples that
> I put in floats. I want to apply different options to each of these.
> For instance, I want the floating listings to have line numbers, but
> the inline listings shouldn't. Further, the inline listings should be
> slightly indented, but the floating listings shouldn't be.
>
> I thought I'd do the following:
>
> \usepackage{listings}
> \newcommand{\lstfloatsettings}{float, numbers=left}
> \newcommand{\lstinlinesettings}{xleftmargin=4ex, xrightmargin=4ex}
> \lstset{
> columns=fullflexible,
> % Don't use visible spaces in strings.
> showstringspaces=false,
> basicstyle=\small,
> captionpos=b,
> frame=single,
> }
>
> But, that doesn't work:
>
> \begin{lstlisting}[\lstfloatsettings, label=lst:example]
> ...
> \end{lstlisting}
>
> =>
>
> ! Package keyval Error: float, numbers=left undefined.
>
> See the keyval package documentation for explanation.
> Type H <return> for immediate help.
> ...
>
> Any ideas or suggestions for a better approach?
>
> Thanks,
>
> Neal
>
because of the expansion you canno store listings keys in macros. Use
listings styles instead, i.e.
\lstdefinestyle{mystyle}{
key-vals
}
and then use it via style=mystyle
very handy
--
/daleif
More information about the texhax
mailing list