\item Here follows the source code of this document.
    \item \lstinputlisting{sublisting.tex}
    \item And now the same again, one level nested.

When compiling this document as a draft, this yields the error

! LaTeX Error: Something's wrong--perhaps a missing \item.

Compiling without the draft class option works perfectly fine, as well as just removing the second listing. The first, although exactly similar apart from its itemization nesting depth, always compiles without problems. Passing draft to the class and final to the listings package also produces a valid document, but somewhat defeats the purpose of setting the option to star with.

Just the combination of nested itemization and \lstinputlisting seems to break. Why is this? Can it be avoided?


I am not sure why the 2nd level of itemized nesting is throwing the error, however, here are a couple of options that work, depending on your preference....

Option 1: If the impetus to using draft option is mainly to do with images, and saving compilation time when rendering images, then you can force the listings to display in final mode ALWAYS via the following:


Option 2: Else, another option is to kill off the listings function during draft mode via the following in the preamble:


Which will yield the following result:


In the 2nd option above, the filename is highlighted in red to indicate that the listing environment has been substituted with the source filename:

My personal preference is Option 1, since, the overall layout in draft mode is not reflective of what it would otherwise be in normal or final mode.

  • These workarounds are quite viable. But I would still be interested in why the problem occurs to start with. – XZS Nov 29 '13 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.