As suggested here, I'm using \includepdf to insert several multi-page PDF files of musical scores into a LaTeX document:

\newcommand{\insertScore}[3] {

  … more stuff following

However, while most of these PDFs consist of two or more pages, some have only one single page, which makes the second \includepdf fail. Is there any way to work around this issue without knowing in advance, how many pages the included PDF will consist of? The LaTeX file is generated automatically in this project, therefore using different commands for different PDFs isn't really an option ...

  • 1
    I posted an answer, but generally it is much better to provide an MWE (starting with \documentclass and ending with \end{document}) than code fragments like this. This allows people to reproduce your problem and test their solutions. It also often helps you in understanding your own problem better.
    – schtandard
    Jun 22, 2022 at 6:42

1 Answer 1


Just test the number of pages in the PDF first (cf. this question).

\newcommand{\insertScore}[3] {%
  % … more stuff following

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .