%%
%% This is file `pdfpages.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% pdfpages.dtx  (with options: `package')
%% 
%% This file is part of the pdfpages package.
%% 
%% Copyright (C) 2001-2025 Andreas MATTHIAS
%%
%% This work may be distributed and/or modified under the conditions
%% of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   <http://www.latex-project.org/lppl.txt>.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is
%%   Andreas Matthias <andreas.matthias@gmail.com>.
%%
%% Please send error reports and suggestions for improvements to
%%   Andreas MATTHIAS <andreas.matthias@gmail.com>.
%%
\def\AM@git@tag{v0.6f}
\def\AM@git@date{2025/03/12}
\def\AM@git@hash{3176420b0f}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pdfpages}
   [\AM@git@date\space\AM@git@tag\space
    Insert pages of external PDF documents (AM)]
\newif\ifAM@pkg@draft \AM@pkg@draftfalse
\DeclareOption{draft}{\AM@pkg@drafttrue}
\DeclareOption{final}{\AM@pkg@draftfalse}
\newif\ifAM@pkg@survey \AM@pkg@surveyfalse
\DeclareOption{enable-survey}{\AM@pkg@surveytrue}
\DeclareOption{disable-survey}{\AM@pkg@surveyfalse}
\newif\ifAM@pkg@demo \AM@pkg@demofalse
\DeclareOption{demo}{\AM@pkg@demotrue}
\DeclareOption{nodemo}{\AM@pkg@demofalse}
\def\AM@ifdriverlater{\@ifl@ter{def}}
\InputIfFileExists{pdfpages.cfg}{%
  \PackageInfo{pdfpages}{Loading configuration file `pdfpages.cfg'}}{}
\DeclareOption{pdftex}{\def\AM@driver{pdftex}}
\DeclareOption{luatex}{\def\AM@driver{luatex}}
\DeclareOption{vtex}{\def\AM@driver{vtex}}
\DeclareOption{xetex}{\def\AM@driver{xetex}}
\DeclareOption{dvips}{\def\AM@driver{dvips}}
\DeclareOption{dvipdfmx}{\def\AM@driver{dvipdfmx}}
\DeclareOption{null}{\def\AM@driver{null}}
\ProcessOptions
\ifAM@pkg@demo
  \def\AM@driver{null}
\fi
\@ifundefined{AM@driver}{
  \begingroup
  \@ifundefined{luatexversion}{%
    \@ifundefined{pdftexversion}{%
      \@ifundefined{XeTeXversion}{%
        \@ifundefined{OpMode}{%
          \gdef\AM@driver{null}
        }{\gedf\AM@driver{vtex}}%
      }{\gdef\AM@driver{xetex}}%
    }{\gdef\AM@driver{pdftex}}%
  }{\gdef\AM@driver{luatex}}%
  \endgroup
}{}
\RequirePackage{ifthen, calc, eso-pic, etoolbox}
  \RequirePackage{graphicx}%
\newif\ifAM@DVIoutput\AM@DVIoutputfalse
\newdimen\AM@pagewidth
\newdimen\AM@pageheight
\newdimen\AM@fboxrule
\input{pp\AM@driver.def}
\ifx\AM@endinput\relax\expandafter\endinput\fi
\ifAM@pkg@survey
  \let\AM@setanchor\AM@anchor@special
  \RequirePackage{count1to}%
  \AddToShipoutPicture{\AM@setanchor}%
\fi
\AtBeginDocument{%
  \let\AM@orig@landscape\landscape
  \let\AM@orig@endlandscape\endlandscape
  \RequirePackage{pdflscape}%
  \let\landscape\AM@orig@landscape
  \let\endlandscape\AM@orig@endlandscape
}
\let\AM@Ginclude@graphics\Ginclude@graphics
\@ifpackagelater{eso-pic}{2001/07/20}
  {\def\AM@AddToShipoutPicture{\AddToShipoutPicture*}%
   \def\AM@ClearShipoutPicture{\relax}}
  {\def\AM@AddToShipoutPicture{\AddToShipoutPicture}%
   \def\AM@ClearShipoutPicture{\ClearShipoutPicture}}
 \let\Orig@AM@AddToShipoutPicture\AM@AddToShipoutPicture
\newif\ifAM@openright\AM@openrightfalse
\newif\ifAM@openrighteach\AM@openrighteachfalse
\newif\ifAM@frame\AM@framefalse
\newif\ifAM@landscape\AM@landscapefalse
\newif\ifAM@turn\AM@turntrue
\newif\ifAM@thread\AM@threadfalse
\newif\ifAM@link\AM@linkfalse
\newif\ifAM@linktodoc\AM@linktodocfalse
\newif\ifAM@survey\AM@surveyfalse
\newif\ifAM@surveynolink\AM@surveynolinkfalse
\newif\ifAM@output\AM@outputtrue
\newif\ifAM@column\AM@columnfalse
\newif\ifAM@columnstrict\AM@columnstrictfalse
\newif\ifAM@noautoscale\AM@noautoscalefalse
\newif\ifAM@fitpaper\AM@fitpaperfalse
\newif\ifAM@doublepages\AM@doublepagesfalse
\newif\ifAM@doublepagestwist\AM@doublepagestwistfalse
\newif\ifAM@doublepagestwistx\AM@doublepagestwistxfalse
\newif\ifAM@doublepagestmp\AM@doublepagestmpfalse
\newif\ifAM@doublepagestmpi\AM@doublepagestmpifalse
\newif\ifAM@duplicatepages\AM@duplicatepagesfalse
\newif\ifAM@linkfilename\AM@linkfilenamefalse
\newif\ifAM@signature\AM@signaturefalse
\newif\ifAM@signaturestar\AM@signaturestarfalse
\newif\ifAM@booklet\AM@bookletfalse
\newif\ifAM@swap@flip@edge\AM@swap@flip@edgefalse
\newif\ifAM@upsidedown\AM@upsidedownfalse
\newif\ifAM@newwindow\AM@newwindowtrue
\newif\ifAM@rescale\AM@rescalefalse
\newif\ifAM@rotateoversize\AM@rotateoversizefalse
\newif\ifAM@firstpage\AM@firstpagefalse
\newif\ifAM@reflect\AM@reflectfalse
\newif\ifAM@reflectall\AM@reflectallfalse
\newif\ifAM@scale\AM@scaletrue
\newif\ifAM@newpage\AM@newpagefalse
\newif\ifAM@pagecount@updated
\newif\ifAM@memoir\AM@memoirfalse
\@ifclassloaded{memoir}{\AM@memoirtrue}{}
\newcount\pdfpages@includegraphics@status
\pdfpages@includegraphics@status\z@
\newcommand*{\AM@pagestemp}{1}
\newcommand*{\AM@pagecommand}{\thispagestyle{empty}}
\newcommand*{\AM@pagecommandstar}{}
\newcommand*{\AM@lscape@rot}{0}
\newcommand*{\AM@threadname}{}\newcommand*{\AM@linkname}{}
\newcommand*{\AM@linkname@option}{}
\newcommand*{\AM@linktodocfit}{/Fit}
\newcommand*{\threadinfodict}{}
\newcommand*{\AM@toclist}{}\newcommand*{\AM@loflist}{}
\newcommand*{\AM@signature}{}
\newcommand*{\AM@ARBug@hook}{}
\newcommand*{\AM@xrprefix}{}
\newcommand*{\AM@picturecommand}{}
\newcommand*{\AM@picturecommandstar}{}
\newsavebox{\AM@pagebox}
\newif\ifAM@integer
\def\AM@checkinteger#1{%
  \expandafter\AM@checkinteger@\expandafter{#1}}
\def\AM@checkinteger@#1{%
  \begingroup
  \def\do##1{\uccode`##1=`\%}%
  \do\0\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9%
  \makeatletter
  \catcode`\%=9
  \endlinechar\m@ne
  \uppercase{\scantokens{\def\AM@temp{#1}}}%
  \ifx\AM@temp\@empty
    \global\AM@integertrue
  \else
    \global\AM@integerfalse
  \fi
  \endgroup}
\newcommand*{\AM@findfile@i}[2]{%
  \ifAM@pkg@demo
  \else
    \let\Ginclude@graphics\AM@Ginclude@graphics
  \fi
  \let\AM@currentdocname\relax
  \AM@IfFileExists{#1.#2}{\edef\AM@currentdocname{#1.#2}}{%
     \AM@IfFileExists{#1}{\edef\AM@currentdocname{#1}}{%
       \ifx\Ginput@path\@undefined\else
         \expandafter\@tfor\expandafter\AM@dir\expandafter
                   :\expandafter=\Ginput@path\do{%
           \AM@IfFileExists{\AM@dir#1.#2}{%
             \ifx\AM@currentdocname\relax
               \edef\AM@currentdocname{\AM@dir#1.#2}%
             \fi
           }{%
             \AM@IfFileExists{\AM@dir#1}{%
               \ifx\AM@currentdocname\relax
                 \edef\AM@currentdocname{\AM@dir#1}%
               \fi
             }{}%
           }%
         }% \@tfor
       \fi
     }%
   }%
}
\newcommand*{\AM@findfile@ii}[1]{%
  \ifx\AM@currentdocname\relax
    \PackageError{pdfpages}{Cannot find file `#1'}{}%
    \let\AM@filenotfound\relax
  \fi
}
\newtoks\AM@global@opts
\newcommand*{\AM@disable@width@height}{width=!,height=!}
\AM@global@opts\expandafter{\AM@disable@width@height}
\newcommand*{\includepdfset}[1]{%
  \AM@global@opts\expandafter{\AM@disable@width@height,#1}%
}
\newcommand*{\includepdf}[2][]{%
  \begingroup
  \global\pdfpages@includegraphics@status\tw@
  \@ifundefined{@setmarks}{\let\@setmarks\relax}{}
  \AM@pagecnt\@ne
  \AM@reset@view
  \let\AM@threadname\relax
  \def\AM@tmp{pdfpages}
  \expandafter\AM@split@options
    \expandafter\AM@tmp
    \expandafter{\the\AM@global@opts,#1}%
  \edef\AM@temp{{pdfpages}{\the\@temptokena}}%
  \expandafter\setkeys\AM@temp
  \ifthenelse{\boolean{AM@pkg@draft} \and \boolean{AM@survey}}{%
    \let\AM@currentdocname\relax
    \renewcommand\includegraphics[2][]{Survey in draft-mode}%
    \def\AM@pagecount{0}%
  }{%
    \AM@findfile{#2}%
    \ifx\AM@threadname\relax
      \def\AM@threadname{\AM@currentdocname}%
    \fi
  }%
  \ifAM@survey
    \def\AM@pagestemp{}%
    \@tempcnta=0
    \def\foo{%
      \@ifundefined{r@\AM@xrprefix pdfpages@page\the\@tempcnta}%
         {\let\foo\relax}
         {\expandafter\ifx\expandafter\\\AM@pagestemp\\
             \edef\AM@pagestemp{%
                \AM@pageref{\AM@xrprefix pdfpages@page\the\@tempcnta}}%
          \else
            \edef\AM@pagestemp{\AM@pagestemp,%
               \AM@pageref{\AM@xrprefix pdfpages@page\the\@tempcnta}}%
          \fi
          \advance\@tempcnta 1\relax
         }%
      \foo
    }%
    \foo
    \expandafter\ifx\expandafter\\\AM@pagestemp\\
      \def\AM@pagestemp{1}%
    \fi
  \fi
  \ifAM@output
    \expandafter\AM@readlist\expandafter{\AM@pagestemp}%
    \expandafter\AM@output\expandafter{\the\AM@global@opts,#1}%
  \fi
  \AM@CheckAtEnd
  \endgroup
  \AM@ClearShipoutPicture
  \global\pdfpages@includegraphics@status\z@
}
\newcommand*{\includepdfmerge}[2][]{%
  \begingroup
  \global\pdfpages@includegraphics@status\tw@
  \AM@pagecnt\@ne
  \AM@reset@view
  \let\AM@threadname\relax
  \let\AM@currentdocname\relax
  \def\AM@tmp{pdfpages}
  \expandafter\AM@split@options
    \expandafter\AM@tmp
    \expandafter{\the\AM@global@opts,#1}%
  \edef\AM@temp{{pdfpages}{\the\@temptokena}}%
  \expandafter\setkeys\AM@temp
  \AM@readlist{#2}%
  \expandafter\AM@output\expandafter{\the\AM@global@opts,#1}%
  \AM@CheckAtEnd
  \endgroup
  \AM@ClearShipoutPicture
  \global\pdfpages@includegraphics@status\z@
}
\newcommand{\AM@CheckAtEnd}{%
    \ifx\@empty\AM@toclist\else
      \PackageWarning{pdfpages}{%
           There's something wrong with the entries\MessageBreak
           of `addtotoc'. Not all entries were\MessageBreak
           processed. Check `addtotoc'}%
    \fi
    \ifx\@empty\AM@loflist\else
      \PackageWarning{pdfpages}{%
           There's something wrong with the entries\MessageBreak
           of `addtolist'. Not all entries were\MessageBreak
           processed. Check `addtolist'}%
    \fi
}
\newcommand\AM@output{%
  \ifdefined\AM@filenotfound
  \else
    \expandafter\AM@output@i
  \fi
}
\newcommand{\AM@output@i}[1]{%
    \AM@getpagedimen
    \ifdim\AM@pagewidth=\z@
      \AM@pagewidth=210mm
      \PackageWarningNoLine{pdfpages}{%
        Erroneous page width of 0.0pt is corrected}%
    \fi
    \ifdim\AM@pageheight=\z@
      \AM@pageheight=297mm
      \PackageWarningNoLine{pdfpages}{%
        Erroneous page height of 0.0pt is corrected}%
    \fi
  \xdef\@deferlist{\@toplist\@botlist\@deferlist}%
  \gdef\@toplist{}%
  \gdef\@botlist{}%
  \xdef\@dbldeferlist{\@dbltoplist\@dbldeferlist}%
  \gdef\@dbltoplist{}%
  \global\let\AM@deferlist\@deferlist
  \gdef\@deferlist{}%
  \global\let\AM@dbldeferlist\@dbldeferlist
  \gdef\@dbldeferlist{}%
  \AM@disable@includegraphics
  \@ifundefined{AM@xnup}
    {\def\AM@xnup{\@ne}\def\AM@ynup{\@ne}%
     \def\AM@xnupminusi{\z@}\def\AM@ynupminusi{\z@}}{}%
  \@ifundefined{AM@deltax}
    {\def\AM@deltax{-\AM@fboxrule}\def\AM@deltay{-\AM@fboxrule}}{}%
  \@ifundefined{AM@xoffset}
    {\def\AM@xoffset{\z@}\def\AM@yoffset{\z@}}{}%
  \def\AM@xpos{\z@}\def\AM@ypos{\z@}%
  \ifAM@pkg@draft \setkeys{Gin}{draft=true}%
  \else \setkeys{Gin}{draft=false}%
  \fi
  \ifAM@landscape
    \def\AM@lscape@rot{90}%
      \let\AM@temp\AM@xnup
      \let\AM@xnup\AM@ynup
      \let\AM@ynup\AM@temp
  \fi
  \AM@setphantom
  \ifthenelse{\boolean{AM@openright}\and\not\boolean{AM@openrighteach}}
         {\AM@openright}{}%
  \ifx\AM@signature\@empty\AM@filluppagelist
  \else\AM@prepare@signature\AM@signaturetrue\fi
  \@tempcnta=\AM@xnup\relax \advance\@tempcnta\m@ne
  \edef\AM@xnupminusi{\the\@tempcnta}%
  \@tempcnta=\AM@ynup\relax \advance\@tempcnta\m@ne
  \edef\AM@ynupminusi{\the\@tempcnta}%
  \ifthenelse{\boolean{AM@column}%
              \and\not\boolean{AM@columnstrict}}
         {\AM@getlastn{\AM@doclist}{\AM@nup}%
          \edef\AM@lastndocs{\AM@lastnitems}%
          \AM@getlastn{\AM@pagelist}{\AM@nup}%
          \edef\AM@lastnpages{\AM@lastnitems}%
          \AM@resort
          \AM@count{\AM@pagelist}%
          \expandafter\ifx\expandafter\\\AM@pagelist\\%
            \edef\AM@pagelist{\AM@resortedpagelist}%
            \edef\AM@doclist{\AM@resorteddoclist}%
          \else
            \edef\AM@pagelist{\AM@pagelist,\AM@resortedpagelist}%
            \edef\AM@doclist{\AM@doclist,\AM@resorteddoclist}%
          \fi}{}%
  \ifthenelse{\boolean{AM@frame}}%
         {\global\let\AM@fbox\fbox
          \setlength\AM@fboxrule{\fboxrule}}%
         {\global\let\AM@fbox\relax
          \setlength\AM@fboxrule{\z@}}%
  \ifthenelse{\boolean{AM@reflect}}%
         {\global\let\AM@reflectbox\reflectbox}%
         {\global\let\AM@reflectbox\relax}%
  \setbox\AM@pagebox\null
  \ifthenelse{\boolean{AM@column}}
         {\def\AM@xnupi{\@ne}%
          \def\AM@ynupi{\z@}}
         {\def\AM@xnupi{\z@}%
          \def\AM@ynupi{\@ne}}%
  \AM@firstpagetrue
  \@ifundefined{AM@pagetemplate}
      {\AM@readfirst{\AM@pagelist}%
       \edef\AM@nextpage{\the\toks@}}
      {\edef\AM@nextpage{\AM@pagetemplate}}%
  \AM@readfirst{\AM@doclist}%
  \edef\AM@docname{\the\toks@}%
  \AM@isphantom
  \edef\AM@page{\AM@nextpage}%
  \ifAM@noautoscale
    \def\AM@globalscale{1}%
  \else
    \AM@split@options{Gin@noscale}{#1}%
    \let\AM@filelist@save\@filelist
    \ifAM@DVIoutput
      \setbox\@tempboxa=\hbox{\rule{597pt}{845pt}}%
    \else
      \ifAM@templatesize
        \setbox\@tempboxa=\hbox{%
          \rotatebox{\AM@lscape@rot}{\copy\AM@templatesizebox}}%
      \else
        \edef\AM@opts{[\AM@disable@width@height,\the\@temptokena,
                       page=\AM@page, angle=\AM@lscape@rot]}%
        \setbox\@tempboxa=\hbox{%
          \expandafter\includegraphics\AM@opts{\AM@docname}}%
      \fi
    \fi
    \ifthenelse{\boolean{AM@fitpaper}}{
      \setlength{\AM@pagewidth}{\wd\@tempboxa}%
      \setlength{\AM@pageheight}{\ht\@tempboxa + \dp\@tempboxa}%
    }{}%
    \def\AM@xscale{%
      (\AM@pagewidth - \tw@\AM@fboxrule*\AM@xnup
       - \AM@deltax * \AM@xnupminusi) /
      (\AM@xnup * \real{\strip@pt\wd\@tempboxa})
    }%
    \setlength{\@tempdima}{\AM@xscale}%
    \edef\AM@xscale{\strip@pt\@tempdima}%
    \setlength{\@tempdimb}{\ht\@tempboxa + \dp\@tempboxa}%
    \def\AM@yscale{
      (\AM@pageheight - \tw@\AM@fboxrule*\AM@ynup
       - \AM@deltay *\AM@ynupminusi) /
      (\AM@ynup * \real{\strip@pt\@tempdimb})
    }%
    \setlength{\@tempdima}{\AM@yscale}%
    \edef\AM@yscale{\strip@pt\@tempdima}%
    \@tempdima=\AM@xscale\p@
    \@tempdimb=\AM@yscale\p@
    \ifdim\@tempdima<\@tempdimb
      \let\AM@globalscale\AM@xscale
    \else
      \let\AM@globalscale\AM@yscale
    \fi
  \fi
  \let\AM@filelist@save\@filelist
  \AM@split@options{Gin}{#1}%
  \ifAM@templatesize
    \setbox\@tempboxa=\hbox{%
      \scalebox{\AM@scale@factor}{\copy\AM@templatesizebox}}%
    \setbox\@tempboxa=\hbox{%
      \scalebox{\AM@globalscale}{\copy\@tempboxa}}%
    \setbox\@tempboxa=\hbox{%
      \rotatebox{\AM@lscape@rot}{\copy\@tempboxa}}%
  \else
    \edef\AM@opts{[\AM@disable@width@height,\the\@temptokena,
                   page=\AM@page, scale=\AM@globalscale,
                   angle=\AM@lscape@rot]}%
    \setbox\@tempboxa=\hbox{%
      \expandafter\includegraphics\AM@opts{\AM@docname}}%
  \fi
  \let\@filelist\AM@filelist@save
  \edef\AM@templatewidth{\the\wd\@tempboxa}%
  \setlength{\@tempdima}{\ht\@tempboxa + \dp\@tempboxa}%
  \edef\AM@templateheight{\the\@tempdima}%
  \setlength{\@tempdimb}{\ht\@tempboxa + \dp\@tempboxa}%
  \def\AM@xmargin{%
    (\AM@pagewidth - (\wd\@tempboxa+\tw@\AM@fboxrule)*\AM@xnup
     - \AM@deltax * \AM@xnupminusi) * \real{.5}%
  }%
  \def\AM@ymargin{%
    (\AM@pageheight - (\@tempdimb+\tw@\AM@fboxrule)*\AM@ynup
     - \AM@deltay * \AM@ynupminusi) * \real{.5}%
  }%
  \setlength{\@tempdima}{\AM@xmargin}%
  \edef\AM@xmargin{\the\@tempdima}%
  \setlength{\@tempdima}{\AM@ymargin}%
  \edef\AM@ymargin{\the\@tempdima}%
  \ifthenelse{\boolean{AM@landscape}}{%
    \edef\AM@temp{\AM@xnup}%
    \edef\AM@xnup{\AM@ynup}%
    \edef\AM@ynup{\AM@temp}%
  }{}%
  \setboolean{AM@endoflist}{false}%
  \clearpage
  \whiledo{\not\boolean{AM@endoflist}}{%
    \AM@getfirst{\AM@pagelist}%
      \edef\AM@nextpage{\the\toks@}%
      \AM@isphantom
      \@tempcnta=\AM@nextpage\relax
      \edef\AM@linktodoc@page{\the\@tempcnta}%
      \advance\@tempcnta\m@ne
      \edef\AM@linktodoc@page@m@ne{\the\@tempcnta}%
    \AM@getfirst{\AM@doclist}%
      \edef\AM@docname{\the\toks@}%
      \ifAM@linkfilename
      \else
        \let\AM@linkfilename\AM@docname
      \fi
      \ifx\@empty\AM@linkname@option \edef\AM@linkname{\the\toks@}%
      \else \edef\AM@linkname{\AM@linkname@option} \fi
    \ifthenelse{\boolean{AM@column}}
      {\@tempcnta=\AM@ynupi\relax
       \@tempcntb=\AM@ynup\relax
       \advance\@tempcnta\@ne
       \ifnum\@tempcnta>\@tempcntb
         \@tempcnta=\@ne
         \@tempcntb=\AM@xnupi\relax
         \advance\@tempcntb\@ne
         \edef\AM@xnupi{\the\@tempcntb}%
       \fi
       \edef\AM@ynupi{\the\@tempcnta}%
       \@tempcnta=\AM@xnupi\relax
       \@tempcntb=\AM@xnup\relax
       \ifnum\@tempcnta>\@tempcntb
         \def\AM@xnupi{\@ne}%
         \AM@newpagetrue
       \fi
      }
      {\@tempcnta=\AM@xnupi\relax
       \@tempcntb=\AM@xnup\relax
       \advance\@tempcnta\@ne
       \ifnum\@tempcnta>\@tempcntb
         \@tempcnta=\@ne
         \@tempcntb=\AM@ynupi\relax
         \advance\@tempcntb\@ne
         \edef\AM@ynupi{\the\@tempcntb}%
       \fi
       \edef\AM@xnupi{\the\@tempcnta}%
       \@tempcnta=\AM@ynupi\relax
       \@tempcntb=\AM@ynup\relax
       \ifnum\@tempcnta>\@tempcntb
         \def\AM@ynupi{\@ne}%
         \AM@newpagetrue
       \fi
      }%
     \ifAM@newpage
       \clearpage
       \AM@newpagefalse
     \fi
     \edef\AM@page{\AM@nextpage}%
    \edef\AM@opts{[\AM@disable@width@height,\the\@temptokena,
                   page=\AM@page, scale=\AM@globalscale,
                   angle=\AM@lscape@rot]}%
    \setbox\@tempboxa=\hbox{%
      \expandafter\includegraphics\AM@opts{\AM@docname}}%
    \edef\AM@localwd{\the\wd\@tempboxa}%
    \setlength{\@tempdima}{\ht\@tempboxa + \dp\@tempboxa}%
    \edef\AM@localht{\the\@tempdima}%
    \AM@rescalefalse
    \ifdim\AM@localwd=\AM@templatewidth \else \AM@rescaletrue \fi
    \ifdim\AM@localht=\AM@templateheight \else \AM@rescaletrue \fi
    \def\AM@localxoff{\z@}%
    \def\AM@localyoff{\z@}%
    \def\AM@rotateoversize{0}%
    \def\AM@localscale{\p@}%
    \ifAM@rescale
      \ifthenelse{\lengthtest{\AM@localwd<\AM@templatewidth} \and
                  \lengthtest{\AM@localht<\AM@templateheight}}{%
        \setlength{\@tempdima}{(\AM@templatewidth - \AM@localwd)
             * \real{.5}}%
        \edef\AM@localxoff{\the\@tempdima}%
        \setlength{\@tempdima}{(\AM@templateheight - \AM@localht)
             * \real{.5}}%
        \edef\AM@localyoff{\the\@tempdima}%
      }{%
        \ifAM@rotateoversize
          \def\AM@rotateoversize{90}%
          \let\AM@filelist@save\@filelist
          \edef\AM@opts{[\AM@disable@width@height,\the\@temptokena,
                        page=\AM@page, scale=\AM@globalscale,
                        angle=\AM@lscape@rot, angle=90]}%
          \setbox\@tempboxa=\hbox{%
            \expandafter\includegraphics\AM@opts{\AM@docname}}%
          \let\@filelist\AM@filelist@save
          \edef\AM@localwd{\the\wd\@tempboxa}%
          \setlength{\@tempdima}{\ht\@tempboxa + \dp\@tempboxa}%
          \edef\AM@localht{\the\@tempdima}%
        \fi
        \setlength{\@tempdima}
                  {\p@ * \ratio{\AM@templatewidth}{\AM@localwd}}%
        \edef\AM@localxscale{\the\@tempdima}%
        \setlength{\@tempdima}
                  {\p@ * \ratio{\AM@templateheight}{\AM@localht}}%
        \edef\AM@localyscale{\the\@tempdima}%
        \ifdim\AM@localxscale<\AM@localyscale
          \let\AM@localscale\AM@localxscale
          \setlength{\@tempdima}{\AM@localxscale}%
          \setlength{\@tempdima}{(\AM@templateheight -
            \AM@localht * \real{\strip@pt\@tempdima}) * \real{.5}}%
          \edef\AM@localyoff{\the\@tempdima}%
        \else
          \let\AM@localscale\AM@localyscale
          \setlength{\@tempdima}{\AM@localyscale}%
          \setlength{\@tempdima}{(\AM@templatewidth -
             \AM@localwd * \real{\strip@pt\@tempdima}) * \real{.5}}%
          \edef\AM@localxoff{\the\@tempdima}%
        \fi
      }%
    \fi
    \setlength{\@tempdima}{\AM@localscale}%
    \edef\AM@localscale{\strip@pt\@tempdima}%
    \ifAM@noautoscale
      \def\AM@localxoff{\z@}%
      \def\AM@localyoff{\z@}%
      \def\AM@localscale{1}%
    \fi
    \let\AM@filelist@save\@filelist
    \AM@split@options{Gin}{#1}%
    \edef\AM@opts{[\AM@disable@width@height,\the\@temptokena,
                   page=\AM@page, scale=\AM@globalscale,
                   angle=\AM@lscape@rot]}%
    \setbox\@tempboxa=\hbox{%
      \expandafter\includegraphics\AM@opts{\AM@docname}}%
    \let\@filelist\AM@filelist@save
    \setlength{\@tempdimc}{\ht\@tempboxa + \dp\@tempboxa}%
    \edef\AM@texcoord{%
      \ifESO@texcoord
        -\AM@pageheight
      \else
         \z@
      \fi
    }%
    \def\AM@add{+}%
    \if@twoside\ifodd\c@page\else\def\AM@add{-}\fi\fi
    \setlength{\@tempdimb}{\ht\@tempboxa + \dp\@tempboxa}%
    \ifthenelse{\boolean{AM@landscape}}
      {\def\AM@xpos{%
         \AM@xmargin \AM@add\AM@xoffset + \AM@localxoff +
         (\AM@templatewidth + \AM@deltax + \tw@\AM@fboxrule) *
         (\AM@ynupi - 1)
       }%
       \def\AM@ypos{%
         \AM@texcoord +
         \AM@ymargin + \AM@yoffset + \AM@localyoff +
         (\AM@templateheight + \AM@deltay + \tw@\AM@fboxrule) *
         (\AM@xnupi - 1)
       }%
      }
      {\def\AM@xpos{%
         \AM@xmargin \AM@add\AM@xoffset + \AM@localxoff +
         (\AM@templatewidth + \AM@deltax + \tw@\AM@fboxrule) *
         (\AM@xnupi - 1)
       }%
       \def\AM@ypos{%
         \AM@texcoord +
         \AM@ymargin + \AM@yoffset + \AM@localyoff +
         (\AM@templateheight + \AM@deltay + \tw@\AM@fboxrule) *
         (\AM@ynup-\AM@ynupi)
       }%
      }%
    \setlength{\@tempdima}{\AM@xpos}%
    \edef\AM@xpos{\strip@pt\@tempdima}%
    \setlength{\@tempdima}{\AM@ypos}%
    \edef\AM@ypos{\strip@pt\@tempdima}%
    \ifnum\AM@xnupi=1
      \ifnum\AM@ynupi=1
        \ifAM@reflectall
          \setbox\AM@pagebox\null
        \fi
        \ifAM@swap@flip@edge
          \ifAM@signature
            \ifAM@upsidedown\AM@upsidedownfalse\else\AM@upsidedowntrue\fi
            \@tempdima=\AM@xoffset\relax
            \multiply\@tempdima\m@ne
            \edef\AM@xoffset{\the\@tempdima}%
          \fi
        \fi
      \fi
    \fi
    \ifAM@phantompage
      \def\AM@shippage{}%
    \else
      \AM@split@options{Gin}{#1}%
        \edef\AM@opts{[\AM@disable@width@height,\the\@temptokena,
                       page=\AM@page, scale=\AM@globalscale,
                       scale=\AM@localscale,
                       \ifAM@upsidedown angle=180,\fi
                       \ifAM@doublepagestwist\ifAM@doublepagestmp
                       angle=180,\fi\fi
                       angle=\AM@rotateoversize, angle=\AM@lscape@rot]}%
      \edef\AM@shippage{%
        \noexpand\put(\AM@xpos,\AM@ypos){%
        \noexpand\raisebox{\dp\@tempboxa}{%
        \noexpand\raise \ifx\\\AM@view@ypos\\\ht\@tempbox\else\AM@view@ypos\p@\fi
        \hbox to 0pt {\hskip\AM@view@xpos bp\AM@hyper@begin@i}%
        \global\pdfpages@includegraphics@status\@ne
        \fboxsep=\z@
        \AM@hyper@begin@ii\noexpand\AM@fbox{%
          \noexpand\AM@ARBug@hook
          \noexpand\AM@reflectbox{%
            \expandafter\noexpand\expandafter
            \includegraphics\AM@opts{\AM@docname}}}%
        \global\pdfpages@includegraphics@status\tw@
        \AM@hyper@end}}%
      }%
    \fi
    \ifAM@doublepagestwist
      \ifAM@doublepagestmpi
        \ifAM@doublepagestwistx\AM@doublepagestmpifalse\fi
        \ifAM@doublepagestmp\AM@doublepagestmpfalse
        \else\AM@doublepagestmptrue\fi
      \else\AM@doublepagestmpitrue\fi
    \fi
    \AM@AddToShipoutPicture{\setlength{\unitlength}{\p@}%
      \global\let\AM@filelist@save\@filelist}%
    \ifthenelse{\boolean{AM@fitpaper}}{
      \setlength{\paperwidth}{\AM@pagewidth}%
      \setlength{\paperheight}{\AM@pageheight}%
      \AM@fitpaper@special
      \AM@setpagedimen
      \ifAM@memoir
        \setlength{\stockwidth}{\AM@pagewidth}%
        \setlength{\stockheight}{\AM@pageheight}%
        \setlength{\trimtop}{0pt}%
        \setlength{\trimedge}{0pt}%
      \fi
    }{}
    \ifdim\paperwidth=\z@
      \let\paperwidth\AM@pagewidth
    \fi
    \ifdim\paperheight=\z@
      \let\paperheight\AM@pageheight
    \fi
    \if@twocolumn
      \@twocolumnfalse
      \let\AM@twocolumn\relax
    \fi
    \ifAM@reflectall
      \begin{lrbox}{\AM@pagebox}
        \global\let\AM@filelist@save\@filelist
        \usebox{\AM@pagebox}\AM@shippage
        \global\let\@filelist\AM@filelist@save
      \end{lrbox}
    \else
      \expandafter\AM@AddToShipoutPicture\expandafter{%
        \AM@shippage
        \global\let\@filelist\AM@filelist@save
      }%
    \fi
    \AM@toclof{\AM@page}%
    \ifnum\AM@xnupi=\AM@xnup\relax
      \ifnum\AM@ynupi=\AM@ynup\relax
        \begingroup
           \ifAM@firstpage\AM@pagecommandstar\fi
           \AM@pagecommand
        \endgroup
        \hskip\z@
        \ifthenelse{\boolean{AM@turn}\AND\boolean{AM@landscape}}{%
          \AM@setRotate
        }{}%
        \AM@AddToShipoutPicture{%
          \begingroup\AM@picturecommand\endgroup}%
        \ifAM@firstpage
          \AM@AddToShipoutPicture{%
            \begingroup\AM@picturecommandstar\endgroup}%
          \AM@firstpagefalse
        \fi
        \ifAM@reflectall
          \AM@AddToShipoutPicture{%
            \hskip\AM@pagewidth
            \reflectbox{\usebox\AM@pagebox}%
            \global\let\@filelist\AM@filelist@save
          }%
          \AM@ClearShipoutPicture
        \fi
      \fi
    \fi
  }% whiledo
  \global\let\@deferlist\AM@deferlist
  \global\let\@dbldeferlist\AM@dbldeferlist
  \ifx\AM@twocolumn\relax
    \@twocolumntrue
    \@firstcolumnfalse
  \fi
  \newpage
  \ifthenelse{\boolean{AM@turn}\AND\boolean{AM@landscape}}{%
    \AM@resetRotate
  }{}
}% AM@output
\newif\ifAM@default@range@added
\newcommand*{\AM@readlist}[1]{%
  \AM@pagecount@updatedfalse
  \AM@default@range@addedtrue
  \def\AM@pagelist{}%
  \def\AM@doclist{}%
  \AM@readlisti#1,\END,
  \AM@add@default@range
  \edef\AM@doclist{\expandafter\@gobble\AM@doclist\@empty}%
  \edef\AM@pagelist{\expandafter\@gobble\AM@pagelist\@empty}%
}
\def\AM@add@default@range{%
  \ifAM@default@range@added
  \else
    \expandafter\AM@read@defaultpages\AM@pagestemp,\END,
  \fi
  \AM@default@range@addedtrue
}
\def\AM@read@defaultpages#1,{%
  \ifx\END#1
  \else
    \edef\AM@x{\AM@trim@space{#1}}%
    \ifx\AM@x\@empty
      \AM@append{}%
      \AM@ReturnAfterElseFiFi\AM@read@defaultpages
    \else
      \expandafter\AM@checkrange\AM@x-\END
      \AM@expand@range\AM@i\AM@ii
      \AM@ReturnAfterFiFi\AM@read@defaultpages
    \fi
  \fi
}
\newcommand{\AM@readlisti}{}
\def\AM@readlisti#1,{%
  \ifx\AM@currentdocname\relax
  \else
    \ifAM@pagecount@updated
    \else
      \AM@getpagecount
      \AM@pagecount@updatedtrue
    \fi
  \fi
  \def\AM@temp{#1}%
  \ifx\END#1
  \else
    \AM@range@or@docname{#1}%
    \expandafter\AM@readlisti
  \fi
}
\def\AM@range@or@docname#1{%
  \edef\AM@arg{\AM@trim@space{#1}}%
  \ifx\AM@arg\@empty
    \AM@append{}%
  \else
    \expandafter\AM@checkrange\AM@arg-\END
    \ifAM@isrange
      \ifx\AM@currentdocname\relax
        \AM@setnewdocname{\AM@arg}%
      \else
        \AM@expand@range\AM@i\AM@ii
        \AM@default@range@addedtrue
      \fi
    \else
      \AM@add@default@range
      \AM@setnewdocname{\AM@arg}%
      \AM@pagecount@updatedfalse
    \fi
  \fi
}
\def\AM@last{last}
\def\AM@empty{}
\newif\ifAM@isrange
\def\AM@checkrange#1-#2\END{%
  \AM@israngefalse
  \AM@check@valid@pagenumber{#1}%
  \ifx\\#1\\%
    \def\AM@i{1}%
  \else
    \edef\AM@i{#1}%
  \fi
  \def\AM@ii{}%
  \ifAM@isrange
    \ifx\\#2\\%
    \else
      \edef\AM@ii{\AM@strip@slash#2\END}%
      \AM@check@valid@pagenumber{\AM@ii}%
      \ifx\AM@ii\AM@empty
        \let\AM@ii\AM@last
      \fi
    \fi
  \fi
}
\def\AM@expand@range#1#2{%
  \edef\AM@i{#1}%
  \edef\AM@ii{#2}%
  \ifx\AM@i\AM@last
    \let\AM@i\AM@lastpage
    \let\AM@i\AM@pagecount
  \fi
  \ifx\AM@ii\AM@last
    \let\AM@ii\AM@lastpage
    \let\AM@ii\AM@pagecount
  \fi
  \ifx\AM@ii\AM@empty
    \let\AM@ii\AM@i
  \fi
  \@tempcnta=\AM@i\relax
  \@tempcntb=\AM@ii\relax
  \ifnum\@tempcnta<\@tempcntb
    \def\AM@rel{<}%
    \let\AM@inc\@ne
  \else
    \def\AM@rel{>}%
    \let\AM@inc\m@ne
  \fi
  \advance\@tempcntb\AM@inc
  \whiledo{\@tempcnta\AM@rel\@tempcntb}{%
    \AM@checkpagenumber{\the\@tempcnta}%
    \AM@append{\the\@tempcnta}%
    \advance\@tempcnta\AM@inc
  }%
}
\def\AM@check@valid@pagenumber#1{%
  \AM@checkinteger{#1}%
  \ifAM@integer
    \AM@israngetrue
  \else
    \AM@israngefalse
  \fi
  \edef\AM@tmp{#1}%
  \ifx\AM@tmp\AM@last
    \AM@israngetrue
  \fi
}
\def\AM@strip@slash#1-#2\END{%
  \ifx\\#2\\%
    #1%
  \else
    #1-#2%
  \fi
}
\providecommand*{\AM@checkpagenumber}[1]{%
  \ifnum#1>\AM@pagecount\relax
    \ifthenelse{\boolean{AM@pkg@draft} \and \boolean{AM@survey}}{%
    }{%
      \PackageError{pdfpages}
        {Page #1 of `\AM@currentdocname' does not exist}
        {You have set a wrong page number in the `pages' option.
         Document \MessageBreak `\AM@currentdocname' does not
         have #1 pages.}%
    }%
  \fi
}
\newcommand*{\AM@setnewdocname}[1]{%
  \ifAM@openrighteach
    \ifodd\AM@pagecnt
      \AM@append{}
    \fi
  \fi
  \AM@add@default@range
  \edef\AM@temp{\AM@trim@space{#1}}%
  \AM@findfile{\AM@temp}%
  \AM@default@range@addedfalse
}
\newcount\AM@pagecnt
\newcommand*{\AM@append}[1]{%
  \advance\AM@pagecnt\@ne
  \edef\AM@doclist{\AM@doclist,\AM@currentdocname}%
  \edef\AM@pagelist{\AM@pagelist,#1}%
  \ifAM@doublepages
    \edef\AM@doclist{\AM@doclist,\AM@currentdocname}%
    \edef\AM@pagelist{\AM@pagelist,#1}%
  \fi
  \ifAM@duplicatepages
    \count@=0
    \loop
    \advance\count@ 1
    \ifnum\count@<\AM@nduplicatepages
    \edef\AM@doclist{\AM@doclist,\AM@currentdocname}%
    \edef\AM@pagelist{\AM@pagelist,#1}%
    \repeat
  \fi
}
\newif\ifAM@endoflist\AM@endoflistfalse
\newcommand{\AM@getfirst}{}
\def\AM@getfirst#1{\expandafter\AM@getfirsti#1,\END#1\END}
\newcommand{\AM@getfirsti}{}
\def\AM@getfirsti#1,#2\END#3\END{%
  \edef#3{#2}%
  \ifx\\#2\\%
    \setboolean{AM@endoflist}{true}%
    \def#3{}%
  \else
    \edef#3{\AM@getfirstii#2\END}%
  \fi
  \toks@{#1}%
}
\newcommand{\AM@getfirstii}{}
\def\AM@getfirstii#1,\END{#1}
\newcommand{\AM@readfirst}{}
\newcommand{\AM@readfirsti}{}
\def\AM@readfirst#1{\expandafter\AM@readfirsti#1,\END}
\def\AM@readfirsti#1,#2\END{\toks@{#1}}
\newcommand{\AM@getlast}{}
\def\AM@getlast#1{%
  \let\AM@temp\relax
  \expandafter\AM@getlasti#1,\END
  \@ifundefined{AM@temp}{\def#1{}}{\edef#1{\AM@temp}}%
}
\def\AM@ReturnAfterFi#1\fi{\fi#1}
\def\AM@ReturnAfterFiFi#1\fi\fi{\fi\fi#1}
\def\AM@ReturnAfterElseFiFi#1\else#2\fi#3\fi{\fi\fi#1}
\newcommand{\AM@getlasti}{}
\def\AM@getlasti#1,#2\END{%
  \ifx\\#2\\%
    \def\AM@lastitem{#1}%
  \else
    \@ifundefined{AM@temp}
      {\edef\AM@temp{#1}}
      {\edef\AM@temp{\AM@temp,#1}}%
    \AM@ReturnAfterFi{\AM@getlasti#2\END}%
  \fi
}
\newcommand{\AM@getlastn}{}
\def\AM@getlastn#1#2{%
  \let\AM@templist\relax
  \@tempcnta=\z@
  \loop
  \ifnum\@tempcnta<#2
    \AM@getlast{#1}%
    \@ifundefined{AM@templist}
      {\edef\AM@templist{\AM@lastitem}}
      {\edef\AM@templist{\AM@lastitem,\AM@templist}}%
    \advance\@tempcnta\@ne
  \repeat
  \edef\AM@lastnitems{\AM@templist}%
}
\newcommand{\AM@split@firstn}{}
\def\AM@split@firstn#1#2{%
  \edef\AM@tmp{\expandafter\@gobble\string#1@firstn}%
  \AM@getfirst{#1}%
  \expandafter\edef\csname\AM@tmp\endcsname{\the\toks@}%
  \@tempcnta=\@ne
  \@tempcntb=#2 \divide\@tempcntb\tw@
  \loop\ifnum\@tempcnta<\@tempcntb
    \AM@getfirst{#1}%
    \expandafter\edef\csname\AM@tmp\endcsname
        {\@nameuse{\AM@tmp},\the\toks@}%
    \advance\@tempcnta\@ne
  \repeat
  \edef\AM@tmp{\expandafter\@gobble\string#1@lastn}%
  \AM@getfirst{#1}%
  \expandafter\edef\csname\AM@tmp\endcsname{\the\toks@}%
  \@tempcnta=\@ne
  \loop\ifnum\@tempcnta<\@tempcntb
    \AM@getfirst{#1}%
    \expandafter\edef\csname\AM@tmp\endcsname
        {\the\toks@,\@nameuse{\AM@tmp}}%
    \advance\@tempcnta\@ne
  \repeat
}
\newif\ifAM@again\AM@againtrue
\newcommand{\AM@count}{}
\def\AM@count#1{%
  \edef\AM@templist{#1}%
  \loop
    \AM@getlast{\AM@templist}%
    \expandafter\ifx\expandafter\\\AM@lastitem\\%
    \else
      \AM@againfalse
      \expandafter\ifx\expandafter\\\AM@templist\\%
        \edef\AM@templist{\AM@lastitem}%
      \else
        \edef\AM@templist{\AM@templist,\AM@lastitem}%
      \fi
      \@tempcnta=\z@
      \expandafter\AM@counti\AM@templist,\END,
    \fi
  \ifAM@again
  \repeat
}
\newcommand{\AM@counti}{}
\def\AM@counti#1,{%
  \ifx\END#1
  \else
    \advance\@tempcnta\@ne
    \expandafter\AM@counti
  \fi
}
\newif\ifAM@resort@end\AM@resort@endfalse
\newcommand{\AM@resort}{}
\def\AM@resort{%
  \def\AM@resortedpagelist{}%
  \def\AM@resorteddoclist{}%
  \def\AM@xnupi{\@ne}%
  \def\AM@ynupi{\@ne}%
  \AM@count{\AM@lastnpages}%
  \def\AM@xnuplast{%
    \the\@tempcnta - (\the\@tempcnta / \AM@xnup * \AM@xnup) + 1}%
  \def\AM@ynuplast{1 + (\the\@tempcnta / \AM@xnup)}%
  \setlength{\@tempdima}{\p@*(\AM@xnuplast)}%
  \edef\AM@xnuplast{\strip@pt\@tempdima}%
  \setlength{\@tempdima}{\p@*(\AM@ynuplast)}%
  \edef\AM@ynuplast{\strip@pt\@tempdima}%
  \whiledo{\not\boolean{AM@resort@end}}{%
    \@tempcnta=\AM@ynupi\relax
    \@tempcntb=\AM@ynuplast\relax
    \ifnum\@tempcnta=\@tempcntb
        \@tempcnta=\AM@xnupi\relax
        \@tempcntb=\AM@xnuplast\relax
        \ifnum\@tempcnta<\@tempcntb
          \AM@getfirst{\AM@lastndocs}%
          \edef\AM@firstdocitem{\the\toks@}%
          \AM@getfirst{\AM@lastnpages}%
          \edef\AM@resortedpagelist{\AM@resortedpagelist,\the\toks@}%
          \edef\AM@resorteddoclist{%
            \AM@resorteddoclist,\AM@firstdocitem}%
        \else
          \edef\AM@resortedpagelist{\AM@resortedpagelist,}%
          \edef\AM@resorteddoclist{\AM@resorteddoclist,\AM@phantomdoc}%
        \fi
    \else
      \ifnum\@tempcnta<\@tempcntb
        \AM@getfirst{\AM@lastndocs}%
        \edef\AM@firstdocitem{\the\toks@}%
        \AM@getfirst{\AM@lastnpages}%
        \edef\AM@resortedpagelist{\AM@resortedpagelist,\the\toks@}%
        \edef\AM@resorteddoclist{\AM@resorteddoclist,\AM@firstdocitem}%
      \else
        \edef\AM@resortedpagelist{\AM@resortedpagelist,}%
        \edef\AM@resorteddoclist{\AM@resorteddoclist,\AM@phantomdoc}%
      \fi
    \fi
    \@tempcnta=\AM@ynupi\relax
    \advance\@tempcnta\@ne
    \edef\AM@ynupi{\the\@tempcnta}%
    \@tempcntb=\AM@ynup\relax
    \ifnum\@tempcnta>\@tempcntb
      \@tempcntb=\AM@xnupi\relax
      \advance\@tempcntb\@ne
      \edef\AM@xnupi{\the\@tempcntb}%
      \def\AM@ynupi{\@ne}%
      \@tempcnta=\AM@xnup\relax
      \ifnum\@tempcntb>\@tempcnta
        \setboolean{AM@resort@end}{true}%
      \fi
    \fi
  }%
  \edef\AM@resortedpagelist{\expandafter\@gobble\AM@resortedpagelist}%
  \edef\AM@resorteddoclist{\expandafter\@gobble\AM@resorteddoclist}%
}
\newif\ifAM@pdfpages@options
\newcommand{\AM@split@options}{}
\def\AM@split@options#1#2{%
  \def\AM@param{#1}%
  \def\AM@scale@factor{1}%
  \@temptokena{}%
  \AM@split@optionsi#2,\END,
}
\def\AM@split@optionsi#1,{%
  \ifx\END#1
  \else
    \AM@pdfpages@optionsfalse \AM@scalefalse
    \AM@split@optionsii#1=\END
    \ifthenelse{\equal{\AM@param}{pdfpages}}
      {\ifAM@pdfpages@options
          \@temptokena\expandafter{\the\@temptokena,#1}%
       \fi}{}%
    \ifthenelse{\equal{\AM@param}{Gin}}
      {\ifAM@pdfpages@options\else
         \@temptokena\expandafter{\the\@temptokena,#1}%
       \fi}{}%
    \ifthenelse{\equal{\AM@param}{Gin@noscale}}
      {\ifAM@pdfpages@options\else
         \ifAM@scale\else
           \@temptokena\expandafter{\the\@temptokena,#1}%
         \fi
       \fi}{}%
    \expandafter\AM@split@optionsi
  \fi
}
\newcommand{\AM@split@optionsii}{}
\def\AM@split@optionsii#1=#2\END{%
  \edef\AM@temp{\AM@trim@space{#1}}%
  \ifthenelse{\equal{page}{\AM@temp}\or
              \equal{pages}{\AM@temp}\or
              \equal{nup}{\AM@temp}\or
              \equal{deltax}{\AM@temp}\or
              \equal{deltay}{\AM@temp}\or
              \equal{delta}{\AM@temp}\or
              \equal{offset}{\AM@temp}\or
              \equal{frame}{\AM@temp}\or
              \equal{openright}{\AM@temp}\or
              \equal{openrighteach}{\AM@temp}\or
              \equal{pagecommand}{\AM@temp}\or
              \equal{pagecommand*}{\AM@temp}\or
              \equal{landscape}{\AM@temp}\or
              \equal{turn}{\AM@temp}\or
              \equal{column}{\AM@temp}\or
              \equal{columnstrict}{\AM@temp}\or
              \equal{noautoscale}{\AM@temp}\or
              \equal{thread}{\AM@temp}\or
              \equal{threadname}{\AM@temp}\or
              \equal{link}{\AM@temp}\or
              \equal{linkfit}{\AM@temp}\or
              \equal{linkname}{\AM@temp}\or
              \equal{linktodoc}{\AM@temp}\or
              \equal{linktodocfit}{\AM@temp}\or
              \equal{linkfilename}{\AM@temp}\or
              \equal{survey}{\AM@temp}\or
              \equal{survey-nolink}{\AM@temp}\or
              \equal{output}{\AM@temp}\or
              \equal{xr-prefix}{\AM@temp}\or
              \equal{fitpaper}{\AM@temp}\or
              \equal{addtotoc}{\AM@temp}\or
              \equal{addtolist}{\AM@temp}\or
              \equal{doublepages}{\AM@temp}\or
              \equal{doublepagestwist}{\AM@temp}\or
              \equal{doublepagestwistodd}{\AM@temp}\or
              \equal{doublepagestwist*}{\AM@temp}\or
              \equal{doublepagestwistodd*}{\AM@temp}\or
              \equal{duplicatepages}{\AM@temp}\or
              \equal{signature}{\AM@temp}\or
              \equal{signature*}{\AM@temp}\or
              \equal{booklet}{\AM@temp}\or
              \equal{booklet*}{\AM@temp}\or
              \equal{flip-other-edge}{\AM@temp}\or
              \equal{pagetemplate}{\AM@temp}\or
              \equal{templatesize}{\AM@temp}\or
              \equal{rotateoversize}{\AM@temp}\or
              \equal{picturecommand}{\AM@temp}\or
              \equal{picturecommand*}{\AM@temp}\or
              \equal{newwindow}{\AM@temp}\or
              \equal{reflect}{\AM@temp}\or
              \equal{reflect*}{\AM@temp}\or
              \equal{lastpage}{\AM@temp}}
             {\AM@pdfpages@optionstrue}{}%
  \ifthenelse{\equal{scale}{\AM@temp}}{%
    \AM@scaletrue
    \def\AM@ooo##1={##1}%
    \setlength{\@tempdima}{\p@ * \AM@scale@factor * \real{\AM@ooo#2}}%
    \edef\AM@scale@factor{\strip@pt\@tempdima}%
  }{}%
}
\newcommand{\AM@trim@space}{}\newcommand{\AM@trim@spacei}{}
\newcommand{\AM@trim@spaceii}{}
\def\AM@trim@space#1{%
  \expandafter\AM@trim@spacei\expandafter{\ifdim\z@=0pt#1}\fi}
\def\AM@trim@spacei#1{\AM@trim@spaceii#1 \END}
\def\AM@trim@spaceii#1 #2\END{#1}
\DeclareRobustCommand{\AM@trim@leadingspace}[1]{\ifdim\z@=0pt#1\fi}
\newif\ifAM@phantompage
\newcommand*{\AM@isphantom}{%
  \expandafter\ifx\expandafter\\\AM@nextpage\\%
    \let\AM@nextpage\AM@phantompage
    \let\AM@ph\phantom
    \AM@phantompagetrue
  \else
    \let\AM@ph\relax
    \AM@phantompagefalse
  \fi
}
\newcommand{\AM@hyper@begin@i}{%
  \ifAM@link \AM@dest@special\fi
}
\newcommand{\AM@hyper@begin@ii}{%
  \ifAM@survey \ifAM@surveynolink\else
    \AM@survey@special@begin
  \fi\fi
  \ifAM@linktodoc\AM@linktodoc@special@begin\fi
  \ifAM@thread\AM@thread@special@begin\fi
}
\newcommand{\AM@hyper@end}{%
  \ifAM@survey \ifAM@surveynolink\else
    \AM@survey@special@end
  \fi \fi
  \ifAM@linktodoc\AM@linktodoc@special@end\fi
  \ifAM@thread\AM@thread@special@end\fi
}
\newcommand{\AM@openright}{}
\def\AM@openright{%
  \edef\AM@pagelist{,\AM@pagelist}%
  \edef\AM@doclist{\AM@phantomdoc,\AM@doclist}%
}
\newcommand{\AM@countpagelist}{}
\def\AM@countpagelist{%
  \@tempcnta=\z@
  \expandafter\AM@countpagelisti\AM@pagelist,\END,
}
\newcommand{\AM@countpagelisti}{}
\def\AM@countpagelisti#1,{%
  \ifx\END#1
  \else
    \advance\@tempcnta\@ne
    \expandafter\AM@countpagelisti
  \fi
}
\newcommand{\AM@filluppagelist}{}
\def\AM@filluppagelist{%
  \@tempcnta=\AM@xnup\relax
  \@tempcntb=\AM@ynup\relax
  \multiply\@tempcnta\@tempcntb
  \edef\AM@nup{\the\@tempcnta}%
  \AM@countpagelist
  \@tempcntb=\@tempcnta
  \divide\@tempcntb\AM@nup
  \multiply\@tempcntb\AM@nup
  \advance\@tempcnta-\@tempcntb
  \ifnum\@tempcnta=\z@
    \else
      \advance\@tempcnta-\AM@nup
      \multiply\@tempcnta\m@ne
  \fi
  \whiledo{\@tempcnta > \z@}{%
    \let\saveAM@pagelist\AM@pagelist
    \edef\AM@pagelist{\saveAM@pagelist,}%
    \advance\@tempcnta\m@ne
    \let\saveAM@doclist\AM@doclist
    \edef\AM@doclist{\saveAM@doclist,\AM@phantomdoc}%
  }%
}
\newcommand{\AM@prepare@signature}{}
\def\AM@prepare@signature{%
  \def\AM@newpagelist{}%
  \def\AM@newdoclist{}%
  \ifAM@booklet
    \AM@countpagelist
    \@tempcntb=\@tempcnta
    \divide\@tempcnta by 4
    \multiply\@tempcnta by 4
    \advance\@tempcntb-\@tempcnta
    \ifnum\@tempcntb=0\else \advance\@tempcnta by 4\fi
    \edef\AM@signature{\the\@tempcnta}%
  \fi
  \@tempcnta=\AM@signature\relax
  \divide\@tempcnta by 4
  \multiply\@tempcnta by 4
  \ifnum\@tempcnta=0\@tempcnta=4\fi
  \edef\AM@signature{\the\@tempcnta}%
  \AM@countpagelist
  \count@=\@tempcnta
  \@tempcntb=\AM@signature\relax
  \divide\count@\@tempcntb
  \multiply\count@\@tempcntb
  \advance\@tempcnta-\count@
  \ifnum\@tempcnta=0 \@tempcntb=0
  \else\advance\@tempcntb-\@tempcnta
  \fi
  \whiledo{\@tempcntb>\z@}{%
    \edef\AM@pagelist{\AM@pagelist,}%
    \edef\AM@doclist{\AM@doclist,\AM@phantomdoc}%
    \advance\@tempcntb\m@ne
  }%
  \def\AM@sort{%
    \def\AM@sigpagelist{}%
    \def\AM@sigdoclist{}%
    \AM@split@firstn{\AM@pagelist}{\AM@signature}%
    \AM@split@firstn{\AM@doclist}{\AM@signature}%
    \def\AM@first{%
      \AM@getfirst{\AM@pagelist@firstn}%
      \edef\AM@sigpagelist{\AM@sigpagelist,\the\toks@}%
      \AM@getfirst{\AM@doclist@firstn}%
      \edef\AM@sigdoclist{\AM@sigdoclist,\the\toks@}%
    }%
    \def\AM@last{%
      \AM@getfirst{\AM@pagelist@lastn}%
      \edef\AM@sigpagelist{\AM@sigpagelist,\the\toks@}%
      \AM@getfirst{\AM@doclist@lastn}%
      \edef\AM@sigdoclist{\AM@sigdoclist,\the\toks@}%
    }%
    \@tempcnta=\z@
    \@tempcntb=\AM@signature\relax
    \whiledo{\@tempcnta<\@tempcntb}{%
      \ifAM@landscape
        \ifAM@signaturestar
          \ifAM@swap@flip@edge
            \AM@last\AM@first\AM@last\AM@first
          \else
            \AM@first\AM@last\AM@last\AM@first
          \fi
        \else
          \ifAM@swap@flip@edge
            \AM@first\AM@last\AM@first\AM@last
          \else
            \AM@last\AM@first\AM@first\AM@last
          \fi
        \fi
      \else
        \ifAM@signaturestar
          \ifAM@swap@flip@edge
            \AM@last\AM@first\AM@last\AM@first
          \else
            \AM@first\AM@last\AM@last\AM@first
          \fi
        \else
          \ifAM@swap@flip@edge
            \AM@first\AM@last\AM@first\AM@last
          \else
            \AM@last\AM@first\AM@first\AM@last
          \fi
        \fi
      \fi
      \advance\@tempcnta by 4
    }%
    \edef\AM@newpagelist{\AM@newpagelist\AM@sigpagelist}%
    \edef\AM@newdoclist{\AM@newdoclist\AM@sigdoclist}%
    \ifx\AM@pagelist\@empty
    \else\expandafter\AM@sort
    \fi
  }%
  \AM@sort
  \edef\AM@pagelist{\expandafter\@gobble\AM@newpagelist}%
  \edef\AM@doclist{\expandafter\@gobble\AM@newdoclist}%
  \AM@pagesize@boogie
  \ifnum\AM@xnup=1\relax
    \ifnum\AM@ynup=1\relax
      \ifdim\AM@pagewidth<\AM@pageheight
        \def\AM@xnup{1}\def\AM@ynup{2}%
      \else
        \def\AM@xnup{2}\def\AM@ynup{1}%
      \fi
      \PackageWarningNoLine{pdfpages}{%
        Option `nup' not set correctly. \MessageBreak
        I will continue with `nup=\AM@xnup x\AM@ynup'. Please remember\MessageBreak
        to set `nup' correctly when using `\ifAM@booklet booklet\else signature\fi'}
    \fi
  \fi
}
\newcommand*{\AM@setphantom}{%
  \@ifundefined{AM@pagetemplate}
    {\expandafter\AM@setphantompage\AM@pagelist,\END,}
    {\edef\AM@phantompage{\AM@pagetemplate}}%
  \expandafter\AM@setphantomdoc\AM@doclist,\END
}
\newcommand{\AM@setphantompage}{}
\def\AM@setphantompage#1,{%
  \def\AM@gobble##1\END,{}%
  \ifx\\#1\\%
    \expandafter\AM@setphantompage
  \else
    \def\AM@phantompage{#1}%
    \expandafter\AM@gobble
  \fi
}
\newcommand{\AM@setphantomdoc}{}
\def\AM@setphantomdoc#1,#2\END{\edef\AM@phantomdoc{#1}}
\newcommand{\AM@addtotoc@hook}{\relax}
\newcommand{\AM@addtotoc}{}
\def\AM@addtotoc{%
  \begingroup
  \def\@seccntformat##1{}\def\@makechapterhead##1{}%
  \def\@endpart{}\def\partname{}%
  \def\autodot{}% KOMA classes
  \edef\ch@pt@c{\the\AM@toc@title}% memoir classes
  \let\AM@addcontentsline\addcontentsline
  \def\addcontentsline##1##2##3{%
    \AM@addcontentsline{##1}{##2}{##3}%
    \def\thepart{}}%
  \AM@addtotoc@hook
  \edef\AM@temp{{\AM@toc@section}{\AM@toc@level}%
           {\z@}{\z@}{\z@}{}[\the\AM@toc@title]{}}%
  \edef\AM@tempi{\leavevmode\noexpand\csname @\AM@toc@section\noexpand\endcsname%
                 [\the\AM@toc@title]{}}%
  \@ifundefined{@\AM@toc@section}
    {\expandafter\@sect\AM@temp
     \hskip\z@\par\vskip-\parskip\vskip-\baselineskip\hskip\z@}
    {\AM@tempi}%
  \xdef\@currentlabel{\@currentlabel}%
  \label{\AM@toc@label}%
  \endgroup
}
\newcommand{\AM@parse@toclist}{}
\def\AM@parse@toclist{%
  \ifx\AM@toclist\empty \def\AM@toc@page{0}%
  \else \expandafter\AM@parse@toclisti\AM@toclist\END
  \fi
}
\newtoks\AM@toc@title
\newcommand{\AM@parse@toclisti}{}
\def\AM@parse@toclisti#1,#2,#3,#4,#5,#6\END{%
  \edef\AM@toc@page{\AM@trim@space{#1}}%
  \edef\AM@toc@section{\AM@trim@space{#2}}%
  \edef\AM@toc@level{\AM@trim@space{#3}}%
  \AM@toc@title{\ignorespaces #4}%
  \edef\AM@toc@label{\AM@trim@space{#5}}%
  \AM@checkinteger{\AM@toc@page}%
  \ifAM@integer\else
    \PackageError{pdfpages}
         {Missing number.\MessageBreak
          Page number in option `addtotoc' is not a number}
         {See the pdfpages manual for explanation.}%
   \fi
}
\newcommand{\AM@rm@from@toclist}{}
\def\AM@rm@from@toclist{%
    \expandafter\AM@rm@from@toclisti\AM@toclist\END
}
\newcommand{\AM@rm@from@toclisti}{}
\def\AM@rm@from@toclisti#1,#2,#3,#4,#5,#6\END{%
  \def\AM@toclist{#6}%
}
\newcommand{\AM@addtolist@hook}{\relax}
\newcommand{\AM@addtolist}{}
\def\AM@addtolist{%
  \def\@captype{\AM@lof@list}%
  \long\def\@makecaption##1##2{}%
  \def\@fs@capt##1##2{}% float.sty
  \edef\@currentlabelname{\the\AM@lof@heading}% float.sty
  \AM@addtolist@hook
  \@ifundefined{hyper@@anchor}{%
    \expandafter\caption\expandafter{\the\AM@lof@heading}%
  }{%
    \hyper@makecurrent{\@captype}%
    \expandafter\caption\expandafter{\the\AM@lof@heading}%
    \hyper@@anchor{\@currentHref}{\relax}%
    \let\Hy@float@currentHref\@undefined
  }%
  \label{\AM@lof@label}%
  \vskip-\baselineskip
}
\newcommand{\AM@parse@loflist}{}
\def\AM@parse@loflist{%
  \ifx\AM@loflist\empty \def\AM@lof@page{0}%
  \else \expandafter\AM@parse@loflisti\AM@loflist\END
  \fi
}
\newtoks\AM@lof@heading
\newcommand{\AM@parse@loflisti}{}
\def\AM@parse@loflisti#1,#2,#3,#4,#5\END{%
  \edef\AM@lof@page{\AM@trim@space{#1}}%
  \edef\AM@lof@list{\AM@trim@space{#2}}%
  \AM@lof@heading{#3}%
  \edef\AM@lof@label{\AM@trim@space{#4}}%
  \AM@checkinteger{\AM@lof@page}%
  \ifAM@integer\else
    \PackageError{pdfpages}
         {Missing number.\MessageBreak
          Page number in option `addtolist' is not a number}
         {See the pdfpages manual for explanation.}%
  \fi
}
\newcommand{\AM@rm@fromloflist}{}
\def\AM@rm@from@loflist{%
    \expandafter\AM@rm@from@loflisti\AM@loflist\END
}
\newcommand{\AM@rm@from@loflisti}{}
\def\AM@rm@from@loflisti#1,#2,#3,#4,#5\END{%
  \def\AM@loflist{#5}%
}
\newcommand{\AM@toclof}{}
\def\AM@toclof#1{%
  \AM@parse@toclist
  \whiledo{#1=\AM@toc@page}{%
    \ifx\AM@toclist\empty
    \else
      \AM@addtotoc
      \AM@rm@from@toclist
      \def\AM@toc@page{0}%
      \AM@parse@toclist
    \fi
  }%
  \AM@parse@loflist
  \whiledo{#1=\AM@lof@page}{%
    \ifx\AM@loflist\empty
    \else
      \AM@addtolist
      \AM@rm@from@loflist
      \def\AM@lof@page{0}%
      \AM@parse@loflist
    \fi
  }%
}
\ifAM@pkg@survey
  \newcommand{\AddToSurvey}{%
      \protected@write\@auxout{\let\AM@abs@page\relax}
         {\string\newlabel{\AM@xrprefix pdfpages@page\the\c@AM@survey}%
            {{}{\AM@abs@page}}}%
      \stepcounter{AM@survey}%
  }%
  \let\r@TotalPages\undefined
\else
  \newcommand{\AddToSurvey}{}
\fi
\newcounter{AM@survey}
\def\AM@abs@page{\the\count1}
\newcommand{\AM@pageref}{}
\newcommand{\AM@@pageref}{}
\newcommand{\AM@secondarg}{}
\def\AM@pageref#1{\expandafter\AM@@pageref\csname r@#1\endcsname}
\def\AM@@pageref#1{\expandafter\AM@secondarg#1\@nil}
\def\AM@secondarg#1#2#3\@nil{#2}
\def\AM@TeXpower@hook{%
  \ifAM@pkg@survey
  \@ifpackageloaded{texpower}{%
    \releasecounter{AM@survey}%
    \let\AM@SetLabel\relax
    \g@addto@macro\do@insert@firstanchor@TP{%
      \AM@SetLabel\AM@SetTarget}%
    \g@addto@macro\dont@insert@firstanchor@TP{%
      \AM@SetLabel\AM@SetTarget}%
    \let\AM@setanchor\relax
    \def\AM@SetTarget{%
      \begingroup
      \advance\count1\m@ne
      \AM@anchor@special
      \endgroup
    }%
    \let\OrigAddToSurvey\AddToSurvey
    \def\AddToSurvey{%
      \ifthenelse{\boolean{instepwise@TP}}
        {\ifthenelse{\boolean{firstactivation}}{\AM@AddLabel}{}}
        {\AM@AddLabel}%
    }%
    \def\AM@AddLabel{\global\let\AM@SetLabel\OrigAddToSurvey
      \AtShipout{\AM@KillLabel}}%
    \def\AM@KillLabel{\global\let\AM@SetLabel\relax}%
  }{}%
  \fi
}
\AtBeginDocument{\AM@TeXpower@hook}
\def\AM@CheckValue#1#2{%
  \ifx\\#2\\\PackageError{pdfpages}
             {Option `#1' must have a non-empty value}{}%
  \fi
}
\define@key{pdfpages}{page}{\PackageWarningNoLine{pdfpages}{%
    Option `page' is unknow to \string\includepdf.\MessageBreak
    Did you mean `pages'? (Note the `s'!)\MessageBreak
    OK, I'll proceed as if it were `pages'}%
  \AM@CheckValue{pages}{#1}%
  \def\AM@pagestemp{#1}}
\define@key{pdfpages}{pages}{\AM@CheckValue{pages}{#1}%
                             \edef\AM@pagestemp{#1}}
\define@key{pdfpages}{nup}{\expandafter\AM@parse@nup\expanded{#1}x\END}
\define@key{pdfpages}{deltax}{\expandafter\AM@parse@deltax\expanded{#1} \\}
\define@key{pdfpages}{deltay}{\expandafter\AM@parse@deltay\expanded{#1} \\}
\define@key{pdfpages}{delta}{\expandafter\AM@parse@delta\expanded{#1} \\}
\define@key{pdfpages}{offset}{\expandafter\AM@parse@offset\expanded{#1} \\}
\define@key{pdfpages}{frame}[true]{\setboolean{AM@frame}{#1}}
\define@key{pdfpages}{openright}[true]{\setboolean{AM@openright}{#1}}
\define@key{pdfpages}{openrighteach}[true]{\setboolean{AM@openrighteach}{#1}}
\define@key{pdfpages}{pagecommand}{\def\AM@pagecommand{#1}}
\define@key{pdfpages}{pagecommand*}{\def\AM@pagecommandstar{#1}}
\define@key{pdfpages}{landscape}[true]{\setboolean{AM@landscape}{#1}}
\define@key{pdfpages}{turn}[true]{\setboolean{AM@turn}{#1}}
\define@key{pdfpages}{column}[true]{\setboolean{AM@column}{#1}}
\define@key{pdfpages}{columnstrict}[true]%
                     {\setboolean{AM@columnstrict}{#1}}
\define@key{pdfpages}{noautoscale}[true]%
                     {\setboolean{AM@noautoscale}{#1}}
\define@key{pdfpages}{thread}[true]{\setboolean{AM@thread}{#1}}
\define@key{pdfpages}{threadname}{\edef\AM@threadname{#1}}
\define@key{pdfpages}{link}[true]{\setboolean{AM@link}{#1}}
\define@key{pdfpages}{linkfit}{\expandafter\AM@convert@dest\expanded{{#1}}}
\define@key{pdfpages}{linkname}{\edef\AM@linkname@option{#1}}
\define@key{pdfpages}{linktodoc}[true]{\setboolean{AM@linktodoc}{#1}}
\define@key{pdfpages}{linktodocfit}{\edef\AM@linktodocfit{#1}}
\define@key{pdfpages}{linkfilename}{\pdfstringdef\AM@linkfilename{#1}%
                               \AM@linkfilenametrue}
\define@key{pdfpages}{survey}[true]{%
                      \ifAM@pkg@survey\setboolean{AM@survey}{#1}%
                      \else\AM@outputfalse\fi}
\define@key{pdfpages}{survey-nolink}[true]{%
                      \ifAM@pkg@survey\setboolean{AM@surveynolink}{#1}%
                                      \setboolean{AM@survey}{#1}
                      \else\AM@outputfalse\fi}
\define@key{pdfpages}{xr-prefix}{\edef\AM@xrprefix{#1}}
\define@key{pdfpages}{fitpaper}[true]{\setboolean{AM@fitpaper}{#1}}
\define@key{pdfpages}{addtotoc}{\protected@edef\AM@toclist{#1,}}
\define@key{pdfpages}{addtolist}{\protected@edef\AM@loflist{#1,}}
\define@key{pdfpages}{doublepages}[true]%
                     {\setboolean{AM@doublepages}{#1}}
\define@key{pdfpages}{doublepagestwist}[true]%
                     {\setboolean{AM@doublepages}{#1}%
                      \setboolean{AM@doublepagestwist}{#1}%
                      \AM@doublepagestmptrue\AM@doublepagestmpitrue}
\define@key{pdfpages}{doublepagestwistodd}[true]%
                     {\setboolean{AM@doublepages}{#1}%
                      \setboolean{AM@doublepagestwist}{#1}%
                      \AM@doublepagestmpfalse\AM@doublepagestmpitrue}
\define@key{pdfpages}{doublepagestwist*}[true]%
                     {\setboolean{AM@doublepages}{#1}%
                      \setboolean{AM@doublepagestwist}{#1}%
                      \AM@doublepagestmptrue\AM@doublepagestmpitrue
                      \AM@doublepagestwistxtrue}
\define@key{pdfpages}{doublepagestwistodd*}[true]%
                     {\setboolean{AM@doublepages}{#1}%
                      \setboolean{AM@doublepagestwist}{#1}%
                      \AM@doublepagestmpfalse\AM@doublepagestmpitrue
                      \AM@doublepagestwistxtrue}
\define@key{pdfpages}{duplicatepages}[2]%
                     {\edef\AM@nduplicatepages{#1}%
                      \AM@duplicatepagestrue}
\define@key{pdfpages}{signature}{\edef\AM@signature{#1}}
\define@key{pdfpages}{signature*}{\edef\AM@signature{#1}%
                                  \AM@signaturestartrue}
\define@key{pdfpages}{booklet}[true]{
  \setboolean{AM@booklet}{#1}%
  \ifAM@booklet
    \def\AM@signature{non-empty}
  \fi}
\define@key{pdfpages}{booklet*}[true]{
  \ifstrequal{#1}{true}{%
      \setboolean{AM@booklet}{#1}
      \ifAM@booklet
        \def\AM@signature{non-empty}
        \AM@signaturestartrue
      \fi}}
\define@key{pdfpages}{flip-other-edge}[true]{\setboolean{AM@swap@flip@edge}{#1}}
\define@key{pdfpages}{pagetemplate}{\AM@CheckValue{pagetemplate}{#1}%
                                    \def\AM@pagetemplate{#1}}
\define@key{pdfpages}{templatesize}{\expandafter\AM@parse@templatesize\expanded{#1}\END}
\define@key{pdfpages}{rotateoversize}[true]%
                     {\setboolean{AM@rotateoversize}{#1}}
\define@key{pdfpages}{picturecommand}{\def\AM@picturecommand{#1}}
\define@key{pdfpages}{picturecommand*}{\def\AM@picturecommandstar{#1}}
\define@key{pdfpages}{newwindow}[true]{\setboolean{AM@newwindow}{#1}}
\define@key{pdfpages}{reflect*}[true]{\setboolean{AM@reflect}{#1}}
\define@key{pdfpages}{reflect}[true]{\setboolean{AM@reflectall}{#1}}
\define@key{pdfpages}{lastpage}{\edef\AM@pagecount{#1}}
\newcommand{\AM@parse@nup}{}
\def\AM@parse@nup#1x#2\END{%
  \ifx\\#2\\%
    \def\AM@shortnupsyntax{}%
    \def\AM@xnup{\@ne}%
    \def\AM@ynup{\@ne}%
    \ifnum#1=\tw@
      \def\AM@xnup{\tw@}%
      \def\AM@ynup{\@ne}%
    \fi
    \ifnum#1=4
      \def\AM@xnup{\tw@}%
      \def\AM@ynup{\tw@}%
    \fi
  \else
    \def\AM@xnup{#1}%
    \AM@parse@nupi#2%
  \fi
}
\def\AM@parse@nupi#1x{\def\AM@ynup{#1}}
\newcommand{\AM@parse@templatesize}{}
\def\AM@parse@templatesize#1#2\END{%
  \setbox\AM@templatesizebox=\hbox{\rule{#1}{#2}}%
  \AM@templatesizetrue
}
\newbox\AM@templatesizebox
\newif\ifAM@templatesize\AM@templatesizefalse
\def\AM@parse@deltax#1 #2\\{\AMGin@defaultbp\AM@deltax{#1}}
\def\AM@parse@deltay#1 #2\\{\AMGin@defaultbp\AM@deltay{#1}}
\def\AM@parse@delta#1 #2 #3\\{%
  \AMGin@defaultbp\AM@deltax{#1}%
  \AMGin@defaultbp\AM@deltay{#2}}
\def\AM@parse@offset#1 #2 #3\\{%
  \AMGin@defaultbp\AM@xoffset{#1}%
  \AMGin@defaultbp\AM@yoffset{#2}}
\def\AMGin@defaultbp#1#2{%
  \afterassignment\AMGin@def@bp\dimen@#2bp\relax{#1}{#2}}
\def\AMGin@def@bp#1\relax#2#3{%
   \if!#1!%
     \def#2{#3bp}%
    \else
      \dimen@.99626\dimen@
      \edef#2{\strip@pt\dimen@ bp}%
    \fi
  }
\def\AM@thousand#1{\AM@thousand@i#1.0000.\END}
\def\AM@thousand@i#1.#2.#3\END{\AM@thousand@ii#1.#2#3\END}
\def\AM@thousand@ii#1.#2#3#4#5#6\END{#1#2#3#4}
\InputIfFileExists{pdfpages.fix}{%
  \PackageInfo{pdfpages}{Loading patch file `pdfpages.fix'}}{}
\endinput
%%
%% End of file `pdfpages.sty'.
