I'm trying to put some Python code on a beamer slide. I would like to take one big file and print it with lstinputlisting.

I've tried to set the frame fragile with:

\begin{frame} [fragile]

It compiles ok, but LaTeX seems to ignore me =(

Am I missing something?

  • 3
    You're missing a description of which behavior you're observing and how it differs from your expected/desired result. "LaTeX seems to ignore me" is not really informative.
    – Henning Makholm
    Sep 12 '11 at 22:12
  • Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question.
    – N.N.
    Sep 30 '11 at 11:34

Usually the allowframebreaks option allows that overlong content creates several frames. However, this seems not to work with \lstinputlisting. My suggestion is therefore to use a loop to include only e.g. 10 lines of code per slide. If this should really be done for a presentation is an own question, I only answer the technical part.

Here I use \foreach from pgffor to loop in steps of 10 from the first to the last page (120 in this example). Then \only<+> is used to create a new slide as part of the frame. I also added a subtitle to show the current line number. This requires some manually expanding because the loop variable isn't accessible otherwise.


\begin{frame}{My code}
    \foreach \n in {1,11,...,120} {%
            \edef\thesubtitle{{Lines \n--\m\ / 120}}%


This code creates 12 slides. You only need to adjust the title text and the maximum line number. Note that the fragile option is not required here because the frame doesn't actually include verbatim material directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.