# multido and fragile frames in beamer

I'm trying to use multido package to create a sequence of slides with multiple code snippets using listing. Unfortunately the fragile option leads to the following error:

! File ended while scanning use of \next.


Is there any workaround? Here is a minimal code to reproduce the error:

\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{multido}
\usepackage{listings}
\begin{document}

\begin{frame}[fragile]
\frametitle{test}
\begin{lstlisting}
import numpy as np
\end{lstlisting}
\end{frame}

\multido{\i=1+1}{7}{%
\begin{frame}[fragile]
\frametitle{\i}
\begin{lstlisting}
import numpy as np
\end{lstlisting}
\end{frame}
}

\end{document}


## Clarification from Manuel:

From my understanding, the question of the OP is the following.

• The OP wants to include listings (\usepackage{listings}) in beamer frames.
• In order to use listings, beamer requires the fragile frame option
• In addition, the OP wants to programmatically create the code for the frames, e. g. using \usepackage{multido} or pgffor package.
• The problem is that multido does not work together with the fragile option.
• Question: How can the OP programmatically create code for frames that contain listings.
• Fragile is a beamer option, not an option of multido. You may have a look here: tex.stackexchange.com/questions/11328/… Jun 2, 2021 at 14:44
• @C.Peters this example you pointed only shows how to define a frame with option fragile as default.
– LEo
Jun 2, 2021 at 16:48
• I added an -- in my opinion -- clearer problem statement, feel free to delete it if you don't like it. I try to help :). Jun 2, 2021 at 17:07

Not sure if I understand your question but if you remove the fragile option that the code works.

\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{multido}
\begin{document}
\multido{\i=1+1}{7}{%
\begin{frame}%[fragile]
\frametitle{\i}
\end{frame}
}
\end{document}


By the way, you can also use the pgffor package to create frames in a loop, see here. This approach also does not work with the fragile option according to the comments.

% Taken from https://tex.stackexchange.com/questions/544528
\documentclass{beamer}
\usepackage{pgffor}
\begin{document}
\foreach \nn in{a,b,c,duck}{
\begin{frame}
\frametitle{Image \nn}
\centering
\includegraphics[width=0.8\textwidth]{example-image-\nn}
\end{frame}
}
\end{document}

• @dr-manuel-kuehner I've updated the example, maybe it is more clear now.
– LEo
Jun 2, 2021 at 16:39
• @dr-manuel-kuehner pgffor gives the same error when using fragile option.
– LEo
Jun 2, 2021 at 16:52
• @LEo Yes, that is what I wrote in the answer: "This approach also does not work with the fragile option according to the comments." It was unclear from your question (for me) that you need the fragile option. Jun 2, 2021 at 17:01