# Using the “combine” document class with the listings package

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.

-
Can you recreate the error with a minimal version of your document?? Without that it is hard to tell. –  Martin Scharrer May 30 '11 at 21:52
The \c@lstlisting macro is the lstlisting 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. –  Martin Scharrer May 30 '11 at 21:55
Alright, I just added a minimal example... I will try \relaxing or using \@undefined and see what I get. Thanks for your help! –  TJ Ellis May 31 '11 at 0:12
Lo! adding \makeatletter\let\c@lstlisting\@undefined\makeatother just before the \import{} command worked! I also tested when including a document that actually uses listings -- still works :-) thanks a ton! –  TJ Ellis May 31 '11 at 0:15
@Martin if you add that as an answer, I'll accept it. It solved my problem. For future reference, it needs to be added before each \import -- on my actual document, I was including a number of them, and had to put it before each one, whether the imported document was using listings or not. –  TJ Ellis May 31 '11 at 0:27

The \c@lstlisting macro is the lstlisting 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.