%%
%% Copyright (c) 2022-2023 by Friedemann Bartels
%%
%% This file 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
%%
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2008/05/04 or later.
%%

\documentclass[twoside,bleed=3mm,safetymargin=2mm,beginleft]{pagelayout}

\pagewidth=100mm
\pageheight=100mm
\spinewidth=6mm
\gutter=10mm

\safezone\grid\placeholders
\newbeforepage{primary}{
  \begingroup
    \setgrid[height=10mm,y=0mm,inner margin=5mm,outer margin=5mm]{
      {{1}}
    }
    \place{0 0 1 1}
    \text[center]{\ifrightpage{\hspace*{\fill}}\thepage}
  \endgroup
}
\setbeforepage{primary}

\newcommand\mim[1]{\the\numexpr#1*2540/7227*1000/65536\relax}
\makeatletter
\newcommand\printgrid{
  w=\mim\pal@gridwidth\ h=\mim\pal@gridheight\
  r=\the\numexpr 1000*\number\pal@gridwidth/\pal@gridheight\relax\\
  \foreach \gridI in {1,...,\pal@rowscount} {
    \ifnum\gridI=1
      \ifnum\pal@get{if1F}=1\textbf{\mim{\pal@get{1HR}}}\else\mim{\pal@get{1HR}}\fi\ /\
      \ifnum\pal@get{1C}>0
        \ifnum\pal@get{if1-1F}=1\textbf{\mim{\pal@get{1-1WR}}}\else\mim{\pal@get{1-1WR}}\fi\
      \fi
      \ifnum\pal@get{1C}>1
        \ifnum\pal@get{if1-2F}=1\textbf{\mim{\pal@get{1-2WR}}}\else\mim{\pal@get{1-2WR}}\fi\
      \fi
      \ifnum\pal@get{1C}>2
        \ifnum\pal@get{if1-3F}=1\textbf{\mim{\pal@get{1-3WR}}}\else\mim{\pal@get{1-3WR}}\fi\
      \fi
      \\
    \else
      \ifnum\gridI=2
        \ifnum\pal@get{if2F}=1\textbf{\mim{\pal@get{2HR}}}\else\mim{\pal@get{2HR}}\fi\ /\
        \ifnum\pal@get{2C}>0
          \ifnum\pal@get{if2-1F}=1\textbf{\mim{\pal@get{2-1WR}}}\else\mim{\pal@get{2-1WR}}\fi\
        \fi
        \ifnum\pal@get{2C}>1
          \ifnum\pal@get{if2-2F}=1\textbf{\mim{\pal@get{2-2WR}}}\else\mim{\pal@get{2-2WR}}\fi\
        \fi
        \ifnum\pal@get{2C}>2
          \ifnum\pal@get{if2-3F}=1\textbf{\mim{\pal@get{2-3WR}}}\else\mim{\pal@get{2-3WR}}\fi\
        \fi
        \\
      \else
        \ifnum\gridI=3
          \ifnum\pal@get{if3F}=1\textbf{\mim{\pal@get{3HR}}}\else\mim{\pal@get{3HR}}\fi\ /\
          \ifnum\pal@get{3C}>0
            \ifnum\pal@get{if3-1F}=1\textbf{\mim{\pal@get{3-1WR}}}\else\mim{\pal@get{3-1WR}}\fi\
          \fi
          \ifnum\pal@get{3C}>1
            \ifnum\pal@get{if3-2F}=1\textbf{\mim{\pal@get{3-2WR}}}\else\mim{\pal@get{3-2WR}}\fi\
          \fi
          \ifnum\pal@get{3C}>2
            \ifnum\pal@get{if3-3F}=1\textbf{\mim{\pal@get{3-3WR}}}\else\mim{\pal@get{3-3WR}}\fi\
          \fi
          \\
        \fi
      \fi
    \fi
  }%
}
\makeatother

\begin{document}

  \setpagecolor{pink!80}
  \setpagegraphic[scale=2.12,hpos=0.014]{3x2}
  \setborder[radius=0.5\width,width=10mm,color=cyan,opacity=0.3]{}
  \template[margin=15mm,back cover]{f}{
    \graphic{2x3}
  }
  \setpagegraphic{}
  \setborder{}
  \setpagecolor{}

  \page[front cover]{
    \gutter=0mm
    \margin=0mm
    \setgrid{
      {[1]{1}}
    }
    \place{0 0 1 1}
    \graphic[hpos=1]{2x1}

    \gutter=5mm
    \margin=17mm
    \setgrid{
      {[16]{1}{2}{4}{8}{16}}
      {[8]{1}{2}{4}{8}{16}}
      {[2]{1}{2}{8}{4}{16}}
      {[4]{1}{2}{4}{8}{16}}
      {[1]{1}{2}{4}{8}{16}}
    }

    \place{0 0 5 5}
    \graphic{2x1}
  }

  \page{
    \margin=25mm
    \gutter=4mm
    \setgrid{
      {[2]{2!}{2!}{4!}}
      {[4]{6!}{6!}{6!}}
    }
    \place{0 0 1 1}
    \graphic{1x1}
    \place{0 1 1 2}
    \graphic{1x1}
    \place{0 2 1 3}
    \graphic{2x1}
    \place{1 0 2 1}
    \graphic{3x2}
    \place{1 1 2 2}
    \graphic{3x2}
    \place{1 2 2 3}
    \graphic{3x2}
    \place{0 0 2 3}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=54000 h=27833 r=1940\\
      14500 / \textbf{14500} \textbf{14500} \textbf{25000}\\
      13333 / \textbf{18000} \textbf{18000} \textbf{18000}\\
    }
    \place{0 0 2 3}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid\\
    }
  }

  \page{
    \margin=25mm
    \gutter=4mm
    \setgrid{
      {[4]{6!}{6!}{6!}}
      {[2]{2!}{2!}{4!}}
    }
    \place{0 0 1 1}
    \graphic{3x2}
    \place{0 1 1 2}
    \graphic{3x2}
    \place{0 2 1 3}
    \graphic{3x2}
    \place{1 0 2 1}
    \graphic{1x1}
    \place{1 1 2 2}
    \graphic{1x1}
    \place{1 2 2 3}
    \graphic{2x1}
    \place{0 0 2 3}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=54000 h=27833 r=1940\\
      13333 / \textbf{18000} \textbf{18000} \textbf{18000}\\
      14500 / \textbf{14500} \textbf{14500} \textbf{25000}\\
    }
    \place{0 0 2 3}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid
    }
  }

  \page{
    \margin=25mm
    \gutter=4mm
    \setgrid{
      {[2]{2!}{2!}{4!}}
      {[2!]{3!}{3}{3!}}
    }
    \place{0 0 1 1}
    \graphic{1x1}
    \place{0 1 1 2}
    \graphic{1x1}
    \place{0 2 1 3}
    \graphic{2x1}
    \place{1 0 2 1}
    \graphic{3x2}
    \place{1 1 2 2}
    \graphic{3x2}
    \place{1 2 2 3}
    \graphic{3x2}
    \place{0 0 2 3}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=54000 h=29000 r=1862\\
      14500 / \textbf{14500} \textbf{14500} \textbf{25000}\\
      \textbf{14500} / \textbf{19750} 14500 \textbf{19750}\\
    }
    \place{0 0 2 3}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid
    }
  }

  \page{
    \margin=25mm
    \gutter=4mm
    \setgrid{
      {[2!]{3!}{3}{3!}}
      {[2]{2!}{2!}{4!}}
    }
    \place{0 0 1 1}
    \graphic{3x2}
    \place{0 1 1 2}
    \graphic{3x2}
    \place{0 2 1 3}
    \graphic{3x2}
    \place{1 0 2 1}
    \graphic{1x1}
    \place{1 1 2 2}
    \graphic{1x1}
    \place{1 2 2 3}
    \graphic{2x1}
    \place{0 0 2 3}
    \text{
      \setcolor{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=54000 h=29000 r=1862\\
      \textbf{14500} / \textbf{19750} 14500 \textbf{19750}\\
      14500 / \textbf{14500} \textbf{14500} \textbf{25000}\\
    }
    \place{0 0 2 3}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid
    }
  }

  \page{
    \margin=25mm
    \gutter=4mm
    \setgrid{
      {[2!]{2!}{2!}{4}}
      {[2]{3!}{3!}{3!}}
    }
    \place{0 0 1 1}
    \graphic{1x1}
    \place{0 1 1 2}
    \graphic{1x1}
    \place{0 2 1 3}
    \graphic{2x1}
    \place{1 0 2 1}
    \graphic{3x2}
    \place{1 1 2 2}
    \graphic{3x2}
    \place{1 2 2 3}
    \graphic{3x2}
    \place{0 0 2 3}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=54000 h=26667 r=2025\\
      \textbf{13333} / \textbf{13333} \textbf{13333} 27333\\
      13333 / \textbf{18000} \textbf{18000} \textbf{18000}\\
    }
    \place{0 0 2 3}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid
    }
  }

  \page{
    \margin=25mm
    \gutter=4mm
    \setgrid{
      {[2]{3!}{3!}{3!}}
      {[2!]{2!}{2!}{4}}
    }
    \place{0 0 1 1}
    \graphic{3x2}
    \place{0 1 1 2}
    \graphic{3x2}
    \place{0 2 1 3}
    \graphic{3x2}
    \place{1 0 2 1}
    \graphic{1x1}
    \place{1 1 2 2}
    \graphic{1x1}
    \place{1 2 2 3}
    \graphic{2x1}
    \place{0 0 2 3}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=54000 h=26667 r=2025\\
      13333 / \textbf{18000} \textbf{18000} \textbf{18000}\\
      \textbf{13333} / \textbf{13333} \textbf{13333} 27333\\
    }
    \place{0 0 2 3}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid
    }
  }

  \page{
    \margin=25mm
    \gutter=0mm
    \setgrid{
      {[1]{1!}{2!}}
    }
    \place{0 0 1 1}
    \graphic{1x1}
    \place{0 1 1 2}
    \graphic{2x1}
    \place{0 0 1 2}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=50000 h=16667 r=3000\\
      16667 / \textbf{16667} \textbf{33333}\\
    }
    \place{0 0 1 2}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid
    }
  }

  \page{
    \margin=25mm
    \gutter=4mm
    \setgrid{
      {[4]{4!}{8!}{0!}}
      {[2]{2!}{1!}{3!}}
      {[1]{1!}{1!}{1!}}
    }
    \place{0 0 1 1}
    \graphic{1x1}
    \place{0 1 1 2}
    \graphic{2x1}
    \place{1 0 2 1}
    \graphic{1x1}
    \place{1 1 2 2}
    \graphic{1x2}
    \place{1 2 2 3}
    \graphic{3x2}
    \place{2 0 3 1}
    \graphic{1x1}
    \place{2 1 3 2}
    \graphic{1x1}
    \place{2 2 3 3}
    \graphic{1x1}
    \place{0 0 3 3}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=54000 h=54000 r=1000\\
      18000 / \textbf{18000} \textbf{32000} \textbf{4000}\\
      18000 / \textbf{18000} \textbf{11000} \textbf{25000}\\
      18000 / \textbf{18000} \textbf{18000} \textbf{18000}\\
    }
    \place{0 0 3 3}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid
    }
  }

  \page{
    \margin=25mm
    \gutter=4mm
    \setgrid{
      {[4]{4!}{8!}{0!}}
      {[2]{2!}{1!}{3!}}
      {[1!]{1}{1}{1}}
    }
    \place{0 0 1 1}
    \graphic{1x1}
    \place{0 1 1 2}
    \graphic{2x1}
    \place{1 0 2 1}
    \graphic{1x1}
    \place{1 1 2 2}
    \graphic{1x2}
    \place{1 2 2 3}
    \graphic{3x2}
    \place{2 0 3 1}
    \graphic{1x1}
    \place{2 1 3 2}
    \graphic{1x1}
    \place{2 2 3 3}
    \graphic{1x1}
    \place{0 0 3 3}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=54000 h=44667 r=1209\\
      18000 / \textbf{18000} \textbf{32000} \textbf{4000}\\
      18000 / \textbf{18000} \textbf{11000} \textbf{25000}\\
      \textbf{8667} / 18000 18000 18000\\
    }
    \place{0 0 3 3}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid
    }
  }

  \page{
    \margin=25mm
    \gutter=4mm
    \setgrid{
      {[2]{2!}{1!}{3!}}
      {[4]{4!}{8!}{0!}}
      {[1!]{1!}{1}{1!}}
    }
    \place{0 0 1 1}
    \graphic{1x1}
    \place{0 1 1 2}
    \graphic{1x2}
    \place{0 2 1 3}
    \graphic{3x2}
    \place{1 0 2 1}
    \graphic{1x1}
    \place{1 1 2 2}
    \graphic{2x1}
    \place{2 0 3 1}
    \graphic{1x1}
    \place{2 1 3 2}
    \graphic{1x1}
    \place{2 2 3 3}
    \graphic{1x1}
    \place{0 0 3 3}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=54000 h=44667 r=1209\\
      18000 / \textbf{18000} \textbf{11000} \textbf{25000}\\
      18000 / \textbf{18000} \textbf{32000} \textbf{4000}\\
      \textbf{8667} / \textbf{8667} 36667 \textbf{8667}\\
    }
    \place{0 0 3 3}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid
    }
  }

  \page{
    \margin=25mm
    \gutter=2mm
    \setgrid{
      {[2!]{4!}{2!}{6}}
      {[4]{4!}{8!}{0!}}
      {[1!]{1!}{1}{1!}}
    }
    \place{0 0 1 1}
    \graphic{1x1}
    \place{0 1 1 2}
    \graphic{1x2}
    \place{0 2 1 3}
    \graphic{3x2}
    \place{1 0 2 1}
    \graphic{1x1}
    \place{1 1 2 2}
    \graphic{2x1}
    \place{2 0 3 1}
    \graphic{1x1}
    \place{2 1 3 2}
    \graphic{1x1}
    \place{2 2 3 3}
    \graphic{1x1}
    \place{0 0 3 3}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=52000 h=32833 r=1584\\
      \textbf{9667} / \textbf{17333} \textbf{9667} 25000\\
      17333 / \textbf{17333} \textbf{32667} \textbf{2000}\\
      \textbf{5833} / \textbf{5833} 40333 \textbf{5833}\\
    }
    \place{0 0 3 3}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid
    }
  }

  \page{
    \margin=25mm
    \gutter=4mm
    \setgrid{
      {[2]{5!}}
      {[2!]{2}}
      {[1!]{1!}{1}{1}}
    }
    \place{0 0 1 1}
    \graphic{1x1}
    \place{1 0 2 1}
    \graphic{2x1}
    \place{2 0 3 1}
    \graphic{1x1}
    \place{0 0 2 1}
    \text{
      \color{red}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      w=46000 h=54000 r=852\\
      20800 / \textbf{46000}\\
      \textbf{20800} / 46000\\
      \textbf{12400} / \textbf{12400} 16800 16800\\
    }
    \place{0 0 2 1}
    \text{
      \pgfsetfillopacity{0.8}
      \color{black}\fontsize{5pt}{6pt} \fontseries{m}\selectfont%
      \printgrid\\
    }
  }

  \setgraphpaper{10mm,50mm}

  \newtemplate{testtemplate}{
    \setgrid{
      {{1}{1}}
      {{1}{1}}
      {{1}{1}}
    }
    \placeholder{0 0 2 2}
    \placeholder{0 0 1 1}
    \placeholder{1 1 2 2}
    \placeholder{2 0 3 2}
  }

  \template{testtemplate}{
    \graphic[hpos=0]{2x1}
    \graphic{3x2}
  }

  \page{
    \nosafezone
    \setgrid{
      {{1}{1}{1}}
      {{1}{1}{1}}
    }
    \place{0 0 2 2}
    \graphic[hpos=1]{2x1}
    \place{0 0 1 1}
    \graphic{3x2}
    \place{1 1 2 2}
    \graphic[hpos=1]{1x1}
  }

  \page{
    \setgrid{
      {[1]{1!}{1!}}
      {[1]{1!}{1!}}
    }
    \place{0 0 2 2}
    \graphic[hpos=0]{2x1}
    \place{1 0 2 1}
    \graphic{3x2}
    \place{0 1 1 2}
    \graphic{1x1}
  }
  \page{
    \setgrid{
      {[1]{1!}{1!}}
      {[1]{1!}{1!}}
    }
    \place{0 0 2 2}
    \graphic[hpos=1]{2x1}
    \place{1 0 2 1}
    \graphic{3x2}
    \place{0 1 1 2}
    \graphic[hpos=1]{1x1}
  }

  \page[double]{
    \setgrid{
      {{1}{1}{1}{1}}
      {{1}{1}{1}{1}}
    }
    \place{0 0 2 4}
    \graphic{2x1}
    \place{1 0 2 1}
    \graphic{3x2}
    \place{0 1 1 2}
    \graphic{3x2}
    \place{1 2 2 3}
    \graphic{3x2}
    \place{0 3 1 4}
    \graphic{3x2}
  }

  \page{
    \gutter=0mm
    \margin=0mm
    \setgrid{
      {{1}}
    }
    \place{0 0 1 1}
    \graphic[hpos=0]{2x1}
    \setgrid{
      {{1}{1}}
      {{1}{1}}
    }
    \place{1 0 2 1}
    \graphic{3x2}
    \place{1 1 2 2}
    \graphic{2x1}
  }
  \page{
    \gutter=0mm
    \margin=0mm
    \setgrid{
      {{1}{1}}
      {{1}{1}}
    }
    \place{0 0 2 2}
    \graphic[hpos=1]{2x1}
    \place{1 0 2 1}
    \graphic{1x1}
    \place{0 0 1 1}
    \graphic{1x2}
    \place{0 1 1 2}
    \graphic{2x3}
  }

  \page[double]{
    \gutter=0mm
    \margin=0mm
    \setgrid{
      {{1}{1}{1}{1}}
      {{1}{1}{1}{1}}
    }
    \place{0 0 2 4}
    \graphic{3x2}
    \place{1 0 2 1}
    \graphic{3x2}
    \place{1 1 2 2}
    \graphic{2x1}
    \place{0 2 1 3}
    \graphic{1x2}
    \place{1 2 2 3}
    \graphic{1x1}
    \place{0 3 1 4}
    \graphic{2x3}
  }

  \page{
    \gutter=0mm
    \margin=0mm
    \setgrid{
      {[1]{1!}{1!}}
    }
    \place{0 0 1 1}
    \graphic[hpos=0]{2x1}
    \place{0 1 1 2}
    \graphic[hpos=1]{2x1}
    \place{0 0 1 1}
    \graphic{2x1}
    \place{0 1 1 2}
    \graphic{2x1}
    \place{0 0 1 1}
    \graphic[hpos=1]{2x1}
    \place{0 1 1 2}
    \graphic[hpos=0]{2x1}
  }

  \page{
    \gutter=0mm
    \margin=0mm
    \setgrid{
      {[4]{3!}}
    }
    \place{0 0 1 1}
    \graphic{1x2}
    \setgrid{
      {[2]{2!}}
      {[2]{2!}}
    }
    \place{0 0 1 1}
    \graphic{1x2}
    \place{1 0 2 1}
    \graphic{1x2}
  }

  \page{
    \gutter=10mm
    \margin=7mm
    \setgrid{
      {[2]{3!}{2!}}
      {[2]{3!}{2!}}
    }
    \place{1 0 2 1}
    \graphic{3x2}
    \place{1 0 2 1}
    \xput{%
      \begin{tikzpicture}
        \pgflowlevelsynccm
        \draw[line cap=rect,line width=1mm,draw=red,opacity=0.5] (0,\height) -- (\width,0);
      \end{tikzpicture}
    }
    \put(0,0){%
      \begin{tikzpicture}%
        \pgflowlevelsynccm
        \draw[line cap=rect,line width=0.05mm,draw=blue,opacity=1] ({\posx{0}{0}{1}{0}},{\posy{1}{1}}) -- ({\posx{0}{0}{-1}{1}},{\posy{-1}{2}});%
        \draw[line cap=rect,line width=0.05mm,draw=blue,opacity=1] ({\posx{0}{0}{1}{1}},{\posy{1}{0}}) -- ({\posx{0}{0}{-1}{2}},{\posy{-1}{1}});%
        \draw[line cap=rect,line width=0.05mm,draw=blue,opacity=1] ({\posx{0}{0}{1}{0}},{\posy{-1}{2}}) -- ({\posx{0}{0}{0}{0.5}},{\posy{0}{1.5}});%
        \draw[line cap=rect,line width=0.05mm,draw=blue,opacity=1] ({\posx{0}{0}{1}{1}},{\posy{-1}{1}}) -- ({\posx{0}{0}{0}{1.5}},{\posy{0}{0.5}});%
      \end{tikzpicture}%
    }
  }

  \page{
    \gutter=10mm
    \margin=7mm
    \setgrid[hpos=1]{
      {[2]{2!}{2!}}
      {[3]{2!}{2!}}
    }
  }

  \page{
    \margin=0mm
    \gutter=10mm
    \setgrid[hpos=0]{
      {[3]{2!}}
    }
    \place{0 0 1 1}
    \graphic{2x3}
  }

  \page[double]{
    \margin=0mm
    \setgrid{
      {{1}}
    }
    \place{0 0 1 1}
    \graphic{2x1}
    \margin=17mm
    \gutter=0mm
    \setgrid{
      {[2!]{2}{2}}
      {[2]{2!}{3!}}
    }
    \place{0 0 1 1}
    \graphic{3x2}
    \place{0 1 1 2}
    \graphic{1x1}
    \place{1 0 2 1}
    \graphic[hpos=1]{2x1}
    \place{1 1 2 2}
    \graphic{3x2}
  }

  \page[double]{
    \margin=0mm
    \bindingoffset=2mm
    \setgrid{
      {{1}}
    }
    \place{0 0 1 1}
    \graphic{2x1}
    \margin=17mm
    \setgrid{
      {[2]{2!}{2!}{2!}{2!}}
      {[2!]{3}{3}{3}}
    }

    \place{0 0 1 1}
    \graphic{1x1}
    \place{0 1 1 2}
    \graphic{1x1}
    \place{0 2 1 4}
    \graphic{2x1}
    \place{1 0 2 1}
    \graphic{3x2}
    \place{1 1 2 2}
    \graphic{3x2}
    \place{1 2 2 3}
    \graphic{3x2}
  }

  \page[double]{
    \bindingoffset=2mm
    \margin=0mm
    \gutter=0mm
    \setgrid{
      {{1}}
    }
    \place{0 0 1 1}
    \graphic{1x1}
    \margin=7mm
    \gutter=8mm
    \setgrid{
      {[2!]{2}{2}}
      {[2]{2!}{3!}}
    }
    \place{0 0 1 1}
    \graphic{3x2}
    \place{0 1 1 2}
    \graphic{1x1}
    \place{1 0 2 1}
    \graphic[hpos=1]{2x1}
    \place{1 1 2 2}
    \graphic{3x2}
  }

  \pageheight=50mm
  \template[gutter=0mm,margin=0mm]{f}{
    \graphic{1x1}
  }
  \template[gutter=0mm,margin=0mm]{ff}{
    \graphic{2x1}
    \graphic{2x1}
  }
  \pageheight=200mm
  \template[gutter=0mm,margin=0mm]{f}{
    \graphic{1x1}
  }
  \template[gutter=0mm,margin=0mm]{ff}{
    \graphic{2x1}
    \graphic{3x2}
  }
  \pageheight=100mm

  \nographpaper\nogrid
  \margin=12mm
  \gutter=4mm

  \template[page graphic=1x1]{f}{}
  \template[gutter=0mm,margin=0mm,hpos=0]{p}{}
  \template[gutter=0mm,margin=0mm,double]{f}{}

  \template{ff}{}
  \template[gutter=0mm,margin=0mm]{f-f}{}

  \template[double]{sss}{}
  \newtemplate{ww-w}{
    \setgrid{
      {[2]{4!}{4!}}
      {[2!]{1}{4!}{1}}
    }
    \placeholder{0 0 1 1}
    \placeholder{0 1 1 2}
    \placeholder{1 1 2 2}
  }
  \template[double]{ww-w}{}

  \template{sl-ls}{}
  \nosafezone
  \newtemplate{fourvariouse}{
    \setgrid{
      {[3]{2!}{3!}}
      {[2!]{1}}
    }
    \placeholder{0 0 1 1}
    \setgrid{
      {[2]{2!}{3!}}
      {[3!]{1}}
    }
    \placeholder{0 1 1 2}
    \setgrid{
      {[3!]{1}}
      {[2]{3!}{2!}}
    }
    \placeholder{1 0 2 1}
    \setgrid{
      {[2!]{1}}
      {[3]{3!}{2!}}
    }
    \placeholder{1 1 2 2}
  }
  \template{fourvariouse}{}
  \safezone

  \newtemplate{fivesquaresa}{
    \setgrid{
      {[1]{1!}{1!}{1!}{1!}}
      {[1]{1!}{1!}{1!}{1!}}
    }
    \placeholder{0 0 1 1}
    \placeholder{1 0 2 1}
    \placeholder{0 1 2 3}
    \placeholder{0 3 1 4}
    \placeholder{1 3 2 4}
  }
  \template[double]{fivesquaresa}{}

\end{document}
