2

I've split an animated GIF into the frames and saved them as a PNG sequence. I use the beamer class and want to load the images from the sequence, replacing each other without an autostart animation.

\begin{frame}\frametitle{FooBar}
\foreach \x in {0,...,5} {
   \includegraphics<\x+1>[width=0.95\textwidth]{dbgp-setup2-\x.png}
}
\end{frame}

The compiler output says that

Latexmk: Missing input file: 'dbgp-setup2-.png' from line

The filename should be dbgp-setup2-0.png, dbgp-setup2-1.png etc.. Why does \x not work?

Werner
  • 603,163
  • 2
    Welcome! Try \foreach \x [count=\y] in {0,...,5} { \includegraphics<\y>[width=0.95\textwidth]{dbgp-setup2-\x.png} } The parser does not know that it should compute the argument of <....>, so you have to do that. –  Feb 28 '19 at 00:29
  • Are you sure dbgp-setup2-0.png, dbgp-setup2-1.png, ... are in the working folder? – Werner Feb 28 '19 at 01:00
  • @Werner yes they are. I've included \graphicspath{ {./img/} } before. The package graphicx is also loaded. – Christian Feb 28 '19 at 21:31
  • @Christian: The solution to the question seem to be related to \foreach that isn't defined. As such, the \x isn't defined, leading to the missing number in the image reference. For future reference, include a complete, yet minimal example that allows us to replicate the behaviour. Such a minimal, working example (MWE) should start with \documentclass and end with \end{document} and allow the community to copy-and-paste-and-compile and see exactly what you're seeing. For that, use images from mwe and lipsum text, if needed. – Werner Feb 28 '19 at 22:23

2 Answers2

5

The parser does not parse \x+1, so you need to do this yourself. In this case \x+1 coincides with the count, so we can use this. (Of course I do not have your images so I renamed some standard images.)

\documentclass{beamer}
\usepackage{pgffor}
\begin{document}
\begin{frame}\frametitle{FooBar}
\foreach \x [count=\y] in {0,...,3} {
   \includegraphics<\y>[width=0.95\textwidth]{dbgp-setup2-\x}
}
\end{frame}
\end{document}

enter image description here

  • 1
    I made two mistakes. The first one was not including \usepackage{pgffor} and the second one was the one with \x+1. Thank you, everything's working fine now! – Christian Feb 28 '19 at 21:46
  • @Christian Glad to hear! (The first one is hard to detect since you did not show your preamble.) –  Feb 28 '19 at 21:47
0

I'm not sure why doing the thing so complicated:

\documentclass{beamer}
\usepackage{pgffor}
\begin{document}
\begin{frame}\frametitle{FooBar}
\foreach \x in {0,...,3} {%
   \includegraphics<+>[width=0.95\textwidth]{dbgp-setup2-\x}%
}
\end{frame}
\end{document}

enter image description here

egreg
  • 1,121,712