\restoregeometry from inside afterpage

I want to create a twoside article as a booklet where the first page is centered, and the rest is not. Using \newgeometry and restoregeometry within the afterpage macro doesn't work for some reason. Here's a minimal (non-)working example:

\documentclass[11pt,twoside,a5paper]{article}
\newlength{\marg}
\setlength{\marg}{1in}
\usepackage[paper=a5paper,twoside,bottom=\marg,top=\marg,left=\dimexpr\marg-.4in\relax,right=\marg]{geometry}
\usepackage{afterpage,lipsum}

\title{Some Booklet}
\author{Me \and Myself \and I}

\begin{document}
\newgeometry{margin=\marg}
\maketitle
\afterpage{\clearpage\restoregeometry}
Here is some text that will still be on the first page. As soon as the page breaks,
there should be a new (resp. old) twoside geometry, with the text continuing freely.
But it doesn't work! %(ノ°Д°）ノ︵ ┻━┻
\lipsum[1-6]
\end{document}


Does someone know why this does not work?

• this can't work, the start of the second page is typeset before the afterpage insertion, so it is too late to change the page geometry. Do you really need to change the text width? – David Carlisle Jun 4 '17 at 18:29
• More to the point, do you really need \afterpage? Both \clearpage and \restoregeometry force new pages. – John Kormylo Jun 4 '17 at 21:39

TeX line breaking happens before page breaking, so you need to know the line width before the paragraph is broken into lines, this means you need to know which page the text will fall on. With a bit of hand work you can however force the desired output.

\documentclass[11pt,twoside,a5paper]{article}
\newlength{\marg}
\setlength{\marg}{1in}
\usepackage[paper=a5paper,twoside,bottom=\marg,top=\marg,left=\dimexpr\marg-.4in\relax,right=\marg]{geometry}
\usepackage{afterpage,lipsum}

\title{Some Booklet}
\author{Me \and Myself \and I}

\begin{document}
\newgeometry{margin=\marg}
\maketitle
Here is some text that will still be on the first page. As soon as the page breaks,
there should be a new (resp. old) twoside geometry, with the text continuing freely.
But it doesn't work! %(ノ°Д°）ノ︵ ┻━┻
\lipsum[1]

% first bit of paragraph 2
Nam dui ligula, fringilla a, euismod sodales, sollicitudin
vel, wisi. Morbi auctor lorem non justo. Nam lacus libero,
pretium at, lobortis vitae, ultricies et, tellus. Donec
aliquet, tortor sed accumsan bibendum, erat ligula aliquet{\parfillskip=0pt\par}

\restoregeometry
%\lipsum[2]

% second bit of paragraph 2
\noindent magna, vitae ornare odio metus a mi. Morbi ac orci et nisl
hendrerit mollis. Suspendisse ut massa. Cras nec ante. Pellentesque a
nulla. Cum sociis natoque penatibus et magnis dis parturient montes,
nascetur ridiculus mus. Aliquam tincidunt urna. Nulla ullamcorper
vestibulum turpis. Pellentesque cursus luctus mauris.

\lipsum[3-6]

\end{document}

• Indeed, but it seems like a very non-LaTeXic way to do things. If I wanted to do hand work, I'd use MS Word. – ionree Jun 5 '17 at 6:50
• @ionree that depends how you define what is or what is not "the latex way". I've been maintaining latex for 25 years, and that's what I'd do to set that with latex. (if you were just changing the margins to be centred without changing the width of the text block it would be much easier.) – David Carlisle Jun 5 '17 at 7:44
• Out of curiosity, how would you go about changing the page margins without modifying the text block width? – ionree Jun 11 '17 at 19:59