# Presentation that shows how to use lualatex to make a presentation

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.

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.

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

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}


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

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}