texlive[51051] Master: pgfmorepages (8may19)

commits+karl at tug.org commits+karl at tug.org
Wed May 8 23:17:11 CEST 2019


Revision: 51051
          http://tug.org/svn/texlive?view=revision&revision=51051
Author:   karl
Date:     2019-05-08 23:17:11 +0200 (Wed, 08 May 2019)
Log Message:
-----------
pgfmorepages (8may19)

Modified Paths:
--------------
    trunk/Master/tlpkg/bin/tlpkg-ctan-check
    trunk/Master/tlpkg/tlpsrc/collection-pictures.tlpsrc

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/pgfmorepages/
    trunk/Master/texmf-dist/doc/latex/pgfmorepages/README
    trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.pdf
    trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.tex
    trunk/Master/texmf-dist/tex/latex/pgfmorepages/
    trunk/Master/texmf-dist/tex/latex/pgfmorepages/pgfmorepages.sty
    trunk/Master/tlpkg/tlpsrc/pgfmorepages.tlpsrc

Added: trunk/Master/texmf-dist/doc/latex/pgfmorepages/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pgfmorepages/README	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/pgfmorepages/README	2019-05-08 21:17:11 UTC (rev 51051)
@@ -0,0 +1,14 @@
+----------------------------------------------------------------
+pgfmorepages --- LaTeX functions for manipulating multiple pages
+E-mail: loopspace at mathforge.org
+Released jointly under the LaTeX Project Public License v1.3c (or
+later) and under the GNU Public License.
+
+See http://www.latex-project.org/lppl.txt
+and https://www.gnu.org/licenses/gpl.html
+----------------------------------------------------------------
+
+This package replaces and extends the pgfpages sub-package of the PGF
+system.  It provides the capability to arrange multiple "logical"
+pages on multiple "physical" pages, for example as for arranging pages
+to make booklets.


Property changes on: trunk/Master/texmf-dist/doc/latex/pgfmorepages/README
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.pdf	2019-05-08 21:16:33 UTC (rev 51050)
+++ trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.pdf	2019-05-08 21:17:11 UTC (rev 51051)

Property changes on: trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.tex	2019-05-08 21:17:11 UTC (rev 51051)
@@ -0,0 +1,390 @@
+\documentclass{ltxdoc}
+
+\usepackage{tikz}
+\usetikzlibrary{positioning}
+\usepackage{pgfmorepages}
+\usepackage{fancyvrb}
+
+\GetFileInfo{pgfmorepages.sty}
+
+\title{PGF \emph{more} Pages}
+\author{Andrew Stacey \\ \texttt{loopspace at mathforge.org}}
+\date{\fileversion\ from \filedate}
+
+\begin{document}
+
+\maketitle
+
+\section{Introduction}
+
+The \Verb+pgfmorepages+ package is a drop-in replacement for the \Verb+pgfpages+ package which comes with TikZ/PGF.
+As it is a drop-in replacement, it \emph{ought} to be fully backwards compatible with \Verb+pgfpages+.
+
+\Verb+pgfpages+ allows you the ability to place several pages of your document (hereafter \emph{logical pages}) onto one page of the output (hereafter \emph{physical pages}).
+\Verb+pgfmorepages+ adds extra features, the primary one being that whereas \Verb+pgfpages+ is ``many to one'', \Verb+pgfmorepages+ is ``many to many''.
+That is, while \Verb+pgfpages+ works one physical page at a time then \Verb+pgfmorepages+ can juggle several logical pages onto several physical pages.
+
+As an example of its capability, the layout \Verb+4 on 2, book format+ places four logical pages onto two physical pages so that when folded it forms a booklet.
+The layout is therefore:
+
+\begin{center}
+\begin{tikzpicture}
+\node at (0,0) {\(4\)};
+\node at (1,0) {\(1\)};
+\node at (3,0) {\(2\)};
+\node at (4,0) {\(3\)};
+\draw (-.5,-.7) rectangle (.5,.7);
+\draw (1,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (3,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (4,0)  +(-.5,-.7) rectangle +(.5,.7);
+\end{tikzpicture}
+\end{center}
+
+This requires knowing all four logical pages before the first physical page is output.
+
+\section{Usage}
+
+In your preamble:
+
+\begin{verbatim}
+\usepackage{pgfmorepages}
+\end{verbatim}
+
+\subsection{Layouts}
+
+The original \Verb+pgfpages+ defined the following layouts:
+
+\begin{itemize}
+\item \Verb+rounded corners+
+\item \Verb+resize to+
+\item \Verb+two screens with lagging second+
+\item \Verb+two screens with optional second+
+\item \Verb+2 on 1+
+\item \Verb+4 on 1+
+\item \Verb+6 on 1+
+\item \Verb+8 on 1+
+\item \Verb+16 on 1+
+\end{itemize}
+
+The \Verb+pgfmorepages+ defines some extra layouts, which require the following command in your preamble:
+%
+\begin{verbatim}
+\pgfmorepagesloadextralayouts
+\end{verbatim}
+
+\begin{itemize}
+\item \Verb+4 on 2, odd then even+
+
+\begin{center}
+\begin{tikzpicture}
+\node at (0,0) {\(1\)};
+\node at (1,0) {\(3\)};
+\node at (3,0) {\(2\)};
+\node at (4,0) {\(4\)};
+\draw (-.5,-.7) rectangle (.5,.7);
+\draw (1,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (3,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (4,0)  +(-.5,-.7) rectangle +(.5,.7);
+\end{tikzpicture}
+\end{center}
+
+\item \Verb+4 on 2, even then odd+
+
+\begin{center}
+\begin{tikzpicture}
+\node at (0,0) {\(2\)};
+\node at (1,0) {\(4\)};
+\node at (3,0) {\(1\)};
+\node at (4,0) {\(3\)};
+\draw (-.5,-.7) rectangle (.5,.7);
+\draw (1,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (3,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (4,0)  +(-.5,-.7) rectangle +(.5,.7);
+\end{tikzpicture}
+\end{center}
+
+\item \Verb+4 on 2, book format+
+
+\begin{center}
+\begin{tikzpicture}
+\node at (0,0) {\(4\)};
+\node at (1,0) {\(1\)};
+\node at (3,0) {\(2\)};
+\node at (4,0) {\(3\)};
+\draw (-.5,-.7) rectangle (.5,.7);
+\draw (1,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (3,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (4,0)  +(-.5,-.7) rectangle +(.5,.7);
+\end{tikzpicture}
+\end{center}
+
+\item \Verb+8 on 4, book format+
+
+\begin{center}
+\begin{tikzpicture}
+\node at (0,0) {\(8\)};
+\node at (1,0) {\(1\)};
+\node at (3,0) {\(2\)};
+\node at (4,0) {\(7\)};
+\node at (6,0) {\(6\)};
+\node at (7,0) {\(3\)};
+\node at (9,0) {\(4\)};
+\node at (10,0) {\(5\)};
+\draw (-.5,-.7) rectangle (.5,.7);
+\draw (1,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (3,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (4,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (6,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (7,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (9,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (10,0)  +(-.5,-.7) rectangle +(.5,.7);
+\end{tikzpicture}
+\end{center}
+
+\item \Verb+8 on 4, book format, reverse second, single sided+
+
+\begin{center}
+\begin{tikzpicture}
+\node at (0,0) {\(8\)};
+\node at (1,0) {\(1\)};
+\node at (3,0) {\(6\)};
+\node at (4,0) {\(3\)};
+\node[rotate=180] at (6,0) {\(5\)};
+\node[rotate=180] at (7,0) {\(4\)};
+\node[rotate=180] at (9,0) {\(7\)};
+\node[rotate=180] at (10,0) {\(2\)};
+\draw (-.5,-.7) rectangle (.5,.7);
+\draw (1,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (3,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (4,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (6,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (7,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (9,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (10,0)  +(-.5,-.7) rectangle +(.5,.7);
+\end{tikzpicture}
+\end{center}
+
+
+\item \Verb+5 index cards+
+\item \Verb+repeated 2-up+
+
+\begin{center}
+\begin{tikzpicture}
+\node at (0,0) {\(1\)};
+\node at (1,0) {\(1\)};
+\node at (3,0) {\(2\)};
+\node at (4,0) {\(2\)};
+\draw (-.5,-.7) rectangle (.5,.7);
+\draw (1,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (3,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (4,0)  +(-.5,-.7) rectangle +(.5,.7);
+\end{tikzpicture}
+\end{center}
+
+\item \Verb+repeated 4-up+
+
+\begin{center}
+\begin{tikzpicture}
+\node at (0,0) {\(1\)};
+\node at (1,0) {\(1\)};
+\node at (0,1.4) {\(1\)};
+\node at (1,1.4) {\(1\)};
+\node at (3,0) {\(2\)};
+\node at (4,0) {\(2\)};
+\node at (3,1.4) {\(2\)};
+\node at (4,1.4) {\(2\)};
+\draw (-.5,-.7) rectangle (.5,.7);
+\draw (1,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (3,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (4,0)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (0,1.4)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (1,1.4)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (3,1.4)  +(-.5,-.7) rectangle +(.5,.7);
+\draw (4,1.4)  +(-.5,-.7) rectangle +(.5,.7);
+\end{tikzpicture}
+\end{center}
+
+
+\item \Verb+1 on 1+
+
+This is a layout that ``resets'' the mechanism back to one logical page on one physical page.
+It still uses the mechanics of the \Verb+pgfmorepages+ package so is not quite the same as removing it altogether, but is effectively the same.
+
+\item \Verb+discard+
+
+This layout discards all its pages.
+Useful to remove pages from a document without changing the source file too much.
+
+\end{itemize}
+
+To use a layout, use the command:
+%
+\begin{verbatim}
+\pgfpagesuselayout{<layout name>}[<optional arguments>]
+\end{verbatim}
+
+
+
+\subsection{Options}
+
+The optional arguments are a superset of the ones that \Verb+pgfpages+ allows.
+
+\begin{itemize}
+\item \Verb+physical paper width+
+\item \Verb+physical paper height+
+\item \Verb+a0paper+
+\item \Verb+a1paper+
+\item \Verb+a2paper+
+\item \Verb+a3paper+
+\item \Verb+a4paper+
+\item \Verb+a5paper+
+\item \Verb+a6paper+
+\item \Verb+letterpaper+
+\item \Verb+legalpaper+
+\item \Verb+executivepaper+
+\item \Verb+landscape+
+\item \Verb+border shrink+
+\item \Verb+border code+
+\item \Verb+corner width+
+\item \Verb+odd numbered pages right+
+\item \Verb+second right+
+\item \Verb+second left+
+\item \Verb+second top+
+\item \Verb+second bottom+
+\end{itemize}
+
+The only additional option is \Verb+border code+ which, if the layout does anything with it, is designed for passing a command to the layout for the border path.
+The intention of this is that sometimes it is useful to draw the page border when designing a document but you might want to disable it for the final version.
+This makes it easy to switch between those (providing the layout supports it).
+
+\subsection{Changing Layout}
+
+The documentation for \Verb+pgfpages+ states that it is possible to change layout mid-document.
+This turns out not to be correct for \Verb+pgfpages+ as it doesn't reset everything correctly.
+\Verb+pgfmorepages+ fixes this\footnote{Or tries to -- I keep discovering new options that I haven't reset properly.}.
+It is best practice to use a \Verb+\newpage+ or \Verb+\clearpage+ before doing so.
+The layout \Verb+1 on 1+ is useful here as it sets the layout back to one logical page on one physical page.
+
+\section{Defining a New Layout}
+
+The best way to define a new layout is to start with one of the predefined ones and modify it.
+To that end, here is an example layout with comments.
+
+\begin{verbatim}
+ % Set the name of the layout
+\pgfpagesdeclarelayout{4 on 2, book format}% 
+{%
+ % Unless overridden, this layout uses the same paper size
+ % but rotated so that two logical pages fit naturally on
+ % one physical page
+  \edef\pgfpageoptionheight{\the\paperwidth}
+  \edef\pgfpageoptionwidth{\the\paperheight}
+ % Defaults for the border
+  \def\pgfpageoptionborder{0pt}
+  \def\pgfpageoptionbordercode{}
+ % Start with the first page of the document
+  \def\pgfpageoptionfirstshipout{1}
+}%
+{%
+ % These are the settings for the physical pages
+  \pgfpagesphysicalpageoptions
+  {%
+ % Each set consists of 4 logical and 2 physical pages
+    logical pages=4,%
+    physical pages=2,%
+    physical height=\pgfpageoptionheight,%
+    physical width=\pgfpageoptionwidth,%
+    current logical shipout=\pgfpageoptionfirstshipout%
+  }
+ % These are the settings for the logical pages.
+ % These hold for all the logical pages.
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+ % Our arrangement is different for two portrait pages
+ % on one landscape as opposed to two landscape on
+ % one portrait.
+ % This is for two portrait on one landscape
+  \ifdim\paperheight>\paperwidth\relax
+    % put side-by-side
+ % There are several ways to declare which logical page
+ % goes on which physical page.  This command sets the
+ % physical page for the following logical pages.  The
+ % second argument is any options to be set for that
+ % physical page. 
+  \pgfpagesphysicalpage{1}{}
+ % Our fourth logical page goes on the first physical page
+    \pgfpageslogicalpageoptions{4}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+ % The second and third logical pages go on the second
+ % physical page.
+  \pgfpagesphysicalpage{2}{}
+    \pgfpageslogicalpageoptions{3}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+ % The first logical page goes back on the first physical page.
+  \pgfpagesphysicalpage{1}{}
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+  \else
+ % These are essentially the same as above, except with
+ % two landscape pages on one portrait, so the pages
+ % are in different locations.
+    % stack on top of one another
+  \pgfpagesphysicalpage{1}{}
+    \pgfpageslogicalpageoptions{4}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+  \pgfpagesphysicalpage{2}{}
+    \pgfpageslogicalpageoptions{3}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+  \pgfpagesphysicalpage{2}{}
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+  \fi    
+}
+\end{verbatim}
+
+\end{document}


Property changes on: trunk/Master/texmf-dist/doc/latex/pgfmorepages/pgfmorepages.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/tex/latex/pgfmorepages/pgfmorepages.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/pgfmorepages/pgfmorepages.sty	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/pgfmorepages/pgfmorepages.sty	2019-05-08 21:17:11 UTC (rev 51051)
@@ -0,0 +1,1513 @@
+% Original code copyright 2006 by Till Tantau
+% Extension copyright 2012-2019 by Andrew Stacey
+%
+% This file may be distributed and/or modified
+%
+% 1. under the LaTeX Project Public License and/or
+% 2. under the GNU Public License.
+%
+% See the file doc/generic/pgf/licenses/LICENSE for more details.
+
+\ProvidesPackage{pgfmorepages}[2019/03/22 v1.00 multiple page manipulation]
+
+\@ifpackageloaded{pgfpages}{%
+  \PackageWarning{pgfmorepages}{I notice that the package "pgfpages" has already been loaded.  This is an extension of that package and redefines various internal pieces so the two should not be used together.}
+}{}
+
+
+\RequirePackage{pgfcore,calc}
+
+\newcount\pgf at logicalpages
+\newcount\pgf at physicalpages
+\newcount\pgf at firstshipout
+\newcount\pgf at lastshipout
+\newcount\pgf at currentshipout
+\newcount\pgf at cpn
+\newcount\pgf at clpn
+\newcount\pgf at cppn
+\newcount\pgfactualpage
+\newcount\pgf at shipoutnextto
+\newdimen\pgfphysicalheight
+\newdimen\pgfphysicalwidth
+\newif\ifpgfpagesship
+
+\pgf at shipoutnextto=0\relax
+\pgf at logicalpages=0\relax
+\pgf at physicalpages=1\relax
+\pgf at firstshipout=1\relax
+\pgf at lastshipout=1\relax
+\pgf at currentshipout=1\relax
+\pgfphysicalheight=\paperheight
+\pgfphysicalwidth=\paperwidth
+\pgfactualpage=0
+\def\pgf at currentpage{1}
+
+\newif\ifpgfphysicalpageempty
+\newif\ifpgf at holdingphysicalpage
+
+\pgfphysicalpageemptytrue
+\pgf at holdingphysicalpagefalse
+
+% Define a layout
+%
+% #1 = layout name
+% #2 = code before options have been set
+% #2 = code after options have been set
+%
+% Example:
+%
+% \pgfpagesdeclarelayout{resize to}{
+%    \pgfpagesphysicalpageoptions{logical pages=1,physical height=\pgfpageoptionheight,physical width=\pgfpageoptionwidth}
+%    \pgfpageslogicalpageoptions{1}{resized width=\pgfphysicalwidth,%
+%      resized height=\pgfphysicalheight,center=\pgfpoint{.5\pgfphysicalwidth}{.5\pgfphysicalheight}}}
+
+\let\pgfpages at layouts=\pgfutil at gobble
+
+\newcommand\pgfpagesdeclarelayout[3]{%
+  \pgfutil at ifundefined{pgfpages at layout@#1}{%
+  \expandafter\def\expandafter\pgfpages at layouts\expandafter{\pgfpages at layouts, #1}
+  \expandafter\newcommand\csname pgfpages at layoutbefore@#1\endcsname{#2}
+    \expandafter\newcommand\csname pgfpages at layout@#1\endcsname{#3}
+  }{%
+    \PackageWarning{pgfmorepages}{Layout #1 already defined}%
+  }}
+
+
+% Use a layout
+%
+% #1 = layout name
+% #2 = options
+%
+% Example:
+%
+% \pgfpagesuselayout{resize to}[a4paper]
+
+\def\pgfpagesuselayout#1{\pgfutil at ifnextchar[{\pgf at pagelayout{#1}}{\pgf at pagelayout{#1}[]}}
+\def\pgf at pagelayout#1[#2]{
+  \pgfutil at ifundefined{pgfpages at layout@#1}{
+    \PackageError{pgfmorepages}{Page layout `#1' undefined.  Currently defined layouts are: \pgfpages at layouts \pgfmorepages at extramessage}{}
+  }
+  {
+    \pgfpages at reset
+    \csname pgfpages at layoutbefore@#1\endcsname
+    \setkeys{pgfpagesuselayoutoption}{#2}
+    \csname pgfpages at layout@#1\endcsname
+  }
+}
+
+\def\pgfpages at reset{
+\pgfshipoutphysicalpage
+\pgfphysicalheight=\paperheight
+\pgfphysicalwidth=\paperwidth
+  \pgf at cppn=1\relax%
+    \loop%
+    \expandafter\let\csname pgfpages at lp@\the\pgf at cppn @skipcode\endcsname\relax
+    \expandafter\let\csname pgfpages at lp@\the\pgf at cppn @height\endcsname\relax
+    \expandafter\let\csname pgfpages at lp@\the\pgf at cppn @width\endcsname\relax
+    \expandafter\let\csname pgfpages at lp@\the\pgf at cppn @copy\endcsname\relax
+    \expandafter\let\csname pgf at lpageson@\the\pgf at cppn\endcsname=\relax
+    \advance \pgf at cppn by 1\relax%  
+   \expandafter\unless\expandafter\ifx\csname pgf at lpageson@\the\pgf at cppn\endcsname\relax%
+  \repeat%
+  \pgf at clpn=1\relax%
+  \loop%
+    \expandafter\let\csname pgfpages at pp@\the\pgf at clpn @skipcode\endcsname\relax
+    \expandafter\let\csname pgfpages at box@\the\pgf at clpn\endcsname=\relax
+    \advance \pgf at clpn by 1\relax%  
+   \expandafter\unless\expandafter\ifx\csname pgfpages at box@\the\pgf at clpn\endcsname\relax%
+  \repeat%
+  \pgf at cppn=1\relax%
+  \pgf at clpn=1\relax%
+  \loop%
+    \loop%
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @reheight\endcsname\relax
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @rewidth\endcsname\relax
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @border\endcsname\relax
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @bordercode\endcsname\relax
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @center\endcsname\relax
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @cornerwidth\endcsname\relax
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @scale\endcsname\relax%
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @xscale\endcsname\relax%
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @yscale\endcsname\relax%
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @rotation\endcsname\relax%
+      \expandafter\let\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @skipcode\endcsname\relax%
+      \advance\pgf at clpn by 1\relax
+   \expandafter\unless\expandafter\ifx\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @reheight\endcsname\relax
+   \repeat
+   \pgf at clpn=1\relax%
+   \advance\pgf at cppn by 1\relax
+   \expandafter\unless\expandafter\ifx\csname pgfpages at p@\the\pgf at clpn @\the\pgf at cppn @reheight\endcsname\relax
+   \repeat
+}
+
+% Predefined options
+
+\define at key{pgfpagesuselayoutoption}{physical paper width}%
+{\def\pgfpageoptionwidth{#1}}
+
+\define at key{pgfpagesuselayoutoption}{physical paper height}%
+{\def\pgfpageoptionheight{#1}}
+
+\define at key{pgfpagesuselayoutoption}{a0paper}[]%
+{\def\pgfpageoptionheight{1189mm} \def\pgfpageoptionwidth{841mm}}
+
+\define at key{pgfpagesuselayoutoption}{a1paper}[]%
+{\def\pgfpageoptionheight{841mm} \def\pgfpageoptionwidth{594mm}}
+
+\define at key{pgfpagesuselayoutoption}{a2paper}[]%
+{\def\pgfpageoptionheight{594mm} \def\pgfpageoptionwidth{420mm}}
+
+\define at key{pgfpagesuselayoutoption}{a3paper}[]%
+{\def\pgfpageoptionheight{420mm} \def\pgfpageoptionwidth{297mm}}
+
+\define at key{pgfpagesuselayoutoption}{a4paper}[]%
+{\def\pgfpageoptionheight{297mm} \def\pgfpageoptionwidth{210mm}}
+
+\define at key{pgfpagesuselayoutoption}{a5paper}[]%
+{\def\pgfpageoptionheight{210mm} \def\pgfpageoptionwidth{148mm}}
+
+\define at key{pgfpagesuselayoutoption}{a6paper}[]%
+{\def\pgfpageoptionheight{148mm} \def\pgfpageoptionwidth{105mm}}
+
+\define at key{pgfpagesuselayoutoption}{letterpaper}[]%
+{\def\pgfpageoptionheight{11in}  \def\pgfpageoptionwidth{8.5in}}
+
+\define at key{pgfpagesuselayoutoption}{legalpaper}[]%
+{\def\pgfpageoptionheight{14in}  \def\pgfpageoptionwidth{8.5in}}
+
+\define at key{pgfpagesuselayoutoption}{executivepaper}[]%
+{\def\pgfpageoptionheight{10.5in}\def\pgfpageoptionwidth{7.25in}}
+
+\define at key{pgfpagesuselayoutoption}{landscape}[]%
+{
+  \let\pgf at temp=\pgfpageoptionwidth
+  \let\pgfpageoptionwidth=\pgfpageoptionheight
+  \let\pgfpageoptionheight=\pgf at temp
+}
+
+\define at key{pgfpagesuselayoutoption}{border shrink}%
+{\def\pgfpageoptionborder{#1}}
+
+\define at key{pgfpagesuselayoutoption}{border code}%
+{\def\pgfpageoptionbordercode{#1}}
+
+\define at key{pgfpagesuselayoutoption}{corner width}%
+{\def\pgfpageoptioncornerwidth{#1}}
+
+\define at key{pgfpagesuselayoutoption}{odd numbered pages right}[]%
+{\def\pgfpageoptionfirstshipout{2}}
+
+\define at key{pgfpagesuselayoutoption}{second right}[]%
+{%
+  \def\pgfpageoptionfirstcenter{\pgfpoint{.5\paperwidth}{.5\paperheight}}%
+  \def\pgfpageoptionsecondcenter{\pgfpoint{1.5\paperwidth}{.5\paperheight}}%
+  \def\pgfpageoptiontwoheight{\paperheight}%
+  \def\pgfpageoptiontwowidth{2\paperwidth}%
+}
+
+\define at key{pgfpagesuselayoutoption}{second left}[]%
+{%
+  \def\pgfpageoptionfirstcenter{\pgfpoint{1.5\paperwidth}{.5\paperheight}}%
+  \def\pgfpageoptionsecondcenter{\pgfpoint{.5\paperwidth}{.5\paperheight}}%
+  \def\pgfpageoptiontwoheight{\paperheight}%
+  \def\pgfpageoptiontwowidth{2\paperwidth}%
+}
+
+\define at key{pgfpagesuselayoutoption}{second top}[]%
+{%
+  \def\pgfpageoptionfirstcenter{\pgfpoint{.5\paperwidth}{.5\paperheight}}%
+  \def\pgfpageoptionsecondcenter{\pgfpoint{.5\paperwidth}{1.5\paperheight}}%
+  \def\pgfpageoptiontwoheight{2\paperheight}%
+  \def\pgfpageoptiontwowidth{\paperwidth}%
+}
+
+\define at key{pgfpagesuselayoutoption}{second bottom}[]%
+{%
+  \def\pgfpageoptionfirstcenter{\pgfpoint{.5\paperwidth}{1.5\paperheight}}%
+  \def\pgfpageoptionsecondcenter{\pgfpoint{.5\paperwidth}{.5\paperheight}}%
+  \def\pgfpageoptiontwoheight{2\paperheight}%
+  \def\pgfpageoptiontwowidth{\paperwidth}%
+}
+
+
+
+% Predefined layouts
+
+\pgfpagesdeclarelayout{rounded corners}
+{
+  \def\pgfpageoptioncornerwidth{10pt}
+}
+{
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=1
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \pgfpageslogicalpageoptions{1}
+  {%
+    center=\pgfpoint{.5\pgfphysicalwidth}{.5\pgfphysicalheight},%
+    corner width=\pgfpageoptioncornerwidth%
+  }%
+}
+
+\pgfpagesdeclarelayout{resize to}
+{
+  \def\pgfpageoptionborder{0pt}
+  \def\pgfpageoptionbordercode{}
+}
+{
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=1,%
+    physical height=\pgfpageoptionheight,%
+    physical width=\pgfpageoptionwidth%
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \pgfpageslogicalpageoptions{1}
+  {%
+    resized width=\pgfphysicalwidth,%
+    resized height=\pgfphysicalheight,%
+    border shrink=\pgfpageoptionborder,%
+    center=\pgfpoint{.5\pgfphysicalwidth}{.5\pgfphysicalheight}%
+  }%
+}
+
+\pgfpagesdeclarelayout{two screens with lagging second}
+{}
+{
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=2,%
+    physical height=\pgfpageoptiontwoheight,%
+    physical width=\pgfpageoptiontwowidth,%
+    last logical shipout=1,%
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \pgfpageslogicalpageoptions{1}
+  {%
+    center=\pgfpageoptionfirstcenter,%
+  }%
+  \pgfpageslogicalpageoptions{2}
+  {%
+    center=\pgfpageoptionsecondcenter,%
+    copy from=1%
+  }%
+}
+
+\pgfpagesdeclarelayout{two screens with optional second}
+{}
+{
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=2,%
+    physical height=\pgfpageoptiontwoheight,%
+    physical width=\pgfpageoptiontwowidth,%
+    last logical shipout=1%
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \pgfpageslogicalpageoptions{1}
+  {%
+    center=\pgfpageoptionfirstcenter,%
+  }%
+  \pgfpageslogicalpageoptions{2}
+  {%
+    center=\pgfpageoptionsecondcenter,%
+    copy from=2%
+  }%
+}
+
+\pgfpagesdeclarelayout{2 on 1}
+{
+  \edef\pgfpageoptionheight{\the\paperwidth} % landscaped by default
+  \edef\pgfpageoptionwidth{\the\paperheight}
+  \def\pgfpageoptionborder{0pt}
+  \def\pgfpageoptionbordercode{}
+  \def\pgfpageoptionfirstshipout{1}
+}
+{
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=2,%
+    physical height=\pgfpageoptionheight,%
+    physical width=\pgfpageoptionwidth,%
+    current logical shipout=\pgfpageoptionfirstshipout%
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \ifdim\paperheight>\paperwidth\relax
+    % put side-by-side
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+  \else
+    % stack on top of one another
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+  \fi    
+}
+
+
+\pgfpagesdeclarelayout{4 on 1}
+{
+  \edef\pgfpageoptionheight{\the\paperheight} 
+  \edef\pgfpageoptionwidth{\the\paperwidth}
+  \edef\pgfpageoptionborder{0pt}
+  \def\pgfpageoptionbordercode{}
+}
+{
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=4,%
+    physical height=\pgfpageoptionheight,%
+    physical width=\pgfpageoptionwidth%
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \pgfpageslogicalpageoptions{1}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.5\pgfphysicalwidth,%
+    resized height=.5\pgfphysicalheight,%
+    center=\pgfpoint{.25\pgfphysicalwidth}{.75\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{2}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.5\pgfphysicalwidth,%
+    resized height=.5\pgfphysicalheight,%
+    center=\pgfpoint{.75\pgfphysicalwidth}{.75\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{3}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.5\pgfphysicalwidth,%
+    resized height=.5\pgfphysicalheight,%
+    center=\pgfpoint{.25\pgfphysicalwidth}{.25\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{4}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.5\pgfphysicalwidth,%
+    resized height=.5\pgfphysicalheight,%
+    center=\pgfpoint{.75\pgfphysicalwidth}{.25\pgfphysicalheight}%
+  }%
+}
+
+\pgfpagesdeclarelayout{6 on 1}
+{
+  \edef\pgfpageoptionheight{\the\paperwidth} % landscaped by default
+  \edef\pgfpageoptionwidth{\the\paperheight}
+  \def\pgfpageoptionborder{0pt}
+  \def\pgfpageoptionbordercode{}
+}
+{
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=6,%
+    physical height=\pgfpageoptionheight,%
+    physical width=\pgfpageoptionwidth%
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \ifdim\paperheight>\paperwidth\relax
+    % put side-by-side
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.167\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{3}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.833\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{4}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.167\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{5}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{6}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.833\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+  \else
+    % stack on top of one another
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.833\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.833\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{3}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{4}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{5}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.167\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{6}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.167\pgfphysicalheight}%
+    }%
+  \fi    
+}
+
+
+\pgfpagesdeclarelayout{8 on 1}
+{
+  \edef\pgfpageoptionheight{\the\paperwidth} % landscaped by default
+  \edef\pgfpageoptionwidth{\the\paperheight}
+  \def\pgfpageoptionborder{0pt}
+  \def\pgfpageoptionbordercode{}
+}
+{
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=8,%
+    physical height=\pgfpageoptionheight,%
+    physical width=\pgfpageoptionwidth%
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \ifdim\paperheight>\paperwidth\relax
+    % put side-by-side
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.125\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.375\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{3}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.625\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{4}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.875\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{5}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.125\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{6}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.375\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{7}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.625\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{8}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.25\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.875\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+  \else
+    % stack on top of one another
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.875\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.875\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{3}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.625\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{4}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.625\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{5}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.375\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{6}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.375\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{7}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.125\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{8}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=.25\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.125\pgfphysicalheight}%
+    }%
+  \fi    
+}
+
+
+\pgfpagesdeclarelayout{16 on 1}
+{
+  \edef\pgfpageoptionheight{\the\paperheight} 
+  \edef\pgfpageoptionwidth{\the\paperwidth}
+  \edef\pgfpageoptionborder{0pt}
+  \def\pgfpageoptionbordercode{}
+}
+{
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=16,%
+    physical height=\pgfpageoptionheight,%
+    physical width=\pgfpageoptionwidth%
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \pgfpageslogicalpageoptions{1}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.125\pgfphysicalwidth}{.875\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{2}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.375\pgfphysicalwidth}{.875\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{3}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.625\pgfphysicalwidth}{.875\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{4}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.875\pgfphysicalwidth}{.875\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{5}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.125\pgfphysicalwidth}{.625\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{6}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.375\pgfphysicalwidth}{.625\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{7}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.625\pgfphysicalwidth}{.625\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{8}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.875\pgfphysicalwidth}{.625\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{9}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.125\pgfphysicalwidth}{.375\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{10}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.375\pgfphysicalwidth}{.375\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{11}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.625\pgfphysicalwidth}{.375\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{12}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.875\pgfphysicalwidth}{.375\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{13}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.125\pgfphysicalwidth}{.125\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{14}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.375\pgfphysicalwidth}{.125\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{15}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.625\pgfphysicalwidth}{.125\pgfphysicalheight}%
+  }%
+  \pgfpageslogicalpageoptions{16}
+  {%
+    border shrink=\pgfpageoptionborder,%
+    resized width=.25\pgfphysicalwidth,%
+    resized height=.25\pgfphysicalheight,%
+    center=\pgfpoint{.875\pgfphysicalwidth}{.125\pgfphysicalheight}%
+  }%
+}
+
+\pgfpagesdeclarelayout{4 on 2, odd then even}%
+{%
+  \edef\pgfpageoptionheight{\the\paperwidth} % landscaped by default
+  \edef\pgfpageoptionwidth{\the\paperheight}
+  \def\pgfpageoptionborder{0pt}
+  \def\pgfpageoptionbordercode{}
+  \def\pgfpageoptionfirstshipout{1}
+}%
+{%
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=4,%
+    physical pages=2,%
+    physical height=\pgfpageoptionheight,%
+    physical width=\pgfpageoptionwidth,%
+    current logical shipout=\pgfpageoptionfirstshipout%
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \ifdim\paperheight>\paperwidth\relax
+    % put side-by-side
+  \pgfpagesphysicalpage{1}{}
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{3}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+  \pgfpagesphysicalpage{2}{}
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{4}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+  \else
+    % stack on top of one another
+  \pgfpagesphysicalpage{1}{}
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{3}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+  \pgfpagesphysicalpage{2}{}
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{4}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+  \fi    
+}
+
+\pgfpagesdeclarelayout{4 on 2, even then odd}%
+{%
+   \edef\pgfpageoptionheight{\the\paperwidth} % landscaped by default
+  \edef\pgfpageoptionwidth{\the\paperheight}
+  \def\pgfpageoptionborder{0pt}
+  \def\pgfpageoptionbordercode{}
+  \def\pgfpageoptionfirstshipout{1}
+}%
+{%
+  \pgfpagesphysicalpageoptions
+  {%
+    logical pages=4,%
+    physical pages=2,%
+    physical height=\pgfpageoptionheight,%
+    physical width=\pgfpageoptionwidth,%
+    current logical shipout=\pgfpageoptionfirstshipout%
+  }
+  \pgfpagessetdefaults{%
+    border code=\pgfpageoptionbordercode
+  }
+  \ifdim\paperheight>\paperwidth\relax
+    % put side-by-side
+  \pgfpagesphysicalpage{2}{}
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{3}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+  \pgfpagesphysicalpage{1}{}
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.25\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{4}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=.5\pgfphysicalwidth,%
+      resized height=\pgfphysicalheight,%
+      center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}%
+    }%
+  \else
+    % stack on top of one another
+  \pgfpagesphysicalpage{2}{}
+    \pgfpageslogicalpageoptions{1}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{3}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+  \pgfpagesphysicalpage{1}{}
+    \pgfpageslogicalpageoptions{2}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
+    }%
+    \pgfpageslogicalpageoptions{4}
+    {%
+      border shrink=\pgfpageoptionborder,%
+      resized width=\pgfphysicalwidth,%
+      resized height=.5\pgfphysicalheight,%
+      center=\pgfpoint{.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
+    }%
+  \fi    
+}
+
+% Load more layouts
+
+\def\pgfmorepages at extramessage{.  Extra layouts can be loaded with the command \string\pgfmorepagesloadextralayouts}
+\newcommand\pgfmorepagesloadextralayouts{%
+  \input{pgfmorepageslayouts.code.tex}%
+  \def\pgfmorepages at extramessage{}%
+}
+
+% Change/set main option
+%
+% #1 = options
+%
+% Options:
+%
+% logical pages     = number of logical pages per physical page
+% logical shipouts  = number of shipouts needed to fill a physical page
+%                     (may be less than the number of logical pages,
+%                     if some logical pages are calculated
+%                     automatically) 
+% current logical shipout = number of logical shipout that will come
+%                           next. 
+%
+% Example:
+%
+% \pgfpagesphysicalpageoptions{logical pages=2,logical shipouts=1}
+
+\newcommand\pgfpagesphysicalpageoptions[1]{%
+  \pgf at lastshipout=0\relax%
+  \pgf at currentshipout=0\relax%
+  \setkeys{pgfpages at main}{#1}%
+  \ifnum\pgf at lastshipout=0\relax%not set
+    \pgf at lastshipout=\pgf at logicalpages%
+  \fi%  
+  \ifnum\pgf at currentshipout=0\relax%not set
+    \pgf at currentshipout=\pgf at firstshipout%
+  \fi%  
+}
+
+\define at key{pgfpages at main}{logical pages}{\pgf at logicalpages=#1\relax}
+\define at key{pgfpages at main}{physical pages}{\pgf at physicalpages=#1\relax}
+\define at key{pgfpages at main}{first logical shipout}{\pgf at firstshipout=#1\relax}
+\define at key{pgfpages at main}{last logical shipout}{\pgf at lastshipout=#1\relax}
+\define at key{pgfpages at main}{current logical shipout}{\pgf at currentshipout=#1\relax}
+\define at key{pgfpages at main}{physical height}{\pgfphysicalheight=#1\relax}
+\define at key{pgfpages at main}{physical width}{\pgfphysicalwidth=#1\relax}
+
+
+
+% Setup/change parameters of a logical page. You must call this
+% macro for each logical page.
+%
+% #1 = logical page number
+% #2 = options
+%
+% Options:
+%
+% original height = height of the logical page (\paperheight at point of
+%                   first invocation by default) 
+% original width  = width of the logical page (\paperwidth by default)
+% resized height  = height of the logical page after resizing
+% resized width   = width of the logical page after resizing
+% border shrink   = length that is subtracted from resized height and
+%                   resized width
+% border code     = pgf commands to be used for drawing a border (a
+%                   path with the border set will already have been
+%                   set) 
+% rounded corners = clip the frame against a rectangle of the size of
+%                   the frame with corners of the given radius
+% scale           = factor by which the page is enlarged/shrunk 
+% center          = center of the logical page in the physical page
+% rotation        = degree by which the page is rotated around its center
+% xscale          = scale only x-axis (use -1 to flip along y-axis)
+% yscale          = scale only y-axis (use -1 to flip along x-axis)
+% copy from       = copy the contents from this logical page of the
+%                   previous physical page, if no contents is specified 
+%
+% If more than one of the three options ``resized height'', ``resized
+% width'' and ``scale'' are given, the smallest resulting scaling
+% wins. 
+%
+% Example:
+%
+% \pgfpageslogicalpageoptions{1}{scale=0.5,center=\pgfpoint{0cm}{2cm}}
+% \pgfpageslogicalpageoptions{1 on 2}{scale=0.5,center=\pgfpoint{0cm}{2cm}}
+
+\newcommand\pgfpageslogicalpageoptions[2]{%
+% First step is to work out which physical page and which logical page we're dealing with.
+% This could be set via the first argument if it is of the form ``x on y'': this means ``logical page x on physical page y''.
+% Or we could set the physical page beforehand via the \pgfpagesphysicalpage macro.
+  \pgfutil at in@{on}{#1}%
+  \ifpgfutil at in@
+  \pgf at mp@seplp#1\relax
+  \else
+  \pgf at clpn=#1\relax%
+  \pgf at cppn=\pgf at currentpage\relax%
+  \fi
+% Make sure we have the box for this logical page.
+  \expandafter\ifx\csname pgfpages at box@\the\pgf at clpn\endcsname\relax%
+    \expandafter\newbox\csname pgfpages at box@\the\pgf at clpn\endcsname%
+\pgf at elpsetcurrent{height}{\the\paperheight}%
+\pgf at elpsetcurrent{width}{\the\paperwidth}%
+\fi
+% Now set the count \pgf at cpn so that it is the number of logical pages on this particular physical page.
+      \expandafter\ifx\csname pgf at lpageson@\the\pgf at cppn\endcsname\relax
+\expandafter\def\csname pgf at lpageson@\the\pgf at cppn\endcsname{1}%
+\else
+\expandafter\edef\csname pgf at lpageson@\the\pgf at cppn\endcsname{\number\numexpr\csname pgf at lpageson@\the\pgf at cppn\endcsname + 1\relax}%
+\fi
+      \pgf at cpn=\numexpr\csname pgf at lpageson@\the\pgf at cppn\endcsname\relax
+\pgf at epsetcurrent{logicalpage}{\the\pgf at clpn}%
+\pgfpages at processdefaults
+  \setkeys{pgfpages at page}{#2}%
+  \pgf at calculateresizes{height}%
+  \pgf at calculateresizes{width}%
+  \pgfsetupphysicalpagesizes%
+}
+
+\def\pgf at mp@seplp#1on#2\relax{%
+  \pgf at cpn=#1\relax
+  \pgf at cppn=#2\relax
+}
+
+% Set the current default physical page for the logical page options
+\newcommand\pgfpagesphysicalpage[2]{%
+      \edef\pgf at currentpage{#1}%
+      \pgf at cppn=#1\relax
+      \setkeys{pgfpages at ppage}{#2}%
+}
+
+% Set some defaults
+\newcommand\pgfpagessetdefaults[1]{%
+      \def\pgf at defaults{#1}}
+\def\pgf at defaults{}
+
+\def\pgfpages at processdefaults{%
+      \def\pgf at temp{\setkeys{pgfpages at page}}%
+      \expandafter\pgf at temp\expandafter{\pgf at defaults}%
+}
+
+% Set and get options for a particular logical page on a particular physical page.
+\def\pgf at epset#1#2#3#4{\expandafter\edef\csname pgfpages at p@#1@#2@#3\endcsname{#4}}
+\def\pgf at pset#1#2#3#4{\expandafter\def\csname pgfpages at p@#1@#2@#3\endcsname{#4}}
+\def\pgf at pget#1#2#3{\csname pgfpages at p@#1@#2@#3\endcsname}
+\def\pgf at epsetcurrent#1#2{\pgf at epset{\the\pgf at cpn}{\the\pgf at cppn}{#1}{#2}}
+\def\pgf at psetcurrent#1#2{\pgf at pset{\the\pgf at cpn}{\the\pgf at cppn}{#1}{#2}}
+\def\pgf at pgetcurrent#1{\pgf at pget{\the\pgf at cpn}{\the\pgf at cppn}{#1}}
+
+% Set and get options for a particular logical page.
+\def\pgf at elpset#1#2#3{\expandafter\edef\csname pgfpages at lp@#1@#2\endcsname{#3}}
+\def\pgf at lpset#1#2#3{\expandafter\def\csname pgfpages at lp@#1@#2\endcsname{#3}}
+\def\pgf at lpget#1#2{\csname pgfpages at lp@#1@#2\endcsname}
+\def\pgf at elpsetcurrent#1#2{\pgf at elpset{\the\pgf at clpn}{#1}{#2}}
+\def\pgf at lpsetcurrent#1#2{\pgf at lpset{\the\pgf at clpn}{#1}{#2}}
+\def\pgf at lpgetcurrent#1{\pgf at lpget{\the\pgf at clpn}{#1}}
+
+% Set and get options for a particular physical page.
+\def\pgf at eppset#1#2#3{\expandafter\edef\csname pgfpages at pp@#1@#2\endcsname{#3}}
+\def\pgf at ppset#1#2#3{\expandafter\def\csname pgfpages at pp@#1@#2\endcsname{#3}}
+\def\pgf at ppget#1#2{\csname pgfpages at pp@#1@#2\endcsname}
+\def\pgf at eppsetcurrent#1#2{\pgf at eppset{\the\pgf at cppn}{#1}{#2}}
+\def\pgf at ppsetcurrent#1#2{\pgf at ppset{\the\pgf at cppn}{#1}{#2}}
+\def\pgf at ppgetcurrent#1{\pgf at ppget{\the\pgf at cppn}{#1}}
+
+\define at key{pgfpages at page}{skip code}{\pgf at psetcurrent{skipcode}{#1}}
+\define at key{pgfpages at page}{scale}{\pgf at epsetcurrent{scale}{#1}}
+\define at key{pgfpages at page}{xscale}{\pgf at epsetcurrent{xscale}{#1}}
+\define at key{pgfpages at page}{yscale}{\pgf at epsetcurrent{yscale}{#1}}
+\define at key{pgfpages at page}{original height}{\pgf at elpsetcurrent{height}{#1}}
+\define at key{pgfpages at page}{original width}{\pgf at elpsetcurrent{width}{#1}}
+\define at key{pgfpages at page}{resized height}{\pgf at epsetcurrent{reheight}{#1}}
+\define at key{pgfpages at page}{resized width}{\pgf at epsetcurrent{rewidth}{#1}}
+\define at key{pgfpages at page}{center}{\pgf at psetcurrent{center}{#1}}
+\define at key{pgfpages at page}{rotation}{\pgf at epsetcurrent{rotation}{#1}}
+\define at key{pgfpages at page}{copy from}{\pgf at elpsetcurrent{copy}{#1}}
+\define at key{pgfpages at page}{border shrink}{\pgf at epsetcurrent{border}{#1}}
+\define at key{pgfpages at page}{border code}{\pgf at psetcurrent{bordercode}{#1}}
+\define at key{pgfpages at page}{corner width}{\pgf at psetcurrent{cornerwidth}{#1}}
+
+\define at key{pgfpages at ppage}{skip code}{\pgf at ppsetcurrent{skipcode}{#1}}
+\define at key{pgfpages at ppage}{defaults}{\pgfpagessetdefaults{#1}}
+
+\def\pgf at calculateresizes#1{%
+  \expandafter\ifx\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @re#1\endcsname\relax%
+  \else%
+    \expandafter\pgfutil at tempdima\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @re#1\endcsname\relax%
+    \expandafter\ifx\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @border\endcsname\relax%
+    \else%
+      \expandafter\pgfutil at tempdimb\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @border\endcsname\relax%
+      \advance\pgfutil at tempdima by-2\pgfutil at tempdimb\relax%
+    \fi%
+    \expandafter\pgfutil at tempdimb\csname pgfpages at lp@\the\pgf at clpn @#1\endcsname\relax%
+    \pgfutil at tempcnta=\pgfutil at tempdimb%
+    \divide\pgfutil at tempcnta by 65536\relax%
+    \ifnum\pgfutil at tempcnta=0\relax%
+      \pgfutil at tempcnta=1\relax%
+    \fi%
+    \divide\pgfutil at tempdima by\pgfutil at tempcnta\relax%
+    \expandafter\ifx\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @scale\endcsname\relax%
+      \pgfutil at tempdimb=10000pt%
+    \else%
+      \expandafter\pgfutil at tempdimb\expandafter=\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @scale\endcsname pt\relax%
+    \fi%
+    \ifdim\pgfutil at tempdima<\pgfutil at tempdimb%
+      \edef\pgf at temp{{scale}{\expandafter\Pgf at geT\the\pgfutil at tempdima}}%
+      \expandafter\pgf at psetcurrent\pgf at temp%
+    \fi%
+  \fi%
+}
+
+
+
+% Shipout a physical page immediately
+%
+% Example:
+%
+% \pgfshipoutphysicalpage
+
+
+\newcommand\pgfshipoutphysicalpage{%
+  \ifnum\pgf at logicalpages>0\relax%
+  \pgf at cppn=1\relax%
+  \loop%
+  \global\advance\pgfactualpage by 1\relax
+      \pgfpagesshiptrue
+  \csname pgfpages at pp@\the\pgf at cppn @skipcode\endcsname
+      \ifpgfpagesship
+    \pgfpages at buildshipoutbox%
+    \pgfpages at shipoutshipoutbox%
+      \fi
+  \ifnum\pgf at cppn<\pgf at physicalpages%
+  \advance \pgf at cppn by 1\relax
+  \repeat%
+    \pgfpages at performcopying%
+    \global\pgfphysicalpageemptytrue%
+    \global\pgf at holdingphysicalpagefalse%  
+  \fi%
+}
+
+\newbox\pgfpages at shipoutbox
+
+\def\pgfpages at buildshipoutbox{%
+  \setbox\pgfpages at shipoutbox=\vbox{{%
+    \set at typeset@protect%
+    \offinterlineskip%
+    \pgfsys at beginpicture%
+    \pgf at cpn=1\relax%
+    \loop%
+      \pgfpagesshiptrue
+          \csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @skipcode\endcsname
+\ifpgfpagesship
+\pgf at clpn=\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @logicalpage\endcsname\relax%
+      \setbox0=\hbox to \csname pgfpages at lp@\the\pgf at clpn @width\endcsname{%
+        \hskip1in%
+        \vbox to \csname pgfpages at lp@\the\pgf at clpn @height\endcsname%
+          {\vskip1in\offinterlineskip \expandafter\copy\csname
+            pgfpages at box@\the\pgf at clpn\endcsname\vss}\hss}%
+      \pgfsys at beginscope%
+        % Translate lower left corner
+        \expandafter\ifx\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @center\endcsname\relax%
+        \else%
+          \pgflowlevel{\pgftransformshift{\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @center\endcsname}}%
+        \fi%
+        \expandafter\ifx\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @scale\endcsname\relax%
+        \else%
+          \pgflowlevel{\pgftransformscale{\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @scale\endcsname}}%
+        \fi%
+        \expandafter\ifx\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @xscale\endcsname\relax%
+        \else%
+          \pgflowlevel{\pgftransformxscale{\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @xscale\endcsname}}%
+        \fi%
+        \expandafter\ifx\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @yscale\endcsname\relax%
+        \else%
+          \pgflowlevel{\pgftransformyscale{\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @yscale\endcsname}}%
+        \fi%
+        \expandafter\ifx\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @rotation\endcsname\relax%
+%          \pgfscope%
+        \else%
+          \pgflowlevel{\pgftransformrotate{\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @rotation\endcsname}}%
+        \fi%
+        \pgfutil at tempdima=\csname pgfpages at lp@\the\pgf at clpn @width\endcsname\relax%
+        \pgfutil at tempdimb=\csname pgfpages at lp@\the\pgf at clpn @height\endcsname\relax%
+        \pgflowlevel{\pgftransformshift{\pgfpoint{-.5\pgfutil at tempdima}{-.5\pgfutil at tempdimb}}}%
+        \expandafter\ifx\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @bordercode\endcsname\relax%
+        \else%
+          \pgfpathmoveto{\pgfpointorigin}%
+          \pgfpathlineto{\pgfpoint{\wd0}{0pt}}%
+          \pgfpathlineto{\pgfpoint{\wd0}{\ht0}}%
+          \pgfpathlineto{\pgfpoint{0pt}{\ht0}}%
+          \pgfpathclose%
+          {\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @bordercode\endcsname}%
+        \fi%
+        \expandafter\ifx\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @cornerwidth\endcsname\relax%
+        \else%
+          {
+            \expandafter\pgfutil at tempdima\csname pgfpages at p@\the\pgf at cpn @\the\pgf at cppn @cornerwidth\endcsname\relax%
+            \color{black}
+            \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\pgfutil at tempdima}{\pgfutil at tempdima}}%
+            \pgfpathrectangle{\pgfpoint{0pt}{\ht0-\pgfutil at tempdima}}{\pgfpoint{\pgfutil at tempdima}{\pgfutil at tempdima}}%
+            \pgfpathrectangle{\pgfpoint{\wd0-\pgfutil at tempdima}{0pt}}{\pgfpoint{\pgfutil at tempdima}{\pgfutil at tempdima}}%
+            \pgfpathrectangle{\pgfpoint{\wd0-\pgfutil at tempdima}{\ht0-\pgfutil at tempdima}}{\pgfpoint{\pgfutil at tempdima}{\pgfutil at tempdima}}%
+            \pgfusepath{fill}%
+            \pgfpathmoveto{\pgfpoint{0pt}{\pgfutil at tempdima}}%
+            \pgfpathcurveto{\pgfpoint{0pt}{0.555\pgfutil at tempdima}}{\pgfpoint{.555\pgfutil at tempdima}{0pt}}{\pgfpoint{\pgfutil at tempdima}{0pt}}%
+            \pgfpathlineto{\pgfpoint{\wd0-\pgfutil at tempdima}{0pt}}%
+            \pgfpathcurveto{\pgfpoint{\wd0-.555\pgfutil at tempdima}{0pt}}{\pgfpoint{\wd0}{.555\pgfutil at tempdima}}{\pgfpoint{\wd0}{\pgfutil at tempdima}}%
+            \pgfpathlineto{\pgfpoint{\wd0}{\ht0-\pgfutil at tempdima}}%
+            \pgfpathcurveto{\pgfpoint{\wd0}{\ht0-.555\pgfutil at tempdima}}{\pgfpoint{\wd0-.555\pgfutil at tempdima}{\ht0}}{\pgfpoint{\wd0-\pgfutil at tempdima}{\ht0}}%
+            \pgfpathlineto{\pgfpoint{\pgfutil at tempdima}{\ht0}}%
+            \pgfpathcurveto{\pgfpoint{.555\pgfutil at tempdima}{\ht0}}{\pgfpoint{0pt}{\ht0-.555\pgfutil at tempdima}}{\pgfpoint{0pt}{\ht0-\pgfutil at tempdima}}%
+            \pgfpathclose
+            \pgfusepath{clip}%
+            \color{white}%
+            \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\wd0}{\ht0}}%
+            \pgfusepath{fill}%
+          }%
+        \fi%
+        \ht0=0pt%
+        \wd0=0pt%
+        \dp0=0pt%
+          \pgfsys at hbox0%
+%        \endpgfscope%
+      \pgfsys at endscope%
+    \fi
+    \ifnum\pgf at cpn<\csname pgf at lpageson@\the\pgf at cppn\endcsname\relax%
+      \advance \pgf at cpn by 1\relax%  
+    \repeat%
+    \pgfsys at endpicture%
+    }}%
+}
+
+
+\def\pgfpages at shipoutshipoutbox{%
+  \begingroup
+    \let \protect \noexpand
+    \@resetactivechars
+    \global\let\@@if at newlist\if at newlist
+    \global\@newlistfalse
+    \@parboxrestore%
+    \pgfpages at originalshipout%
+    \vbox{\hbox{%
+      \hskip-1in%
+      \vbox to \pgfphysicalheight{%
+        \vss\box\pgfpages at shipoutbox%
+        \vskip1in%
+      }}}%
+  \endgroup%
+}
+
+\def\pgfpages at performcopying{
+  \pgf at clpn=1\relax% copy first
+  \loop%
+    \expandafter\ifx\csname pgfpages at lp@\the\pgf at clpn @copy\endcsname\relax
+    \else%
+      \edef\pgf at temp{\noexpand\global\noexpand\setbox\csname pgfpages at box@%
+        \the\pgf at clpn\endcsname=\noexpand\copy\csname pgfpages at box@\csname
+        pgfpages at lp@\the\pgf at clpn @copy\endcsname\endcsname}%
+      \pgf at temp%
+    \fi%
+  \ifnum\pgf at clpn<\pgf at logicalpages%
+    \advance \pgf at clpn by 1\relax%  
+  \repeat%
+  \pgf at clpn=1\relax% then void
+  \loop%
+    \expandafter\ifx\csname pgfpages at lp@\the\pgf at clpn @copy\endcsname\relax
+      \expandafter\global\expandafter\setbox\csname pgfpages at box@\the\pgf at clpn\endcsname=\box\voidb at x%
+    \else%
+    \fi%
+  \ifnum\pgf at clpn<\pgf at logicalpages%
+    \advance \pgf at clpn by 1\relax%  
+  \repeat%
+}
+
+
+
+% Save original shipout commands
+%
+% Example:
+%
+% \pgfhookintoshipout
+
+\newcommand\pgfhookintoshipout{
+  \let\pgfpages at originalshipout=\shipout
+  \let\shipout=\pgfpages at interceptshipout
+}
+
+\def\pgfpages at interceptshipout{%
+  \ifnum\pgf at shipoutnextto>0\relax
+    \def\pgf at next{%
+      \expandafter\global\expandafter\setbox\csname pgfpages at box@\the\pgf at shipoutnextto\endcsname=\box\voidb at x%
+      \afterassignment\pgfpages at shipouttestnext%
+      \pgfpagesshipoutlogicalpage{\the\pgf at shipoutnextto}%
+    }%
+  \else%
+    \ifpgf at holdingphysicalpage% shipout physical page now
+      {\pgfshipoutphysicalpage}%
+    \fi%    
+    \ifnum\pgf at logicalpages=0\relax
+      \def\pgf at next{\pgfpages at originalshipout}%
+    \else%
+      \def\pgf at next{%
+        \expandafter\global\expandafter\setbox\csname pgfpages at box@\the\pgf at currentshipout\endcsname=\box\voidb at x%
+        \afterassignment\pgfpages at shipouttest%
+        \pgfpagesshipoutlogicalpage{\the\pgf at currentshipout}%
+      }%
+    \fi%
+  \fi%
+  \pgf at next%  
+}
+
+\def\pgfpages at shipouttest{%
+  \ifvoid\csname pgfpages at box@\the\pgf at currentshipout\endcsname\relax%
+    \aftergroup\pgfpages at preparenextshipout%
+  \else%
+    \pgfpages at preparenextshipout%
+  \fi%
+}
+
+\def\pgfpages at shipouttestnext{%
+  \ifvoid\csname pgfpages at box@\the\pgf at shipoutnextto\endcsname\relax%
+    \aftergroup\pgfpages at preparenextshipout%
+  \else%
+    \pgfpages at preparenextshipout%
+  \fi%
+}
+ 
+\def\pgfpages at preparenextshipout{%
+  \ifnum\pgf at shipoutnextto=0\relax%
+    \global\advance\pgf at currentshipout by 1\relax%
+  \else%
+    \global\pgf at shipoutnextto=0\relax%
+  \fi%
+  \ifnum\pgf at currentshipout>\pgf at lastshipout\relax%
+    \global\pgf at currentshipout=\pgf at firstshipout\relax%
+    \global\pgf at holdingphysicalpagetrue%
+  \fi%
+}
+
+
+
+% Shipout a logical page
+%
+% #1 = logical page number
+%
+% The command should be followed by a box. This box will become the
+% contents of the logical page.
+%
+% Example:
+%
+% \pgfpagesshipoutlogicalpage{0}\vbox{Hi!}
+
+\newcommand\pgfpagesshipoutlogicalpage[1]{%
+  \global\pgfphysicalpageemptyfalse%
+  \expandafter\global\expandafter\setbox\csname pgfpages at box@#1\endcsname=}
+
+
+
+% Finish current page and shipout next page to a specific logical page.
+%
+% #1 = logical page number
+%
+% When the current page has been typset, it will be become the given
+% logical page. This command ``interrupts'' the normal order of
+% logical pages.
+%
+% Example:
+%
+% \pgfpagesuselayout{two screens with optional second}
+%
+% Text for main page.\clearpage
+%
+% \pgfpagescurrentpagewillbelogicalpage{2}
+%
+% Text that goes to second page
+%
+% \clearpage
+%
+% Text for main page.
+
+\newcommand\pgfpagescurrentpagewillbelogicalpage[1]{%
+  \global\pgf at shipoutnextto=#1\relax%
+}
+
+
+% Setup the physical page sizes
+%
+% Example:
+%
+% \pgfsetupphysicalpagesizes
+
+\newcommand\pgfsetupphysicalpagesizes{%
+  % The following code was send to me by Rolf Niepraschk
+    \ifx\Gin at driver\pgfutil at empty\else%
+      \filename at parse{\Gin at driver}\@tempswafalse%
+      \def\reserved at a{dvips}%
+      \ifx\filename at base\reserved at a\@tempswatrue\fi%
+      \def\reserved at a{dvipdfm}%
+      \ifx\filename at base\reserved at a\@tempswatrue\fi%
+      \if at tempswa%
+        \AtBeginDvi{%
+          \special{papersize=\the\pgfphysicalwidth,\the\pgfphysicalheight}}%
+      \fi%
+      \def\reserved at a{pdftex}%
+      \ifx\filename at base\reserved at a
+        \pdfpagewidth\pgfphysicalwidth\pdfpageheight\pgfphysicalheight%
+      \fi%
+      \def\reserved at a{vtex}%
+      \ifx\filename at base\reserved at a
+        \mediawidth\pgfphysicalwidth\mediaheight\pgfphysicalheight%
+      \fi%
+      \def\reserved at a{luatex}%
+      \ifx\filename at base\reserved at a
+        \pagewidth\pgfphysicalwidth\pageheight\pgfphysicalheight%
+      \fi%
+    \fi
+}
+
+
+%
+% Start/End setup
+%
+\AtBeginDocument
+{
+  \pgfhookintoshipout
+  \pgfsetupphysicalpagesizes
+}
+\AtEndDocument
+{
+  \clearpage
+  \ifpgfphysicalpageempty
+  \else
+    \pgfshipoutphysicalpage
+  \fi
+}
+


Property changes on: trunk/Master/texmf-dist/tex/latex/pgfmorepages/pgfmorepages.sty
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/tlpkg/bin/tlpkg-ctan-check
===================================================================
--- trunk/Master/tlpkg/bin/tlpkg-ctan-check	2019-05-08 21:16:33 UTC (rev 51050)
+++ trunk/Master/tlpkg/bin/tlpkg-ctan-check	2019-05-08 21:17:11 UTC (rev 51051)
@@ -521,7 +521,7 @@
     permute persian-bib
     petiteannonce petri-nets pfarrei
     pgf pgf-blur pgf-cmykshadings pgf-soroban pgf-spectra pgf-umlcd pgf-umlsd
-    pgfgantt pgfkeyx pgfmolbio
+    pgfgantt pgfkeyx pgfmolbio pgfmorepages
     pgfopts pgfornament pgfornament-han pgfplots
     phaistos phffullpagefigure phfnote phfparen phfqit phfquotetext
     phfsvnwatermark phfthm

Modified: trunk/Master/tlpkg/tlpsrc/collection-pictures.tlpsrc
===================================================================
--- trunk/Master/tlpkg/tlpsrc/collection-pictures.tlpsrc	2019-05-08 21:16:33 UTC (rev 51050)
+++ trunk/Master/tlpkg/tlpsrc/collection-pictures.tlpsrc	2019-05-08 21:17:11 UTC (rev 51051)
@@ -100,6 +100,7 @@
 depend pgfgantt
 depend pgfkeyx
 depend pgfmolbio
+depend pgfmorepages
 depend pgfopts
 depend pgfornament
 depend pgfplots

Added: trunk/Master/tlpkg/tlpsrc/pgfmorepages.tlpsrc
===================================================================


More information about the tex-live-commits mailing list