13

In my presentation, I would like to have a listings environment that shows how to make a presentation. So far I have found that, when using listings in a presentation, we should pass the option fragile to the frame we want use the listings environment in. I then thought that the following would work (compiling with lualatex):

\documentclass[lualatex]{beamer}

\usepackage{listings}
\lstset{language={[LaTeX]TeX}}

\begin{document}
    \begin{frame}[fragile]{Minimum Working Example}
        \begin{lstlisting}
\documentclass[lualatex]{beamer}

\begin{document}
    \begin{frame}{I am the title of this slide!}
        I am some body text.
    \end{frame}
\end{document}
        \end{lstlisting}
    \end{frame}
\end{document}

This gives lua a panic attack:

PANIC: unprotected error in call to Lua API (object in use)

The first few latex errors are:

./test.tex:14: Missing } inserted.
} l.14 \end{frame}

./test.tex:14: LaTeX Error: \begin{lstlisting} on input line 2 ended by \end{be amer@framepauses}.

./test.tex:14: Extra }, or forgotten \endgroup.

When commenting out the lines \begin{frame} ... \end{frame} it compiles fine, as can be seen in the picture below.

output

Googling this I didn't get very far, mostly ending up on questions that had as answer that we should not forget to pass fragile to the frame when using listings. The difference between those questions and this one is that I am trying to put a frame in a listing, besides having a listing in a frame.

2
  • This problem also occurs with pdflatex and xelatex with the same LaTeX error.
    – Marijn
    Commented Oct 8, 2018 at 20:23
  • 5
    Put your example in an external file and use \lstinputlisting. The inner \end{frame} confuses beamer. Commented Oct 8, 2018 at 20:24

2 Answers 2

16

Another option is to use [containsverbatim]:

\documentclass[lualatex]{beamer}

\usepackage{listings}
\lstset{language={[LaTeX]TeX}}

\begin{document}
    \begin{frame}[containsverbatim]
    \frametitle{Minimum Working Example}
        \begin{lstlisting}
\documentclass[lualatex]{beamer}

\begin{document}
    \begin{frame}{I am the title of this slide!}
        I am some body text.
    \end{frame}
\end{document}
        \end{lstlisting}
    \end{frame}
\end{document}

enter image description here

Source: https://stackoverflow.com/questions/2981008/latex-issue-with-beamer-and-listings.

1
  • 2
    This is also more intuitive than fragile.
    – Abby
    Commented Oct 9, 2018 at 4:37
12

As a workaround you can apply the example from page 62 of the beamer user guide:

% !TeX TS-program = lualatex
\documentclass[lualatex]{beamer}

\usepackage{listings}
\lstset{language={[LaTeX]TeX}}

\newenvironment{slide}
    {\begin{frame}[fragile,environment=slide]}
    {\end{frame}}

\begin{document}
    \begin{slide}
    \frametitle{Minimum Working Example}
        \begin{lstlisting}
\documentclass[lualatex]{beamer}

\begin{document}
    \begin{frame}{I am the title of this slide!}
        I am some body text.
    \end{frame}
\end{document}
        \end{lstlisting}
    \end{slide}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .