It seems as if the listings package can not be loaded after all other packages using \AtBeginDocument
\documentclass[]{scrbook} %
\AtBeginDocument{\RequirePackage{listings}}
\begin{document}
\end{document}
This raises the error
! Undefined control sequence.
<argument> ... \iffalse }{}\lst@ifnumberbychapter
In the code sequence
\AtBeginDocument{
\@ifundefined{thechapter}{\let\lst@ifnumberbychapter\iffalse}{}
\lst@ifnumberbychapter
\newcounter{lstlisting}[chapter]
\gdef\thelstlisting%
{\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@lstlisting}
\else
\newcounter{lstlisting}
\gdef\thelstlisting{\@arabic\c@lstlisting}
\fi}
Is this a bug or am I misusing \AtBeginDocument ?
