I want to use lstinputlisting
to include a file with code within an lstlisting
block, which is defined through a new environment. However, the lstinputlisting
command itself, not the code, is reproduced verbatim in the code block. MWE:
\documentclass{minimal}
\usepackage{color}
\usepackage{listings}
\usepackage{verbatim}
\definecolor{customblue}{RGB}{235,241,245}
\lstnewenvironment{terminalblock}{%
\lstset{backgroundcolor=\color{customblue},
frame=single,
framerule=0pt,
basicstyle=\ttfamily,
breaklines=true,
columns=fullflexible}}{}
\begin{document}
\begin{terminalblock}
\lstinputlisting{code.cpp}
\end{terminalblock}
\begin{verbatim}
\verbatiminput{code.cpp}
\end{verbatim}
\begin{lstlisting}
\lstinputlisting{code.cpp}
\end{lstlisting}
\end{document}
The same problem occurs in the standard lstlisting
and verbatim
environments as well. The PDF document just contains \lstinputlisting{code.cpp}
three times, as shown.
Since the background of the block generated by the custom environment is the correct colour, so I think the configuration settings are working in the custom environment, but not lstinputlistings
. I don't know if it's relevant, but these are the contents of code.cpp
:
#include <iostream>
#define abusing using
abusing namespace std;
int main()
{
cout<<"Hello, world!"<<endl;
return 0;
}