A token like \_
in the file name is not allowed, whereas _
is.
You can do
\newcommand{\namedinclude}[2]{%
\subsection{\texttt{#1}}%
#2\par
\begingroup\def\_{_}%
\lstinputlisting{#1}%
\endgroup
}
or
\newcommand{\namedinclude}[2]{%
\subsection{\texttt{\detokenize{#1}}}%
#2\par
\lstinputlisting{#1}%
}
but, in this case, you do
\namedinclude{perceptron_multilayer.h}{Multi-layer perceptron class definition}
However, I'd see better this as an environment:
\usepackage{xparse}
\newenvironment{codesection}{m}
{\subsection{\texttt{\detokenize{#1}}}}
{\par\lstinputlisting{#1}}
and use this as
\begin{codesection}{perceptron_multilayer.h}
Multi-layer perceptron class definition
with more words.
Even a new paragraph.
\end{codesection}
\subsection
doesn't take two arguments, but I guess that doesn't matter in this case.\lstinputlisting{a\_b}
is not allowed.