使用 LuaLaTeX 编译 pdfpages 代码

使用 LuaLaTeX 编译 pdfpages 代码

考虑以下 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引擎进行编译?

更新

我已尝试%按照 David 的建议删除所有 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}它来根据 luatex 原语定义大多数 pdftex 名称。

相关内容