I am trying to extend the rotating
package to also show the respective pages properly rotated in the PDF output by setting the PDF page attribute /Rotate
. I have a working version for XeLaTeX, however, I don't manage to get this done for LuaLaTeX. Please consider the following MWE:
\documentclass{article}
\usepackage{lipsum}
\usepackage{rotating}
\usepackage{etoolbox}
\usepackage{iftex}
\usepackage{afterpage}
\ifLuaTeX
\edef\pdfpageattr{\pdfvariable pageattr}
\fi
\makeatletter
\def\@PDFrot#1{%
\ifXeTeX%
\special{pdf: put @thispage <</Rotate #1>>}%
\fi%
\ifLuaTeX%
\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate #1}%
\afterpage{\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 0}}%
\fi%
}
\patchcmd{\@xrotfloat}%
{\begin{minipage}\textheight}%
{\begin{minipage}\textheight\@PDFrot{90}}%
{}{}%
\makeatother
\begin{document}
\lipsum[1-10]
\begin{sidewaysfigure}
\centering
Test
\caption{Just an example figure.}
\end{sidewaysfigure}
\lipsum[1-5]
\end{document}
When compiling this MWE with XeLaTeX, one will get the desired behavior: The float page with the sidewaysfigure
contents (page 3) is properly rotated in the PDF output. But when compiled with LuaLaTeX, also page 2 will be rotated, too, which is not desired.
Desired PDF page orientations when compiled with XeLaTeX.
Wrong PDF page orientation of page 2 when compiled with LuaLaTeX.
I think this is because the definition of the sidewaysfigure
contents (together with setting the PDF attribute) will already be evaluated on page 2, where the content would appear if it would not be a float. I've found no way of circumventing this problem and would be glad for any idea.
N.B.: The MWE is just a reduced example, which does not properly take the orientation of the page based on its page number (even/odd) into account. I eliminated these code parts for the sake of easier understanding of the MWE.