%%
%% 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-2006 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@fileversion{v0.4f}
\def\AM@SVN@Date@i#1-#2-#3\END{\def\AM@filedate{#1/#2/#3}}
\def\AM@SVN@Date$Date: #1 #2${\AM@SVN@Date@i#1\END}
\AM@SVN@Date$Date: 2008-06-22 22:50:12 +0200 (Sun, 22 Jun 2008) $
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pdfpages}
   [\AM@filedate\space\AM@fileversion\space
    Insert pages of external PDF documents (AM)]
\newif\ifAM@pkg@draft \AM@pkg@draftfalse
\newif\ifAM@pkg@survey \AM@pkg@surveyfalse
\DeclareOption{draft}{\AM@pkg@drafttrue}
\DeclareOption{final}{\AM@pkg@draftfalse}
\DeclareOption{enable-survey}{\AM@pkg@surveytrue}
\DeclareOption{disable-survey}{\AM@pkg@surveyfalse}
\def\AM@ifdriverlater{\@ifl@ter{def}}
\InputIfFileExists{pdfpages.cfg}{%
  \PackageInfo{pdfpages}{Loading configuration file `pdfpages.cfg'}}{}
\DeclareOption{pdftex}{\def\AM@driver{pdftex}}
\DeclareOption{vtex}{\def\AM@driver{vtex}}
\DeclareOption{null}{\def\AM@driver{null}}
\DeclareOption{xetex}{\def\AM@driver{xetex}}
\ProcessOptions
\@ifundefined{AM@driver}{
  \begingroup
  \@ifundefined{pdftexversion}{%
    \@ifundefined{XeTeXversion}{%
      \@ifundefined{OpMode}{%
        \def\AM@driver{null}
      }{\gdef\AM@driver{vtex}}%
    }{\gdef\AM@driver{xetex}}%
  }{\gdef\AM@driver{pdftex}}
  \endgroup
}{}
\RequirePackage{ifthen, graphicx, calc, eso-pic}
\newif\ifAM@DVIoutput\AM@DVIoutputfalse
\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
\@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@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@linkfilename\AM@linkfilenamefalse
\newif\ifAM@signature\AM@signaturefalse
\newif\ifAM@signaturestar\AM@signaturestarfalse
\newif\ifAM@booklet\AM@bookletfalse
\newif\ifAM@sigrotate\AM@sigrotatefalse
\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
\newcommand*{\AM@pagestemp}{1}
\newcommand*{\AM@pagecommand}{\thispagestyle{empty}}
\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@thumbpdf
\newif\ifAM@pdflscape
\AtBeginDocument{%
  \@ifpackageloaded{thumbpdf}{\AM@thumbpdftrue}{\AM@thumbpdffalse}%
  \@ifpackageloaded{pdflscape}{\AM@pdflscapetrue}{\AM@pdflscapefalse}%
  \ifAM@thumbpdf
    \ifAM@pdflscape
      \def\AM@setlscape{\PLS@Rotate{90}}%
    \else
      \PackageWarningNoLine{pdfpages}{%
        You are using `thumbpdf.sty' but not\MessageBreak
        `pdflscape.sty'.\MessageBreak
        Please, insert `pdflscape.sty' in  your document\MessageBreak
        to get a pleasant PDF document with thumbs}%
    \fi
  \fi
}
\newif\ifAM@integer
\newcommand{\AM@checkinteger}{}
\def\AM@checkinteger#1{%
  \ifcat _\ifnum9<1#1_\else A\fi
    \AM@integertrue
  \else
    \AM@integerfalse
  \fi
}
\newcommand*{\AM@findfile@i}[2]{%
  \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'}{}%
  \fi
}
\newcommand*{\includepdfset}[1]{%
  \AM@split@options{pdfpages}{#1}%
  \edef\AM@temp{{pdfpages}{\the\@temptokena}}%
  \expandafter\setkeys\AM@temp
}
\newcommand*{\includepdf}[2][]{%
  \begingroup
  \let\AM@threadname\relax
  \AM@split@options{pdfpages}{#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}%
    \if\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}%
    \AM@output{#1}%
  \fi
  \AM@CheckAtEnd
  \endgroup
  \AM@ClearShipoutPicture
}
\newcommand*{\includepdfmerge}[2][]{%
  \begingroup
  \let\AM@currentdocname\relax
  \AM@readlist{#2}%
  \AM@split@options{pdfpages}{#1}%
  \edef\AM@temp{{pdfpages}{\the\@temptokena}}%
  \expandafter\setkeys\AM@temp
  \AM@output{#1}%
  \AM@CheckAtEnd
  \endgroup
  \AM@ClearShipoutPicture
}
\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}[1]{%
  \c@totalnumber=0
  \if@twocolumn\let\AM@twocolumn\relax \onecolumn \fi
  \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{-\fboxrule}\def\AM@deltay{-\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
  \ifthenelse{\boolean{AM@landscape}}
    {\def\AM@lscape@rot{90}%
     \@ifundefined{AM@shortnupsyntax}{}
       {\let\AM@temp\AM@xnup
        \let\AM@xnup\AM@ynup
        \let\AM@ynup\AM@temp}%
    }{}%
  \AM@setphantom
  \ifthenelse{\boolean{AM@openright}}
         {\AM@openright}{}%
  \ifx\AM@signature\@empty\AM@filluppagelist
  \else\AM@prepare@signature\AM@signaturetrue\AM@turnfalse\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}}
         {\let\AM@fbox\fbox}
         {\let\AM@fbox\relax
          \setlength{\fboxrule}{\z@}}%
  \ifthenelse{\boolean{AM@reflect}}
         {\let\AM@reflectbox\reflectbox}
         {\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
  \setlength{\fboxsep}{\z@}%
  \@ifundefined{AM@pagetemplate}
      {\AM@readfirst{\AM@pagelist}%
       \edef\AM@page{\the\toks@}}
      {\edef\AM@page{\AM@pagetemplate}}%
  \AM@readfirst{\AM@doclist}%
  \edef\AM@docname{\the\toks@}%
  \newpage
  \AM@isphantom
  \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
        \setbox\@tempboxa=\hbox{%
          \expandafter\includegraphics\expandafter[\the\@temptokena,
            page=\AM@page, angle=\AM@lscape@rot]{\AM@docname}}%
      \fi
    \fi
    \ifthenelse{\boolean{AM@fitpaper}}
      {\setlength{\AM@pagewidth}{\the\wd\@tempboxa}%
       \setlength{\AM@pageheight}{\the\ht\@tempboxa+\the\dp\@tempboxa}%
       \setlength{\paperwidth}{\the\wd\@tempboxa}%
       \setlength{\paperheight}{\the\ht\@tempboxa+\the\dp\@tempboxa}%
       \AM@fitpaper@special
       \AM@setpagedimen
       \@ifundefined{stockwidth}{}{%
         \setlength{\stockwidth}{\AM@pagewidth}%
         \setlength{\stockheight}{\AM@pageheight}%
         \setlength{\trimtop}{0pt}%
         \setlength{\trimedge}{0pt}}%
      }{}%
    \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
    \ifdim\paperwidth=\z@
      \let\paperwidth\AM@pagewidth
    \fi
    \ifdim\paperheight=\z@
      \let\paperheight\AM@pageheight
    \fi
    \def\AM@xscale{%
      (\paperwidth - \tw@\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{
      (\paperheight - \tw@\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@globalscale}{\copy\AM@templatesizebox}}%
    \setbox\@tempboxa=\hbox{%
      \rotatebox{\AM@lscape@rot}{\copy\@tempboxa}}%
  \else
    \setbox\@tempboxa=\hbox{%
      \expandafter\includegraphics\expandafter[\the\@temptokena,
                       page=\AM@page, scale=\AM@globalscale,
                       angle=\AM@lscape@rot]{\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{%
    (\paperwidth - (\wd\@tempboxa+\tw@\fboxrule)*\AM@xnup
     - \AM@deltax * \AM@xnupminusi) * \real{.5}%
  }%
  \def\AM@ymargin{%
    (\paperheight - (\@tempdimb+\tw@\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}}
       {}%
  \ifAM@signature
    \ifAM@landscape\AM@sigrotatefalse\else\AM@sigrotatetrue\fi
  \fi
  \setboolean{AM@endoflist}{false}%
  \whiledo{\not\boolean{AM@endoflist}}{%
    \AM@getfirst{\AM@pagelist}%
      \edef\AM@page{\the\toks@}%
      \AM@isphantom
      \@tempcnta=\AM@page\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}%
       \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}%
       \fi
      }%
    \setbox\@tempboxa=\hbox{%
      \expandafter\includegraphics\expandafter[\the\@temptokena,
                       page=\AM@page, scale=\AM@globalscale,
                       angle=\AM@lscape@rot]{\AM@docname}}%
    \edef\AM@localwd{\the\wd\@tempboxa}%
    \setlength{\@tempdima}{\the\ht\@tempboxa + \the\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
          \setbox\@tempboxa=\hbox{%
            \expandafter\includegraphics\expandafter
                [\the\@temptokena, page=\AM@page,
                 scale=\AM@globalscale,
                 angle=\AM@lscape@rot, angle=90]{\AM@docname}}%
          \let\@filelist\AM@filelist@save
          \edef\AM@localwd{\the\wd\@tempboxa}%
          \setlength{\@tempdima}{\the\ht\@tempboxa + \the\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}%
    \let\AM@filelist@save\@filelist
    \AM@split@options{Gin}{#1}%
    \setbox\@tempboxa=\hbox{%
      \expandafter\includegraphics\expandafter[\the\@temptokena,
                       page=\AM@page, scale=\AM@globalscale,
                       angle=\AM@lscape@rot]{\AM@docname}}%
    \let\@filelist\AM@filelist@save
    \setlength{\@tempdimc}{\ht\@tempboxa + \dp\@tempboxa}%
    \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@\fboxrule) *
         (\AM@ynupi - 1)
       }%
       \def\AM@ypos{%
         \AM@ymargin + \AM@yoffset + \AM@localyoff +
         (\AM@templateheight + \AM@deltay + \tw@\fboxrule) *
         (\AM@xnupi - 1)
       }%
      }
      {\def\AM@xpos{%
         \AM@xmargin \AM@add\AM@xoffset + \AM@localxoff +
         (\AM@templatewidth + \AM@deltax + \tw@\fboxrule) *
         (\AM@xnupi - 1)
       }%
       \def\AM@ypos{%
         \AM@ymargin + \AM@yoffset + \AM@localyoff +
         (\AM@templateheight + \AM@deltay + \tw@\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}%
    \setlength{\fboxsep}{\z@}%
     \AM@region@calc
    \ifAM@phantompage
      \def\AM@shippage{}%
    \else
      \AM@split@options{Gin}{#1}%
      \edef\AM@shippage{%
        \noexpand\put(\AM@xpos,\AM@ypos){%
        \noexpand\raisebox{\dp\@tempboxa}{%
        \noexpand\raise \ht\@tempboxa \hbox{\AM@hyper@begin@i}%
        \AM@hyper@begin@ii\noexpand\AM@fbox{%
          \noexpand\AM@ARBug@hook
          \noexpand\AM@reflectbox{%
          \noexpand\includegraphics[\the\@temptokena,
                    page=\AM@page, scale=\AM@globalscale,
                    scale=\AM@localscale,
                    \ifAM@sigrotate angle=180,\fi
                    \ifAM@doublepagestwist\ifAM@doublepagestmp
                      angle=180,\fi\fi
                    angle=\AM@rotateoversize,
                    angle=\AM@lscape@rot]{\AM@docname}}}%
        \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}%
    \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\AM@pagecommand\endgroup
        \hskip\z@
        \ifthenelse{\boolean{AM@turn}}
          {\ifthenelse{\boolean{AM@landscape}}
             {\AM@setlscape}{}}
          {}%
        \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
        \newpage
        \ifAM@reflectall \setbox\AM@pagebox\null \fi
        \ifAM@pdflscape\PLS@Rotate{0}\fi
        \AM@ClearShipoutPicture
        \ifAM@signature
          \ifAM@sigrotate\AM@sigrotatefalse\else\AM@sigrotatetrue\fi
        \fi
      \fi
    \fi
  }% whiledo
  \ifx\AM@twocolumn\relax\twocolumn\fi
}% AM@output
\newif\ifAM@defaultone
\newcommand*{\AM@readlist}[1]{%
  \AM@defaultonefalse
  \def\AM@pagelist{}%
  \def\AM@doclist{}%
  \AM@readlisti#1,\END,
  \ifAM@defaultone\AM@append{1}\fi
  \edef\AM@doclist{\expandafter\@gobble\AM@doclist\@empty}%
  \edef\AM@pagelist{\expandafter\@gobble\AM@pagelist\@empty}%
}
\newcommand{\AM@readlisti}{}
\def\AM@readlisti#1,{%
  \ifx\AM@currentdocname\relax
  \else
    \AM@getpagecount
  \fi
  \def\AM@temp{#1}%
  \ifx\END#1
  \else
    \AM@checkrange#1-\END
    \expandafter\AM@readlisti
  \fi
}
\newcommand{\AM@checkrange}{}
\def\AM@checkrange#1-#2\END{%
  \edef\AM@tempi{\AM@trim@space{#1}}%
  \ifx\\#2\\%
    \AM@checkinteger{\AM@tempi}%
    \ifAM@integer
      \AM@checkpagenumber{\AM@tempi}%
      \AM@append{\AM@tempi}%
    \else
      \expandafter\ifx\expandafter\\\AM@tempi\\\AM@append{}%
      \else\AM@setnewdocname{\AM@tempi}\fi
    \fi
  \else
    \expandafter\ifx\expandafter\\\AM@tempi\\%
      \@tempcnta=1\relax
      \AM@checklast#2\END
    \else
      \def\AM@cmp{last}%
      \ifx\AM@cmp\AM@tempi
        \@tempcnta=\AM@pagecount\relax
        \AM@checklast#2\END
      \else
        \AM@checkinteger{\AM@tempi}%
        \ifAM@integer
          \@tempcnta=\AM@tempi\relax
          \AM@checkpagenumber{\the\@tempcnta}%
          \AM@checklast#2\END
        \else
          \AM@setnewdocname{\AM@temp}%
        \fi
      \fi
    \fi
  \fi
}
\newcommand{\AM@checklast}{}
\def\AM@checklast#1-\END{%
  \edef\AM@tempii{\AM@trim@space{#1}}%
  \expandafter\ifx\expandafter\\\AM@tempii\\
    \@tempcntb=\AM@pagecount\relax
    \ifAM@DVIoutput
      \ifnum\AM@pagecount=1
        \@tempcntb\@tempcnta
      \fi
    \fi
    \advance\@tempcntb\@ne
    \whiledo{\@tempcnta<\@tempcntb}{%
      \AM@append{\the\@tempcnta}%
      \advance\@tempcnta\@ne
    }%
  \else
    \def\AM@cmp{last}%
    \ifx\AM@cmp\AM@tempii
      \let\AM@tempii\AM@pagecount
    \fi
    \AM@checkinteger{\AM@tempii}%
    \ifAM@integer
      \@tempcntb=\AM@tempii\relax
      \AM@checkpagenumber{\the\@tempcntb}%
      \ifnum\@tempcnta<\@tempcntb \def\AM@rel{<}\def\AM@inc{\@ne}%
      \else \def\AM@rel{>}\def\AM@inc{\m@ne}\fi
      \advance\@tempcntb\AM@inc
      \whiledo{\@tempcnta\AM@rel\@tempcntb}{%
        \AM@append{\the\@tempcnta}%
        \advance\@tempcnta\AM@inc
      }%
    \else
      \AM@setnewdocname{\AM@temp}%
    \fi
  \fi
}
\providecommand*{\AM@checkpagenumber}[1]{%
  \ifnum#1>\AM@pagecount\relax
    \ifthenelse{\boolean{AM@pkg@draft} \and \boolean{AM@survey}}{%
    }{%
      \PackageError{pdfpages}
        {page number #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@defaultone
    \AM@append{1}%
  \fi
  \edef\AM@temp{\AM@trim@space{#1}}%
  \AM@findfile{\AM@temp}%
  \AM@defaultonetrue
}
\newcommand*{\AM@append}[1]{%
  \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
  \AM@defaultonefalse
}
\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}
\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@scale
\newcommand{\AM@remove@scale}{}
\def\AM@remove@scale#1{%
  \def\AM@options{}%
  \AM@remove@scalei#1,\END,
}
\newcommand{\AM@remove@scalei}{}
\def\AM@remove@scalei#1,{%
  \ifx\END#1
  \else
    \AM@scalefalse
    \AM@remove@scaleii#1=\END
    \ifAM@scale
    \else
      \ifx\empty\AM@options
        \edef\AM@options{#1}%
      \else
        \toks@\expandafter{\AM@options,#1}%
        \edef\AM@options{\the\toks@}%
      \fi
    \fi
    \expandafter\AM@remove@scalei
  \fi
}
\newcommand{\AM@remove@scaleii}{}
\def\AM@remove@scaleii#1=#2\END{%
  \ifx\\#2\\%
  \else
    \def\AM@temp{#1}%
    \edef\AM@temp{\AM@trim@space{\AM@temp}}%
    \ifthenelse{\equal{scale}{\AM@temp}}{\AM@scaletrue}{}%
  \fi
}
\newif\ifAM@pdfpages@options
\newcommand{\AM@split@options}{}
\def\AM@split@options#1#2{%
  \def\AM@param{#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{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{signature}{\AM@temp}\or
              \equal{signature*}{\AM@temp}\or
              \equal{booklet}{\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}{}%
}
\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]{%
  \AM@@trim@leadingspace#1 \END{#1}%
}
\def\AM@@trim@leadingspace#1 #2\END#3{%
  \begingroup
    \def\x{#1}%
  \expandafter\endgroup
  \ifx\x\@empty
    \AM@remove@leadingspace#3\END
  \else
    #3%
  \fi
}
\@firstofone{\def\AM@remove@leadingspace} #1\END{#1}
\newif\ifAM@phantompage
\newcommand*{\AM@isphantom}{%
  \expandafter\ifx\expandafter\\\AM@page\\%
    \let\AM@page\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
          \AM@first\AM@last\AM@first\AM@last
        \else
          \AM@last\AM@first\AM@last\AM@first
        \fi
      \else
        \AM@first\AM@last\AM@first\AM@last
      \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
  \ifdim\AM@pagewidth<\AM@pageheight
    \def\AM@xnup{\@ne}\def\AM@ynup{\tw@}%
  \else
    \def\AM@xnup{\tw@}\def\AM@ynup{\@ne}%
  \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
  \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{\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{%
  \def\AM@toc@page{\AM@trim@space{#1}}%
  \def\AM@toc@section{\AM@trim@space{#2}}%
  \def\AM@toc@level{\AM@trim@space{#3}}%
  \AM@toc@title\expandafter{\ifdim\z@=0pt#4}\fi
  \def\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{}%
  \let\@fs@capt\relax% float.sty
  \expandafter\caption\expandafter{\AM@lof@heading}%
  \AM@addtolist@hook
  \@ifundefined{hyper@@anchor}{}{%
    \@ifundefined{float@caption}{%
      \hyper@@anchor{\@currentHref}{\relax}%
  }{}}%
  \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
}
\newcommand{\AM@parse@loflisti}{}
\def\AM@parse@loflisti#1,#2,#3,#4,#5\END{%
  \def\AM@lof@page{\AM@trim@space{#1}}%
  \def\AM@lof@list{\AM@trim@space{#2}}%
  \def\AM@lof@heading{\AM@trim@leadingspace{#3}}%
  \def\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}%
                             \def\AM@pagestemp{#1}}
\define@key{pdfpages}{nup}{\AM@parse@nup#1x\END}
\define@key{pdfpages}{deltax}{\AM@parse@deltax#1 \\}
\define@key{pdfpages}{deltay}{\AM@parse@deltay#1 \\}
\define@key{pdfpages}{delta}{\AM@parse@delta#1 \\}
\define@key{pdfpages}{offset}{\AM@parse@offset#1 \\}
\define@key{pdfpages}{frame}[true]{\setboolean{AM@frame}{#1}}
\define@key{pdfpages}{openright}[true]{\setboolean{AM@openright}{#1}}
\define@key{pdfpages}{pagecommand}{\def\AM@pagecommand{#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}{\def\AM@threadname{#1}}
\define@key{pdfpages}{link}[true]{\setboolean{AM@link}{#1}}
\define@key{pdfpages}{linkfit}{\AM@convert@dest{#1}}
\define@key{pdfpages}{linkname}{\def\AM@linkname@option{#1}}
\define@key{pdfpages}{linktodoc}[true]{\setboolean{AM@linktodoc}{#1}}
\define@key{pdfpages}{linktodocfit}{\def\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}{\def\AM@xrprefix{#1}}
\define@key{pdfpages}{fitpaper}[true]{\setboolean{AM@fitpaper}{#1}}
\define@key{pdfpages}{addtotoc}{\def\AM@toclist{#1,}}
\define@key{pdfpages}{addtolist}{\def\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}{signature}{\def\AM@signature{#1}}
\define@key{pdfpages}{signature*}{\def\AM@signature{#1}%
                                  \AM@signaturestartrue}
\define@key{pdfpages}{booklet}[true]{\setboolean{AM@booklet}{#1}%
                                     \def\AM@signature{x}}
\define@key{pdfpages}{pagetemplate}{\AM@CheckValue{pagetemplate}{#1}%
                                    \def\AM@pagetemplate{#1}}
\define@key{pdfpages}{templatesize}{\AM@parse@templatesize#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}{\def\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
}
\InputIfFileExists{pdfpages.fix}{%
  \PackageInfo{pdfpages}{Loading patch file `pdfpages.fix'}}{}
\endinput
%%
%% End of file `pdfpages.sty'.
