Компилировать код pdfpages с помощью LuaLaTeX

Компилировать код pdfpages с помощью LuaLaTeX

Рассмотрим следующий MWE:

\documentclass[
  a4paper
]{article}

\usepackage{pdfpages}

\newcount\firstmaxpages
\newcount\secondmaxpages
\newcount\curpage
\newcount\untilpage
\makeatletter
\newif\if@pdfdingsSecondFin
\newcount\@pdfdingsPages

\newcommand*\@incpdfdings[5][]{%
    \includepdf[
        nup = #5,
        pages = {#2-#3},
        #1
    ]{#4}}
\newcommand*\@@incpdfdings{}%
\def\@@incpdfdings#1x#2;{%
    \@pdfdingsPages=#1%
    \multiply\@pdfdingsPages by #2%
    \advance\@pdfdingsPages by -1%
}
\newcommand*\incpdfdings[4][]{%
    \ifx\relax#1\relax%
        \pdfximage{#3}%
        \firstmaxpages=\pdflastximagepages%
        \pdfximage{#4}%
        \secondmaxpages=\pdflastximagepages%
        \ifnum\firstmaxpages<\secondmaxpages%
            \@latex@error{incpdfdings: Fail!}{}%
        \fi%
    \else%
        \firstmaxpages=#1%
    \fi%
    \curpage=0%
    \@@incpdfdings#2;%
    \loop\ifnum\firstmaxpages>\curpage%
        \advance\curpage by 1%
        \untilpage=\numexpr\curpage+\@pdfdingsPages\relax%
        \ifnum\untilpage>\firstmaxpages%
            \untilpage=\firstmaxpages%
        \fi%
        \@incpdfdings[frame=true]{\the\curpage}{\the\untilpage}{#3}{#2}%
        \ifnum\secondmaxpages>\untilpage\else%
            \untilpage=\secondmaxpages%
        \fi%
        \if@pdfdingsSecondFin\else%
            \@incpdfdings{\the\curpage}{\the\untilpage}{#4}{#2}%
        \fi%
        \ifnum\secondmaxpages=\untilpage%
            \@pdfdingsSecondFintrue%
        \fi%
        \advance\curpage by \@pdfdingsPages%
    \repeat%
}
\makeatother

\begin{document}

\incpdfdings{3x6}%
  {A.pdf}%
  {B.pdf}

\end{document}

Предположим, у нас есть два файла PDF с именами A.pdfи B.pdfв том же каталоге, что и .texфайл с кодом выше. Если я компилирую код с помощью , pdflatexвсе в порядке, но если я компилирую с помощью lualatex, я получаю следующее сообщение об ошибке:

\incpdfdings ...>\ifx \relax #1\relax \pdfximage 
                                                  {#3}\firstmaxpages =\pdfla...

l.68   {B.pdf}

Вопрос

Как изменить код выше, чтобы его можно было скомпилировать с помощью lualatexдвижка?

Обновлять

Я попытался удалить все %s, следуя совету Дэвида. Я правильно сделал?

\newcommand*\@incpdfdings[5][]{%
    \includepdf[
        nup = #5,
        pages = {#2-#3},
        #1
    ]{#4}}
\newcommand*\@@incpdfdings{}%
\def\@@incpdfdings#1x#2;{%
    \@pdfdingsPages=#1
    \multiply\@pdfdingsPages by #2
    \advance\@pdfdingsPages by -1
}
\newcommand*\incpdfdings[4][]{%
    \ifx\relax#1\relax
        \saveimageresource{#3}%
        \firstmaxpages=\lastsavedimageresourcepages
        \saveimageresource{#4}%
        \secondmaxpages=\lastsavedimageresourcepages
        \ifnum\firstmaxpages<\secondmaxpages
            \@latex@error{incpdfdings: Der er ikke nok forsider.}{}%
        \fi
    \else
        \firstmaxpages=#1
    \fi
    \curpage=0
    \@@incpdfdings#2;%
    \loop\ifnum\firstmaxpages>\curpage
        \advance\curpage by 1
        \untilpage=\numexpr\curpage+\@pdfdingsPages\relax
        \ifnum\untilpage>\firstmaxpages
            \untilpage=\firstmaxpages
        \fi
        \@incpdfdings[frame=true]{\the\curpage}{\the\untilpage}{#3}{#2}%
        \ifnum\secondmaxpages>\untilpage\else
            \untilpage=\secondmaxpages
        \fi
        \if@pdfdingsSecondFin\else
            \@incpdfdings{\the\curpage}{\the\untilpage}{#4}{#2}%
        \fi
        \ifnum\secondmaxpages=\untilpage
            \@pdfdingsSecondFintrue
        \fi
        \advance\curpage by \@pdfdingsPages
    \repeat
}

решение1

Вы можете использовать \usepackage{luatex85}, который определяет большинство имен pdftex в терминах примитивов luatex.

Связанный контент