In this question:
Reversing page order from a point onward
user @BrunoLeFloch offered a very useful hack for page reversal using the atbegshi package. Unfortunately, with recent versions of TeXLive, and when using both Hebrew and English, this triggers an error, and since the details are beyond my capabilities, I'd like to ask for help in understanding what's wrong. Here's a minimal(ish) example:
\documentclass{article}
\usepackage{atbegshi}
\makeatletter
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{french}
\newif\ifRP%
\newbox\RPbox%
\setbox\RPbox\vbox{\vskip1pt}%
\AtBeginShipout{%
\ifRP
\AtBeginShipoutDiscard%
\global\setbox\RPbox\vbox{\unvbox\RPbox
\box\AtBeginShipoutBox\kern\c@page sp}%
\fi
}%
\renewcommand{\RPtrue}{% reverse page order
\clearpage
\ifRP\RPfalse\fi
\global\let\ifRP\iftrue
}%
\renewcommand{\RPfalse}{% resume normal page order
\clearpage
\global\let\ifRP\iffalse
\setbox\RPbox\vbox{\unvbox\RPbox
\def\protect{\noexpand\protect\noexpand}%
@whilesw\ifdim0pt=\lastskip\fi
{\c@page\lastkern\unkern\shipout\lastbox}%
}%
}%
\makeatother
\begin{document}
\RPtrue
\begin{french}
Fou
\newpage
\end{french}
Bar % Note: Originally, this question was posted without the extra text.
\RPfalse
\end{document}
The error message:
! Missing } inserted.
<inserted text>
}
l.48 \end{document}
I should mention this does work with TeXLive 2019.
edit: Here are the .aux files with TL 2021:
\relax
\selectlanguage *{english}
\@writefile{toc}{\selectlanguage *{english}}
\@writefile{lof}{\selectlanguage *{english}}
\@writefile{lot}{\selectlanguage *{english}}
\bgroup
\@writefile{toc}{\bgroup }
\@writefile{lof}{\bgroup }
\@writefile{lot}{\bgroup }
\selectlanguage *{french}
\@writefile{toc}{\selectlanguage *{french}}
\@writefile{lof}{\selectlanguage *{french}}
\@writefile{lot}{\selectlanguage *{french}}
\gdef \@abspage@last{1}
and with 2019:
\relax
\protect \select@language {english}
\@writefile{toc}{\protect \select@language {english}}
\@writefile{lof}{\protect \select@language {english}}
\@writefile{lot}{\protect \select@language {english}}
\protect \select@language {french}
\@writefile{toc}{\protect \select@language {french}}
\@writefile{lof}{\protect \select@language {french}}
\@writefile{lot}{\protect \select@language {french}}
\begin{french}and\end{french}insert on the page some code to\write\@auxout{\bgroup}and\write\@auxout{\egroup}, respectively. When the pages are swapped, these two (delayed)\writecommands get swapped, which means that the aux file ends up with\egroupbefore\bgroup. This is a bad nesting of groups, and it also messes up language settings in the aux file. Putting\RPtrueand\RPfalseinside the environment, or making sure that the language environments don't span more than one page, solves the problem. I don't see how to do better. – Bruno Le Floch May 26 '21 at 22:18polyglossiachanged? – Bruno Le Floch May 27 '21 at 10:24