I am trying to use the combine
document class (manual) to combine several pre-existing documents into a single file with consistent formatting. It works great, except that there is a conflict of some kind with the listings pacakge. When I try compiling with \usepackage{listings}
in my main document file, I get
ERROR: LaTeX Error: Command \c@lstlisting already defined.
--- TeX said ---
Or name \end... illegal, see p.192 of the manual.
This happens even without any usage of the package.
My guess is that the listings package automatically defines some things at each \begin{document}
, and this is causing the trouble? (I'm really not sure if that is even possible, but that's what it looks like…)
Does anybody have any ideas for a workaround? (For the time being I'll just use verbatim
environments for my code snippets, but I'd love to have the syntax highlighting etc. provided by listings.)
Edit: Here's a minimal version of a document with the error:
\documentclass{combine}
\usepackage{listings}
\begin{document}
\begin{papers}
\coltoctitle{Title}
\coltocauthor{Author}
\label{lbl}
\import{test}
\end{papers}
\end{document}
with another file, test.tex
in the same directory, which can have anything in it, so long as its valid tex. For my minimal example, I did
\documentclass{article}
\begin{document}
Hello world
\end{document}
If \usepackage{listings}
is commented out, it compiles fine. If it is uncommented, it gives the error as shown.
Best Answer
The
\c@lstlisting
macro is thelstlisting
counter. You could try\makeatletter\let\c@lstlisting\@undefined\makeatother
short before the line where the error appears to official declare the macro undefined. Also often a\relax
is used instead of\@undefined
.