0

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.
LEo
  • 772
  • Fragile is a beamer option, not an option of multido. You may have a look here: https://tex.stackexchange.com/questions/11328/beamers-fragile-frame-as-default – C. Peters Jun 02 '21 at 14:44
  • @C.Peters this example you pointed only shows how to define a frame with option fragile as default. – LEo Jun 02 '21 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 :). – Dr. Manuel Kuehner Jun 02 '21 at 17:07

1 Answers1

1

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}

enter image description here

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 02 '21 at 16:39
  • @dr-manuel-kuehner pgffor gives the same error when using fragile option. – LEo Jun 02 '21 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. – Dr. Manuel Kuehner Jun 02 '21 at 17:01