To further extend my recent question about new listings environments, found here: Multiple listings styles.
How do I define a new lstlistings
environment, via the command \lstnewenvironment
, and, be able to use the command \lstinputlisting
to draw the desired contents from file?
I am referring to newly created lstlistingenvironments
via the command \lstnewenvironment{MYENV}
. These are then accessed by
\begin{MYENV}
BODY
\end{MYENV}
Anything where BODY
is, gets formatted, including the command \input{mycode.whatever}, instead of pulling the contents of the file mycode.whatever
and formatting the contents.
Best Answer
If the file contains the appropriate listing environment (like
cplusplus
orrcode
), then you can just use\input{<filename>}
. If it doesn't (or just contains the raw code that should be formatted), you can create a new command that does all of the setup for you, just like it would for your\lstnewenvironment
creations. The following can be used in conjunction with the solution in Multiple listings styles:The macros provided for inputting a listing of a specific type are
\lstinputcplusplus[<options>]{<filename>}
,\lstinputrcode[<options>]{<filename>}
and\lstinputpseudocode[<options>]{<filename>}
.