For some reasons, I have a 100+ pages LaTeX document that I'm required to format the following way:
- if
\thepage = 1(modulo 4) then margins must be set to 5cm; - if
\thepage = 2(modulo 4) then margins must be set to 4cm; - else margins must be set to 2cm.
The geometry package provides macros for setting margins out of the preamble, namely \newgeometry and \restoregeometry.
Now I need a way to insert them automatically at the beginning of every pages.
Unfortunately, this does not seem to be possible due to the way the output routine works (see an example of a non working solution below).
\documentclass{article}
\usepackage{geometry}
\geometry{a4paper, margin = 2cm}
\usepackage{lipsum}
% https://tex.stackexchange.com/questions/34424/how-do-i-calculate-n-modulo-3-in-latex
\def\truncdiv#1#2{((#1-(#2-1)/2)/#2)}%
\def\moduloop#1#2{(#1-\truncdiv{#1}{#2}*#2)}%
\def\modulo#1#2{\number\numexpr\moduloop{#1}{#2}\relax}%
\makeatletter
\let\@@outputpage\@outputpage
\def\@outputpage{%
\ifcase\modulo{\thepage}{4}\relax
% Page 4
\or
% Page 1
\newgeometry{margin = 5cm}%
\or
% Page 2
\newgeometry{margin = 4cm}%
\or
% Page 3
\restoregeometry
\fi
\@@outputpage}
\makeatother
\begin{document}
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\end{document}
I was wondering if luatex and its callbacks on lua side could be of any help with that matter?