2
%sublisting.tex
\documentclass[draft]{beamer}
\usepackage{listings}
\begin{document}
\begin{frame}[allowframebreaks]
  \begin{itemize}
    \item Here follows the source code of this document.
    \item \lstinputlisting{sublisting.tex}
    \item And now the same again, one level nested.
      \begin{itemize}
        \item
          \lstinputlisting{sublisting.tex}
      \end{itemize}
  \end{itemize}
\end{frame}
\end{document}

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?

2

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:

\usepackage[final]{listings}

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

\usepackage{ifdraft}
\ifoptiondraft{
    \renewcommand{\lstinputlisting}[1]{\texttt{\textcolor{red}{#1}}}
}{}

Which will yield the following result:

Example

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.

| improve this answer | |
  • 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.