1

I feel a bit stupid not to be able to solve this problem, but I can't find a way to turn the following command, usefull to get the number of pages in a pdf : \pdfximage{mypdf.tex} \the\pdflastximagepages into an actual command so that I can just write \pdfximage{images.pdf} in a \foreach loop. And if someone can explain me why the first two examples works but not the last one, I'd be really interested.

Thanks!

MWE:

\documentclass{beamer}
\usepackage{tikz}

\newcommand{\nbpagepdf}[1]{\pdfximage{#1}\the\pdflastximagepages}

\begin{document}
\begin{frame}[fragile]
  %% Ok:
  The number of pages is: \nbpagepdf{images.pdf} !
  %% Ok:
  \pdfximage{images.pdf}
  \foreach \ov in {1,...,\the\pdflastximagepages}{
    \includegraphics<\ov>[page=\ov]{images.pdf}
  }
  %% Not ok:
  \foreach \ov in {1,...,\nbpagepdf{images.pdf}}{
    \includegraphics<\ov>[page=\ov]{images.pdf}
  }
\end{frame}
\end{document}

Error:

ERROR: Missing number, treated as zero.

--- TeX said ---
<to be read again> 
                   \pdfximage 
l.10   }
  • 1
    \nbpagepdf is not a number, it only outputs at the end a number. you can't use it in a context where tex needs a real number. – Ulrike Fischer Aug 13 '18 at 17:57
  • @Ulrike Fischer : so what can I do to embed everything into a single function ? – tobiasBora Aug 13 '18 at 20:59
  • Nothing (at least not with pdflatex, with lualatex it would be perhaps possible to write a lua function). It won't work like you want it to work. – Ulrike Fischer Aug 13 '18 at 21:04
2

Define a suitable macro that first does \pdfximage.

\documentclass{beamer}
\usepackage{tikz}

\newcommand{\includepdfpages}[1]{%
  \pdfximage{#1}%
  \foreach \ov in {1,...,\the\pdflastximagepages}{%
    \includegraphics<\ov>[page=\ov]{#1}%
  }%
}

\begin{document}
\begin{frame}
  \includepdfpages{tobiasimages.pdf}
\end{frame}
\end{document}

The file has ten images and this is the result:

enter image description here

  • Thank you, even if it's not exactly what I was asking for, it should do the job most of the time. But I still don't understand what make it fondamentally different from others macros? For example I would expect that using an \edef would solve the issue, but it does not work... If you have some good explanation for that it would be really nice. – tobiasBora Aug 14 '18 at 6:34

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.