I am creating a beamer presentation, and I'm using the packages thmtools
, thm-restate
and listings
.
Inside one of my \frame
s, I want to create an example
block containing a code listing.
Later, I want to restate this entire block.
Unfortunately, lstlistings
inside restatable
blocks causes the following error, right before the \end{frame}
:
Package Listings Warning: Text dropped after begin of listing on input line 18.
)
! Missing } inserted.
<inserted text>
}
l.58 \end{frame}
How can I resolve this?
Since (in beamer documents) example
is a pre-defined theorem type, I am not creating one myself with \newtheorem
.
MWE:
\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{textcomp}
\usepackage{thmtools,thm-restate}
\usepackage{listings}
\lstset{language=[Sharp]C,
captionpos=b,
showspaces=false,
showtabs=false,
linewidth=\textwidth{},
breaklines=true,
showstringspaces=false,
breakatwhitespace=true,
escapeinside={(*@}{@*)},
basicstyle=\ttfamily\fontseries{c},
morekeywords=[1]{partial},
literate={\\\-}{}{0\discretionary{{\normalfont \texttildelow}}{}{}}
}
\title{Presentation}
%\subtitle{}
\institute[UoF]{University of Foo}
\author{derabbink}
\date{\today}
\begin{document}
\begin{frame}[fragile]
\frametitle{Code}
\begin{restatable}[Human readable code]{example}{humanCodeI}
\begin{itemize}
\item \emph{Wait} for `Click Me!' button to become enabled
\item \emph{Click} `Click Me!' button
\item \emph{Verify} that `Click Me!' button is disabled
\end{itemize}
\end{restatable}
% this causes an error
\begin{restatable}[C\# code]{example}{csCodeI}
\begin{lstlisting}
Button btn = GuiHelper.FindButton("Click Me!");
GuiHelper.WaitUntilEnabled(btn, Is.True);
GuiHelper.Click(btn);
Assert.That(GuiHelper.IsEnabled(ping), Is.False);
\end{lstlisting}
\end{restatable}
% this doesn't cause errors
% \begin{example}[C\# code]
% \begin{lstlisting}
% Button btn = GuiHelper.FindButton("Click Me!");
% GuiHelper.WaitUntilEnabled(btn, Is.True);
% GuiHelper.Click(btn);
% Assert.That(GuiHelper.IsEnabled(ping), Is.False);
% \end{lstlisting}
% \end{example}
\end{frame}
\end{document}