Code listing in LaTeX beamer presentation frames

Bozhidar Batsov picture Bozhidar Batsov · Oct 8, 2010 · Viewed 7.8k times · Source

I'm trying to create a LaTeX beamer presentation that has several Java code listings. However, I encountered a very bizarre problem - my listing snippet causes a compilation failure when in the presentation, but works just fine in some other document.

\begin{frame}[Fragile]
  \frametitle{Test}
 \begin{lstlisting}
    public class SimpleClass {
      public static void main(String[] args) {
        System.out.println("Hello!");
      }
    }
  \end{lstlisting}
\end{frame}

If I remove this code from my presentation it will work just fine, but with it I get the error message:

===

ERROR: Paragraph ended before \lst@next was complete.

--- TeX said --- \par l.129

--- HELP --- A blank line occurred in a command argument that shouldn't contain one. You probably forgot the right brace at the end of an argument.

====

I'm totally at a loss here, because this exact listing works just fine in some regular report. I've searched around and found out that I should have the fragile attribute set for frames with listings in them, but this didn't change anything.

Thanks in advance for your help.

Answer

Svante picture Svante · Oct 8, 2010

I believe that the option fragile is meant to be entirely lowercase.