The package fancyvrb
provides \begin{SaveVerbatim}
and \UseVerbatim
, which does almost exactly what I need. I want to use this with a custom lstlisting
environment. The environment looks exactly how I want it, with the backgroundcolor and everything (it's quite involved).
So what I need is some sort of \begin{SaveLstlisting}
and \UseLstlisting
, so I can store the contents of a lstlisting environment in a macro at one point and use it at a later point. How can I achieve this?
\lstinputlisting
. If you want to store the settings of the colors, fonts etc. then you can use\lstdefinestyle
and use the defined style for multiple code fragments.\usesnippet{snippetA}{listingOne}{listingTwo}
where listingOne and listingTwo refer to a different listing each. I guess it could work with an extra file, but it would be nice if I could do it without that. Maybe thefilecontents
will do what I need? I just had that idea.